diff options
author | blazy <blazy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-10-20 12:37:13 +0000 |
---|---|---|
committer | blazy <blazy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-10-20 12:37:13 +0000 |
commit | ca0c62265eb8cdd5fb0d8a8b34ee77baf3de987e (patch) | |
tree | 50a139db8e2ac51c6ff41f3790ff72aa417ed3be /test/ccured_olden/bh/getparam.c | |
parent | 43668d9109b1f36329646fd07324d435be6f0050 (diff) | |
download | compcert-ca0c62265eb8cdd5fb0d8a8b34ee77baf3de987e.tar.gz compcert-ca0c62265eb8cdd5fb0d8a8b34ee77baf3de987e.zip |
Ajout du banc de tests de CCured (Olden benchmark suite, cf.
CCured: type-safe retrofitting of legacy code, G.Necula et al.)
rapportCompcert_all.txt liste les erreurs produites par ccomp.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@121 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/ccured_olden/bh/getparam.c')
-rw-r--r-- | test/ccured_olden/bh/getparam.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/test/ccured_olden/bh/getparam.c b/test/ccured_olden/bh/getparam.c new file mode 100644 index 00000000..9f3d1cf2 --- /dev/null +++ b/test/ccured_olden/bh/getparam.c @@ -0,0 +1,142 @@ +/****************************************************************************/ +/* GETPARAM.C: export version prompts user for values. Public routines: */ +/* initparam(), getparam(), getiparam(), getbparam(), getrparam(). */ +/* */ +/* Copyright (c) 1993 by Joshua E. Barnes, Honolulu, HI. */ +/* It's free because it's yours. */ +/****************************************************************************/ + +#include "stdinc.h" +#include "real.h" +#include <string.h> +#include <stdlib.h> + +void *allocate(int); +void error(string, ...); + +local string *defaults = NULL; /* "name=value" strings */ + +/* + * INITPARAM: ignore arg vector, remember defaults. + */ + +void initparam(string *argv, string *defv) +{ + defaults = defv; +} + +/* + * GETPARAM: export version prompts user for value of name. + */ + +local int scanbind(string *, string); +local string extrvalue(string); + +string getparam(string name) +{ + int i, len; + string def; + char buf[128]; + + if (defaults == NULL) /* check initialization */ + error("getparam: called before initparam\n"); + i = scanbind(defaults, name); /* find name in defaults */ + if (i < 0) + error("getparam: %s unknown\n", name); + def = extrvalue(defaults[i]); /* extract default value */ + if (*def == NULLCHR) + fprintf(stderr, "enter %s: ", name); /* prompt user for value */ + else + fprintf(stderr, "enter %s [%s]: ", name, def); + gets(buf); /* read users response */ + len = strlen(buf); + if (len > 0) /* if user gave a value... */ + return (strcpy((string) allocate(len+1), buf)); + else /* else return default */ + return (def); +} + +/* + * GETIPARAM, ..., GETDPARAM: get int, long, bool, or double parameters. + */ + +int getiparam(string name) +{ + string val; + + for (val = ""; *val == NULLCHR; ) /* while nothing input */ + val = getparam(name); /* obtain value from user */ + return (atoi(val)); /* convert to an integer */ +} + +bool getbparam(string name) +{ + string val; + + for (val = ""; *val == NULLCHR; ) + val = getparam(name); + if (strchr("tTyY1", *val) != NULLCHR) /* is value true? */ + return (TRUE); + if (strchr("fFnN0", *val) != NULLCHR) /* is value false? */ + return (FALSE); + error("getbparam: %s=%s not bool\n", name, val); + return (FALSE); +} + +real getrparam(string name) +{ + string val; + + for (val = ""; *val == NULLCHR; ) + val = getparam(name); + return ((real) atof(val)); /* convert & return real */ +} + +/* + * SCANBIND: scan binding vector for name, return index. + */ + +local bool matchname(string, string); + +local int scanbind(string bvec[], string name) +{ + int i; + + for (i = 0; bvec[i] != NULL; i++) + if (matchname(bvec[i], name)) + return (i); + return (-1); +} + +/* + * MATCHNAME: determine if "name=value" matches "name". + */ + +local bool matchname(string bind, string name) +{ + char *bp, *np; + + bp = bind; + np = name; + while (*bp == *np) { + bp++; + np++; + } + return (*bp == '=' && *np == NULLCHR); +} + +/* + * EXTRVALUE: extract value from name=value string. + */ + +local string extrvalue(string arg) +{ + char *ap; + + ap = (char *) arg; + while (*ap != NULLCHR) + if (*ap++ == '=') + return ((string) ap); + return (NULL); +} + |