about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-11 22:03:16 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-11 22:05:34 +0100
commit75865752dd0e0db44916fa493b78e3761279359c (patch)
tree2582921b4fd2094d1c60d9286a8ac95d75d98e4f /src
parent5e2d67cdd5ad4220426b19592ddf2f827af75f0b (diff)
downloadchawan-75865752dd0e0db44916fa493b78e3761279359c.tar.gz
mailcap: better error messages, accept \ as newline escape
the backslash thing is in the RFC, I just forgot to add it
Diffstat (limited to 'src')
-rw-r--r--src/config/mailcap.nim24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/config/mailcap.nim b/src/config/mailcap.nim
index 725c2c22..90815249 100644
--- a/src/config/mailcap.nim
+++ b/src/config/mailcap.nim
@@ -15,6 +15,7 @@ type
     stream: Stream
     hasbuf: bool
     buf: char
+    line: int
 
   MailcapFlags* = enum
     NEEDSTERMINAL = "needsterminal"
@@ -40,7 +41,15 @@ proc consume(state: var MailcapParser): char =
   if state.hasbuf:
     state.hasbuf = false
     return state.buf
-  return state.stream.readChar()
+  var c = state.stream.readChar()
+  if c == '\\' and not state.stream.atEnd:
+    let c2 = state.stream.readChar()
+    if c2 == '\n' and not state.stream.atEnd:
+      inc state.line
+      c = state.stream.readChar()
+  if c == '\n':
+    inc state.line
+  return c
 
 proc reconsume(state: var MailcapParser, c: char) =
   state.buf = c
@@ -72,7 +81,8 @@ proc consumeTypeField(state: var MailcapParser): Result[string, string] =
       s &= c
       break
     if c notin AsciiAlphaNumeric + {'-', '*'}:
-      return err("Invalid character encountered in type field")
+      return err("line " & $state.line & ": invalid character in type field: " &
+        c)
     s &= c.toLowerAscii()
   if not state.has():
     return err("Missing subtype")
@@ -83,7 +93,8 @@ proc consumeTypeField(state: var MailcapParser): Result[string, string] =
       state.reconsume(c)
       break
     if c notin AsciiAlphaNumeric + {'-', '.', '*', '_', '+'}:
-      return err("Invalid character encountered in subtype field")
+      return err("line " & $state.line &
+        ": invalid character in subtype field: " & c)
     s &= c.toLowerAscii()
   var c: char
   if not state.skipBlanks(c) or c != ';':
@@ -106,7 +117,8 @@ proc consumeCommand(state: var MailcapParser): Result[string, string] =
         quoted = true
         continue
       if c notin Ascii - Controls:
-        return err("Invalid character encountered in command")
+        return err("line " & $state.line & ": invalid character in command: " &
+          c)
     else:
       quoted = false
     s &= c
@@ -163,11 +175,11 @@ proc consumeField(state: var MailcapParser, entry: var MailcapEntry):
       return ok(state.consume() == ';')
     else:
       if c in Controls:
-        return err("Invalid character encountered in field")
+        return err("line " & $state.line & ": invalid character in field: " & c)
       buf &= c
 
 proc parseMailcap*(stream: Stream): Result[Mailcap, string] =
-  var state = MailcapParser(stream: stream)
+  var state = MailcapParser(stream: stream, line: 1)
   var mailcap: Mailcap
   while not stream.atEnd():
     let c = state.consume()
Agaram <vc@akkartik.com> 2017-03-08 19:02:59 -0800 3764 - better colors for cross-links' href='/akkartik/mu/commit/html/factorial.mu.html?h=main&id=4a39d12d4568f76ebf45b34cec722d8e0bcf1207'>4a39d12d ^
a654e4ec ^
e5c11a51 ^
9e751bb8 ^
c5ffb6e1 ^

a654e4ec ^



e5c11a51 ^






















a654e4ec ^

c5ffb6e1 ^
e5c11a51 ^
a654e4ec ^
204dae92 ^

97eb971b ^
204dae92 ^
97eb971b ^
204dae92 ^



97eb971b ^
204dae92 ^

984a6321 ^




















c5ffb6e1 ^


a654e4ec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98