X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=cint%2Fginaccint.bin.cpp;h=38d3daee07949c848bf46c780c2a1340bf8d881d;hp=4c134b4e7a81dcfc7eb28f48ffe96f78e7b1313f;hb=06a2f420f295976355884d8eb2de5ae79f90c1bc;hpb=63187020f00915a25f7b2831cf25f66ca38c4999 diff --git a/cint/ginaccint.bin.cpp b/cint/ginaccint.bin.cpp index 4c134b4e..38d3daee 100644 --- a/cint/ginaccint.bin.cpp +++ b/cint/ginaccint.bin.cpp @@ -11,6 +11,8 @@ extern "C" G__value G__exec_tempfile G__P((char *file)); extern "C" void G__store_undo_position(void); +#define PROMPT "GiNaC> " + #ifdef OBSCURE_CINT_HACK #include @@ -56,14 +58,16 @@ char first_non_whitespace_char(char const * s) { int l = strlen(s); int pos = 0; - while ((pos=0) && is_whitespace_char(s[pos])) pos--; + while ((pos>=0) && is_whitespace_char(s[pos])) + pos--; return s[pos]; } @@ -86,7 +90,7 @@ G__value exec_tempfile(string const & command) fout << "{" << endl << command << endl << "}" << endl; fout.close(); G__store_undo_position(); - retval=G__exec_tempfile(tmpfilename); + retval = G__exec_tempfile(tmpfilename); G__security_recover(stdout); remove(tmpfilename); free(tmpfilename); @@ -111,9 +115,12 @@ void process_tempfile(string const & command) { #ifdef OBSCURE_CINT_HACK static G__value ref_symbol = exec_tempfile("symbol ginac_cint_internal_symbol; ginac_cint_internal_symbol;"); - static G__value ref_ex = exec_tempfile("ex ginac_cint_internal_ex; ginac_cint_internal_ex;"); + static G__value ref_constant = exec_tempfile("constant ginac_cint_internal_constant; ginac_cint_internal_constant;"); static G__value ref_function = exec_tempfile("sin(ginac_cint_internal_symbol);"); - static G__value ref_power = exec_tempfile("power(ginac_cint_internal_symbol,ginac_cint_internal_symbol);"); + static G__value ref_power = exec_tempfile("power(ex(ginac_cint_internal_symbol),ex(ginac_cint_internal_symbol));"); + static G__value ref_numeric = exec_tempfile("numeric ginac_cint_internal_numeric; ginac_cint_internal_numeric;"); + static G__value ref_ex = exec_tempfile("ex ginac_cint_internal_ex; ginac_cint_internal_ex;"); + static bool basic_type_warning_already_displayed=false; #endif // def OBSCURE_CINT_HACK G__value retval = exec_tempfile(command); @@ -144,6 +151,24 @@ void process_tempfile(string const & command) +"LLAST=LAST;\n" +"LAST="+varname+";\n" +"cout << \""+varname+" = \" << "+varname+" << endl << endl;"); + } else if (TYPES_EQUAL(retval,ref_symbol)|| + TYPES_EQUAL(retval,ref_constant)|| + TYPES_EQUAL(retval,ref_function)|| + TYPES_EQUAL(retval,ref_power)|| + TYPES_EQUAL(retval,ref_numeric)) { + if (!basic_type_warning_already_displayed) { + cout << endl + <<"WARNING: The return value of the last expression you entered was a symbol," << endl + << "constant, function, power or numeric, which cannot be safely displayed." << endl + << "To force the output, cast it explicitly to type 'ex' or use 'cout'," << endl + << "for example (assume 'x' is a symbol):" << endl + << PROMPT "ex(x);" << endl + << "OutX = x" << endl << endl + << PROMPT "cout << x << endl;" << endl + << "x" << endl << endl + << "This warning will not be shown again." << endl; + basic_type_warning_already_displayed=true; + } } #endif // def OBSCURE_CINT_HACK } @@ -156,7 +181,8 @@ void greeting(void) << " __, _______ requested, at this moment, for commercial use. Send e-mail to" << endl << " (__) * | . The registration is free." << endl << " ._) i N a C | The GiNaC framework is Copyright by Johannes Gutenberg Univ.," << endl - << "<-------------' Germany and licensed under the terms and conditions of the GPL." << endl << endl; + << "<-------------' Germany and licensed under the terms and conditions of the GPL." << endl + << endl; } int main(void) @@ -164,29 +190,32 @@ int main(void) char *line; char prompt[G__ONELINE]; - greeting(); + if (isatty(0)) + greeting(); atexit(cleanup); signal(SIGTERM,sigterm_handler); G__init_cint("cint"); /* initialize cint */ - exec_tempfile("#include \n"); + // no longer needed as of cint 5.14.31 + // exec_tempfile("#include \n"); + exec_tempfile("ex LAST,LLAST,LLLAST;\n"); bool quit = false; bool next_command_is_function=false; while (!quit) { - strcpy(prompt,"GiNaC> "); + strcpy(prompt,PROMPT); int open_braces = 0; - bool end_of_command=false; + bool end_of_command = false; string command; while (!end_of_command) { line = G__input(prompt); - + int pos = 0; - bool double_quote=false; - bool single_quote=false; + bool double_quote = false; + bool single_quote = false; while(line[pos]!='\0') { switch(line[pos]) { case '"':