mirror of
https://github.com/grblHAL/core.git
synced 2026-02-05 08:34:01 +08:00
Added $384 setting for controlling G92 offset persistence. Improved $help command output and handling. Moved the optional tool table in non-volatile storage. Added gcode parameter support and optional expression support.
50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
// regex.c - A Regular Expression Matcher
|
|
//
|
|
// Code by Rob Pike, exegesis by Brian Kernighan
|
|
//
|
|
// http://genius.cat-v.org/brian-kernighan/articles/beautiful
|
|
//
|
|
// c matches any literal character c
|
|
// . matches any single character
|
|
// ^ matches the beginning of the input string
|
|
// $ matches the end of the input string
|
|
// * matches zero or more occurrences of the previous character
|
|
|
|
#include "regex.h"
|
|
|
|
/* match: search for regexp anywhere in text */
|
|
int match(char *regexp, char *text)
|
|
{
|
|
if (regexp[0] == '^')
|
|
return matchhere(regexp+1, text);
|
|
do { /* must look even if string is empty */
|
|
if (matchhere(regexp, text))
|
|
return 1;
|
|
} while (*text++ != '\0');
|
|
return 0;
|
|
}
|
|
|
|
/* matchhere: search for regexp at beginning of text */
|
|
int matchhere(char *regexp, char *text)
|
|
{
|
|
if (regexp[0] == '\0')
|
|
return 1;
|
|
if (regexp[1] == '*')
|
|
return matchstar(regexp[0], regexp+2, text);
|
|
if (regexp[0] == '$' && regexp[1] == '\0')
|
|
return *text == '\0';
|
|
if (*text!='\0' && (regexp[0]=='.' || regexp[0]==*text))
|
|
return matchhere(regexp+1, text+1);
|
|
return 0;
|
|
}
|
|
|
|
/* matchstar: search for c*regexp at beginning of text */
|
|
int matchstar(int c, char *regexp, char *text)
|
|
{
|
|
do { /* a * matches zero or more instances */
|
|
if (matchhere(regexp, text))
|
|
return 1;
|
|
} while (*text != '\0' && (*text++ == c || c == '.'));
|
|
return 0;
|
|
}
|