home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / dongrovs.zip / array_cli.cmd next >
OS/2 REXX Batch file  |  1996-10-16  |  5KB  |  169 lines

  1. /* ******************************************************************* */
  2. /* Copyright:                                                          */
  3. /*   By: Jetnick Enterprise                                            */
  4. /*       Don E. Groves, Jr.                                            */
  5. /*       6313 Cider Barrell Ctr.                                       */
  6. /*       Centreville, VA 22020                                         */
  7. /*   Contact Information:                                              */
  8. /*     E-mail: jetnick@erols.com                                       */
  9. /*        CIS: 71310,3702                                              */
  10. /*                                                                     */
  11. /*                                                                     */
  12. /* ******************************************************************* */
  13. /*  Array_CLI.cmd */
  14. /* Command Line Interpreter class */
  15.  
  16. parse source . a2 .
  17. atRc= 0
  18. SELECT
  19.  WHEN a2 = 'FUNCTION'
  20.   THEN atRc = .ARRAY_CLI~of(ARG(1),ARG(2),ARG(3))
  21.  WHEN a2 = 'COMMAND'
  22.   THEN do
  23.     say 'used as a ' || a2
  24.     say 'Test Array_CLI'
  25.     say 'Args are: ' || ARG(1)
  26.     Argv = .ARRAY_CLI~of(ARG(1), .true, .true)
  27.     sArgv = Argv~supplier
  28.  
  29.     do while sArgv~Available
  30.       say sArgv~index || ' >' || sArgv~item || '< >' || Argv[sArgv~index]
  31.       if sArgv~item~substr(1,1) = '/'
  32.       then Argv~remove(sArgv~index)
  33.       sArgv~next
  34.     end
  35.     if Argv~first \= .nil
  36.     then say  "Argv's first item is >" || Argv~AT(Argv~first) || "<"
  37.  
  38.     Argv = Argv~makearray
  39.     sArgv = Argv~supplier
  40.     do while sArgv~Available
  41.       say sArgv~index || ' >' || sArgv~item || '< >' || Argv[sArgv~index]
  42.       sArgv~next
  43.     end
  44.   end
  45.  WHEN a2 = 'SUBROUTINE'
  46.   THEN nop
  47.  OTHERWISE
  48.    nop
  49. end
  50. return atRc
  51.  
  52. ::class ARRAY_single subclass list
  53. ::method of class
  54.   use arg args
  55.   data = .Array_single~new
  56.   DO WHILE args \= ''
  57.     data~insert(args~left(1))
  58.     args= args~substr(2)
  59.   end
  60. return data
  61.  
  62. ::class ARRAY_CLI subclass Array public
  63. ::method of class
  64.   args = .ARRAY_single~of(ARG(1)~strip)~supplier
  65.   savequotes = (ARG(2) = '1')
  66.   nilargs = (ARG(3) = '1')
  67.   data = Self~new
  68.   single_quote= "'"
  69.   double_quote= '"'
  70.   index = 1
  71.   save = .false
  72.   targv = ''
  73.   quote_state = .nil
  74.   devider = .nil
  75.   endarg = .false
  76.   DO WHILE args~available
  77.     c = args~item
  78.     args~next
  79.     Select
  80.      when c == quote_state
  81.      then do
  82.        save = .true
  83.        IF args~available  /* Handle the case of Two Quotes in a row. */
  84.        THEN do
  85.          if args~item == c
  86.          then do
  87.            targv= c~insert(targv)
  88.            args~next
  89.            IF savequotes
  90.            THEN targv= c~insert(targv)
  91.            save = .false
  92.          end
  93.        end
  94.        if save
  95.        then do
  96.          IF savequotes
  97.          then targv= c~insert(targv)
  98.        end
  99.      end
  100.      /*  Are we in Quote State if so save the character */
  101.      when quote_state \= .nil then targv= c~insert(targv)
  102.      /* Is it the start of quotes state */
  103.      when double_quote = c | single_quote = c
  104.      then do
  105.        if savequotes
  106.        then targv= c~insert(targv)
  107.        quote_state = c
  108.        devider = c
  109.      end
  110.      /* if not in quotestate and not a space or comma the save */
  111.      when ' ,'~pos(c) = 0 then targv= c~insert(targv)
  112.      otherwise do
  113.        /* must be a space or a comma not within quotes */
  114.        if \ endarg
  115.        then do
  116.           save = .true
  117.           if ' ' == c
  118.           then do
  119.              if targv~length = 0
  120.              then save = .false
  121.           end
  122.           else if c \= devider
  123.           then do
  124.              if targv~length = 0
  125.              then IF \ nilargs THEN save = .false
  126.           end
  127.        end
  128.        devider = c
  129.      end
  130.     End
  131.     endarg = save
  132.     if save | \ args~available
  133.     then do
  134.       if quote_state == .nil
  135.       then targv = targv~strip
  136.       IF ( targv~length \= 0 ) | nilargs
  137.       then do
  138.         data~put(targv,index)
  139.         index= index + 1
  140.       end
  141.       targv = ''
  142.       save= .false
  143.       quote_state = .nil
  144.     end
  145.   END
  146. return data
  147.  
  148. ::class ARRAY_ARGS subclass Array public
  149. ::method of class
  150.   data = .Array_ARGS~new
  151.   index = 1
  152.   do i= 1 to ARG()
  153.     parm1 = ARG(i)
  154.     d = parm1~request('ARRAY')
  155.     if d = .nil
  156.     then do
  157.       data~put(parm1,index)
  158.       index= index + 1
  159.     end
  160.     else do
  161.       do current = 1 to d~items
  162.         data~put(d[current],index)
  163.         index= index + 1
  164.       end
  165.     end
  166.   end
  167. return data
  168.  
  169.