forked from bonsai/harakit
mm(1), mm.1: bring source in line with documentation
This commit is contained in:
parent
d74bc715cf
commit
135bf2a8eb
92
src/mm.c
92
src/mm.c
@ -132,53 +132,57 @@ int main(int argc, char *argv[]){
|
|||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
|
|
||||||
while((c = getopt(argc, argv, "aehi:no:u")) != -1)
|
if(argc > 0)
|
||||||
switch(c){
|
program_name = argv[0];
|
||||||
case 'a': /* "rb+" -> "ab" */
|
|
||||||
files[1].mode[0] = 'a';
|
if(argc > 1)
|
||||||
files[1].mode[2] = '\0';
|
while((c = getopt(argc, argv, "aehi:no:u")) != -1)
|
||||||
break;
|
switch(c){
|
||||||
case 'e':
|
case 'a': /* "rb+" -> "ab" */
|
||||||
if(Files_append(&files[1], stderr, stderr_name) != NULL)
|
files[1].mode[0] = 'a';
|
||||||
|
files[1].mode[2] = '\0';
|
||||||
break;
|
break;
|
||||||
retval = oserr(argv[0], "-e");
|
case 'e':
|
||||||
terminate;
|
if(Files_append(&files[1], stderr, stderr_name) != NULL)
|
||||||
case 'i':
|
|
||||||
if((strcmp(optarg, "-") == 0 && Files_append(&files[0],
|
|
||||||
stdin, stdin_name) != NULL)
|
|
||||||
|| Files_open(&files[0], optarg) != NULL)
|
|
||||||
break;
|
|
||||||
retval = oserr(argv[0], optarg);
|
|
||||||
terminate;
|
|
||||||
case 'o':
|
|
||||||
if((strcmp(optarg, "-") == 0 && Files_append(&files[1],
|
|
||||||
stdout, stdout_name) != NULL)
|
|
||||||
|| Files_open(&files[1], optarg) != NULL)
|
|
||||||
break;
|
|
||||||
/* does not exist, so try to create it */
|
|
||||||
if(errno == ENOENT){
|
|
||||||
files[1].mode = wharsh;
|
|
||||||
if(Files_open(&files[1], optarg) != NULL){
|
|
||||||
files[1].mode = fmode[1];
|
|
||||||
break;
|
break;
|
||||||
|
retval = oserr(argv[0], "-e");
|
||||||
|
terminate;
|
||||||
|
case 'i':
|
||||||
|
if((strcmp(optarg, "-") == 0 && Files_append(&files[0],
|
||||||
|
stdin, stdin_name) != NULL)
|
||||||
|
|| Files_open(&files[0], optarg) != NULL)
|
||||||
|
break;
|
||||||
|
retval = oserr(argv[0], optarg);
|
||||||
|
terminate;
|
||||||
|
case 'o':
|
||||||
|
if((strcmp(optarg, "-") == 0 && Files_append(&files[1],
|
||||||
|
stdout, stdout_name) != NULL)
|
||||||
|
|| Files_open(&files[1], optarg) != NULL)
|
||||||
|
break;
|
||||||
|
/* does not exist, so try to create it */
|
||||||
|
if(errno == ENOENT){
|
||||||
|
files[1].mode = wharsh;
|
||||||
|
if(Files_open(&files[1], optarg) != NULL){
|
||||||
|
files[1].mode = fmode[1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
retval = oserr(argv[0], optarg);
|
||||||
retval = oserr(argv[0], optarg);
|
terminate;
|
||||||
terminate;
|
case 'n':
|
||||||
case 'n':
|
if(signal(SIGINT, SIG_IGN) != SIG_ERR)
|
||||||
if(signal(SIGINT, SIG_IGN) != SIG_ERR)
|
break;
|
||||||
|
retval = oserr(argv[0], "-n");
|
||||||
|
terminate;
|
||||||
|
case 'u':
|
||||||
|
k = 1;
|
||||||
break;
|
break;
|
||||||
retval = oserr(argv[0], "-n");
|
default:
|
||||||
terminate;
|
fprintf(stderr, "Usage: %s (-aenu) (-i [input])..."
|
||||||
case 'u':
|
" (-o [output])...\n", argv[0]);
|
||||||
k = 1;
|
retval = EX_USAGE;
|
||||||
break;
|
terminate;
|
||||||
default:
|
}
|
||||||
fprintf(stderr, "Usage: %s (-aenu) (-i [input])..."
|
|
||||||
" (-o [output])...\n", argv[0]);
|
|
||||||
retval = EX_USAGE;
|
|
||||||
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;
|
||||||
@ -202,6 +206,8 @@ int main(int argc, char *argv[]){
|
|||||||
if(putc(c, files[1].files[j]) == EOF){
|
if(putc(c, files[1].files[j]) == EOF){
|
||||||
/* notebook's full */
|
/* notebook's full */
|
||||||
retval = EX_IOERR;
|
retval = EX_IOERR;
|
||||||
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
|
program_name, files[1].names[j], strerror(errno));
|
||||||
if(fclose(files[1].files[j]) == EOF)
|
if(fclose(files[1].files[j]) == EOF)
|
||||||
fprintf(stderr, "%s: %s: %s\n",
|
fprintf(stderr, "%s: %s: %s\n",
|
||||||
program_name, files[1].names[j], strerror(errno));
|
program_name, files[1].names[j], strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user