3
3
*
4
4
* Copyright 2000 by PostgreSQL Global Development Team
5
5
*
6
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.7 2000/01/20 21:51:09 petere Exp $
6
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.8 2000/01/21 04: 21:12 tgl Exp $
7
7
*/
8
8
#include <c.h>
9
9
#include "copy.h"
@@ -318,7 +318,7 @@ do_copy(const char *args)
318
318
319
319
320
320
/*
321
- * handeCopyOut
321
+ * handleCopyOut
322
322
* receives data as a result of a COPY ... TO stdout command
323
323
*
324
324
* If you want to use COPY TO in your application, this is the code to steal :)
@@ -367,7 +367,7 @@ handleCopyOut(PGconn *conn, FILE *copystream)
367
367
368
368
369
369
/*
370
- * handeCopyOut
370
+ * handleCopyIn
371
371
* receives data as a result of a COPY ... FROM stdin command
372
372
*
373
373
* Again, if you want to use COPY FROM in your application, copy this.
@@ -387,22 +387,28 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
387
387
bool linedone ;
388
388
char copybuf [COPYBUFSIZ ];
389
389
char * s ;
390
- int buflen ;
390
+ int bufleft ;
391
391
int c = 0 ;
392
392
393
+ if (prompt ) /* disable prompt if not interactive */
394
+ {
395
+ if (! isatty (fileno (copystream )))
396
+ prompt = NULL ;
397
+ }
398
+
393
399
while (!copydone )
394
400
{ /* for each input line ... */
395
- if (prompt && isatty ( fileno ( copystream )) )
401
+ if (prompt )
396
402
{
397
403
fputs (prompt , stdout );
398
404
fflush (stdout );
399
405
}
400
406
firstload = true;
401
407
linedone = false;
402
408
while (!linedone )
403
- { /* for each buffer ... */
409
+ { /* for each bufferload in line ... */
404
410
s = copybuf ;
405
- for (buflen = COPYBUFSIZ ; buflen > 1 ; buflen -- )
411
+ for (bufleft = COPYBUFSIZ - 1 ; bufleft > 0 ; bufleft -- )
406
412
{
407
413
c = getc (copystream );
408
414
if (c == '\n' || c == EOF )
@@ -413,7 +419,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
413
419
* s ++ = c ;
414
420
}
415
421
* s = '\0' ;
416
- if (c == EOF )
422
+ if (c == EOF && s == copybuf && firstload )
417
423
{
418
424
PQputline (conn , "\\." );
419
425
copydone = true;
@@ -423,10 +429,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, const char *prompt)
423
429
if (firstload )
424
430
{
425
431
if (!strcmp (copybuf , "\\." ))
426
- {
432
+ {
427
433
copydone = true;
428
- break ;
429
- }
434
+ break ;
435
+ }
430
436
firstload = false;
431
437
}
432
438
}
0 commit comments