summaryrefslogtreecommitdiff
path: root/usr.bin/sectok/main.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-17 07:10:53 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-17 07:10:53 +0000
commit60018b23862bb48ef81f34d004d107838832e22c (patch)
treece0467fc3a963d34109651a8d19f3b42c1b05da5 /usr.bin/sectok/main.c
parentbf58cb10a0a4d352ef847ee1cea1b95275b7ecd9 (diff)
make this readable. If I broke something, someone else gets to fix it now that we can read it
Diffstat (limited to 'usr.bin/sectok/main.c')
-rw-r--r--usr.bin/sectok/main.c241
1 files changed, 121 insertions, 120 deletions
diff --git a/usr.bin/sectok/main.c b/usr.bin/sectok/main.c
index afd107e258d..19651c035b6 100644
--- a/usr.bin/sectok/main.c
+++ b/usr.bin/sectok/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.7 2002/03/14 15:47:31 rees Exp $ */
+/* $OpenBSD: main.c,v 1.8 2002/06/17 07:10:52 deraadt Exp $ */
/*
* Smartcard commander.
@@ -6,39 +6,40 @@
*/
/*
-copyright 2001
-the regents of the university of michigan
-all rights reserved
-
-permission is granted to use, copy, create derivative works
-and redistribute this software and such derivative works
-for any purpose, so long as the name of the university of
-michigan is not used in any advertising or publicity
-pertaining to the use or distribution of this software
-without specific, written prior authorization. if the
-above copyright notice or any other identification of the
-university of michigan is included in any copy of any
-portion of this software, then the disclaimer below must
-also be included.
-
-this software is provided as is, without representation
-from the university of michigan as to its fitness for any
-purpose, and without warranty by the university of
-michigan of any kind, either express or implied, including
-without limitation the implied warranties of
-merchantability and fitness for a particular purpose. the
-regents of the university of michigan shall not be liable
-for any damages, including special, indirect, incidental, or
-consequential damages, with respect to any claim arising
-out of or in connection with the use of the software, even
-if it has been or is hereafter advised of the possibility of
-such damages.
-*/
+ * copyright 2001
+ * the regents of the university of michigan
+ * all rights reserved
+ *
+ * permission is granted to use, copy, create derivative works
+ * and redistribute this software and such derivative works
+ * for any purpose, so long as the name of the university of
+ * michigan is not used in any advertising or publicity
+ * pertaining to the use or distribution of this software
+ * without specific, written prior authorization. if the
+ * above copyright notice or any other identification of the
+ * university of michigan is included in any copy of any
+ * portion of this software, then the disclaimer below must
+ * also be included.
+ *
+ * this software is provided as is, without representation
+ * from the university of michigan as to its fitness for any
+ * purpose, and without warranty by the university of
+ * michigan of any kind, either express or implied, including
+ * without limitation the implied warranties of
+ * merchantability and fitness for a particular purpose. the
+ * regents of the university of michigan shall not be liable
+ * for any damages, including special, indirect, incidental, or
+ * consequential damages, with respect to any claim arising
+ * out of or in connection with the use of the software, even
+ * if it has been or is hereafter advised of the possibility of
+ * such damages.
+ */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
+#include <limits.h>
#include <string.h>
#include <errno.h>
#include <sectok.h>
@@ -48,110 +49,110 @@ such damages.
#define MAXTOKENS 300
#define CARDIOSIZE 200
-void onintr(int sigraised);
+void onintr(int sigraised);
-const char usage[] =
-"Usage: sectok [-0123hf:s:]\n"
-" 0 - 3 : specify card reader number\n"
-" f script_file : run commands from the script file\n"
-" s sleep_time : set sleep between commands in the script\n"
-" h : this message\n"
-;
+int port, fd = -1, cla, sleepytime;
+volatile sig_atomic_t interrupted;
+FILE *cmdf;
-int port, fd = -1, cla, sleepytime, interrupted;
-FILE *cmdf;
+void
+usage(void)
+{
+ fprintf(stderr,
+ "usage: sectok [-0123] [-f scriptfile] [-s sleeptime] [cmd] [args]\n");
+ exit(1);
+}
int
-main(ac, av)
-int ac;
-char *av[];
+main(argc, argv)
+ int argc;
+ char *argv[];
{
- int i, tc;
- char buf[256], *scriptfile = NULL, *tp, *tv[MAXTOKENS];
-
- tp = getenv("SCPORT");
- if (tp)
- port = atoi(tp);
-
- while ((i = getopt(ac, av, "0123f:s:h")) != -1) {
- switch (i) {
- case '0':
- case '1':
- case '2':
- case '3':
- port = i - '0';
- break;
- case 'f':
- scriptfile = optarg;
- break;
- case 's':
- sleepytime = atoi(optarg);
- break;
- case 'h':
- case '?':
- fputs(usage, stdout);
- exit(0);
- break;
+ char buf[_POSIX2_LINE_MAX], *scriptfile = NULL, *tp, *tv[MAXTOKENS];
+ int i, tc;
+
+ tp = getenv("SCPORT");
+ if (tp)
+ port = atoi(tp);
+
+ while ((i = getopt(argc, argv, "0123f:s:h")) != -1) {
+ switch (i) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ port = i - '0';
+ break;
+ case 'f':
+ scriptfile = optarg;
+ break;
+ case 's':
+ sleepytime = atoi(optarg);
+ break;
+ case 'h':
+ default:
+ usage();
+ break;
+ }
}
- }
-
- if (optind != ac) {
- /* Dispatch from command line */
- dispatch(ac - optind, &av[optind]);
- exit(0);
- }
-
- if (scriptfile != NULL) {
- cmdf = fopen(scriptfile, "r");
- if (cmdf == NULL) {
- perror(scriptfile);
- exit(2);
- }
- } else
- cmdf = stdin;
-
- /* Interactive mode, or script file */
- signal(SIGINT, onintr);
+ if (optind != argc) {
+ /* Dispatch from command line */
+ dispatch(argc - optind, &argv[optind]);
+ exit(0);
+ }
+ if (scriptfile != NULL) {
+ cmdf = fopen(scriptfile, "r");
+ if (cmdf == NULL) {
+ perror(scriptfile);
+ exit(2);
+ }
+ } else
+ cmdf = stdin;
+
+ /* Interactive mode, or script file */
+
+ signal(SIGINT, onintr);
#ifdef __OpenBSD__
- siginterrupt(SIGINT, 1);
+ siginterrupt(SIGINT, 1);
#endif
- /* The Main Loop */
- while (1) {
- fflush(stdout);
- interrupted = 0;
- if (sleepytime)
- usleep(sleepytime * 1000);
- if (cmdf == stdin) {
- fprintf(stderr, "sectok> ");
- fflush(stderr);
+ /* The Main Loop */
+ while (1) {
+ fflush(stdout);
+ interrupted = 0;
+ if (sleepytime)
+ usleep(sleepytime * 1000);
+ if (cmdf == stdin) {
+ fprintf(stderr, "sectok> ");
+ fflush(stderr);
+ }
+ if (!fgets(buf, sizeof buf, cmdf)) {
+ putchar('\n');
+ if (interrupted)
+ continue;
+ else
+ break;
+ }
+ if (cmdf != stdin)
+ printf("sectok> %s", buf);
+
+ for ((tp = strtok(buf, " \t\n\r")), tc = 0; tp;
+ (tp = strtok(NULL, " \t\n\r")), tc++) {
+ if (tc < MAXTOKENS - 1)
+ tv[tc] = tp;
+ }
+ tv[tc] = NULL;
+
+ dispatch(tc, tv);
}
- if (!fgets(buf, sizeof buf, cmdf)) {
- putchar('\n');
- if (interrupted)
- continue;
- else
- break;
- }
- if (cmdf != stdin)
- printf("sectok> %s", buf);
-
- for ((tp = strtok(buf, " \t\n\r")), tc = 0; tp; (tp = strtok(NULL, " \t\n\r")), tc++) {
- if (tc < MAXTOKENS - 1)
- tv[tc] = tp;
- }
- tv[tc] = NULL;
-
- dispatch(tc, tv);
- }
-
- quit(0, NULL);
- return 0;
+ quit(0, NULL);
+ return 0;
}
-void onintr(int sigraised)
+void
+onintr(int sigraised)
{
- interrupted++;
+ interrupted++;
}