home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / MNET10.ZIP / MakeNet.cmd < prev    next >
OS/2 REXX Batch file  |  1992-12-11  |  6KB  |  224 lines

  1. /* MakeNet REXX procedure to build NET.CFG */
  2.  
  3.  
  4. Ver = 'v1.01' /* Matthew Palcic, 11 Dec 92 */
  5. ProgTitle = 'MakeNet 'Ver', Copyright 1992, Matthew Palcic'
  6.  
  7. parse arg DefFileSpec
  8.  
  9. address cmd
  10. env='OS2ENVIRONMENT'                    /* Access the OS2 environment */
  11. CltDrv=value('TargetDrive',,env)        /* Gets drive letter from OS2 */
  12. if CltDrv = '' then CltDrv = 'C:'       /* If the TargetDrive environment
  13.                                            variable is empty the default
  14.                                            drive is C:                */
  15. NetCfgFile = CltDrv'\NET.CFG'
  16. RedirNull = ' 1>>NUL: 2>>NUL:'
  17.  
  18. call SetupAnsi
  19. '@ECHO OFF'; say Normal; 'CLS'
  20. Say '';Say Bold||ProgTitle||NoBold
  21.  
  22. if DefFileSpec = '' then
  23.   call TellParameters
  24.  
  25. say
  26. call ParseDefFile DefFileSpec
  27. call Cleanup
  28. say; say 'Finished generating 'NetCfgFile
  29. exit
  30.  
  31. ParseDefFile: arg DefFile
  32.   say; say 'Processing: 'DefFile
  33.   call BackupFile(NetCfgFile)
  34.   call ZapFile(NetCfgFile)
  35.   call ShowDrivers(DefFile); say
  36.   SelDrv = GetDriverNum()
  37.  
  38.   say 'Selected Driver: 'Drivers.SelDrv' [line 'DrvLine.SelDrv']'; say
  39.  
  40.   do while lines(DefFile)
  41.     DefLine = linein(DefFile)
  42.     parse value DefLine with Cmd Rest
  43.     Cmd = translate(Cmd)
  44.     select
  45.       when SubStr(DefLine,1,1) = ';' then
  46.         nop /* Comment */
  47.       when Cmd = 'DRIVER' then do
  48.         Title = Strip(Rest)
  49.         drop Port Memory Int
  50.         Done = 0
  51.         if Title = Drivers.SelDrv then
  52.           rc = CfgPut('Link Driver 'Title)
  53.         do while (Done = 0)  /* Process the indented driver lines */
  54.           ObjLine = linein(DefFile)
  55.           parse value ObjLine with Cmd Rest
  56.           Cmd = Strip(Translate(Cmd))
  57.           select
  58.             when \Lines(DefFile) then
  59.               Done = 1 /* No more lines in file */
  60.             when Length(ObjLine) = 0 then
  61.               Done = 1 /* First empty line ends driver */
  62.             otherwise
  63.               nop
  64.             end
  65.           if Title = Drivers.SelDrv then do /* This is the driver we want */
  66.             select
  67.               when SubStr(ObjLine,1,1) = ';' then
  68.                 nop /* Comment */
  69.               when Cmd = 'PORT' then do
  70.                 parse upper value Strip(Rest) with Port
  71.                 Port = ReqHexInfo('I/O Port',Port)
  72.                 if Port \= '' then rc = CfgPut('  Port 'Port)
  73.                 end
  74.               when Cmd = 'MEM' then do
  75.                 parse upper value Strip(Rest) with Memory
  76.                 Memory = ReqHexInfo('Memory Address',Memory)
  77.                 if Memory \= '' then rc = CfgPut('  Mem 'Memory)
  78.                 end
  79.               when Cmd = 'INT' then do
  80.                 parse upper value Strip(Rest) with Int
  81.                 Int = ReqHexInfo('Interrupt',Int)
  82.                 if Int \= '' then rc = CfgPut('  Int 'Int)
  83.                 end
  84.               when Cmd = 'SAY' then
  85.                 call ScrPut(Rest)
  86.               when Cmd = 'PUT' then
  87.                 call CfgPut('  'Rest)
  88.               when Cmd = 'WARN' then
  89.                 call ScrPut(BrightRed||Title': 'Rest||Normal)
  90.               /*  Add your own command like this:
  91.               when Cmd = 'MYNEWCMD' then
  92.                 DoThis
  93.               */
  94.               otherwise
  95.                 nop
  96.               end
  97.             end
  98.           end
  99.         end
  100.       when Cmd = 'SAY' then
  101.         call ScrPut(Rest)
  102.       when Cmd = 'PUT' then
  103.         call CfgPut(Rest)
  104.       when Cmd = 'WARN' then
  105.         rc = ScrPut(BrightRed||Rest||Normal)
  106.       /*  Add your own commands like this:
  107.       when Cmd = 'MYNEWCMD' then
  108.         DoThis
  109.       */
  110.       otherwise /* Unknown command */
  111.         nop
  112.       end  /* select */
  113.     end /* do */
  114.   return /* Done with ParseDefFile */
  115.  
  116. SetupAnsi:
  117.   Bold = ''
  118.   NoBold = ''
  119.   BrightRed = ''
  120.   Cyan = ''
  121.   BrightCyan = ''
  122.   Normal = NoBold
  123.   return
  124.  
  125. WipePrompt:
  126.   call charout ,'A'
  127.   return
  128.  
  129. ShowDrivers:
  130.   FileLines = 0
  131.   x = 0
  132.   parse arg DrvDef
  133.   say; say 'Drivers:'
  134.   call ResetFile(DrvDef)
  135.   do while lines(DrvDef)     /* Do until end of file     */
  136.     it = linein(DrvDef)      /* Read first line          */
  137.     FileLines = FileLines + 1
  138.     uit = translate(it)
  139.     if pos('DRIVER', uit) = 1 then do
  140.       x = x + 1
  141.       parse var uit junk DrvName
  142.       Drivers.x = DrvName
  143.       DrvLine.x = FileLines
  144.       Drivers.0 = x
  145.       DrvLine.0 = x
  146.       say '  'Bold||x||NoBold'  'DrvName
  147.       end
  148.     end
  149.   call ResetFile(DrvDef)
  150.   return
  151.  
  152. GetDriverNum:
  153.   rx = 0
  154.   do while ((rx < 1) | (rx > Drivers.0))
  155.     call charout ,'Select driver number: '
  156.     pull rx
  157.     call WipePrompt
  158.     if verify(rx,'0123456789')\=0 then
  159.       rx = Drivers.0 + 1
  160.     end
  161.   return rx
  162.  
  163. ResetFile: procedure
  164.   parse arg FileName
  165.   rc = linein(FileName,1,0)
  166.   return
  167.  
  168. TellParameters:
  169.   say; say '  Syntax:  MakeNet netfile'; say
  170.   say '  You must pass a .NET file to process.'
  171.   say '     Example: MakeNet D:\KeepSafe\Drivers.Net'
  172.   call CleanUp
  173.   exit
  174.   return
  175.  
  176. ReqHexInfo: procedure
  177.   say
  178.   Prompt = ARG(1); Contents = ARG(2)
  179.   say 'Default 'Prompt': 'Contents
  180.   UserValue = 'junk'
  181.   do until (verify(UserValue,'0123456789ABCDEF')=0) | (UserValue = '')
  182.     call charout ,'Enter new 'Prompt' or [Enter] for the default: '
  183.     pull UserValue
  184.     call WipePrompt
  185.     end
  186.   if UserValue = '' then
  187.     UserValue = Contents
  188.   do 2
  189.     call WipePrompt
  190.     end /* do */
  191.   say Prompt': 'UserValue
  192.   return UserValue
  193.  
  194. CfgPut: procedure expose NetCfgFile
  195.   Parm = ARG(1)
  196.   rc = lineout(NetCfgFile,Parm)
  197.   return rc
  198.  
  199. BackupFile: procedure expose RedirNull
  200.   Parm = ARG(1)
  201.   BackExt = '.bak'
  202.   DotPos = LastPos('.',Parm)
  203.   if DotPos = 0 then
  204.     ParmB = Parm||BackExt
  205.   else
  206.     ParmB = OverLay(BackExt,Parm,DotPos)
  207.   'copy 'parm' 'parmb||RedirNull
  208.   say; say; say Parm 'backed up to 'ParmB;
  209.   return
  210.  
  211. ZapFile: procedure expose RedirNull
  212.   Parm = ARG(1)
  213.   'del 'parm||RedirNull
  214.   return
  215.  
  216. ScrPut:
  217.   Parm = ARG(1)
  218.   say Parm
  219.   return
  220.  
  221. Cleanup:
  222.   nop
  223.   return
  224.