| 330 | */ |
| 331 | |
| 332 | static int |
| 333 | InteractiveBackend(StringInfo inBuf) |
| 334 | { |
| 335 | int c; /* character read from getc() */ |
| 336 | |
| 337 | /* |
| 338 | * display a prompt and obtain input from the user |
| 339 | */ |
| 340 | printf("backend> "); |
| 341 | fflush(stdout); |
| 342 | |
| 343 | resetStringInfo(inBuf); |
| 344 | |
| 345 | /* |
| 346 | * Read characters until EOF or the appropriate delimiter is seen. |
| 347 | */ |
| 348 | while ((c = interactive_getc()) != EOF) |
| 349 | { |
| 350 | if (c == '\n') |
| 351 | { |
| 352 | if (UseSemiNewlineNewline) |
| 353 | { |
| 354 | /* |
| 355 | * In -j mode, semicolon followed by two newlines ends the |
| 356 | * command; otherwise treat newline as regular character. |
| 357 | */ |
| 358 | if (inBuf->len > 1 && |
| 359 | inBuf->data[inBuf->len - 1] == '\n' && |
| 360 | inBuf->data[inBuf->len - 2] == ';') |
| 361 | { |
| 362 | /* might as well drop the second newline */ |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | /* |
| 369 | * In plain mode, newline ends the command unless preceded by |
| 370 | * backslash. |
| 371 | */ |
| 372 | if (inBuf->len > 0 && |
| 373 | inBuf->data[inBuf->len - 1] == '\\') |
| 374 | { |
| 375 | /* discard backslash from inBuf */ |
| 376 | inBuf->data[--inBuf->len] = '\0'; |
| 377 | /* discard newline too */ |
| 378 | continue; |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | /* keep the newline character, but end the command */ |
| 383 | appendStringInfoChar(inBuf, '\n'); |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /* Not newline, or newline treated as regular character */ |
no test coverage detected