summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-10-22 22:41:14 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-10-22 22:41:14 +0000
commit09db9410aa882e4d981272e409fb23ce8d1ced16 (patch)
tree24c28e57a38e430532bce3f56569ae51f08465d2 /src
parent51f8b95c8c647fc2c91a5828fe7de36e97f00635 (diff)
downloadmdevd-09db9410aa882e4d981272e409fb23ce8d1ced16.tar.xz
Add line counting to first pass; refactor error messages
Diffstat (limited to 'src')
-rw-r--r--src/mdevd/PARSING.txt6
-rw-r--r--src/mdevd/mdevd.c36
2 files changed, 24 insertions, 18 deletions
diff --git a/src/mdevd/PARSING.txt b/src/mdevd/PARSING.txt
index e8715dc..2d7fc61 100644
--- a/src/mdevd/PARSING.txt
+++ b/src/mdevd/PARSING.txt
@@ -6,7 +6,7 @@
class | 0 1 2 3 4 5 6 7 8
st\ev | \0 space ; $ # - @ \n other
-START | env+ele ele ele
+START | env+ele ele + ele
00 | END START X ENDLINE ENDLINE MINUS ENDLINE START DEVVAR
MINUS | env+ele ele ele
@@ -18,12 +18,12 @@ DEVVAR | env
SEMI |
03 | X X X DEVVAR X DEVVAR DEVVAR X DEVVAR
-ENDLINE |
+ENDLINE | +
04 | END ENDLINE ENDLINE ENDLINE ENDLINE ENDLINE ENDLINE START ENDLINE
END = 05, X = 06
States -> 0x00 to 0x06
- Actions -> 0x10 (add an envmatch) and 0x20 (add a scriptelem)
+ Actions -> 0x10 (add an envmatch), 0x20 (add a scriptelem), 0x40 (line++)
Everything fits easily in an unsigned char.
diff --git a/src/mdevd/mdevd.c b/src/mdevd/mdevd.c
index 1f7485e..6784323 100644
--- a/src/mdevd/mdevd.c
+++ b/src/mdevd/mdevd.c
@@ -191,27 +191,33 @@ static inline void script_firstpass (char *s, unsigned short *scriptlen, unsigne
{
static unsigned char const table[5][9] =
{
- { 0x05, 0x00, 0x06, 0x34, 0x04, 0x01, 0x24, 0x00, 0x22 },
+ { 0x05, 0x00, 0x06, 0x34, 0x04, 0x01, 0x24, 0x40, 0x22 },
{ 0x06, 0x06, 0x06, 0x34, 0x06, 0x06, 0x24, 0x06, 0x22 },
{ 0x06, 0x04, 0x13, 0x02, 0x06, 0x02, 0x02, 0x06, 0x02 },
{ 0x06, 0x06, 0x06, 0x02, 0x06, 0x02, 0x02, 0x06, 0x02 },
- { 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04 }
+ { 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x40, 0x04 }
} ;
size_t i = 0 ;
+ size_t col0 = 0 ;
+ unsigned int line = 1 ;
unsigned short n = 0, m = 0 ;
unsigned int state = 0 ;
while (state < 5)
{
- unsigned char what = table[state][firstpass_cclass(s[i++])] ;
+ unsigned char what = table[state][firstpass_cclass(s[i])] ;
state = what & 0x07 ;
if (what & 0x10) m++ ;
if (what & 0x20) n++ ;
+ if (what & 0x40) { line++ ; col0 = i ; }
+ i++ ;
}
if (state == 6)
{
- s[--i] = 0 ;
- while (i && !strchr(" \n\r\t", s[i])) i-- ;
- strerr_dief2x(2, "syntax error during first pass, after string: ", (char *)s + i) ;
+ char fmtline[UINT_FMT] ;
+ char fmtcol[UINT_FMT] ;
+ fmtline[uint_fmt(fmtline, line)] = 0 ;
+ fmtcol[uint_fmt(fmtcol, i - col0)] = 0 ;
+ strerr_dief6x(2, "syntax error during ", "first", " pass: line ", fmtline, " column ", fmtcol) ;
}
*scriptlen = n ;
@@ -295,7 +301,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
regerror(r, &envmatch[j].re, errbuf, 256) ;
- strerr_dief8x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to compile regular expression ", "for envmatch: ", s + mark, ": ", errbuf) ;
+ strerr_diefu6x(2, "compile regular expression ", s + mark, " for envmatch at line ", fmtline, ": ", errbuf) ;
}
j++ ;
script[i].envmatchlen++ ;
@@ -306,7 +312,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to scan major from string: ", s + mark) ;
+ strerr_diefu4x(2, "get major from string ", s + mark, " at line ", fmtline) ;
}
}
if (what & 0x00400000)
@@ -315,7 +321,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to scan minor from string: ", s + mark) ;
+ strerr_diefu4x(2, "get minor from string ", s + mark, " at line ", fmtline) ;
}
}
if (what & 0x00200000) script[i].devmatch.majmin.minhi = script[i].devmatch.majmin.minlo ;
@@ -325,7 +331,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to scan minor from string: ", s + mark) ;
+ strerr_diefu4x(2, "get minor from string ", s + mark, " at line ", fmtline) ;
}
}
if (what & 0x00080000)
@@ -337,7 +343,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
regerror(r, &envmatch[j].re, errbuf, 256) ;
- strerr_dief8x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to compile regular expression ", " for devmatch: ", s + mark, ": ", errbuf) ;
+ strerr_diefu6x(2, "compile regular expression ", s + mark, " for devmatch at line ", fmtline, ": ", errbuf) ;
}
}
if (what & 0x00040000) envmatch[j].var = mark ;
@@ -349,7 +355,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to get uid from string: ", s + mark) ;
+ strerr_diefu4x(2, "get uid from string ", s + mark, " at line ", fmtline) ;
}
}
if (what & 0x00010000)
@@ -360,7 +366,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to get gid from string: ", s + mark) ;
+ strerr_diefu4x(2, "get gid from string ", s + mark, " at line ", fmtline) ;
}
}
if (what & 0x00008000)
@@ -370,7 +376,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
{
char fmtline[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, ": unable to scan mode from string: ", s + mark) ;
+ strerr_diefu4x(2, "get mode from string ", s + mark, " at line ", fmtline) ;
}
script[i].mode = m ;
}
@@ -392,7 +398,7 @@ static inline void script_secondpass (char *s, scriptelem *script, struct envmat
char fmtcol[UINT_FMT] ;
fmtline[uint_fmt(fmtline, line)] = 0 ;
fmtcol[uint_fmt(fmtcol, pos - col0)] = 0 ;
- strerr_dief5x(2, "syntax error during second pass: ", "line ", fmtline, " column ", fmtcol) ;
+ strerr_dief6x(2, "syntax error during ", "second", " pass: line ", fmtline, " column ", fmtcol) ;
}
}