home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / FC20C.ZIP / TYPE4.C < prev    next >
C/C++ Source or Header  |  1990-08-20  |  1KB  |  48 lines

  1. /*
  2.  * Program to display a file assuming tab stops are at 4 character
  3.  * Intervals. By redirecting the output from this program to the
  4.  * printer, you may properly print the MICRO-C listings.
  5.  *
  6.  * In MICRO-C, the operation "a && b" is defined as returning zero
  7.  * without evaluating "b" if "a" evaluates to zero, otherwise "b"
  8.  * is evaluated and returned.
  9.  *
  10.  * The statement "j = (chr != '\n') && j+1" shows how && (or ||) may
  11.  * be used to create a very efficent conditional expression in MICRO-C.
  12.  * NOTE that this is not "standard", and is NOT PORTABLE. The more
  13.  * conventional equivalent is: "j = (chr != '\n') ? j+1 : 0"
  14.  *
  15.  * Copyright 1989,1990 Dave Dunfield
  16.  * All rights reserved.
  17.  */
  18. #include \mc\stdio.h
  19.  
  20. #define TAB_SIZE    4        /* tab spacing */
  21.  
  22. main(argc, argv)
  23.     int argc;
  24.     char *argv[];
  25. {
  26.     int i, j, chr;
  27.     FILE *fp;
  28.  
  29.     if(argc < 2)
  30.         abort("\nUse: type4 <filename*>\n");
  31.  
  32.     for(i=1; i < argc; ++i) {
  33.         if(fp = fopen(argv[i], "r")) {
  34.             j = 0;
  35.             while((chr = getc(fp)) != EOF) {
  36.                 if(chr == '\t') {            /* tab */
  37.                     do
  38.                         putc(' ', stdout);
  39.                     while(++j % TAB_SIZE); }
  40.                 else {                        /* not a tab */
  41.                     j = (chr != '\n') && j+1;    /* see opening comment */
  42.                     putc(chr, stdout); } }
  43.             fclose(fp); }
  44.         else {
  45.             fputs(argv[i], stderr);
  46.             fputs(": Unable to access\n", stderr); } }
  47. }
  48.