SUB READTF (strng$, in.mode%, chnel%, curr.posit%, aray$(), delm$, feld.n%) ! .DEFINE .strg.len% = 192% MAP (INNBUF) innbuf$ = .strg.len% ! ! IN.MODE% = 1 ! This mode will read in a buffer from a terminal ! format file opened for READ on chnel%. ! the MODE% is then set to '2' to seperate fields. ! ! IN.MODE% = 2 ! This mode will seperate strng$ into its fields ! The fields are sent back in the array ARAY$(). ! aray$(0) is left blank. ! The DELM$ contains the field delimiter. ! Curr.posit% will contain the position of the ! last character in the fld.no% field. ! IF feld.n% = 0% ! THEN we find all fields in strng$ ! feld.n% is sent back as max. fields encountered ! ELSE we find all fields up to the feld.n% in strng$ ! and send them back in aray$() ! ! ! NOTE:: words enclosed in double quotes "----" ! are all written to one field. ! ie. FIELD1, FIELD2, "THIS IS, ALL FIELD 3",FIELD4 ! ! ALSO THE aray$() sent out must be dimensioned ! in the calling routine IF larger than 10 fields ! ! feld.n% = 100% IF feld.n% = 0% !...ie. get all fields. User does not know how many ! IF in.mode% = 1% & THEN LSET innbuf$ = " " & \ CALL INPUT. (chnel%, innbuf$, rec.leng%) & \ strng$ = LEFT$(innbuf$, rec.leng%) & \ in.mode% = 2% ! ! IF in.mode% = 2% & THEN feld.n% = fn.getfield%(strng$, feld.n%, delm$) ! ! SUBEXIT ! !*************************************************************** ! ! ! DEF fn.getfield% (bufer$, fld.no%, delim$) ! ! FN.GETFIELD$ returns in ary$(), the 1st fld.no%'th fields ! from bufer$ where the field seperator is delim$ ! IF delim$ does not appear in bufer$, - bufer$ is sent back ! IF delim$ = a null (""), - delim$ = a whitespace ! ie. tabs &or spaces together. ! MAP (STRLIN) buferr$ = .strg.len% MAP (STRLIN) buffr$(.strg.len%) = 1% ! IF delim$ = "" & THEN tabb$ = " " ! a tab & \ delim$ = " " ! a space & ELSE tabb$ = "|||" ! bufer$ = EDIT$(bufer$, 128%) buffr.len% = LEN(bufer$) + 1% LSET buferr$ = bufer$ + delim$ + delim$ + delim$ ! ii% = 0% curr.posit% = ii% FOR nn% = 1% TO fld.no% ! UNTIL buffr$(ii%) <> delim$ AND buffr$(ii%) <> tabb$ ii% = ii% + 1% IF ii% > buffr.len% & THEN fn.getfield% = nn% - 1% \ FNEXIT !...got all the fields ! NEXT ! strt.fld% = ii% \ in.quotes% = 0% \ end.fld% = 0% UNTIL buffr$(ii%) = delim$ OR buffr$(ii%) = tabb$ IF buffr$(ii%) = '"' & THEN ii% = ii% + 1% \ in.quotes% = -1% \ strt.fld% = ii% ! IF in.quotes% AND end.fld% = 0% & THEN UNTIL buffr$(ii%) = '"' & \ print "ERROR: Cannot find End Quotes on field ";nn%;BEL IF ii% > buffr.len% & \ FNEXIT IF ii% > buffr.len% & \ ii% = ii% + 1% & \ NEXT & \ end.fld% = ii% - 1% ! ii% = ii% + 1% IF ii% > buffr.len% !...should never ever happen BUT & THEN print "ERROR: cannot find seperator at end of bufer.";bel & \ print "buffer = ";bufer$ & \ aray$(nn%) = SEG$(buferr$, strt.fld%+1%, ii%+1%) & \ fn.getfield% = nn% \ FNEXIT ! NEXT end.fld% = ii% - 1% IF in.quotes% = 0% aray$(nn%) = SEG$(buferr$, strt.fld%+1%, end.fld%+1%) curr.posit% = end.fld%+1% NEXT nn% ! FNEND !------------------------------------------------------------ ! SUBEND