diff options
author | marc <devnull@localhost> | 1996-07-15 01:56:15 +0000 |
---|---|---|
committer | marc <devnull@localhost> | 1996-07-15 01:56:15 +0000 |
commit | e252e69b3e9773a48ab19b135e5329e1b8839125 (patch) | |
tree | eee3b8e3a632345dfe657a0cc46dfa2c0c170915 /lib | |
parent | 7b947a2d232bb4fbb0bcdd93278f1529a159398f (diff) | |
download | rpm-e252e69b3e9773a48ab19b135e5329e1b8839125.tar.gz rpm-e252e69b3e9773a48ab19b135e5329e1b8839125.tar.bz2 rpm-e252e69b3e9773a48ab19b135e5329e1b8839125.zip |
heavy hackage:
added: getOsNum getArchNum getOsName getArchName
added: showRc()
remove from rpmrc: docdir, os, build_arch
add to rpmrc: packager
added os_data and arch_data to hold arch short_name and archnumber
(same for os)
always parse /usr/lib/rpmrc
added buildarchtranslate, and buildostranslate to rpmrc
to specify default build arch other than what uname() returns (and os)
CVS patchset: 836
CVS date: 1996/07/15 01:56:15
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rpmrc.c | 398 |
1 files changed, 340 insertions, 58 deletions
diff --git a/lib/rpmrc.c b/lib/rpmrc.c index 5970e8249..074aaad88 100644 --- a/lib/rpmrc.c +++ b/lib/rpmrc.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/utsname.h> #include "messages.h" #include "misc.h" @@ -15,24 +16,34 @@ struct option { char * name; int var; int archSpecific; -} ; +}; struct archEquiv { - char * arch, * equiv; + char * arch; + char * equiv; +}; + +struct defaultEntry { + char *name; + char *defName; +}; + +struct dataEntry { + char *name; + char *short_name; + short num; }; /* this *must* be kept in alphabetical order */ struct option optionTable[] = { - { "build_arch", RPMVAR_BUILDARCH, 0 }, { "builddir", RPMVAR_BUILDDIR, 0 }, { "buildroot", RPMVAR_BUILDROOT, 0 }, { "dbpath", RPMVAR_DBPATH, 0 }, { "distribution", RPMVAR_DISTRIBUTION, 0 }, - { "docdir", RPMVAR_DOCDIR, 0 }, { "excludedocs", RPMVAR_EXCLUDEDOCS, 0 }, { "messagelevel", RPMVAR_MESSAGELEVEL, 0 }, { "optflags", RPMVAR_OPTFLAGS, 1 }, - { "os", RPMVAR_OS, 0 }, + { "packager", RPMVAR_PACKAGER, 0 }, { "pgp_name", RPMVAR_PGP_NAME, 0 }, { "pgp_path", RPMVAR_PGP_PATH, 0 }, { "require_distribution", RPMVAR_REQUIREDISTRIBUTION, 0 }, @@ -51,15 +62,38 @@ struct option optionTable[] = { static int optionTableSize = sizeof(optionTable) / sizeof(struct option); -static int readRpmrc(FILE * fd, char * fn, int readArchSpecific); +#define READ_TABLES 1 +#define READ_OTHER 2 + +static int readRpmrc(FILE * fd, char * fn, int readWhat); static void setDefaults(void); static void setPathDefault(int var, char * s); static int optionCompare(const void * a, const void * b); static int numArchCompats = 0; static struct archEquiv * archCompatTable = NULL; - static void addArchCompatibility(char * arch, char * equiv); +static void setArchOs(char *arch, char *os, int building); +static int addData(struct dataEntry **table, int *tableLen, char *line, + char *fn, int lineNum); +static int addDefault(struct defaultEntry **table, int *tableLen, char *line, + char *fn, int lineNum); +static struct dataEntry *lookupInDataTable(char *name, + struct dataEntry *table, + int tableLen); +static char *lookupInDefaultTable(char *name, + struct defaultEntry *table, + int tableLen); + +static int archDefaultTableLen = 0; +static int osDefaultTableLen = 0; +static int archDataTableLen = 0; +static int osDataTableLen = 0; +static struct defaultEntry * archDefaultTable = NULL; +static struct defaultEntry * osDefaultTable = NULL; +static struct dataEntry * archDataTable = NULL; +static struct dataEntry * osDataTable = NULL; + static int optionCompare(const void * a, const void * b) { return strcmp(((struct option *) a)->name, ((struct option *) b)->name); } @@ -142,11 +176,112 @@ static void addArchCompatibility(char * arch, char * equiv) { archCompatTable[numArchCompats - 1].equiv = strdup(equiv); } -static int readRpmrc(FILE * f, char * fn, int readArchSpecific) { +static int addData(struct dataEntry **table, int *tableLen, char *line, + char *fn, int lineNum) +{ + struct dataEntry *t; + char *s, *s1; + + if (! *tableLen) { + *tableLen = 1; + *table = malloc(sizeof(struct dataEntry)); + } else { + (*tableLen)++; + *table = realloc(*table, sizeof(struct dataEntry) * (*tableLen)); + } + t = & ((*table)[*tableLen - 1]); + + t->name = strtok(line, ": \t"); + t->short_name = strtok(NULL, " \t"); + s = strtok(NULL, " \t"); + if (! (t->name && t->short_name && s)) { + error(RPMERR_RPMRC, "Incomplete data line at %s:%d\n", fn, lineNum); + return RPMERR_RPMRC; + } + if (strtok(NULL, " \t")) { + error(RPMERR_RPMRC, "Too many args in data line at %s:%d\n", + fn, lineNum); + return RPMERR_RPMRC; + } + + t->num = strtoul(s, &s1, 10); + if ((*s1) || (s1 == s) || (t->num == ULONG_MAX)) { + error(RPMERR_RPMRC, "Bad arch/os number: %s (%s:%d)\n", s, + fn, lineNum); + return(RPMERR_RPMRC); + } + + t->name = strdup(t->name); + t->short_name = strdup(t->short_name); + + return 0; +} + +static int addDefault(struct defaultEntry **table, int *tableLen, char *line, + char *fn, int lineNum) +{ + struct defaultEntry *t; + + if (! *tableLen) { + *tableLen = 1; + *table = malloc(sizeof(struct defaultEntry)); + } else { + (*tableLen)++; + *table = realloc(*table, sizeof(struct defaultEntry) * (*tableLen)); + } + t = & ((*table)[*tableLen - 1]); + + t->name = strtok(line, ": \t"); + t->defName = strtok(NULL, " \t"); + if (! (t->name && t->defName)) { + error(RPMERR_RPMRC, "Incomplete default line at %s:%d\n", fn, lineNum); + return RPMERR_RPMRC; + } + if (strtok(NULL, " \t")) { + error(RPMERR_RPMRC, "Too many args in default line at %s:%d\n", + fn, lineNum); + return RPMERR_RPMRC; + } + + t->name = strdup(t->name); + t->defName = strdup(t->defName); + + return 0; +} + +static struct dataEntry *lookupInDataTable(char *name, + struct dataEntry *table, + int tableLen) +{ + while (tableLen) { + tableLen--; + if (!strcmp(name, table[tableLen].name)) { + return &(table[tableLen]); + } + } + + return NULL; +} + +static char *lookupInDefaultTable(char *name, + struct defaultEntry *table, + int tableLen) +{ + while (tableLen) { + tableLen--; + if (!strcmp(name, table[tableLen].name)) { + return table[tableLen].defName; + } + } + + return name; +} + +static int readRpmrc(FILE * f, char * fn, int readWhat) { char buf[1024]; char * start; char * chptr; - static char * archName = NULL; + char * archName = NULL; int linenum = 0; struct option * option, searchOption; @@ -208,11 +343,35 @@ static int readRpmrc(FILE * f, char * fn, int readArchSpecific) { /* these are options that don't just get stuffed in a VAR somewhere */ if (!strcmp(start, "arch_compat")) { - if (!readArchSpecific) - if (addArchCompats(chptr, fn, linenum)) return 1; + if (readWhat != READ_TABLES) continue; + if (addArchCompats(chptr, fn, linenum)) + return 1; + } else if (!strcmp(start, "arch_data")) { + if (readWhat != READ_TABLES) continue; + if (addData(&archDataTable, &archDataTableLen, + chptr, fn, linenum)) + return 1; + } else if (!strcmp(start, "os_data")) { + if (readWhat != READ_TABLES) continue; + if (addData(&osDataTable, &osDataTableLen, + chptr, fn, linenum)) + return 1; + } else if (!strcmp(start, "buildarchtranslate")) { + if (readWhat != READ_TABLES) continue; + if (addDefault(&archDefaultTable, &archDefaultTableLen, + chptr, fn, linenum)) + return 1; + } else if (!strcmp(start, "buildostranslate")) { + if (readWhat != READ_TABLES) continue; + if (addDefault(&osDefaultTable, &osDefaultTableLen, + chptr, fn, linenum)) + return 1; + } + if (readWhat == READ_TABLES) { continue; } + /* Parse the argument a little further */ searchOption.name = start; option = bsearch(&searchOption, optionTable, optionTableSize, sizeof(struct option), optionCompare); @@ -222,36 +381,40 @@ static int readRpmrc(FILE * f, char * fn, int readArchSpecific) { return 1; } - if (option->archSpecific && readArchSpecific) { - start = chptr; - - if (!archName) archName = getArchName(); - - for (chptr = start; *chptr && !isspace(*chptr); chptr++); - if (! *chptr) { - error(RPMERR_RPMRC, "missing argument for %s at %s:%d\n", - option->name, fn, linenum); - return 1; - } - *chptr++ = '\0'; - - while (*chptr && isspace(*chptr)) chptr++; - if (! *chptr) { - error(RPMERR_RPMRC, "missing argument for %s at %s:%d\n", - option->name, fn, linenum); - return 1; - } - - if (!strcmp(archName, start)) { - message(MESS_DEBUG, "%s is arg for %s platform", chptr, - archName); - setVar(option->var, chptr); - } - } else { - if (!readArchSpecific) { + if (readWhat == READ_OTHER) { + if (option->archSpecific) { + start = chptr; + + /* getArchName() should be safe by now */ + if (!archName) archName = getArchName(); + + for (chptr = start; *chptr && !isspace(*chptr); chptr++); + if (! *chptr) { + error(RPMERR_RPMRC, "missing argument for %s at %s:%d\n", + option->name, fn, linenum); + return 1; + } + *chptr++ = '\0'; + + while (*chptr && isspace(*chptr)) chptr++; + if (! *chptr) { + error(RPMERR_RPMRC, "missing argument for %s at %s:%d\n", + option->name, fn, linenum); + return 1; + } + + if (!strcmp(archName, start)) { + message(MESS_DEBUG, "%s is arg for %s platform", chptr, + archName); + setVar(option->var, chptr); + } + } else { setVar(option->var, chptr); } + continue; } + error(RPMERR_INTERNAL, "Bad readWhat: %d", readWhat); + exit(1); } return 0; @@ -259,20 +422,29 @@ static int readRpmrc(FILE * f, char * fn, int readArchSpecific) { static void setDefaults(void) { setVar(RPMVAR_TOPDIR, "/usr/src"); - setVar(RPMVAR_DOCDIR, "/usr/doc"); setVar(RPMVAR_OPTFLAGS, "-O2"); setVar(RPMVAR_SIGTYPE, "none"); setVar(RPMVAR_PGP_PATH, NULL); setVar(RPMVAR_PGP_NAME, NULL); } -static int readConfigFilesAux(char *file, int readArchSpecific) +static int readConfigFilesAux(char *file, int readWhat) { FILE * f; char * fn; char * home; int rc = 0; + f = fopen("/usr/lib/rpmrc", "r"); + if (f) { + rc = readRpmrc(f, "/usr/lib/rpmrc", readWhat); + fclose(f); + if (rc) return rc; + } else { + error(RPMERR_RPMRC, "Unable to read /usr/lib/rpmrc"); + return RPMERR_RPMRC; + } + if (file) fn = file; else @@ -280,7 +452,7 @@ static int readConfigFilesAux(char *file, int readArchSpecific) f = fopen(fn, "r"); if (f) { - rc = readRpmrc(f, "/etc/rpmrc", readArchSpecific); + rc = readRpmrc(f, fn, readWhat); fclose(f); if (rc) return rc; } @@ -293,7 +465,7 @@ static int readConfigFilesAux(char *file, int readArchSpecific) strcat(fn, "/.rpmrc"); f = fopen(fn, "r"); if (f) { - rc |= readRpmrc(f, fn, readArchSpecific); + rc |= readRpmrc(f, fn, readWhat); fclose(f); if (rc) return rc; } @@ -303,27 +475,21 @@ static int readConfigFilesAux(char *file, int readArchSpecific) return 0; } -int rpmReadConfigFiles(char * file, char * arch, char * os, int forbuild) { +int rpmReadConfigFiles(char * file, char * arch, char * os, int building) +{ int rc = 0; - + setDefaults(); - if (forbuild) { - setVar(RPMVAR_BUILDARCH, arch); - setVar(RPMVAR_OS, os); - } - - rc = readConfigFilesAux(file, 0); /* non-arch specific */ + + rc = readConfigFilesAux(file, READ_TABLES); if (rc) return rc; - if (forbuild) - initArchOs(getVar(RPMVAR_BUILDARCH), getVar(RPMVAR_OS)); - else - initArchOs(arch, os); - - rc = readConfigFilesAux(file, 1); /* arch-sepcific */ + setArchOs(arch, os, building); + + rc = readConfigFilesAux(file, READ_OTHER); if (rc) return rc; - - /* set default directories here */ + + /* set default directories */ setPathDefault(RPMVAR_BUILDDIR, "BUILD"); setPathDefault(RPMVAR_RPMDIR, "RPMS"); @@ -350,3 +516,119 @@ static void setPathDefault(int var, char * s) { setVar(var, fn); } +static int osnum; +static int archnum; +static char *osname; +static char *archname; +static int archOsIsInit = 0; + +static void setArchOs(char *arch, char *os, int build) +{ + struct utsname un; + struct dataEntry *archData, *osData; + + if (archOsIsInit) { + error(RPMERR_INTERNAL, "Internal error: Arch/OS already initialized!"); + error(RPMERR_INTERNAL, "Arch: %d\nOS: %d", archnum, osnum); + exit(1); + } + + uname(&un); + if (build) { + if (! arch) { + arch = lookupInDefaultTable(un.machine, archDefaultTable, + archDefaultTableLen); + } + if (! os) { + os = lookupInDefaultTable(un.sysname, osDefaultTable, + osDefaultTableLen); + } + } else { + arch = un.machine; + os = un.sysname; + } + + archData = lookupInDataTable(arch, archDataTable, archDataTableLen); + osData = lookupInDataTable(os, osDataTable, osDataTableLen); + if (archData) { + archnum = archData->num; + archname = strdup(archData->short_name); + } else { + archnum = 255; + archname = strdup(arch); + message(MESS_WARNING, "Unknown architecture: %s\n", arch); + message(MESS_WARNING, "Please contact rpm-list@redhat.com\n"); + } + if (osData) { + osnum = osData->num; + osname = strdup(osData->short_name); + } else { + osnum = 255; + osname = strdup(os); + message(MESS_WARNING, "Unknown OS: %s\n", os); + message(MESS_WARNING, "Please contact rpm-list@redhat.com\n"); + } + + archOsIsInit = 1; +} + +#define FAIL_IF_NOT_INIT \ +{\ + if (! archOsIsInit) {\ + error(RPMERR_INTERNAL, "Internal error: Arch/OS not initialized!");\ + error(RPMERR_INTERNAL, "Arch: %d\nOS: %d", archnum, osnum);\ + exit(1);\ + }\ +} + +int getOsNum(void) +{ + FAIL_IF_NOT_INIT; + return osnum; +} + +int getArchNum(void) +{ + FAIL_IF_NOT_INIT; + return archnum; +} + +char *getOsName(void) +{ + FAIL_IF_NOT_INIT; + return osname; +} + +char *getArchName(void) +{ + FAIL_IF_NOT_INIT; + return archname; +} + +int showRc(FILE *f) +{ + struct option *opt; + int count = 0; + char *s; + + fprintf(f, "ARCHITECTURE AND OS:\n"); + fprintf(f, "build arch : %s\n", getArchName()); + fprintf(f, "build os : %s\n", getOsName()); + + /* This is a major hack */ + archOsIsInit = 0; + setArchOs(NULL, NULL, 0); + fprintf(f, "install arch : %s\n", getArchName()); + fprintf(f, "install os : %s\n", getOsName()); + + fprintf(f, "RPMRC VALUES:\n"); + opt = optionTable; + while (count < optionTableSize) { + s = getVar(opt->var); + fprintf(f, "%-20s : %s\n", opt->name, s ? s : "(not set)"); + opt++; + count++; + } + + return 0; +} |