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.
19 #define VERSION "0.01"
21 void usage(char* program
)
23 printf("Usage: %s [options] [file ...]\n", program
);
24 printf("Concatenates file(s) and/or standard input to standard output.\n"
26 " --help Print this message.\n"
27 " --version Show version info.\n");
30 int main(int argc
, char* argv
[])
32 // read from stdin if run with no args
46 for (arg
= 1; arg
< argc
; arg
++)
48 if (strcmp(argv
[arg
], "--help") == 0 && argc
== 2) {
50 } else if (strcmp(argv
[arg
], "--version") == 0 && argc
== 2) {
51 printf("cat (mutos) v"VERSION
"\n");
53 } else if (strcmp(argv
[arg
], "--") == 0) { // the next args will be the actual args
54 arg
++; // jump to first actual args
55 break; // and break out of flag loop
62 for (; arg
< argc
; arg
++)
64 FILE *current_file
= NULL
;
66 if (strcmp(argv
[arg
], "-") == 0) {
69 current_file
= fopen(argv
[arg
], "r");
74 int c
= fgetc(current_file
);
78 c
= fgetc(current_file
);
82 fprintf(stderr
, "%s: %s: %s\n", argv
[0], argv
[arg
], strerror(errno
));