This commit is contained in:
Connor Lane Smith 2011-06-10 02:56:13 +01:00
parent e180a91172
commit 5156758e21
8 changed files with 62 additions and 31 deletions

View File

@ -7,6 +7,7 @@ LIB = \
util/concat.o \ util/concat.o \
util/enmasse.o \ util/enmasse.o \
util/eprintf.o \ util/eprintf.o \
util/putword.o \
util/recurse.o \ util/recurse.o \
SRC = \ SRC = \

4
TODO
View File

@ -1,7 +1,5 @@
cksum [file...] cksum [file...]
cmp [-ls] file1 file2
comm [-123] file1 file2 comm [-123] file1 file2
cp [-r] file [name] cp [-r] file [name]
@ -13,8 +11,6 @@ diff [-ru] file1 file2
id [-gnru] [user] id [-gnru] [user]
kill [-s signal] [pid...]
mv file [name] mv file [name]
mv [file...] directory mv [file...] directory

8
echo.c
View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "util.h"
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@ -18,11 +19,8 @@ main(int argc, char *argv[])
default: default:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for(; optind < argc; optind++) { for(; optind < argc; optind++)
fputs(argv[optind], stdout); putword(argv[optind]);
if(optind+1 < argc)
putchar(' ');
}
if(!nflag) if(!nflag)
putchar('\n'); putchar('\n');
return EXIT_SUCCESS; return EXIT_SUCCESS;

12
kill.1
View File

@ -3,8 +3,13 @@
KILL \- compare two files KILL \- compare two files
.SH SYNOPSIS .SH SYNOPSIS
.B kill .B kill
.RB [ \-s ] .RB [ \-s
.IR signal ]
.RI [ pid ...] .RI [ pid ...]
.P
.B kill
.B -l
.RI [ signum ]
.SH DESCRIPTION .SH DESCRIPTION
.B kill .B kill
sends a sends a
@ -14,5 +19,10 @@ signal to the given processes.
.TP .TP
.BI \-s " signal" .BI \-s " signal"
sends the named signal. sends the named signal.
.TP
.B \-l
lists available signals. If a
.I signum
is given, only the corresponding signal name will be printed.
.SH SEE ALSO .SH SEE ALSO
.IR kill (2) .IR kill (2)

29
kill.c
View File

@ -1,6 +1,8 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>
#include "util.h" #include "util.h"
@ -21,12 +23,16 @@ struct {
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
bool lflag = false;
char c, *end; char c, *end;
int i, sig = SIGTERM; int i, sig = SIGTERM;
pid_t pid; pid_t pid;
while((c = getopt(argc, argv, "s:")) != -1) while((c = getopt(argc, argv, "ls:")) != -1)
switch(c) { switch(c) {
case 'l':
lflag = true;
break;
case 's': case 's':
for(i = 0; i < LEN(sigs); i++) for(i = 0; i < LEN(sigs); i++)
if(!strcasecmp(optarg, sigs[i].name)) { if(!strcasecmp(optarg, sigs[i].name)) {
@ -39,7 +45,24 @@ main(int argc, char *argv[])
default: default:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for(; optind < argc; optind++) { if(lflag) {
if(optind == argc-1) {
sig = strtol(argv[optind], &end, 0);
if(*end != '\0')
eprintf("%s: not a number\n", argv[optind]);
}
else if(optind == argc)
sig = 0;
else
eprintf("usage: %s [-s signal] [pid...]\n"
" %s -l [signum]\n", argv[0], argv[0]);
for(i = 0; i < LEN(sigs); i++)
if(sigs[i].sig == sig || sig == 0)
putword(sigs[i].name);
putchar('\n');
}
else for(; optind < argc; optind++) {
pid = strtol(argv[optind], &end, 0); pid = strtol(argv[optind], &end, 0);
if(*end != '\0') if(*end != '\0')
eprintf("%s: not a number\n", argv[optind]); eprintf("%s: not a number\n", argv[optind]);

23
uname.c
View File

@ -6,8 +6,6 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include "util.h" #include "util.h"
static void print(const char *);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -46,26 +44,15 @@ main(int argc, char *argv[])
eprintf("uname:"); eprintf("uname:");
if(sflag || !(nflag || rflag || vflag || mflag)) if(sflag || !(nflag || rflag || vflag || mflag))
print(u.sysname); putword(u.sysname);
if(nflag) if(nflag)
print(u.nodename); putword(u.nodename);
if(rflag) if(rflag)
print(u.release); putword(u.release);
if(vflag) if(vflag)
print(u.version); putword(u.version);
if(mflag) if(mflag)
print(u.machine); putword(u.machine);
putchar('\n'); putchar('\n');
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void
print(const char *s)
{
static bool first = true;
if(!first)
putchar(' ');
fputs(s, stdout);
first = false;
}

1
util.h
View File

@ -5,4 +5,5 @@
char *agetcwd(void); char *agetcwd(void);
void enmasse(int, char **, int (*)(const char *, const char *)); void enmasse(int, char **, int (*)(const char *, const char *));
void eprintf(const char *, ...); void eprintf(const char *, ...);
void putword(const char *);
void recurse(const char *, void (*)(const char *)); void recurse(const char *, void (*)(const char *));

15
util/putword.c Normal file
View File

@ -0,0 +1,15 @@
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include "../util.h"
void
putword(const char *s)
{
static bool first = true;
if(!first)
putchar(' ');
fputs(s, stdout);
first = false;
}