суббота, 29 мая 2021 г. в 23:22:26 UTC+3, Jonathan Chapman:
Found this thread while working on a copy of crck.c from the UNIX C User's Group archives, I've uploaded my work to GitHub:
https://github.com/glitchwrks/crck
Repository includes the original files, plus patches to a) fix the segfault (I see someone already did the work for that here), and b) fix all the warnings GCC was throwing. I also did up a Makefile and reformatted the manpage. There's a Slackbuild for
it too, but I can't upload it right now since they're getting ready for Slackware 15.0.
I suggest making the code of the main program more elegant:
1. Get rid of the jump to the label by moving the code behind it into the switch statement.
2. The operator exit (0) repeated in two branches; place behind it.
This does not affect the logic of the program, but it looks more beautiful.
The main program code will be as follows:
int main(argc, argv)
int argc;
char **argv;
{
int err = 0;
if (argc > 1 && (++argv)[0][0] == '-') {
switch (argv[0][1]) {
case 't':
++tflag;
break;
case 'c':
++cflag;
break;
case 'u':
++uflag;
break;
case 'i':
++iflag; ++cflag;
break;
default:
fprintf(stderr, "Usage: crck [-t|c|u|i] [filename ... ]\n");
exit(-100);
}
--argc; ++argv;
}
else /* for right now, "Unix mode" is the default */
++uflag;
if (isatty(2)) { /* print header if not in a pipe */
printf("CRCK program for Unix\n");
printf("Version %1d.%1d\n\n", VERSION/10, VERSION%10);
if (iflag) printf("ITS mode selected\n");
if (tflag) printf("CP/M text mode selected\n");
if (cflag) printf("CP/M \".COM\" mode selected\n");
if (uflag) printf("Unix file mode selected\n");
putchar('\n');
}
if (argc == 1 ) { /* we're just taking stdin from somewhere */
docrck("stdin");
}
else { /* we're doing a named file or a list of same */
for (; --argc; ++argv) {
err = 0;
if (freopen(*argv, "r", stdin) == NULL) {
perror(*argv);
++err;
}
if (!err)
docrck(*argv);
}
}
exit(0);
}
With respect
Andrey Nikitin
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)