25 #include "pips_config.h"
33 #include <sys/param.h>
38 #include <readline/readline.h>
39 #include <readline/history.h>
53 #include "constants.h"
54 #include "resources.h"
106 #define tpips_usage \
107 "Usage: %s [-nscvh?jwa] " \
108 "[-l logfile] [-r rcfile] [-e tpips-cmds] tpips-scripts\n" \
109 "\t-n: no execution mode. just to check a script for syntax errors\n" \
110 "\t-s: behaves like a shell. tpips commands simply extend a shell.\n" \
111 "\t-c: behaves like a command, not a shell (it is the default).\n" \
112 "\t-h: this help. (also -?)\n" \
113 "\t-v: display version and architecture informations.\n" \
114 "\t-a: create a logfile automatically.\n" \
115 "\t-j: jpips special mode.\n" \
116 "\t-w: starts with a wrapper (jpips special again)...\n" \
117 "\t-l logfile: log to logfile.\n" \
118 "\t-r rcfile: tpips rc file to source. (default ~/.tpipsrc)\n" \
119 "\t-x xml-logfile: log to this file in XML.\n" \
120 "\t-e tpips-cmds: here tpips commands.\n" \
123 #define SEPARATOR_P(c) (index (" \t", c))
128 return !strncmp(str, prf, strlen(prf));
133 return s && (*s==
'1' || *s==
't' || *s==
'T' || *s==
'y' || *s==
'Y' ||
141 #define TPIPS_IS_A_SHELL "TPIPS_IS_A_SHELL"
164 #define JPIPS_TAG "#jpips:"
221 void jpips_string(
const char* a_message_format, va_list some_arguments)
223 vfprintf(
out_to_jpips, a_message_format, some_arguments);
231 va_list some_arguments;
232 va_start(some_arguments, format);
234 va_end(some_arguments);
292 "readline",
"create",
"close",
"delete",
"echo",
"module",
"activate",
295 "checkpoint",
"info",
"show",
"timeout",
"checkactive", (
char*) NULL
304 static int list_index, len;
313 len = strlen (texte);
321 if (strncmp (name, texte, len) == 0)
334 static char **names = NULL;
351 int module_list_length, i;
356 names = calloc(module_list_length + 1,
sizeof(
char *));
357 for(i = 0; i < module_list_length; i++)
369 static int list_index, len;
377 int number_of_sep = 0;
385 while (rl_line_buffer[current_pos])
391 while ((rl_line_buffer[current_pos]) &&
398 pips_debug (9,
"%d separator have been found on line\n\n",
407 pips_debug (9,
"text is '%s', function found is '%s'\n\n",
413 if (number_of_sep == 1)
418 pips_debug (9,
"completion type %d has been selected\n\n",
421 switch (completion_type)
427 #define RESERVED_FOR_FILENAME (char**) 0x01
452 len = strlen (texte);
458 return rl_filename_completion_function(texte,state);
465 if (strncmp (name, texte, len) == 0)
490 pips_debug (9,
"completing function (START = %d, END= %d)\n\n",
504 rl_readline_name =
"Tpips";
507 rl_basic_word_break_characters =
" \t\n\"\\@$><=;|&{(";
510 #if defined (_RL_FUNCTION_TYPEDEF)
511 rl_attempted_completion_function = (rl_completion_func_t *)
fun_completion;
513 rl_attempted_completion_function = (CPPFunction *)
fun_completion;
517 rl_completion_entry_function = (rl_compentry_func_t *)
param_generator;
520 rl_catch_signals = 0;
568 #define BEGIN_RQ "begin_user_request"
569 #define END_RQ "end_user_request"
575 va_copy(acpy, *args);
588 (void)
fprintf(stdout,
"\nWaiting for your response: ");
589 (void) vfprintf(stdout, fmt, acpy);
596 pips_debug(2,
"returning --%s--\n", response? response:
"<NULL>");
605 #define BEGIN_UE "begin_user_error"
606 #define END_UE "end_user_error"
612 const char * calling_function_name,
619 va_copy(acpy, *args);
644 _UNUSED_ const char * calling_function_name,
645 _UNUSED_ const char * a_message_format,
665 if (hist)
return strdup(hist);
668 home = getenv(
"HOME");
679 history_set_pos(history_length);
684 #define TP_HELP(prefix, simple, full) \
685 if (!*line || prefix_equal_p(line, prefix)) { \
686 printf(simple); if (*line) printf(full);}
693 TP_HELP(
"readline",
"* readline interaction facilities\n",
694 "\ttry <tab><tab> for automatic completion\n"
695 "\temacs-tyle editing capabilities (see man readline)\n");
696 TP_HELP(
"create",
"create <workspace-name> <file-name>...\n",
697 "\tcreate a new worspace from a list of fortran files\n"
698 "\tfirst delete the workspace if it exists\n");
699 TP_HELP(
"open",
"open <workspace-name>\n",
700 "\topen an existing workspace\n");
701 TP_HELP(
"checkactive",
"checkactive <resourcename>\n",
702 "\ttell which phase would produce this resource.\n");
703 TP_HELP(
"checkpoint",
"checkpoint\n",
704 "\tcheckpoint the current workspace\n");
706 "\tclose the current opened workspace\n");
707 TP_HELP(
"delete",
"delete <workspace-name>\n",
708 "\tdelete an existing workspace\n");
709 TP_HELP(
"module",
"module <module-name>\n",
710 "\tselect a module from an opened workspace\n");
711 TP_HELP(
"activate",
"activate <rule-name>\n",
712 "\ttell a rule to be active\n");
713 TP_HELP(
"make",
"make <resourcename([OWNER])>\n",
714 "\tbuild a resource\n"
716 "\t\t make PRINTED_FILE\n"
717 "\t\t make CALLGRAPH_FILE[my_module]\n"
718 "\t\t make DG_FILE[%%ALL]\n"
719 "\t\t make ICFG_FILE[%%CALLEES]\n\n");
720 TP_HELP(
"apply",
"apply <rulename[(OWNER)]>\n",
721 "\tmake the produced resources of a rule\n"
723 "\t\t apply PRINT_SOURCE_WITH_REGIONS\n"
724 "\t\t apply HPFC_CLOSE[my_module]\n"
725 "\t\t apply PRINT_CODE[%%ALL]\n"
726 "\t\t apply PRINT_ICFG[%%CALLEES]\n");
727 TP_HELP(
"capply",
"capply <rulename[(OWNER)]>\n",
728 "\tconcurrently apply a transformation rule\n"
730 "\t\t apply SUPPRESS_DEAD_CODE[%%ALL]\n"
731 "\t\t apply PARTIAL_EVAL[%%CALLEES]\n");
732 TP_HELP(
"display",
"display <fileresourcename([OWNER])>\n",
733 "\tprint a file resource\n"
735 "\t\t display PRINTED_FILE\n"
736 "\t\t display CALLGRAPH_FILE[my_module]\n"
737 "\t\t display DG_FILE[%%ALL]\n"
738 "\t\t display ICFG_FILE[%%CALLEES]\n\n");
739 TP_HELP(
"remove",
"remove <resourcename([OWNER])>\n",
740 "\tremove a resource from the database.\n");
741 TP_HELP(
"cd",
"cd <dirname>\n",
742 "\tchange directory\n");
743 TP_HELP(
"pwd",
"pwd\n",
"\tprint current working directory\n");
744 TP_HELP(
"setenv",
"setenv <name>=<value>\n",
745 "\tchange environment\n");
746 TP_HELP(
"unsetenv",
"unsetenv <name>\n",
747 "\tremove variable from environment\n");
748 TP_HELP(
"getenv",
"getenv <name>\n",
749 "\tprint from environment (echo ${<name>} also ok)\n");
750 TP_HELP(
"setproperty",
"setproperty <name>=<value>\n",
751 "\tchange property\n");
753 "\t print property\n");
754 TP_HELP(
"echo",
"echo <string>\n",
755 "\tprint the string\n");
757 "\texit tpips (you should close the workspace before\n");
759 "\texit tpips quickly (rhough!)\n");
760 TP_HELP(
"source",
"source <filenames...>\n",
761 "\tread tpips commands from files.\n");
762 TP_HELP(
"help",
"help (<help-item>)\n",
763 "\tprint a list of all the commands or a \"detailled\""
764 " description of one\n");
765 TP_HELP(
"show",
"show <resourcename([OWNER])>\n",
766 "\treturns the file of this resource\n");
767 TP_HELP(
"timeout",
"timeout <delay>\n",
768 "\tset pips timeout in seconds\n");
769 TP_HELP(
"info",
"info <name>\n",
770 "\tprint information about <name>\n"
771 "\tname: module, modules, workspace, directory\n");
772 TP_HELP(
"shell",
"shell [<shell-function>]\n",
773 "\tallow shell functions call\n");
774 TP_HELP(
"version",
"version\n",
775 "\tshow tpips version informations, such as:\n"
776 "\t\trepository revisions used by the compilation\n"
777 "\t\tdate of compilation\n"
778 "\t\tcompiler used\n");
779 TP_HELP(
"owner",
"- owner : variable*\n",
780 "\tList of available owners:\n"
787 "\t\t<module_name>\n");
788 TP_HELP(
"*",
"* default rule...\n",
789 "\tan implicit \"shell\" is assumed.\n");
793 printf(
"* rulename : variable*\n");
809 pips_debug (1,
"number of columns is %d\n", columns);
810 columns = (columns > 0) ? columns /big_size : 1;
812 printf(
"\tList of available rules\n");
816 printf(
"%-*s",big_size,*ps);
817 if ((
count % columns) == 0)
826 printf(
"* resourcename : variable*\n");
843 pips_debug (1,
"number of columns is %d\n", columns);
844 columns = (columns > 0) ? columns /big_size : 1;
846 printf(
"\tList of available resources\n");
850 printf(
"%-*s",big_size,*ps);
851 if ((
count % columns) == 0)
915 static char SHELL_CHARS[] =
"${`*?";
918 if (strchr(SHELL_CHARS, *
line))
952 "For instance, check location of your source files.\n",
959 pips_debug(2,
"after substitution: %s\n", substituted);
1053 free(sline), sline = (
char*) NULL;
1064 static bool readline_initialized =
false;
1083 readline_initialized =
true;
1117 "# logfile moved to %s by -%c tpips option\n", filename, opt);
1130 static struct option lopts[] = {
1131 {
"version", 0, NULL,
'v' },
1132 {
"jpips", 0, NULL,
'j' },
1133 {
"help", 0, NULL,
'h' },
1134 {
"shell", 0, NULL,
's' },
1135 {
"log", 1, NULL,
'l' },
1136 {
"rc", 1, NULL,
'r' },
1137 {
"xml", 1, NULL,
'x' },
1138 { NULL, 0, NULL, 0 }
1141 while ((c = getopt_long(argc, argv,
"ane:l:h?vscr:jwx:", lopts, &opt_ind))
1153 fprintf(stderr,
"tpips session logged in \"%s\"\n", filename);
1211 FILE * rc = fopen(tpipsrc,
"r");
1214 user_log(
"sourcing tpips rc file: %s\n", tpipsrc);
1219 free(tpipsrc), tpipsrc=NULL;
1225 bool use_rl = isatty(0);
1227 pips_debug(1,
"reading from stdin, which is%s a tty\n",
1228 use_rl ?
"" :
" not");
1236 string tps = NULL, saved_srcpath = NULL;
1237 FILE * toprocess = (FILE*) NULL;
1238 bool use_rl =
false;
1251 getenv(
"PIPS_SRCPATH"));
1258 free(dir), dir = NULL;
1260 if ((toprocess = fopen(tps,
"r"))==NULL)
1263 fprintf(stderr,
"[TPIPS] cannot open \"%s\"\n", tps);
1264 free(tps), tps=NULL;
1270 fprintf(stderr,
"[TPIPS] \"%s\" not found...\n",
1276 pips_debug(1,
"reading from file %s\n", tps);
1282 free(tps), tps = NULL;
1288 free(saved_srcpath), saved_srcpath = NULL;
1310 asprintf(&pid,
"PID=%d", (
int) getpid());
1324 #define CACHED_STRING_LIST(NAME) \
1325 bool NAME##_name_p(string name) \
1327 static hash_table cache = NULL; \
1330 cache = hash_table_make(hash_string, \
1331 2*sizeof(tp_##NAME##_names)/sizeof(char*)); \
1332 for (p=tp_##NAME##_names; *p; p++) \
1333 hash_put(cache, *p, (char*) 1); \
1336 return hash_get(cache, name)!=HASH_UNDEFINED_VALUE; \
void(* pips_internal_error_handler)(const char *, const char *,...)
PIPS_ERROR is a function that should be called to terminate PIPS execution when data structures are c...
void open_xml_logfile(const char *filename)
void user_log(const char *format,...)
bool properties_initialized_p(void)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
string(* pips_request_handler)(const char *, va_list *)
default assignment of pips_request_handler is default_user_request.
void(* pips_error_handler)(const char *, const char *, va_list *)
PROMPT_USER schould be implemented.
void set_pips_meta_informations(const char *revs, const char *date, const char *comp)
@ any_exception_error
catch all
linear_exception_t the_last_just_thrown_exception
void set_exception_callbacks(exception_callback_t, exception_callback_t)
size_t gen_array_nitems(const gen_array_t a)
void gen_array_full_free(gen_array_t a)
void * gen_array_item(const gen_array_t a, size_t i)
static char * tp_file_rsc_names[]
static char * tp_phase_names[]
static char * tp_resource_names[]
static char * tp_property_names[]
bool close_workspace(bool is_quit)
void push_pips_context(char const *file, char const *function, int line)
exception.c
void pop_pips_context(char const *file, char const *function, int line)
FILE * safe_fopen(const char *filename, const char *what)
bool file_exists_p(const char *name)
char * find_file_in_directories(const char *file_name, const char *dir_path)
returns an allocated string pointing to the file, possibly with an additional path taken from colon-s...
int safe_fclose(FILE *stream, const char *filename)
some path to file suffix some path to *char * pips_dirname(char *fullpath)
char * safe_new_tmp_file(char *prefix)
SunOS forgets to declare this one.
char * safe_readline(FILE *file)
returns the allocated line read, whatever its length.
char * safe_system_substitute(char *what)
returns what after variable, command and file substitutions.
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void set_script_directory_name(string dn)
static int current_size
returns the number of bytes allocated for a given structure may need additional fonctions for externa...
static char start[1024]
The name of the variable from which to start counting domain numbers.
gen_array_t db_get_module_list(void)
Get an array of all the modules (functions, procedures and compilation units) of a workspace.
void pips_checks(void)
add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :)
char *(* variable_debug_name)(Variable)
Debug support: pointer to the function used by debug print outs.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define STRINGIFY(symbol)
If not using this 2-stage macro evaluation, the generated string is not the value of the macro but th...
void set_debug_stack_pointer(const int i)
_int get_debug_stack_pointer(void)
The pair get_ and set_debug_stack_pointer() should never be used except to clean up the stack after a...
void initialize_newgen()
cproto-generated files
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define same_string_p(s1, s2)
bool db_close_workspace(bool)
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
void initialize_signal_catcher(void)
string pips_srcpath_append(string)
returns an allocated pointer to the old value
void pips_srcpath_set(string)
Set the PIPS source path.
void set_bool_property(const char *, bool)
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
void initialize_sc(char *(*var_to_string)(Variable))
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static int line
FLEX_SCANNER.
static hash_table matches
int first_completion_type
int other_completion_type
#define ECHO_N
macro ECHO is reserved by flex
#define TPIPS_HISTORY_LENGTH
#define TPIPS_SECONDARY_PROMPT
#define TPIPS_REQUEST_PROMPT
#define TPIPS_COMMENT_PREFIX
#define TPIPS_CONTINUATION_CHAR
#define TPIPS_PRIMARY_PROMPT
static void initialize_readline(void)
Tell the GNU Readline library how to complete.
static void tpips_exec(char *line)
static void close_workspace_if_opened(bool is_quit)
void tpips_process_a_file(FILE *file, string name, bool use_rl)
processing command line per line.
#define tpips_usage
tp_lex.c
static FILE * in_from_jpips
Ronan suggested a signal driven handling of jpips requests, so as to let the prompt available for dir...
bool tpips_init_done
variable globale, utilisee par le parser helas
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
int tpips_current_line(void)
static void parse_arguments(int argc, char *argv[])
static char * fun_generator(const char *texte, int state)
Generator function for command completion.
static char ** fun_completion(char *texte, int start, int end)
Attempt to complete on the contents of TEXT.
static bool tpips_is_a_shell
void tpips_help(string line)
static bool prefix_equal_p(string str, string prf)
static FILE * current_file
current file being processed, with its name and the line number
bool tpips_behaves_like_a_shell(void)
void tpips_next_line(void)
bool consistency_enforced_p
Pipsmake does not enforce consistency when properties are changed.
static string tp_substitutions(string line)
returns an allocated string after shell substitutions.
static char * tp_help_topics[]
static char * tpips_read_a_line(char *main_prompt)
returns an allocated line read, including continuations.
static char ** current_completion_array
#define CACHED_STRING_LIST(NAME)
int tpips_main(int argc, char *argv[])
MAIN: interactive loop and history management.
#define BEGIN_RQ
Tpips user request.
void jpips_string(const char *a_message_format, va_list some_arguments)
void tpips_set_line_to_parse(char *)
in lex file
string tpips_current_name(void)
void jpips_add_tag(string s)
static string tpips_user_request(const char *fmt, va_list *args)
static bool string_is_true(string s)
char * tpips_get_line_to_parse(void)
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.
static string default_hist_file_name(void)
returns the allocated full tpips history file name, i.e.
#define TP_HELP(prefix, simple, full)
Handlers.
void jpips_tag2(string s1, string s2)
void jpips_begin_tag(string s)
void jpips_printf(const string format,...)
static bool blank_or_comment_line_p(string line)
bool tpips_is_interactive
const char * soft_revisions
could be shared somewhere?
int tpips_current_line_number()
static FILE * out_to_jpips
#define TPIPS_IS_A_SHELL
Whether pips should behave as a shell.
#define JPIPS_TAG
jpips specials.
static struct t_completion_scheme completion_scheme[]
static string default_tpipsrc(void)
default .tpipsrc is $HOME/.tpipsrc.
static char * param_generator(const char *texte, int state)
Generator function for param.
string tpips_current_file_name()
static string current_name
static void initialize_tpips_history(void)
FILE * jpips_out_file(void)
#define RESERVED_FOR_FILENAME
bool tpips_execution_mode
Sometimes, already included by unistd.h.
static bool line_with_substitutions(string line)
whether some substitutions are needed...
static char * get_next_line(char *prompt)
returns the next line from the input, interactive tty or file...
char ** get_module_names(void)
Build an array with the names of all available modules.
static void open_logfile(string filename, char opt)
static void handle(string line)
void tpips_wrapper(void)
wrapper.c
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....