aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/dc/bcode.h
diff options
context:
space:
mode:
authorGabor Kovesdan <gabor@FreeBSD.org>2010-01-20 21:30:52 +0000
committerGabor Kovesdan <gabor@FreeBSD.org>2010-01-20 21:30:52 +0000
commitfdf1f88bcecce7bedef674be598a8cf89c3a3f1c (patch)
tree96e08d56eaa68b31f8e98a726fe2be11d38299d2 /usr.bin/dc/bcode.h
parent32fc554ec6f84b8597d61d15f33f06713224123b (diff)
downloadsrc-fdf1f88bcecce7bedef674be598a8cf89c3a3f1c.tar.gz
src-fdf1f88bcecce7bedef674be598a8cf89c3a3f1c.zip
Replace GNU bc/dc with BSDL versions ported from OpenBSD. They have a good
compatibility level with the GNU counterparts and have shown to be mature enough. For now, the GNU versions aren't removed from the tree, just detached from the build. Sponsored by: Google Summer of Code 2008 Portbuild run by: erwin Approved by: delphij
Notes
Notes: svn path=/head/; revision=202719
Diffstat (limited to 'usr.bin/dc/bcode.h')
-rw-r--r--usr.bin/dc/bcode.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/usr.bin/dc/bcode.h b/usr.bin/dc/bcode.h
new file mode 100644
index 000000000000..df175fe1bcb8
--- /dev/null
+++ b/usr.bin/dc/bcode.h
@@ -0,0 +1,98 @@
+/* $FreeBSD$ */
+/* $OpenBSD: bcode.h,v 1.5 2006/01/16 08:09:25 otto Exp $ */
+
+/*
+ * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <openssl/bn.h>
+
+struct number {
+ BIGNUM *number;
+ u_int scale;
+};
+
+enum stacktype {
+ BCODE_NONE,
+ BCODE_NUMBER,
+ BCODE_STRING
+};
+
+enum bcode_compare {
+ BCODE_EQUAL,
+ BCODE_NOT_EQUAL,
+ BCODE_LESS,
+ BCODE_NOT_LESS,
+ BCODE_GREATER,
+ BCODE_NOT_GREATER
+};
+
+struct array;
+
+struct value {
+ union {
+ struct number *num;
+ char *string;
+ } u;
+ struct array *array;
+ enum stacktype type;
+};
+
+struct array {
+ struct value *data;
+ size_t size;
+};
+
+struct stack {
+ struct value *stack;
+ ssize_t sp;
+ ssize_t size;
+};
+
+struct source;
+
+struct vtable {
+ int (*readchar)(struct source *);
+ void (*unreadchar)(struct source *);
+ char *(*readline)(struct source *);
+ void (*free)(struct source *);
+};
+
+struct source {
+ struct vtable *vtable;
+ union {
+ FILE *stream;
+ struct {
+ u_char *buf;
+ size_t pos;
+ } string;
+ } u;
+ int lastchar;
+};
+
+void init_bmachine(bool);
+void reset_bmachine(struct source *);
+void scale_number(BIGNUM *, int);
+void normalize(struct number *, u_int);
+void eval(void);
+void pn(const char *, const struct number *);
+void pbn(const char *, const BIGNUM *);
+void negate(struct number *);
+void split_number(const struct number *, BIGNUM *, BIGNUM *);
+void bmul_number(struct number *, struct number *,
+ struct number *);
+
+extern BIGNUM zero;