Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-socketcan]: src/usr.bin/dc 758515
details: https://anonhg.NetBSD.org/src/rev/373f56d9c975
branches: bouyer-socketcan
changeset: 820864:373f56d9c975
user: christos <christos%NetBSD.org@localhost>
date: Mon Apr 10 16:37:49 2017 +0000
description:
758515
diffstat:
usr.bin/dc/Makefile | 25 +
usr.bin/dc/USD.doc/Makefile | 8 +
usr.bin/dc/bcode.c | 1762 +++++++++++++++++++++++++++++++++++++++++++
usr.bin/dc/dc.1 | 538 +++++++++++++
usr.bin/dc/dc.c | 125 +++
usr.bin/dc/inout.c | 414 ++++++++++
usr.bin/dc/main.c | 39 +
usr.bin/dc/mem.c | 105 ++
usr.bin/dc/misc.c | 73 +
usr.bin/dc/stack.c | 356 ++++++++
10 files changed, 3445 insertions(+), 0 deletions(-)
diffs (truncated from 3485 to 300 lines):
diff -r 3335add578c2 -r 373f56d9c975 usr.bin/dc/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/dc/Makefile Mon Apr 10 16:37:49 2017 +0000
@@ -0,0 +1,25 @@
+# $NetBSD: Makefile,v 1.2.2.2 2017/04/10 16:37:49 christos Exp $
+
+.include <bsd.own.mk>
+
+PROG= dc
+SRCS= main.c dc.c bcode.c inout.c mem.c stack.c
+
+.if ${MKCRYPTO:Uno} == "yes"
+WARNS=6
+LDADD= -lcrypto
+DPADD= ${LIBCRYPTO}
+.else
+OPENSSL=${NETBSDSRCDIR}/crypto/external/bsd/openssl/dist
+.PATH: ${OPENSSL}/crypto/bn
+CPPFLAGS+=-I${OPENSSL} -I${OPENSSL}/crypto
+SRCS+= bn_lib.c bn_add.c bn_mul.c bn_div.c bn_asm.c bn_word.c bn_shift.c
+SRCS+= bn_ctx.c bn_exp.c bn_mod.c bn_sqr.c bn_mont.c bn_recp.c bn_gcd.c
+SRCS+= misc.c
+COPTS.bn_lib.c += -Wno-cast-qual
+.endif
+
+SUBDIR+=USD.doc
+
+.include <bsd.prog.mk>
+.include <bsd.subdir.mk>
diff -r 3335add578c2 -r 373f56d9c975 usr.bin/dc/USD.doc/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/dc/USD.doc/Makefile Mon Apr 10 16:37:49 2017 +0000
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.2.2.2 2017/04/10 16:37:49 christos Exp $
+
+SECTION=reference/ref1
+ARTICLE=dc
+SRCS= dc
+MACROS= -ms
+
+.include <bsd.doc.mk>
diff -r 3335add578c2 -r 373f56d9c975 usr.bin/dc/bcode.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/dc/bcode.c Mon Apr 10 16:37:49 2017 +0000
@@ -0,0 +1,1762 @@
+/* $NetBSD: bcode.c,v 1.2.2.2 2017/04/10 16:37:49 christos Exp $ */
+/* $OpenBSD: bcode.c,v 1.51 2017/02/26 11:29:55 otto Exp $ */
+
+/*
+ * Copyright (c) 2003, Otto Moerbeek <otto%drijf.net@localhost>
+ *
+ * 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/cdefs.h>
+__RCSID("$NetBSD: bcode.c,v 1.2.2.2 2017/04/10 16:37:49 christos Exp $");
+
+#include <err.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "extern.h"
+
+/* #define DEBUGGING */
+
+#define MAX_ARRAY_INDEX 2048
+#define READSTACK_SIZE 8
+
+#define NO_ELSE -2 /* -1 is EOF */
+#define REG_ARRAY_SIZE_SMALL (UCHAR_MAX + 1)
+#define REG_ARRAY_SIZE_BIG (UCHAR_MAX + 1 + USHRT_MAX + 1)
+
+struct bmachine {
+ struct stack stack;
+ u_int scale;
+ u_int obase;
+ u_int ibase;
+ size_t readsp;
+ bool extended_regs;
+ size_t reg_array_size;
+ struct stack *reg;
+ volatile sig_atomic_t interrupted;
+ struct source *readstack;
+ size_t readstack_sz;
+};
+
+static struct bmachine bmachine;
+static void sighandler(int);
+
+static __inline int readch(void);
+static __inline void unreadch(void);
+static __inline char *readline(void);
+static __inline void src_free(void);
+
+static __inline u_int max(u_int, u_int);
+static u_long get_ulong(struct number *);
+
+static __inline void push_number(struct number *);
+static __inline void push_string(char *);
+static __inline void push(struct value *);
+static __inline struct value *tos(void);
+static __inline struct number *pop_number(void);
+static __inline char *pop_string(void);
+static __inline void clear_stack(void);
+static __inline void print_tos(void);
+static void print_err(void);
+static void pop_print(void);
+static void pop_printn(void);
+static __inline void print_stack(void);
+static __inline void dup(void);
+static void swap(void);
+static void drop(void);
+
+static void get_scale(void);
+static void set_scale(void);
+static void get_obase(void);
+static void set_obase(void);
+static void get_ibase(void);
+static void set_ibase(void);
+static void stackdepth(void);
+static void push_scale(void);
+static u_int count_digits(const struct number *);
+static void num_digits(void);
+static void to_ascii(void);
+static void push_line(void);
+static void comment(void);
+static void badd(void);
+static void bsub(void);
+static void bmul(void);
+static void bdiv(void);
+static void bmod(void);
+static void bdivmod(void);
+static void bexp(void);
+static bool bsqrt_stop(const BIGNUM *, const BIGNUM *, u_int *);
+static void bsqrt(void);
+static void not(void);
+static void equal_numbers(void);
+static void less_numbers(void);
+static void lesseq_numbers(void);
+static void equal(void);
+static void not_equal(void);
+static void less(void);
+static void not_less(void);
+static void greater(void);
+static void not_greater(void);
+static void not_compare(void);
+static bool compare_numbers(enum bcode_compare, struct number *,
+ struct number *);
+static void compare(enum bcode_compare);
+static int readreg(void);
+static void load(void);
+static void store(void);
+static void load_stack(void);
+static void store_stack(void);
+static void load_array(void);
+static void store_array(void);
+static void nop(void);
+static void quit(void);
+static void quitN(void);
+static void skipN(void);
+static void skip_until_mark(void);
+static void parse_number(void);
+static void unknown(void);
+static void eval_string(char *);
+static void eval_line(void);
+static void eval_tos(void);
+
+
+typedef void (*opcode_function)(void);
+
+struct jump_entry {
+ u_char ch;
+ opcode_function f;
+};
+
+static opcode_function jump_table[UCHAR_MAX];
+
+static const struct jump_entry jump_table_data[] = {
+ { ' ', nop },
+ { '!', not_compare },
+ { '#', comment },
+ { '%', bmod },
+ { '(', less_numbers },
+ { '*', bmul },
+ { '+', badd },
+ { '-', bsub },
+ { '.', parse_number },
+ { '/', bdiv },
+ { '0', parse_number },
+ { '1', parse_number },
+ { '2', parse_number },
+ { '3', parse_number },
+ { '4', parse_number },
+ { '5', parse_number },
+ { '6', parse_number },
+ { '7', parse_number },
+ { '8', parse_number },
+ { '9', parse_number },
+ { ':', store_array },
+ { ';', load_array },
+ { '<', less },
+ { '=', equal },
+ { '>', greater },
+ { '?', eval_line },
+ { 'A', parse_number },
+ { 'B', parse_number },
+ { 'C', parse_number },
+ { 'D', parse_number },
+ { 'E', parse_number },
+ { 'F', parse_number },
+ { 'G', equal_numbers },
+ { 'I', get_ibase },
+ { 'J', skipN },
+ { 'K', get_scale },
+ { 'L', load_stack },
+ { 'M', nop },
+ { 'N', not },
+ { 'O', get_obase },
+ { 'P', pop_print },
+ { 'Q', quitN },
+ { 'R', drop },
+ { 'S', store_stack },
+ { 'X', push_scale },
+ { 'Z', num_digits },
+ { '[', push_line },
+ { '\f', nop },
+ { '\n', nop },
+ { '\r', nop },
+ { '\t', nop },
+ { '^', bexp },
+ { '_', parse_number },
+ { 'a', to_ascii },
+ { 'c', clear_stack },
+ { 'd', dup },
+ { 'e', print_err },
+ { 'f', print_stack },
+ { 'i', set_ibase },
+ { 'k', set_scale },
+ { 'l', load },
+ { 'n', pop_printn },
+ { 'o', set_obase },
+ { 'p', print_tos },
+ { 'q', quit },
+ { 'r', swap },
+ { 's', store },
+ { 'v', bsqrt },
+ { 'x', eval_tos },
+ { 'z', stackdepth },
+ { '{', lesseq_numbers },
+ { '~', bdivmod }
+};
+
+#define JUMP_TABLE_DATA_SIZE \
+ (sizeof(jump_table_data)/sizeof(jump_table_data[0]))
+
+/* ARGSUSED */
+static void
+sighandler(int ignored)
+{
+ bmachine.interrupted = true;
+}
+
+void
+init_bmachine(bool extended_registers)
+{
+ size_t i;
+
+ bmachine.extended_regs = extended_registers;
+ bmachine.reg_array_size = bmachine.extended_regs ?
+ REG_ARRAY_SIZE_BIG : REG_ARRAY_SIZE_SMALL;
+
+ bmachine.reg = calloc(bmachine.reg_array_size,
+ sizeof(bmachine.reg[0]));
+ if (bmachine.reg == NULL)
+ err(1, NULL);
+
+ for (i = 0; i < UCHAR_MAX; i++)
+ jump_table[i] = unknown;
+ for (i = 0; i < JUMP_TABLE_DATA_SIZE; i++)
+ jump_table[jump_table_data[i].ch] = jump_table_data[i].f;
+
+ stack_init(&bmachine.stack);
+
+ for (i = 0; i < bmachine.reg_array_size; i++)
+ stack_init(&bmachine.reg[i]);
+
+ bmachine.readstack_sz = READSTACK_SIZE;
+ bmachine.readstack = calloc(sizeof(struct source),
Home |
Main Index |
Thread Index |
Old Index