/* * rpmdata.c : handle the data in the RPM database. * * $Id: rpmdata.c,v 1.7 1997/11/13 06:37:39 veillard Exp $ * * $Log: rpmdata.c,v $ * Revision 1.7 1997/11/13 06:37:39 veillard * Added statistics, ByName, and generation of index.html, Daniel. * * Revision 1.6 1997/11/13 05:04:34 veillard * Lot of improvements, copyright, URLs, E-mail, and config files, Daniel. * * Revision 1.5 1997/11/12 05:56:56 veillard * Beginning of the coding for the configuration, Daniel. * * Revision 1.4 1997/11/11 22:28:11 veillard * Added the support for dependancies on resources, Daniel. * * Revision 1.3 1997/11/11 21:18:53 veillard * Improved a lot, removed bugs related to sorting, Daniel. * * Revision 1.2 1997/11/11 11:10:10 veillard * State after one night of work, Daniel * * Revision 1.1.1.1 1997/11/11 07:12:32 veillard * First revision of RPM-Check * */ #include #include #include #include #include #include #include #include #include #include "rpmdata.h" /* * the lists of RPM and ressources collected so far. */ rpmDataPtr rpmList = NULL; rpmRessPtr ressList = NULL; rpmDirPtr dirList = NULL; /* * Add a ressource to the list if it doesn't exists and add the * corresponding RPM as a provider. */ rpmRessPtr rpmRessAdd(char *ress, rpmDataPtr rpm) { rpmRessPtr cur = ressList; /* search for the ressource */ while (cur != NULL) { if (!strcmp(ress, cur->name)) goto found; cur = cur->next; } /* not found allocate a new ressource block and fill it */ cur = (rpmRessPtr) malloc(sizeof(rpmRess)); if (cur == NULL) { fprintf(stderr, "cannot allocate %d bytes: %s\n", sizeof(rpmRess), strerror(errno)); return(NULL); } cur->name = strdup(ress); cur->nb_provider = 0; cur->next = ressList; ressList = cur; found: /* add the provider to the array */ if (cur->nb_provider >= MAX_PROVIDE) { fprintf(stderr, "MAX_PROVIDE %d overflow, increase the limit!\n", MAX_PROVIDE); return(NULL); } cur->provider[cur->nb_provider++] = rpm; return(cur); } /* * Add a ressource to the list if it doesn't exists and add the * corresponding RPM as a requester. */ rpmRessPtr rpmRequAdd(char *requ, rpmDataPtr rpm) { rpmRessPtr cur = ressList; /* search for the ressource */ while (cur != NULL) { if (!strcmp(requ, cur->name)) goto found; cur = cur->next; } /* not found allocate a new ressource block and fill it */ cur = (rpmRessPtr) malloc(sizeof(rpmRess)); if (cur == NULL) { fprintf(stderr, "cannot allocate %d bytes: %s\n", sizeof(rpmRess), strerror(errno)); return(NULL); } cur->name = strdup(requ); cur->nb_provider = 0; cur->next = ressList; ressList = cur; found: return(cur); } /* * print an RPM data block */ void rpmDataPrint(rpmDataPtr rpm) { int i; printf("%s\n", rpm->filename); printf("%s-%s-%s\n", rpm->name, rpm->version, rpm->release); if (rpm->summary) printf(" %s\n", rpm->summary); for (i = 0; i < rpm->nb_ressources ;i++) printf("-> %s\n", rpm->ressources[i]->name); } /* * A generic sort function. */ typedef int (*rpmCmpFunc)(rpmDataPtr a, rpmDataPtr b); void rpmGenericSort(rpmCmpFunc rpmCmp) { rpmDataPtr unsorted; rpmDataPtr cur, prev; unsorted = rpmList; rpmList = NULL; while (unsorted != NULL) { cur = unsorted; unsorted = cur->next; cur->next = NULL; if ((rpmList == NULL) || (rpmCmp(cur, rpmList) < 0)) { cur->next = rpmList; rpmList = cur; } else { prev = rpmList; while ((prev->next != NULL) && ((rpmCmp(cur, prev->next) >= 0))) { prev = prev->next; } cur->next = prev->next; prev->next = cur; } } } /* * rpmGroupCmp : comparison of groupe values, if equal, compare * the names. */ int rpmGroupCmp(rpmDataPtr a, rpmDataPtr b) { int res = strcmp(a->group, b->group); if (res) return(res); res = strcmp(a->name, b->name); return(res); } /* * sort all the RPMs by Group. */ void rpmGroupSort(void) { #ifdef DEBUG rpmDataPtr cur, prev; #endif rpmGenericSort(rpmGroupCmp); #ifdef DEBUG printf(" List of Groups\n"); cur = rpmList; prev = NULL; while (cur != NULL) { if ((prev == NULL) || (strcmp(prev->group, cur->group))) { printf("%s\n", cur->group); } prev = cur; cur = cur->next; } #endif } /* * rpmDistribCmp : comparison of distributions values, if equal, compare * the names. */ int rpmDistribCmp(rpmDataPtr a, rpmDataPtr b) { int res = strcmp(a->distribution, b->distribution); if (res) return(res); res = strcmp(a->name, b->name); return(res); } /* * sort all the RPMs by Distribution. */ void rpmDistribSort(void) { #ifdef DEBUG rpmDataPtr cur, prev; #endif rpmGenericSort(rpmDistribCmp); #ifdef DEBUG printf(" List of Distributions\n"); cur = rpmList; prev = NULL; while (cur != NULL) { if ((prev == NULL) || (strcmp(prev->distribution, cur->distribution))) { printf("%s\n", cur->distribution); } prev = cur; cur = cur->next; } #endif } /* * rpmVendorCmp : comparison of vendor values, if equal, compare * distributions, then compares the names. */ int rpmVendorCmp(rpmDataPtr a, rpmDataPtr b) { int res = strcmp(a->vendor, b->vendor); if (res) return(res); res = strcmp(a->distribution, b->distribution); if (res) return(res); res = strcmp(a->name, b->name); return(res); } /* * sort all the RPMs by Vendor. */ void rpmVendorSort(void) { #ifdef DEBUG rpmDataPtr cur, prev; #endif rpmGenericSort(rpmVendorCmp); #ifdef DEBUG printf(" List of Vendors\n"); cur = rpmList; prev = NULL; while (cur != NULL) { if ((prev == NULL) || (strcmp(prev->vendor, cur->vendor))) { printf("%s\n", cur->vendor); } prev = cur; cur = cur->next; } #endif } /* * rpmDateCmp : comparison of date values, if equal, compare * distributions, then compares the names. */ int rpmDateCmp(rpmDataPtr a, rpmDataPtr b) { int res = (b->date - a->date) / (60 * 60 * 24); if (res) return(res); res = strcmp(a->name, b->name); return(res); } /* * sort all the RPMs by Date. */ void rpmDateSort(void) { rpmGenericSort(rpmDateCmp); } /* * rpmNameCmp : comparison of names. */ int rpmNameCmp(rpmDataPtr a, rpmDataPtr b) { int res = strcasecmp(a->name, b->name); return(res); } /* * sort all the RPMs by Name. */ void rpmNameSort(void) { rpmGenericSort(rpmNameCmp); } /* * print all RPM data blocks */ void rpmDataPrintAll(void) { rpmDataPtr cur = rpmList; while (cur != NULL) { rpmDataPrint(cur); cur = cur->next; } } /* * Try to extract an E-mail address fron a string. */ char *extractEMail(char *string) { static char buf[200]; char *start; char *end; start = strchr(string, '@'); if (start == NULL) return(NULL); end = start; do { start--; if ((!isprint(*start)) || (isblank(*start)) || (*start == '@') || (*start == '<') || (*start == '>') || (*start == '(') || (*start == ')') || (*start == '[') || (*start == ']') || (*start == ';') || (*start == ',') || (*start == ',')) { start++; break; } } while (start != string); do { end++; if ((!isprint(*end)) || (isblank(*end)) || (*end == '@') || (*end == '<') || (*end == '>') || (*end == '(') || (*end == ')') || (*end == '[') || (*end == ']') || (*end == ';') || (*end == ',') || (*end == ',')) { break; } } while (*end != '\0'); strncpy(buf, start, end - start); buf[end - start] = '\0'; return(buf); }