6 * Copyright (C) 1991 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
17 extern char *ErrorBuf;
20 CompData (argc, argv, CompStr)
21 int argc; /* # of fields outputted by Moira */
22 char **argv; /* Array of strings outputted by Moira */
23 char **CompStr; /* Pointer to Comparison String -- Data section only */
24 /* CompData uses the global variables: */
29 int Field = 0; /* Field number being compared */
30 int Len, Len2; /* Length of a comparison field */
31 int i; /* index for printing */
33 if (*ErrorBuf == '\0') { /* Don't process if there's a data error already */
35 for (;(**CompStr) && isspace(**CompStr); (*CompStr)++); /*whitespace*/
36 if ((**CompStr != '{') && (**CompStr != '\0'))
37 strcpy (ErrorBuf, "Malformed Comparison String");
38 else if (**CompStr != '\0') {
39 for ((*CompStr)++; ((**CompStr != '}') && (**CompStr != '\0')
40 && (Field < argc));) {
41 for (;**CompStr && isspace(**CompStr); (*CompStr)++); /* Whitespace */
42 if (**CompStr == '*') { /* Wildcard -- field automatically checks */
44 else if (**CompStr == '"') { /* Compare a field */
46 Len = (int)(index(*CompStr, '"')) - (int)(*CompStr);
48 strcpy (ErrorBuf, "Malformed Comparison String");
50 else if ((strncmp (*CompStr, argv[Field], Len)) ||
51 (strlen(argv[Field]) != Len)) { /* Data Error */
52 strcpy (ErrorBuf, "Data Error");
54 *CompStr = (char *)index(*CompStr, '"');
57 Len = (int)(index(*CompStr, ' ')) - (int)(*CompStr);
58 Len2 = (int)(index(*CompStr, '}')) - (int)(*CompStr);
59 if ((Len < 0) || ((Len2 >= 0) && (Len2 < Len)))
62 strcpy (ErrorBuf, "Malformed Comparison String");
64 if ((strncmp (*CompStr, argv[Field], Len)) ||
65 (strlen(argv[Field]) != Len)) { /* Data Error */
66 strcpy (ErrorBuf, "Data Error");
68 *CompStr = (char *)(Len + (int)(*CompStr));}}
70 for (;**CompStr && isspace(**CompStr); (*CompStr)++); /* Whitespace */
71 if (*ErrorBuf == '\0') {
72 if (**CompStr == '\0')
73 strcpy (ErrorBuf, "Malformed Comparison String");
74 else if ((**CompStr != '}') || (Field < argc))
75 strcpy (ErrorBuf, "Data Error");}
78 if (!strcmp(ErrorBuf, "Data Error")) strcat (DataBuf, "*****");
81 strcat (DataBuf, " ");}
83 if (strcmp(ErrorBuf, "Data Error")) strcat (DataBuf, " ");
85 /* Write Query output to data buffer */
86 for (i = 0; i < argc; i++) {
87 if (i != 0) strcat (DataBuf, ", ");
88 strcat (DataBuf, argv[i]);
90 strcat (DataBuf, "\n");