home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / AHATCH22.ZIP / AHATCH.CMD next >
OS/2 REXX Batch file  |  1992-12-22  |  17KB  |  392 lines

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