
/****************************************************************/
/* $VER: GetTags.spot 1.0 (21.11.93)                            */
/* ts;4                                                         */
/****************************************************************/
/* This script steals ALL tags from ALL fido messages           */
/* and adds the originator, fido address and date at the top    */
/*  (this 'feature' can be disabled).                           */
/* NO duplicate checking is done.                               */
/****************************************************************/
/* Heuristics:                                                  */
/*  taglines start with '... '                                  */
/*  taglines stop  with '--- ' or '___ '                        */
/****************************************************************/
/* History:                                                     */
/*  0.x aplha                                                   */
/*    prehistory                                                */
/*  0.3 aplha                                                   */
/*    'originator' no longer overwritten by 'thief'             */
/*    better GUI (progress)                                     */
/*  0.4 alpha                                                   */
/*    always close an open progress in case of trouble          */
/*    reset unread flag for unread messages (slow)              */
/*  1.0 (21.11.93)                                              */
/*    use 'markmessage' feature from Spot 1.2c (thanks Nico !)  */
/*    GetTags is much smoother and faster now                   */
/****************************************************************/
/* Author: Marc Duponcheel                                      */
/****************************************************************/

/* for performance, assign T: to somewhere in RAM: */

/* trace results */

version = 1.0
program = 'GetTags.spot' version

OPTIONS RESULTS

/* indeed */
ADDRESS spot

SIGNAL ON break_c
SIGNAL ON syntax
SIGNAL ON failure

/* for upward and backward compatibility, don't change these */
/* I admit they are not very well chosen though ... suggestions are wellcome */
orgstart = "=== ("
orgstop  = ") ==="

LF = '0d'x

title = '"' || " <<< " || program || " WARNING " || " >>>" || '"'
'requestresponse
  TITLE   'title'
  PROMPT  "Running this script takes a while.'LF'Do you wish to continue ?"
  GADGETS "_Run it !|_Exit now !"'
IF RC = 0 THEN
	EXIT

/* you may wish to play with these variables */
askaddorigin = 1
addorigin = 1

IF askaddorigin ~= 0 THEN
DO
	title = '"' || " <<< " || program || " REQUEST " || " >>>" || '"'
	'requestresponse
	  TITLE   'title'
	  PROMPT  "Just one more question to answer ...'LF'Do you wish to add or skip originator information ?"
	  GADGETS "_Add it !|_Skip it !"'
	IF RC = 0 THEN
		addorigin = 0
	ELSE
		addorigin = 1
END

address command 'delete >NIL: T:_tags'

'arealist'
'lockgui'

/* you may wish to play with this variable */
toolong = 16

tags = 0
numareas = 0
popen = 0

/****************************************************************/
IF OPEN('output', 'T:_tags', 'WRITE') THEN
DO
	'getnumareas' ; numareas = RESULT
	IF numareas > 0 THEN
		DO
			'firstarea'
			DO area = 1 TO numareas
				CALL HandleArea
			END
		END
	CALL CLOSE('output')
END
/****************************************************************/

/* program exceptions */
break_c:
syntax:
failure:
IF RC > 0 THEN
	SAY errortext(RC) 'at line' SIGL

exit:
IF popen > 0 THEN
	'progressclose' preq
'unlockgui'
'arealist'
IF numareas > 0 THEN
	'firstarea'

/* some crucial and interesting info for the end user */
prompt = '"' tags 'taglines saved in' 'T:_tags' '"'
'requestnotify PROMPT 'prompt''

address command 'delete >NIL: T:_saveascii'

/* the end */
EXIT

/****************************************************************/
	/* we are now in arealist state */
HandleArea:
	'getareausername' ; areausername = RESULT
	title = '"' || program || " scanning " || areausername || " ..." || '"'
	'progressopen TITLE 'title'' ; preq = RESULT ; popen = 1
	'messagelist'
/* make sure that no messages are selected */
	'excludeflag ALL'
	'getnummsgs' ; nummsgs = RESULT
	IF nummsgs > 0 THEN
		DO msg = 1 TO nummsgs
	/* see if user did not stop */
			'progressupdate' preq msg nummsgs
			IF RC = 5 THEN
				DO
					'progressclose' preq ; popen = 0
					SIGNAL break_c
				END
			CALL HandleMessage
		END
	'excludeflag ALL'
	'progressclose' preq ; popen = 0
	'arealist'
	'nextarea'
	RETURN
/****************************************************************/

/****************************************************************/
	/* we are now in messagelist state */
HandleMessage:
	'gotomessage' msg
/* splendid, fast, underestimated, misunderstood, funky feature of Spot (>1.2c) */
	'markmessage'
	'saveascii "T:_saveascii" OVERWRITE NOHEADER NOKLUDGES'
	IF OPEN('input', 'T:_saveascii', 'READ') THEN
	DO
		CALL Reset
		DO UNTIL EOF('input') = 1
			line = READLN('input')
			IF intag = 0 THEN
				DO
			/* find tag starter */
					IF COMPARE(LEFT(line, 4), '... ') = 0 THEN
						DO
							intag = 1
					/* Spot tag separator */
							tag = '%%'
					/* add tag separator */
							CALL AddTag
							line = SUBSTR(line, 5)
/* did user want to add origin info */
	IF addorigin ~= 0 THEN
		DO
					/* don't overwrite tag originator */
							IF (COMPARE(LEFT(line, 5), orgstart) ~= 0) & (COMPARE(RIGHT(line, 5), orgstop) ~= 0) THEN
								DO
									'getfrom'        ; from        = RESULT
									'getfromaddress' ; fromaddress = RESULT
									'getdatewritten' ; datewritten = RESULT
	/* you may wish to shorten or customise the originator info */
					tag = orgstart 'Origin:' from 'Fido:' fromaddress 'Date:' datewritten '(c)' program orgstop
								/* add tag originator */
									CALL AddTag
								END
		END
							tag = line
							CALL AddTag
						END
				END
			ELSE /* (intag ~= 0) */
				DO
					IF ctr > toolong THEN
						DO
					/* sorry tag originator ... try to be terse */
							SAY '! WARNING ! long tag skipped ...'
							CALL Reset
						END
					ELSE /* ctr <= toolong */
						DO
							tag = line
							CALL AddTag
							line = LEFT(line, 4)
					/* find tag stopper */
							IF (COMPARE(line, '--- ') = 0) | (COMPARE(line, '___ ') = 0) THEN
								DO
									ctr = ctr - 1
									DO tc = 1 TO ctr
										SAY tag.tc
										CALL WRITELN('output', tag.tc)
									END
									tags = tags + 1
									CALL Reset
								END
						END
				END
		END
		CALL CLOSE('input')
	END
	'markmessage CLEAR'
	RETURN
/****************************************************************/

/****************************************************************/
	/* get ready for new taglines */
Reset:
	intag = 0
	tag. = ""
	tag.0 = 0
	ctr = 0
	RETURN
/****************************************************************/

/****************************************************************/
	/* add tagline to taglines */
AddTag:
	ctr = ctr + 1
	tag.0 = ctr
	tag.ctr = tag
	RETURN
/****************************************************************/
