From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/fio/getlline.x | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sys/fio/getlline.x (limited to 'sys/fio/getlline.x') diff --git a/sys/fio/getlline.x b/sys/fio/getlline.x new file mode 100644 index 00000000..e8e25d77 --- /dev/null +++ b/sys/fio/getlline.x @@ -0,0 +1,42 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +# GETLLINE -- Get a logical line of text, i.e., an arbitrarily long line +# possibly broken up into multiple segments of size SZ_LINE. Accumulation +# stops when the indicated number of chars have been read, or newline is +# detected. MAXCH must be at least SZ_LINE characters greater than the +# longest line to be read. + +int procedure getlline (fd, obuf, maxch) + +int fd #I input file +char obuf[ARB] #O output buffer +int maxch #I max chars out, >= SZ_LINE + +int op, status +int getline() +errchk getline + +begin + op = 1 + + while (maxch - op + 1 >= SZ_LINE) { + # Get next physical line from the file. + status = getline (fd, obuf[op]) + if (status == EOF) { + if (op == 1) + return (EOF) + else + return (op - 1) + } else + op = op + status + + # If the last physical line read ends in a newline we are done. + # If no newline we get another line, thereby reconstructing long + # lines broken by the SZ_LINE limit of getline(). + + if (obuf[op-1] == '\n') + break + } + + return (op - 1) +end -- cgit