home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / chkcfg04.zip / ChkCfg.cmd
OS/2 REXX Batch file  |  2002-01-06  |  15KB  |  685 lines

  1. /* ChkCfg.Cmd: Check CONFIG.SYS semantics
  2.  
  3.     Copyright (c) 1997 Steven Levine and Associates, Inc.
  4.     All rights reserved.
  5.  
  6.     $TLIB$: $ &(#) %n - Ver %v, %f $
  7.     TLIB: $ $
  8.  
  9.     Revisions    07 Sep 97 SHL - Release
  10.                 07 Mar 98 SHL - Add arg logic
  11.                 29 Dec 98 SHL - Split ChkDir/ChkDirList logic
  12.                 05 Jan 01 SHL - Support Dir/File lists
  13.  
  14.    TBD  Add %N logic
  15.  
  16. */
  17.  
  18. signal on ERROR
  19. signal on FAILURE name Error
  20. signal on HALT
  21. signal on NOTREADY name Error
  22. signal on NOVALUE name Error
  23. signal on SYNTAX name Error
  24.  
  25. fDebug = 0
  26.  
  27. call Initialize
  28.  
  29. parse arg szInFile szRest
  30.  
  31. if szRest \= '' then do
  32.   say szRest 'unexpected'
  33.   return
  34. end  /* Do */
  35.  
  36. if szInFile == '' then
  37.   szInFile = 'F:\CONFIG.SYS'
  38.  
  39. Main:
  40.  
  41.   say 'Reading' szInFile
  42.  
  43.   /* Scan and parse */
  44.  
  45.   cLines = 0
  46.  
  47.   if stream(szInFile, 'C', 'QUERY EXISTS') = '' then do
  48.     return szInFile 'does not exist.'
  49.   end
  50.  
  51.   call stream szInFile, 'C', 'OPEN READ'
  52.  
  53.   drop szCondition
  54.  
  55.   do while lines(szInFile) \= 0
  56.  
  57.     cLines = cLines + 1
  58.  
  59.     call on NOTREADY name CatchError    /* Avoid death on missing NL */
  60.     szLine = linein(szInFile)
  61.     signal on NOTREADY name Error
  62.  
  63.     call ChkLine szLine
  64.  
  65.   end /* while lines */
  66.  
  67.   call stream szInFile, 'C', 'CLOSE'
  68.  
  69.   say 'Read' cLines 'lines'
  70.  
  71.   exit
  72.  
  73. /* end main */
  74.  
  75. /*=== ChkDir(arg1, ...): Check single directory ===*/
  76.  
  77. ChkDir: procedure
  78.  
  79.   parse arg szPath
  80.  
  81.   /* Chop trailing / */
  82.   if length(szPath) > 2 & right(szPath, 1) == '\' & right(szPath, 2) \== ':\' then
  83.       szPath = substr(szPath, 1, length(szPath) - 1)
  84.  
  85.   szOld = directory()
  86.  
  87.   say ' 'szPath
  88.  
  89.   szNew = directory(szPath)
  90.  
  91.   call directory szOld
  92.  
  93.   if szNew == '' then do
  94.     say ' * 'szPath 'is not a directory'
  95.   end
  96.  
  97.   return
  98.  
  99. /* end ChkDir */
  100.  
  101. /*=== ChkDirFile(arg1, ...): Check dir/file name list ===*/
  102.  
  103. ChkDirFile: procedure
  104.  
  105.   parse arg sz
  106.  
  107.   do while length(sz) \= 0
  108.  
  109.     i = pos(';', sz)
  110.     if i = 0 then do
  111.       szFile = sz
  112.       sz = ''
  113.     end
  114.     else do
  115.       szFile = substr(sz, 1, i - 1)
  116.       sz = substr(sz, i + 1)
  117.     end
  118.  
  119.     say ' 'szFile
  120.  
  121.     if stream(szFile, 'C', 'QUERY EXISTS') = '' then do
  122.       szOld = directory()
  123.  
  124.       szNew = directory(szFile)
  125.  
  126.       call directory szOld
  127.  
  128.       if szNew == '' then do
  129.         say ' * 'szFile 'is not a directory or file'
  130.       end
  131.     end
  132.  
  133.   end
  134.  
  135.   return
  136.  
  137. /* end ChkDirFile */
  138.  
  139. /*=== ChkDirList(arg1, ...): Check directory name list ===*/
  140.  
  141. ChkDirList: procedure
  142.  
  143.   parse arg sz
  144.  
  145.   do while length(sz) \= 0
  146.  
  147.     i = pos(';', sz)
  148.     if i = 0 then do
  149.       szPath = sz
  150.       sz = ''
  151.     end
  152.     else do
  153.       szPath = substr(sz, 1, i - 1)
  154.       sz = substr(sz, i + 1)
  155.     end
  156.  
  157.     /* Chop trailing / */
  158.     if length(szPath) > 2 & right(szPath, 1) == '\' & right(szPath, 2) \== ':\' then
  159.         szPath = substr(szPath, 1, length(szPath) - 1)
  160.     /* Chop NLS suffix */
  161.     else if length(szPath) > 3 & right(szPath, 3) == '\%N' then
  162.         szPath = substr(szPath, 1, length(szPath) - 3)
  163.  
  164.     szOld = directory()
  165.  
  166.     say ' 'szPath
  167.  
  168.     szNew = directory(szPath)
  169.  
  170.     call directory szOld
  171.  
  172.     if szNew == '' then do
  173.       say ' * 'szPath 'is not a directory'
  174.     end
  175.  
  176.   end
  177.  
  178.   return
  179.  
  180. /* end ChkDirList */
  181.  
  182. /*=== ChkFile(arg1, ...): Check file name list ===*/
  183.  
  184. ChkFile: procedure
  185.  
  186.   parse arg sz
  187.  
  188.   do while length(sz) \= 0
  189.  
  190.     i = pos(';', sz)
  191.     if i = 0 then do
  192.       szFile = sz
  193.       sz = ''
  194.     end
  195.     else do
  196.       szFile = substr(sz, 1, i - 1)
  197.       sz = substr(sz, i + 1)
  198.     end
  199.  
  200.     say ' 'szFile
  201.  
  202.     if stream(szFile, 'C', 'QUERY EXISTS') = '' then
  203.       say ' * 'szFile 'is not a file'
  204.  
  205.   end
  206.  
  207.   return
  208.  
  209. /* end ChkFile */
  210.  
  211. /*=== ChkLine: ... ===*/
  212.  
  213. ChkLine: procedure expose fDebug
  214.  
  215.   parse arg szLine
  216.  
  217.   /* Set statements containing single directory name and no semicolon */
  218.  
  219.   szDirSet = ';BA2_CATALOG_PATH' ||,
  220.              ';BA2_LOG_PATH' ||,
  221.              ';BA2_SET_PATH' ||,
  222.              ';CPE' ||,
  223.              ';CPPHELP_INI' ||,
  224.              ';CPPLOCAL' ||,
  225.              ';CPPMAIN' ||,
  226.              ';CPPWORK' ||,
  227.              ';DMIPATH' ||,
  228.              ';DSPPATH' ||,
  229.              ';DSSDIR' ||,
  230.              ';DSSPATH' ||,
  231.              ';ETC' ||,
  232.              ';GNUPLOT' ||,
  233.              ';GS_LIB' ||,
  234.              ';HOME' ||,
  235.              ';I18NDIR' ||,
  236.              ';IBMAV' ||,
  237.              ';INIT' ||,
  238.              ';IWFOPT' ||,
  239.              ';LANINSTEP' ||,
  240.              ';LOTUS_CLS' ||,
  241.              ';NETVIEW_PATH' ||,
  242.              ';OCRNOTES' ||,
  243.              ';OCTAVE_HOME' ||,
  244.              ';SMTMP' ||,
  245.              ';SNMPDIR' ||,
  246.              ';SVA_PATH' ||,
  247.              ';TEMP' ||,
  248.              ';TMP' ||,
  249.              ';TMPDIR' ||,
  250.              ';TMPS' ||,
  251.              ';'
  252.  
  253.   /* Set statements containing single directory name and optional semicolon */
  254.  
  255.   /* fixme to exist */
  256.   szDirOptSemiSet = ';' ||,
  257.                     ';'
  258.  
  259.   /* Set statements containing directory lists */
  260.  
  261.   szDirListSet = ';BA2_CATALOG_PATH' ||,
  262.                  ';BA2_LOG_PATH' ||,
  263.                  ';BA2_SET_PATH' ||,
  264.                  ';BHELP' ||,
  265.                  ';BOOKSHELF' ||,
  266.                  ';BPATH' ||,
  267.                  ';CAT_HOST_BIN_PATH' ||,
  268.                  ';CAT_HOST_SOURCE_PATH' ||,
  269.                  ';CODELPATH' ||,
  270.                  ';CPPLOCAL' ||,
  271.                  ';DPATH' ||,
  272.                  ';DSPPATH' ||,
  273.                  ';EPMPATH' ||,
  274.                  ';GLOSSARY' ||,
  275.                  ';GS_FONTPATH' ||,
  276.                  ';GS_LIB' ||,
  277.                  ';HELP' ||,
  278.                  ';I18NDIR' ||,
  279.                  ';IMNDATACL' ||,
  280.                  ';IMNDATASRV' ||,
  281.                  ';IMNNLPSCL' ||,
  282.                  ';IMNNLPSSRV' ||,
  283.                  ';IMNWORKCL' ||,
  284.                  ';IMNWORKSRV' ||,
  285.                  ';INCLUDE' ||,
  286.                  ';INFOPATH' ||,
  287.                  ';IPFC' ||,
  288.                  ';LIB' ||,
  289.                  ';LITE_LOCALES' ||,
  290.                  ';LOCPATH' ||,
  291.                  ';LPATH' ||,
  292.                  ';MMBASE' ||,
  293.                  ';NLSPATH' ||,
  294.                  ';NWDBPATH' ||,
  295.                  ';PATH' ||,
  296.                  ';PERL5LIB' ||,
  297.                  ';PGPPATH' ||,
  298.                  ';READIBM' ||,
  299.                  ';SMINCLUDE' ||,
  300.                  ';SOMBASE' ||,
  301.                  ';SOMDDIR' ||,
  302.                  ';SOMRUNTIME' ||,
  303.                  ';ULSPATH' ||,
  304.                  ';VBPATH' ||,
  305.                  ';'
  306.  
  307.   /* Set statements containing file lists */
  308.   szFileSet = ';BFILE' ||,
  309.               ';COMSPEC' ||,
  310.               ';OS2_SHELL' ||,
  311.               ';RUNWORKPLACE' ||,
  312.               ';SCFINDUTILITY' ||,
  313.               ';SOMIR' ||,
  314.               ';SYSTEM_INI' ||,
  315.               ';TERMCAP' ||,
  316.               ';TLIBCFG' ||,
  317.               ';USER_INI' ||,
  318.               ';'
  319.  
  320.   /* Set statements containing dir/file lists */
  321.   szDirFileSet = ';CLASSPATH' ||,
  322.               ';'
  323.  
  324.   iStart = FindNonWhite(szLine)         /* Skip leading */
  325.  
  326.   if iStart = 0 then
  327.     return
  328.  
  329.   szRest = substr(szLine, iStart)
  330.  
  331.   iEnd = FindDelim(szRest)              /* Find delimiter */
  332.  
  333.   if iEnd = 0 then do
  334.     szCmd = szRest
  335.     szRest = ''
  336.   end
  337.   else do
  338.     szCmd = substr(szRest, 1, iEnd - 1)
  339.     szDelim = substr(szRest, iEnd, 1)
  340.     szRest = substr(szRest, iEnd + 1)
  341.   end
  342.  
  343.   szCmd = translate(szCmd)
  344.  
  345.   if fDebug then
  346.     say 'CMD '''szCmd''''
  347.  
  348.   select
  349.   when szCmd == 'CALL'  then
  350.     nop                                 /* fixme to check */
  351.   when szCmd == 'REM'  then
  352.     nop
  353.   when szCmd == 'RUN'  then
  354.     nop                                 /* fixme to check */
  355.   when szCmd == 'BASEDEV' then do
  356.     nop                                 /* fixme to check */
  357.   end
  358.   when szCmd == 'DEVICE' then do
  359.     nop                                 /* fixme to check */
  360.   end
  361.   when szCmd == 'LIBPATH' then do
  362.     say
  363.     say 'Checking LIBPATH'
  364.     call ChkDirList szRest
  365.     nop
  366.   end
  367.   when szCmd == 'SET' then do
  368.     iEnd = FindDelim(szRest)
  369.     if iEnd = 0 then do
  370.       say 'Missing delimiter for' szLine
  371.       exit
  372.     end
  373.     szSet = substr(szRest, 1, iEnd - 1)
  374.     if fDebug then
  375.       say '-> DEBUG' ''''szSet''''
  376.     szRest = substr(szRest, iEnd)
  377.     iEnd = FindNonWhite(szRest)
  378.     if iEnd = 0 then do
  379.       say 'Missing delimiter for' szLine
  380.       exit
  381.     end
  382.     szDelim = substr(szRest, iEnd, 1)
  383.     if szDelim \== '=' then do
  384.       say 'Missing = for' szLine
  385.       exit
  386.     end
  387.     szRest = substr(szRest, iEnd + 1)
  388.     iEnd = FindNonWhite(szRest)
  389.     if iEnd = 0 then do
  390.       say 'Missing delimiter for' szLine
  391.       exit
  392.     end
  393.     szRest = substr(szRest, iEnd)
  394.     select
  395.     when pos(';'szSet';', szDirListSet) \= 0
  396.     then do
  397.       say
  398.       say 'Checking' szSet
  399.       call ChkDirList szRest
  400.     end
  401.     when pos(';'szSet';', szDirSet) \= 0
  402.     then do
  403.       say
  404.       say 'Checking' szSet
  405.       call ChkDir szRest
  406.     end
  407.     when pos(';'szSet';', szFileSet) \= 0
  408.     then do
  409.       say
  410.       say 'Checking' szSet
  411.       call ChkFile szRest
  412.     end
  413.     when pos(';'szSet';', szDirFileSet) \= 0
  414.     then do
  415.       say
  416.       say 'Checking' szSet
  417.       call ChkDirFile szRest
  418.     end
  419.     otherwise do
  420.       if fDebug then
  421.         say
  422.         say 'Skipped' szSet
  423.     end /* otherwise */
  424.     end /* select */
  425.   end
  426.   otherwise do
  427.     if fDebug then
  428.       say
  429.       say 'Skipped' szLine
  430.     nop
  431.   end /* otherwise */
  432.   end /* select */
  433.  
  434.   return
  435.  
  436. /* end ChkLine */
  437.  
  438. /*=== FindDelim(arg1, ...): Find blank, tab or = ===*/
  439.  
  440. FindDelim: procedure
  441.  
  442.   parse arg sz
  443.  
  444.   iBlank = pos(' ', sz)
  445.   iTab = pos(x2c(9), sz)
  446.   iEq = pos('=', sz)
  447.  
  448.   i = max(iBlank, iTab, iEq)
  449.   if iBlank \= 0 then
  450.     i = min(i, iBlank)
  451.   if iTab \= 0 then
  452.     i = min(i, iTab)
  453.   if iEq \= 0 then
  454.     i = min(i, iEq)
  455.  
  456.   return i
  457.  
  458. /* end FindDelim */
  459.  
  460. /*=== FindWhite(arg1, ...): Find blank, tab or = ===*/
  461.  
  462. FindWhite: procedure
  463.  
  464.   parse arg sz
  465.  
  466.   iBlank = pos(' ', sz)
  467.   iTab = pos(x2c(9), sz)
  468.  
  469.   i = max(iBlank, iTab)
  470.   if iTab \= 0 then
  471.     i = min(i, iTab)
  472.  
  473.   return i
  474.  
  475. /* end FindWhite */
  476.  
  477. /*=== FindNonWhite(arg1, ...): Findnext Non blank or tab ===*/
  478.  
  479. FindNonWhite: procedure
  480.  
  481.   parse arg sz
  482.  
  483.   do i = 1 to length(sz)
  484.     ch = substr(sz, i, 1)
  485.     if ch \= ' ' & ch \= x2c(9) then
  486.       leave
  487.   end
  488.  
  489.   if i > length(sz) then
  490.     i = 0
  491.  
  492.   return i
  493.  
  494. /* end FindNonWhite */
  495.  
  496. /*=== Help: Display help ===*/
  497.  
  498. Help:
  499.  
  500.   say 'Usage: ChkCfg arg....'
  501.  
  502.   return
  503.  
  504. /* end Help */
  505.  
  506. /*=== Usage: ... ===*/
  507.  
  508. Usage:
  509.  
  510.   parse arg szMsg
  511.  
  512.   say szMsg
  513.  
  514.   call Help
  515.  
  516.   exit 255
  517.  
  518. /* end Usage */
  519.  
  520. /*====================================================== */
  521. /*=== Common Code - Delete unused, but do not modify === */
  522. /*====================================================== */
  523.  
  524. /*=== AskYNQ(szPrompt): returns 0=No, 1=Yes, 2=Quit ===*/
  525.  
  526. AskYNQ: procedure
  527.  
  528.   parse arg sz
  529.  
  530.   if sz = '' then
  531.     sz = 'Continue'
  532.   call charout ,sz '(y/n/q) ? '
  533.   do forever
  534.     key = translate(SysGetKey('NOECHO'))
  535.     if key = 'Y' | key = 'N' then do
  536.       call charout ,key
  537.       if key = 'Y' then
  538.         x = 0
  539.       else
  540.         x = 1
  541.       leave
  542.     end
  543.     if key = 'Q' | c2x(key) = '1B' then do
  544.       say
  545.       x = 2
  546.     end
  547.   end
  548.  
  549.   return x
  550.  
  551. /* end AskYNQ */
  552.  
  553. /*=== CatchError: Catch condition for user ===*/
  554.  
  555. CatchError:
  556.  
  557.   szCondition = condition('C')
  558.   return
  559.  
  560. /* end CatchError */
  561.  
  562. /*=== Error: Trap ERROR, FAILURE etc. conditions ===*/
  563.  
  564. Error:
  565.  
  566.   /*=== Returns szCondition or Exits ===*/
  567.  
  568.   say
  569.   parse source . . szThisCmd
  570.   say condition('C') 'signaled at' SIGL 'of' szThisCmd
  571.   drop szThisCmd
  572.   say 'Source =' sourceline(SIGL)
  573.   call SysSleep 2
  574.   if condition('I') = 'CALL' then do
  575.     szCondition = condition('C')
  576.     say 'Returning'
  577.     return
  578.   end
  579.   else do
  580.     trace '?A'
  581.     say 'Exiting'
  582.     call SysSleep 2
  583.     exit 255
  584.   end
  585.  
  586. /* end Error */
  587.  
  588. /*=== Halt: Trap HALT condition ===*/
  589.  
  590. Halt:
  591.  
  592.   /*=== Returns szCondition or Exits ===*/
  593.  
  594.   say
  595.   parse source . . szThisCmd
  596.   say condition('C') 'signaled at' SIGL 'of' szThisCmd
  597.   drop szThisCmd
  598.   say 'Source = ' sourceline(SIGL)
  599.   call SysSleep 2
  600.   if condition('I') = 'CALL' then do
  601.     szCondition = condition('C')
  602.     say 'Returning'
  603.     return
  604.   end
  605.   else do
  606.    say 'Exiting'
  607.    exit
  608.   end
  609.  
  610. /* end Halt */
  611.  
  612. /*=== Initialize: Intialize globals ===*/
  613.  
  614. Initialize:
  615.  
  616. call LoadFuncs
  617.  
  618. parse source . . szThisCmd
  619.  
  620. szTmpDir = value('TMP',,'OS2ENVIRONMENT')
  621. if szTmpDir \= '' & right(szTmpDir, 1) \= ':' & right(szTmpDir, 1) \= '\' then
  622.   szTmpDir = szTmpDir'\'
  623.  
  624. return
  625.  
  626. /* end Initialize */
  627.  
  628. /*=== LoadFuncs: Load fuctions ===*/
  629.  
  630. LoadFuncs:
  631.  
  632. /* Add all Rexx functions */
  633. if RxFuncQuery('SysLoadFuncs') then do
  634.   call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  635.   if RESULT then do
  636.     say 'Cannot load SysLoadFuncs'
  637.     exit
  638.   end
  639.   call SysLoadFuncs
  640. end /* end do */
  641.  
  642. return
  643.  
  644. /* end LoadFuncs */
  645.  
  646. /*=== ReadFile2Stem(FileName, Stem): Read file into stem variable ===*/
  647.  
  648. ReadFile2Stem:
  649.  
  650.   if arg() \= 2 | \ arg(1, 'E') | \ arg(2, 'E') then do
  651.     say 'ReadFile2Stem: expected 2 arguments'
  652.     signal Error
  653.   end
  654.  
  655.   if stream(arg(1), 'C', 'QUERY EXISTS') = '' then do
  656.     return 'ReadFile2Stem:' arg(1) 'does not exist.'
  657.   end
  658.  
  659.   rf2sPath = arg(1)
  660.   call stream rf2sPath, 'C', 'OPEN READ'
  661.  
  662.   rf2sStem = arg(2)
  663.   rf2sLine = 0
  664.  
  665.   drop szCondition
  666.   do while lines(rf2sPath) \= 0
  667.     rf2sLine = rf2sLine + 1
  668.     call on NOTREADY name CatchError    /* Avoid death on missing NL */
  669.     sz = linein(rf2sPath)
  670.     signal on NOTREADY name Error
  671.     interpret rf2sStem'.'rf2sLine' = sz'
  672.     if symbol('szCondition') = 'VAR' then
  673.       leave            /* Last line missing NL */
  674.   end
  675.   interpret rf2sStem'.0 = 'rf2sLine
  676.   call stream rf2sPath, 'C', 'CLOSE'
  677.  
  678.   drop rf2sPath rf2sStem rf2sLine szCondition
  679.  
  680.   return ''                /* Say no errors */
  681.  
  682. /* end ReadFile2Stem */
  683.  
  684. /* The end */
  685.