diff options
author | jdp <jdp@FreeBSD.org> | 1998-10-21 15:13:16 +0000 |
---|---|---|
committer | jdp <jdp@FreeBSD.org> | 1998-10-21 15:13:16 +0000 |
commit | b2cef22522be876196a5c9a670579c9ccf3e50b8 (patch) | |
tree | ce486a3894da4d0354866c0a8dd7f9a14f559d99 | |
parent | 92891f8e3d8fbdfee912c69bf9573707ead0bff0 (diff) | |
download | FreeBSD-src-b2cef22522be876196a5c9a670579c9ccf3e50b8.zip FreeBSD-src-b2cef22522be876196a5c9a670579c9ccf3e50b8.tar.gz |
Remove most of the code and replace it with a call to getobjformat().
-rw-r--r-- | usr.bin/objformat/Makefile | 10 | ||||
-rw-r--r-- | usr.bin/objformat/objformat.c | 120 |
2 files changed, 14 insertions, 116 deletions
diff --git a/usr.bin/objformat/Makefile b/usr.bin/objformat/Makefile index 1f28d3b..70bb911 100644 --- a/usr.bin/objformat/Makefile +++ b/usr.bin/objformat/Makefile @@ -1,14 +1,8 @@ # $FreeBSD$ PROG= objformat -NOMAN= not yet -CFLAGS+= -DMAIN - -.if ${OBJFORMAT} == elf -CFLAGS+= -DFREEBSD_ELF -.else -CFLAGS+= -DFREEBSD_AOUT -.endif +NOMAN= noman +CFLAGS+= -Wall LINKS+= ${BINDIR}/objformat ${BINDIR}/addr2line LINKS+= ${BINDIR}/objformat ${BINDIR}/ar diff --git a/usr.bin/objformat/objformat.c b/usr.bin/objformat/objformat.c index 827af6e..32ed385 100644 --- a/usr.bin/objformat/objformat.c +++ b/usr.bin/objformat/objformat.c @@ -26,112 +26,32 @@ * $FreeBSD$ */ -#include <sys/types.h> - +#include <err.h> +#include <objformat.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> -#ifdef FREEBSD_ELF -int objformat_aout = 0; -#else -int objformat_aout = 1; -#endif - -void -getobjfmt(void) -{ - char *env; - int i; - - /* first hint is /etc/objformat */ - FILE *fp = fopen("/etc/objformat", "r"); - if (fp) { - char buf[1024]; - buf[1023] = '\0'; - while (fgets(buf, sizeof(buf) - 1, fp) != NULL) { - i = strlen(buf); - if (buf[i - 1] == '\n') - buf[i - 1] = '\0'; - if (strcmp(buf, "OBJFORMAT=aout") == 0) - objformat_aout = 1; - else if (strcmp(buf, "OBJFORMAT=elf") == 0) - objformat_aout = 0; - else - fprintf(stderr, "Unrecognized line in /etc/objformat: %s\n", buf); - } - fclose(fp); - } - /* but the user $OBJFORMAT overrides system default */ - env = getenv("OBJFORMAT"); - if (env) { - if (strcmp(env, "aout") == 0) - objformat_aout = 1; - else if (strcmp(env, "elf") == 0) - objformat_aout = 0; - else - fprintf(stderr, "Unrecognized value of $OBJFORMAT: %s\n", env); - } -} - -void -scanargv(int *argc, char **argv, int strip) -{ - int i, j; - - for (i = 1; i < *argc; i++) { - if (strcmp (argv[i], "-aout") == 0) { - objformat_aout = 1; - continue; - } else if (strcmp (argv[i], "-elf") == 0) { - objformat_aout = 0; - continue; - } - } - - /* if just looking, return now */ - if (!strip) - return; - - /* otherwise, remove all traces of switches from argv */ - for (i = 1; i < *argc; i++) { - if (strcmp (argv[i], "-aout") == 0 || - strcmp (argv[i], "-elf") == 0) { - /* copy NULL at end of argv as well */ - for (j = i + 1; j <= *argc; j++) { - argv[j - 1] = argv[j]; - } - (*argc)--; - } - } -} - - -#ifdef MAIN int main(int argc, char **argv) { + char objformat[32]; char *path, *chunk; - char *postfix; char *cmd, *newcmd = NULL; char *objformat_path; - int i; + + if (getobjformat(objformat, sizeof objformat, &argc, argv) == -1) + errx(1, "Invalid object format"); cmd = strrchr(argv[0], '/'); - if (cmd) + if (cmd != NULL) cmd++; else cmd = argv[0]; - getobjfmt(); - scanargv(&argc, argv, 1); - if (strcmp(cmd, "objformat") == 0) { - if (objformat_aout) - printf("aout\n"); - else - printf("elf\n"); + printf("%s\n", objformat); exit(0); } @@ -141,35 +61,19 @@ main(int argc, char **argv) objformat_path = "/usr/libexec"; path = strdup(objformat_path); - if (objformat_aout) { - putenv("OBJFORMAT=aout"); - postfix = "aout"; - } else { - putenv("OBJFORMAT=elf"); - postfix = "elf"; - } + setenv("OBJFORMAT", objformat, 1); while ((chunk = strsep(&path, ":")) != NULL) { if (newcmd != NULL) { free(newcmd); newcmd = NULL; } - asprintf(&newcmd, "%s/%s/%s", chunk, postfix, cmd); + asprintf(&newcmd, "%s/%s/%s", chunk, objformat, cmd); if (newcmd == NULL) err(1, "cannot allocate memory for new command"); - if (getenv("OBJFORMAT_DEBUG") != NULL) { - fprintf(stderr, "objformat: %s -> %s\n", cmd, newcmd); -#if 0 - for (i = 1; i < argc; i++) - fprintf(stderr, "argv[%d]: %s\n", i, argv[i]); -#endif - } - argv[0] = newcmd; execv(newcmd, argv); } - err(1, "could not exec %s/%s in %s", postfix, cmd, objformat_path); + err(1, "could not exec %s/%s in %s", objformat, cmd, objformat_path); } - -#endif |