summaryrefslogtreecommitdiff
path: root/smu.c
diff options
context:
space:
mode:
authorgottox@work <gottox@work>2008-01-28 14:10:32 +0100
committergottox@work <gottox@work>2008-01-28 14:10:32 +0100
commitfc9310966e8c38fea21fd1cfe2f3e916cbbb11b7 (patch)
tree7ae8768cffc0cd509bc556bac89984332c43f28f /smu.c
parentc87f6e21b60354f352c2fd8aa02fc7aff1b9d737 (diff)
More documentation; fixed dosurround
Diffstat (limited to 'smu.c')
-rw-r--r--smu.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/smu.c b/smu.c
index 8b99042..43bd011 100644
--- a/smu.c
+++ b/smu.c
@@ -433,29 +433,28 @@ doshortlink(const char *begin, const char *end, int newblock) {
int
dosurround(const char *begin, const char *end, int newblock) {
unsigned int i, l;
- const char *p, *ps, *q, *qend;
+ const char *p, *start, *stop;
for(i = 0; i < LENGTH(surround); i++) {
l = strlen(surround[i].search);
- if(end - begin < l || strncmp(begin, surround[i].search, l) != 0)
+ if(end - begin < 2*l || strncmp(begin, surround[i].search, l) != 0)
continue;
- for(ps = surround[i].search; *ps == '\n'; ps++);
- l = strlen(ps);
- p = begin + strlen(surround[i].search) - 1;
+ start = begin + l;
+ p = start - 1;
do {
- p = strstr(p + 1, ps);
+ p = strstr(p + 1, surround[i].search);
} while(p && p[-1] == '\\');
- if(!p || p == end)
+ if(!p || p >= end)
continue;
fputs(surround[i].before, stdout);
- for(q = begin + strlen(surround[i].search); *q == ' '; q++);
- for(qend = p-1; *qend == ' '; qend--);
+ if(!(stop = strstr(start, surround[i].search)) || stop >= end)
+ continue;
if(surround[i].process)
- process(q, qend + 1, 0);
+ process(start, stop, 0);
else
- hprint(q, qend + 1);
+ hprint(start, stop);
fputs(surround[i].after, stdout);
- return p - begin + l;
+ return stop - begin + l;
}
return 0;
}