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