more cleaning
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
#include "noargvzero.h"
|
||||
|
||||
extern char *optarg; /* getopt(3); unistd.h */
|
||||
extern int optind, opterr, optopt; /* getopt(3); unistd.h */
|
||||
|
||||
void
|
||||
occurrences(FILE *f, char *s){
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
usage(char *name){
|
||||
fprintf(stderr,
|
||||
"Usage: %s (-b [list] (-n))"
|
||||
"\t|(-c [list])"
|
||||
"\t|(-f [list] (-d [delim]) (-s))"
|
||||
"\t[file...]\n", name);
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]){
|
||||
int c;
|
||||
char *delimiter;
|
||||
char *list;
|
||||
char mode;
|
||||
|
||||
NOARGVZERO(argv[0]);
|
||||
|
||||
/* perhaps mode could be specified after submodal stuff. this would
|
||||
* move checks to after argument parsing though which could take more
|
||||
* time. */
|
||||
mode = 0;
|
||||
submode = 0;
|
||||
while((c = getopt(argc, argv, "b:c:d:f:ns")) != -1)
|
||||
switch(c){
|
||||
case 'b': case 'c': case 'f':
|
||||
if(mode != 0)
|
||||
usage(argv[0]);
|
||||
mode = c;
|
||||
list = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
if(mode != 'f')
|
||||
usage(argv[0]);
|
||||
delimiter = optarg;
|
||||
break;
|
||||
|
||||
case 'n': case 's':
|
||||
if((c == 's' && mode != 'f')
|
||||
|| (c == 'b' && mode != 'b'))
|
||||
usage(argv[0]);
|
||||
submode = c;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
return EX_OK;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
int main() { return 1; }
|
||||
@@ -1,73 +0,0 @@
|
||||
#include <ascii.h> /* ASCII_MAX_VALUE */
|
||||
#include <stdbool.h> /* bool */
|
||||
#include <stdio.h> /* fprintf(3), getc(3), putc(3), stderr, stdin, stdout */
|
||||
#include <stdlib.h> /* exit(3) */
|
||||
#include <sysexits.h> /* EX_OK, EX_USAGE, EX_SOFTWARE */
|
||||
#include <unistd.h> /* getopt(3) */
|
||||
|
||||
/* Enable Unicode support using official Unicode library. */
|
||||
#ifdef USE_ICU
|
||||
# include <unicode/uchar.h> /* UCHAR_MAX_VALUE, u_tolower(3) */
|
||||
# include <unicode/umachine.h> /* UChar32 */
|
||||
# include <unicode/ustdio.h> /* u_fgetc(3) */
|
||||
#endif /* USE_ICU */
|
||||
|
||||
#define PROGRAM_NAME "lowercase"
|
||||
|
||||
void
|
||||
usage(char *name){
|
||||
fprintf(stderr, "Usage: %s (-f)\n", name);
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
#ifdef USE_ICU
|
||||
UChar32
|
||||
#else
|
||||
int
|
||||
#endif
|
||||
c; /* iterating over character stream */
|
||||
int d; /* iterating over getopt */
|
||||
bool force;
|
||||
force = false;
|
||||
|
||||
while((d = getopt(argc, argv, "f")) != -1)
|
||||
switch(d){
|
||||
case 'f':
|
||||
force = true;
|
||||
break;
|
||||
case '?':
|
||||
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
|
||||
break;
|
||||
}
|
||||
if(argv[optind] != NULL) /* don't accept arguments */
|
||||
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
|
||||
|
||||
#ifdef USE_ICU
|
||||
while((c = u_fgetc(stdin)) != U_EOF){
|
||||
#else
|
||||
while((c = getc(stdin)) != EOF){
|
||||
#endif
|
||||
if(c <= ASCII_MAX_VALUE)
|
||||
c += ('a' - 'A') * (c >= 'A' && c <= 'Z');
|
||||
#ifdef USE_ICU
|
||||
else if(c <= UCHAR_MAX_VALUE)
|
||||
c = u_tolower(c);
|
||||
#endif
|
||||
else if(!force){ /* past supported */
|
||||
fprintf(
|
||||
stderr,
|
||||
"%s: Sorry, extra-ASCII characters are not yet"
|
||||
" supported!\n",
|
||||
argv[0] != NULL ? argv[0] : PROGRAM_NAME
|
||||
);
|
||||
return EX_SOFTWARE;
|
||||
}
|
||||
#ifdef USE_ICU
|
||||
u_fputc(c, stdout);
|
||||
#else
|
||||
putc(c, stdout);
|
||||
#endif
|
||||
}
|
||||
return EX_OK;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#include <ctype.h> /* isdigit(3) */
|
||||
#include <sysexits.h> /* EX_USAGE */
|
||||
#include <unistd.h> /* write(2) */
|
||||
#include "libio.h" /* fdprint(3), parse_uint(3) */
|
||||
|
||||
static char *program_name = "retval";
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
unsigned int s;
|
||||
|
||||
if(argc < 2){
|
||||
usage: write(2, "Usage: ", 7);
|
||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
||||
write(2, " [status]\n", 10);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
for(s = 0; argv[1][s] != '\0'; ++s)
|
||||
if(!isdigit(argv[1][s]))
|
||||
goto usage;
|
||||
|
||||
s = parse_uint(argv[1]);
|
||||
|
||||
return s;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <sysexits.h> /* EX_USAGE */
|
||||
#include <unistd.h> /* execv(3), write(2) */
|
||||
#include "libio.h" /* fdprint(3) */
|
||||
|
||||
static char *program_name = "simexec";
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if(argc < 2){
|
||||
write(2, "Usage: ", 7);
|
||||
if(argv[0] == NULL)
|
||||
argv[0] = program_name;
|
||||
fdprint(2, argv[0]);
|
||||
write(2, " [pathname] [argv...]\n", 22);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
return execv(argv[1], argv+2);
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
#include <ctype.h> /* isdigit(3) */
|
||||
#include <stdlib.h> /* atoi(3) */
|
||||
#include <sysexits.h> /* EX_USAGE */
|
||||
#include <unistd.h> /* sleep(3) */
|
||||
#include "libio.h"
|
||||
|
||||
static char *program_name = "sleep";
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int s;
|
||||
if(argc != 2){
|
||||
usage: write(2, "Usage: ", 7);
|
||||
fdprint(2, argv[0] == NULL ? program_name : argv[0]);
|
||||
write(2, " [seconds]\n", 11);
|
||||
return EX_USAGE;
|
||||
}
|
||||
s = parse_uint(argv[1]);
|
||||
while(isdigit(*argv[1]))
|
||||
++argv[1];
|
||||
if(*argv[1] != '\0')
|
||||
goto usage;
|
||||
while(s > 0)
|
||||
s = sleep(s);
|
||||
return s;
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
#include "libio.h"
|
||||
|
||||
static char *program_name = "streq";
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if(argc < 3){
|
||||
write(2, "Usage: ", 7);
|
||||
if(argv[0] == NULL)
|
||||
argv[0] = program_name;
|
||||
fdprint(2, argv[0]);
|
||||
write(2, " [strings...]\n", 14);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
/* i is the arg index, j is the char index */
|
||||
for(j = 0; argv[1][j] != '\0'; ++j)
|
||||
for(i = 2; i < argc; ++i)
|
||||
if(argv[i-1][j] != argv[i][j])
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
int main(){ return 0; }
|
||||
Reference in New Issue
Block a user