Mercurial > octave
diff libinterp/corefcn/toplev.cc @ 20799:c349d4c91ce2
eliminate return statements after calls to print_usage
* symtab.cc, sysdep.cc, toplev.cc, tsearch.cc, urlwrite.cc,
variables.cc: Eliminate return statements after calls to print_usage.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 03 Dec 2015 16:40:05 -0500 |
parents | f7084eae3318 |
children | 35241c4b696c |
line wrap: on
line diff
--- a/libinterp/corefcn/toplev.cc Thu Dec 03 15:07:01 2015 -0500 +++ b/libinterp/corefcn/toplev.cc Thu Dec 03 16:40:05 2015 -0500 @@ -1029,112 +1029,110 @@ int nargin = args.length (); - if (nargin > 0 && nargin < 4) - { - bool return_output = (nargin == 1 && nargout > 1); + if (nargin == 0 || nargin > 3) + print_usage (); - system_exec_type type = et_sync; + bool return_output = (nargin == 1 && nargout > 1); - if (nargin == 3) - { - std::string type_str = args(2).xstring_value ("system: TYPE must be a string"); + system_exec_type type = et_sync; - if (type_str == "sync") - type = et_sync; - else if (type_str == "async") - type = et_async; - else - { - error ("system: TYPE must be \"sync\" or \"async\""); - return retval; - } - } + if (nargin == 3) + { + std::string type_str = args(2).xstring_value ("system: TYPE must be a string"); - if (nargin > 1) + if (type_str == "sync") + type = et_sync; + else if (type_str == "async") + type = et_async; + else { - try - { - return_output = args(1).is_true (); - } - catch (octave_execution_exception& e) - { - error (e, "system: RETURN_OUTPUT must be boolean value true or false"); - } - } - - if (return_output && type == et_async) - { - error ("system: can't return output from commands run asynchronously"); + error ("system: TYPE must be \"sync\" or \"async\""); return retval; } + } - std::string cmd_str = args(0).xstring_value ("system: first argument must be a string"); + if (nargin > 1) + { + try + { + return_output = args(1).is_true (); + } + catch (octave_execution_exception& e) + { + error (e, "system: RETURN_OUTPUT must be boolean value true or false"); + } + } + + if (return_output && type == et_async) + { + error ("system: can't return output from commands run asynchronously"); + return retval; + } + + std::string cmd_str = args(0).xstring_value ("system: first argument must be a string"); #if defined (__WIN32__) && ! defined (__CYGWIN__) - // Work around weird double-quote handling on Windows systems. - if (type == et_sync) - cmd_str = "\"" + cmd_str + "\""; + // Work around weird double-quote handling on Windows systems. + if (type == et_sync) + cmd_str = "\"" + cmd_str + "\""; #endif - if (type == et_async) - { - // FIXME: maybe this should go in sysdep.cc? + if (type == et_async) + { + // FIXME: maybe this should go in sysdep.cc? #ifdef HAVE_FORK - pid_t pid = fork (); + pid_t pid = fork (); - if (pid < 0) - error ("system: fork failed -- can't create child process"); - else if (pid == 0) - { - // FIXME: should probably replace this - // call with something portable. + if (pid < 0) + error ("system: fork failed -- can't create child process"); + else if (pid == 0) + { + // FIXME: should probably replace this + // call with something portable. - execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), - static_cast<void *> (0)); + execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), + static_cast<void *> (0)); - panic_impossible (); - } - else - retval(0) = pid; + panic_impossible (); + } + else + retval(0) = pid; #elif defined (__WIN32__) - STARTUPINFO si; - PROCESS_INFORMATION pi; - ZeroMemory (&si, sizeof (si)); - ZeroMemory (&pi, sizeof (pi)); - OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); - strcpy (xcmd_str, cmd_str.c_str ()); + STARTUPINFO si; + PROCESS_INFORMATION pi; + ZeroMemory (&si, sizeof (si)); + ZeroMemory (&pi, sizeof (pi)); + OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); + strcpy (xcmd_str, cmd_str.c_str ()); - if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) - error ("system: CreateProcess failed -- can't create child process"); - else - { - retval(0) = pi.dwProcessId; - CloseHandle (pi.hProcess); - CloseHandle (pi.hThread); - } -#else - error ("system: asynchronous system calls are not supported"); -#endif - } - else if (return_output) - retval = run_command_and_return_output (cmd_str); + if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) + error ("system: CreateProcess failed -- can't create child process"); else { - int status = system (cmd_str.c_str ()); - - // The value in status is as returned by waitpid. If - // the process exited normally, extract the actual exit - // status of the command. Otherwise, return 127 as a - // failure code. + retval(0) = pi.dwProcessId; + CloseHandle (pi.hProcess); + CloseHandle (pi.hThread); + } +#else + error ("system: asynchronous system calls are not supported"); +#endif + } + else if (return_output) + retval = run_command_and_return_output (cmd_str); + else + { + int status = system (cmd_str.c_str ()); - if (octave_wait::ifexited (status)) - status = octave_wait::exitstatus (status); + // The value in status is as returned by waitpid. If + // the process exited normally, extract the actual exit + // status of the command. Otherwise, return 127 as a + // failure code. - retval(0) = status; - } + if (octave_wait::ifexited (status)) + status = octave_wait::exitstatus (status); + + retval(0) = status; } - else - print_usage (); return retval; } @@ -1221,27 +1219,24 @@ int nargin = args.length (); - if (nargin == 1 || nargin == 2) - { - std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string"); + if (nargin < 1 || nargin > 2) + print_usage (); - bool add_mode = true; + std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string"); - if (nargin == 2) - add_mode = args(1).xbool_value ("atexit: FLAG argument must be a logical value"); + bool add_mode = (nargin == 2) + ? args(1).xbool_value ("atexit: FLAG argument must be a logical value") + : true; - if (add_mode) - octave_add_atexit_function (arg); - else - { - bool found = octave_remove_atexit_function (arg); + if (add_mode) + octave_add_atexit_function (arg); + else + { + bool found = octave_remove_atexit_function (arg); - if (nargout > 0) - retval(0) = found; - } + if (nargout > 0) + retval(0) = found; } - else - print_usage (); return retval; } @@ -1521,6 +1516,9 @@ int nargin = args.length (); + if (nargin > 1) + print_usage (); + if (nargin == 1) { std::string arg = args(0).string_value (); @@ -1537,10 +1535,8 @@ else error ("octave_config_info: invalid parameter '%s'", arg.c_str ()); } - else if (nargin == 0) + else retval = m; - else - print_usage (); return retval; }