home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libstdio / stdiock.c < prev   
C/C++ Source or Header  |  1989-06-27  |  2KB  |  114 lines

  1. /*
  2.  * If this compiles and runs successfully, your stdio is very probably
  3.  * compatible with stdio.fast, except on SunOS 4.x, for unknown reasons.
  4.  * Buffers by default; -u stops buffering.
  5.  * Writes on stdout by default; -i read from stdin.
  6.  */
  7. #include <stdio.h>
  8.  
  9. FILE *fp = stdout;
  10.  
  11. main(argc, argv)
  12. char **argv;
  13. {
  14.     int wantbuf = 1, usestdin = 0;
  15.     char line[1024];
  16.     static char buf[BUFSIZ];
  17.     static char buggered[] =
  18. "Your stdio appears to be buggered: fwrite of 4 bytes doesn't yield 4.\n";
  19.  
  20.     for (; argc > 1; argv++, argc--) {
  21.         if (strcmp(argv[1], "-u") == 0)
  22.             wantbuf = 0;
  23.         if (strcmp(argv[1], "-i") == 0) {
  24.             usestdin = 1;
  25.             fp = stdin;
  26.         }
  27.     }
  28.  
  29.     evalfile("start");
  30.  
  31.     if (wantbuf) {
  32.         setbuf(fp, buf);
  33.         evalfile("setbuf(buf)");
  34.     } else {
  35.         setbuf(fp, (char *)NULL);
  36.         evalfile("setbuf(0)");
  37.     }
  38.  
  39.     if (usestdin) {
  40.         (void) fgets(line, sizeof line, fp);
  41.         evalfile("fgets");
  42.     } else {
  43.         if (fwrite("your", 1, 4, fp) != 4)
  44.             (void) write(1, buggered, strlen(buggered));
  45.         evalfile("fwrite");
  46.  
  47.         (void) fputs(" stdio seems to be ", stdout);
  48.         evalfile("fputs");
  49.     }
  50.  
  51.     if (wantbuf && fp->_ptr == NULL)
  52.         (void) fputs("incompatible (_ptr) ", stdout);
  53.     else
  54.         (void) fputs("compatible (_ptr) ", stdout);
  55.     if (fp->_cnt >= 0 && fp->_cnt <= BUFSIZ)
  56.         (void) fputs("compatible (_cnt)", stdout);
  57.     else
  58.         (void) fputs("incompatible (_cnt)", stdout);
  59.     evalfile("test");
  60.  
  61.     (void) fputs(" with stdio.fast\n", stdout);
  62.     evalfile("fputs");
  63.  
  64.     (void) fflush(fp);
  65.     (void) fflush(stdout);
  66.     evalfile("fflush");
  67.  
  68.     exit(0);
  69. }
  70.  
  71. /* write on stdout with using stdio. ugh */
  72. evalfile(s)
  73. char *s;
  74. {
  75.     static char ptr[] = "ptr ";
  76.     static char cnt[] = " cnt ";
  77.     static char *bufend = NULL;
  78.     static char buggered[] =
  79. "Your stdio appears to be buggered: _ptr+_cnt does not yield a constant.\n";
  80.  
  81.     if (fp->_ptr != NULL && fp->_cnt != 0) {
  82.         if (bufend == NULL)
  83.             bufend = (char *)fp->_ptr + fp->_cnt;
  84.         if (bufend != (char *)fp->_ptr + fp->_cnt)
  85.             (void) write(1, buggered, strlen(buggered));
  86.     }
  87.  
  88.     (void) write(1, s, strlen(s));
  89.     (void) write(1, "\t", 1);
  90.     (void) write(1, ptr, strlen(ptr));
  91.     prn((int)fp->_ptr, 10);
  92.     (void) write(1, cnt, strlen(cnt));
  93.     prn((int)fp->_cnt, 10);
  94.     (void) write(1, "\n", 1);
  95. }
  96.  
  97. prn(i, rad)
  98. int i, rad;
  99. {
  100.     int quot, rem;
  101.     char c;
  102.  
  103.     if (i < 0) {
  104.         (void) write(1, "-", 1);
  105.         i = -i;
  106.     }
  107.     quot = i / rad;
  108.     rem = i % rad;
  109.     if (quot > 0)
  110.         prn(quot, rad);
  111.     c = rem + '0';
  112.     (void) write(1, &c, 1);
  113. }
  114.