home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / bbs / ahatch21 / ahatch.cmd next >
OS/2 REXX Batch file  |  1992-10-16  |  14KB  |  329 lines

  1. /*    AHATCH.CMD - REXX Automatic Hatch procedure, will release uploaded     */
  2. /*                 files (via FILES.BBS) into a Tick area.                   */
  3. /*                 Version: 2.1, date: 10-16-1992                            */
  4. /*                           ┌────────────────┐                              */
  5. /*                           V                │                              */
  6. /*     Usage: AHATCH ─ area ───┬────────────┬─┴─┬───────┬─┬──────┬─┤         */
  7. /*                             ├── /Ccfg ───┤   └ drive ┘ └ path ┘           */
  8. /*                             ├── /Ttmp ───┤                                */
  9. /*                             ├── /Bfbbs ──┤                                */
  10. /*                             ├── /Ddup ───┤                                */
  11. /*                             ├── /R ──────┤                                */
  12. /*                             └── /Ffile ──┘                                */
  13. /*     where  : area    - Tick area name                                     */
  14. /*              /Ccfg   - the name and location of the Tick/Hatch config     */
  15. /*                        file default will be that of Hatch itself          */
  16. /*              /Ttmp   - the name and location of the temporary ahatch file */
  17. /*                        default will be AHATCH.TMP in the current dir      */
  18. /*              /Bfbbs  - the name of FILES.BBS, located in drive/path       */
  19. /*              /Ddup   - file containing already released filenames;        */
  20. /*                        dupcheck will not include file extension unless    */
  21. /*                        the extension contains a (sequence-)number         */
  22. /*              /R      - use the Hatch replace file function, check for     */
  23. /*                        [R:file] at te beginning of the description,       */
  24. /*                        when not used complete description is always used  */
  25. /*              /Ffile  - one file to hatch from FILES.BBS (no path)         */
  26. /*              drive   - drive where file and FILES.BBS resides (default    */
  27. /*                        current drive)                                     */
  28. /*              path    - directory path where file and FILES.BBS resides    */
  29. /*                        (default current path)                             */
  30. /*     example: AHATCH OS2NEW C:\FILE\FERNUP                                 */
  31. /*              will release all files in C:\FILE\FERNUP into area OS2NEW    */
  32. /*                                                                           */
  33. /* Author:      Marcel Stikkelman                                            */
  34. /*              PC-Square, the BBS of the IBM PCPC, the Netherlands          */
  35. /*              FidoNet node 2:512/4                                         */
  36. /*              Data +31-79-424107                                           */
  37.  
  38. ver_no    = "2.1"            /* AHATCH version number */
  39. ver_date  = "10-16-1992"     /* AHATCH version date */
  40. progname  = "AHATCH"         /* AHATCH program name for display purposes */
  41. hatchname = "HATCHP.EXE"     /* hatch program to be started for hatching */
  42. hatchopt  = "/r0"            /* hatch command line option (release now) */
  43. filebbs   = "FILES.BBS"      /* name of file-list file */
  44. confdef   = "TIC.CFG"        /* Hatch default config file */
  45. rdirfile  = "AHATCH.TMP"     /* Startup: Hatch < rdirfile instead of /d */
  46. /*rdirfile  = "" */          /* parameter, set to "" for full parameter use */
  47.  
  48. TRUE = 1==1
  49. FALSE = 1==2
  50.  
  51. PARSE ARG arg.1 arg.2 arg.3 arg.4 arg.5 arg.6 arg.7 arg.8 arg.9 .
  52. lastarg = 9
  53.  
  54. /* check command line parameters */
  55. IF arg.1 == '' | arg.1 == '-?' | arg.1 == '?' | arg.1 == '/?' | arg.1 == '-H' THEN
  56.   SIGNAL HELP
  57.  
  58. area = arg.1       /* tick area name */
  59.  
  60. /* default values */
  61. config  = confdef
  62. dupfile = ''
  63. onefile = ''
  64. path    = ''
  65. replace = FALSE
  66.  
  67. DO cnt = 2 TO lastarg while LEFT(arg.cnt,1) == '/'
  68.   cmd = TRANSLATE(LEFT(arg.cnt,2))
  69.   IF cmd == '/C' THEN             /* check if config */
  70.     config   = STRIP(SUBSTR(arg.cnt,3,LENGTH(arg.cnt)-2))
  71.   ELSE IF cmd == '/T' THEN        /* check if rdirfile */
  72.     rdirfile = STRIP(SUBSTR(arg.cnt,3,LENGTH(arg.cnt)-2))
  73.   ELSE IF cmd == '/B' THEN        /* check if filebbs */
  74.     filebbs  = STRIP(SUBSTR(arg.cnt,3,LENGTH(arg.cnt)-2))
  75.   ELSE IF cmd == '/D' THEN        /* check if one file hatch */
  76.     dupfile  = STRIP(SUBSTR(arg.cnt,3,LENGTH(arg.cnt)-2))
  77.   ELSE IF cmd == '/R' THEN        /* check if use replace option */
  78.     replace  = TRUE
  79.   ELSE IF cmd == '/F' THEN        /* check if one file hatch */
  80.     onefile  = STRIP(SUBSTR(arg.cnt,3,LENGTH(arg.cnt)-2))
  81.   ELSE
  82.   DO
  83.     SAY "-> Parse error:" arg.cnt
  84.     SIGNAL HELP
  85.   END
  86. END
  87. if cnt <= lastarg THEN
  88.   path = STRIP(arg.cnt)      /* remove blanks from path (last argument) */
  89.  
  90. /*
  91. say "area    =" area
  92. say "dupfile =" dupfile
  93. say "onefile =" onefile
  94. say "config  =" config
  95. say "path    =" path
  96. exit
  97. */
  98.  
  99. IF path == '' | RIGHT(path,1) == ':' THEN   /* add . if no path or drive */
  100.   path = path || "."
  101. IF LENGTH(path) > 0 & SUBSTR(path,LENGTH(path),1) \== '\' THEN
  102.   path = path || "\"                        /* add \ if needed */
  103.  
  104. filesbbs = path || filebbs
  105. IF STREAM(filesbbs, 'C', 'QUERY EXISTS') == '' THEN  /* check for FILES.BBS */
  106. DO
  107.   IF path == '.\' THEN
  108.     path = 'the current directory'
  109.   SAY "No" filebbs "found in" path"."
  110.   SAY progname "aborted."
  111.   EXIT 1
  112. END
  113.  
  114. IF (dupfile \== '') THEN
  115.   IF (STREAM(dupfile, 'C', 'QUERY EXISTS') == '') THEN  /* check for dupfile */
  116.   DO
  117.     SAY "No duplicate file" dupfile "found."
  118.     SAY progname "aborted."
  119.     EXIT 1
  120.   END
  121.  
  122. /* get area path of Tick area from config file */
  123. areapath = ''
  124. searchfor = TRANSLATE(area)
  125. DO WHILE areapath == '' & LINES(config)
  126.   PARSE UPPER VALUE LINEIN(config) WITH "AREA" dir tickarea .
  127.   IF tickarea == searchfor THEN
  128.     areapath = dir
  129. END
  130. IF areapath == '' THEN       /* if no path was found */
  131. DO
  132.   SAY "Tick area" area "not found in" config"."
  133.   SAY progname "aborted."
  134.   EXIT 1
  135. END
  136.  
  137. numhatched = 0
  138. SAY "Hatching into area" area":"
  139. /* scan through FILES.BBS */
  140. DO WHILE LINES(filesbbs)
  141.   inline = LINEIN(filesbbs)
  142.   /* skip comment and empty lines */
  143.   DO WHILE LINES(filesbbs) & (LEFT(inline,1) == ' ' | LEFT(inline,1) == '')
  144.     inline = LINEIN(filesbbs)
  145.   END
  146.   DO
  147.     /* get filename and description from parseline */
  148.     PARSE VAR inline filename description
  149.     filename = STRIP(filename)
  150.     /* skip empty filenames */
  151.     IF filename \== '' & (onefile == '' | TRANSLATE(onefile) == TRANSLATE(filename)) THEN
  152.     DO
  153.       /* add path to original filename */
  154.       hatchfile = path || filename
  155.       /* check if file exists in path (if not: probably hatched previously) */
  156.       IF STREAM(hatchfile, 'C', 'QUERY EXISTS') \== '' THEN
  157.       DO
  158.         /* add path to hatch (target) filename */
  159.         tofile = areapath || "\" || filename
  160.         dotpos = POS('.',filename)
  161.         IF dotpos > 0 THEN
  162.         DO
  163.           /* check if extension has sequence# in it, then do full namecheck */
  164.           dupname = ''
  165.           tpos = dotpos + 1
  166.           DO WHILE dupname = '' & tpos <= LENGTH(filename)
  167.             IF POS(SUBSTR(filename,tpos,1),"0123456789") > 0 THEN
  168.             DO
  169.               dupname  = filename
  170.               globname = dupname
  171.             END
  172.             tpos = tpos + 1
  173.           END
  174.           IF dupname = '' THEN
  175.           DO
  176.             dupname  = LEFT(filename,dotpos)
  177.             globname = dupname || "*"
  178.           END
  179.         END
  180.         ELSE
  181.         DO
  182.           dupname  = filename || "."
  183.           globname = dupname || "*"
  184.         END
  185.         globfile = areapath || "\" || globname
  186.         /* check if no duplicate filename in hatch area exists */
  187.         IF STREAM(globfile, 'C', 'QUERY EXISTS') == '' THEN
  188.         DO
  189.           /* check if no duplicate filename in dupfile exists */
  190.           found = 'N'
  191.           IF dupfile \== '' THEN
  192.           DO
  193.             searchfor = TRANSLATE(dupname)
  194.             dupline = LINEIN(dupfile,1,0)
  195.             IF searchfor == TRANSLATE(LEFT(dupline, LENGTH(searchfor))) THEN
  196.               found = 'Y'
  197.             DO WHILE LINES(dupfile) & (found == 'N')
  198.               dupline = LINEIN(dupfile)
  199.               IF searchfor == TRANSLATE(LEFT(dupline, LENGTH(searchfor))) THEN
  200.                 found = 'Y'
  201.             END
  202.           END
  203.           IF found == 'N' THEN
  204.           DO
  205.             description = STRIP(description)
  206.             /* check for replace filename */
  207.             IF replace THEN
  208.             DO
  209.               PARSE VAR description WITH '[R:' repfile ']' repdesc
  210.               IF repfile == '' THEN
  211.                 PARSE VAR description WITH '[r:' repfile ']' repdesc
  212.               IF repfile \== '' THEN
  213.               DO
  214.                 repfile = STRIP(repfile)
  215.                 description = STRIP(repdesc)
  216.               END
  217.               ELSE
  218.                 repfile = filename
  219.             END
  220.             ELSE
  221.               repfile = filename
  222.             /* skip file entries with no descriptions */
  223.             IF description \== '' THEN
  224.             DO
  225.               /* copy file to be hatched */
  226.               "@COPY" hatchfile tofile "> NUL:"
  227.               /* hatch /o<no input asked> /r<release now> /f<filename> /x<repfile> /d<desr> */
  228.               /* pity hatch isn't silent (I don't show off while running) */
  229.               IF rdirfile == '' THEN
  230.                 "@"hatchname hatchopt "/c"config "/a"area "/f"filename "/x"repfile "/d"description "> NUL:"
  231.               ELSE
  232.               DO
  233.                 /* delete (and be sure) rdirfile */
  234.                 "@IF EXIST" rdirfile "DEL" rdirfile "> NUL:"
  235.                 IF STREAM(rdirfile, 'C', 'QUERY EXISTS') == '' THEN
  236.                 DO
  237.                   /* write description into rdirfile */
  238.                   IF LINEOUT(rdirfile, STRIP(LEFT(description,255))) \== '' THEN
  239.                   DO
  240.                     IF STREAM(rdirfile, 'C', 'CLOSE') == 'READY:' THEN
  241.                       "@"hatchname hatchopt "/c"config "/a"area "/f"filename "/x"repfile "<" rdirfile "> NUL:"
  242.                     ELSE
  243.                       rc = 999
  244.                   END
  245.                   ELSE
  246.                     rc = 999
  247.                 END
  248.                 ELSE
  249.                   rc = 999
  250.               END
  251.               IF rc == 0 THEN    /* check errorlevel of hatch */
  252.               DO    /* delete orignal file from upload area */
  253.                 "@IF EXIST" tofile "DEL" hatchfile "> NUL:"
  254.                 SAY filename
  255.                 numhatched = numhatched + 1
  256.               END
  257.               ELSE
  258.               DO                 /* report hatch error */
  259.                 IF rc == 1 THEN
  260.                   hatcherror = "Error reading a file"
  261.                 ELSE IF rc == 2 THEN
  262.                   hatcherror = "Error writing a file"
  263.                 ELSE IF rc == 3 THEN
  264.                   hatcherror = "Out of Memory"
  265.                 ELSE IF rc == 4 THEN
  266.                   hatcherror = "Invalid CFG file"
  267.                 ELSE IF rc == 5 THEN
  268.                   hatcherror = "Invalid PATH or filespec"
  269.                 ELSE IF rc == 6 THEN
  270.                   hatcherror = "Processing Error"
  271.                 ELSE
  272.                   hatcherror = "errorlevel" rc
  273.                 IF rc == 999 THEN
  274.                   SAY "Error accessing" rdirfile "for hatching description of" filename"."
  275.                 ELSE
  276.                   SAY "Hatch" '"'hatcherror'"' "while hatching" filename "into area" area"."
  277.                 /* restore situtation by deleting hatchfile (so the
  278.                    file will be hatched again next time if possible) */
  279.                 "@IF EXIST" hatchfile "DEL" tofile "> NUL:"
  280.               END
  281.             END
  282.             ELSE
  283.               SAY filename "has no description."
  284.           END
  285.           ELSE
  286.             SAY dupname"* found in" dupfile"."
  287.         END
  288.         ELSE
  289.           SAY globname "already exists in" areapath"."
  290.       END
  291.     END
  292.   END
  293. END
  294. SAY "Number of files hatched:" numhatched
  295.  
  296. IF rdirfile \== '' THEN
  297.   "@IF EXIST" rdirfile "DEL" rdirfile "> NUL:"
  298.  
  299. EXIT 0
  300.  
  301.  
  302. HELP:
  303.   SAY "   AHATCH.CMD - Automatic Hatch procedure, will release uploaded"
  304.   SAY "                files (via" filebbs") into a Tick area."
  305.   SAY "                Version:" ver_no", date:" ver_date"."
  306.   SAY "                          ┌────────────────┐"
  307.   SAY "                                          │"
  308.   SAY "    Usage: AHATCH ─ area ───┬────────────┬─┴─┬───────┬─┬──────┬─┤"
  309.   SAY "                            ├── /Ccfg ───┤   └ drive ┘ └ path ┘"
  310.   SAY "                            ├── /Ttmp ───┤"
  311.   SAY "                            ├── /Bfbbs ──┤"
  312.   SAY "                            ├── /Ddup ───┤"
  313.   SAY "                            ├── /R ──────┤"
  314.   SAY "                            └── /Ffile ──┘"
  315.   SAY "    where  : area    - Tick area name"
  316.   SAY "             /Ccfg   - the name and location of the Tick/Hatch config file"
  317.   SAY "             /Ttmp   - the name and location of the temporary ahatch file"
  318.   SAY "             /Bfbbs  - the name of FILES.BBS, located in drive/path"
  319.   SAY "             /Ddup   - dupfile containing already released filenames"
  320.   SAY "             /R      - use the Hatch replace file function, checks for"
  321.   SAY "                       [R:file] at te beginning of the description,"
  322.   SAY "                       when not used complete description is always used"
  323.   SAY "             /Ffile  - one file to hatch from" filebbs "(no path)"
  324.   SAY "             drive   - drive where file and" filebbs "resides (default"
  325.   SAY "                       current drive)"
  326.   SAY "             path    - directory path where file and" filebbs "resides"
  327.   SAY "                       (default current path)"
  328. EXIT 1
  329.