** Read input from *in and process it. If *in==0 then input ** is interactive - the user is typing it it. Otherwise, input ** is coming from a file or device. A prompt is issued and history ** is saved only if input is interactive. An interrupt signal will ** cause this routine to exit immediately, unless input is interactive. ** ** Return the number of errors. */
| 1490 | ** Return the number of errors. |
| 1491 | */ |
| 1492 | static int process_input(struct callback_data *p, FILE *in){ |
| 1493 | char *zLine = 0; |
| 1494 | char *zSql = 0; |
| 1495 | int nSql = 0; |
| 1496 | int nSqlPrior = 0; |
| 1497 | char *zErrMsg; |
| 1498 | int rc; |
| 1499 | int errCnt = 0; |
| 1500 | int lineno = 0; |
| 1501 | int startline = 0; |
| 1502 | |
| 1503 | while( errCnt==0 || !bail_on_error || (in==0 && stdin_is_interactive) ){ |
| 1504 | //fflush(p->out); |
| 1505 | free(zLine); |
| 1506 | zLine = one_input_line(in); |
| 1507 | if( zLine==0 ){ |
| 1508 | break; /* We have reached EOF */ |
| 1509 | } |
| 1510 | if( seenInterrupt ){ |
| 1511 | if( in!=0 ) break; |
| 1512 | seenInterrupt = 0; |
| 1513 | } |
| 1514 | lineno++; |
| 1515 | if( (zSql==0 || zSql[0]==0) && _all_whitespace(zLine) ) continue; |
| 1516 | if( zLine && zLine[0]=='.' && nSql==0 ){ |
| 1517 | continue; |
| 1518 | } |
| 1519 | if( _is_command_terminator(zLine) && _is_complete(zSql, nSql) ){ |
| 1520 | memcpy(zLine,";",2); |
| 1521 | } |
| 1522 | nSqlPrior = nSql; |
| 1523 | if( zSql==0 ){ |
| 1524 | int i; |
| 1525 | for(i=0; zLine[i] && isspace((unsigned char)zLine[i]); i++){} |
| 1526 | if( zLine[i]!=0 ){ |
| 1527 | nSql = strlen30(zLine); |
| 1528 | zSql = (char*)malloc( nSql+3 ); |
| 1529 | if( zSql==0 ){ |
| 1530 | fprintf(stderr, "Error: out of memory\n"); |
| 1531 | exit(1); |
| 1532 | } |
| 1533 | memcpy(zSql, zLine, nSql+1); |
| 1534 | startline = lineno; |
| 1535 | } |
| 1536 | }else{ |
| 1537 | int len = strlen30(zLine); |
| 1538 | zSql = (char*)realloc( zSql, nSql + len + 4 ); |
| 1539 | if( zSql==0 ){ |
| 1540 | fprintf(stderr,"Error: out of memory\n"); |
| 1541 | exit(1); |
| 1542 | } |
| 1543 | zSql[nSql++] = '\n'; |
| 1544 | memcpy(&zSql[nSql], zLine, len+1); |
| 1545 | nSql += len; |
| 1546 | } |
| 1547 | if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior) |
| 1548 | && sqlite3_complete(zSql) ){ |
| 1549 | p->cnt = 0; |
no test coverage detected