* RegExp::Prop(): Fixed build (assignment of string literals to a char*).

* Automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38618 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-09-12 15:08:01 +00:00
parent 8cd456aad1
commit e83635fd5a
+45 -45
View File
@@ -109,23 +109,23 @@ const uint8 kRegExpMagic = 0234;
// to the thing following the set of kRegExpBranches.) The opcodes are:
//
// definition number opnd? meaning
// definition number opnd? meaning
enum {
kRegExpEnd = 0, // no End of program.
kRegExpBol = 1, // no Match "" at beginning of line.
kRegExpEol = 2, // no Match "" at end of line.
kRegExpAny = 3, // no Match any one character.
kRegExpAnyOf = 4, // str Match any character in this string.
kRegExpAnyBut = 5, // str Match any character not in this string.
kRegExpBranch = 6, // node Match this alternative, or the next...
kRegExpBack = 7, // no Match "", "next" ptr points backward.
kRegExpExactly = 8, // str Match this string.
kRegExpNothing = 9, // no Match empty string.
kRegExpStar = 10, // node Match this (simple) thing 0 or more times.
kRegExpPlus = 11, // node Match this (simple) thing 1 or more times.
kRegExpOpen = 20, // no Mark this point in input as start of #n.
// kRegExpOpen + 1 is number 1, etc.
kRegExpClose = 30 // no Analogous to kRegExpOpen.
kRegExpEnd = 0, // no End of program.
kRegExpBol = 1, // no Match "" at beginning of line.
kRegExpEol = 2, // no Match "" at end of line.
kRegExpAny = 3, // no Match any one character.
kRegExpAnyOf = 4, // str Match any character in this string.
kRegExpAnyBut = 5, // str Match any character not in this string.
kRegExpBranch = 6, // node Match this alternative, or the next...
kRegExpBack = 7, // no Match "", "next" ptr points backward.
kRegExpExactly = 8, // str Match this string.
kRegExpNothing = 9, // no Match empty string.
kRegExpStar = 10, // node Match this (simple) thing 0 or more times.
kRegExpPlus = 11, // node Match this (simple) thing 1 or more times.
kRegExpOpen = 20, // no Mark this point in input as start of #n.
// kRegExpOpen + 1 is number 1, etc.
kRegExpClose = 30 // no Analogous to kRegExpOpen.
};
//
@@ -148,7 +148,7 @@ enum {
// and to minimize recursive plunges.
//
// kRegExpOpen,kRegExpClose ...are numbered at compile time.
//
//
//
//
// A node is one char of opcode followed by two chars of "next" pointer.
@@ -166,10 +166,10 @@ const int32 kMaxSize = 32767L; // Probably could be 65535L.
// Flags to be passed up and down:
enum {
kHasWidth = 01, // Known never to match null string.
kSimple = 02, // Simple enough to be kRegExpStar/kRegExpPlus operand.
kSPStart = 04, // Starts with * or +.
kWorst = 0 // Worst case.
kHasWidth = 01, // Known never to match null string.
kSimple = 02, // Simple enough to be kRegExpStar/kRegExpPlus operand.
kSPStart = 04, // Starts with * or +.
kWorst = 0 // Worst case.
};
const char *kRegExpErrorStringArray[] = {
@@ -250,7 +250,7 @@ RegExp::Matches(const char *string) const
{
if (!fRegExp || !string)
return false;
return RunMatcher(fRegExp, string) == 1;
}
@@ -302,7 +302,7 @@ RegExp::Compile(const char *exp)
if (Reg(0, &flags) == NULL)
return NULL;
// Small enough for pointer-storage convention?
// Small enough for pointer-storage convention?
if (fCodeSize >= kMaxSize) {
SetError(REGEXP_TOO_BIG);
return NULL;
@@ -325,13 +325,13 @@ RegExp::Compile(const char *exp)
free(r);
return NULL;
}
// Dig out information for optimizations.
r->regstart = '\0'; // Worst-case defaults.
r->reganch = 0;
r->regmust = NULL;
r->regmlen = 0;
scan = r->program + 1; // First kRegExpBranch.
scan = r->program + 1; // First kRegExpBranch.
if (*Next((char *)scan) == kRegExpEnd) { // Only one top-level choice.
scan = Operand(scan);
@@ -444,7 +444,7 @@ RegExp::Reg(int32 paren, int32 *flagp)
}
// Make a closing node, and hook it on the end.
ender = Node(paren ? (char)(kRegExpClose + parno) : (char)kRegExpEnd);
ender = Node(paren ? (char)(kRegExpClose + parno) : (char)kRegExpEnd);
Tail(ret, ender);
// Hook the tails of the branches to the closing node.
@@ -542,7 +542,7 @@ RegExp::Piece(int32 *flagp)
Insert(kRegExpStar, ret);
else if (op == '*') {
// Emit x* as (x&|), where & means "self".
Insert(kRegExpBranch, ret); // Either x
Insert(kRegExpBranch, ret); // Either x
OpTail(ret, Node(kRegExpBack)); // and loop
OpTail(ret, ret); // back
Tail(ret, Node(kRegExpBranch)); // or
@@ -559,14 +559,14 @@ RegExp::Piece(int32 *flagp)
} else if (op == '?') {
// Emit x? as (x|)
Insert(kRegExpBranch, ret); // Either x
Tail(ret, Node(kRegExpBranch)); // or
Tail(ret, Node(kRegExpBranch)); // or
next = Node(kRegExpNothing); // null.
Tail(ret, next);
OpTail(ret, next);
}
fInputScanPointer++;
if (IsMult(*fInputScanPointer)) {
SetError(REGEXP_NESTED_STAR_QUESTION_PLUS);
SetError(REGEXP_NESTED_STAR_QUESTION_PLUS);
return NULL;
}
return ret;
@@ -603,7 +603,7 @@ RegExp::Atom(int32 *flagp)
{
int32 cclass;
int32 classend;
if (*fInputScanPointer == '^') { // Complement of range.
ret = Node(kRegExpAnyBut);
fInputScanPointer++;
@@ -669,7 +669,7 @@ RegExp::Atom(int32 *flagp)
{
int32 len;
char ender;
fInputScanPointer--;
len = (int32)strcspn(fInputScanPointer, kMeta);
if (len <= 0) {
@@ -733,9 +733,9 @@ RegExp::Char(char b)
//
// - Insert - insert an operator in front of already-emitted operand
//
//
// Means relocating the operand.
//
//
void
RegExp::Insert(char op, char *opnd)
{
@@ -815,15 +815,15 @@ RegExp::RunMatcher(regexp *prog, const char *string) const
{
const char *s;
// Be paranoid...
// Be paranoid...
if (prog == NULL || string == NULL) {
SetError(B_BAD_VALUE);
SetError(B_BAD_VALUE);
return 0;
}
// Check validity of program.
if (UCharAt(prog->program) != kRegExpMagic) {
SetError(REGEXP_CORRUPTED_PROGRAM);
SetError(REGEXP_CORRUPTED_PROGRAM);
return 0;
}
@@ -869,7 +869,7 @@ RegExp::RunMatcher(regexp *prog, const char *string) const
//
// - Try - try match at specific point
//
int32 // 0 failure, 1 success
int32 // 0 failure, 1 success
RegExp::Try(regexp *prog, const char *string) const
{
int32 i;
@@ -978,10 +978,10 @@ RegExp::Match(const char *prog) const
{
int32 no;
const char *save;
no = *scan - kRegExpOpen;
save = fStringInputPointer;
if (Match(next)) {
//
// Don't set startp if some later
@@ -1007,10 +1007,10 @@ RegExp::Match(const char *prog) const
{
int32 no;
const char *save;
no = *scan - kRegExpClose;
save = fStringInputPointer;
if (Match(next)) {
//
// Don't set endp if some later
@@ -1027,7 +1027,7 @@ RegExp::Match(const char *prog) const
case kRegExpBranch:
{
const char *save;
if (*next != kRegExpBranch) // No choice.
next = Operand(scan); // Avoid recursion.
else {
@@ -1050,7 +1050,7 @@ RegExp::Match(const char *prog) const
int32 no;
const char *save;
int32 min;
//
//Lookahead to avoid useless match attempts
// when we know what character comes next.
@@ -1224,7 +1224,7 @@ RegExp::Dump()
next = Next(s);
if (next == NULL) // Next ptr.
printf("(0)");
else
else
printf("(%ld)", (s - fRegExp->program) + (next - s));
s += 3;
if (op == kRegExpAnyOf || op == kRegExpAnyBut || op == kRegExpExactly) {
@@ -1254,7 +1254,7 @@ RegExp::Dump()
char *
RegExp::Prop(const char *op) const
{
char *p = NULL;
const char *p = NULL;
static char buf[50];
(void) strcpy(buf, ":");