home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / filerx11.zip / PARSE.CMD < prev    next >
OS/2 REXX Batch file  |  1995-02-05  |  4KB  |  120 lines

  1. /******************************************************************
  2.  * PARSE.CMD
  3.  *
  4.  * This program calls the various REXX external functions provided in the FILEREXX DLL.
  5.  *
  6.  * Demonstrates using FileGets' parsing features to parse a file of names and
  7.  * addresses.
  8.  *******************************************************************/
  9.  
  10.  
  11. /* The FileLoadFuncs loads all the rest of the REXX functions in the FILEREXX DLL. */
  12. /* So, we don't have to make calls to RxFuncAdd to add each one of those functions. Of */
  13. /* course, in order to call FileLoadFuncs, we have to add that one. */
  14. CALL RxFuncAdd 'FileLoadFuncs', 'FILEREXX', 'FileLoadFuncs'
  15. CALL FileLoadFuncs
  16.  
  17.  
  18.  
  19. /* ================================ FilePuts ================================= */
  20. /** Use FilePuts to create the file of names/addresses. It's assumed that the first line of an entry
  21.       will be the person's name. The next line contains his street address. This could be a P.O. Box
  22.       and a street name, separated by a comma. Or, maybe there's an apartment number in there
  23.       separated from the street name with a comma. The third line contains the city/state/country/zip.
  24.       The city is assumed to be the first item on that line, and separated from the remainder of the
  25.       line with a comma. The zip is assumed to be last, and separated by a space. The state and
  26.       country are between the city and zip, and separated by spaces.
  27.  **/
  28. handle = FileOpen('c:\blort', 'w', 'on')
  29.  
  30. line.1 = "Jeff Glatt"
  31. line.2 = "6 Sycamore Drive East"
  32. line.3 = "New Hartford, NY 13413"
  33. line.4 = "" /* a blank line before the next person's address */
  34. line.5 = "John Q. Public"
  35. line.6 = "13 Elm Street, Apt. 16"
  36. line.7 = "Anytown, New York   18640"
  37. line.8 = ""
  38. line.9 = "IBM"
  39. line.10 = "OS/2 Square"
  40. line.11 = "End of the world, NY  USA  13500"
  41.  
  42. DO i=1 TO 11
  43.     err = FilePuts(handle, line.i)
  44. END
  45.  
  46. err = FileClose(handle)
  47.  
  48.  
  49. /* ========================= FileGets with parsing ======================== */
  50. handle = FileOpen('c:\blort')
  51. IF handle <> 0 THEN DO
  52.  
  53.     person=1
  54.     DO FOREVER
  55.      /* Get the next person's name. Chop up all the pieces of his name according to space separators. Make it all upper
  56.          case. */
  57.      FileGets(handle, 'tsc', ' ')
  58.  
  59.      /* No more lines? */
  60.      IF FileArg.0 = 0 THEN LEAVE
  61.  
  62.      /* Was this a blank line? If so, skip it */
  63.      IF FileArg.0 = 1 & FileArg.1 = "" THEN ITERATE
  64.  
  65.      /* Print the person's name */
  66.      SAY "Person #"person" ========================================="
  67.      SAY "Name:"
  68.      DO i = 1 to FileArg.0
  69.          SAY "Arg #"i"="FileArg.i
  70.      END
  71.  
  72.      /* Get the person's street address. Chop up all the pieces according to comma separators. Make it all upper case. */
  73.      FileGets(handle, 'tsc', ',')
  74.  
  75.      /* No more lines? */
  76.      IF FileArg.0 = 0 THEN LEAVE
  77.  
  78.      /* Print the person's street */
  79.      SAY "Street Address:"
  80.      DO i = 1 to FileArg.0
  81.          SAY "Arg #"i"="FileArg.i
  82.      END
  83.  
  84.      /* Get the person's city/state/country/zip. Chop off the state from the head of the line, according to a comma
  85.          separator. Chop off the zip from the tail of the line, according to a space. Make it all upper case. Note that
  86.          the city is FileArg.1 because we specified a rightseparator of ','.  We request step match of right separators with
  87.          no extending the last separator, so this ensures that we only chop off the street. The zip will be FileArg.2
  88.          because we specified a leftseparator of ' ', also with step match and no extension. The state/country is FileArg.3
  89.          because that's what is left of the line after we chop off the args. */
  90.      FileGets(handle, 'tscrl', ',', ' ')
  91.  
  92.      /* No more lines? */
  93.      IF FileArg.0 = 0 THEN LEAVE
  94.  
  95.      /* Print the person's city/state/country/zip */
  96.      SAY "City/State/Country/Zip:"
  97.      DO i = 1 to FileArg.0
  98.          SAY "Arg #"i"="FileArg.i
  99.      END
  100.  
  101.      /* Next person */
  102.      person = person+1
  103.     END
  104.  
  105.     /* Close the file */
  106.     err = FileClose(handle)
  107.  
  108.     /* Delete the file */
  109.     err = FileDeleteFile('c:\blort')
  110.  
  111. END
  112.  
  113. ELSE SAY "Error opening file"
  114.  
  115.  
  116. /* =============================================================================== */
  117. /* FileDropFuncs: This unloads all of the functions in the FILEREXX DLL. This is not necessary, and
  118.     we could otherwise leave it open for some other REXX script */
  119. CALL FileDropFuncs
  120.