home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * fl_func.c - file functions.
- *
- * Purpose: This file contains the file functions used in most C programs.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include "blackstr.h"
- #include "kb_head.h"
-
-
- /********
- *
- * fl_getl(buff,fp) - get a line from a file
- *
- **/
-
- int fl_getl(char *buff, FILE *fp)
- {
- int i,n = 0;
-
- while (((i=fgetc(fp)) != NEWLINE) && (n<MAX_LN)) {
- if((i==EOF)||(i==0x1a))
- return(EOF);
- else if(i!=CR)
- buff[n++]=(char)i;
- }
- buff[n] = NEWLINE; /* add newline to it */
- buff[n+1] = NUL;
- return(n);
- }
-
-
- /********
- *
- * fl_getln(buff,fp) - get a line and terminate with null only
- *
- **/
-
- int fl_getln(char *buff, FILE *fp)
- {
- short int i;
-
- i = fl_getl(buff,fp);
- buff[i] = NUL;
- return(i);
- }
-
-
- /********
- *
- * fl_putl(buff,fp) - put a line to a text file
- *
- **/
-
- int fl_putl(char *buff, FILE *fp)
- {
- int n = 0;
-
- while((*buff!=NEWLINE) && (n<MAX_LN)) {
- fputc(*buff++,fp);
- ++n;
- }
- fputc(CR,fp); /* now append carriage ret and line feed */
- fputc(NEWLINE,fp);
- return(n);
- }
-
-
- /********
- *
- * fl_getvr(buff,fp) - get variable record
- *
- **/
-
- int fl_getvr(char *buff, FILE *fp)
- {
- int nc = fgetc(fp); /* get # chars */
-
- return(fl_getr(buff,fp,nc-1)); /* use record get */
- }
-
-
- /********
- *
- * fl_getr(buff,fp,len) - get fixed length record
- *
- **/
-
- int fl_getr(char *buff, FILE *fp, int len)
- {
- int i = len;
-
- while(( ((*buff=fgetc(fp))!=EOF)||(!feof(fp)) ) && (--i))
- buff++;
- return (i? EOF:len); /* return chars read or EOF */
- }
-
-
- /********
- *
- * fl_putr(buff,fp,len) - put record of length len
- *
- **/
-
- int fl_putr(char *buff, FILE *fp, int len)
- {
- int i=len;
-
- while(i--) {
- fputc(*buff++,fp);
- --len;
- }
- return(len);
- }
-
-
- /********
- *
- * fl_putvr(buff,fp) - put variable length record to file
- *
- **/
-
- int fl_putvr(char *buff, FILE *fp)
- {
- return(fl_putr(buff,fp,*buff));
- }
-
-