Compare commits
No commits in common. "5545846c92f310bbb74e70c184f2b467e9fea701" and "2e172d93e8735c6e35040d324dd2e898c7a13840" have entirely different histories.
5545846c92
...
2e172d93e8
2
src/dj.c
2
src/dj.c
@ -118,7 +118,7 @@ oserr(char *e, int n) {
|
|||||||
|
|
||||||
/* Prints statistics regarding the use of dj, particularly partially and
|
/* Prints statistics regarding the use of dj, particularly partially and
|
||||||
* completely read and written records. */
|
* completely read and written records. */
|
||||||
static int
|
static void
|
||||||
fprintio(FILE *stream, char *fmt, struct Io io[2]) {
|
fprintio(FILE *stream, char *fmt, struct Io io[2]) {
|
||||||
return fprintf(
|
return fprintf(
|
||||||
stream,
|
stream,
|
||||||
|
43
src/mm.c
43
src/mm.c
@ -88,6 +88,25 @@ oserr(char *s, char *r) {
|
|||||||
return EX_OSERR;
|
return EX_OSERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hijacks i and j from main and destructs the files[2] struct used by main by
|
||||||
|
* closing its files and freeing its files and names arrays, returning retval
|
||||||
|
* from main. */
|
||||||
|
#define terminate \
|
||||||
|
for (i = 0; i < 2; ++i) { \
|
||||||
|
for (j = 0; j < files[i].s; ++j) { \
|
||||||
|
if ( \
|
||||||
|
files[i].files[j] != stdin \
|
||||||
|
&& files[i].files[j] != stdout \
|
||||||
|
&& files[i].files[j] != stderr \
|
||||||
|
) { \
|
||||||
|
fclose(files[i].files[j]); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
free(files[i].files); \
|
||||||
|
free(files[i].names); \
|
||||||
|
} \
|
||||||
|
return retval
|
||||||
|
|
||||||
static int
|
static int
|
||||||
usage(char *argv0) {
|
usage(char *argv0) {
|
||||||
(void)fprintf(
|
(void)fprintf(
|
||||||
@ -144,7 +163,8 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return oserr(program_name, "-e");
|
retval = oserr(program_name, "-e");
|
||||||
|
terminate;
|
||||||
case 'i':
|
case 'i':
|
||||||
if (
|
if (
|
||||||
(strcmp(optarg, "-") == 0
|
(strcmp(optarg, "-") == 0
|
||||||
@ -152,7 +172,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|| Files_open(&files[0], optarg) != NULL
|
|| Files_open(&files[0], optarg) != NULL
|
||||||
) { break; }
|
) { break; }
|
||||||
|
|
||||||
return oserr(program_name, optarg);
|
retval = oserr(program_name, optarg);
|
||||||
|
terminate;
|
||||||
case 'o':
|
case 'o':
|
||||||
if (
|
if (
|
||||||
(strcmp(optarg, "-") == 0
|
(strcmp(optarg, "-") == 0
|
||||||
@ -169,21 +190,27 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return oserr(program_name, optarg);
|
retval = oserr(program_name, optarg);
|
||||||
|
terminate;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (signal(SIGINT, SIG_IGN) != SIG_ERR) { break; }
|
if (signal(SIGINT, SIG_IGN) != SIG_ERR) { break; }
|
||||||
|
|
||||||
return oserr(program_name, "-n");
|
retval = oserr(program_name, "-n");
|
||||||
|
terminate;
|
||||||
case 'u':
|
case 'u':
|
||||||
k = 1;
|
k = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return usage(program_name);
|
retval = usage(program_name);
|
||||||
|
terminate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind != argc) { return usage(program_name); }
|
if (optind != argc) {
|
||||||
|
retval = usage(program_name);
|
||||||
|
terminate;
|
||||||
|
}
|
||||||
|
|
||||||
files[0].s += files[0].s == 0;
|
files[0].s += files[0].s == 0;
|
||||||
files[1].s += files[1].s == 0;
|
files[1].s += files[1].s == 0;
|
||||||
@ -231,11 +258,11 @@ int main(int argc, char *argv[]) {
|
|||||||
files[1].names[k] = files[1].names[k+1];
|
files[1].names[k] = files[1].names[k+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(--files[1].s == 0) { return retval; }
|
if(--files[1].s == 0) { terminate; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
terminate;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user