2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
21 #define VERSION "0.01"
23 void usage(char* program
)
25 printf("Usage: %s [options] [file ...]\n", program
);
26 printf("Concatenates file(s) and/or standard input to standard output.\n"
30 " --help Print this message.\n"
31 " --version Show version info.\n");
34 int main(int argc
, char* argv
[])
36 // read from stdin if run with no args
50 for (arg
= 1; arg
< argc
; arg
++)
52 if (strcmp(argv
[arg
], "-u") == 0) {
54 } else if (strcmp(argv
[arg
], "--help") == 0){
56 } else if (strcmp(argv
[arg
], "--version") == 0) {
57 printf("cat (mutos) v"VERSION
"\n");
59 } else if (strcmp(argv
[arg
], "--") == 0) { // the next args will be the actual args
60 arg
++; // jump to first actual args
61 break; // and break out of flag loop
68 for (; arg
< argc
; arg
++)
70 FILE *current_file
= NULL
;
72 if (strcmp(argv
[arg
], "-") == 0) {
75 current_file
= fopen(argv
[arg
], "r");
80 int c
= fgetc(current_file
);
84 c
= fgetc(current_file
);
88 fprintf(stderr
, "%s: %s: %s\n", argv
[0], strerror(errno
), argv
[arg
]);