home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
MC20.ZIP
/
TYPE4.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-20
|
1KB
|
48 lines
/*
* Program to display a file assuming tab stops are at 4 character
* Intervals. By redirecting the output from this program to the
* printer, you may properly print the MICRO-C listings.
*
* In MICRO-C, the operation "a && b" is defined as returning zero
* without evaluating "b" if "a" evaluates to zero, otherwise "b"
* is evaluated and returned.
*
* The statement "j = (chr != '\n') && j+1" shows how && (or ||) may
* be used to create a very efficent conditional expression in MICRO-C.
* NOTE that this is not "standard", and is NOT PORTABLE. The more
* conventional equivalent is: "j = (chr != '\n') ? j+1 : 0"
*
* Copyright 1989,1990 Dave Dunfield
* All rights reserved.
*/
#include \mc\stdio.h
#define TAB_SIZE 4 /* tab spacing */
main(argc, argv)
int argc;
char *argv[];
{
int i, j, chr;
FILE *fp;
if(argc < 2)
abort("\nUse: type4 <filename*>\n");
for(i=1; i < argc; ++i) {
if(fp = fopen(argv[i], "r")) {
j = 0;
while((chr = getc(fp)) != EOF) {
if(chr == '\t') { /* tab */
do
putc(' ', stdout);
while(++j % TAB_SIZE); }
else { /* not a tab */
j = (chr != '\n') && j+1; /* see opening comment */
putc(chr, stdout); } }
fclose(fp); }
else {
fputs(argv[i], stderr);
fputs(": Unable to access\n", stderr); } }
}