- char const * line;
- char prompt[G__ONELINE];
- std::string linebuffer;
-
- bool quit = false;
- bool eof = false;
- bool next_command_is_function = false;
- bool single_quote = false;
- bool double_quote = false;
- bool comment = false;
- unsigned open_braces = 0;
-
- while ((!quit)&&(!eof)) {
- strcpy(prompt,PROMPT1);
- bool end_of_command = false;
- std::string command;
- std::string preprocessed;
- while (!end_of_command) {
- if (is==NULL) {
- line = G__input(prompt);
- } else {
- getline(*is,linebuffer);
- line = linebuffer.c_str();
- }
- command += line;
- 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,PROMPT2);
- }
- if ((preprocessed=="quit;")||
- (preprocessed=="exit;")||
- (preprocessed=="bye;")||
- (is_command(command,preprocessed,"quit"))||
- (is_command(command,preprocessed,"exit"))||
- (is_command(command,preprocessed,"bye"))||
- (is_command(command,preprocessed,"q"))) {
- quit = true;
- } else if (is_command(command,preprocessed,"function")) {
- if (!silent)
- std::cout << "next expression can be a function definition" << std::endl;
- next_command_is_function = true;
- } else if (is_command(command,preprocessed,"cint")) {
- std::cout << std::endl << "switching to cint interactive mode" << std::endl;
- std::cout << "'h' for help, 'q' to quit, '{ statements }' or 'p [expression]' to evaluate" << std::endl;
- G__pause();
- std::cout << "back from cint" << std::endl;
- } else if (is_command(command,preprocessed,"help")) {
- helpmessage();
- } else if (is_command(command,preprocessed,"read",true)) {
- quit = readfile(preprocessed.substr(5),allcommands);
- } else if (is_command(command,preprocessed,"save",true)) {
- command = "/* "+command+" */"; // we do not want the .save command itself in saved files
- savefile(preprocessed.substr(5),allcommands);
- } else if (is_command(command,preprocessed,"restart")) {
- restart();
- } else if (is_command(command,preprocessed,"redirect",true)) {
- redirect(preprocessed.substr(9));
- } else if (is_command(command,preprocessed,">",true)) {
- redirect(preprocessed.substr(2));
- } else if (is_command(command,preprocessed,"silent")) {
- if (!silent) {
- redirect("/dev/null");
- silent = true;
- } else {
- redirect("");
- silent = false;
- }
- } else if (is_command(command,preprocessed,"warranty")) {
- warrantymessage();
- /* test for more special commands
- } else if (preprocessed==".xyz") {
- std::cout << "special command (TBD): " << command << std::endl;
- */
- } else if (command.substr(0,2)=="#!") {
- // ignore lines which indicate that this file is executed as a script
- } else {
- // std::cout << "now processing: " << command << std::endl;
- if (next_command_is_function) {
- next_command_is_function = false;
- filenames.push_back(process_permanentfile(command));
- } else {
- process_tempfile(command);
- }
- }
- if (is!=NULL) {
- // test for end of file if reading from a stream
- eof = is->eof();
- } else {
- // save commands only when reading from keyboard
- allcommands += command;
- }
-
- }
- return quit;
-}
+ char const * line;
+ char prompt[G__ONELINE];
+ std::string linebuffer;
+
+ bool quit = false;
+ bool eof = false;
+ bool next_command_is_function = false;
+ bool single_quote = false;
+ bool double_quote = false;
+ bool comment = false;
+ unsigned open_braces = 0;
+
+ while ((!quit)&&(!eof)) {
+ strcpy(prompt,PROMPT1);
+ bool end_of_command = false;
+ std::string command;
+ std::string preprocessed;
+ while (!end_of_command) {
+ if (is==NULL) {
+ line = G__input(prompt);
+ } else {
+ getline(*is,linebuffer);
+ line = linebuffer.c_str();
+ }
+ command += line;
+ 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,PROMPT2);
+ }
+ if ((preprocessed=="quit;")||
+ (preprocessed=="exit;")||
+ (preprocessed=="bye;")||
+ (is_command(command,preprocessed,"quit"))||
+ (is_command(command,preprocessed,"exit"))||
+ (is_command(command,preprocessed,"bye"))||
+ (is_command(command,preprocessed,"q"))) {
+ quit = true;
+ } else if (is_command(command,preprocessed,"function")) {
+ if (!silent)
+ std::cout << "next expression can be a function definition" << std::endl;
+ next_command_is_function = true;
+ } else if (is_command(command,preprocessed,"cint")) {
+ std::cout << std::endl << "switching to cint interactive mode" << std::endl;
+ std::cout << "'h' for help, 'q' to quit, '{ statements }' or 'p [expression]' to evaluate" << std::endl;
+ G__pause();
+ std::cout << "back from cint" << std::endl;
+ } else if (is_command(command,preprocessed,"help")) {
+ helpmessage();
+ } else if (is_command(command,preprocessed,"read",true)) {
+ quit = readfile(preprocessed.substr(5),allcommands);
+ } else if (is_command(command,preprocessed,"save",true)) {
+ command = "/* "+command+" */"; // we do not want the .save command itself in saved files
+ savefile(preprocessed.substr(5),allcommands);
+ } else if (is_command(command,preprocessed,"restart")) {
+ restart();
+ } else if (is_command(command,preprocessed,"redirect",true)) {
+ redirect(preprocessed.substr(9));
+ } else if (is_command(command,preprocessed,">",true)) {
+ redirect(preprocessed.substr(2));
+ } else if (is_command(command,preprocessed,"silent")) {
+ if (!silent) {
+ redirect("/dev/null");
+ silent = true;
+ } else {
+ redirect("");
+ silent = false;
+ }
+ } else if (is_command(command,preprocessed,"warranty")) {
+ warrantymessage();
+ /* insert tests for more special commands here */
+ } else if (command.substr(0,2)=="#!") {
+ // ignore lines which indicate that this file is executed as a script
+ } else {
+ // std::cout << "now processing: " << command << std::endl;
+ if (next_command_is_function) {
+ next_command_is_function = false;
+ filenames.push_back(process_permanentfile(command));
+ } else {
+ process_tempfile(command);
+ }
+ }
+ if (is!=NULL) {
+ // test for end of file if reading from a stream
+ eof = is->eof();
+ } else {
+ // save commands only when reading from keyboard
+ allcommands += command;
+ }
+
+ }
+ return quit;
+}