[102] | 1 | /* |
---|
| 2 | * |
---|
[1927] | 3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
| 4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
| 5 | * For copying information, see the file mit-copyright.h in this release. |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | /* |
---|
| 9 | * |
---|
[22404] | 10 | * $Id: trn_select.c,v 1.18 2006-03-10 07:11:31 ghudson Exp $ |
---|
[102] | 11 | * |
---|
| 12 | */ |
---|
[1634] | 13 | |
---|
[602] | 14 | #ifndef lint |
---|
[1634] | 15 | static char rcsid_discuss_c[] = |
---|
[22404] | 16 | "$Id: trn_select.c,v 1.18 2006-03-10 07:11:31 ghudson Exp $"; |
---|
[12459] | 17 | #endif /* lint */ |
---|
[102] | 18 | |
---|
[84] | 19 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
---|
[102] | 20 | #define MAX(a,b) ((a)>(b)?(a):(b)) |
---|
[84] | 21 | #include <stdio.h> |
---|
[22404] | 22 | #include <stdlib.h> |
---|
[1634] | 23 | #include <discuss/discuss.h> |
---|
[84] | 24 | #include "globals.h" |
---|
| 25 | |
---|
[102] | 26 | selection_list * |
---|
[1805] | 27 | sl_insert_range(low, high, flags, old_list, code_ptr) |
---|
[102] | 28 | register int low, high; |
---|
[1805] | 29 | int flags; |
---|
[102] | 30 | register selection_list *old_list; |
---|
[144] | 31 | int *code_ptr; |
---|
[102] | 32 | { |
---|
| 33 | register selection_list *p, *new; |
---|
| 34 | p = old_list; |
---|
| 35 | |
---|
| 36 | new = (selection_list *)malloc(sizeof(selection_list)); |
---|
| 37 | if (!new) { |
---|
[144] | 38 | *code_ptr = errno; |
---|
[102] | 39 | return((selection_list *)NULL); |
---|
| 40 | } |
---|
| 41 | new->low = low; |
---|
| 42 | new->high = high; |
---|
[1805] | 43 | new->flags = flags; |
---|
[102] | 44 | new->next = (selection_list *)NULL; |
---|
| 45 | |
---|
| 46 | if (!p) |
---|
[123] | 47 | return(new); /* first one, so just return it */ |
---|
[102] | 48 | |
---|
[123] | 49 | /* we just add it on to the end, and let the user lose if he |
---|
| 50 | wants...(he might want them printed/listed out of order. |
---|
| 51 | Ken, try to document... */ |
---|
[102] | 52 | |
---|
[123] | 53 | while (p->next != NULL) { |
---|
| 54 | p = p->next; |
---|
[102] | 55 | } |
---|
[123] | 56 | |
---|
| 57 | p->next = new; |
---|
| 58 | return(old_list); |
---|
[102] | 59 | } |
---|
| 60 | |
---|
| 61 | selection_list * |
---|
[1805] | 62 | sl_insert_num(num, flags, old_list, code_ptr) |
---|
[102] | 63 | int num; |
---|
[1805] | 64 | int flags; |
---|
[102] | 65 | selection_list *old_list; |
---|
[144] | 66 | int *code_ptr; |
---|
[102] | 67 | { |
---|
[1805] | 68 | return(sl_insert_range(num, num, flags, old_list, code_ptr)); |
---|
[102] | 69 | } |
---|
| 70 | |
---|
[84] | 71 | void |
---|
[102] | 72 | sl_free(list) |
---|
| 73 | selection_list *list; |
---|
[84] | 74 | { |
---|
[102] | 75 | register selection_list *p, *q; |
---|
| 76 | p = list; |
---|
| 77 | while (p) { |
---|
| 78 | q = p->next; |
---|
| 79 | free(p); |
---|
| 80 | p = q; |
---|
| 81 | } |
---|
| 82 | } |
---|
[84] | 83 | |
---|
[1845] | 84 | int filter_call_func (func, t, r, flags) |
---|
| 85 | int (*func)(); |
---|
[2738] | 86 | trn_info3 *t; |
---|
[1845] | 87 | int *r; |
---|
| 88 | int flags; |
---|
| 89 | { |
---|
| 90 | if (flags & filter_ONLY_DELETED) if (!(t->flags & TRN_FDELETED)) return (0); |
---|
| 91 | if (flags & filter_ONLY_INITIAL) if (t->pref) return (0); |
---|
| 92 | if (flags & filter_ONLY_TERMINAL) if (t->nref) return (0); |
---|
| 93 | /* note, FLAG_SET and FLAG_RESET are not really opposites. |
---|
| 94 | The default is to map transaction with either flag set or reset */ |
---|
| 95 | if (flags & filter_FLAG_SET) if (!(t->flags & TRN_FLAG1)) return (0); |
---|
| 96 | if (flags & filter_FLAG_RESET) if (t->flags & TRN_FLAG1) return (0); |
---|
| 97 | return (func (t, r)); |
---|
| 98 | } |
---|
| 99 | |
---|
[102] | 100 | int |
---|
[1845] | 101 | sl_map(func, list, filter_flags) |
---|
[1805] | 102 | int (*func)(); /* return 0 -> continue */ |
---|
| 103 | selection_list *list; |
---|
[1845] | 104 | int filter_flags; |
---|
[102] | 105 | { |
---|
[1805] | 106 | register selection_list *p; |
---|
| 107 | register int i; |
---|
| 108 | int result,trn_no; |
---|
[2738] | 109 | trn_info3 t_info; |
---|
[1805] | 110 | |
---|
| 111 | flag_interrupts(); |
---|
| 112 | for (p = list; p; p = p->next) { |
---|
| 113 | if ((p->flags & flag_AREF)) { /* Handle aref */ |
---|
[2738] | 114 | dsc_get_trn_info3 (&dsc_public.nb, p->low, &t_info, &result); |
---|
[1805] | 115 | t_info.current = p->low; |
---|
| 116 | if (result != 0) { |
---|
[1845] | 117 | filter_call_func(func, &t_info, &result, filter_flags); |
---|
[2738] | 118 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 119 | if (result != 0) { |
---|
| 120 | return(result); |
---|
| 121 | } |
---|
| 122 | continue; |
---|
| 123 | } |
---|
| 124 | if (t_info.fref != t_info.current) { /* Get fref */ |
---|
[2738] | 125 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 126 | trn_no = t_info.fref; |
---|
[2738] | 127 | dsc_get_trn_info3 (&dsc_public.nb, trn_no, &t_info, &result); |
---|
[1805] | 128 | t_info.current = trn_no; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | do { |
---|
[1845] | 132 | filter_call_func(func, &t_info, &result, filter_flags); |
---|
[2738] | 133 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 134 | if (result != 0) |
---|
| 135 | return(result); |
---|
| 136 | |
---|
| 137 | if (interrupt) |
---|
| 138 | goto exit; |
---|
| 139 | |
---|
| 140 | trn_no = t_info.nref; |
---|
| 141 | if (trn_no != 0) { |
---|
[2738] | 142 | dsc_get_trn_info3 (&dsc_public.nb, trn_no, &t_info, &result); |
---|
[1805] | 143 | t_info.current = trn_no; |
---|
| 144 | } |
---|
| 145 | } while (trn_no != 0); |
---|
[1845] | 146 | } else if (filter_flags & |
---|
| 147 | (filter_INCLUDE_DELETED | filter_ONLY_DELETED)) { |
---|
| 148 | |
---|
| 149 | /* Range */ |
---|
[1805] | 150 | for (i = p->low; i <= p->high; i++) { |
---|
| 151 | if (i == 0) |
---|
| 152 | continue; |
---|
| 153 | |
---|
[2738] | 154 | dsc_get_trn_info3 (&dsc_public.nb, i, &t_info, &result); |
---|
[1845] | 155 | if ((result != DELETED_TRN) || (t_info.current != 0)) { |
---|
| 156 | t_info.current = i; |
---|
| 157 | filter_call_func(func, &t_info, &result, filter_flags); |
---|
| 158 | } |
---|
[2738] | 159 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 160 | if (result != 0) |
---|
| 161 | return(result); |
---|
| 162 | |
---|
| 163 | if (interrupt) |
---|
| 164 | goto exit; |
---|
| 165 | } |
---|
| 166 | } else { /* Walk chains where possible */ |
---|
| 167 | trn_no = p->low; |
---|
| 168 | if (trn_no < dsc_public.m_info.first) |
---|
| 169 | trn_no = dsc_public.m_info.first; |
---|
| 170 | |
---|
| 171 | while (trn_no != 0 && trn_no <= p->high) { |
---|
| 172 | if (interrupt) |
---|
| 173 | goto exit; |
---|
| 174 | |
---|
[2738] | 175 | dsc_get_trn_info3(&dsc_public.nb, trn_no, &t_info, &result); |
---|
[1805] | 176 | t_info.current = trn_no; |
---|
| 177 | |
---|
| 178 | if (result == DELETED_TRN) { |
---|
| 179 | trn_no++; |
---|
[2738] | 180 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 181 | continue; |
---|
| 182 | } |
---|
| 183 | |
---|
[1845] | 184 | filter_call_func(func, &t_info, &result, filter_flags); |
---|
[2738] | 185 | dsc_destroy_trn_info3(&t_info); |
---|
[1805] | 186 | if (result != 0) |
---|
| 187 | return(result); |
---|
| 188 | |
---|
| 189 | trn_no = t_info.next; |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | } |
---|
[220] | 193 | exit: |
---|
[1805] | 194 | dont_flag_interrupts(); |
---|
| 195 | return(0); |
---|
[84] | 196 | } |
---|
| 197 | |
---|
[102] | 198 | selection_list * |
---|
| 199 | trn_select(t_info, string, old_sl_ptr, code_ptr) |
---|
[84] | 200 | trn_info *t_info; |
---|
[102] | 201 | char *string; |
---|
| 202 | selection_list *old_sl_ptr; |
---|
[144] | 203 | register int *code_ptr; |
---|
[84] | 204 | { |
---|
[1805] | 205 | int low, high, flags; |
---|
[84] | 206 | |
---|
[144] | 207 | *code_ptr = trnexpr_parse(&dsc_public.m_info, t_info, string, |
---|
[1805] | 208 | &low, &high, &flags); |
---|
[102] | 209 | if (*code_ptr != 0) |
---|
| 210 | return((selection_list *)NULL); |
---|
[1805] | 211 | old_sl_ptr = sl_insert_range(low, high, flags, old_sl_ptr, code_ptr); |
---|
[102] | 212 | return(old_sl_ptr); |
---|
[84] | 213 | } |
---|