From: cse@wetware.com (Scott Ellard) Newsgroups: comp.databases.informix Date: Fri, 17 Jun 1994 21:45:40 GMT Subject: Comparing RECORD's /*------------------------------------------------------------------------------ * * FUNCTION: fgl_reccmp.c * * AUTHOR: C. S. Ellard * * PURPOSE: compare two 4gl records for equality. * * USAGE: LET N = fgl_reccmp(rec1.*, rec2.*) * * N == 0, records compare equal * N != 0, records compare not equal at field number N * NOTES: * * 1. Nulls compare equal. * 2. Trailing spaces are not significant. * 3. Assumes Ifmx string conversions create equal strings for numerics. * 4. BLOBS aren't handled. * *------------------------------------------------------------------------------ */ #include #include #include #define MAXARGSIZE (512) /* adjust to largest string expected */ int fgl_reccmp(nargs) int nargs; { char* *argvec; int i; if ((nargs <= 0) || ((nargs % 2) != 0)) { (void) fprintf(stderr, "fgl_reccmp: EINVAL = %d\n", nargs); exit(1); } if ((argvec = (char**) malloc(nargs * sizeof(char**))) == 0) { (void) fprintf(stderr, "fgl_reccmp: ENOMEM\n"); exit(1); } for (i = nargs-1; i >= 0; --i) { char buff[MAXARGSIZE+1]; /* +1 for the NULL */ char *p; popquote(buff, sizeof(buff)); if (*buff == 0) { argvec[i] = ""; continue; } /* trim trailing spaces */ for (p = buff + (sizeof(buff)-2); p >= buff && *p == ' '; --p) ; *(p+1) = 0; if ((argvec[i] = strdup(buff)) == 0) { (void) fprintf(stderr, "fgl_reccmp: ENOMEM\n"); exit(1); } } for (nargs /= 2, i = 0; i < nargs; ++i) { if (strcmp(argvec[i], argvec[i+nargs]) != 0) break; } retint((i == nargs) ? 0 : ++i); /* adjust from origin 0 to origin 1 */ for (nargs *= 2, i = 0; i < nargs; ++i) { if (*argvec[i] != 0) free(argvec[i]); } free((char*)argvec); return(1); }