1 /*- 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Peter McIlroy. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)sort.h 8.1 (Berkeley) 06/06/93 11 */ 12 13 #include <sys/param.h> 14 15 #include <db.h> 16 #include <err.h> 17 #include <errno.h> 18 #include <fcntl.h> 19 #include <limits.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #define NBINS 256 24 #define MAXMERGE 16 25 26 /* values for masks, weights, and other flags. */ 27 #define I 1 /* mask out non-printable characters */ 28 #define D 2 /* sort alphanumeric characters only */ 29 #define N 4 /* Field is a number */ 30 #define F 8 /* weight lower and upper case the same */ 31 #define R 16 /* Field is reversed with respect to the global weight */ 32 #define BI 32 /* ignore blanks in icol */ 33 #define BT 64 /* ignore blanks in tcol */ 34 35 /* masks for delimiters: blanks, fields, and termination. */ 36 #define BLANK 1 /* ' ', '\t'; '\n' if -T is invoked */ 37 #define FLD_D 2 /* ' ', '\t' default; from -t otherwise */ 38 #define REC_D_F 4 /* '\n' default; from -T otherwise */ 39 40 #define ND 10 /* limit on number of -k options. */ 41 42 #define min(a, b) ((a) < (b) ? (a) : (b)) 43 #define max(a, b) ((a) > (b) ? (a) : (b)) 44 45 #define FCLOSE(file) { \ 46 if (EOF == fclose(file)) \ 47 err(2, "%s", file); \ 48 } 49 50 #define EWRITE(ptr, size, n, f) { \ 51 if (!fwrite(ptr, size, n, f)) \ 52 err(2, NULL); \ 53 } 54 55 /* length of record is currently limited to 2^16 - 1 */ 56 typedef u_short length_t; 57 58 #define SALIGN(n) ((n+1) & ~1) 59 60 /* a record is a key/line pair starting at rec.data. It has a total length 61 * and an offset to the start of the line half of the pair. 62 */ 63 typedef struct recheader { 64 length_t length; 65 length_t offset; 66 u_char data[1]; 67 } RECHEADER; 68 69 typedef struct trecheader { 70 length_t length; 71 length_t offset; 72 } TRECHEADER; 73 74 /* This is the column as seen by struct field. It is used by enterfield. 75 * They are matched with corresponding coldescs during initialization. 76 */ 77 struct column { 78 struct coldesc *p; 79 int num; 80 int indent; 81 }; 82 83 /* a coldesc has a number and pointers to the beginning and end of the 84 * corresponding column in the current line. This is determined in enterkey. 85 */ 86 typedef struct coldesc { 87 u_char *start; 88 u_char *end; 89 int num; 90 } COLDESC; 91 92 /* A field has an initial and final column; an omitted final column 93 * implies the end of the line. Flags regulate omission of blanks and 94 * numerical sorts; mask determines which characters are ignored (from -i, -d); 95 * weights determines the sort weights of a character (from -f, -r). 96 */ 97 struct field { 98 struct column icol; 99 struct column tcol; 100 u_int flags; 101 u_char *mask; 102 u_char *weights; 103 }; 104 105 union f_handle { 106 int top; 107 char **names; 108 }; 109 extern int PANIC; /* maximum depth of fsort before fmerge is called */ 110 extern u_char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS]; 111 extern u_char alltable[NBINS], dtable[NBINS], itable[NBINS]; 112 extern u_char d_mask[NBINS]; 113 extern int SINGL_FLD, SEP_FLAG, UNIQUE; 114 extern int REC_D; 115 116 #include "extern.h" 117