/*******************************************************************/
/*              QuotePercent v1.0 calculator for Spot              */
/*                    written: May 22th 1994 by                    */
/*               Kent Hansen  (2:230/418.31@FIDONET)               */
/*                e-mail: kent.hansen@scala.pink.dk                */
/*                                                                 */
/* This script calculates the percentage of quoted characters in a */
/* message, and put up a requester showing the percentage          */
/********************************************************************/


ADDRESS spot
OPTIONS results

'lockgui'

/* Check for, and load libraries */
IF ~EXISTS('LIBS:rexxsupport.library') THEN DO
  'requestnotify "Please install the rexxsupport.library in your LIBS: directory"'
  CALL quit
END
CALL ADDLIB('rexxsupport.library',0,-30,0)
IF ~EXISTS('LIBS:rexxreqtools.library') THEN DO
  'requestnotify "Please install the rexxreqtools.library in your LIBS: directory"'
  CALL quit
END
CALL ADDLIB('rexxreqtools.library',0,-30,0)


/* Check if Spot is in the messagewindow */
'ismessages'
IF rc~=0 THEN DO
  'requestnotify "Please use only while viewing a message" center'
  CALL quit
END

saveascii 'T:Spot_1.tmp' overwrite noheader notearline nokludges

'getfrom'
name=result


/* Check for quoted and new characters, skip the tagline */
CALL OPEN('infile','T:Spot_1.tmp','READ')
quoted=0; new=0;
currentline=READLN('infile')
DO WHILE ~EOF('infile') & ~(LEFT(currentline,4)='... ')
  IF RIGHT(WORD(currentline,1),1)='>' THEN quoted=quoted+LENGTH(currentline)
  ELSE new=new+LENGTH(currentline)
  currentline=READLN('infile')
END
CALL CLOSE('infile')
proc=TRUNC((quoted/(new+quoted))*10000)/100


/* Put up requester */
reply=name 'quoted 'proc'%%'

CALL rtezrequest(reply,,'QuotePercent',,'rt_pubscreenname=SPOT')


/* Cleanup */
CALL DELETE('t:Spot_1.tmp')

quit:
'unlockgui'
EXIT
