home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / adrstuff.zip / adrfix.cmd next >
OS/2 REXX Batch file  |  1997-01-17  |  4KB  |  120 lines

  1. /* mr2ice address utility - jt Jan 1997 proglevel */
  2. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  3. call SysLoadFuncs
  4. proglevel = 1.00
  5. say 'ADRFIX.cmd level' proglevel
  6.  
  7. arg inarg test .
  8.  
  9. if \ ((inarg=1)|(inarg=2)|(inarg=3))  then do
  10.    say "Usage is adrfix 1|2|3 [test]  This utility manipulates an MR2ICE"
  11.    say "address book to put the NAME field as part of the email address"
  12.    say "in one of the forms suggested by the RFC or in common use:"
  13.    say '1     "Joe Blow" <jb123@windy.com'
  14.    say '2     Joe Blow <jb123@windy.com'
  15.    say '3     jb123@windy.com (Joe Blow)'
  16.    say 'you must select one of these options'
  17.    say ''
  18.    say 'If an entry appears to already have a name in the email address'
  19.    say 'it is not changed.'
  20.    say ''
  21.    say 'This reads mr2i.adr as input and rewrites it (the old one is saved'
  22.    say 'as mr2iadr.bk unless the 2nd argument is test, in which case it'
  23.    say 'will read mr2i.adr and create a file named mr2inew.adr'
  24.    say 'To use:  exit mr2ice, cd to your mr2ice directory.'
  25.    say 'invoke adrfix with an argument of 1,2, or 3 '
  26.    say 'Then start mr2ice and review the entries in the address book'
  27.    exit
  28.    end
  29.  
  30. /* based on these assumptions: */
  31. /* address file entries are of the form name \ email \ flag \ tag */
  32. /* but anything after flag will be preserved if Nick adds additional fields */
  33. /* the comment field is optional, */
  34. /* begins with a ^A, and consists of 3 lines total */
  35.  
  36. adrfile = 'mr2i.adr'
  37.  
  38. signal on notready
  39. which = adrfile
  40. if lines(adrfile) = 0 then signal notready
  41. call lineout(adrfile)   /* close file */
  42. which = ''
  43.  
  44. if test <> "TEST" then do
  45.    infile = 'mr2iadr.bk'
  46.    outfile = adrfile
  47.    if stream(infile,C,QUERY EXISTS) > '' then '@del' infile '> NUL'
  48.    '@rename' outfile infile   '>NUL' 
  49.    end
  50. else do
  51.     infile = adrfile
  52.     outfile = 'mr2inew.adr'
  53.     if stream(outfile,C,QUERY EXISTS) > '' then '@del' outfile '> NUL'
  54.     end
  55.    
  56.  
  57. do while lines(infile)
  58.    line = linein(infile)
  59.    if substr(line,1,1) = '' then do
  60.       call lineout outfile,line
  61.       line = linein(infile)  /* also the next 2 lines */
  62.       call lineout outfile,line
  63.       line = linein(infile)  
  64.       call lineout outfile,line
  65.       end
  66.    else do
  67.       parse var line name '\' email '\' rest
  68.       if (check4name(email) = 1)| (name='') then outline = line
  69.          else call buildline 
  70.       call lineout outfile,outline
  71.       end
  72.     end /* processing of line */
  73. call lineout(outfile)   /* close output file */
  74. say "all done"
  75. exit
  76.  
  77. check4name: PROCEDURE
  78.     ARG  x
  79.     /* check for " < or (  */
  80.     if (pos('"',x) + pos('<',x) + pos('(',x))>0 then rv=1
  81.     else rv = 0
  82.     return rv
  83.  
  84. buildline: PROCEDURE expose inarg name email rest outline
  85.  
  86.    /* 1     "Joe Blow" <jb123@windy.com  */
  87.    /* 2     Joe Blow <jb123@windy.com    */
  88.    /* 3     jb123@windy.com (Joe Blow)   */
  89.    select
  90.        when (inarg = 1) then do 
  91.        if pos('"',name)>0 then do
  92.           newemail = email
  93.           say name email 'not processed due to " in name'
  94.           end
  95.            else newemail = '"'||name||'" <'||email||'>'
  96.        end
  97.        when (inarg = 2) then do
  98.             if (pos('.',name)+pos('!',name)+pos('@',name))>0 then do
  99.           newemail = email
  100.           say name email 'not processed due to ! @ or . in name'
  101.           end
  102.             else newemail = name||' <'||email||'>'
  103.             end
  104.        when (inarg = 3) then do 
  105.        if (pos('(',name)+pos(')',name))>0 then do
  106.           newemail = email
  107.           say name email 'not processed due to ( or ) in name'
  108.           end
  109.            else newemail = email '('||name||')'
  110.        end
  111.        otherwise ;
  112.        end
  113.  
  114.     outline = name||'\'||newemail||'\'||rest
  115.     return 
  116.  
  117. notready:
  118. say which " file error"
  119. exit
  120.