PIPS
|
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <strings.h>
#include <sys/param.h>
#include <getopt.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "database.h"
#include "misc.h"
#include "newgen.h"
#include "ri-util.h"
#include "pipsdbm.h"
#include "properties.h"
#include "constants.h"
#include "resources.h"
#include "pipsmake.h"
#include "preprocessor.h"
#include "top-level.h"
#include "tpips.h"
#include "completion_list.h"
Go to the source code of this file.
Data Structures | |
struct | t_completion_scheme |
Macros | |
#define | tpips_usage |
tp_lex.c More... | |
#define | SEPARATOR_P(c) (index (" \t", c)) |
#define | TPIPS_IS_A_SHELL "TPIPS_IS_A_SHELL" |
Whether pips should behave as a shell. More... | |
#define | JPIPS_TAG "#jpips:" |
jpips specials. More... | |
#define | RESERVED_FOR_FILENAME (char**) 0x01 |
#define | BEGIN_RQ "begin_user_request" |
Tpips user request. More... | |
#define | END_RQ "end_user_request" |
#define | BEGIN_UE "begin_user_error" |
#define | END_UE "end_user_error" |
#define | TP_HELP(prefix, simple, full) |
Handlers. More... | |
#define | CACHED_STRING_LIST(NAME) |
Enumerations | |
enum | COMPLETION_TYPES { COMP_NONE , COMP_FILENAME , COMP_MODULE , COMP_RULE , COMP_RESOURCE , COMP_PROPERTY , COMP_HELP_TOPIC , COMP_FILE_RSC } |
Functions | |
string | tpips_current_file_name () |
int | tpips_current_line_number () |
void | tpips_next_line (void) |
int | tpips_current_line (void) |
string | tpips_current_name (void) |
int | tgetnum () |
void | tp_restart (FILE *) |
static bool | prefix_equal_p (string str, string prf) |
static bool | string_is_true (string s) |
bool | tpips_behaves_like_a_shell (void) |
FILE * | jpips_out_file (void) |
void | jpips_begin_tag (string s) |
void | jpips_add_tag (string s) |
void | jpips_end_tag (void) |
void | jpips_tag (string s) |
void | jpips_tag2 (string s1, string s2) |
void | jpips_done (void) |
void | jpips_string (const char *a_message_format, va_list some_arguments) |
void | jpips_printf (const string format,...) |
static char * | fun_generator (const char *texte, int state) |
Generator function for command completion. More... | |
char ** | get_module_names (void) |
Build an array with the names of all available modules. More... | |
static char * | param_generator (const char *texte, int state) |
Generator function for param. More... | |
static char ** | fun_completion (char *texte, int start, int end) |
Attempt to complete on the contents of TEXT. More... | |
static void | initialize_readline (void) |
Tell the GNU Readline library how to complete. More... | |
static char * | get_next_line (char *prompt) |
returns the next line from the input, interactive tty or file... More... | |
static char * | tpips_read_a_line (char *main_prompt) |
returns an allocated line read, including continuations. More... | |
static string | tpips_user_request (const char *fmt, va_list *args) |
static void | tpips_user_error (const char *calling_function_name, const char *format, va_list *args) |
handle a user error DO NOT TERMINATE here, see pips_log_end More... | |
void | tpips_internal_error (_UNUSED_ const char *calling_function_name, _UNUSED_ const char *a_message_format,...) |
In case of a tpips internal error, either core dump or try to save the workspace. More... | |
static string | default_hist_file_name (void) |
returns the allocated full tpips history file name, i.e. More... | |
static void | initialize_tpips_history (void) |
void | tpips_help (string line) |
static void | close_workspace_if_opened (bool is_quit) |
void | tpips_close (void) |
void | tpips_set_line_to_parse (char *) |
in lex file More... | |
char * | tpips_get_line_to_parse (void) |
static void | handle (string line) |
static bool | line_with_substitutions (string line) |
whether some substitutions are needed... More... | |
static string | tp_substitutions (string line) |
returns an allocated string after shell substitutions. More... | |
void | tpips_init (void) |
static bool | blank_or_comment_line_p (string line) |
static void | tpips_exec (char *line) |
void | tpips_process_a_file (FILE *file, string name, bool use_rl) |
processing command line per line. More... | |
static string | default_tpipsrc (void) |
default .tpipsrc is $HOME/.tpipsrc. More... | |
static void | open_logfile (string filename, char opt) |
static void | parse_arguments (int argc, char *argv[]) |
int | tpips_main (int argc, char *argv[]) |
MAIN: interactive loop and history management. More... | |
Variables | |
bool | tpips_execution_mode = true |
Sometimes, already included by unistd.h. More... | |
bool | tpips_is_interactive = false |
static bool | tpips_is_a_shell = false |
static bool | use_readline = false |
static FILE * | logfile |
static FILE * | current_file = NULL |
current file being processed, with its name and the line number More... | |
static string | current_name = "<unknown>" |
static int | current_line = 0 |
bool | jpips_is_running = false |
static FILE * | in_from_jpips |
Ronan suggested a signal driven handling of jpips requests, so as to let the prompt available for direct commands. More... | |
static FILE * | out_to_jpips |
static char ** | current_completion_array |
static struct t_completion_scheme | completion_scheme [] |
static char * | tp_help_topics [] |
bool | tpips_init_done = false |
variable globale, utilisee par le parser helas More... | |
bool | consistency_enforced_p = false |
Pipsmake does not enforce consistency when properties are changed. More... | |
char * | optarg |
int | optind |
const char * | soft_revisions |
could be shared somewhere? More... | |
const char * | soft_date |
const char * | cc_version |
#define CACHED_STRING_LIST | ( | NAME | ) |
#define JPIPS_TAG "#jpips:" |
#define RESERVED_FOR_FILENAME (char**) 0x01 |
Handlers.
#define TPIPS_IS_A_SHELL "TPIPS_IS_A_SHELL" |
#define tpips_usage |
enum COMPLETION_TYPES |
Definition at line 994 of file tpips.c.
References line, skip_blanks, and TPIPS_COMMENT_PREFIX.
Referenced by tpips_exec().
|
static |
Definition at line 862 of file tpips.c.
References close_workspace(), and db_get_current_workspace_name().
Referenced by tpips_close().
|
static |
returns the allocated full tpips history file name, i.e.
else builds the default name.
Definition at line 662 of file tpips.c.
References concatenate(), strdup(), TPIPS_HISTENV, and TPIPS_HISTORY.
Referenced by initialize_tpips_history(), and tpips_close().
|
static |
default .tpipsrc is $HOME/.tpipsrc.
the returned string is allocated.
Definition at line 1104 of file tpips.c.
References concatenate(), and strdup().
Referenced by parse_arguments().
Attempt to complete on the contents of TEXT.
START and END show the region of TEXT that contains the word to complete. We can use the entire line in case we want to do some simple parsing. Return the array of matches, or NULL if there aren't any.
If this word is at the start of the line, then it is a command to complete. Otherwise it is the name of a file in the current directory.
Definition at line 478 of file tpips.c.
References end, fun_generator(), matches, pips_debug, and start.
Referenced by initialize_readline().
|
static |
Generator function for command completion.
STATE lets us know whether to start from scratch; without any state (i.e. STATE == 0), then we start at the top of the list.
If this is a new word to complete, initialize now. This includes saving the length of TEXT for efficiency, and initializing the index variable to 0.
Return the next name which partially matches from the command list.
If no names matched, then return NULL.
Definition at line 302 of file tpips.c.
References completion_scheme, t_completion_scheme::fun_name, and strdup().
Referenced by fun_completion().
char** get_module_names | ( | void | ) |
Build an array with the names of all available modules.
Free after a previous use:
By default, no available module:
Mainly inspired from wpips/emacs.c
Overkilling since most of time, the module list does not change but I guess there is no indicator in PIPS to tell some modules have been created or destroyed.
Note that since calloc initialize the memory to 0, this array will end with a NULL pointer as expected.
Definition at line 332 of file tpips.c.
References db_get_current_workspace_name(), db_get_module_list(), free(), gen_array_full_free(), gen_array_item(), and gen_array_nitems().
Referenced by param_generator().
|
static |
returns the next line from the input, interactive tty or file...
the final
does not appear.
Definition at line 529 of file tpips.c.
References current_file, safe_readline(), tpips_next_line(), and use_readline.
Referenced by tpips_read_a_line().
|
static |
parse if non-null line
Definition at line 894 of file tpips.c.
References line, tp_init_lex(), tp_parse(), tpips_get_line_to_parse(), and tpips_set_line_to_parse().
Referenced by tpips_exec().
|
static |
Tell the GNU Readline library how to complete.
We want to try to complete on command names if this is the first word in the line, or on filenames if not.
Definition at line 501 of file tpips.c.
References fun_completion(), and param_generator().
Referenced by tpips_process_a_file().
|
static |
Definition at line 672 of file tpips.c.
References default_hist_file_name(), file_name, and free().
Referenced by tpips_process_a_file().
void jpips_add_tag | ( | string | s | ) |
Definition at line 192 of file tpips.c.
References fprintf(), and out_to_jpips.
Referenced by jpips_tag2(), and tp_some_info().
void jpips_begin_tag | ( | string | s | ) |
Definition at line 187 of file tpips.c.
References fprintf(), JPIPS_TAG, and out_to_jpips.
Referenced by jpips_tag(), jpips_tag2(), and tp_some_info().
void jpips_done | ( | void | ) |
Definition at line 216 of file tpips.c.
References jpips_tag().
Referenced by tpips_process_a_file().
void jpips_end_tag | ( | void | ) |
Definition at line 197 of file tpips.c.
References fprintf(), and out_to_jpips.
Referenced by jpips_tag(), jpips_tag2(), and tp_some_info().
FILE* jpips_out_file | ( | void | ) |
Definition at line 182 of file tpips.c.
References out_to_jpips.
void jpips_printf | ( | const string | format, |
... | |||
) |
format | ormat |
Definition at line 229 of file tpips.c.
References out_to_jpips.
Referenced by tpips_user_error(), and tpips_user_request().
void jpips_string | ( | const char * | a_message_format, |
va_list | some_arguments | ||
) |
a_message_format | _message_format |
some_arguments | ome_arguments |
Definition at line 221 of file tpips.c.
References out_to_jpips.
Referenced by tpips_user_error(), and tpips_user_request().
void jpips_tag | ( | string | s | ) |
Definition at line 203 of file tpips.c.
References jpips_begin_tag(), and jpips_end_tag().
Referenced by jpips_done(), tpips_user_error(), and tpips_user_request().
s1 | 1 |
s2 | 2 |
Definition at line 209 of file tpips.c.
References jpips_add_tag(), jpips_begin_tag(), jpips_end_tag(), and s1.
Referenced by display_a_resource(), and tp_some_info().
whether some substitutions are needed...
variables are restricted to the ${xxx} syntax.
autres : ~ ???
Definition at line 913 of file tpips.c.
References line.
Referenced by tp_substitutions().
|
static |
Definition at line 1112 of file tpips.c.
References fprintf(), logfile, safe_fclose(), and safe_fopen().
Referenced by parse_arguments().
|
static |
Generator function for param.
completion. STATE lets us know whether to start from scratch; without any state (i.e. STATE == 0), then we start at the top of the list.
If this is a new word to complete, initialize now. This includes saving the length of TEXT for efficiency, and initializing the index variable to 0.
e should count the number of separator before the actual pos
We scan the array of function to find the used function
Now we can determine the completion type
Return the next name which partially matches from the command list.
If no names matched, then return NULL.
Definition at line 367 of file tpips.c.
References COMP_FILE_RSC, COMP_FILENAME, COMP_HELP_TOPIC, COMP_MODULE, COMP_NONE, COMP_PROPERTY, COMP_RESOURCE, COMP_RULE, completion_scheme, current_completion_array, t_completion_scheme::first_completion_type, t_completion_scheme::fun_name, get_module_names(), t_completion_scheme::other_completion_type, pips_debug, prefix_equal_p(), RESERVED_FOR_FILENAME, SEPARATOR_P, strdup(), tp_file_rsc_names, tp_help_topics, tp_phase_names, tp_property_names, and tp_resource_names.
Referenced by initialize_readline().
|
static |
the wrapper process will never return
sources ~/.tpipsrc or the like, if any.
no arguments, parses stdin.
process file arguments.
the tpips dirname is appended to PIPS_SRCPATH
Definition at line 1126 of file tpips.c.
References _FALLTHROUGH_, cc_version, default_tpipsrc(), exit, file_exists_p(), find_file_in_directories(), fprintf(), free(), jpips_is_running, open_logfile(), open_xml_logfile(), optarg, optind, pips_debug, pips_dirname(), pips_srcpath_append(), pips_srcpath_set(), safe_fclose(), safe_new_tmp_file(), same_string_p, set_script_directory_name(), soft_date, soft_revisions, strdup(), STRINGIFY, tpips_exec(), tpips_execution_mode, tpips_is_a_shell, tpips_is_interactive, tpips_process_a_file(), tpips_usage, tpips_wrapper(), and user_log().
Referenced by tpips_main().
Definition at line 125 of file tpips.c.
References skip_blanks.
Referenced by param_generator(), tp_substitutions(), and tpips_help().
Definition at line 131 of file tpips.c.
Referenced by tpips_behaves_like_a_shell().
int tgetnum | ( | ) |
void tp_restart | ( | FILE * | ) |
returns an allocated string after shell substitutions.
shell and comments are not substituted...
substitutions are performed by forking sh;-) however sh does not understand ~
Definition at line 927 of file tpips.c.
References abort, get_bool_property(), line, line_with_substitutions(), pips_debug, pips_user_warning, prefix_equal_p(), safe_system_substitute(), strdup(), and tpips_init().
Referenced by tpips_exec().
bool tpips_behaves_like_a_shell | ( | void | ) |
Definition at line 143 of file tpips.c.
References get_bool_property(), string_is_true(), tpips_is_a_shell, and TPIPS_IS_A_SHELL.
void tpips_close | ( | void | ) |
Definition at line 868 of file tpips.c.
References close_workspace_if_opened(), default_hist_file_name(), file_name, logfile, safe_fclose(), TPIPS_HISTORY_LENGTH, and use_readline.
Referenced by tpips_exec(), and tpips_main().
string tpips_current_file_name | ( | void | ) |
Definition at line 76 of file tpips.c.
References current_name.
int tpips_current_line | ( | void | ) |
Definition at line 91 of file tpips.c.
References current_line.
Referenced by tpips_lex_print_pos().
int tpips_current_line_number | ( | void | ) |
string tpips_current_name | ( | void | ) |
Definition at line 96 of file tpips.c.
References current_name.
Referenced by tpips_lex_print_pos().
|
static |
after environment variable substitution
leading setenv/getenv in a tpips script are performed PRIOR to pips initialization, hence the environment variable NEWGEN_MAX_TABULATED_ELEMENTS can be taken into account for a run. little of a hack. That results in a core dump when the tpips script starts with setenv commands generating user warnings because those imply a check of the property NO_USER_WARNING. Also errors are likely to lead to a check of ABORT_ON_USER_ERROR. And properties cannot be used before tpips_init() has been executed. So pips_user_warning() have to be protected in tpips.c by a preliminary call to tpips_init()
Definition at line 1000 of file tpips.c.
References any_exception_error, blank_or_comment_line_p(), CATCH, free(), get_debug_stack_pointer(), GET_ENV, handle(), line, pips_debug, pips_stop, set_debug_stack_pointer(), SET_ENV, strdup(), the_last_just_thrown_exception, TIMEOUT_CODE, timeout_error, tp_in, tp_restart(), tp_substitutions(), tpips_close(), tpips_init(), tpips_init_done, TPIPS_SOURCE, TRY, UNCATCH, use_readline, and user_error_log.
Referenced by parse_arguments(), and tpips_process_a_file().
char* tpips_get_line_to_parse | ( | void | ) |
void tpips_help | ( | string | line | ) |
get the number of colunms for 80 chars
get the number of colunms for 80 chars
line | ine |
Definition at line 688 of file tpips.c.
References count, current_size, GET_PROP, line, pips_debug, prefix_equal_p(), printf(), skip_blanks, tgetnum(), TP_HELP, tp_phase_names, and tp_resource_names.
void tpips_init | ( | void | ) |
set_exception_callbacks(push_pips_context, pop_pips_context);
???
Definition at line 970 of file tpips.c.
References consistency_enforced_p, entity_local_name(), get_bool_property(), in_from_jpips, initialize_newgen(), initialize_sc(), out_to_jpips, pips_checks(), pips_error_handler, pips_internal_error_handler, pips_request_handler, set_bool_property(), tpips_init_done, tpips_internal_error(), tpips_user_error(), and tpips_user_request().
Referenced by tp_substitutions(), and tpips_exec().
void tpips_internal_error | ( | _UNUSED_ const char * | calling_function_name, |
_UNUSED_ const char * | a_message_format, | ||
... | |||
) |
In case of a tpips internal error, either core dump or try to save the workspace.
Definition at line 643 of file tpips.c.
References db_close_workspace(), exit, and get_bool_property().
Referenced by tpips_init().
MAIN: interactive loop and history management.
I need this one right now, as tpips init may be called too late.
argc | rgc |
argv | rgv |
Definition at line 1298 of file tpips.c.
References asprintf, cc_version, debug_on, entity_local_name(), fprintf(), info_log, initialize_signal_catcher(), parse_arguments(), pips_stop, pop_pips_context(), push_pips_context(), set_exception_callbacks(), set_pips_meta_informations(), soft_date, soft_revisions, tpips_close(), and variable_debug_name.
void tpips_next_line | ( | void | ) |
Definition at line 86 of file tpips.c.
References current_line.
Referenced by get_next_line().
processing command line per line.
might be called recursively thru source.
push globals
interactive loop
file | ile |
name | ame |
use_rl | se_rl |
Definition at line 1062 of file tpips.c.
References current_file, current_line, current_name, free(), initialize_readline(), initialize_tpips_history(), jpips_done(), jpips_is_running, line, tpips_exec(), TPIPS_PRIMARY_PROMPT, tpips_read_a_line(), and use_readline.
Referenced by parse_arguments(), and process_file_list().
|
static |
returns an allocated line read, including continuations.
may return NULL at end of file.
Definition at line 538 of file tpips.c.
References concatenate(), fprintf(), free(), get_next_line(), line, logfile, pips_debug, strdup(), TPIPS_CONTINUATION_CHAR, and TPIPS_SECONDARY_PROMPT.
Referenced by tpips_process_a_file(), and tpips_user_request().
void tpips_set_line_to_parse | ( | char * | line | ) |
|
static |
handle a user error DO NOT TERMINATE here, see pips_log_end
Definition at line 611 of file tpips.c.
References BEGIN_UE, db_close_workspace(), db_get_current_workspace_name(), END_UE, get_bool_property(), jpips_is_running, jpips_printf(), jpips_string(), jpips_tag(), pips_user_warning, and properties_initialized_p().
Referenced by tpips_init().
|
static |
Definition at line 571 of file tpips.c.
References BEGIN_RQ, debug_off, debug_on, END_RQ, fprintf(), jpips_is_running, jpips_printf(), jpips_string(), jpips_tag(), pips_debug, tpips_read_a_line(), TPIPS_REQUEST_PROMPT, and use_readline.
Referenced by tpips_init().
const char * cc_version |
Definition at line 1124 of file tpips.c.
Referenced by parse_arguments(), pips_main(), tpips_main(), and wpips_main().
|
static |
Definition at line 239 of file tpips.c.
Referenced by fun_generator(), and param_generator().
Pipsmake does not enforce consistency when properties are changed.
The consistency can be enforced by forbidding setproperty during a processing phase.
Definition at line 968 of file tpips.c.
Referenced by tpips_init().
|
static |
Definition at line 239 of file tpips.c.
Referenced by param_generator().
|
static |
current file being processed, with its name and the line number
Definition at line 72 of file tpips.c.
Referenced by get_next_line(), and tpips_process_a_file().
|
static |
Definition at line 74 of file tpips.c.
Referenced by tpips_current_line(), tpips_current_line_number(), tpips_next_line(), and tpips_process_a_file().
|
static |
Definition at line 73 of file tpips.c.
Referenced by lazy_open_module(), tpips_current_file_name(), tpips_current_name(), and tpips_process_a_file().
|
static |
Ronan suggested a signal driven handling of jpips requests, so as to let the prompt available for direct commands.
This seems great, but is not implemented at the time. This would mean interruption driven tpips execution from jpips. The executions should not interfere... SIGIO handling on in_from_jpips... forward to readline maybe... a new -J option? how to link C FILE* to unix file descriptors? ? f = fopen(); dup2(..., fileno(f)); OR freopen()...
Definition at line 179 of file tpips.c.
Referenced by tpips_init().
Definition at line 166 of file tpips.c.
Referenced by display_a_resource(), parse_arguments(), tp_some_info(), tpips_process_a_file(), tpips_user_error(), and tpips_user_request().
|
static |
Definition at line 69 of file tpips.c.
Referenced by open_logfile(), tpips_close(), and tpips_read_a_line().
|
extern |
Referenced by parse_arguments(), pips_parse_arguments(), and set_hyperplane_parameters().
|
extern |
|
static |
Definition at line 180 of file tpips.c.
Referenced by jpips_add_tag(), jpips_begin_tag(), jpips_end_tag(), jpips_out_file(), jpips_printf(), jpips_string(), and tpips_init().
const char * soft_date |
Definition at line 1124 of file tpips.c.
Referenced by parse_arguments(), pips_main(), pips_parse_arguments(), tpips_main(), and wpips_main().
|
extern |
could be shared somewhere?
First part of user prologue.
Definition at line 33 of file revisions.c.
Referenced by parse_arguments(), and tpips_main().
|
static |
Definition at line 290 of file tpips.c.
Referenced by param_generator().
Sometimes, already included by unistd.h.
cproto-generated files
Definition at line 64 of file tpips.c.
Referenced by parse_arguments(), perform(), and tp_close_the_workspace().
variable globale, utilisee par le parser helas
Definition at line 964 of file tpips.c.
Referenced by process_file_list(), tpips_exec(), and tpips_init().
Definition at line 67 of file tpips.c.
Referenced by parse_arguments(), and tpips_behaves_like_a_shell().
Definition at line 65 of file tpips.c.
Referenced by parse_arguments(), process_file_list(), and tp_system().
Definition at line 68 of file tpips.c.
Referenced by get_next_line(), tpips_close(), tpips_exec(), tpips_process_a_file(), and tpips_user_request().