1 /* zzeknres.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* Table of constant values */
9 
10 static integer c__1 = 1;
11 
12 /* $Procedure  ZZEKNRES ( Private: EK, resolve names in encoded query ) */
zzeknres_(char * query,integer * eqryi,char * eqryc,logical * error,char * errmsg,integer * errptr,ftnlen query_len,ftnlen eqryc_len,ftnlen errmsg_len)13 /* Subroutine */ int zzeknres_(char *query, integer *eqryi, char *eqryc,
14 	logical *error, char *errmsg, integer *errptr, ftnlen query_len,
15 	ftnlen eqryc_len, ftnlen errmsg_len)
16 {
17     /* System generated locals */
18     integer i__1, i__2, i__3, i__4, i__5;
19 
20     /* Builtin functions */
21     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
22     integer s_rnge(char *, integer, char *, integer), s_cmp(char *, char *,
23 	    ftnlen, ftnlen);
24 
25     /* Local variables */
26     integer base, ntab, ncnj, ncns, nord, nsel;
27     extern /* Subroutine */ int zzekcchk_(char *, integer *, char *, integer *
28 	    , char *, char *, integer *, logical *, char *, integer *, ftnlen,
29 	     ftnlen, ftnlen, ftnlen, ftnlen), zzekqtab_(integer *, char *,
30 	    integer *, char *, char *, ftnlen, ftnlen, ftnlen), zzekreqi_(
31 	    integer *, char *, integer *, ftnlen), zzekweqi_(char *, integer *
32 	    , integer *, ftnlen);
33     integer i__, j;
34     char table[64*10], alias[64*10];
35     extern /* Subroutine */ int chkin_(char *, ftnlen);
36     integer nload;
37     extern /* Subroutine */ int repmc_(char *, char *, char *, char *, ftnlen,
38 	     ftnlen, ftnlen, ftnlen);
39     integer cc[10];
40     extern logical failed_(void);
41     char ltable[64];
42     extern /* Subroutine */ int ekntab_(integer *);
43     extern integer isrchc_(char *, integer *, char *, ftnlen, ftnlen);
44     integer cnstyp, iparse;
45     extern /* Subroutine */ int setmsg_(char *, ftnlen), sigerr_(char *,
46 	    ftnlen), chkout_(char *, ftnlen), ektnam_(integer *, char *,
47 	    ftnlen), ekccnt_(char *, integer *, ftnlen);
48     logical fnd;
49     integer lxb, lxe;
50 
51 /* $ Abstract */
52 
53 /*     SPICE Private routine intended solely for the support of SPICE */
54 /*     routines.  Users should not call this routine directly due */
55 /*     to the volatile nature of this routine. */
56 
57 /*     Resolve and semantically check table names, aliases, and column */
58 /*     names in an encoded EK query. */
59 
60 /* $ Disclaimer */
61 
62 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
63 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
64 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
65 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
66 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
67 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
68 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
69 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
70 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
71 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
72 
73 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
74 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
75 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
76 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
77 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
78 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
79 
80 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
81 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
82 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
83 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
84 
85 /* $ Required_Reading */
86 
87 /*     EK */
88 
89 /* $ Keywords */
90 
91 /*     EK */
92 /*     PRIVATE */
93 
94 /* $ Declarations */
95 /* $ Disclaimer */
96 
97 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
98 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
99 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
100 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
101 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
102 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
103 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
104 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
105 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
106 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
107 
108 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
109 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
110 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
111 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
112 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
113 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
114 
115 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
116 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
117 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
118 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
119 
120 
121 /*     Include Section:  EK Boolean Enumerated Type */
122 
123 
124 /*        ekbool.inc Version 1   21-DEC-1994 (NJB) */
125 
126 
127 /*     Within the EK system, boolean values sometimes must be */
128 /*     represented by integer or character codes.  The codes and their */
129 /*     meanings are listed below. */
130 
131 /*     Integer code indicating `true': */
132 
133 
134 /*     Integer code indicating `false': */
135 
136 
137 /*     Character code indicating `true': */
138 
139 
140 /*     Character code indicating `false': */
141 
142 
143 /*     End Include Section:  EK Boolean Enumerated Type */
144 
145 /* $ Disclaimer */
146 
147 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
148 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
149 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
150 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
151 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
152 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
153 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
154 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
155 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
156 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
157 
158 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
159 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
160 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
161 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
162 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
163 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
164 
165 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
166 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
167 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
168 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
169 
170 
171 /*     Include Section:  EK Query Limit Parameters */
172 
173 /*        ekqlimit.inc  Version 3    16-NOV-1995 (NJB) */
174 
175 /*           Parameter MAXCON increased to 1000. */
176 
177 /*        ekqlimit.inc  Version 2    01-AUG-1995 (NJB) */
178 
179 /*           Updated to support SELECT clause. */
180 
181 
182 /*        ekqlimit.inc  Version 1    07-FEB-1995 (NJB) */
183 
184 
185 /*     These limits apply to character string queries input to the */
186 /*     EK scanner.  This limits are part of the EK system's user */
187 /*     interface:  the values should be advertised in the EK required */
188 /*     reading document. */
189 
190 
191 /*     Maximum length of an input query:  MAXQRY.  This value is */
192 /*     currently set to twenty-five 80-character lines. */
193 
194 
195 /*     Maximum number of columns that may be listed in the */
196 /*     `order-by clause' of a query:  MAXSEL.  MAXSEL = 50. */
197 
198 
199 /*     Maximum number of tables that may be listed in the `FROM */
200 /*     clause' of a query: MAXTAB. */
201 
202 
203 /*     Maximum number of relational expressions that may be listed */
204 /*     in the `constraint clause' of a query: MAXCON. */
205 
206 /*     This limit applies to a query when it is represented in */
207 /*     `normalized form': that is, the constraints have been */
208 /*     expressed as a disjunction of conjunctions of relational */
209 /*     expressions. The number of relational expressions in a query */
210 /*     that has been expanded in this fashion may be greater than */
211 /*     the number of relations in the query as orginally written. */
212 /*     For example, the expression */
213 
214 /*             ( ( A LT 1 ) OR ( B GT 2 ) ) */
215 /*        AND */
216 /*             ( ( C NE 3 ) OR ( D EQ 4 ) ) */
217 
218 /*     which contains 4 relational expressions, expands to the */
219 /*     equivalent normalized constraint */
220 
221 /*             (  ( A LT 1 ) AND ( C NE 3 )  ) */
222 /*        OR */
223 /*             (  ( A LT 1 ) AND ( D EQ 4 )  ) */
224 /*        OR */
225 /*             (  ( B GT 2 ) AND ( C NE 3 )  ) */
226 /*        OR */
227 /*             (  ( B GT 2 ) AND ( D EQ 4 )  ) */
228 
229 /*     which contains eight relational expressions. */
230 
231 
232 
233 /*     MXJOIN is the maximum number of tables that can be joined. */
234 
235 
236 /*     MXJCON is the maximum number of join constraints allowed. */
237 
238 
239 /*     Maximum number of order-by columns that may be used in the */
240 /*     `order-by clause' of a query: MAXORD. MAXORD = 10. */
241 
242 
243 /*     Maximum number of tokens in a query: 500. Tokens are reserved */
244 /*     words, column names, parentheses, and values. Literal strings */
245 /*     and time values count as single tokens. */
246 
247 
248 /*     Maximum number of numeric tokens in a query: */
249 
250 
251 /*     Maximum total length of character tokens in a query: */
252 
253 
254 /*     Maximum length of literal string values allowed in queries: */
255 /*     MAXSTR. */
256 
257 
258 /*     End Include Section:  EK Query Limit Parameters */
259 
260 /* $ Disclaimer */
261 
262 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
263 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
264 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
265 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
266 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
267 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
268 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
269 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
270 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
271 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
272 
273 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
274 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
275 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
276 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
277 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
278 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
279 
280 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
281 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
282 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
283 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
284 
285 
286 /*     Include Section:  EK Encoded Query Internal Parameters */
287 
288 /*        ekquery.inc  Version 3    16-NOV-1995 (NJB) */
289 
290 /*           Updated to reflect increased value of MAXCON in */
291 /*           ekqlimit.inc. */
292 
293 /*        ekquery.inc  Version 2    03-AUG-1995 (NJB) */
294 
295 /*           Updated to support representation of the SELECT clause. */
296 
297 
298 /*        ekquery.inc  Version 1    12-JAN-1995 (NJB) */
299 
300 
301 /*     An encoded EK query is an abstract data type implemented */
302 /*     as an integer cell, along with a double precision cell and */
303 /*     a character string.  The d.p. cell and string contain numeric */
304 /*     and string values from the query string represented by the */
305 /*     encoded query. */
306 
307 /*     The parameters in this file are intended for use only by the */
308 /*     EK encoded query access routines.  Callers of EK routines should */
309 /*     not use these parameters. */
310 
311 /*     The following parameters are indices of specified elements */
312 /*     in the integer portion of the encoded query. */
313 
314 /*     Encoded query architecture type: */
315 
316 
317 /*     `Name resolution' consists of: */
318 
319 /*        - Verifying existence of tables:  any table names listed */
320 /*          in the FROM clause of a query must be loaded. */
321 
322 /*        - Validating table aliases used to qualify column names. */
323 
324 /*        - Verifying existence of columns and obtaining data types */
325 /*          for columns. */
326 
327 /*        - Setting data type codes for literal values in the encoded */
328 /*          query. */
329 
330 /*        - Checking consistency of operators and operand data types. */
331 
332 /*        - Making sure unqualified column names are unambiguous. */
333 
334 /*        - For constraints, mapping the table names used to qualify */
335 /*          column names to the ordinal position in the FROM clause */
336 /*          of the corresponding table. */
337 
338 
339 /*     Initialization status---this flag indicates whether the encoded */
340 /*     query has been initialized.  Values are ITRUE or IFALSE.  See the */
341 /*     include file ekbool.inc for parameter values. */
342 
343 
344 /*     Parse status---this flag indicates whether the parsing operation */
345 /*     that produced an encoded query has been completed. Values are */
346 /*     ITRUE or IFALSE. */
347 
348 
349 /*     Name resolution status---this flag indicates whether names */
350 /*     have been resolved in an encoded query.  Values are ITRUE or */
351 /*     IFALSE. */
352 
353 
354 /*     Time resolution status---this flag indicates whether time values */
355 /*     have been resolved in an encoded query.  Time resolution */
356 /*     consists of converting strings representing time values to ET. */
357 /*     Values of the status are ITRUE or IFALSE. */
358 
359 
360 /*     Semantic check status---this flag indicates whether semantic */
361 /*     checking of constraints has been performed. */
362 
363 
364 /*     Number of tables specified in FROM clause: */
365 
366 
367 /*     Number of constraints in query: */
368 
369 
370 /*     A special value is used to indicate the `maximal' constraint--- */
371 /*     one that logically cannot be satisfied.  If the constraints */
372 /*     are equivalent to the maximal constraint, the location EQNCNS */
373 /*     is assigned the value EQMXML */
374 
375 
376 /*     Number of constraint conjunctions: */
377 
378 
379 /*     Number of order-by columns: */
380 
381 
382 /*     Number of SELECT columns: */
383 
384 
385 /*     Size of double precision buffer: */
386 
387 
388 /*     `Free' pointer into double precision buffer: */
389 
390 
391 /*     Size of character string buffer: */
392 
393 
394 /*     `Free' pointer into character string buffer: */
395 
396 
397 /*     The following four base pointers will be valid after a query */
398 /*     has been parsed: */
399 
400 /*     Base pointer for SELECT column descriptors: */
401 
402 
403 /*     Base pointer for constraint descriptors: */
404 
405 
406 /*     Base pointer for conjunction sizes: */
407 
408 
409 /*     Base pointer for order-by column descriptors: */
410 
411 
412 /*     After the quantities named above, the integer array contains */
413 /*     series of descriptors for tables, constraints, and order-by */
414 /*     columns, as well as a list of `conjunction sizes'---that is, */
415 /*     the sizes of the groups of constraints that form conjunctions, */
416 /*     after the input query has been re-arranged as a disjunction of */
417 /*     conjunctions of constraints. */
418 
419 
420 /*     The offsets of specific elements within descriptors are */
421 /*     parameterized. The base addresses of the descriptors themselves */
422 /*     must be  calculated using the counts and sizes of the items */
423 /*     preceding them. */
424 
425 /*     A diagram of the structure of the variable-size portion of the */
426 /*     integer array is shown below: */
427 
428 
429 /*        +-------------------------------------+ */
430 /*        | Fixed-size portion of encoded query | */
431 /*        +-------------------------------------+ */
432 /*        |         Encoded FROM clause         | */
433 /*        +-------------------------------------+ */
434 /*        |      Encoded constraint clause      | */
435 /*        +-------------------------------------+ */
436 /*        |          Conjunction sizes          | */
437 /*        +-------------------------------------+ */
438 /*        |       Encoded ORDER BY clause       | */
439 /*        +-------------------------------------+ */
440 /*        |        Encoded SELECT clause        | */
441 /*        +-------------------------------------+ */
442 
443 
444 /*     Value Descriptors */
445 /*     ---------------- */
446 
447 /*     In order to discuss the various descriptors below, we'll make use */
448 /*     of sub-structures called `value descriptors'.  These descriptors */
449 /*     come in two flavors:  character and double precision.  For */
450 /*     strings, a descriptor is a set of begin and end pointers that */
451 /*     indicate the location of the string in the character portion of an */
452 /*     encoded query, along with the begin and end pointers for the */
453 /*     corresponding lexeme in the original query.  The pointers are set */
454 /*     to zero when they are not in use, for example if they refer to an */
455 /*     optional lexeme that did not appear in the input query. */
456 
457 /*     All value descriptors start with a data type indicator; values */
458 /*     are from ektype.inc.  Integer and time values are referred to */
459 /*     by double precision descriptors. */
460 
461 /*     Parameters for string value descriptor elements: */
462 
463 
464 /*     Numeric value descriptors are similar to those for string values, */
465 /*     the difference being that they have only one pointer to the value */
466 /*     they represent.  This pointer is the index of the value in the */
467 /*     encoded query's numeric buffer. */
468 
469 
470 /*     All value descriptors have the same size.  In order to allow */
471 /*     table descriptors to have the same size as value descriptors, */
472 /*     we include an extra element in the descriptor. */
473 
474 
475 /*     Column Descriptors */
476 /*     ----------------- */
477 
478 /*     Each column descriptor consists of a character descriptor for the */
479 /*     name of the column, followed by an index, which gives the ordinal */
480 /*     position of the column in the logical table to which the column */
481 /*     belongs.  The index element is filled in during name resolution. */
482 
483 
484 /*     Table Descriptors */
485 /*     ----------------- */
486 
487 /*     Each table descriptor consists of a character descriptor for the */
488 /*     name of the table, followed by an index, which gives the ordinal */
489 /*     position of the table in the FROM clause in the original query. */
490 /*     The index element is filled in during name resolution.  Aliases */
491 /*     and table names have identical descriptor structures. */
492 
493 
494 /*     Constraint descriptors */
495 /*     ------------------ */
496 
497 /*     Each constraint is characterized by: */
498 
499 /*        - A code indicating whether the constraint compares values */
500 /*          in two columns or the value in a column and a literal */
501 /*          value.  The values of this element are EQCOL and EQVAL. */
502 
503 
504 
505 /*        - A descriptor for the table used to qualify the */
506 /*          column name on the left side of the constraint. */
507 
508 
509 /*        - A character value descriptor for the column name on the left */
510 /*          side of the query. */
511 
512 
513 /*        - An operator code indicating the relational operator used */
514 /*          in the constraint. */
515 
516 
517 /*        If the constraint compares values from two columns, the */
518 /*        next items are table and column name descriptors that apply to */
519 /*        the column named on the right side of the relational operator. */
520 
521 
522 /*        If the constraint has a literal value on the right side, the */
523 /*        operator code is followed by... */
524 
525 /*        - a value descriptor. */
526 
527 
528 /*        - Size of a constraint descriptor: */
529 
530 
531 /*     Conjunction sizes */
532 /*     ----------------- */
533 
534 /*     The size of each conjunction of constraints occupies a single */
535 /*     integer. */
536 
537 
538 
539 
540 /*     Order-by Column Descriptors */
541 /*     --------------------------- */
542 
543 /*     Each order-by column descriptor contains descriptors for */
544 /*     the table containing the column and for the name of the column */
545 /*     itself; one additional element is used to indicate the direction */
546 /*     of the ordering (ascending vs descending). */
547 
548 
549 /*        - The last integer in the descriptor indicates whether the */
550 /*          order direction is ascending or descending. */
551 
552 
553 /*        - Size of an order-by column descriptor: */
554 
555 
556 /*     Codes indicating sense of ordering (ascending vs descending): */
557 
558 
559 /*     SELECT Column Descriptors */
560 /*     --------------------------- */
561 
562 /*     Each SELECT column descriptor contains descriptors for */
563 /*     the table containing the column and for the name of the column */
564 /*     itself. */
565 
566 
567 /*        - Size of a SELECT column descriptor: */
568 
569 
570 /*     Miscellaneous parameters: */
571 
572 
573 /*     EQIMIN is the minimum size of the integer portion of */
574 /*     an encoded query.  EQIMIN depends on the parameters */
575 
576 /*        MAXTAB */
577 /*        MAXCON */
578 /*        MAXORD */
579 /*        MAXSEL */
580 
581 /*     all of which are declared in the include file ekqlimit.inc. */
582 /*     The functional definition of EQIMIN is: */
583 
584 /*     INTEGER               EQIMIN */
585 /*     PARAMETER           ( EQIMIN =   EQVBAS */
586 /*    .                              +  MAXTAB * EQVDSZ * 2 */
587 /*    .                              +  MAXCON * EQCDSZ */
588 /*    .                              +  MAXCON */
589 /*    .                              +  MAXORD * EQODSZ */
590 /*    .                              +  MAXSEL * EQSDSZ     ) */
591 
592 
593 /*     End Include Section:  EK Encoded Query Internal Parameters */
594 
595 /* $ Disclaimer */
596 
597 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
598 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
599 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
600 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
601 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
602 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
603 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
604 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
605 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
606 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
607 
608 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
609 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
610 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
611 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
612 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
613 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
614 
615 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
616 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
617 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
618 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
619 
620 
621 /*     Include Section:  EK Table Name Size */
622 
623 /*        ektnamsz.inc Version 1    17-JAN-1995 (NJB) */
624 
625 
626 /*     Size of table name, in characters. */
627 
628 
629 /*     End Include Section:  EK Table Name Size */
630 
631 /* $ Brief_I/O */
632 
633 /*     Variable  I/O  Description */
634 /*     --------  ---  -------------------------------------------------- */
635 /*     EQRYI     I-O  Integer component of query. */
636 /*     EQRYC     I-O  Character component of query. */
637 /*     ERROR      O   Error flag. */
638 /*     ERRMSG     O   Error message. */
639 /*     ERRPTR     O   Position in query where error was detected. */
640 
641 /* $ Detailed_Input */
642 
643 /*     QUERY          is the original query from which EQRYI and EQRYC */
644 /*                    were obtained.  QUERY is used only for */
645 /*                    construction of error messages. */
646 
647 /*     EQRYI          is the integer portion of an encoded EK query. */
648 /*                    The query must have been parsed. */
649 
650 /*     EQRYC          is the character portion of an encoded EK query. */
651 
652 /* $ Detailed_Output */
653 
654 /*     EQRYI          is the integer portion of an encoded EK query. */
655 /*                    On output, all names have been resolved, and */
656 /*                    table names, aliases, and column names have */
657 /*                    been semantically checked. */
658 
659 /*     EQRYC          is the character portion of an encoded EK query. */
660 
661 /*     ERROR          is a logical flag indicating whether an error was */
662 /*                    detected.  The error could be a name resolution */
663 /*                    error or a semantic error. */
664 
665 /*     ERRMSG         is an error message describing an error in the */
666 /*                    input query, if one was detected.  If ERROR is */
667 /*                    returned .FALSE., then ERRPTR is undefined. */
668 
669 /*     ERRPTR         is the character position in the original query */
670 /*                    at which an error was detected, if an error was */
671 /*                    found.  This index refers to the offending lexeme's */
672 /*                    position in the original query represented by the */
673 /*                    input encoded query.  If ERROR is returned .FALSE., */
674 /*                    ERRPTR is undefined. */
675 /* $ Parameters */
676 
677 /*     None. */
678 
679 /* $ Exceptions */
680 
681 /*     1)  If the input query is not initialized, the error will be */
682 /*         diagnosed by routines called by this routine.  The outputs */
683 /*         will not be modified. */
684 
685 /*     2)  If the input query has not been parsed, the error */
686 /*         SPICE(QUERYNOTPARSED) will be signalled.  The outputs */
687 /*         will not be modified. */
688 
689 /*     3)  If any sort of name resolution error or semantic error is */
690 /*         detected in the input query, the output flag ERROR is set, */
691 /*         and an error message is returned.  The checks performed by */
692 /*         this routine are listed below: */
693 
694 /*           - All tables named in the FROM clause must be loaded */
695 /*             in the EK system. */
696 
697 /*           - All aliases in the FROM clause must be distinct. */
698 
699 /*           - No alias may be the name of a table in the FROM clause, */
700 /*             unless it is identical to the name of the table it is */
701 /*             associated with. */
702 
703 /*           - No column name may be qualified with a name that is not */
704 /*             the name or alias of a table in the FROM clause. */
705 
706 /*           - Each qualified column must be present in the table */
707 /*             indicated by its qualifying name. */
708 
709 /*           - Each unqualified column name must be the name of a */
710 /*             column present in exactly one of the tables listed in the */
711 /*             FROM clause. */
712 /* $ Files */
713 
714 /*     None. */
715 
716 /* $ Particulars */
717 
718 /*     Resolution of table names involves finding each table's ordinal */
719 /*     position in the FROM clause, and setting the table's descriptor */
720 /*     to record that position.  The same is done for column descriptors. */
721 
722 /* $ Examples */
723 
724 /*     See EKFIND. */
725 
726 /* $ Restrictions */
727 
728 /*     None. */
729 
730 /* $ Literature_References */
731 
732 /*     None. */
733 
734 /* $ Author_and_Institution */
735 
736 /*     N.J. Bachman       (JPL) */
737 
738 /* $ Version */
739 
740 /* -    Beta Version 1.0.0, 17-OCT-1995 (NJB) */
741 
742 /* -& */
743 
744 /*     SPICELIB functions */
745 
746 
747 /*     Local parameters */
748 
749 
750 /*     Local variables */
751 
752 
753 /*     No error to start with. */
754 
755     *error = FALSE_;
756     s_copy(errmsg, " ", errmsg_len, (ftnlen)1);
757     *errptr = 0;
758 
759 /*     The query must have been parsed at this point, or it's no go. */
760 
761     zzekreqi_(eqryi, "PARSED", &iparse, (ftnlen)6);
762     if (failed_()) {
763 	return 0;
764     }
765     if (iparse == -1) {
766 	chkin_("ZZEKNRES", (ftnlen)8);
767 	setmsg_("Encoded query has not been parsed.", (ftnlen)34);
768 	sigerr_("SPICE(QUERYNOTPARSED)", (ftnlen)21);
769 	chkout_("ZZEKNRES", (ftnlen)8);
770 	return 0;
771     }
772 
773 /*     Get the important counts from the query. */
774 
775     zzekreqi_(eqryi, "NUM_TABLES", &ntab, (ftnlen)10);
776     zzekreqi_(eqryi, "NUM_CONSTRAINTS", &ncns, (ftnlen)15);
777     zzekreqi_(eqryi, "NUM_CONJUNCTIONS", &ncnj, (ftnlen)16);
778     zzekreqi_(eqryi, "NUM_ORDERBY_COLS", &nord, (ftnlen)16);
779     zzekreqi_(eqryi, "NUM_SELECT_COLS", &nsel, (ftnlen)15);
780 
781 /*     Start out by fetching the table names and their aliases. */
782 
783     i__1 = ntab;
784     for (i__ = 1; i__ <= i__1; ++i__) {
785 	zzekqtab_(eqryi, eqryc, &i__, table + (((i__2 = i__ - 1) < 10 && 0 <=
786 		i__2 ? i__2 : s_rnge("table", i__2, "zzeknres_", (ftnlen)254))
787 		 << 6), alias + (((i__3 = i__ - 1) < 10 && 0 <= i__3 ? i__3 :
788 		s_rnge("alias", i__3, "zzeknres_", (ftnlen)254)) << 6),
789 		eqryc_len, (ftnlen)64, (ftnlen)64);
790     }
791 
792 /*     Make sure that the aliases are distinct.  Rather than sorting */
793 /*     them, we'll check them in left-to-right order. */
794 
795     i__1 = ntab - 1;
796     for (i__ = 1; i__ <= i__1; ++i__) {
797 	i__2 = ntab;
798 	for (j = i__ + 1; j <= i__2; ++j) {
799 	    if (s_cmp(alias + (((i__3 = i__ - 1) < 10 && 0 <= i__3 ? i__3 :
800 		    s_rnge("alias", i__3, "zzeknres_", (ftnlen)265)) << 6),
801 		    alias + (((i__4 = j - 1) < 10 && 0 <= i__4 ? i__4 :
802 		    s_rnge("alias", i__4, "zzeknres_", (ftnlen)265)) << 6), (
803 		    ftnlen)64, (ftnlen)64) == 0 && s_cmp(alias + (((i__5 =
804 		    i__ - 1) < 10 && 0 <= i__5 ? i__5 : s_rnge("alias", i__5,
805 		    "zzeknres_", (ftnlen)265)) << 6), " ", (ftnlen)64, (
806 		    ftnlen)1) != 0) {
807 		*error = TRUE_;
808 		s_copy(errmsg, "Non-distinct alias <#> was found.",
809 			errmsg_len, (ftnlen)33);
810 		base = ((j - 1 << 1) + 1) * 6 + 19;
811 		lxb = eqryi[base + 7];
812 		lxe = eqryi[base + 8];
813 		repmc_(errmsg, "#", query + (lxb - 1), errmsg, errmsg_len, (
814 			ftnlen)1, lxe - (lxb - 1), errmsg_len);
815 		*errptr = lxb;
816 		return 0;
817 	    }
818 
819 /*           We've checked the Jth alias for a match. */
820 
821 	}
822     }
823 
824 /*     Make sure that no alias matches a table name other than that of */
825 /*     the table it corresponds to. */
826 
827     i__1 = ntab;
828     for (i__ = 1; i__ <= i__1; ++i__) {
829 	j = isrchc_(alias + (((i__2 = i__ - 1) < 10 && 0 <= i__2 ? i__2 :
830 		s_rnge("alias", i__2, "zzeknres_", (ftnlen)295)) << 6), &ntab,
831 		 table, (ftnlen)64, (ftnlen)64);
832 	if (j != 0) {
833 	    if (j != i__) {
834 		*error = TRUE_;
835 		s_copy(errmsg, "Alias <#> conflicts with table name.",
836 			errmsg_len, (ftnlen)36);
837 		base = ((i__ - 1 << 1) + 1) * 6 + 19;
838 		lxb = eqryi[base + 7];
839 		lxe = eqryi[base + 8];
840 		repmc_(errmsg, "#", query + (lxb - 1), errmsg, errmsg_len, (
841 			ftnlen)1, lxe - (lxb - 1), errmsg_len);
842 		*errptr = lxb;
843 		return 0;
844 	    }
845 	}
846     }
847 
848 /*     Make sure that all of the tables are loaded in the EK system. */
849 
850     ekntab_(&nload);
851     i__1 = ntab;
852     for (i__ = 1; i__ <= i__1; ++i__) {
853 	fnd = FALSE_;
854 	j = 1;
855 	while(j <= nload && ! fnd) {
856 	    ektnam_(&j, ltable, (ftnlen)64);
857 	    if (s_cmp(table + (((i__2 = i__ - 1) < 10 && 0 <= i__2 ? i__2 :
858 		    s_rnge("table", i__2, "zzeknres_", (ftnlen)336)) << 6),
859 		    ltable, (ftnlen)64, (ftnlen)64) == 0) {
860 
861 /*              When we find a loaded table, save the column count for */
862 /*              that table. */
863 
864 		fnd = TRUE_;
865 		ekccnt_(table, &cc[(i__2 = i__ - 1) < 10 && 0 <= i__2 ? i__2 :
866 			 s_rnge("cc", i__2, "zzeknres_", (ftnlen)342)], (
867 			ftnlen)64);
868 	    } else {
869 		++j;
870 	    }
871 	}
872 	if (! fnd) {
873 	    *error = TRUE_;
874 	    s_copy(errmsg, "Table <#> is not currently loaded.", errmsg_len, (
875 		    ftnlen)34);
876 
877 /*           In order to set the error pointer, we'll need the */
878 /*           lexeme begin value for the offending table. */
879 
880 	    base = (i__ - 1) * 12 + 19;
881 	    lxb = eqryi[base + 7];
882 	    lxe = eqryi[base + 8];
883 	    repmc_(errmsg, "#", query + (lxb - 1), errmsg, errmsg_len, (
884 		    ftnlen)1, lxe - (lxb - 1), errmsg_len);
885 	    *errptr = lxb;
886 	    return 0;
887 	}
888     }
889 
890 /*     At this point, the tables and aliases are deemed correct.  For */
891 /*     safety, fill in each table and alias descriptor with its */
892 /*     ordinal position. */
893 
894     i__1 = ntab;
895     for (i__ = 1; i__ <= i__1; ++i__) {
896 	base = (i__ - 1) * 12 + 19;
897 	eqryi[base + 11] = i__;
898 	eqryi[base + 17] = i__;
899     }
900 
901 /*     Check the column names used in the constraints. */
902 
903     i__1 = ncns;
904     for (i__ = 1; i__ <= i__1; ++i__) {
905 
906 /*        Calculate the base address of the constraint. */
907 
908 	base = ntab * 12 + 19 + (i__ - 1) * 26;
909 
910 /*        Obtain the constraint type. */
911 
912 	cnstyp = eqryi[base + 6];
913 
914 /*        Check the column and table on the LHS of the constraint. */
915 
916 	i__2 = base + 1;
917 	zzekcchk_(query, eqryi, eqryc, &ntab, table, alias, &i__2, error,
918 		errmsg, errptr, query_len, eqryc_len, (ftnlen)64, (ftnlen)64,
919 		errmsg_len);
920 	if (*error) {
921 	    return 0;
922 	}
923 	if (cnstyp == 1) {
924 
925 /*           Check the column and table on the RHS of the constraint. */
926 
927 	    i__2 = base + 14;
928 	    zzekcchk_(query, eqryi, eqryc, &ntab, table, alias, &i__2, error,
929 		    errmsg, errptr, query_len, eqryc_len, (ftnlen)64, (ftnlen)
930 		    64, errmsg_len);
931 	    if (*error) {
932 		return 0;
933 	    }
934 	}
935     }
936 
937 /*     Do the same checks and assignments for the SELECT columns. */
938 
939     i__1 = nsel;
940     for (i__ = 1; i__ <= i__1; ++i__) {
941 
942 /*        Calculate the base address of the SELECT column descriptor. */
943 
944 	base = ntab * 12 + 19 + ncnj + ncns * 26 + nord * 13 + (i__ - 1) * 12;
945 	zzekcchk_(query, eqryi, eqryc, &ntab, table, alias, &base, error,
946 		errmsg, errptr, query_len, eqryc_len, (ftnlen)64, (ftnlen)64,
947 		errmsg_len);
948 	if (*error) {
949 	    return 0;
950 	}
951     }
952 
953 /*     Do the same checks and assignments for the order-by columns. */
954 
955     i__1 = nord;
956     for (i__ = 1; i__ <= i__1; ++i__) {
957 
958 /*        Calculate the base address of the order-by column descriptor. */
959 
960 	base = ntab * 12 + 19 + ncnj + ncns * 26 + (i__ - 1) * 13;
961 	zzekcchk_(query, eqryi, eqryc, &ntab, table, alias, &base, error,
962 		errmsg, errptr, query_len, eqryc_len, (ftnlen)64, (ftnlen)64,
963 		errmsg_len);
964 	if (*error) {
965 	    return 0;
966 	}
967     }
968 
969 /*     Indicate completion of name resolution. */
970 
971     zzekweqi_("NAMES_RESOLVED", &c__1, eqryi, (ftnlen)14);
972     return 0;
973 } /* zzeknres_ */
974 
975