| 165 | |
| 166 | |
| 167 | static void *commandLineFunc(void *arg) |
| 168 | { |
| 169 | const char *prompt = "OpenBTS> "; //gConfig.getStr("CLI.Prompt"); CLI.Prompt no longer defined. |
| 170 | try { |
| 171 | #ifdef HAVE_READLINE |
| 172 | using_history(); |
| 173 | while (true) { |
| 174 | clearerr(stdin); // Control-D may set the eof bit which causes getline to return immediately. Fix it. |
| 175 | char *inbuf = readline(prompt); |
| 176 | if (inbuf) { |
| 177 | if (*inbuf) { |
| 178 | add_history(inbuf); |
| 179 | // The parser returns -1 on exit. |
| 180 | if (gParser.process(inbuf, cout, cin)<0) { |
| 181 | free(inbuf); |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | free(inbuf); |
| 186 | } else { |
| 187 | printf("EOF ignored\n"); |
| 188 | } |
| 189 | sleep(1); // in case something goofs up here, dont steal all the cpu cycles. |
| 190 | } |
| 191 | #else |
| 192 | while (true) { |
| 193 | //cout << endl << |
| 194 | cout << endl << prompt; |
| 195 | cout.flush(); |
| 196 | char inbuf[1024]; |
| 197 | cin.clear(); // Control-D may set the eof bit which causes getline to return immediately. Fix it. |
| 198 | cin.getline(inbuf,1024,'\n'); // istream::getline |
| 199 | if (!cin.fail()) { |
| 200 | // The parser returns -1 on exit. |
| 201 | if (gParser.process(inbuf,cout)<0) break; |
| 202 | } |
| 203 | sleep(1); // in case something goofs up here, dont steal all the cpu cycles. |
| 204 | } |
| 205 | #endif |
| 206 | } catch (ConfigurationTableKeyNotFound e) { |
| 207 | LOG(EMERG) << "required configuration parameter " << e.key() << " not defined, aborting"; |
| 208 | gReports.incr("OpenBTS.Exit.Error.ConfigurationParamterNotFound"); |
| 209 | } |
| 210 | |
| 211 | exit(0); // Exit OpenBTS |
| 212 | return NULL; |
| 213 | } |
| 214 | |
| 215 | void Parser::startCommandLine() // (pat) Start a simple command line processor as a separate thread. |
| 216 | { |