PROCEDURE Castin(VAR asc: PACKED ARRAY [lo..hi: integer] OF char; VAR Int: integer; VAR pos: integer); EXTERNAL; {*USER* Pascal-3 procedure which converts an input string of ASCII characters in ASC to an integer INT (signed binary word) using a decimal (base 10) radix. POS specifies starting point in the string (array). Upon exit from this procedure, POS will be left pointing to the position of the terminating character or the end of the string, whichever comes first. Leading space or tab character(s) are ignored. The number will be considered negative if a leading "-" minus sign is encountered, and the number will be considered positive is a leading "+" plus sign or no sign at all is encountered. The plus or minus sign needs to preceed the first ascii digit, but can be separated from that first digit by any number of (ignored) space or tab characters. Any non-digit following the first valid digit will terminate the conversion. This includes a period (decimal point), a comma, a blank, or any other non digit. In any case, POS will be left pointing at this terminating character, so you may use it to go on to the next number. Thus you can parse strings like "34,+55,+ 45, -834,,3". Where no valid digit is encountered before the next terminator (such as the ",," in the example), a value of zero will be returned. Likewise a number like "345.344" could be parsed into two integers, the first representing the number before the decimal point, the second the number after the decimal. Remember that this routine handles arrays using the string conventions. The length of a type 0 string is determined by the 0 element of the array, and the length of a type 1 string is determined by the first null character in the string. Be careful if you use strings made up of left justified numbers with extra blank padding to the right of the number. The first blank encountered will act as the terminator. If you keep POS where it is and call CASTIN again, the remaining blanks will be read as another number and give you a zero. This is nice in that an all blank string like " " will return a value of zero. It does also mean that a string like "34 " will return a value of 34, the first time you call CASTIN, and if you do not alter POS, will return a 0, the second time you call CASTIN. Integer overflow (greater than +32767 or less than -32768) is indicated by a negative POS value. No error messages are issued on integer overflow, so caller must check POS if overflow possiblity exists. On the other hand, this also permits the caller to use this routine to validate input to insure that the ascii string represents a valid integer. }