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/enmasse.o \
util/eprintf.o \
util/putword.o \
util/recurse.o \
SRC = \

4
TODO
View File

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

8
echo.c
View File

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

12
kill.1
View File

@ -3,8 +3,13 @@
KILL \- compare two files
.SH SYNOPSIS
.B kill
.RB [ \-s ]
.RB [ \-s
.IR signal ]
.RI [ pid ...]
.P
.B kill
.B -l
.RI [ signum ]
.SH DESCRIPTION
.B kill
sends a
@ -14,5 +19,10 @@ signal to the given processes.
.TP
.BI \-s " 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
.IR kill (2)

29
kill.c
View File

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

23
uname.c
View File

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