06.12.2012 Aufrufe

Technische Dokumentation zum Unix-Verbund ... - Dr. Hubert Feyrer

Technische Dokumentation zum Unix-Verbund ... - Dr. Hubert Feyrer

Technische Dokumentation zum Unix-Verbund ... - Dr. Hubert Feyrer

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

B.29 Monitoring/wildmat_code.c 318<br />

}<br />

return 0;<br />

B.29 Monitoring/wildmat_code.c<br />

/* $Revision: 1.9 $<br />

**<br />

** Do shell-style pattern matching for ?, \, [], and * characters.<br />

** Might not be robust in face of malformed patterns; e.g., "foo[a-"<br />

** could cause a segmentation violation. It is 8bit clean.<br />

**<br />

** Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.<br />

** Rich $alz is now .<br />

** April, 1991: Replaced mutually-recursive calls with in-line code<br />

** for the star character.<br />

**<br />

** Special thanks to Lars Mathiesen for the ABORT code.<br />

** This can greatly speed up failing wildcard patterns. For example:<br />

** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-*<br />

** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70iso8859-1<br />

** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70iso8859-1<br />

** Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without<br />

** the ABORT code, it takes 22310 calls to fail. Ugh. The following<br />

** explanation is from Lars:<br />

** The precondition that must be fulfilled is that DoMatch will consume<br />

** at least one character in text. This is true if *p is neither '*' nor<br />

** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic<br />

** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With<br />

** FALSE, each star-loop has to run to the end of the text; with ABORT<br />

** only the last one does.<br />

**<br />

** Once the control of one instance of DoMatch enters the star-loop, that<br />

** instance will return either TRUE or ABORT, and any calling instance<br />

** will therefore return immediately after (without calling recursively<br />

** again). In effect, only one star-loop is ever active. It would be<br />

** possible to modify the code to maintain this context explicitly,<br />

** eliminating all recursive calls at the cost of some complication and<br />

** loss of clarity (and the ABORT stuff seems to be unclear enough by<br />

** itself). I think it would be unwise to try to get this into a<br />

** released version unless you have a good test data base to try it out<br />

** on.<br />

*/<br />

#define TRUE 1<br />

#define FALSE 0<br />

#define ABORT -1<br />

/* What character marks an inverted character class? */<br />

#define NEGATE_CLASS '^'<br />

/* Is "*" a common pattern? */<br />

#define OPTIMIZE_JUST_STAR<br />

/* Do tar(1) matching rules, which ignore a trailing slash? */<br />

#undef MATCH_TAR_PATTERN<br />

/*<br />

** Match text and p, return TRUE, FALSE, or ABORT.<br />

*/<br />

static int<br />

DoMatch(text, p)<br />

register char*text;<br />

register char*p;<br />

{<br />

register intlast;<br />

register intmatched;<br />

(c) 1996-2003 <strong>Hubert</strong> <strong>Feyrer</strong> Stand: 21. Oktober 2003

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!