diff options
author | Yuras Shumovich <shumovichy@gmail.com> | 2015-08-29 12:25:14 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-08-29 13:08:18 +0200 |
commit | 0c823af84d80ac103528e54eda8e1c6bdf2bea69 (patch) | |
tree | 24776ce9a191570684a709b77a791855d329ea8b /utils/hp2ps/HpFile.c | |
parent | 8476ce24c77f4323bd4e03552d3d1513318589f4 (diff) | |
download | haskell-0c823af84d80ac103528e54eda8e1c6bdf2bea69.tar.gz |
Fix identifier parsing in hp2ps
Now identifiers can start with a package key, which is a hash, so they
may also start with a digit. Identifiers always appear at the beginning
of a line, and numbers never appear here, soit's safe to allow
identifiers to start with a digit.
Test Plan: `concprog002` passes under `threaded2_hT` way
Reviewers: austin, bgamari, thomie
Reviewed By: austin, bgamari, thomie
Differential Revision: https://phabricator.haskell.org/D1175
GHC Trac Issues: #10661
Diffstat (limited to 'utils/hp2ps/HpFile.c')
-rw-r--r-- | utils/hp2ps/HpFile.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/utils/hp2ps/HpFile.c b/utils/hp2ps/HpFile.c index 9459247a03..12ef8d6ece 100644 --- a/utils/hp2ps/HpFile.c +++ b/utils/hp2ps/HpFile.c @@ -35,7 +35,7 @@ static boolish insample = 0; /* true when in sample */ static floatish lastsample; /* the last sample time */ static void GetHpLine PROTO((FILE *)); /* forward */ -static void GetHpTok PROTO((FILE *)); /* forward */ +static void GetHpTok PROTO((FILE *, int)); /* forward */ static struct entry *GetEntry PROTO((char *)); /* forward */ @@ -77,7 +77,7 @@ GetHpFile(FILE *infp) linenum = 1; lastsample = 0.0; - GetHpTok(infp); + GetHpTok(infp, 1); while (endfile == 0) { GetHpLine(infp); @@ -122,49 +122,49 @@ GetHpLine(FILE *infp) switch (thetok) { case JOB_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != STRING_TOK) { Error("%s, line %d: string must follow JOB", hpfile, linenum); } jobstring = thestring; gotjob = 1; - GetHpTok(infp); + GetHpTok(infp, 1); break; case DATE_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != STRING_TOK) { Error("%s, line %d: string must follow DATE", hpfile, linenum); } datestring = thestring; gotdate = 1; - GetHpTok(infp); + GetHpTok(infp, 1); break; case SAMPLE_UNIT_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != STRING_TOK) { Error("%s, line %d: string must follow SAMPLE_UNIT", hpfile, linenum); } sampleunitstring = thestring; gotsampleunit = 1; - GetHpTok(infp); + GetHpTok(infp, 1); break; case VALUE_UNIT_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != STRING_TOK) { Error("%s, line %d: string must follow VALUE_UNIT", hpfile, linenum); } valueunitstring = thestring; gotvalueunit = 1; - GetHpTok(infp); + GetHpTok(infp, 1); break; case MARK_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != FLOAT_TOK) { Error("%s, line %d, floating point number must follow MARK", hpfile, linenum); @@ -182,12 +182,12 @@ GetHpLine(FILE *infp) } } markmap[ nmarks++ ] = thefloatish; - GetHpTok(infp); + GetHpTok(infp, 1); break; case BEGIN_SAMPLE_TOK: insample = 1; - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != FLOAT_TOK) { Error("%s, line %d, floating point number must follow BEGIN_SAMPLE", hpfile, linenum); } @@ -207,28 +207,28 @@ GetHpLine(FILE *infp) } } samplemap[ nsamples ] = thefloatish; - GetHpTok(infp); + GetHpTok(infp, 1); break; case END_SAMPLE_TOK: insample = 0; - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != FLOAT_TOK) { Error("%s, line %d: floating point number must follow END_SAMPLE", hpfile, linenum); } nsamples++; - GetHpTok(infp); + GetHpTok(infp, 1); break; case IDENTIFIER_TOK: - GetHpTok(infp); + GetHpTok(infp, 0); if (thetok != INTEGER_TOK) { Error("%s, line %d: integer must follow identifier", hpfile, linenum); } StoreSample(GetEntry(theident), nsamples, thefloatish); - GetHpTok(infp); + GetHpTok(infp, 1); break; case EOF_TOK: @@ -274,10 +274,12 @@ TokenToString(token t) * the corresponding value is also assigned to "theinteger" * or "thefloatish" as appropriate; in the case of identifiers * it is assigned to "theident". + * + * startline argument should be true for the first token on a line */ static void -GetHpTok(FILE *infp) +GetHpTok(FILE *infp, int startline) { while (isspace(ch)) { /* skip whitespace */ @@ -290,7 +292,8 @@ GetHpTok(FILE *infp) return; } - if (isdigit(ch)) { + if (isdigit(ch) && !startline) { + /* there should not be numbers at start of line */ thetok = GetNumber(infp); return; } else if (ch == '\"') { @@ -298,7 +301,6 @@ GetHpTok(FILE *infp) thetok = STRING_TOK; return; } else if (IsIdChar(ch)) { - ASSERT(! (isdigit(ch))); /* ch can't be a digit here */ GetIdent(infp); if (!isupper((int)theident[0])) { thetok = IDENTIFIER_TOK; |