1 /****************************************************************************** 2 * Copyright 1995-2010,2015 by Thomas E. Dickey * 3 * All Rights Reserved. * 4 * * 5 * Permission to use, copy, modify, and distribute this software and its * 6 * documentation for any purpose and without fee is hereby granted, provided * 7 * that the above copyright notice appear in all copies and that both that * 8 * copyright notice and this permission notice appear in supporting * 9 * documentation, and that the name of the above listed copyright holder(s) * 10 * not be used in advertising or publicity pertaining to distribution of the * 11 * software without specific, written prior permission. * 12 * * 13 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD * 14 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * 15 * FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE * 16 * FOR ANY SPECIAL, 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 OR * 19 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 20 ******************************************************************************/ 21 22 /* $Id: add.h,v 1.15 2015/07/05 01:00:04 tom Exp $ 23 * 24 * common definitions for 'add' utility 25 */ 26 27 #ifndef ADD_H 28 #define ADD_H 29 30 #if defined(vaxc) || defined(vms) 31 # define SYS_VMS 1 32 #elif defined(__TURBOC__) 33 # define SYS_MSDOS 1 34 # define HAVE_GETOPT_H 1 /* GNU library */ 35 #else 36 # define SYS_UNIX 1 37 # include <config.h> /* generated by 'configure' */ 38 #endif 39 40 #ifndef HAVE_BKGD 41 #define HAVE_BKGD 0 42 #endif 43 44 #ifndef HAVE_COLOR_PAIR 45 #define HAVE_COLOR_PAIR 0 46 #endif 47 48 #ifndef HAVE_DBMALLOC_H 49 #define HAVE_DBMALLOC_H 0 50 #endif 51 52 #ifndef HAVE_DEFINE_KEY 53 #define HAVE_DEFINE_KEY 0 54 #endif 55 56 #ifndef HAVE_FLASH 57 #define HAVE_FLASH 0 58 #endif 59 60 #ifndef HAVE_GETOPT 61 #define HAVE_GETOPT 0 62 #endif 63 64 #ifndef HAVE_GETOPT_H 65 #define HAVE_GETOPT_H 0 66 #endif 67 68 #ifndef HAVE_KEYPAD 69 #define HAVE_KEYPAD 0 70 #endif 71 72 #ifndef HAVE_TYPEAHEAD 73 #define HAVE_TYPEAHEAD 0 74 #endif 75 76 #ifndef HAVE_UNISTD_H 77 #define HAVE_UNISTD_H 0 78 #endif 79 80 #ifndef HAVE_WSETSCRREG 81 #define HAVE_WSETSCRREG 0 82 #endif 83 84 #ifndef HAVE_XCURSES 85 #define HAVE_XCURSES 0 86 #endif 87 88 #ifndef NEED_GETOPT_H 89 #define NEED_GETOPT_H 0 90 #endif 91 92 #ifndef HAVE_GETOPT_HEADER 93 #define HAVE_GETOPT_HEADER 0 94 #endif 95 96 #ifndef NO_LEAKS 97 #define NO_LEAKS 0 98 #endif 99 100 #ifndef SYS_MSDOS 101 #define SYS_MSDOS 0 102 #endif 103 104 #ifndef SYS_UNIX 105 #define SYS_UNIX 0 106 #endif 107 108 #ifndef SYS_VMS 109 #define SYS_VMS 0 110 #endif 111 112 #include <stdlib.h> 113 114 #if HAVE_UNISTD_H 115 #include <unistd.h> 116 #endif 117 118 #include <stdio.h> 119 #include <assert.h> 120 #include <ctype.h> 121 #include <errno.h> 122 #include <string.h> 123 #include <math.h> 124 #include <signal.h> 125 #include <sys/types.h> 126 #include <sys/stat.h> 127 128 #if NEED_GETOPT_H 129 # include <getopt.h> 130 #endif 131 #if !HAVE_GETOPT_HEADER 132 extern char *optarg; 133 extern int optind; 134 #endif 135 136 #if HAVE_DBMALLOC_H 137 #include <dbmalloc.h> 138 #define NO_LEAKS 1 139 #endif 140 141 #ifndef TRUE 142 #define TRUE (1) 143 #endif 144 145 #ifndef FALSE 146 #define FALSE (0) 147 #endif 148 149 #ifndef EXIT_SUCCESS 150 #define EXIT_SUCCESS 0 151 #endif 152 153 #ifndef EXIT_FAILURE 154 #define EXIT_FAILURE 1 155 #endif 156 157 #if SYS_UNIX 158 #define PATHSEP ':' 159 #endif 160 161 #if SYS_VMS 162 #define PATHSEP ',' 163 #define A_BOLD _BOLD 164 #define KEY_UP SMG$K_TRM_UP 165 #define KEY_DOWN SMG$K_TRM_DOWN 166 #define KEY_LEFT SMG$K_TRM_LEFT 167 #define KEY_RIGHT SMG$K_TRM_RIGHT 168 #define KEY_NPAGE SMG$K_TRM_PF3 169 #define KEY_PPAGE SMG$K_TRM_PF4 170 #define wattrset(w,a) wsetattr(w,a) 171 #define wattrclr(w,a) wclrattr(w,a) 172 #define HAVE_BEEP 1 173 #endif 174 175 #if SYS_MSDOS 176 #define PATHSEP ';' 177 #include <io.h> 178 #define HAVE_BEEP 1 179 #define HAVE_KEYPAD 1 180 #endif 181 182 /* 183 * Local declarations: 184 */ 185 #ifndef min 186 #define min(a,b) ((a)<(b)?(a):(b)) 187 #endif 188 189 #ifndef max 190 #define max(a,b) ((a)>(b)?(a):(b)) 191 #endif 192 193 #define MAXPATH 256 194 #define MAXBFR 132 195 196 #undef SIZEOF 197 #define SIZEOF(v) (sizeof(v)/sizeof(v[0])) 198 199 /* Tests for special character types */ 200 #define CTL(c) ((c) & 0x1f) 201 #define VI_UP 'k' 202 #define VI_DOWN 'j' 203 #define VI_LEFT 'h' 204 #define VI_RIGHT 'l' 205 #define VI_PPAGE CTL('B') 206 #define VI_NPAGE CTL('F') 207 208 #define UCH(c) ((unsigned char)c) 209 #define isAscii(c) ((c) < 128) /* isascii isn't portable */ 210 #define isReturn(c) ((c) == '\r' || (c) == '\n') 211 #define isDigit(c) (isAscii(c) && isdigit(UCH(c))) 212 213 #define LastData(np) ((np)->next == 0) 214 215 /* Operators */ 216 #define OP_ADD '+' 217 #define OP_SUB '-' 218 #define OP_NEG '~' 219 #define OP_MUL '*' 220 #define OP_DIV '/' 221 #define OP_INT '%' 222 #define OP_TAX '$' 223 224 #define DefaultOp(np) np->cmd 225 226 /* Miscellaneous characters */ 227 #define L_PAREN '(' 228 #define R_PAREN ')' 229 230 #define EQUALS '=' 231 #define PERIOD '.' 232 #define COMMA ',' 233 #define COLON ':' 234 235 #define EOS '\0' 236 237 /* 238 * Local types 239 */ 240 typedef int Bool; 241 typedef double Value; /* provides more precision than 'long' */ 242 243 #define DATA struct _oprs 244 DATA { 245 DATA *next; 246 DATA *prev; 247 char *txt; /* comment, if any */ 248 char cmd; /* operator */ 249 Bool psh; /* true if we use left paren instead of 'val' */ 250 int dot; /* number of digits past '.' */ 251 Value val; /* operand value */ 252 Value sum; /* running total */ 253 Value aux; /* auxiliary value (derived from 'val') */ 254 }; 255 256 #endif /* ADD_H */ 257