home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / CLIB / FL_FUNC.C next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.1 KB  |  133 lines

  1. /*********************
  2.  *
  3.  *  fl_func.c - file functions.
  4.  *
  5.  *  Purpose: This file contains the file functions used in most C programs.
  6.  *
  7.  *  Blackstar C Function Library
  8.  *  (c) Copyright 1985,1989 Sterling Castle Software
  9.  *
  10.  *******/
  11.  
  12. #include "blackstr.h"
  13. #include "kb_head.h"
  14.  
  15.  
  16. /********
  17.  *
  18.  *   fl_getl(buff,fp) - get a line from a file
  19.  *
  20.  **/
  21.  
  22. int fl_getl(char *buff, FILE *fp)
  23. {
  24.     int i,n = 0;
  25.  
  26.     while (((i=fgetc(fp)) != NEWLINE) && (n<MAX_LN)) {
  27.     if((i==EOF)||(i==0x1a))
  28.         return(EOF);
  29.     else if(i!=CR)
  30.         buff[n++]=(char)i;
  31.     }
  32.     buff[n] = NEWLINE;  /* add newline to it */
  33.     buff[n+1] = NUL;
  34.     return(n);
  35. }
  36.  
  37.  
  38. /********
  39.  *
  40.  *   fl_getln(buff,fp) - get a line and terminate with null only
  41.  *
  42.  **/
  43.  
  44. int fl_getln(char *buff, FILE *fp)
  45. {
  46.     short int i;
  47.  
  48.     i = fl_getl(buff,fp);
  49.     buff[i] = NUL;
  50.     return(i);
  51. }
  52.  
  53.  
  54. /********
  55.  *
  56.  *   fl_putl(buff,fp) - put a line to a text file
  57.  *
  58.  **/
  59.  
  60. int fl_putl(char *buff, FILE *fp)
  61. {
  62.     int n = 0;
  63.  
  64.     while((*buff!=NEWLINE) && (n<MAX_LN)) {
  65.     fputc(*buff++,fp);
  66.     ++n;
  67.     }
  68.     fputc(CR,fp);           /* now append carriage ret and line feed */
  69.     fputc(NEWLINE,fp);
  70.     return(n);
  71. }
  72.  
  73.  
  74. /********
  75.  *
  76.  *   fl_getvr(buff,fp) - get variable record
  77.  *
  78.  **/
  79.  
  80. int fl_getvr(char *buff, FILE *fp)
  81. {
  82.     int nc = fgetc(fp);   /* get # chars */
  83.  
  84.     return(fl_getr(buff,fp,nc-1));  /* use record get */
  85. }
  86.  
  87.  
  88. /********
  89.  *
  90.  *   fl_getr(buff,fp,len) - get fixed length record
  91.  *
  92.  **/
  93.  
  94. int fl_getr(char *buff, FILE *fp, int len)
  95. {
  96.     int i = len;
  97.  
  98.     while(( ((*buff=fgetc(fp))!=EOF)||(!feof(fp)) ) && (--i))
  99.     buff++;
  100.     return (i? EOF:len);        /* return chars read or EOF */
  101. }
  102.  
  103.  
  104. /********
  105.  *
  106.  *   fl_putr(buff,fp,len) - put record of length len
  107.  *
  108.  **/
  109.  
  110. int fl_putr(char *buff, FILE *fp, int len)
  111. {
  112.    int i=len;
  113.  
  114.    while(i--) {
  115.        fputc(*buff++,fp);
  116.        --len;
  117.    }
  118.    return(len);
  119. }
  120.  
  121.  
  122. /********
  123.  *
  124.  *   fl_putvr(buff,fp) - put variable length record to file
  125.  *
  126.  **/
  127.  
  128. int fl_putvr(char *buff, FILE *fp)
  129. {
  130.    return(fl_putr(buff,fp,*buff));
  131. }
  132.  
  133.