home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / crlist.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-08  |  13KB  |  286 lines

  1. /*                                                                    */
  2. /* name:      CRFLIST.CMD                                             */
  3. /*                                                                    */
  4. /* function:  REXX script to create a file list from an image         */
  5. /*            directory tree                                          */
  6. /*                                                                    */
  7. /* usage:     CRFLIST imageDir listFile                               */
  8. /*                                                                    */
  9. /* where:     imageDir - fully qualified base directory for the       */
  10. /*                       directory tree with the images               */
  11. /*                       Def.: E:\OS2IMAGE                            */
  12. /*                                                                    */
  13. /*            listFile - name of the file for the file listing        */
  14. /*                       Def.: .\filelist.cd                          */
  15. /*                       If the file already exist, CRFLIST deletes   */
  16. /*                       it prior to do anything!                     */
  17. /*                                                                    */
  18. /*                                                                    */
  19. /*                                                                    */
  20. /* example:   CRFLIST E:\OS2IMAGE WARP4CD.LST                         */
  21. /*                                                                    */
  22. /* author:    Bernd Schemmer                                          */
  23. /*            Baeckerweg 48                                           */
  24. /*            D-60316 Frankfurt                                       */
  25. /*            Germany                                                 */
  26. /*            EMail: 100104.613@compuserve.com                        */
  27. /*                                                                    */
  28. /* history:                                                           */
  29. /*  01.12.1996 v1.00 /bs                                              */
  30. /*    initial release                                                 */
  31. /*                                                                    */
  32. /* distribution: This program is freeware.                            */
  33. /*                                                                    */
  34. /* notes:                                                             */
  35. /*   - works only with OS/2 installation CDs                          */
  36. /*   - CRFLIST assumes that all archives are packed with PACK2.EXE    */
  37. /*     and do not have an extension                                   */
  38. /*   - needs UNPACK2.EXE and RXQUEUE.EXE                              */
  39. /*                                                                    */
  40. /*                                                                    */
  41. /*                                                                    */
  42.  
  43.                         /* default values for the parameters          */
  44.   DefImgDir  = 'E:\OS2IMAGE'
  45.   DefListFile = '.\filelist.cd'
  46.  
  47.                         /* get the name of this program               */
  48.   parse source . . thisFile
  49.   progName = fileSpec( 'N', thisFile )
  50.  
  51.                         /* get the parameter                          */
  52.   parse upper arg ImgDir ListFile
  53.   if pos( '?', ImgDir ListFile ) <> 0 then
  54.   do
  55.     say progName || ' - create a filelist of an OS/2 installation CD-ROM'
  56.     say
  57.     say 'Usage: ' || progName || ' {imgDir} {listFile}'
  58.     say 'where: imgDir  = directory with the images'
  59.     say '       (def.: ' || defImgDir || ')'
  60.     say '       listFile = file for the filelist'
  61.     say '       (def.: ' || defListFile || ')'
  62.     say
  63.     exit 1
  64.   end /* if */
  65.  
  66.                         /* check the parameter                        */
  67.   if imgDir = '' then
  68.     imgDir = DefImgDir
  69.  
  70.   if ListFile = '' then
  71.     ListFile = defListFile
  72.  
  73.                         /* load REXXUTIL                              */
  74.   call rxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  75.   call SysLoadFuncs
  76.  
  77.                         /* search UNPACK.EXE                          */
  78.   unpackProg = SysSearchpath( 'PATH', 'UNPACK2.EXE' )
  79.   if unpackProg = '' then
  80.   do
  81.     say 'Error: Can not find UNPACK2.EXE!'
  82.     say 'Hint:  UNPACK2.EXE must either  in the current directory or'
  83.     say'        accessbile about the PATH variable!'
  84.     exit 255
  85.   end /* if */
  86.  
  87.                         /* search RXQUEUE.EXE                         */
  88.   rxqueueProg = SysSearchPath( 'PATH', 'RXQUEUE.EXE' )
  89.   if unpackProg = '' then
  90.   do
  91.     say 'Error: Can not find RXQUEUE.EXE!'
  92.     say 'Hint:  RXQUEUE.EXE must either  in the current directory or'
  93.     say'        accessbile about the PATH variable!'
  94.     exit 255
  95.   end /* if */
  96.  
  97.   say
  98.   say 'Creating a list of the files in the OS/2 image in the directory'
  99.   say ' ' imgDir
  100.   say 'The list is written to the file '
  101.   say ' ' ListFile
  102.   say
  103.  
  104.   '@del' ListFile '2>NUL 1>NUL'
  105.  
  106.   call LineOut ListFile , 'Filelist of the OS/2 Image in '
  107.   call LineOUt ListFile , ' ' imgDir
  108.   call LineOut ListFile
  109.  
  110.   say ' Reading the base directory structure ...'
  111.   call SysFileTree imgDir || '\*', 'baseDirs.', 'DO'
  112.  
  113.   say '  ...' baseDirs.0 'directorys found.'
  114.  
  115.   if baseDirs.0 = 0 then
  116.     say 'Warning:  Either the directory does not exist or is empty!'
  117.   else
  118.     say ' Reading the sub directorys ...'
  119.  
  120.   nLevel = 1
  121.  
  122.   do i = 1 to baseDirs.0
  123.  
  124.     call ReadDirectory baseDirs.i , nLevel
  125.  
  126.   end /* do i = 1 to baseDirs.0 */
  127.  
  128. exit
  129.  
  130.  
  131. ReadDirectory: PROCEDURE expose ListFile unpackProg rxQueueProg
  132.   parse arg curDir , nLevel
  133.  
  134.   say '  Reading the directory "' || curDir || '" ...'
  135.  
  136.   call SysFileTree curDir || '\*.*', 'subDir',  'BO'
  137.  
  138.   do i = 1 to subDir.0
  139.     curEntry = subDir.i
  140.  
  141.     if stream( curEntry, 'c', 'QUERY EXIST' ) <> '' then
  142.     do
  143.                     /* entry is a file                                */
  144.       if FileSpec( 'E', curEntry ) = '' then
  145.       do
  146.         say '   Reading the file "' || curEntry || '" ...'
  147.  
  148.         fileOK = 0
  149.  
  150.         do while queued() <> 0; parse pull; end;
  151.  
  152.         '@' || unpackProg  curEntry '/SHOW' ' | ' rxQueueProg
  153.  
  154.         do while queued() <> 0
  155.           curSubEntry = lineIn( 'QUEUE:' )
  156.           parse var curSubEntry _2Chars +2 curFileName
  157.           if _2Chars = '->' then
  158.           do
  159.             if fileOk = 0 then
  160.             do
  161.               call lineOut ListFile, copies( ' ', nLevel*2 ) || curEntry '<Archive>'
  162.               fileOK = 1
  163.             end /* if fileOK = 0 then */
  164.             call lineOut ListFile, copies( ' ',nLevel*2 ) curSubEntry
  165.           end /* if _2Chars = '->' then */
  166.         end /* do while queued() */
  167.  
  168.         if fileOk = 0 then
  169.           call lineOut ListFile, copies( ' ', nLevel*2 ) || curEntry
  170.  
  171.       end /* if fileSpec( 'E', curEntry ) = '' then */
  172.       else
  173.         call lineOut ListFile, copies( ' ', nLevel*2 ) || curEntry
  174.  
  175.     end /*  if stream( curEntry, 'c', 'QUERY EXIST' ) <> '' then */
  176.     else
  177.     do
  178.       call lineOut ListFile, copies( ' ', nLevel*2 ) || curEntry '<DIR>'
  179.                     /* entry is a directory                           */
  180.       call ReadDirectory curEntry , nLevel + 1
  181.     end /* else */
  182.   end /* do i = 1 to subdDir.0 */
  183.  
  184. return
  185.  
  186. /* ------------------------------------------------------------------ */
  187. /* function: Extended FILESPEC function                               */
  188. /*                                                                    */
  189. /* call:     FileSpec option,fileName                                 */
  190. /*                                                                    */
  191. /* where:    option                                                   */
  192. /*                                                                    */
  193. /*             - E{xtension}                                          */
  194. /*               return the extension of the file                     */
  195. /*                                                                    */
  196. /*             - B{asename}                                           */
  197. /*               returns the name of the file without extension       */
  198. /*                                                                    */
  199. /*             - H{ome]                                               */
  200. /*               returns the fully qualified path of the file         */
  201. /*               (including the drive specifier; without the trailing */
  202. /*               backslash)                                           */
  203. /*                                                                    */
  204. /*             All other values for "option" are processed by the     */
  205. /*             original FILESPEC function.                            */
  206. /*                                                                    */
  207. /*           fileName                                                 */
  208. /*             - name of the file                                     */
  209. /*                                                                    */
  210. /* returns:  if option = E{xtension}:                                 */
  211. /*             the extension of the fileName or "" if none            */
  212. /*           else                                                     */
  213. /*             if option = B{asename}:                                */
  214. /*               the name of the file without the path and extension  */
  215. /*             else                                                   */
  216. /*               the return code of the original FILESPEC function    */
  217. /*               or "SYNTAX ERROR" if called with invalid parameter   */
  218. /*                                                                    */
  219. /* note:     To call the original FILESPEC function direct use        */
  220. /*             myResult = "FILESPEC"( option, fileName )              */
  221. /*                                                                    */
  222. /* history:                                                           */
  223. /*           RXT&T v1.90 /bs                                          */
  224. /*            - added the option B{asename}                           */
  225. /*           RXT&T v2.30 /bs                                          */
  226. /*            - added the option H{ome}                               */
  227. /*                                                                    */
  228. FileSpec: PROCEDURE
  229.   parse arg option, fileName
  230.  
  231.                         /* init the return code                       */
  232.   rc = "SYNTAX ERROR"
  233.                         /* install a local error handler              */
  234.  
  235.   SIGNAL ON SYNTAX NAME FileSpecError
  236.  
  237.   fileName = strip( fileName )                               /* v2.30 */
  238.   option = translate( strip( option ) )
  239.  
  240.                         /* check the option code                      */
  241.   select
  242.  
  243.     when abbrev( "EXTENSION", option ) = 1 then
  244.     do
  245.                         /* process the new added option code          */
  246.       i = lastPos( ".", fileName )
  247.       if i > lastPos( "\", fileName ) then
  248.         rc = substr( fileName, i+1 )
  249.       else
  250.         rc = ""
  251.     end /* when */
  252.  
  253.     when abbrev( "BASENAME", option ) = 1 then               /* v1.90 */
  254.     do                                                       /* v1.90 */
  255.                         /* call the original FILESPEC function  v1.90 */
  256.                         /* to get the filename                  v1.90 */
  257.       rc = "FILESPEC"( "N", fileName )                       /* v1.90 */
  258.       i = lastpos( ".", rc )                                 /* v1.90 */
  259.       if i <> 0 then                                         /* v1.90 */
  260.         rc = substr( rc,1, i-1 )                             /* v1.90 */
  261.     end /* when */                                           /* v1.90 */
  262.  
  263.     when abbrev( "HOME", option ) = 1 then                   /* v2.30 */
  264.     do                                                       /* v2.30 */
  265.       rc = "FILESPEC"( "D", fileName ) ||,                   /* v2.30 */
  266.            "FILESPEC"( "P", fileName )                       /* v2.30 */
  267.       if right( rc,1 ) = "\" then                            /* v2.30 */
  268.         rc = dbrright( rc,1 )                                /* v2.30 */
  269.     end /* when */                                           /* v2.30 */
  270.  
  271.     otherwise
  272.     do
  273.                         /* call the original FILESPEC function        */
  274.       rc = "FILESPEC"( option, fileName )
  275.     end /* otherwise */
  276.  
  277.   end /* select */
  278.  
  279. FileSpecError:
  280.  
  281. RETURN rc
  282.  
  283.  
  284.  
  285.  
  286.