FENIX_coreutils/asa.c

47 lines
957 B
C
Executable file

#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
FILE *in_file;
int i, error = 0, eof_reached = 0;
char c, c_temp;
for(i = 1; i < argc; i++) {
if(argv[i][0] == '-' && argv[i][1] == '\0')
in_file = stdin;
else {
in_file = fopen(argv[i], "r");
if(in_file == NULL) {
fprintf(stderr, "Cannot find file %s\n", argv[i]);
error = 1;
continue;
}
}
eof_reached = 0;
while(!eof_reached) {
c = fgetc(in_file);
switch(c) {
case '1': printf("\f"); break;
case '0': printf("\n"); break;
case '+': printf("\r"); break;
case EOF: eof_reached = 1; continue;
}
for(c_temp = fgetc(in_file); c_temp != '\n'; c_temp = fgetc(in_file)) {
if(c_temp == EOF) {
eof_reached = 1;
break;
}
else
printf("%c", c_temp);
}
}
printf("\n");
}
if(error)
return 1;
else
return 0;
}