home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / install / libadd.cmd < prev    next >
Encoding:
Text File  |  1994-03-01  |  3.6 KB  |  115 lines

  1. /*********************************************************/
  2. /* LIBADD  - Add a directory entry to LIBPATH.           */
  3. /*                                                       */
  4. /* Syntax:   LIBADD dir                                  */
  5. /*                                                       */
  6. /* Purpose:  Add a specified directory to the beginning  */
  7. /*           of the LIBPATH statement of C:\CONFIG.SYS.  */
  8. /*                                                       */
  9. /*           If the specified entry is already in the    */
  10. /*           LIBPATH it will be moved to the beginning.  */
  11. /*                                                       */
  12. /*           The original CONFIG.SYS will be backed up   */
  13. /*           as C:\CONFIG.BAK.                           */
  14. /*                                                       */
  15. /* Note:     This program deliberately avoids RXUTILS    */
  16. /*           functions as the sole purpose of this prog- */
  17. /*           ram is to add the current directory entry   */
  18. /*           to the LIBPATH so that RXUTILS may be       */
  19. /*           loaded upon the next reboot.                */
  20. /*                                                       */
  21. /*                                                       */
  22. /* (C) Copyright IBM Corp. 1994                          */
  23. /*********************************************************/
  24. '@echo off'
  25. trace 'o'
  26. parse arg dir file
  27.  
  28.  
  29. /****************/
  30. /* Check syntax */
  31. /****************/
  32. if dir='' then do
  33.  say 'Syntax:   LIBADD dir file'
  34.  say
  35.  say 'Purpose:  Add a specified directory to the beginning'
  36.  say '          of the LIBPATH statement of CONFIG.SYS.'
  37.  exit 2
  38. end
  39.  
  40.  
  41. /**************************************/
  42. /* Reset counters and setup variables */
  43. /**************************************/
  44. i=0
  45. LibLine=0
  46. Dirty=0
  47.  
  48.  
  49. /*****************/
  50. /* Read the file */
  51. /*****************/
  52. i=0
  53. do while lines(file)
  54.  i=i+1
  55.  stem.i = linein(file)
  56.  str=translate(strip(space(stem.i)))
  57.  if abbrev(str, 'LIBPATH ') | abbrev(str, 'LIBPATH=') then LibLine=i
  58. end
  59. call stream file, 'c', 'close'
  60. stem.0 = i
  61.  
  62. /*****************************************/
  63. /* Insert new directory if LibPath found */
  64. /*****************************************/
  65. if LibLine<>0 then do
  66.  oldstuff=strip(substr(stem.LibLine, pos('LIBPATH', translate(stem.LibLine))+8))
  67.  if left(oldstuff,1)='=' then oldstuff=strip(substr(oldstuff, 2))
  68.  pos = pos(translate(dir), translate(oldstuff))
  69.  /*********************************/
  70.  /* If not found add to beginning */
  71.  /*********************************/
  72.  if pos=0 then do
  73.    stem.LibLine='LIBPATH='dir';'oldstuff
  74.    Dirty=1
  75.  end
  76.  else
  77.  /*******************************************/
  78.  /* If found and not at beginning then move */
  79.  /*******************************************/
  80.  if pos<>1 then do
  81.    pre=left(oldstuff, pos-1)
  82.    post=substr(oldstuff, pos+length(dir))
  83.    if right(pre,1)=';' & left(post,1)=';' then post=substr(post,2)
  84.    stem.LibLine='LIBPATH='dir';'pre||post
  85.    Dirty=1
  86.  end
  87. end
  88.  
  89.  
  90. /********************************/
  91. /* Write the new file if needed */
  92. /********************************/
  93. if Dirty<>0 then do
  94.  'COPY C:\CONFIG.SYS C:\CONFIG.BAK>nul 2>&1'
  95.  if RC=0 then do
  96.    'DEL C:\CONFIG.SYS>nul 2>&1'
  97.    if RC=0 then
  98.      do i=1 to stem.0
  99.        call lineout file, stem.i
  100.      end
  101.    else
  102.      do
  103.       say 'Old CONFIG.SYS could not be updated.'
  104.       say 'The file might be READ-ONLY.'
  105.       exit 2
  106.      end
  107.  end
  108.  else do
  109.    say 'Old CONFIG.SYS could not be backed up.'
  110.    exit 2
  111.  end
  112. end
  113. call stream file, 'c', 'close'
  114. exit 0
  115.