C++ compile.
[yaz-moved-to-github.git] / zutil / pquery.c
1 /*
2  * Copyright (c) 1995-2001, Index Data.
3  * See the file LICENSE for details.
4  *
5  * $Log: pquery.c,v $
6  * Revision 1.8  2001-07-19 19:14:53  adam
7  * C++ compile.
8  *
9  * Revision 1.7  2001/05/09 23:31:35  adam
10  * String attribute values for PQF. Proper C-backslash escaping for PQF.
11  *
12  * Revision 1.6  2001/03/07 13:24:40  adam
13  * Member and_not in Z_Operator is kept for backwards compatibility.
14  * Added support for definition of CCL operators in field spec file.
15  *
16  * Revision 1.5  2001/02/21 13:46:54  adam
17  * C++ fixes.
18  *
19  * Revision 1.4  1999/12/21 16:25:20  adam
20  * Fixed handling of default/inherited attributes.
21  *
22  * Revision 1.3  1999/12/20 15:20:13  adam
23  * Implemented ccl_pquery to convert from CCL tree to prefix query.
24  *
25  * Revision 1.2  1999/11/30 13:47:12  adam
26  * Improved installation. Moved header files to include/yaz.
27  *
28  * Revision 1.1  1999/06/08 10:10:16  adam
29  * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
30  *
31  * Revision 1.22  1999/04/20 09:56:49  adam
32  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
33  * Modified all encoders/decoders to reflect this change.
34  *
35  * Revision 1.21  1998/10/13 16:03:37  adam
36  * Better checking for invalid OID's in p_query_rpn.
37  *
38  * Revision 1.20  1998/03/31 15:13:20  adam
39  * Development towards compiled ASN.1.
40  *
41  * Revision 1.19  1998/03/05 08:09:03  adam
42  * Minor change to make C++ happy.
43  *
44  * Revision 1.18  1998/02/11 11:53:36  adam
45  * Changed code so that it compiles as C++.
46  *
47  * Revision 1.17  1997/11/24 11:33:57  adam
48  * Using function odr_nullval() instead of global ODR_NULLVAL when
49  * appropriate.
50  *
51  * Revision 1.16  1997/09/29 13:19:00  adam
52  * Added function, oid_ent_to_oid, to replace the function
53  * oid_getoidbyent, which is not thread safe.
54  *
55  * Revision 1.15  1997/09/29 07:13:43  adam
56  * Changed type of a few variables to avoid warnings.
57  *
58  * Revision 1.14  1997/09/22 12:33:41  adam
59  * Fixed bug introduced by previous commit.
60  *
61  * Revision 1.13  1997/09/17 12:10:42  adam
62  * YAZ version 1.4.
63  *
64  * Revision 1.12  1997/09/01 08:54:13  adam
65  * New windows NT/95 port using MSV5.0. Made prefix query handling
66  * thread safe. The function options ignores empty arguments when met.
67  *
68  * Revision 1.11  1996/11/11 13:15:29  adam
69  * Added proximity operator.
70  *
71  * Revision 1.10  1996/08/12 14:10:35  adam
72  * New function p_query_attset to define default attribute set.
73  *
74  * Revision 1.9  1996/03/15  11:03:46  adam
75  * Attribute set can be set globally for a query with the @attrset
76  * operator. The @attr operator has an optional attribute-set specifier
77  * that sets the attribute set locally.
78  *
79  * Revision 1.8  1996/01/02  11:46:56  quinn
80  * Changed 'operator' to 'roperator' to avoid C++ conflict.
81  *
82  * Revision 1.7  1995/09/29  17:12:36  quinn
83  * Smallish
84  *
85  * Revision 1.6  1995/09/27  15:03:03  quinn
86  * Modified function heads & prototypes.
87  *
88  * Revision 1.5  1995/06/15  12:31:02  quinn
89  * *** empty log message ***
90  *
91  * Revision 1.4  1995/06/15  07:45:19  quinn
92  * Moving to v3.
93  *
94  * Revision 1.3  1995/06/14  11:06:35  adam
95  * Bug fix: Attributes wasn't interpreted correctly!
96  *
97  * Revision 1.2  1995/05/26  08:56:11  adam
98  * New function: p_query_scan.
99  *
100  * Revision 1.1  1995/05/22  15:31:49  adam
101  * New function, p_query_rpn, to convert from prefix (ascii) to rpn (asn).
102  *
103  */
104
105 #include <stdio.h>
106 #include <string.h>
107 #include <stdlib.h>
108
109 #include <yaz/proto.h>
110 #include <yaz/oid.h>
111 #include <yaz/pquery.h>
112
113 static oid_value p_query_dfset = VAL_NONE;
114
115 struct lex_info {
116     const char *query_buf;
117     const char *lex_buf;
118     size_t lex_len;
119     int query_look;
120     char *left_sep;
121     char *right_sep;
122     int escape_char;
123     int term_type;
124 };
125
126 static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, oid_proto, 
127                                       int num_attr, int max_attr, 
128                                       int *attr_list, char **attr_clist,
129                                       oid_value *attr_set);
130
131 static enum oid_value query_oid_getvalbyname (struct lex_info *li)
132 {
133     enum oid_value value;
134     char buf[32];
135
136     if (li->lex_len > 31)
137         return VAL_NONE;
138     memcpy (buf, li->lex_buf, li->lex_len);
139     buf[li->lex_len] = '\0';
140     value = oid_getvalbyname (buf);
141     return value;
142 }
143
144 static int compare_term (struct lex_info *li, const char *src, size_t off)
145 {
146     size_t len=strlen(src);
147
148     if (li->lex_len == len+off && !memcmp (li->lex_buf+off, src, len-off))
149         return 1;
150     return 0;
151 }
152
153 static int query_token (struct lex_info *li)
154 {
155     int sep_char = ' ';
156     const char *sep_match;
157     const char **qptr = &li->query_buf;
158
159     while (**qptr == ' ')
160         (*qptr)++;
161     if (**qptr == '\0')
162         return 0;
163     li->lex_len = 0;
164     if ((sep_match = strchr (li->left_sep, **qptr)))
165     {
166         sep_char = li->right_sep[sep_match - li->left_sep];
167         ++(*qptr);
168     }
169     li->lex_buf = *qptr;
170     
171     while (**qptr && **qptr != sep_char)
172     {
173         if (**qptr == '\\')
174         {
175             ++(li->lex_len);
176             ++(*qptr);
177         }
178         ++(li->lex_len);
179         ++(*qptr);
180     }
181     if (**qptr)
182         ++(*qptr);
183     if (li->lex_len >= 1 && li->lex_buf[0] == li->escape_char)
184     {
185         if (compare_term (li, "and", 1))
186             return 'a';
187         if (compare_term (li, "or", 1))
188             return 'o';
189         if (compare_term (li, "not", 1))
190             return 'n';
191         if (compare_term (li, "attr", 1))
192             return 'l';
193         if (compare_term (li, "set", 1))
194             return 's';
195         if (compare_term (li, "attrset", 1))
196             return 'r';
197         if (compare_term (li, "prox", 1))
198             return 'p';
199         if (compare_term (li, "term", 1))
200             return 'y';
201     }
202     return 't';
203 }
204
205 static int lex (struct lex_info *li)
206 {
207     return li->query_look = query_token (li);
208 }
209
210 static int escape_string(char *out_buf, const char *in, int len)
211 {
212
213     char *out = out_buf;
214     while (--len >= 0)
215         if (*in == '\\' && len > 0)
216         {
217             --len;
218             switch (*++in)
219             {
220             case 't':
221                 *out++ = '\t';
222                 break;
223             case 'n':
224                 *out++ = '\n';
225                 break;
226             case 'r':
227                 *out++ = '\r';
228                 break;
229             case 'f':
230                 *out++ = '\f';
231                 break;
232             case 'x':
233                 if (len > 1)
234                 {
235                     char s[4];
236                     int n = 0;
237                     s[0] = *++in;
238                     s[1] = *++in;
239                     s[2] = '\0';
240                     len = len - 2;
241                     sscanf (s, "%x", &n);
242                     *out++ = n;
243                 }
244                 break;
245             case '0':
246             case '1':
247             case '2':
248             case '3':
249                 if (len > 1)
250                 {
251                     char s[4];
252                     int n = 0;
253                     s[0] = *in;
254                     s[1] = *++in;                   
255                     s[2] = *++in;
256                     s[3] = '\0';
257                     len = len - 2;
258                     sscanf (s, "%o", &n);
259                     *out++ = n;
260                 }
261                 break;
262             default:
263                 *out++ = *in;
264                 break;
265             }
266             in++;
267         }
268         else
269             *out++ = *in++;
270     return out - out_buf;
271 }
272
273 static int p_query_parse_attr(struct lex_info *li, ODR o,
274                               int num_attr, int *attr_list,
275                               char **attr_clist, oid_value *attr_set)
276 {
277     const char *cp;
278     if (!(cp = strchr (li->lex_buf, '=')) ||
279         (size_t) (cp-li->lex_buf) > li->lex_len)
280     {
281         attr_set[num_attr] = query_oid_getvalbyname (li);
282         if (attr_set[num_attr] == VAL_NONE)
283             return 0;
284         lex (li);
285         
286         if (!(cp = strchr (li->lex_buf, '=')))
287             return 0;
288     }
289     else 
290     {
291         if (num_attr > 0)
292             attr_set[num_attr] = attr_set[num_attr-1];
293         else
294             attr_set[num_attr] = VAL_NONE;
295     }
296     attr_list[2*num_attr] = atoi(li->lex_buf);
297         cp++;
298     if (*cp >= '0' && *cp <= '9')
299     {
300         attr_list[2*num_attr+1] = atoi (cp);
301         attr_clist[num_attr] = 0;
302     }
303     else
304     {
305         int len = li->lex_len - (cp - li->lex_buf);
306         attr_list[2*num_attr+1] = 0;
307         attr_clist[num_attr] = (char *) odr_malloc (o, len+1);
308         len = escape_string(attr_clist[num_attr], cp, len);
309         attr_clist[num_attr][len] = '\0';
310     }
311     return 1;
312 }
313
314 static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o,
315                                        oid_proto proto, 
316                                        int num_attr, int *attr_list,
317                                        char **attr_clist, oid_value *attr_set)
318 {
319     Z_AttributesPlusTerm *zapt;
320     Odr_oct *term_octet;
321     Z_Term *term;
322     Z_AttributeElement **elements;
323
324     zapt = (Z_AttributesPlusTerm *)odr_malloc (o, sizeof(*zapt));
325     term_octet = (Odr_oct *)odr_malloc (o, sizeof(*term_octet));
326     term = (Z_Term *)odr_malloc (o, sizeof(*term));
327
328     if (!num_attr)
329         elements = (Z_AttributeElement**)odr_nullval();
330     else
331     {
332         int i, k = 0;
333         int *attr_tmp;
334
335         elements = (Z_AttributeElement**)
336             odr_malloc (o, num_attr * sizeof(*elements));
337
338         attr_tmp = (int *)odr_malloc (o, num_attr * 2 * sizeof(int));
339         memcpy (attr_tmp, attr_list, num_attr * 2 * sizeof(int));
340         for (i = num_attr; --i >= 0; )
341         {
342             int j;
343             for (j = i+1; j<num_attr; j++)
344                 if (attr_tmp[2*j] == attr_tmp[2*i])
345                     break;
346             if (j < num_attr)
347                 continue;
348             elements[k] =
349                 (Z_AttributeElement*)odr_malloc (o,sizeof(**elements));
350             elements[k]->attributeType = &attr_tmp[2*i];
351             if (attr_set[i] == VAL_NONE)
352                 elements[k]->attributeSet = 0;
353             else
354             {
355                 oident attrid;
356                 int oid[OID_SIZE];
357                 
358                 attrid.proto = PROTO_Z3950;
359                 attrid.oclass = CLASS_ATTSET;
360                 attrid.value = attr_set[i];
361                    
362                 elements[k]->attributeSet =
363                     odr_oiddup (o, oid_ent_to_oid (&attrid, oid));
364             }
365             if (attr_clist[i])
366             {
367                 elements[k]->which = Z_AttributeValue_complex;
368                 elements[k]->value.complex = (Z_ComplexAttribute *)
369                     odr_malloc (o, sizeof(Z_ComplexAttribute));
370                 elements[k]->value.complex->num_list = 1;
371                 elements[k]->value.complex->list =
372                     (Z_StringOrNumeric **)
373                     odr_malloc (o, 1 * sizeof(Z_StringOrNumeric *));
374                 elements[k]->value.complex->list[0] =
375                     (Z_StringOrNumeric *)
376                     odr_malloc (o, sizeof(Z_StringOrNumeric));
377                 elements[k]->value.complex->list[0]->which =
378                     Z_StringOrNumeric_string;
379                 elements[k]->value.complex->list[0]->u.string =
380                     attr_clist[i];
381                 elements[k]->value.complex->semanticAction = (int **)
382                     odr_nullval();
383                 elements[k]->value.complex->num_semanticAction = 0;
384             }
385             else
386             {
387                 elements[k]->which = Z_AttributeValue_numeric;
388                 elements[k]->value.numeric = &attr_tmp[2*i+1];
389             }
390             k++;
391         }
392         num_attr = k;
393     }
394 #ifdef ASN_COMPILED
395     zapt->attributes = (Z_AttributeList *)
396         odr_malloc (o, sizeof(*zapt->attributes));
397     zapt->attributes->num_attributes = num_attr;
398     zapt->attributes->attributes = elements;
399 #else
400     zapt->num_attributes = num_attr;
401     zapt->attributeList = elements;
402 #endif    
403
404     zapt->term = term;
405     term->which = Z_Term_general;
406     term->u.general = term_octet;
407     term_octet->buf = (unsigned char *)odr_malloc (o, li->lex_len);
408     term_octet->size = term_octet->len =
409         escape_string ((char *) (term_octet->buf), li->lex_buf, li->lex_len);
410     return zapt;
411 }
412
413 static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto,
414                               int num_attr, int *attr_list, char **attr_clist,
415                               oid_value *attr_set)
416 {
417     Z_Operand *zo;
418
419     zo = (Z_Operand *)odr_malloc (o, sizeof(*zo));
420     switch (li->query_look)
421     {
422     case 't':
423         zo->which = Z_Operand_APT;
424         if (!(zo->u.attributesPlusTerm =
425               rpn_term (li, o, proto, num_attr, attr_list, attr_clist,
426                         attr_set)))
427             return NULL;
428         lex (li);
429         break;
430     case 's':
431         lex (li);
432         if (!li->query_look)
433             return NULL;
434         zo->which = Z_Operand_resultSetId;
435         zo->u.resultSetId = (char *)odr_malloc (o, li->lex_len+1);
436         memcpy (zo->u.resultSetId, li->lex_buf, li->lex_len);
437         zo->u.resultSetId[li->lex_len] = '\0';
438         lex (li);
439         break;
440     default:
441         return NULL;
442     }
443     return zo;
444 }
445
446 static Z_ProximityOperator *rpn_proximity (struct lex_info *li, ODR o)
447 {
448     Z_ProximityOperator *p = (Z_ProximityOperator *)odr_malloc (o, sizeof(*p));
449
450     if (!lex (li))
451         return NULL;
452     if (*li->lex_buf == '1')
453     {
454         p->exclusion = (int *)odr_malloc (o, sizeof(*p->exclusion));
455         *p->exclusion = 1;
456     } 
457     else if (*li->lex_buf == '0')
458     {
459         p->exclusion = (int *)odr_malloc (o, sizeof(*p->exclusion));
460         *p->exclusion = 0;
461     }
462     else
463         p->exclusion = NULL;
464
465     if (!lex (li))
466         return NULL;
467     p->distance = (int *)odr_malloc (o, sizeof(*p->distance));
468     *p->distance = atoi (li->lex_buf);
469
470     if (!lex (li))
471         return NULL;
472     p->ordered = (int *)odr_malloc (o, sizeof(*p->ordered));
473     *p->ordered = atoi (li->lex_buf);
474     
475     if (!lex (li))
476         return NULL;
477     p->relationType = (int *)odr_malloc (o, sizeof(*p->relationType));
478     *p->relationType = atoi (li->lex_buf);
479
480     if (!lex (li))
481         return NULL;
482     if (*li->lex_buf == 'k')
483         p->which = 0;
484     else if (*li->lex_buf == 'p')
485         p->which = 1;
486     else
487         p->which = atoi (li->lex_buf);
488
489     if (!lex (li))
490         return NULL;
491 #ifdef ASN_COMPILED
492     p->which = Z_ProximityOperator_known;
493     p->u.known = (int *)odr_malloc (o, sizeof(*p->u.known));
494     *p->u.known = atoi (li->lex_buf);
495 #else
496     p->proximityUnitCode = (int *)odr_malloc (o, sizeof(*p->proximityUnitCode));
497     *p->proximityUnitCode = atoi (li->lex_buf);
498 #endif
499     return p;
500 }
501
502 static Z_Complex *rpn_complex (struct lex_info *li, ODR o, oid_proto proto,
503                                int num_attr, int max_attr, 
504                                int *attr_list, char **attr_clist,
505                                oid_value *attr_set)
506 {
507     Z_Complex *zc;
508     Z_Operator *zo;
509
510     zc = (Z_Complex *)odr_malloc (o, sizeof(*zc));
511     zo = (Z_Operator *)odr_malloc (o, sizeof(*zo));
512     zc->roperator = zo;
513     switch (li->query_look)
514     {
515     case 'a':
516         zo->which = Z_Operator_and;
517         zo->u.and_not = odr_nullval();
518         break;
519     case 'o':
520         zo->which = Z_Operator_or;
521         zo->u.and_not = odr_nullval();
522         break;
523     case 'n':
524         zo->which = Z_Operator_and_not;
525         zo->u.and_not = odr_nullval();
526         break;
527     case 'p':
528         zo->which = Z_Operator_prox;
529         zo->u.prox = rpn_proximity (li, o);
530         if (!zo->u.prox)
531             return NULL;
532         break;
533     default:
534         return NULL;
535     }
536     lex (li);
537     if (!(zc->s1 =
538           rpn_structure (li, o, proto, num_attr, max_attr, attr_list,
539                          attr_clist, attr_set)))
540         return NULL;
541     if (!(zc->s2 =
542           rpn_structure (li, o, proto, num_attr, max_attr, attr_list,
543                          attr_clist, attr_set)))
544         return NULL;
545     return zc;
546 }
547
548 static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o,
549                                       oid_proto proto, 
550                                       int num_attr, int max_attr, 
551                                       int *attr_list,
552                                       char **attr_clist,
553                                       oid_value *attr_set)
554 {
555     Z_RPNStructure *sz;
556
557     sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz));
558     switch (li->query_look)
559     {
560     case 'a':
561     case 'o':
562     case 'n':
563     case 'p':
564         sz->which = Z_RPNStructure_complex;
565         if (!(sz->u.complex =
566               rpn_complex (li, o, proto, num_attr, max_attr, attr_list,
567                            attr_clist, attr_set)))
568             return NULL;
569         break;
570     case 't':
571     case 's':
572         sz->which = Z_RPNStructure_simple;
573         if (!(sz->u.simple =
574               rpn_simple (li, o, proto, num_attr, attr_list,
575                           attr_clist, attr_set)))
576             return NULL;
577         break;
578     case 'l':
579         lex (li);
580         if (!li->query_look)
581             return NULL;
582         if (num_attr >= max_attr)
583             return NULL;
584         p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set);
585         num_attr++;
586         lex (li);
587         return
588             rpn_structure (li, o, proto, num_attr, max_attr, attr_list,
589                            attr_clist,  attr_set);
590     case 'y':
591         lex (li);
592         if (!li->query_look)
593             return NULL;
594         if (compare_term (li, "general", 0))
595             li->term_type = Z_Term_general;
596         else if (compare_term (li, "numeric", 0))
597             li->term_type = Z_Term_numeric;
598         else if (compare_term (li, "string", 0))
599             li->term_type = Z_Term_characterString;
600         else if (compare_term (li, "oid", 0))
601             li->term_type = Z_Term_oid;
602         else if (compare_term (li, "datetime", 0))
603             li->term_type = Z_Term_dateTime;
604         else if (compare_term (li, "null", 0))
605             li->term_type = Z_Term_null;
606         lex (li);
607         return
608             rpn_structure (li, o, proto, num_attr, max_attr, attr_list,
609                            attr_clist, attr_set);
610     case 0:                /* operator/operand expected! */
611         return NULL;
612     }
613     return sz;
614 }
615
616 Z_RPNQuery *p_query_rpn_mk (ODR o, struct lex_info *li, oid_proto proto,
617                             const char *qbuf)
618 {
619     Z_RPNQuery *zq;
620     int attr_array[1024];
621     char *attr_clist[512];
622     oid_value attr_set[512];
623     oid_value topSet = VAL_NONE;
624     oident oset;
625     int oid[OID_SIZE];
626
627     zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq));
628     lex (li);
629     if (li->query_look == 'r')
630     {
631         lex (li);
632         topSet = query_oid_getvalbyname (li);
633         if (topSet == VAL_NONE)
634             return NULL;
635
636         lex (li);
637     }
638     if (topSet == VAL_NONE)
639         topSet = p_query_dfset;
640     if (topSet == VAL_NONE)
641         topSet = VAL_BIB1;
642     oset.proto = proto;
643     oset.oclass = CLASS_ATTSET;
644     oset.value = topSet;
645
646     if (!oid_ent_to_oid (&oset, oid))
647         return NULL;
648     zq->attributeSetId = odr_oiddup (o, oid);
649
650     if (!(zq->RPNStructure = rpn_structure (li, o, proto, 0, 512,
651                                             attr_array, attr_clist, attr_set)))
652         return NULL;
653     return zq;
654 }
655
656 Z_RPNQuery *p_query_rpn (ODR o, oid_proto proto,
657                          const char *qbuf)
658 {
659     struct lex_info li;
660     
661     li.left_sep = "{\"";
662     li.right_sep = "}\"";
663     li.escape_char = '@';
664     li.term_type = Z_Term_general;
665     li.query_buf = qbuf;
666     return p_query_rpn_mk (o, &li, proto, qbuf);
667 }
668
669
670 Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li,
671                                        ODR o, oid_proto proto,
672                                        Odr_oid **attributeSetP,
673                                        const char *qbuf)
674 {
675     int attr_list[1024];
676     char *attr_clist[512];
677     oid_value attr_set[512];
678     int num_attr = 0;
679     int max_attr = 512;
680     oid_value topSet = VAL_NONE;
681     oident oset;
682     int oid[OID_SIZE];
683
684     lex (li);
685     if (li->query_look == 'r')
686     {
687         lex (li);
688         topSet = query_oid_getvalbyname (li);
689
690         lex (li);
691     }
692     if (topSet == VAL_NONE)
693         topSet = p_query_dfset;
694     if (topSet == VAL_NONE)
695         topSet = VAL_BIB1;
696     oset.proto = proto;
697     oset.oclass = CLASS_ATTSET;
698     oset.value = topSet;
699
700     *attributeSetP = odr_oiddup (o, oid_ent_to_oid (&oset, oid));
701
702     while (li->query_look == 'l')
703     {
704         lex (li);
705         if (!li->query_look)
706             return NULL;
707         if (num_attr >= max_attr)
708             return NULL;
709         p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set);
710         num_attr++;
711         lex (li);
712     }
713     if (!li->query_look)
714         return NULL;
715     return rpn_term (li, o, proto, num_attr, attr_list, attr_clist, attr_set);
716 }
717
718 Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto,
719                                     Odr_oid **attributeSetP,
720                                     const char *qbuf)
721 {
722     struct lex_info li;
723
724     li.left_sep = "{\"";
725     li.right_sep = "}\"";
726     li.escape_char = '@';
727     li.term_type = Z_Term_general;
728     li.query_buf = qbuf;
729
730     return p_query_scan_mk (&li, o, proto, attributeSetP, qbuf);
731 }
732
733 int p_query_attset (const char *arg)
734 {
735     p_query_dfset = oid_getvalbyname (arg);
736     return (p_query_dfset == VAL_NONE) ? -1 : 0;
737 }
738