# HG changeset patch # User jwe # Date 879494355 0 # Node ID ff8b4d6371b313759165087f60ef90b91add7800 # Parent 528f4270e904b880c1f31b4d9f8ab9b1ee7f1db2 [project @ 1997-11-14 07:59:14 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,22 @@ +Fri Nov 14 01:53:13 1997 John W. Eaton + + * lex.l (have_continuation, have_ellipsis_continuation): Declare + arg as bool, not int. Change callers. + + * lex.l (Vbackslash_escapes): New static variable. + (backslash_escapes): New function. + (do_string_escapes): Return immediately if ! Vbackslash_escapes. + (eat_whitespace, eat_continuation): Only call have_continuation if + Vbackslash_escapes. + (handle_string): Backslash is only special if Vbackslash_escapes. + (symbols_of_lex): Add DEFVAR for backslash_escapes. + * octave.cc (maximum_braindamage): Set backslash_escapes to 0. + Thu Nov 13 16:20:40 1997 John W. Eaton + * variables.cc (Fexist): Also return 2 if NAME is a regular file + somewhere in the LOADPATH. + * data.cc (sumsq): Fix doc string. * parse.y (Fsource): Call parse_fcn_file, not parse_and_execute. diff --git a/src/defun-int.h b/src/defun-int.h --- a/src/defun-int.h +++ b/src/defun-int.h @@ -100,7 +100,7 @@ { \ check_version (OCTAVE_VERSION, #name); \ install_builtin_function (F ## name, #name, doc); \ - installed = true; + installed = true; \ } \ return installed; \ } diff --git a/src/lex.l b/src/lex.l --- a/src/lex.l +++ b/src/lex.l @@ -159,6 +159,9 @@ static int Vwhitespace_in_literal_matrix; +// Should Octave treat backslashes in strings as escapes that +// introduce special characters like newline (\n), tab (\t), etc.? +static bool Vbackslash_escapes; // Forward declarations for functions defined at the bottom of this // file. @@ -179,8 +182,8 @@ static int handle_string (char delim, int text_style = 0); static int handle_close_brace (int spc_gobbled); static int handle_identifier (const string& tok, int spc_gobbled); -static bool have_continuation (int trailing_comments_ok = 1); -static bool have_ellipsis_continuation (int trailing_comments_ok = 1); +static bool have_continuation (bool trailing_comments_ok = true); +static bool have_ellipsis_continuation (bool trailing_comments_ok = true); static yum_yum eat_whitespace (void); static yum_yum eat_continuation (void); @@ -721,6 +724,9 @@ static void do_string_escapes (char *s) { + if (! Vbackslash_escapes) + return; + char *p1 = s; char *p2 = s; @@ -1367,7 +1373,7 @@ break; else { - if (have_continuation ()) + if (Vbackslash_escapes && have_continuation ()) break; else goto done; @@ -1433,7 +1439,7 @@ // characters, return 0. Otherwise, return 1. static bool -have_continuation (int trailing_comments_ok) +have_continuation (bool trailing_comments_ok) { ostrstream buf; @@ -1472,7 +1478,7 @@ yyunput (c, yytext); return false; - cleanup: +cleanup: buf << ends; char *s = buf.str (); if (s) @@ -1482,6 +1488,7 @@ yyunput (s[len], yytext); } delete [] s; + return false; } @@ -1490,7 +1497,7 @@ // line character. static bool -have_ellipsis_continuation (int trailing_comments_ok) +have_ellipsis_continuation (bool trailing_comments_ok) { char c1 = yyinput (); if (c1 == '.') @@ -1521,7 +1528,7 @@ int retval = ATE_NOTHING; int c = yyinput (); if ((c == '.' && have_ellipsis_continuation ()) - || (c == '\\' && have_continuation ())) + || (c == '\\' && Vbackslash_escapes && have_continuation ())) retval = eat_whitespace (); else yyunput (c, yytext); @@ -1541,7 +1548,7 @@ { current_input_column++; - if (c == '\\') + if (c == '\\' && Vbackslash_escapes) { if (escape_pending) { @@ -1550,7 +1557,7 @@ } else { - if (have_continuation (0)) + if (have_continuation (false)) escape_pending = 0; else { @@ -1562,7 +1569,7 @@ } else if (c == '.') { - if (! have_ellipsis_continuation (0)) + if (! have_ellipsis_continuation (false)) buf << (char) c; } else if (c == '\n') @@ -1955,6 +1962,14 @@ } int +backslash_escapes (void) +{ + Vbackslash_escapes = check_preference ("backslash_escapes"); + + return 0; +} + +int whitespace_in_literal_matrix (void) { int pref = 0; @@ -1977,6 +1992,10 @@ void symbols_of_lex (void) { + DEFVAR (backslash_escapes, 1.0, 0, backslash_escapes, + "if nonzero, Octave recognizes backslashes in strings as escapes that\n\ +introduce special characters like newline (\\n), tab (\\t), etc."); + DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, "control auto-insertion of commas and semicolons in literal matrices"); } diff --git a/src/octave.cc b/src/octave.cc --- a/src/octave.cc +++ b/src/octave.cc @@ -325,6 +325,7 @@ { bind_builtin_variable ("PS1", ">> "); bind_builtin_variable ("PS2", ""); + bind_builtin_variable ("backslash_escapes", 0.0); bind_builtin_variable ("beep_on_error", 1.0); bind_builtin_variable ("default_eval_print_flag", 0.0); bind_builtin_variable ("default_save_format", "mat-binary"); diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -398,7 +398,12 @@ 1 : NAME is a variable\n\ 2 : NAME is a function\n\ 3 : NAME is a .oct file in the current LOADPATH\n\ - 5 : NAME is a built-in function") + 5 : NAME is a built-in function\n\ +\n\ +This function also returns 2 if a regular file called NAME exists in\n\ +Octave's LOADPATH. If you want information about other types of\n\ +files, you should use some combination of the functions file_in_path\n\ +and stat instead.") { octave_value_list retval; @@ -466,10 +471,15 @@ } else { - file_stat fs (name); + string file_name = file_in_path (name, ""); - if (fs && fs.is_reg ()) - retval = 2.0; + if (! file_name.empty ()) + { + file_stat fs (file_name); + + if (fs && fs.is_reg ()) + retval = 2.0; + } } } }