home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Backup / Backup.zip / psnsg601.zip / tapec.cmd < prev    next >
OS/2 REXX Batch file  |  1999-10-05  |  4KB  |  126 lines

  1. /* -------------------------------------------------- */
  2. /* Title:               tapec.cmd                     */
  3. /*                                                    */
  4. /* Author:              J.Cobb                        */
  5. /*                                                    */
  6. /* Change History:      11/11/1997 - Created JAC      */
  7. /*                                                    */
  8. /* Function:            Looks throuh the config.sys   */
  9. /*                      file for and adds tape support*/
  10. /* -------------------------------------------------- */
  11.  
  12.  
  13. Parse Arg bootdrv target_path
  14.  
  15. _proddmd  = 'BASEDEV=?OS2SCSI.DMD'     /* SCSI Device Manager we need */
  16. _prodsdid = 'DEVICE=?ADSMSDID.SYS'     /* SCSI tape auto detect driver */
  17. _prodtape = 'DEVICE=?ADSMTAPE.SYS'     /* SCSI tape interface */
  18. prodddmd = 'OS2SCSI.DMD'
  19. prodsdid = 'ADSMSDID.SYS'     
  20. prodtape = 'ADSMTAPE.SYS'     
  21.  
  22. /* Query the system functions */
  23. if RxFuncQuery(SysTempFileName) <> 0 then
  24.    if RxFuncAdd(SysTempFileName,Rexxutil,SysTempFileName) <> 0 then Exit
  25.  
  26. if RxFuncQuery(SysFileDelete) <> 0 then
  27.    if RxFuncAdd(SysFileDelete,Rexxutil,SysFileDelete) <> 0 then Exit
  28. Call Modify_Config
  29.  
  30. Exit
  31.  
  32. Modify_Config:Procedure expose bootdrv _proddmd _prodsdid _prodtape target_path
  33.  
  34.    in_file = bootdrv'\config.sys'
  35.    temp_file = systempfilename(bootdrv'\pssconf.???')
  36.    back_file = systempfilename(bootdrv'\config.???')
  37.    action = 'COPY' in_file back_file
  38.    action
  39.    if rc <> 0 then Return   /* not continuing without backup of config.sys */
  40.    /*  First, copy CONFIG.SYS in its entirety *except* lines that we */
  41.    /*  placed (or will place) there. If we find such lines, they are */
  42.    /*  discarded, possibly to be re-added later. */
  43.    /*  n.b. We also notice whether BASEDEV=OS2SCSI.DMD is installed. */
  44.    /*       If it isn't, the SCSI tape interface isn't applicable. */
  45.    found_dmd = 0
  46.    do i=1 by 1 while lines(in_file) > 0
  47.       raw_line = linein(in_file)
  48.       if IsTypeDMD(raw_line) then found_dmd = 1 /* found OS2SCSI.DMD */
  49.      
  50.       if \IsTypeSDID(raw_line) then
  51.          if \IsTypeTAPE(raw_line) then
  52.          do
  53.             call lineout temp_file, raw_line
  54.             iterate i
  55.          end
  56.    end
  57.    call lineout in_file /* Close file */
  58.  
  59.    /* Install the SCSI tape device interface. */
  60.    if found_dmd = 1 then do
  61.       parse var _prodtape '?' device
  62.       device = 'DEVICE='target_path'\'device
  63.       call lineout temp_file, device
  64.  
  65.       parse var _prodsdid '?' device
  66.       device = 'DEVICE='target_path'\'device
  67.       call lineout temp_file, device
  68.    end
  69.  
  70.  
  71.    /* Close our temporary copy of CONFIG.SYS. */
  72.    call lineout temp_file
  73.  
  74.  
  75.    /* Delete old config.sys. */
  76. /*   call sysfiledelete in_file */
  77.  
  78.    /* Copy temp_file to give new config.sys. */
  79.    action = 'COPY' temp_file in_file
  80.    action
  81.    if rc <> 0 then do
  82.       action = 'COPY' back_file in_file
  83.       action
  84.    end
  85.  
  86.    call sysfiledelete temp_file
  87.  
  88. return
  89.  
  90. IsTypeDMD: procedure expose _proddmd
  91. /* Local subroutine to detect corequisite OS2SCSI.DMD statement. */
  92.    parse upper arg string
  93.    return Match_HeadTail(string, _proddmd)
  94.  
  95. IsTypeSDID: procedure expose _prodsdid
  96. /* Local subroutine to detect our scsi tape identifier driver. */
  97.    parse upper arg string
  98.    return Match_HeadTail(string, _prodsdid)
  99.  
  100. IsTypeTAPE: procedure expose _prodtape
  101. /* Local subroutine to detect our scsi tape device driver. */
  102.    parse upper arg string
  103.    return Match_HeadTail(string, _prodtape)
  104.  
  105. Match_HeadTail: procedure
  106. /* Search "string" to see if "head" is the leading substring and */
  107. /* "tail" is the ending substring.  Case insensitive, ignores */
  108. /* comment lines.  Returns 0 or 1. */
  109.    parse upper arg string, head '?' tail
  110.    parse var string token .
  111.    if token = 'REM' then               /* Comment line? */
  112.       return 0
  113.    string = space(string, 0)           /* Remove all blanks. */
  114.    n=length(head)
  115.    if n > length(string) then          /* More "head" than "string"? */
  116.       return 0
  117.    if left(string, n) \= head then
  118.       return 0
  119.    n=length(tail)
  120.    if n > length(string) then          /* More "tail" than "string"? */
  121.       return 0
  122.    if right(string, n) \= tail then
  123.       return 0
  124.    return 1
  125.  
  126.