home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / cpyiak.zip / copy-iak.cmd next >
OS/2 REXX Batch file  |  1995-06-17  |  7KB  |  205 lines

  1. /* --------------------------------------------------------------------- */
  2. /*  REXX - START OF SCRIPT - Last modified June 17 995                   */
  3. /*                                                                       */
  4. /*  Program: Small REXX script to copy entries for SlipPM, within        */
  5. /*           TCPOS2.INI, either via command line parameters, or          */
  6. /*           Interactively.                                              */
  7. /*                                                                       */
  8. /*  Author:  Ethan Hall-Beyer                                            */
  9. /*           eahallbe@undergrad.math.uwaterloo.ca                        */
  10. /*                                                                       */
  11. /* --------------------------------------------------------------------- */
  12.  
  13.  
  14. /* take two arguments, source and target. */
  15.  
  16. parse arg source target
  17.  
  18. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  19. call SysLoadFuncs
  20.  
  21.                        
  22. say ''
  23. say ''
  24. say 'COPY-IAK ver 1.01 - Ethan Hall-Beyer, Team OS/2 Canada, June 1995'
  25. say '(Use, copy, modify, distribute as you wish!)'
  26. say ''
  27. say '    Syntax:    copy-iak [<sourceentry> <targetentry>]'
  28. say ''
  29.  
  30.  
  31. /* verify whether arguments are given */
  32. ParMode = 'true'
  33. if target = '' then do
  34.    ParMode = 'false'
  35.    if source <> '' then
  36.       say 'COPY-IAK requires two parameters. See syntax.'
  37. end
  38.  
  39.  
  40. /* Get the ETC global OS/2 environment, which is set by IAK installation */
  41. TcpipEtc = translate(value('etc',,'OS2ENVIRONMENT'))
  42. if TcpipEtc = '' then do
  43.    say 'OS/2 ETC= environment variable not defined. IAK not properly installed!'
  44.    exit 9
  45. end
  46. SourceINI = tcpipEtc || '\TCPOS2.INI'
  47.  
  48.  
  49. /* verify file exists. */
  50. '@attrib -s ' || SourceINI || ' > nul'
  51. if stream(SourceINI,'c','query exists') = '' then do
  52.    say 'Can''t find system source file ' || SourceINI || '! Exiting.'
  53.    exit 9
  54. end
  55. '@attrib +s ' || SourceINI || ' > nul'
  56.  
  57.  
  58. /* Back up original file */
  59. say '--'
  60. say 'Backing up ' || SourceINI || ' as ' || tcpipEtc || '\TCPOS2.BKP.'
  61. '@attrib -s ' || SourceINI
  62. '@copy ' || SourceINI || ' ' || tcpipEtc || '\TCPOS2.BKP >nul'
  63. '@attrib +s ' || SourceINI
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /* MAIN LOOP */
  70.  
  71. /* loop forever. Means to exit are provided in loop, user input. */
  72. do forever
  73.  
  74.    /* first do the stuff needed when there are no parameters. */
  75.    if ParMode = 'false' then do
  76.  
  77.       /* Now get a list of all the current applications in TCPOS2.INI */
  78.       rc = SysIni(SourceINI,'ALL:',CurrentIAK)
  79.       say ''
  80.       say 'Current IAK entries in ' || SourceINI || ':'
  81.       say ''
  82.  
  83.  
  84.       /* got through an display all but 'CONNECTION' and see which entry is */
  85.       /* the offset. */
  86.       Offset = 0
  87.       WhereOffset = 0
  88.       do i = 1 to CurrentIAK.0
  89.          /* test to see if not the application */
  90. /*       say 'Current iak for ' || i || ' is ' || CurrentIAK.i
  91.          say 'Offset is ' || WhereOffset
  92. */       if CurrentIAK.i <> 'CONNECTION' then do
  93.             say '   ' || i-offset || ')  ' || CurrentIAK.i
  94.          if offset <> 1 then
  95.             WhereOffset = WhereOffset + 1
  96.       end
  97.       else
  98.          offset = 1
  99.       end
  100.       say ''
  101.  
  102.  
  103.       /* Get in target name. */
  104.       do forever until IAKEntry = 'good'
  105.          say 'Copy which entry? (1 - ' || CurrentIAK.0 - offset || ', or ''quit'' to exit.)'
  106.          parse upper pull CopyChoice
  107.          if CopyChoice = 'QUIT' then
  108.             exit 0
  109.          else
  110.          if (CopyChoice < 1) | (CopyChoice > (CurrentIAK.0 - offset)) then do
  111.             IAKEntry = 'nogood'
  112.             say ' - Invalid input, try again'
  113.          end /* if */
  114.          else
  115.             IAKEntry = 'good'
  116.       end
  117.       if CopyChoice > WhereOffset then
  118.          CopyChoice = CopyChoice + Offset
  119.       say 'Choice is ' || CopyChoice
  120.  
  121.       /* Now get the name for the new entry. */
  122.       say '--'
  123.       say 'Enter name for copy of ' || CurrentIAK.CopyChoice || '.'
  124.       say 'Entry will be truncated to 10 characters. Do not included non-alphanumeric'
  125.       say 'characters (ie !, /, @, etc.)'
  126.       parse pull NewName
  127.       NewName = strip(substr(NewName,1,10))
  128.  
  129.    end /* if parmode false, get user info, etc. */
  130.  
  131.  
  132.    /* now do the step is parmode is true - verify source exists. */
  133.    if ParMode = 'true' then do
  134.       SourceEntry = source
  135.       TargetEntry = target
  136.       /* check the first key of any valid entry. */
  137.       if SysIni(SourceINI,SourceEntry,'AUTOSTART') = 'ERROR:' then do
  138.          say 'The specified source ''' || SourceEntry || ''' is invalid. Exiting.'
  139.          say ''
  140.          exit 9
  141.       end
  142.    end
  143.    else do
  144.       /* now define SourceEntry, TargetEntry for non-parmode. */
  145.       SourceEntry = CurrentIAK.CopyChoice
  146.       TargetEntry = NewName
  147.    end /* if parmode = true. */
  148.  
  149.  
  150.  
  151.    /* Now go through and and read/write all the new values. */
  152.    /* First get the keys for source entry, and trap if not 41. */
  153.    rc = SysIni(SourceINI,SourceEntry,'ALL:',SourceKey)
  154.    say '--'
  155.    say 'Copying ' || SourceKey.0 || ' entry keys...'
  156.    say ''
  157.  
  158.    /* cycle through and read/write them. */
  159.    do i = 1 to SourceKey.0
  160.       say 'Copying ' || SourceKey.i || '...'
  161.       readvalue = SysIni(SourceINI,SourceEntry,SourceKey.i)
  162.       if readvalue = 'ERROR:' then do
  163.          say 'An error occured reading key ' || SourceKey.i ||'. Exiting.'
  164.          exit 9
  165.       end
  166.       rc = SysIni(SourceINI,TargetEntry,SourceKey.i,readvalue)
  167.       if rc = 'ERROR:' then do
  168.          say 'An error occured writing key ' || SourceKey.i ||'. Exiting.'
  169.          exit 9
  170.       end
  171.  
  172.    end
  173.  
  174.    /* Now write the main CONNECTION key. */
  175.    say ''
  176.    say 'Updating CONNECTION with new entry...'
  177.    ConnectValue = SysIni(SourceINI,'CONNECTION',SourceEntry)
  178.    if ConnectValue = 'ERROR:' then do
  179.          say 'An error occured reading CONNECTION key. Exiting.'
  180.          exit 9
  181.    end
  182.    rc = SysIni(SourceINI,'CONNECTION',TargetEntry,ConnectValue)
  183.    if rc = 'ERROR:' then do
  184.       say 'An error occured writing CONNECTION key. Exiting.'
  185.       exit 9
  186.    end
  187.  
  188.  
  189.    /* add some blank space... */
  190.    say ''
  191.    say 'Done!'
  192.    say ''
  193.    say ''
  194.  
  195.    /* exit if it was via parameters. */
  196.    if ParMode = 'true' then
  197.       exit 0
  198.  
  199. end  /* do forever */
  200.  
  201.  
  202. /* --------------------------------------------------------------------- */
  203. /*  END OF SCRIPT.                                                       */
  204. /* --------------------------------------------------------------------- */
  205.