| 1 | /* filteritem.c - */ |
| 2 | |
| 3 | #ifndef lint |
| 4 | static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/filteritem.c,v 7.3 91/02/22 09:40:33 mrose Interim $"; |
| 5 | #endif |
| 6 | |
| 7 | /* |
| 8 | * $Header: /f/osi/quipu/dish/RCS/filteritem.c,v 7.3 91/02/22 09:40:33 mrose Interim $ |
| 9 | * |
| 10 | * |
| 11 | * $Log: filteritem.c,v $ |
| 12 | * Revision 7.3 91/02/22 09:40:33 mrose |
| 13 | * Interim 6.8 |
| 14 | * |
| 15 | * Revision 7.2 90/10/17 11:55:20 mrose |
| 16 | * sync |
| 17 | * |
| 18 | * Revision 7.1 90/07/09 14:47:10 mrose |
| 19 | * sync |
| 20 | * |
| 21 | * Revision 7.0 89/11/23 22:20:07 mrose |
| 22 | * Release 6.0 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * NOTICE |
| 28 | * |
| 29 | * Acquisition, use, and distribution of this module and related |
| 30 | * materials are subject to the restrictions of a license agreement. |
| 31 | * Consult the Preface in the User's Manual for the full terms of |
| 32 | * this agreement. |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | #include "quipu/util.h" |
| 38 | #include "quipu/ds_search.h" |
| 39 | |
| 40 | #define OPT (!frompipe || rps -> ps_byteno == 0 ? opt : rps) |
| 41 | #define RPS (!frompipe || opt -> ps_byteno == 0 ? rps : opt) |
| 42 | extern char frompipe; |
| 43 | extern PS opt, rps; |
| 44 | |
| 45 | /* Regular Expression parser written by P.Sharpe */ |
| 46 | /* QUIPU specific tailoring by CJR */ |
| 47 | |
| 48 | #define debug(a,b) /* remove debug statements */ |
| 49 | |
| 50 | Filter get_filter (); |
| 51 | char *TidyString (); |
| 52 | |
| 53 | filteritem (str, fltr) |
| 54 | char *str; |
| 55 | Filter fltr; |
| 56 | { |
| 57 | |
| 58 | char *ptr, |
| 59 | *index (), *rindex (); |
| 60 | AttributeValue av; |
| 61 | AttributeType at; |
| 62 | |
| 63 | fltr->flt_type = FILTER_ITEM; |
| 64 | |
| 65 | if ((ptr = index (str, '=')) == NULLCP) { |
| 66 | /* set default (cn~=) */ |
| 67 | fltr->FUITEM.fi_type = FILTERITEM_APPROX; |
| 68 | at = AttrT_new (CN_OID); |
| 69 | } else { |
| 70 | switch (*--ptr) { |
| 71 | case '~': |
| 72 | fltr->FUITEM.fi_type = FILTERITEM_APPROX; |
| 73 | *ptr = 0; |
| 74 | break; |
| 75 | case '>': |
| 76 | fltr->FUITEM.fi_type = FILTERITEM_GREATEROREQUAL; |
| 77 | *ptr = 0; |
| 78 | break; |
| 79 | case '<': |
| 80 | fltr->FUITEM.fi_type = FILTERITEM_LESSOREQUAL; |
| 81 | *ptr = 0; |
| 82 | break; |
| 83 | default: |
| 84 | fltr->FUITEM.fi_type = FILTERITEM_EQUALITY; |
| 85 | break; |
| 86 | } |
| 87 | *++ptr = '\0'; |
| 88 | str = TidyString (str); |
| 89 | at = AttrT_new (str); |
| 90 | if (at == NULLAttrT) { |
| 91 | ps_printf (OPT,"invalid attribute type (%s)\n", str); |
| 92 | return (NOTOK); |
| 93 | } |
| 94 | str = ptr + 1; |
| 95 | } |
| 96 | |
| 97 | if ((*str == '*') || (*str == 0)) { |
| 98 | if (*++str == 0) { |
| 99 | fltr->FUITEM.fi_type = FILTERITEM_PRESENT; |
| 100 | fltr->FUITEM.UNTYPE = at; |
| 101 | return (OK); |
| 102 | } else |
| 103 | str--; |
| 104 | } |
| 105 | |
| 106 | /* test for whether there is only the simple 'equality' case */ |
| 107 | if ((ptr = index (str, '*')) == NULLCP) { |
| 108 | debug (1, ("[EXACT(%s)]", str)); |
| 109 | |
| 110 | fltr->FUITEM.UNAVA.ava_type = at; |
| 111 | str = TidyString (str); |
| 112 | if ((fltr->FUITEM.UNAVA.ava_value = str2AttrV (str, at->oa_syntax)) == NULLAttrV) |
| 113 | return (NOTOK); |
| 114 | return (OK); |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * We have to parse the string for 'initial', 'final' and 'any' |
| 119 | * components |
| 120 | */ |
| 121 | |
| 122 | fltr->FUITEM.UNSUB.fi_sub_initial = NULLAV; |
| 123 | fltr->FUITEM.UNSUB.fi_sub_any = NULLAV; |
| 124 | fltr->FUITEM.UNSUB.fi_sub_final = NULLAV; |
| 125 | fltr->FUITEM.UNSUB.fi_sub_type = at; |
| 126 | fltr->FUITEM.fi_type = FILTERITEM_SUBSTRINGS; |
| 127 | if ( ! sub_string (at->oa_syntax)) { |
| 128 | ps_print (OPT,"Can only substring search on strings\n"); |
| 129 | return (NOTOK); |
| 130 | } |
| 131 | |
| 132 | debug (1, ("[ ")); |
| 133 | /* This is the 'initial' section of the string - maybe NULL */ |
| 134 | *ptr = '\0'; |
| 135 | str = TidyString (str); |
| 136 | if (*str != 0) { |
| 137 | debug (1, ("INITIAL(%s) ", str)); |
| 138 | if ((av = str2AttrV (str, at->oa_syntax)) == NULLAttrV) |
| 139 | return NOTOK; |
| 140 | fltr->FUITEM.UNSUB.fi_sub_initial = avs_comp_new (av); |
| 141 | } |
| 142 | str = ptr + 1; |
| 143 | |
| 144 | /* Test for whether there are going to be any 'any' bits */ |
| 145 | if ((ptr = rindex (str, '*')) == NULLCP) { |
| 146 | ptr = TidyString (str); |
| 147 | if (*str != 0) { |
| 148 | debug (1, ("FINAL(%s) ", str)); |
| 149 | if ((av = str2AttrV (str, at->oa_syntax)) == NULLAttrV) |
| 150 | return NOTOK; |
| 151 | fltr->FUITEM.UNSUB.fi_sub_final = avs_comp_new (av); |
| 152 | } |
| 153 | debug (1, ("]")); |
| 154 | return (OK); |
| 155 | } |
| 156 | *ptr = '\0'; |
| 157 | ptr = TidyString (ptr + 1); |
| 158 | if (*ptr != 0) { |
| 159 | debug (1, ("FINAL(%s) ", ptr)); |
| 160 | if ((av = str2AttrV (ptr, at->oa_syntax)) == NULLAttrV) |
| 161 | return NOTOK; |
| 162 | |
| 163 | fltr->FUITEM.UNSUB.fi_sub_final = avs_comp_new (av); |
| 164 | } |
| 165 | /* There are some internal 'any's to be found */ |
| 166 | do { |
| 167 | AV_Sequence any_end; |
| 168 | |
| 169 | if ((ptr = index (str, '*')) != NULLCP) |
| 170 | *ptr = '\0'; |
| 171 | |
| 172 | if (*str != 0) { |
| 173 | str = TidyString (str); |
| 174 | debug (1, ("ANY(%s) ", str)); |
| 175 | if ((av = str2AttrV (str, at->oa_syntax)) == NULLAttrV) |
| 176 | return NOTOK; |
| 177 | if (fltr->FUITEM.UNSUB.fi_sub_any == NULLAV) { |
| 178 | fltr->FUITEM.UNSUB.fi_sub_any = avs_comp_new (av); |
| 179 | any_end = fltr->FUITEM.UNSUB.fi_sub_any; |
| 180 | } else { |
| 181 | any_end->avseq_next = avs_comp_new (av); |
| 182 | any_end = any_end->avseq_next; |
| 183 | } |
| 184 | } |
| 185 | if (ptr != NULLCP) |
| 186 | str = ptr + 1; |
| 187 | } |
| 188 | |
| 189 | while (ptr != NULLCP); |
| 190 | debug (1, ("]")); |
| 191 | return (OK); |
| 192 | } |