annotate 3rdparty/packages/ed/matchs.c @ 1642:31cba223dc92

sysgo.asm has new dts and dtb pseudo ops clock2.asm has emulator clock support by Robert Gault
author boisy
date Thu, 15 Jul 2004 12:18:04 +0000
parents bef1844de0dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
994
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
1 /* matchs.c */
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
2 #include <stdio.h>
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
3 #include "tools.h"
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
4
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
5 /* Compares line and pattern. Line is a character string while pat
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
6 * is a pattern template made by getpat().
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
7 * Returns:
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
8 * 1. A zero if no match was found.
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
9 *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
10 * 2. A pointer to the last character satisfing the match
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
11 * if ret_endp is non-zero.
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
12 *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
13 * 3. A pointer to the beginning of the matched string if
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
14 * ret_endp is zero.
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
15 *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
16 * e.g.:
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
17 *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
18 * matchs ("1234567890", getpat("4[0-9]*7), 0);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
19 * will return a pointer to the '4', while:
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
20 *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
21 * matchs ("1234567890", getpat("4[0-9]*7), 1);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
22 * will return a pointer to the '7'.
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
23 */
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
24 char *
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
25 matchs(line, pat, ret_endp)
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
26 char *line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
27 TOKEN *pat;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
28 int ret_endp;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
29 {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
30
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
31 char *rval, *bptr;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
32 char *line2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
33 TOKEN *pat2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
34 char c;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
35 short ok;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
36
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
37 bptr = line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
38
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
39 while (*line) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
40
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
41 if (pat && pat->tok == LITCHAR) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
42 while (*line) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
43 pat2 = pat;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
44 line2 = line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
45 if (*line2 != pat2->lchar) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
46 c = pat2->lchar;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
47 while (*line2 && *line2 != c) ++line2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
48 line = line2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
49 if (*line2 == '\0') break;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
50 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
51 ok = 1;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
52 ++line2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
53 pat2 = pat2->next;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
54 while (pat2 && pat2->tok == LITCHAR) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
55 if (*line2 != pat2->lchar) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
56 ok = 0;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
57 break;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
58 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
59 ++line2;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
60 pat2 = pat2->next;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
61 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
62 if (!pat2) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
63 if (ret_endp)
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
64 return(--line2);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
65 else
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
66 return(line);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
67 } else if (ok)
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
68 break;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
69 ++line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
70 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
71 if (*line == '\0') return(0);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
72 } else {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
73 line2 = line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
74 pat2 = pat;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
75 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
76 if ((rval = amatch(line2, pat2, bptr)) == 0) {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
77 if (pat && pat->tok == BOL) break;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
78 line++;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
79 } else {
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
80 if (rval > bptr && rval > line)
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
81 rval--; /* point to last char matched */
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
82 rval = ret_endp ? rval : line;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
83 break;
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
84 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
85 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
86 return(rval);
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
87 }
bef1844de0dc The ED editor ported from Minix
roug
parents:
diff changeset
88