2 * $OpenBSD: dc.c,v 1.6 2004/10/18 07:49:00 otto Exp $
3 * $DragonFly: src/usr.bin/dc/dc.c,v 1.2 2005/04/21 18:50:50 swildner Exp $
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.
29 static __dead2 void usage(void);
31 extern char *__progname;
36 fprintf(stderr, "usage: %s [-x] [-e expr] [file]\n", __progname);
41 main(int argc, char *argv[])
44 bool extended_regs = false;
49 if ((buf = strdup("")) == NULL)
51 /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */
52 while ((ch = getopt(argc, argv, "e:x-")) != -1) {
56 if (asprintf(&buf, "%s %s", buf, optarg) == -1)
72 init_bmachine(extended_regs);
79 src_setstring(&src, buf);
87 file = fopen(argv[0], "r");
89 err(1, "cannot open file %s", argv[0]);
90 src_setstream(&src, file);
95 * BSD and Solaris dc(1) continue with stdin after processing
96 * the file given as the argument. We follow GNU dc(1).
100 src_setstream(&src, stdin);
101 reset_bmachine(&src);