define ERROR -1 # definition for readit status /************************************************************************ * getlin -- get a line into the buffer * * * * subroutine function: * * 1.) Read a line from the most recently open file into * * the buffer buf, right justified. * * 2.) Set the pointer to the first character. * * 3.) If an end of file is encountered above, close the * * most recently opened file, and read from the next * * most recently opened file. * * 4.) upon reaching an end of file, return end of file. * * useage: * * call getlin(err) * * params: err =OK if line read properly, EOF otherwise. * * program log: * * 27jun79 original coding by GB. * * 28jun79 slight modification for clarity by MSS * * 17Dec80 modified for passing a null line back on "%" line * * and some coding changes - gb * ************************************************************************/ subroutine getlin(status) integer status #error status return include ratfor.def #useful definitions of constants and such include lineno.cmm #contains the current line number include getlin.cmm #common area holds ptr, lun, and buf(BUFSIZE) integer length #the length of line read integer readit character temp (MAXLINE) logical hack data hack /.false./ label cc_format, blank_format /*----->* The following loop just reads a line until either the * line is read properly, or it is time for an end of file. */ if (hack) if (length > 1) write (OUTLUN, cc_format) (temp(i),i=2,length) else write (OUTLUN, blank_format) cc_format format (MAXLINE a 1) ; blank_format format (' ') hack =.false. repeat { length = readit (temp, lun) # read next line lineno (lun) = lineno (lun) + 1 #increment line number. if (length == ERROR | length == EOF) { if (length == ERROR) call synerr (S_INPUT_FILE) #error reading file close (unit = lun) if (lun <= 1) { #no more files status = EOF #indicate end of file return } lun = lun - 1 } } until (length > 0) #there is something in the line if (temp (1) == '%') { #pass control cards unmodified hack = .true. ptr = INBUFSIZE - 1 # give back null line buf (ptr) = ";" } else { ptr = INBUFSIZE - length for ({ i = ptr ; j = 1 }; j <= length ;{ i = i + 1 ; j = j + 1 }) buf (i) = temp (j) # fill input buffer } buf (INBUFSIZE) = NEWLINE status = OK return end integer function readit (buf, lun) character buf (MAXLINE) integer lun integer len label inbuf_format, read_end, read_err read (lun, inbuf_format, end = read_end, err = read_err) len, buf inbuf_format format (q, MAXLINE a 1) readit = len ; return read_err readit = ERROR ; return read_end readit = EOF ; return end