summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2010-06-08 15:11:19 +0100
committerDaniel Stone <daniel@fooishbar.org>2010-06-15 19:26:49 +0100
commit41b0857c8c1179b87a26888588cbfff28f8bb0d6 (patch)
tree19a906b75cfddd57c333920759e7bba4d98a4ee9
parent7f7a57c75beb5e1dfb53351e490ef00a324b2727 (diff)
Don't malloc() and free() most scanned symbols
Use a constant buffer. Sigh. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r--parseutils.h2
-rw-r--r--xkbparse.y18
-rw-r--r--xkbscan.c44
3 files changed, 26 insertions, 38 deletions
diff --git a/parseutils.h b/parseutils.h
index e16adff..0d06ce9 100644
--- a/parseutils.h
+++ b/parseutils.h
@@ -33,7 +33,7 @@
#include "xkbcomp.h"
-extern char *scanStr;
+extern char scanBuf[1024];
extern int scanInt;
extern int lineNum;
diff --git a/xkbparse.y b/xkbparse.y
index 8f9a073..862acd8 100644
--- a/xkbparse.y
+++ b/xkbparse.y
@@ -311,10 +311,10 @@ Decl : OptMergeMode VarDecl
{
if ($1==MergeAltForm) {
yyerror("cannot use 'alternate' to include other maps");
- $$= &IncludeCreate(scanStr,MergeDefault)->common;
+ $$= &IncludeCreate(scanBuf,MergeDefault)->common;
}
else {
- $$= &IncludeCreate(scanStr,$1)->common;
+ $$= &IncludeCreate(scanBuf,$1)->common;
}
}
;
@@ -721,7 +721,7 @@ KeySymList : KeySymList COMMA KeySym
{ $$= CreateKeysymList($1); }
;
-KeySym : IDENT { $$= scanStr; scanStr= NULL; }
+KeySym : IDENT { $$= strdup(scanBuf); }
| SECTION { $$= strdup("section"); }
| Integer
{
@@ -744,21 +744,21 @@ Float : FLOAT { $$= scanInt; }
Integer : INTEGER { $$= scanInt; }
;
-KeyName : KEYNAME { $$= scanStr; scanStr= NULL; }
+KeyName : KEYNAME { $$= strdup(scanBuf); }
;
-Ident : IDENT { $$= XkbInternAtom(NULL,scanStr,False); }
+Ident : IDENT { $$= XkbInternAtom(NULL,scanBuf,False); }
| DEFAULT { $$= XkbInternAtom(NULL,"default",False); }
;
-String : STRING { $$= XkbInternAtom(NULL,scanStr,False); }
+String : STRING { $$= XkbInternAtom(NULL,scanBuf,False); }
;
OptMapName : MapName { $$= $1; }
| { $$= NULL; }
;
-MapName : STRING { $$= scanStr; scanStr= NULL; }
+MapName : STRING { $$= strdup(scanBuf); }
;
%%
void
@@ -767,8 +767,8 @@ yyerror(const char *s)
if (warningLevel>0) {
(void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
(scanFile?scanFile:"(unknown)"));
- if ((scanStr)&&(warningLevel>3))
- (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);
+ if ((warningLevel>3))
+ (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);
}
return;
}
diff --git a/xkbscan.c b/xkbscan.c
index 8c88ddd..1e7902d 100644
--- a/xkbscan.c
+++ b/xkbscan.c
@@ -45,11 +45,10 @@ int lineNum = 0;
int scanInt;
-char *scanStr = NULL;
+char scanBuf[1024];
static int scanStrLine = 0;
#define BUFSIZE 4096
-static int nInBuf = 0;
static char readBuf[BUFSIZE];
static int readBufPos = 0;
static int readBufLen = 0;
@@ -220,7 +219,7 @@ tokText(int tok)
break;
case STRING:
- snprintf(buf, sizeof(buf), "STRING (%s)", scanStr);
+ snprintf(buf, sizeof(buf), "STRING (%s)", scanBuf);
break;
case INTEGER:
snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt);
@@ -230,10 +229,10 @@ tokText(int tok)
scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM);
break;
case IDENT:
- snprintf(buf, sizeof(buf), "IDENT (%s)", scanStr);
+ snprintf(buf, sizeof(buf), "IDENT (%s)", scanBuf);
break;
case KEYNAME:
- snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr);
+ snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanBuf);
break;
case PARTIAL:
@@ -310,7 +309,6 @@ static int
yyGetString(void)
{
int ch, i;
- char buf[1024];
i = 0;
while (((ch = scanchar()) != EOF) && (ch != '"'))
@@ -378,15 +376,12 @@ yyGetString(void)
else
return ERROR_TOK;
}
- if (i < sizeof(buf) - 1)
- buf[i++] = ch;
+ if (i < sizeof(scanBuf) - 1)
+ scanBuf[i++] = ch;
}
if (ch == '"')
{
- buf[i++] = '\0';
- if (scanStr)
- uFree(scanStr);
- scanStr = (char *) uStringDup(buf);
+ scanBuf[i++] = '\0';
scanStrLine = lineNum;
return STRING;
}
@@ -397,7 +392,6 @@ static int
yyGetKeyName(void)
{
int ch, i;
- char buf[1024];
i = 0;
while (((ch = scanchar()) != EOF) && (ch != '>'))
@@ -460,15 +454,12 @@ yyGetKeyName(void)
return ERROR_TOK;
}
- if (i < sizeof(buf) - 1)
- buf[i++] = ch;
+ if (i < sizeof(scanBuf) - 1)
+ scanBuf[i++] = ch;
}
if ((ch == '>') && (i < 5))
{
- buf[i++] = '\0';
- if (scanStr)
- uFree(scanStr);
- scanStr = (char *) uStringDup(buf);
+ scanBuf[i++] = '\0';
scanStrLine = lineNum;
return KEYNAME;
}
@@ -579,21 +570,20 @@ yyGetIdent(int first)
{
int ch, i, j, found;
int rtrn = IDENT;
- char buf[1024];
- buf[0] = first;
+ scanBuf[0] = first;
j = 1;
while (((ch = scanchar()) != EOF) && (isalnum(ch) || (ch == '_')))
{
- if (j < sizeof(buf) - 1)
- buf[j++] = ch;
+ if (j < sizeof(scanBuf) - 1)
+ scanBuf[j++] = ch;
}
- buf[j++] = '\0';
+ scanBuf[j++] = '\0';
found = 0;
for (i = 0; (!found) && (i < numKeywords); i++)
{
- if (uStrCaseCmp(buf, keywords[i].keyword) == 0)
+ if (uStrCaseCmp(scanBuf, keywords[i].keyword) == 0)
{
rtrn = keywords[i].token;
found = 1;
@@ -601,9 +591,6 @@ yyGetIdent(int first)
}
if (!found)
{
- if (scanStr)
- uFree(scanStr);
- scanStr = (char *) uStringDup(buf);
scanStrLine = lineNum;
rtrn = IDENT;
}
@@ -621,6 +608,7 @@ yyGetNumber(int ch)
{
int isFloat = 0;
char buf[1024];
+ int nInBuf = 0;
buf[0] = ch;
nInBuf = 1;