/* GrabTag.Spot Vers 1.2 (6-9-93) By Chi Wai Lee <2:253/167.9>  */
/* Interogates a message and writes the tagline to your tagline */
/* file in standard SPOT tagfile format.                        */
/* Tagline must begin with '...'                                */
/* ------------------------------------------------------------ */
/* Enhanced by Philippe Van Der Gucht
   Date: 9/10/1993
   FIDO: 2:292/603.47
*/

address SPOT
options results
options failat 21

/* Put the full path to your tagline file here */
tagfilename = "MAIL:spot.taglines"
cr='0a'x
lf='0d'x

'ismessages'
if rc = 0 then do   /* Must be in messages */

     /* Save out message and read it into a variable */
     'saveascii t:spotascii.tmp overwrite noheader'
     call open(in,'t:spotascii.tmp','r')
     msg = readch(in,65535)

     /* Find the tagline identifier i.e. '...' */
     'requeststring TITLE "Tagline recognition" PROMPT "By which characters is the tagline identified?" DEFAULT "..."'
     recog=RESULT
     start = lastpos(cr''recog,msg)
     if start ~= 0 then do    /* Can't find a tagline */

          /* Puts the tagline into a variable */
          call seek(in,start+length(recog)+1,'b')
          tag=''
          zoek=''
          do while 1
              erin=strip(readln(in),'b')
              if left(erin,3) == '---' then do
                 tag=left(tag,length(tag)-1)
                 leave
              end
              tag = tag || erin || cr
              zoek = zoek || erin || cr
          end
          say tag
          'requestresponse TITLE "GrabTag2" PROMPT "Add tagline to tagfile?'lf'Check for dupe in tagfile?" Gadgets "_Ok|_Dupecheck|_Cancel"'
          Antw=RC
          IF Antw = 1 then do
             call store_tag()
          end
          If Antw = 2 then do
/* check only for 30 first chars of tagline...
   due to limitation of 'search' command */
             if length(zoek) > 30 then zoek=left(zoek,30)
             posi=pos(cr,zoek)
             if posi ~= 0 then zoek=left(zoek,posi-1)
             Address command 'search >t:dupes from "'tagfilename'" string "'zoek'"'
             call open(dupe,'t:dupes','R')
             tel=0
             do while 1
                say readln(dupe)
                if eof(dupe) then leave
                tel=tel+1
             end
             call close(dupe)
             if tel <= 2 then do
                'requestresponse TITLE "Grabtag2" PROMPT "No dupes were found...'lf'   Add tagline?"'
                if RC ~= 5 then call store_tag()
             end
             else do
                'requestresponse TITLE "Grabtag2" PROMPT "Dupes were found!'lf'   Add anyway?"'
                if RC ~= 5 then call store_tag()
             end
             Address command 'Delete >NIL: t:dupes'
          end
     end
     else 'requestnotify "I can''t seem to find a tagline."'
     call close in
     address command 'delete >nil: t:spotascii.tmp'
end
else 'requestnotify "Use in message window only!"'
exit

store_tag:
      /* Makes sure that the tagfile exists */
      if ~exists(tagfilename) then call open(tagfile,tagfilename,'w')
      else do
           call open(tagfile,tagfilename,'a')
           call writeln(tagfile,'%%')
      end
      call writeln(tagfile,tag)
return

