summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/dc/misc.c
diff options
context:
space:
mode:
authorphil <phil@NetBSD.org>1997-04-29 00:34:25 +0000
committerphil <phil@NetBSD.org>1997-04-29 00:34:25 +0000
commitbc4e66aef97f86fd61dc4cd478f6564b0b3857b3 (patch)
tree32b08a693b1a9045e32f00e5b1542f8fc92f24db /gnu/usr.bin/dc/misc.c
parentf18cfec654719ae1e1ce6725d7b6fd8834919d6a (diff)
Complete import of bc-1.04 by updating dc.
Diffstat (limited to 'gnu/usr.bin/dc/misc.c')
-rw-r--r--gnu/usr.bin/dc/misc.c80
1 files changed, 10 insertions, 70 deletions
diff --git a/gnu/usr.bin/dc/misc.c b/gnu/usr.bin/dc/misc.c
index a7d3a5ffa37..8c360cacb05 100644
--- a/gnu/usr.bin/dc/misc.c
+++ b/gnu/usr.bin/dc/misc.c
@@ -1,7 +1,7 @@
/*
- * implement the "dc" Desk Calculator language.
+ * misc. functions for the "dc" Desk Calculator language.
*
- * Copyright (C) 1994 Free Software Foundation, Inc.
+ * Copyright (C) 1994, 1997 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,9 +19,6 @@
* Inc.; 675 Mass Ave. Cambridge, MA 02139, USA.
*/
-/* Written with strong hiding of implementation details
- * in their own specialized modules.
- */
/* This module contains miscelaneous functions that have no
* special knowledge of any private data structures.
* They could all be moved to their own separate modules, but
@@ -47,73 +44,16 @@
# define isgraph isprint
# endif
#endif
+#include <getopt.h>
#include "dc.h"
#include "dc-proto.h"
-#include "dc-version.h"
+#include "version.h"
-#ifndef EXIT_SUCCESS /* C89 <stdlib.h> */
-# define EXIT_SUCCESS 0
-#endif
#ifndef EXIT_FAILURE /* C89 <stdlib.h> */
# define EXIT_FAILURE 1
#endif
-const char *progname; /* basename of program invocation */
-
-/* your generic usage function */
-static void
-usage DC_DECLARG((f))
- FILE *f DC_DECLEND
-{
- fprintf(f, "Usage: %s [OPTION]\n", progname);
- fprintf(f, " --help display this help and exit\n");
- fprintf(f, " --version output version information and exit\n");
-}
-
-/* returns a pointer to one past the last occurance of c in s,
- * or s if c does not occur in s.
- */
-static char *
-r1bindex DC_DECLARG((s, c))
- char *s DC_DECLSEP
- int c DC_DECLEND
-{
- char *p = strrchr(s, c);
-
- if (!p)
- return s;
- return p + 1;
-}
-
-
-int
-main DC_DECLARG((argc, argv))
- int argc DC_DECLSEP
- char **argv DC_DECLEND
-{
- progname = r1bindex(*argv, '/');
- if (argc>1 && strcmp(argv[1], "--version")==0){
- printf("%s\n", Version);
- return EXIT_SUCCESS;
- }else if (argc>1 && strcmp(argv[1], "--help")==0){
- usage(stdout);
- return EXIT_SUCCESS;
- }else if (argc==2 && strcmp(argv[1], "--")==0){
- /*just ignore it*/
- }else if (argc != 1){
- usage(stderr);
- return EXIT_FAILURE;
- }
-
- dc_math_init();
- dc_string_init();
- dc_register_init();
- dc_array_init();
- dc_evalfile(stdin);
- return EXIT_SUCCESS;
-}
-
/* print an "out of memory" diagnostic and exit program */
void
@@ -169,9 +109,9 @@ dc_garbage DC_DECLARG((msg, regid))
const char *msg DC_DECLSEP
int regid DC_DECLEND
{
- if (regid < 0){
+ if (regid < 0) {
fprintf(stderr, "%s: garbage %s\n", progname, msg);
- }else{
+ } else {
fprintf(stderr, "%s:%s register ", progname, msg);
dc_show_id(stderr, regid, " is garbage\n");
}
@@ -194,7 +134,7 @@ dc_system DC_DECLARG((s))
size_t len;
p = strchr(s, '\n');
- if (p){
+ if (p) {
len = p - s;
tmpstr = dc_malloc(len + 1);
strncpy(tmpstr, s, len);
@@ -214,11 +154,11 @@ dc_print DC_DECLARG((value, obase))
dc_data value DC_DECLSEP
int obase DC_DECLEND
{
- if (value.dc_type == DC_NUMBER){
+ if (value.dc_type == DC_NUMBER) {
dc_out_num(value.v.number, obase, DC_TRUE, DC_FALSE);
- }else if (value.dc_type == DC_STRING){
+ } else if (value.dc_type == DC_STRING) {
dc_out_str(value.v.string, DC_TRUE, DC_FALSE);
- }else{
+ } else {
dc_garbage("in data being printed", -1);
}
}