X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=cint%2Fginaccint.bin.cpp;h=9c4cd8d3ee5311bd7b97fcdb86940b7fbd1b20c9;hp=23cb38bd3b502802ad0d1aa69e6dccae2970ff91;hb=65dd17f1d3b192b7fbe773250702ad191c4019f8;hpb=736fa98c85ffb3632e7a910cce34e3e1cc2a3b4b diff --git a/cint/ginaccint.bin.cpp b/cint/ginaccint.bin.cpp index 23cb38bd..9c4cd8d3 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 @@ -47,38 +49,6 @@ void sigterm_handler(int n) exit(1); } -bool is_whitespace_char(char c) -{ - return ((c==' ') || (c=='\t') || (c=='\n') || (c=='\r')); -} - -char first_non_whitespace_char(char const * s) -{ - int l = strlen(s); - int pos = 0; - while ((pos=0) && is_whitespace_char(s[pos])) - pos--; - return s[pos]; -} - -string strip_whitespace(string const & s) -{ - string s2; - int l = s.length(); - for (int pos=0; pos0)) { + open_braces--; + } + break; + case '/': + slash=true; + break; + case '*': + asterisk=true; + break; + default: + preprocessed += line[pos]; + } + } + pos++; + } + + /* + cout << "preprocessed=" << preprocessed << endl; + cout << "comment=" << comment << ", single_quote=" << single_quote + << ",double_quote=" << double_quote << ", open_braces=" << open_braces + << endl; + */ + + return preprocessed; +} + int main(void) { char *line; @@ -175,70 +267,60 @@ int main(void) 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; + bool next_command_is_function=false; + bool single_quote=false; + bool double_quote=false; + bool comment=false; + unsigned open_braces=0; + while (!quit) { - strcpy(prompt,"GiNaC> "); - int open_braces = 0; + strcpy(prompt,PROMPT); bool end_of_command = false; string command; + string preprocessed; while (!end_of_command) { line = G__input(prompt); - - int pos = 0; - bool double_quote = false; - bool single_quote = false; - while(line[pos]!='\0') { - switch(line[pos]) { - case '"': - if (!single_quote) double_quote = !double_quote; - break; - case '\'': - if (!double_quote) single_quote = !single_quote; - break; - case '{': - if ((!single_quote) && (!double_quote)) open_braces++; - break; - case '}': - if ((!single_quote) && (!double_quote)) open_braces--; - break; - } - pos++; - } command += line; - command += '\n'; - if (open_braces==0) { - if ((first_non_whitespace_char(command.c_str())=='#')|| - (first_non_whitespace_char(command.c_str())=='.')|| - (last_non_whitespace_char(command.c_str())==';')|| - (last_non_whitespace_char(command.c_str())=='}')) { + command += "\n"; + preprocessed += preprocess(line,comment,single_quote,double_quote,open_braces); + if ((open_braces==0)&&(!single_quote)&&(!double_quote)&&(!comment)) { + unsigned l=preprocessed.length(); + if ((l==0)|| + (preprocessed[0]=='#')|| + (preprocessed[0]=='.')|| + (preprocessed[l-1]==';')|| + (preprocessed[l-1]=='}')) { end_of_command=true; } } strcpy(prompt," > "); } - string stripped_command=strip_whitespace(command); - if ((stripped_command=="quit;")|| - (stripped_command=="exit;")|| - (stripped_command=="bye;")|| - (stripped_command==".q")|| - (stripped_command==".quit")|| - (stripped_command==".exit")|| - (stripped_command==".bye")) { + if ((preprocessed=="quit;")|| + (preprocessed=="exit;")|| + (preprocessed=="bye;")|| + (preprocessed==".q")|| + (preprocessed==".quit")|| + (preprocessed==".exit")|| + (preprocessed==".bye")) { quit = true; - } else if (stripped_command==".function") { + } else if (preprocessed==".function") { cout << "next expression can be a function definition" << endl; next_command_is_function=true; - } else if (stripped_command==".cint") { + } else if (preprocessed==".cint") { cout << endl << "switching to cint interactive mode" << endl; cout << "'h' for help, 'q' to quit, '{ statements }' or 'p [expression]' to evaluate" << endl; G__pause(); cout << "back from cint" << endl; - } else if (command[0]=='.') { + /* test for more special commands + } else if (preprocessed==".xyz") { cout << "special command (TBD): " << command << endl; + */ } else { // cout << "now processing: " << command << endl; if (next_command_is_function) {