home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / shackos2.zip / makepops.cmd < prev    next >
OS/2 REXX Batch file  |  1997-05-21  |  4KB  |  119 lines

  1. /* Copyright (c)1997 Kari Jackson for InnoVal Systems Solutions, Inc. */
  2. /* To create Post Road Mailer-style *.POP files from a Hacksaw email file */
  3. PROGNAME='MakePops.Cmd'
  4. if RxFuncQuery('SysLoadFuncs') then call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  5. signal on syntax name NoREXX
  6. call SysLoadFuncs
  7. signal on syntax name Syntax
  8. signal on halt name Halt
  9. '@ECHO OFF'
  10. parse arg firstarg secondarg thirdarg
  11. if firstarg='' | pos('?',firstarg)>0 | thirdarg<>'' then do
  12.    say ""
  13.    say "Parameters:"
  14.    say "-----------"
  15.    say "1.  Source file specification:  Hacksaw's email output file."
  16.    say ""
  17.    say "2.  Target file specification:  The directory where you want the *.POP"
  18.    say "    files created.  If omitted, the current directory will be assumed."
  19.    exit
  20. end
  21. sourcefile=stream(firstarg,'c','query exists')
  22. if sourcefile='' then do
  23.    say ""
  24.    say "Could not find" firstarg"."
  25.    exit
  26. end
  27. select
  28.    when secondarg='' then directory=directory()
  29.    when length(secondarg)=3 & right(secondarg,2)=':\' then directory=secondarg
  30.    otherwise do
  31.       call sysfiletree secondarg,'dirnames.','DO'
  32.       directory=dirnames.1
  33.       if directory='DIRNAMES.1' then do
  34.          say
  35.          say secondarg "does not seem to be an existing directory."
  36.          exit
  37.       end
  38.    end
  39. end
  40. testfile=getpopname(directory,'tmp')
  41. if lineout(testfile) then do
  42.    say
  43.    say "Attempt to write to" directory "failed."
  44.    exit
  45. end
  46. else call sysfiledelete testfile
  47. do while lines(sourcefile)
  48.    line=linein(sourcefile)
  49.    select
  50.  
  51. /* the following line is for use with blamspam.cmd, and is incredibly
  52.    unlikely to ever affect anything else, but can be removed or
  53.    commented out without any effect on the rest of this program, if
  54.    it's not to be used with blamspam.cmd */
  55.  
  56.       when left(line,38)="Message killed for presence of string:" then nop
  57.  
  58. /* the following line is for Hacksaw's default separator line */
  59. /* comment it out if you uncomment the subsequent line for a Unix-style file */
  60.  
  61.       when left(line,13)="-=-=-=-=-=-= " & pos(" Message [",line)>27 & right(line,14)="] =-=-=-=-=-=-" then do
  62.  
  63. /* the following line is for a Unix-style separator line */
  64. /* uncomment it and comment the one above, if you use that separator */
  65. /* instead of Hacksaw's default one */
  66.  
  67. /*    when left(line,5)="From " then do */
  68.  
  69.          if outfile<>'OUTFILE' then call lineout outfile
  70.          outfile=getpopname(directory,'pop')
  71.       end
  72.       otherwise call lineout outfile,line
  73.    end
  74. end
  75. exit
  76. Syntax:
  77.   say 'Error' rc 'in line' sigl':' errortext(rc)
  78.   say sigl':' sourceline(sigl)
  79.   exit
  80. return
  81. Halt:
  82.    say ProgName 'interrupted by Ctrl-C, ShutDown, or closing of WorkArea.'
  83.    exit
  84. return
  85. NoREXX:
  86.    say 'Unable to load the REXXUtil functions.  Either the REXXUTIL.DLL file'
  87.    say 'is not on the LIBPATH or REXX support is not installed on this system.'
  88.    exit
  89. return
  90. /* Copyright (c)1996,1997 Kari Jackson for InnoVal Systems Solutions, Inc. */
  91. /* Subroutine to produce a *.POP-style filename */
  92. /* Returns d:\dirname\filename.ext or "error" */
  93. GetPopName:procedure
  94. parse arg directory,extension
  95. if right(directory,1)='\' then directory=substr(directory,1,length(directory)-1)
  96. if left(extension,1)='.' then extension=substr(extension,2)
  97. characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  98. parse value date("O") with . 2 year "/" month "/" day
  99. parse value time() with hour ":" minute ":" second
  100. month=substr(characters,month+1,1)
  101. day=substr(characters,day+1,1)
  102. hour=substr(characters,hour+1,1)
  103. fifth=minute%36
  104. sixth=substr(characters,minute//36+1,1)
  105. test=second//36
  106. string=year||month||day||hour||fifth||sixth
  107. do j=1 to 36
  108.    test2=(test+j)//36
  109.    if test2=0 then seventh=substr(characters,36,1)
  110.    else seventh=substr(characters,test2,1)
  111.    do i=1 to 36
  112.       tryit=string||seventh||substr(characters,i,1)
  113.       filename=directory||"\"||tryit||'.'||extension
  114.       if stream(filename,'c','query exists')='' then return filename
  115.    end
  116. end
  117. /* there have already been 1296 files created in that directory this minute */
  118. return 'error'
  119.