#include
#include
#define PACKAGE "todos"
#define VERSION "0.0.1"
void print_help(int exval);
void todos(FILE *fp);
int main (int argc, char* argv[]) {
FILE *fp = stdin;
int opt = 0;
while((opt = getopt(argc, argv, "hv")) != -1) {
switch(opt) {
case 'h':
print_help(0);
break;
case 'v':
printf("%s %s\n", PACKAGE, VERSION);
exit(0);
break;
case '?':
fprintf(stderr, "%s: Error - No such option `%c'\n\n",
PACKAGE, optopt);
print_help(1);
}
}
/* no input files ... ? parse stdin() */
if((argc - optind) == 0) {
todos(fp);
} else {
for(; optind < argc; optind++) {
if(freopen(argv[optind], "r", fp) == NULL) {
fprintf(stderr, "%s: Error opening `%s'\n", PACKAGE, argv[optind]);
return 1;
}
todos(fp);
fclose(fp);
}
}
return 0;
}
void todos(FILE *fp) {
char c;
while((c = fgetc(fp)) != EOF) {
if(c == '\n')
printf("%c", '\r');
printf("%c", c);
}
}
void print_help(int exval) {
printf("%s,%s Convert unix to dos newlines\n", PACKAGE, VERSION);
printf("Usage: %s [-h] [-v] FILE...\n\n", PACKAGE);
printf(" -h print this help and exit\n");
printf(" -v print version and exit\n\n");
exit(exval);
}