SUB DISBIN (string.inp$, format.$, out.string$, delimiter$, er.msg$) ! ! This subprogram recieves a terminal format string ! eg. 123,FRED,654.7,nots ! and converts it into a binary format string of the ! form specified in FORMAT.$ ! ON ERROR GOTO 31000 ! quotechar$ = chr$(34%) ! MAP (DTOSTR) doub$ = 8% MAP (DTOSTR) doub MAP (ITOSTR) intg$ = 2% MAP (ITOSTR) intg% ! string.in$ = string.inp$ + delimiter$ string.in$ = edit$(string.in$, 8%) IF delimiter$ = " " ! strip the leading whitespace to avoid getting an extra field string.out$ = "" ! WHILE len (format.$) > 0% delim.psn% = pos (string.in$, delimiter$, 1%) quotes.psn% = pos(string.in$, quotechar$, 1%) ! IF quotes.psn% < delim.psn% & THEN next.quotes.psn% = pos(string.in$, quotechar$, quotes.psn% + 1%) & \ delim.psn% = pos(string.in$, delimiter$, next.quotes.psn%) & \ data.item$ = seg$(string.in$, 1%, quotes.psn% -1%) + seg$(string.in$, quotes.psn% + 1%, next.quotes.psn% - 1%) & + seg$(string.in$, next.quotes.psn% + 1%, delim.psn% - 1%) & \ string.in$ = right$(string.in$, delim.psn% + 1%) & ELSE data.item$ = left$(string.in$, delim.psn% - 1%) & \ string.in$ = right$ (string.in$, delim.psn% + 1) ! data.item$ = edit$ (data.item$, 8%) ! discard leading whitespace data.item$ = edit$ (data.item$, 128%) ! discard trailing whitespace string.in$ = edit$ (string.in$, 8%) ! discard lead whitespace so we can use whitespace as a terminator data.type$ = left$ (format.$, 1%) IF data.type$ = "D" & THEN GOSUB 10000 & ELSE IF data.type$ = "I" & THEN GOSUB 12000 & ELSE IF data.type$ = "S" & THEN GOSUB 13000 & ELSE er.msg$ = "Invalid data type " + & "in format string: " + & "'" + data.type$ + "'" & \ SUBEXIT ! NEXT out.string$ = string.out$ ! SUBEXIT 10000 ! Double precision convert doub = val (data.item$) format.$ = right$ (format.$, 2%) string.out$ = string.out$ + doub$ RETURN ! 12000 ! Integer convert intg% = val (data.item$) format.$ = right$ (format.$, 2%) string.out$ = string.out$ + intg$ RETURN ! 13000 ! String convert end.string.pointer% = pos (format.$, "%", 2%) str.len% = val (seg$ (format.$, 2%, end.string.pointer%-1)) data.item$ = edit$ (data.item$, 8%) ! discard leading spaces data.item$ = edit$ (data.item$, 128%) ! discard trailing spaces data.string$ = left$ ((data.item$ + space$ (str.len%)), str.len%) format.$ = right$ (format.$, end.string.pointer%+1) string.out$ = string.out$ + data.string$ RETURN ! 31000 er.msg$ = ert$(err) + " in module " + ern$ ! 32767 SUBEND