[6952] | 1 | /* Copyright (C) 1988 Tim Shepard All rights reserved. */ |
---|
| 2 | |
---|
| 3 | #if defined(_AUX_SOURCE) |
---|
| 4 | #define NO_RLIMIT |
---|
| 5 | #define NO_LINEBUF |
---|
| 6 | #endif |
---|
| 7 | |
---|
| 8 | #include <ctype.h> |
---|
| 9 | #define MAXNRULES 2000 |
---|
| 10 | |
---|
| 11 | #ifdef FALSE |
---|
| 12 | #undef FALSE |
---|
| 13 | #endif |
---|
| 14 | #ifdef TRUE |
---|
| 15 | #undef TRUE |
---|
| 16 | #endif |
---|
| 17 | typedef enum bool { FALSE, TRUE} bool; |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | typedef struct boolstruct { |
---|
| 21 | enum boolexp_type { VARIABLE, UNARY, BINARY } type; |
---|
| 22 | enum bool_operator { NOT, AND, OR } op; |
---|
| 23 | char *variable; |
---|
| 24 | struct boolstruct *left; |
---|
| 25 | struct boolstruct *right; |
---|
| 26 | } *bool_exp; |
---|
| 27 | |
---|
| 28 | bool_exp bool_var(); |
---|
| 29 | bool_exp bool_not(); |
---|
| 30 | bool_exp bool_and(); |
---|
| 31 | bool_exp bool_or(); |
---|
| 32 | void bool_free(); |
---|
| 33 | bool bool_eval(); |
---|
| 34 | bool getvar(); |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | typedef struct { |
---|
| 38 | enum rule_type { R_MAP, R_CHASE, R_ACTION, R_WHEN, |
---|
| 39 | R_IF, R_IF_ELSE, R_SKIP, |
---|
| 40 | R_FRAMEMARKER } type; |
---|
| 41 | union { struct { char *globexp; |
---|
| 42 | unsigned int file_types; |
---|
| 43 | char **dests; |
---|
| 44 | } u_map; |
---|
| 45 | struct { char *globexp; } u_chase; |
---|
| 46 | struct { enum action_type |
---|
| 47 | { ACTION_COPY, ACTION_LOCAL, ACTION_LINK, |
---|
| 48 | ACTION_DELETE, ACTION_IGNORE } type; |
---|
| 49 | char *globexp; |
---|
| 50 | unsigned int file_types; |
---|
| 51 | unsigned int options; |
---|
| 52 | } u_action; |
---|
| 53 | struct { enum when_type { WHEN_SH, WHEN_CSH } type; |
---|
| 54 | char *globexp; |
---|
| 55 | unsigned int file_types; |
---|
| 56 | char **cmds; |
---|
| 57 | } u_when; |
---|
| 58 | struct { bool_exp boolexp; |
---|
| 59 | int first; |
---|
| 60 | bool inactive; /* this is not filled in by readrules */ |
---|
| 61 | } u_if; |
---|
| 62 | struct { int first; |
---|
| 63 | } u_skip; |
---|
| 64 | } u; |
---|
| 65 | } rule; |
---|
| 66 | |
---|
| 67 | #define letternum(c) (c - (isupper(c)? 'A':'a')) |
---|
| 68 | #define set_option(bf,c) (bf |= (0x01 << letternum(c))) |
---|
| 69 | #define option_on(rno,c) ((bool) ((rules[rno].type == R_ACTION)? \ |
---|
| 70 | (((rules[rno].u.u_action.options) >> letternum(c)) & 0x01): \ |
---|
| 71 | panic("option_on: rules[rno].type is not R_ACTION"))) |
---|
| 72 | |
---|
| 73 | /* definitions for 'types' field */ |
---|
| 74 | #define TYPE_D 0x01 |
---|
| 75 | #define TYPE_C 0x02 |
---|
| 76 | #define TYPE_B 0x04 |
---|
| 77 | #define TYPE_R 0x08 |
---|
| 78 | #define TYPE_L 0x10 |
---|
| 79 | #define TYPE_S 0x20 |
---|
| 80 | #define TYPE_X 0x40 |
---|
| 81 | #define TYPE_V 0x80 |
---|
| 82 | #define TYPE_ALL (TYPE_D|TYPE_C|TYPE_B|TYPE_R|TYPE_L|TYPE_S|TYPE_V) |
---|
| 83 | |
---|
| 84 | #define hastype(bf,tp) ((bool) ((bf & tp) != 0)) |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | /* now implemented as a procedure in rules.c |
---|
| 88 | #define newrule() { if (++lastrule == MAXNRULES) { \ |
---|
| 89 | fprintf(stderr,"Too many rules.\n"); \ |
---|
| 90 | exit(1); }} |
---|
| 91 | */ |
---|
| 92 | void newrule(); |
---|
| 93 | #define lstrule rules[lastrule] |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /* definitions for 'rflag' variable */ |
---|
| 97 | #define RFLAG_SCAN_TARGET 0x01 /* Target directory scan necessary */ |
---|