/* * fgets * This function is slightly different from the one of the same name * in the BDS C Standard library. Here as in the Version 7 U**X Library * the size parameter specifies the maximum size of the string to help * prevent buffer overflow. The maximum size for buffers on tty devices * is limited to MAXLINE because of the limitations of the CP/M. * Last Edit 7/1/83 */ char * fgets(s,size,stream) char *s; int *size; FILE *stream; { int count, c; char *cptr; count = size; if (isatty(stream)) { if (count>MAXLINE) count = MAXLINE; } cptr = s; if ((c = fgetc(stream)) == CPMEOF || c == EOF) return NULL; do { if ((*cptr++ = c) == '\n') { if (cptr>s+1 && *(cptr-2) == '\r') *(--cptr - 1) = '\n'; break; } } while (count-- && (c=fgetc(stream)) != EOF && c != CPMEOF) ; if (c == CPMEOF) ungetc(c,stream); /* push back control-Z */ *cptr = '\0'; return s; } /* * fputs * This is essentially the same as the function in the BDS C Standard * Library. It conforms exactly to the function of the same name in * the Version 7 U**X Standard C Library. * Last Edit 7/1/83 */ void fputs(s,stream) char *s; FILE *stream; { char c; while (c = *s++) { if (c == '\n') fputc('\r',stream); fputc(c,stream); } return ; } /* * puts * This writes the specified string on standard output terminated * with a newline character. It is slightly different from the * function in the BDS C Standard Library for the sake of compatibility * Last Edit 7/1/83 */ void puts(s) char *s; { char c; while (c = *s++) { if (c == '\n') fputc('\r',stdout); fputc(c,stdout); } fputc('\n',stdout); return ; }