1 /* System dependencies */ 2 #include "dep.h" 3 4 struct Format { 5 char *text; /* The input format text */ 6 char *p; /* For walking through the input. */ 7 int file; /* !0 means format comes from file */ 8 int linenum; /* current line number in format list */ 9 char *line; /* pointer to start of current line */ 10 char *item; /* pointer to one past last item */ 11 }; 12 extern long count_reg[256]; 13 extern int process_to_eof; 14 extern int debug; 15 extern char *prog; 16 #ifndef VIZ_MAIN 17 extern struct Format Fmt; 18 #endif 19 20 #define UPTO_EOF -1000 /* Code for '$' used as a number; must not be -255..0, 21 * because those are the codes for the $x registers. 22 */ 23 24 #define T_LISTHEAD 00000001 25 #define T_COPYOUT 00000010 26 #define T_IOSPEC 00000100 27 #define T_NEWLINE 00001000 28 #define T_MATH 00010000 29 #define T_SEEK 00100000 30 31 typedef struct { 32 short size; 33 char ichar; 34 char ochar; 35 unsigned char reg_no; /* If reg_no != 0, indicates that the value 36 * read in at runtime is to be stored in 37 * count_reg[reg_no]. 38 */ 39 char *fmt; /* Format spec, such as "%d", to control 40 * printing of these data. 41 */ 42 43 } IOSPEC; 44 45 typedef struct member *LISTHEAD; 46 47 typedef struct { 48 short reg_no; 49 short operator; 50 long operand; 51 } REG_MATH; 52 53 typedef struct { 54 long count; 55 int direction; 56 } STRM_SEEK; 57 58 typedef union { 59 LISTHEAD sublist; 60 char *copyout; 61 IOSPEC iospec; 62 REG_MATH math; 63 STRM_SEEK seek; 64 } ITEM; 65 66 typedef struct member { 67 struct member *next; 68 69 int type; /* One of T_LISTHEAD, T_COPYOUT, T_IOSPEC, 70 * T_NEWLINE, T_MATH, T_PRINT 71 */ 72 73 long count; /* Number of repeats of u.<type>. 74 * If count < 0, take actual count from 75 * count_reg[-count]. 76 */ 77 78 ITEM u; /* union of listhead ptr, copyout ptr, iospec, math */ 79 } MEMBER; 80 81 typedef MEMBER *MEMP; 82 83 #define NIL ((MEMP) 0) 84 85 extern MEMP rootlist; 86 87 88 typedef union { 89 char *sval; 90 int ival; 91 long lval; 92 unsigned long nval; 93 ITEM item; 94 MEMP memp; 95 } YYSTYPE; 96 97 extern void printlist(); /* Prints a list in human-readable form */ 98 extern int condenselist(); /* Condenses a list to most efficient form */ 99 extern int listlen(); /* Length of a list */ 100 extern int duplicates(); /* Non-zero if two lists or mem's are similar */ 101 extern MEMP newlist(); /* Creates a new listhead */ 102 extern MEMP addmember(); /* Adds a member to the tail of a list */ 103 extern IOSPEC makecore(); /* Creates the basic structure of a member */ 104 extern IOSPEC makecorepct(); /* like makecore(), but takes user's own fmt */ 105 extern int defaultichar(); /* Returns default ichar for given ochar */ 106 extern int defaultochar(); /* Returns default ochar for given ichar */ 107 extern int getsize(); /* Returns size of input data, given ichar */ 108 extern int inval4reg(); /* Checks if datum can be stored in a #x reg */ 109 extern int comb_dup_nl(); /* Combines duplicate non-list members */ 110 extern int comb_dup_list(); /* Combines duplicates sublists */ 111 extern int merge_sublist(); /* Merges a sublist into parent list */ 112 extern void viz_decode(); /* Interprets viz copyouts */ 113 114 115 116 /* REVERSE_nn reverses an nn-char atomic object, x. It 117 * requires an additional argument Type_nn that specifies the 118 * type of the atomic object. 119 */ 120 #define REVERSE_2(x, Type_2) { \ 121 union { char c[2]; Type_2 i; } u0, u1; \ 122 u0.i = (x); \ 123 u1.c[1] = u0.c[0]; \ 124 u1.c[0] = u0.c[1]; \ 125 (x) = u1.i; \ 126 } 127 128 #define REVERSE_3(x, Type_3) { \ 129 union { char c[3]; Type_3 i; } u0, u1; \ 130 u0.i = (x); \ 131 u1.c[2] = u0.c[0]; \ 132 u1.c[1] = u0.c[1]; \ 133 u1.c[0] = u0.c[2]; \ 134 (x) = u1.i; \ 135 } 136 137 #define REVERSE_4(x, Type_4) { \ 138 union { char c[4]; Type_4 i; } u0, u1; \ 139 u0.i = (x); \ 140 u1.c[3] = u0.c[0]; \ 141 u1.c[2] = u0.c[1]; \ 142 u1.c[1] = u0.c[2]; \ 143 u1.c[0] = u0.c[3]; \ 144 (x) = u1.i; \ 145 } 146 147 #define REVERSE_5(x, Type_5) { \ 148 union { char c[5]; Type_5 i; } u0, u1; \ 149 u0.i = (x); \ 150 u1.c[4] = u0.c[0]; \ 151 u1.c[3] = u0.c[1]; \ 152 u1.c[2] = u0.c[2]; \ 153 u1.c[1] = u0.c[3]; \ 154 u1.c[0] = u0.c[4]; \ 155 (x) = u1.i; \ 156 } 157 158 #define REVERSE_6(x, Type_6) { \ 159 union { char c[6]; Type_6 i; } u0, u1; \ 160 u0.i = (x); \ 161 u1.c[5] = u0.c[0]; \ 162 u1.c[4] = u0.c[1]; \ 163 u1.c[3] = u0.c[2]; \ 164 u1.c[2] = u0.c[3]; \ 165 u1.c[1] = u0.c[4]; \ 166 u1.c[0] = u0.c[5]; \ 167 (x) = u1.i; \ 168 } 169 170 #define REVERSE_7(x, Type_7) { \ 171 union { char c[7]; Type_7 i; } u0, u1; \ 172 u0.i = (x); \ 173 u1.c[6] = u0.c[0]; \ 174 u1.c[5] = u0.c[1]; \ 175 u1.c[4] = u0.c[2]; \ 176 u1.c[3] = u0.c[3]; \ 177 u1.c[2] = u0.c[4]; \ 178 u1.c[1] = u0.c[5]; \ 179 u1.c[0] = u0.c[6]; \ 180 (x) = u1.i; \ 181 } 182 183 #define REVERSE_8(x, Type_8) { \ 184 union { char c[8]; Type_8 i; } u0, u1; \ 185 u0.i = (x); \ 186 u1.c[7] = u0.c[0]; \ 187 u1.c[6] = u0.c[1]; \ 188 u1.c[5] = u0.c[2]; \ 189 u1.c[4] = u0.c[3]; \ 190 u1.c[3] = u0.c[4]; \ 191 u1.c[2] = u0.c[5]; \ 192 u1.c[1] = u0.c[6]; \ 193 u1.c[0] = u0.c[7]; \ 194 (x) = u1.i; \ 195 } 196 197 #if ( L_SHORT == 2 ) 198 #define REVERSE_SHORT REVERSE_2 199 #endif 200 #if ( L_SHORT == 3 ) 201 #define REVERSE_SHORT REVERSE_3 202 #endif 203 #if ( L_SHORT == 4 ) 204 #define REVERSE_SHORT REVERSE_4 205 #endif 206 #if ( L_SHORT == 5 ) 207 #define REVERSE_SHORT REVERSE_5 208 #endif 209 #if ( L_SHORT == 6 ) 210 #define REVERSE_SHORT REVERSE_6 211 #endif 212 #if ( L_SHORT == 7 ) 213 #define REVERSE_SHORT REVERSE_7 214 #endif 215 #if ( L_SHORT == 8 ) 216 #define REVERSE_SHORT REVERSE_8 217 #endif 218 219 220 #if ( L_INT == 2 ) 221 #define REVERSE_INT REVERSE_2 222 #endif 223 #if ( L_INT == 3 ) 224 #define REVERSE_INT REVERSE_3 225 #endif 226 #if ( L_INT == 4 ) 227 #define REVERSE_INT REVERSE_4 228 #endif 229 #if ( L_INT == 5 ) 230 #define REVERSE_INT REVERSE_5 231 #endif 232 #if ( L_INT == 6 ) 233 #define REVERSE_INT REVERSE_6 234 #endif 235 #if ( L_INT == 7 ) 236 #define REVERSE_INT REVERSE_7 237 #endif 238 #if ( L_INT == 8 ) 239 #define REVERSE_INT REVERSE_8 240 #endif 241 242 #if ( L_LONG == 2 ) 243 #define REVERSE_LONG REVERSE_2 244 #endif 245 #if ( L_LONG == 3 ) 246 #define REVERSE_LONG REVERSE_3 247 #endif 248 #if ( L_LONG == 4 ) 249 #define REVERSE_LONG REVERSE_4 250 #endif 251 #if ( L_LONG == 5 ) 252 #define REVERSE_LONG REVERSE_5 253 #endif 254 #if ( L_LONG == 6 ) 255 #define REVERSE_LONG REVERSE_6 256 #endif 257 #if ( L_LONG == 7 ) 258 #define REVERSE_LONG REVERSE_7 259 #endif 260 #if ( L_LONG == 8 ) 261 #define REVERSE_LONG REVERSE_8 262 #endif 263 264 265 /* Macro <S><o>_fmt give format for printing data of size S in format o */ 266 267 #define Bb_fmt "0b%s " 268 #define Bo_fmt "%#5o " 269 #define Bd_fmt "%5d " 270 #define Bu_fmt "%4u " 271 #define Bx_fmt "%#5x " 272 273 #define Cb_fmt "0b%s " 274 #define Co_fmt "%#5o " 275 #define Cd_fmt "%5d " 276 #define Cu_fmt "%4u " 277 #define Cx_fmt "%#5x " 278 279 #define Zb_fmt "0b%s " 280 #define Zo_fmt "%#5o " 281 #define Zd_fmt "%5d " 282 #define Zu_fmt "%4u " 283 #define Zx_fmt "%#5x " 284 285 #if ( L_SHORT == 2 ) 286 #define Sb_fmt "0b%s,%s " /* Args are 1 string per byte */ 287 #endif 288 #if ( L_SHORT == 3 ) 289 #define Sb_fmt "0b%s,%s,%s " 290 #endif 291 #if ( L_SHORT == 4 ) 292 #define Sb_fmt "0b%s,%s,%s,%s " 293 #endif 294 #if ( L_SHORT == 5 ) 295 #define Sb_fmt "0b%s,%s,%s,%s,%s " 296 #endif 297 #if ( L_SHORT == 6 ) 298 #define Sb_fmt "0b%s,%s,%s,%s,%s,%s " 299 #endif 300 #if ( L_SHORT == 7 ) 301 #define Sb_fmt "0b%s,%s,%s,%s,%s,%s,%s " 302 #endif 303 #if ( L_SHORT == 8 ) 304 #define Sb_fmt "0b%s,%s,%s,%s,%s,%s,%s,%s " 305 #endif 306 #define So_fmt "%#8o " 307 #define Sd_fmt "%6d " 308 #define Su_fmt "%6u " 309 #define Sx_fmt "%#7x " 310 311 #if ( L_INT == 2 ) 312 #define Ib_fmt "0b%s,%s " /* Args are 1 string per byte */ 313 #endif 314 #if ( L_INT == 3 ) 315 #define Ib_fmt "0b%s,%s,%s " 316 #endif 317 #if ( L_INT == 4 ) 318 #define Ib_fmt "0b%s,%s,%s,%s " 319 #endif 320 #if ( L_INT == 5 ) 321 #define Ib_fmt "0b%s,%s,%s,%s,%s " 322 #endif 323 #if ( L_INT == 6 ) 324 #define Ib_fmt "0b%s,%s,%s,%s,%s,%s " 325 #endif 326 #if ( L_INT == 7 ) 327 #define Ib_fmt "0b%s,%s,%s,%s,%s,%s,%s " 328 #endif 329 #if ( L_INT == 8 ) 330 #define Ib_fmt "0b%s,%s,%s,%s,%s,%s,%s,%s " 331 #endif 332 #define Io_fmt "%#14o " 333 #define Id_fmt "%12d " 334 #define Iu_fmt "%12u " 335 #define Ix_fmt "%#10x " 336 337 #if ( L_LONG == 2 ) 338 #define Lb_fmt "0b%s,%s " /* Args are 1 string per byte */ 339 #endif 340 #if ( L_LONG == 3 ) 341 #define Lb_fmt "0b%s,%s,%s " 342 #endif 343 #if ( L_LONG == 4 ) 344 #define Lb_fmt "0b%s,%s,%s,%s " 345 #endif 346 #if ( L_LONG == 5 ) 347 #define Lb_fmt "0b%s,%s,%s,%s,%s " 348 #endif 349 #if ( L_LONG == 6 ) 350 #define Lb_fmt "0b%s,%s,%s,%s,%s,%s " 351 #endif 352 #if ( L_LONG == 7 ) 353 #define Lb_fmt "0b%s,%s,%s,%s,%s,%s,%s " 354 #endif 355 #if ( L_LONG == 8 ) 356 #define Lb_fmt "0b%s,%s,%s,%s,%s,%s,%s,%s " 357 #endif 358 #define Lo_fmt "%#14lo " 359 #define Ld_fmt "%12ld " 360 #define Lu_fmt "%12lu " 361 #define Lx_fmt "%#10lx " 362 363 #define Ff_fmt "%7f " 364 #define Fg_fmt "%7g " 365 366 #define Df_fmt "%.16f " 367 #define Dg_fmt "%.16g " 368 369 /* Buffer size for fread */ 370 #define BUFFERSIZE 8192 371