]> andersk Git - moira.git/blob - clients/mrtest/comp.c
dbck fixes by kcr, dkk, and myself from the end of the summer.
[moira.git] / clients / mrtest / comp.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1991 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  *
10  */
11
12 #include <ctype.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <moira.h>
16
17 extern char *DataBuf;
18 extern char *ErrorBuf;
19 extern int count;
20
21 CompData (argc, argv, CompStr)
22 int argc;        /* # of fields outputted by Moira  */
23 char **argv;     /* Array of strings outputted by Moira */
24 char **CompStr;  /* Pointer to Comparison String -- Data section only */
25 /*  CompData uses the global variables: */
26 /*      char *DataBuf;   */
27 /*      char *ErrorBuf;  */
28 /*      int  count;      */
29 {
30 int Field = 0; /* Field number being compared  */
31 int Len, Len2;   /* Length of a comparison field */
32 int i;     /* index for printing */
33
34 if (*ErrorBuf == '\0') {    /* Don't process if there's a data error already */
35
36   for (;(**CompStr) && isspace(**CompStr); (*CompStr)++); /*whitespace*/
37   if ((**CompStr != '{') && (**CompStr != '\0')) 
38     strcpy (ErrorBuf, "Malformed Comparison String");
39   else if (**CompStr != '\0') {
40     for ((*CompStr)++; ((**CompStr != '}') && (**CompStr != '\0') 
41                         && (Field < argc));) {
42       for (;**CompStr && isspace(**CompStr); (*CompStr)++);  /* Whitespace */
43       if (**CompStr == '*') {   /* Wildcard -- field automatically checks */
44         (*CompStr)++;}
45       else if (**CompStr == '"') {  /* Compare a field */
46         (*CompStr)++;
47         Len = (int)(strchr(*CompStr, '"')) - (int)(*CompStr);
48         if (Len < 0) {
49           strcpy (ErrorBuf, "Malformed Comparison String");
50           break;}
51         else if ((strncmp (*CompStr, argv[Field], Len)) ||
52                  (strlen(argv[Field]) != Len)) {   /* Data Error */
53           strcpy (ErrorBuf, "Data Error");
54           break;}
55         *CompStr = (char *)strchr(*CompStr, '"');
56         (*CompStr)++;}
57       else {
58         Len  = (int)(strchr(*CompStr, ' ')) - (int)(*CompStr);
59         Len2 = (int)(strchr(*CompStr, '}')) - (int)(*CompStr);
60         if ((Len < 0) || ((Len2 >= 0) && (Len2 < Len)))
61           Len = Len2;
62         if (Len < 0) 
63           strcpy (ErrorBuf, "Malformed Comparison String");
64         else {
65           if ((strncmp (*CompStr, argv[Field], Len)) ||
66               (strlen(argv[Field]) != Len)) {   /* Data Error */
67             strcpy (ErrorBuf, "Data Error");
68             break;}
69           *CompStr = (char *)(Len + (int)(*CompStr));}}
70       Field++;}
71     for (;**CompStr && isspace(**CompStr); (*CompStr)++);  /* Whitespace */
72     if (*ErrorBuf == '\0') {
73       if (**CompStr == '\0')
74         strcpy (ErrorBuf, "Malformed Comparison String");
75       else if ((**CompStr != '}') || (Field < argc)) 
76         strcpy (ErrorBuf, "Data Error");}
77     (*CompStr)++;
78   }
79   if (!strcmp(ErrorBuf, "Data Error")) strcat (DataBuf, "*****");
80 }
81 else {
82   strcat (DataBuf, "     ");}
83
84 if (strcmp(ErrorBuf, "Data Error")) strcat (DataBuf, "     ");
85
86 /* Write Query output to data buffer */
87 for (i = 0; i < argc; i++) {
88   if (i != 0) strcat (DataBuf, ", ");
89   strcat (DataBuf, argv[i]);
90 }
91 strcat (DataBuf, "\n");
92 count++;
93 return(MR_CONT);
94 }
95       
96             
97           
98
This page took 0.047974 seconds and 5 git commands to generate.