Clean up the networking code before I parallelize the routing code.
[dragonfly.git] / usr.bin / dc / dc.c
blob65f29cc06337eba1fb6cc595833e688e81b50b6f
1 /*
2 * $OpenBSD: dc.c,v 1.5 2004/01/13 08:17:41 otto Exp $
3 * $DragonFly: src/usr.bin/dc/dc.c,v 1.1 2004/09/20 04:20:39 dillon Exp $
4 */
6 /*
7 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <err.h>
23 #include <stdlib.h>
24 #include <unistd.h>
26 #include "extern.h"
28 static void usage(void);
30 extern char *__progname;
32 static void
33 usage(void)
35 fprintf(stderr, "usage: %s [-x] [file]\n", __progname);
36 exit(1);
39 int
40 main(int argc, char *argv[])
42 int ch;
43 bool extended_regs = false;
44 FILE *file;
45 struct source src;
47 /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */
48 while ((ch = getopt(argc, argv, "x-")) != -1) {
49 switch (ch) {
50 case 'x':
51 extended_regs = true;
52 break;
53 case '-':
54 break;
55 default:
56 usage();
59 argc -= optind;
60 argv += optind;
62 init_bmachine(extended_regs);
63 setlinebuf(stdout);
64 setlinebuf(stderr);
66 if (argc > 1)
67 usage();
68 else if (argc == 1) {
69 file = fopen(argv[0], "r");
70 if (file == NULL)
71 err(1, "cannot open file %s", argv[0]);
72 src_setstream(&src, file);
73 reset_bmachine(&src);
74 eval();
75 fclose(file);
78 * BSD dc and Solaris dc continue with stdin after processing
79 * the file given as the argument.
81 src_setstream(&src, stdin);
82 reset_bmachine(&src);
83 eval();
85 return 0;