commit 204c8cedb99683d264e2612a4e126142a20e3042
parent 25d46ce743e68c9d920190bfe29262f16214b194
Author: Christoph Lohmann <20h@r-36.net>
Date: Tue, 26 Jul 2022 23:39:22 +0200
Implement new escaping in geomyidae.
Thanks Bob for all of your help and hints!
Diffstat:
3 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/geomyidae.8 b/geomyidae.8
@@ -257,11 +257,11 @@ Note: geomyidae doesn't require "informational" text to be formally
Typed as "[i|...]"; any line
.Em not
beginning with "[" is treated as informational, greatly simplifying the
-formatting of index.gph files. However, if a line begins with a "t", this
-"t" is left out. This quirk is there to allow "informational" text lines
-beginning with a "[" to display. For dynamically generated index files
-it may be desirable to either formally Type informational text or run
-it through a filter to add a second "t" - .ie sed 's/^t/&&/' .
+formatting of index.gph files. If you want to display some informational
+text beginning with "[" you can use the special case of an empty item
+type. "[|[some link" will be shortened to "[some link". For dynamically
+generated content it may be desirable to either formally type
+informational text or run it through a filter to prepend "[|" - .ie sed 's,^[,[|&,' .
.Ed
.Bd -filled
Note 2: You can escape a pipe ("|") character in for example a
diff --git a/ind.c b/ind.c
@@ -255,12 +255,15 @@ getadv(char *str)
char *b, *e, *o, *bo;
Elems *ret;
+ if (strlen(str) == 0)
+ return NULL;
+
ret = xcalloc(1, sizeof(Elems));
if (strchr(str, '\t')) {
addelem(ret, "i");
addelem(ret, "Happy helping ☃ here: You tried to "
- "output a spurious tab character. This will "
+ "output a spurious TAB character. This will "
"break gopher. Please review your scripts. "
"Have a nice day!");
addelem(ret, "Err");
@@ -270,7 +273,8 @@ getadv(char *str)
return ret;
}
- if (str[0] == '[') {
+ /* Check for escape sequence. */
+ if (str[0] == '[' && str[1] != '|') {
o = xstrdup(str);
b = o + 1;
bo = b;
@@ -294,38 +298,21 @@ getadv(char *str)
}
free(o);
- /*
- * TODO: Add new [| escape handling after brcon2022 discussion.
- */
- if (ret->e != NULL && ret->e[0] != NULL && ret->e[0][0] == '\0') {
- freeelem(ret);
- ret = xcalloc(1, sizeof(Elems));
-
- addelem(ret, "i");
- addelem(ret, "Happy helping ☃ here: You did not "
- "specify an item type on this line. Please "
- "review your scripts. "
- "Have a nice day!");
- addelem(ret, "Err");
- addelem(ret, "server");
- addelem(ret, "port");
-
+ if (ret->e != NULL && ret->e[0] != NULL &&
+ ret->e[0][0] != '\0' && ret->num == 5) {
return ret;
}
- if (ret->e != NULL && ret->num == 5)
- return ret;
-
/* Invalid entry: Give back the whole line. */
freeelem(ret);
ret = xcalloc(1, sizeof(Elems));
}
- b = str;
- if (*str == 't')
- b++;
addelem(ret, "i");
- addelem(ret, b);
+ /* Jump over escape sequence. */
+ if (str[0] == '[' && str[1] == '|')
+ str += 2;
+ addelem(ret, str);
addelem(ret, "Err");
addelem(ret, "server");
addelem(ret, "port");
diff --git a/index.gph b/index.gph
@@ -1,12 +1,14 @@
comment
-tcomment
+tcomment (old style comment)
[1|R-36|/|server|port]
[0|file - comment|/file.txt|server|port]
[h|http://www.heise.de|URL:http://www.heise.de|server|port]
[0|some \| escape and [ special characters ] test|error|server|port]
[9|binary data file|/file.dat|server|port]
+[9|unclosed entry|/file.dat|server|port
[|empty type||server|port]
-[|Escape something
+[|Escape something, [| is skipped.
some invalid line
+[|[9|binary data file (escaped entry, shown as 'i')|/file.dat|server|port]