about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-13 19:31:39 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-13 19:31:39 +0200
commit069685478c6bd8c38723b10158464c33ecdfc9c7 (patch)
treeb8255f424ebbf339ad1ec4bf9731b3634b3341c8
parentf50f41d7954aeb63510f23c0600b9eb23793cae8 (diff)
downloadchawan-069685478c6bd8c38723b10158464c33ecdfc9c7.tar.gz
Simplify mailcap entry matching
-rw-r--r--src/config/mailcap.nim39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/config/mailcap.nim b/src/config/mailcap.nim
index da9b8f69..71e3d6c1 100644
--- a/src/config/mailcap.nim
+++ b/src/config/mailcap.nim
@@ -315,28 +315,17 @@ proc getMailcapEntry*(mailcap: Mailcap, mimeType, outpath: string,
     return nil
   let st = mimeType[mt.len + 1 .. ^1]
   for entry in mailcap:
-    block try_entry:
-      block check_mt:
-        if entry.mt.len == 1 and entry.mt[0] == '*':
-          break check_mt
-        if entry.mt.len != mt.len:
-          break try_entry
-        for i in 0 ..< mt.len:
-          if entry.mt[i] != mt[i]:
-            break try_entry
-      block check_subt:
-        if entry.subt.len == 1 and entry.subt[0] == '*':
-          break check_subt
-        if entry.subt.len != st.len:
-          break try_entry
-        for i in 0 ..< st.len:
-          if entry.subt[i] != st[i]:
-            break try_entry
-      if entry.test != "":
-        var canpipe = true
-        let cmd = unquoteCommand(entry.test, mimeType, outpath, url, charset,
-          canpipe)
-        #TODO TODO TODO if not canpipe ...
-        if execCmd(cmd) != 0:
-          break try_entry
-      return unsafeAddr entry
+    if not (entry.mt.len == 1 and entry.mt[0] == '*') and
+        entry.mt != mt:
+      continue
+    if not (entry.subt.len == 1 and entry.subt[0] == '*') and
+        entry.subt != st:
+      continue
+    if entry.test != "":
+      var canpipe = true
+      let cmd = unquoteCommand(entry.test, mimeType, outpath, url, charset,
+        canpipe)
+      #TODO TODO TODO if not canpipe ...
+      if execCmd(cmd) != 0:
+        continue
+    return unsafeAddr entry