home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / install / libadd.cmd < prev    next >
Encoding:
Text File  |  1992-08-29  |  3.6 KB  |  116 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. /* Author:   Thomas J. Rogers                            */
  22. /*                                                       */
  23. /* (C) Copyright IBM Corp. 1991                          */
  24. /*********************************************************/
  25. '@echo off'
  26. trace 'o'
  27. parse arg dir file
  28.  
  29.  
  30. /****************/
  31. /* Check syntax */
  32. /****************/
  33. if dir='' then do
  34.  say 'Syntax:   LIBADD dir file'
  35.  say
  36.  say 'Purpose:  Add a specified directory to the beginning'
  37.  say '          of the LIBPATH statement of CONFIG.SYS.'
  38.  exit 2
  39. end
  40.  
  41.  
  42. /**************************************/
  43. /* Reset counters and setup variables */
  44. /**************************************/
  45. i=0
  46. LibLine=0
  47. Dirty=0
  48.  
  49.  
  50. /*****************/
  51. /* Read the file */
  52. /*****************/
  53. i=0
  54. do while lines(file)
  55.  i=i+1
  56.  stem.i = linein(file)
  57.  str=translate(strip(space(stem.i)))
  58.  if abbrev(str, 'LIBPATH ') | abbrev(str, 'LIBPATH=') then LibLine=i
  59. end
  60. call stream file, 'c', 'close'
  61. stem.0 = i
  62.  
  63. /*****************************************/
  64. /* Insert new directory if LibPath found */
  65. /*****************************************/
  66. if LibLine<>0 then do
  67.  oldstuff=strip(substr(stem.LibLine, pos('LIBPATH', translate(stem.LibLine))+8))
  68.  if left(oldstuff,1)='=' then oldstuff=strip(substr(oldstuff, 2))
  69.  pos = pos(translate(dir), translate(oldstuff))
  70.  /*********************************/
  71.  /* If not found add to beginning */
  72.  /*********************************/
  73.  if pos=0 then do
  74.    stem.LibLine='LIBPATH='dir';'oldstuff
  75.    Dirty=1
  76.  end
  77.  else
  78.  /*******************************************/
  79.  /* If found and not at beginning then move */
  80.  /*******************************************/
  81.  if pos<>1 then do
  82.    pre=left(oldstuff, pos-1)
  83.    post=substr(oldstuff, pos+length(dir))
  84.    if right(pre,1)=';' & left(post,1)=';' then post=substr(post,2)
  85.    stem.LibLine='LIBPATH='dir';'pre||post
  86.    Dirty=1
  87.  end
  88. end
  89.  
  90.  
  91. /********************************/
  92. /* Write the new file if needed */
  93. /********************************/
  94. if Dirty<>0 then do
  95.  'COPY C:\CONFIG.SYS C:\CONFIG.BAK>nul 2>&1'
  96.  if RC=0 then do
  97.    'DEL C:\CONFIG.SYS>nul 2>&1'
  98.    if RC=0 then
  99.      do i=1 to stem.0
  100.        call lineout file, stem.i
  101.      end
  102.    else
  103.      do
  104.       say 'Old CONFIG.SYS could not be updated.'
  105.       say 'The file might be READ-ONLY.'
  106.       exit 2
  107.      end
  108.  end
  109.  else do
  110.    say 'Old CONFIG.SYS could not be backed up.'
  111.    exit 2
  112.  end
  113. end
  114. call stream file, 'c', 'close'
  115. exit 0
  116.