home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / fltintch.zip / icefi.cmd < prev    next >
OS/2 REXX Batch file  |  1997-10-01  |  10KB  |  367 lines

  1. /* ICEFI.cmd:  filter import from interchange format jt Sept 1997 */
  2. /* companion to icefx.cmd; reads its interchange format and rebuilds */
  3. /* lines for mr2i.flt which are written either in a separate file or */
  4. /* appended to the end of mr2i.flt */
  5. /* September 1997 with new FIF format for mr2i 1.34 new filter format */
  6.  
  7. /* filters are left not enabled  unless a + flag is used */
  8.  
  9. arg infile rest 
  10.  
  11. proglev=0.7
  12. fiflev="1.35nf1"
  13. say 'ICEFI program level' proglev '; requires FIF level' fiflev
  14.  
  15. if infile='' then do
  16.    say 'usage is:  ICEFI  infile [outfile] [+] [-]'
  17.    say ''
  18.    say 'Run this program in the directory that contains your mr2i.flt'
  19.    say 'file (even if you explicitly specify a different outfile).'
  20.    say ''
  21.    say 'If outfile is omitted, lines are appended to mr2i.flt.  If the +'
  22.    say 'switch is not present, filters are left disabled regardless of'
  23.    say 'setting of the enabled flag in the interchange file.  If the + is'
  24.    say 'present, the enabled state is copied from the input.  '
  25.    say 'If folders.ndx or mail\folders.ndx file is found, will try to'
  26.    say 'match folder NAME (not directory) in interchange file and use'
  27.    say 'corresponding folder directory on target system; if no match'
  28.    say 'found you will be asked to select a folder directory for this'
  29.    say 'case [and optionally, any subsequent cases where there is no'
  30.    say 'folder name match].'
  31.    say ''
  32.    say 'Unless the - switch is present, the output will be in 1.34 and later'
  33.    say 'filterfile format.'
  34.    say 'If the - switch is present, output will be in old format.'
  35.    exit
  36.   end
  37.  
  38. fieldsep='01'x
  39. lpiece=72       /* set in icefx */
  40. enable=0
  41. old=0
  42. outfile='mr2i.flt'
  43. if length(rest)>0 then do
  44.   parse var rest a b
  45.   if pos(left(a,1),'-+')=0 then parse var rest outfile a b
  46.   if left(a,1)='+' then enable=1 
  47.   if left(b,1)='+' then enable=1
  48.   if left(b,1)='-' then old=1
  49.   if left(a,1)='-' then old=1
  50.   if a='+-' then old=1
  51.   end
  52.  
  53. if old=1 then fieldsep='\'
  54.  
  55. fldnam.=''
  56. flddir.=''
  57.  
  58. call readndx
  59. folderask=''
  60.  
  61. signal on notready
  62. which = infile
  63. if lines(infile) = 0 then signal notready
  64. call lineout(infile)   /* close file */
  65. which = ''
  66.  
  67. line=linein(infile)  /* the delimiter is the last line read by process */
  68. parse var line x x filtno x iflev x  /* for error messages */
  69. if fiflev <> iflev then do
  70.    say 'FIF level mismatch.  Input file' infile 'was level' iflev
  71.    say 'This version of the program requires level' fiflev
  72.    call lineout infile  /* close it */
  73.    exit
  74.    end
  75.  
  76. do while lines(infile)
  77.    if substr(line,1,10)='----------' then do
  78.         call process
  79.         parse var line x x filtno x iflev x  /* for error messages */
  80.     end
  81.    else do
  82.       say 'last filter completely processed was number' filtno-1
  83.       say 'lost place in input file; last line read:'
  84.       say line
  85.       /* close files */
  86.       call lineout infile
  87.       call lineout outfile
  88.       exit
  89.       end
  90.    end
  91. /* close files */
  92. call lineout infile
  93. call lineout outfile
  94. say 'ICEFI done'
  95. exit
  96.  
  97. finit:
  98. /* init the templates for the output filter line */
  99. f.=''
  100. ff.=''
  101. ff.4='Y'
  102. ff.14='M'
  103. do i=5 to 12
  104.    ff.i='N'
  105.    end
  106. return /* finit */
  107.  
  108. process:
  109. call finit   /* init the template for the output filter */
  110. enflag=''
  111. do while lines(infile)
  112.    line = linein(infile)
  113.    if substr(line,1,10)='----------' then do
  114.       /* assemble check and output */
  115.       if checkit() then call writeit
  116.       else do 
  117.          say 'error[s] in processing filter number' filtno
  118.          say 'not written'
  119.      say 'fiflevel of input filter was ' fiflev
  120.      end
  121.       return
  122.       end
  123.    /* parse for "xxx " field size value  */
  124.    parse var line '"' text '"' field size value
  125.    select
  126.       when field='f1.1' then enflag=value
  127.       when field='f1.2' then do
  128.           if enable then f.1=enflag||value
  129.           else f.1='-'||value
  130.           end
  131.       when (field='f5') & (old=1)  then do
  132.          value=pathsep(value)
  133.      f.5=value
  134.          end
  135.       when (field='f10') & (old=1)  then do
  136.          value=pathsep(value)
  137.      f.10=value
  138.          end
  139.       when field='f4' then do
  140.          /* new split format for search text */
  141.      eloop=0
  142.      if value='' then do until eloop>0
  143.           nxx=stream(infile,'c','seek +0')
  144.           l2=linein(infile)
  145.           if left(l2,1)<>' ' then do
  146.               /* we are done; back out the line */
  147.           njunk=stream(infile,'c','seek =' nxx)
  148.           eloop=1
  149.           f.4=strip(value,'T')
  150.           end   /* backout and quit */
  151.               else do 
  152.               l2= substr(l2,2,lpiece,' ')
  153.           /* we pad it out in case trailing blanks got lost
  154.           somewhere... */
  155.               value=value||l2
  156.           end
  157.           end /* multiline value */
  158.      else f.4=value
  159.      end  /* f4 */
  160.       when field='f6' then do
  161.       /* rework for new format here */
  162.          do until f.6<>''
  163.             f.6= folderfix()
  164.         end /* do until */
  165.      end /* f6 */
  166.       when substr(field,1,4)='f13.' then do
  167.          /* process f13.# lines */
  168.          parse var field . '.' subfield .
  169.      ff.subfield=substr(value,1,1)
  170.      end
  171.       otherwise do
  172.          fieldno=substr(field,2)
  173.          f.fieldno=value
  174.          end
  175.       end /* select */
  176.    end /* end of infile */
  177. say 'premature end of input file in filter number' filtno
  178. say 'last line read:'
  179. say line
  180. return /* abend process */
  181.  
  182. checkit:
  183.    rv=1
  184.    if old=1 then do
  185.       if pos('\',f.1) + pos('\',f.2) + pos('\',f.4) >0 then do
  186.          say 'Backslash in f.1 f.2 or f.4 not allowed in old format'
  187.      rv=0
  188.      end
  189.       end
  190.    /* f1 */   
  191.    if (pos(enflag,'+-')=0)|(length(f.1)<2) then do
  192.       say 'bad input enabled flag or filter name'
  193.       rv=0
  194.       end
  195.    /* f2 */ 
  196.    if length(f.2)=0 then do
  197.       say 'filter alias field f.2 missing in input'
  198.       rv=0
  199.       end
  200.    if (datatype(f.3)=char)|(f.3<1)|(f.3>1023) then do
  201.       say 'search mode field not numeric or out of range'
  202.       rv=0
  203.       end
  204.    /* needs to be dependent on old/new format !! */
  205.    if pos('\',f.4)>0 then do
  206.       say 'search expression field contains one or more \ characters'
  207.       rv=0
  208.       end
  209.    if ((ff.2='S')&(length(f.4)>80))|((ff.2='F')&(length(f.4)>1024)) then do
  210.        say 'Search expression too long'
  211.        rv=0
  212.        end
  213.    if (ff.2='R')&(f.5='') then do
  214.       say 'Rexx search specified but no command name f.5 present'
  215.       rv=0
  216.       end
  217.    if (ff.7='Y')&(f.6='') then do
  218.       say 'Copy to folder flag specified but no folder f.6 present'
  219.       rv=0
  220.       end
  221.    if (ff.8='Y')&(f.7='') then do
  222.       say 'Autoreply flag specified but no autoreply template f.7'
  223.       rv=0
  224.       end
  225.    if (ff.12='Y')&(f.10='') then do
  226.       say 'Link to rexx on match flag specified but no cmd file f.10'
  227.       rv=0
  228.       end
  229.    if pos(ff.1,'IOBSTDF')=0 then do
  230.       say 'filter type flag invalid value'
  231.       rv=0
  232.       end
  233.    if pos(ff.2,'FRPS')=0 then do
  234.       say 'search type flag invalid value'
  235.       rv=0
  236.       end
  237.    if pos(ff.3,'NAM')=0 then do
  238.       say 'match type flag invalid value'
  239.       rv=0
  240.       end
  241.    if pos(ff.13,'YNA')=0 then do
  242.       say 'Disposition is delete flag invalid value'
  243.       rv=0
  244.       end
  245.    do i=4 to 9
  246.       if pos(ff.i,'YN')=0 then do
  247.          say 'flag' i 'invalid value; not Y or N'
  248.          rv=0
  249.          end
  250.       end /* 4 to 9 */
  251.    if pos(ff.10,'YNV')=0 then do
  252.          say 'flag 10 invalid value; not Y N or V'
  253.          rv=0
  254.          end
  255.    do i=11 to 12
  256.       if pos(ff.i,'YN')=0 then do
  257.          say 'flag' i 'invalid value; not Y or N'
  258.          rv=0
  259.          end
  260.       end /* 11 to 12 */
  261.    return rv
  262.  
  263. writeit:
  264.    outline=''
  265.    do i=1 to 12 
  266.       outline=outline||f.i||fieldsep
  267.       end
  268.    do i=1 to 14
  269.       outline=outline||ff.i
  270.       end
  271.    call lineout outfile,outline
  272.    return
  273.  
  274. readndx: procedure expose fldnam. flddir. 
  275. /* reads in the folders.ndx file and sets 2 arrays for lookup */
  276.  
  277. infile = 'folders.ndx'  /* same directory for a 2ndary acct */
  278. if lines(infile) = 0 then do
  279.    infile='mail\folders.ndx'  /* look in mail if default acct */
  280.    if lines(infile)=0 then do
  281.       say "can't find folders.ndx or mail\folders.ndx"
  282.       exit
  283.       end
  284.    end
  285. call lineout(infile)   /* close file */
  286. which = ''
  287. lineno=0
  288.  
  289. do while lines(infile)
  290.    line = linein(infile)
  291.    lineno=lineno+1
  292.    parse var line name '' tab '' folder '' rest
  293.    fldnam.lineno=name
  294.    flddir.lineno=folder
  295.    end
  296. fldnam.0=lineno
  297. return  /* readndx */
  298.  
  299. folderfix:
  300. /* we have an f6 line parsed out.  value is a folder name */
  301. /* let's see if it exists locally; if so we will set value */
  302. /* to the folder directory on this system for which the name matches. */
  303. /* if no match, get a folder to use; ask whether for once */
  304. /* or all subsequent cases of no match */
  305. /* we are working on filter number filtno */
  306. hit=0
  307. search=translate(value)  /* will use case-insensitive match */
  308. do jj=1 to fldnam.0
  309.   if search=translate(fldnam.jj) then do
  310.      hit=1
  311.      return flddir.jj
  312.      end
  313.    if hit=1 then leave
  314.    end  /* loop through tables */
  315. if hit=1 then return
  316. if folderask<>'' then do
  317.    say 'filter' filtno 'specified folder name' value
  318.    say 'using fallback folder' folderask fallbackname
  319.    return folderask
  320.    end
  321. /* we need to ask for the fallback folder value */
  322. say 'filter ' filtno 'specifies folder name' value
  323. say 'which does not match any of your folder names'
  324. say 'pick a folder to use for this filter'
  325. done=0
  326. do jk=1 to fldnam.0
  327.    say jk fldnam.jk flddir.jk
  328.    if jk=fldnam.0 then do
  329.       done=1
  330.       end
  331.    if  done | (jk//15)=0 then do
  332.        say 'enter a number or press enter to see more choices'
  333.        pull xxx
  334.        if xxx<>'' then do
  335.           folderans=flddir.xxx
  336.       fallbackname=fldnam.xxx
  337.       say 'Do you want to use this folder for any subsequent mismatches?'
  338.       do until pos(xxy,'YN')>0
  339.          say 'Enter Y[es] or N[o]'
  340.          pull xxx
  341.          xxy=translate(substr(xxx,1))
  342.          end
  343.       if xxy='Y' then  folderask=folderans
  344.       return folderans
  345.       end
  346.        end
  347.    end jk
  348. if folderask='' then do
  349.    say '07'X 'you must specify a folder; try again'
  350.    return ''
  351.    end
  352. /* end folderfix */
  353.  
  354.  
  355. pathsep: procedure
  356.    parse arg inarg
  357.    z=1
  358.    do until z=0
  359.       z=pos('\',inarg)
  360.       if z>0 then inarg=left(inarg,z-1)||'/'||substr(inarg,z+1)
  361.       end
  362.    return inarg
  363.  
  364. notready:
  365. say which " file error"
  366. exit
  367.