[hackers] [sbase] kill -l || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Fri, 10 Jun 2011 03:56:19 +0200 (CEST)

changeset: 65:3ad8edbbee88
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Fri Jun 10 02:56:13 2011 +0100
files: Makefile TODO echo.c kill.1 kill.c uname.c util.h util/putword.c
description:
kill -l

diff -r 95bb36ed00c9 -r 3ad8edbbee88 Makefile
--- a/Makefile Fri Jun 10 02:29:10 2011 +0100
+++ b/Makefile Fri Jun 10 02:56:13 2011 +0100
@@ -7,6 +7,7 @@
         util/concat.o \
         util/enmasse.o \
         util/eprintf.o \
+ util/putword.o \
         util/recurse.o \
 
 SRC = \
diff -r 95bb36ed00c9 -r 3ad8edbbee88 TODO
--- a/TODO Fri Jun 10 02:29:10 2011 +0100
+++ b/TODO Fri Jun 10 02:56:13 2011 +0100
@@ -1,7 +1,5 @@
 cksum [file...]
 
-cmp [-ls] file1 file2
-
 comm [-123] file1 file2
 
 cp [-r] file [name]
@@ -13,8 +11,6 @@
 
 id [-gnru] [user]
 
-kill [-s signal] [pid...]
-
 mv file [name]
 mv [file...] directory
 
diff -r 95bb36ed00c9 -r 3ad8edbbee88 echo.c
--- a/echo.c Fri Jun 10 02:29:10 2011 +0100
+++ b/echo.c Fri Jun 10 02:56:13 2011 +0100
@@ -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 @@
                 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;
diff -r 95bb36ed00c9 -r 3ad8edbbee88 kill.1
--- a/kill.1 Fri Jun 10 02:29:10 2011 +0100
+++ b/kill.1 Fri Jun 10 02:56:13 2011 +0100
@@ -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 @@
 .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)
diff -r 95bb36ed00c9 -r 3ad8edbbee88 kill.c
--- a/kill.c Fri Jun 10 02:29:10 2011 +0100
+++ b/kill.c Fri Jun 10 02:56:13 2011 +0100
@@ -1,6 +1,8 @@
 /* See LICENSE file for copyright and license details. */
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <strings.h>
 #include <unistd.h>
 #include "util.h"
@@ -21,12 +23,16 @@
 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 @@
                 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]);
diff -r 95bb36ed00c9 -r 3ad8edbbee88 uname.c
--- a/uname.c Fri Jun 10 02:29:10 2011 +0100
+++ b/uname.c Fri Jun 10 02:56:13 2011 +0100
@@ -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 @@
                 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;
-}
diff -r 95bb36ed00c9 -r 3ad8edbbee88 util.h
--- a/util.h Fri Jun 10 02:29:10 2011 +0100
+++ b/util.h Fri Jun 10 02:56:13 2011 +0100
@@ -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 *));
diff -r 95bb36ed00c9 -r 3ad8edbbee88 util/putword.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/putword.c Fri Jun 10 02:56:13 2011 +0100
@@ -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;
+}
Received on Fri Jun 10 2011 - 03:56:19 CEST

This archive was generated by hypermail 2.2.0 : Fri Jun 10 2011 - 04:00:09 CEST