home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / unix / macps_pr.hqx / macaux.c next >
Encoding:
C/C++ Source or Header  |  1988-09-22  |  1.4 KB  |  66 lines

  1. /*
  2.  * Copyright (c) 1988, The Trustees of the University of California.
  3.  * Edward Moy, Workstation Software Support Group, Workstation Support Serices,
  4.  * Information Systems and Technology.
  5.  *
  6.  * Permission is granted to any individual or institution to use, copy,
  7.  * or redistribute this software so long as it is not sold for profit,
  8.  * provided that this notice and the original copyright notices are
  9.  * retained.  The University of California makes no representations about the
  10.  * suitability of this software for any purpose.  It is provided "as is"
  11.  * without express or implied warranty.
  12.  */
  13.  
  14. #ifndef lint
  15. static char *SCCSid = "@(#)macaux.c    1.1 9/19/88";
  16. #endif lint
  17.  
  18. #include <ctype.h>
  19. #include <stdio.h>
  20.  
  21. char *Fgets(b, n, fp)
  22. char *b;
  23. register int n;
  24. register FILE *fp;
  25. {
  26.     register int c;
  27.     register char *cp = b;
  28.  
  29.     while(--n > 0) {
  30.         if((c = getc(fp)) == EOF) {
  31.             if(cp > b)
  32.                 break;
  33.             else
  34.                 return(NULL);
  35.         }
  36.         if(isascii(c) && !isprint(c)) {
  37.             if(c == '\n' || c == '\r') {
  38.                 *cp++ = '\n';
  39.                 *cp = 0;
  40.                 return(b);
  41.             } else if(c == 0)
  42.                 c = 0200;
  43.         }
  44.         *cp++ = c;
  45.     }
  46.     *cp = 0;
  47.     return(b);
  48. }
  49.  
  50. Fputs(b, fp)
  51. register char *b;
  52. register FILE *fp;
  53. {
  54.     while(*b) {
  55.         if(*b & 0200) {
  56.             if((*b & 0177) == 0)
  57.                 *b = 0;
  58.             fprintf(fp, "\\%03o", *b);
  59.         } else if(!isprint(*b) && *b != '\n' && *b != '\t')
  60.             fprintf(fp, "\\%03o", *b);
  61.         else
  62.             putc(*b, fp);
  63.         b++;
  64.     }
  65. }
  66.