home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / src / guide / csv-norm.e < prev    next >
Text File  |  1977-12-31  |  1KB  |  43 lines

  1. /* A suitably large size for the record buffer */
  2. CONST BUFFERSIZE=512
  3.  
  4. PROC main()
  5.   DEF filehandle, status, buffer[BUFFERSIZE]:STRING, filename
  6.   filename:='datafile'
  7.   IF filehandle:=Open(filename, OLDFILE)
  8.     REPEAT
  9.       status:=ReadStr(filehandle, buffer)
  10.       /* This is the way to check ReadStr() actually read something */
  11.       IF buffer[] OR (status<>-1) THEN process_record(buffer)
  12.     UNTIL status=-1
  13.     /* If Open() succeeded then we must Close() the file */
  14.     Close(filehandle)
  15.   ELSE
  16.     WriteF('Error: Failed to open "\s"\n', filename)
  17.   ENDIF
  18. ENDPROC
  19.  
  20. PROC process_record(line)
  21.   DEF i=1, start=0, end, s
  22.   /* Show the whole line being processed */
  23.   WriteF('Processing record: "\s"\n', line)
  24.   REPEAT
  25.     /* Find the index of a comma after the start index */
  26.     end:=InStr(line, ',', start)
  27.     /* If a comma was found then terminate with a NIL */
  28.     IF end<>-1 THEN line[end]:=NIL
  29.     /* Point to the start of the field */
  30.     s:=line+start
  31.     IF s[]
  32.       /* At this point we could do something useful... */
  33.       WriteF('\t\d) "\s"\n', i, s)
  34.     ELSE
  35.       WriteF('\t\d) Empty Field\n', i)
  36.     ENDIF
  37.     /* The new start is after the end we found */
  38.     start:=end+1
  39.     INC i
  40.   /* Once a comma is not found we've finished */
  41.   UNTIL end=-1
  42. ENDPROC
  43.