Bugfixing Syntaxcoloring

This commit is contained in:
Mike Beck
2002-06-12 16:12:07 +00:00
parent e4026cda01
commit 923a2c12e6
3 changed files with 25 additions and 13 deletions

View File

@@ -232,7 +232,7 @@ $cfg['colorFunctions'] = 'red';
$cfg['colorKeywords'] = 'blue'; $cfg['colorKeywords'] = 'blue';
$cfg['colorStrings'] = 'green'; $cfg['colorStrings'] = 'green';
$cfg['colorColType'] = '#FF9900'; $cfg['colorColType'] = '#FF9900';
$cfg['colorAdd'] = '#9999CC'; $cfg['colorAdd'] = 'blue';
/** /**
@@ -312,6 +312,7 @@ if($cfg['UseSyntaxColoring']) {
'SELECT', 'SELECT',
'INSERT', 'INSERT',
'LEFT', 'LEFT',
'INNER',
'UPDATE', 'UPDATE',
'REPLACE', 'REPLACE',
'EXPLAIN', 'EXPLAIN',
@@ -326,7 +327,8 @@ if($cfg['UseSyntaxColoring']) {
'ORDER', 'ORDER',
'CHANGE', 'CHANGE',
'CREATE', 'CREATE',
'DELETE' 'DELETE',
'VALUES'
); );
} // end if } // end if
if($cfg['UseSyntaxColoring']) { if($cfg['UseSyntaxColoring']) {

View File

@@ -210,35 +210,41 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
$_skeyw = '^' . implode('$|^', $cfg['keywords']) . '$'; $_skeyw = '^' . implode('$|^', $cfg['keywords']) . '$';
$_scoltype = '^' . implode('$|^', $cfg['ColumnTypes']) . '$'; $_scoltype = '^' . implode('$|^', $cfg['ColumnTypes']) . '$';
$_add = '^' . implode('$|^', $cfg['additional']) . '$'; $_add = '^' . implode('$|^', $cfg['additional']) . '$';
// first of all lets remove all newlines - we'll add our own later
// first of all lets remove all newlines - we'll add our own later
$sql = str_replace("\n", ' ', $sql); $sql = str_replace("\n", ' ', $sql);
// there should always be blanks around = and after , () // there should always be blanks around = and after , ()
$sql = str_replace('=', ' = ', $sql); $sql = str_replace('=', ' = ', $sql);
$sql = str_replace(',', ', ', $sql); $sql = str_replace(',', ', ', $sql);
$sql = str_replace(')', ' ) ', $sql); $sql = str_replace(')', ' ) ', $sql);
$sql = str_replace('(', ' ( ', $sql); $sql = str_replace('(', ' ( ', $sql);
$sql = str_replace(';', ' ; ', $sql); $sql = str_replace(';', ' ; ', $sql);
// now split everything by the blanks // now split everything by the blanks
$_sql_parts=explode(' ',$sql); $_sql_parts=explode(' ',$sql);
// start a loop over the parts check each word and put them back into $sql // start a loop over the parts check each word and put them back into $sql
unset($sql); unset($sql);
$s_nr=0; $s_nr=0;
while (list($_num,$_word) = each($_sql_parts)) { while (list($_num,$_word) = each($_sql_parts)) {
// we might have added to many blanks when checking for = and , // we might have added to many blanks when checking for = and ,
// which might lead to empty members in the array // which might lead to empty members in the array
if(strlen($_word)==0){continue;} if(strlen($_word)==0){continue;}
$_is_string = FALSE;
// Anything inside quots might be more than one word // Anything inside quots might be more than one word
// so as we splitted by the blanks we have to try to get those parts back // so as we splitted by the blanks we have to try to get those parts back
// together // together
if (substr($_word, 0, 1) == '\'' || substr($_word, 0, 1) == '"') { if (
(substr($_word, 0, 1) == '\'' || substr($_word, 0, 1) == '"') &&
(!isset($_temp) || strlen($_temp)==0)
) {
// start of a string // start of a string
$_temp = $_word; $_temp = $_word;
} else { $_is_string = TRUE;
} else {
if(isset($_temp) && strlen($_temp)>0){ if(isset($_temp) && strlen($_temp)>0){
// we are continuing a string // we are continuing a string
$_temp .= $_word; $_temp .= $_word;
$_is_string = TRUE;
} }
} }
if(substr($_word, strlen($_word)-1, 1) == '\'' if(substr($_word, strlen($_word)-1, 1) == '\''
@@ -246,7 +252,9 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
// End of a String // End of a String
$_word = '<font color="' . $cfg['colorStrings'] . '">' . $_temp . '</font>'; $_word = '<font color="' . $cfg['colorStrings'] . '">' . $_temp . '</font>';
$_temp = ''; $_temp = '';
} else { $_is_string = FALSE;
}
if(!isset($_is_string) || $_is_string == FALSE) {
// no String // no String
if(eregi($_sfuncs, $_word)) { if(eregi($_sfuncs, $_word)) {
$_word = '<font color="' . $cfg['colorFunctions'].'">' . $_word . '</font>'; $_word = '<font color="' . $cfg['colorFunctions'].'">' . $_word . '</font>';
@@ -257,7 +265,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
} else { } else {
$_word = "\n" . $_word; $_word = "\n" . $_word;
} }
} else { } else {
if(eregi($_scoltype, $_word)) { if(eregi($_scoltype, $_word)) {
$_word = '<font color="' . $cfg['colorColType'].'">' . $_word . '</font>'; $_word = '<font color="' . $cfg['colorColType'].'">' . $_word . '</font>';
@@ -271,6 +279,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
if($_word==')') { if($_word==')') {
if(isset($_brack_o)){ if(isset($_brack_o)){
unset($_brack_o[count($_brack_o)-1]); unset($_brack_o[count($_brack_o)-1]);
if(count($_brack_o)==0){ unset($_brack_o);}
} else { } else {
$_brack_c[]=$s_nr; $_brack_c[]=$s_nr;
} }
@@ -299,11 +308,12 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold}
if(isset($_brack_c)) { if(isset($_brack_c)) {
while (list($_num,$elem) = each($_brack_c)) { while (list($_num,$elem) = each($_brack_c)) {
$_sql_p[$elem] = '<font color="red">' . $_sql_p[$elem] . '</font>'; $_sql_p[$elem] = '<font color="red">' . $_sql_p[$elem] . '</font>';
echo '<br /><font color="red">' . $GLOBALS['strMissingBracket'] . '</font><br />'; echo '<br /><font color="red">' . $GLOBALS['strMissingBracket'] . '</font><br />';
} }
} }
$sql = implode(' ',$_sql_p); $sql = implode(' ',$_sql_p);
return nl2br($sql); $sql = ereg_replace("((\015\012)|(\015)|(\012))+", '<br />', $sql);
return $sql;
} // End of PMA_format_sql function } // End of PMA_format_sql function
/** /**
@@ -1097,7 +1107,7 @@ if (typeof(document.getElementById) != 'undefined'
if (!empty($GLOBALS['show_as_php'])) { if (!empty($GLOBALS['show_as_php'])) {
$new_line = '&quot;;<br />' . "\n" . ' $sql .= &quot;'; $new_line = '&quot;;<br />' . "\n" . ' $sql .= &quot;';
}else{ }else{
$new_line = "\n"; $new_line = "<br />\n";
} }
$query_base = htmlspecialchars($GLOBALS['sql_query']); $query_base = htmlspecialchars($GLOBALS['sql_query']);
$query_base = ereg_replace("((\015\012)|(\015)|(\012))+", $new_line, $query_base); $query_base = ereg_replace("((\015\012)|(\015)|(\012))+", $new_line, $query_base);

View File

@@ -355,7 +355,7 @@ if ($sql_query != '') {
$a_sql_query = $pieces[$i]; $a_sql_query = $pieces[$i];
$result = mysql_query($a_sql_query); $result = mysql_query($a_sql_query);
if ($result == FALSE) { // readdump failed if ($result == FALSE) { // readdump failed
$my_die = PMA_format_sql($a_sql_query); $my_die = $a_sql_query;
break; break;
} }
if (!isset($reload) && eregi('^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)', $a_sql_query)) { if (!isset($reload) && eregi('^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)', $a_sql_query)) {