本文整理汇总了C++中setsymtab函数的典型用法代码示例。如果您正苦于以下问题:C++ setsymtab函数的具体用法?C++ setsymtab怎么用?C++ setsymtab使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setsymtab函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: syminit
syminit()
{
setsymtab("0", tostring("0"), 0.0, NUM|STR|CON|FLD, symtab);
recloc = setsymtab("$record", record, 0.0, STR|FLD, symtab);
dprintf("recloc %o lookup %o\n", recloc, lookup("$record", symtab), NULL);
FS = &setsymtab("FS", tostring(" "), 0.0, STR|FLD, symtab)->sval;
RS = &setsymtab("RS", tostring("\n"), 0.0, STR|FLD, symtab)->sval;
OFS = &setsymtab("OFS", tostring(" "), 0.0, STR|FLD, symtab)->sval;
ORS = &setsymtab("ORS", tostring("\n"), 0.0, STR|FLD, symtab)->sval;
OFMT = &setsymtab("OFMT", tostring("%.6g"), 0.0, STR|FLD, symtab)->sval;
FILENAME = &setsymtab("FILENAME", NULL, 0.0, STR|FLD, symtab)->sval;
nfloc = setsymtab("NF", NULL, 0.0, NUM, symtab);
NF = &nfloc->fval;
nrloc = setsymtab("NR", NULL, 0.0, NUM, symtab);
NR = &nrloc->fval;
}
示例2: execute
Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
{
Cell *x, *y, *z;
char *s;
Node *np;
char buf[RECSIZE];
x = execute(a[0]); /* Cell* for symbol table */
buf[0] = 0;
for (np = a[1]; np; np = np->nnext) {
y = execute(np); /* subscript */
s = getsval(y);
strcat(buf, s); /* BUG: unchecked! */
if (np->nnext)
strcat(buf, *SUBSEP);
tempfree(y);
}
if (!isarr(x)) {
dprintf( ("making %s into an array\n", x->nval) );
if (freeable(x))
xfree(x->sval);
x->tval &= ~(STR|NUM|DONTFREE);
x->tval |= ARR;
x->sval = (char *) makesymtab(NSYMTAB);
}
z = setsymtab(buf, "", 0.0, STR|NUM, (Array *) x->sval);
z->ctype = OCELL;
z->csub = CVAR;
tempfree(x);
return(z);
}
示例3: envinit
void envinit(uchar **envp)
{
Cell *cp;
uchar *p;
cp = setsymtab("ENVIRON", "", 0.0, ARR, symtab);
ENVtab = makesymtab(NSYMTAB);
cp->sval = (uchar *) ENVtab;
for ( ; *envp; envp++) {
if ((p = (uchar *) strchr((char *) *envp, '=')) == NULL) /* index() on bsd */
continue;
*p++ = 0; /* split into two strings at = */
if (isnumber(p))
setsymtab(*envp, p, atof(p), STR|NUM, ENVtab);
else
setsymtab(*envp, p, 0.0, STR, ENVtab);
p[-1] = '='; /* restore in case env is passed down to a shell */
}
}
示例4: word
int word(char *w)
{
Keyword *kp;
int c, n;
n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
kp = keywords + n;
if (n != -1) { /* found in table */
yylval.i = kp->sub;
switch (kp->type) { /* special handling */
case BLTIN:
if (kp->sub == FSYSTEM && safe)
SYNTAX( "system is unsafe" );
RET(kp->type);
case FUNC:
if (infunc)
SYNTAX( "illegal nested function" );
RET(kp->type);
case RETURN:
if (!infunc)
SYNTAX( "return not in function" );
RET(kp->type);
case VARNF:
yylval.cp = setsymtab("NF", "", 0.0, NUM, symtab);
RET(VARNF);
default:
RET(kp->type);
}
}
c = peek(); /* look for '(' */
if (c != '(' && infunc && (n=isarg(w)) >= 0) {
yylval.i = n;
RET(ARG);
} else {
yylval.cp = setsymtab(w, "", 0.0, STR|NUM|DONTFREE, symtab);
if (c == '(') {
RET(CALL);
} else {
RET(VAR);
}
}
}
示例5: word
int word(char *w)
{
Keyword *kp;
int c, n;
n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
kp = keywords + n;
if (n != -1) { /* found in table */
yylval.i = kp->sub;
switch (kp->type) { /* special handling */
case FSYSTEM:
if (safe)
ERROR "system is unsafe" SYNTAX;
RET(kp->type);
case FUNC:
if (infunc)
ERROR "illegal nested function" SYNTAX;
RET(kp->type);
case RETURN:
if (!infunc)
ERROR "return not in function" SYNTAX;
RET(kp->type);
case VARNF:
yylval.cp = setsymtab("NF", "", 0.0, NUM, symtab);
RET(VARNF);
default:
RET(kp->type);
}
}
c = peek(); /* look for '(' */
if (c != '(' && infunc && (n=isarg(w)) >= 0) {
yylval.i = n;
RET(ARG);
} else {
yylval.cp = setsymtab(w, "", 0.0, STR|NUM|DONTFREE, symtab);
if (c == '(') {
RET(CALL);
} else {
RET(VAR);
}
}
}
示例6: sprintf
char *getargv(int n) /* get ARGV[n] */
{
Cell *x;
char *s, temp[50];
extern Array *ARGVtab;
sprintf(temp, "%d", n);
x = setsymtab(temp, "", 0.0, STR, ARGVtab);
s = getsval(x);
dprintf( ("getargv(%d) returns |%s|\n", n, s) );
return s;
}
示例7: snprintf
unsigned char *getargv(int n) /* get ARGV[n] */
{
Cell *x;
unsigned char *s, temp[25];
extern Array *ARGVtab;
snprintf((char *)temp, sizeof temp, "%d", n);
x = setsymtab(temp, "", 0.0, STR, ARGVtab);
s = getsval(x);
dprintf( ("getargv(%d) returns |%s|\n", n, s) );
return s;
}
示例8: setclvar
void
setclvar(char *s) /* set var=value from s */
{
char *p;
cell *q;
for (p=s; *p != '='; p++)
;
*p++ = 0;
q = setsymtab(s, tostring(p), 0.0, STR, symtab);
setsval(q, p);
dprintf("command line set %s to |%s|\n", s, p);
}
示例9: snprintf
char *getargv(int n) /* get ARGV[n] */
{
Cell *x;
char *s, temp[50];
extern Array *ARGVtab;
snprintf(temp, sizeof(temp), "%d", n);
if (lookup(temp, ARGVtab) == NULL)
return NULL;
x = setsymtab(temp, "", 0.0, STR, ARGVtab);
s = getsval(x);
dprintf( ("getargv(%d) returns |%s|\n", n, s) );
return s;
}
示例10: getsval
Cell *catstr(Cell *a, Cell *b) /* concatenate a and b */
{
Cell *c;
char *p;
char *sa = getsval(a);
char *sb = getsval(b);
size_t l = strlen(sa) + strlen(sb) + 1;
p = malloc(l);
if (p == NULL)
FATAL("out of space concatenating %s and %s", sa, sb);
snprintf(p, l, "%s%s", sa, sb);
c = setsymtab(p, p, 0.0, CON|STR|DONTFREE, symtab);
free(p);
return c;
}
示例11: arginit
void arginit(int ac, uchar *av[])
{
Cell *cp;
int i;
uchar temp[5];
for (i = 1; i < ac; i++) /* first make FILENAME first real argument */
if (!isclvar(av[i])) {
setsval(lookup("FILENAME", symtab), av[i]);
break;
}
ARGC = &setsymtab("ARGC", "", (Awkfloat) ac, NUM, symtab)->fval;
cp = setsymtab("ARGV", "", 0.0, ARR, symtab);
ARGVtab = makesymtab(NSYMTAB); /* could be (int) ARGC as well */
cp->sval = (uchar *) ARGVtab;
for (i = 0; i < ac; i++) {
sprintf((char *)temp, "%d", i);
if (isnumber(*av))
setsymtab(temp, *av, atof(*av), STR|NUM, ARGVtab);
else
setsymtab(temp, *av, 0.0, STR, ARGVtab);
av++;
}
}
示例12: setclvar
void setclvar(char *s) /* set var=value from s */
{
char *p;
Cell *q;
for (p=s; *p != '='; p++)
;
*p++ = 0;
p = qstring(p, '\0');
q = setsymtab(s, p, 0.0, STR, symtab);
setsval(q, p);
if (is_number(q->sval)) {
q->fval = atof(q->sval);
q->tval |= NUM;
}
dprintf( ("command line set %s to |%s|\n", s, p) );
}
示例13: syminit
void
syminit(void)
{
static wchar_t L_0[] = L"0";
static wchar_t L_zeronull[] = L"$zero&null";
static wchar_t L_record[] = L"$record";
static wchar_t L_FS[] = L"FS";
static wchar_t L_OFS[] = L"OFS";
static wchar_t L_ORS[] = L"ORS";
static wchar_t L_RS[] = L"RS";
static wchar_t L_OFMT[] = L"OFMT";
static wchar_t L_space[] = L" ";
static wchar_t L_newline[] = L"\n";
static wchar_t L_dot6g[] = L"%.6g";
static wchar_t L_FILENAME[] = L"FILENAME";
static wchar_t L_NF[] = L"NF";
static wchar_t L_NR[] = L"NR";
setsymtab(L_0, tostring(L_0), 0.0, NUM|STR|CON|FLD, symtab);
/* this one is used for if (x)... tests: */
setsymtab(L_zeronull, tostring(L_NULL), 0.0, NUM|STR|CON|FLD, symtab);
recloc = setsymtab(L_record, record, 0.0, STR|FLD, symtab);
dprintf("recloc %o lookup %o\n",
recloc, lookup(L_record, symtab, 0), NULL);
FS = &setsymtab(L_FS, tostring(L_space), 0.0, STR|FLD, symtab)->sval;
RS = &setsymtab(L_RS, tostring(L_newline), 0.0, STR|FLD, symtab)->sval;
OFS = &setsymtab(L_OFS, tostring(L_space), 0.0, STR|FLD, symtab)->sval;
ORS = &setsymtab(L_ORS, tostring(L_newline), 0.0, STR|FLD,
symtab)->sval;
OFMT = &setsymtab(L_OFMT, tostring(L_dot6g), 0.0, STR|FLD,
symtab)->sval;
FILENAME = &setsymtab(L_FILENAME, NULL, 0.0, STR|FLD, symtab)->sval;
nfloc = setsymtab(L_NF, NULL, 0.0, NUM, symtab);
NF = &nfloc->fval;
nrloc = setsymtab(L_NR, NULL, 0.0, NUM, symtab);
NR = &nrloc->fval;
}
示例14: syminit
void
syminit(void)
{
setsymtab("0", tostring("0"), 0.0, NUM|STR|CON|FLD, symtab);
/* this one is used for if(x)... tests: */
setsymtab("$zero&null", tostring(""), 0.0, NUM|STR|CON|FLD, symtab);
recloc = setsymtab("$record", record, 0.0, STR|FLD, symtab);
dprintf("recloc %lo lookup %lo\n", (long)recloc, (long)lookup("$record", symtab, 0));
FS = &setsymtab("FS", tostring(" "), 0.0, STR|FLD, symtab)->sval;
RS = &setsymtab("RS", tostring("\n"), 0.0, STR|FLD, symtab)->sval;
OFS = &setsymtab("OFS", tostring(" "), 0.0, STR|FLD, symtab)->sval;
ORS = &setsymtab("ORS", tostring("\n"), 0.0, STR|FLD, symtab)->sval;
OFMT = &setsymtab("OFMT", tostring("%.6g"), 0.0, STR|FLD, symtab)->sval;
FILENAME = &setsymtab("FILENAME", EMPTY, 0.0, STR|FLD, symtab)->sval;
nfloc = setsymtab("NF", EMPTY, 0.0, NUM, symtab);
NF = &nfloc->fval;
nrloc = setsymtab("NR", EMPTY, 0.0, NUM, symtab);
NR = &nrloc->fval;
}
示例15: string
int string(void)
{
int c, n;
char *s, *bp;
static char *buf = 0;
static int bufsz = 500;
if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
FATAL("out of space for strings");
for (bp = buf; (c = input()) != '"'; ) {
if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0))
FATAL("out of space for string %.10s...", buf);
switch (c) {
case '\n':
case '\r':
case 0:
SYNTAX( "non-terminated string %.10s...", buf );
lineno++;
if (c == 0) /* hopeless */
FATAL( "giving up" );
break;
case '\\':
c = input();
switch (c) {
case '"': *bp++ = '"'; break;
case 'n': *bp++ = '\n'; break;
case 't': *bp++ = '\t'; break;
case 'f': *bp++ = '\f'; break;
case 'r': *bp++ = '\r'; break;
case 'b': *bp++ = '\b'; break;
case 'v': *bp++ = '\v'; break;
case 'a': *bp++ = '\007'; break;
case '\\': *bp++ = '\\'; break;
case '0': case '1': case '2': /* octal: \d \dd \ddd */
case '3': case '4': case '5': case '6': case '7':
n = c - '0';
if ((c = peek()) >= '0' && c < '8') {
n = 8 * n + input() - '0';
if ((c = peek()) >= '0' && c < '8')
n = 8 * n + input() - '0';
}
*bp++ = n;
break;
case 'x': /* hex \x0-9a-fA-F + */
{ char xbuf[100], *px;
for (px = xbuf; (c = input()) != 0 && px-xbuf < 100-2; ) {
if (isdigit(c)
|| (c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F'))
*px++ = c;
else
break;
}
*px = 0;
unput(c);
sscanf(xbuf, "%x", &n);
*bp++ = n;
break;
}
default:
*bp++ = c;
break;
}
break;
default:
*bp++ = c;
break;
}
}
*bp = 0;
s = tostring(buf);
*bp++ = ' '; *bp++ = 0;
yylval.cp = setsymtab(buf, s, 0.0, CON|STR|DONTFREE, symtab);
RET(STRING);
}