diff -rc cvs/pgsql/src/bin/psql/psql.c cvswork/pgsql/src/bin/psql/psql.c *** cvs/pgsql/src/bin/psql/psql.c Mon Dec 14 07:02:28 1998 --- cvswork/pgsql/src/bin/psql/psql.c Thu Dec 31 19:42:20 1998 *************** *** 203,208 **** --- 203,209 ---- fprintf(stderr, "\t -T html set html3.0 table command options (cf. -H)\n"); fprintf(stderr, "\t -u ask for a username and password for authentication\n"); fprintf(stderr, "\t -x turn on expanded output (field names on left)\n"); + fprintf(stderr, "\t -X turn on XML output\n"); exit(1); } *************** *** 281,286 **** --- 282,288 ---- fprintf(fout, " \\t -- toggle table headings and row count (currently %s)\n", on(pset->opt.header)); fprintf(fout, " \\T [] -- set html3.0 options (currently '%s')\n", pset->opt.tableOpt ? pset->opt.tableOpt : ""); fprintf(fout, " \\x -- toggle expanded output (currently %s)\n", on(pset->opt.expanded)); + fprintf(fout, " \\X -- toggle XML output (currently %s)\n", on(pset->opt.html3)); fprintf(fout, " \\w -- output current buffer to a file\n"); fprintf(fout, " \\z -- list current grant/revoke permissions\n"); fprintf(fout, " \\! [] -- shell escape or command\n"); *************** *** 2224,2229 **** --- 2226,2239 ---- pset->opt.standard = 0; break; + case 'X': + { + char x = pset->opt.html3; + pset->opt.html3 = 'X'; + if (x == 'X') + pset->opt.html3 = pset->opt.standard = 0; + } + break; case 'l': /* \l is list database */ listAllDbs(pset); break; *************** *** 2775,2781 **** has_client_encoding = getenv("PGCLIENTENCODING"); #endif ! while ((c = getopt(argc, argv, "Aa:c:d:ef:F:lh:Hnso:p:qStT:ux")) != EOF) { switch (c) { --- 2785,2791 ---- has_client_encoding = getenv("PGCLIENTENCODING"); #endif ! while ((c = getopt(argc, argv, "Aa:c:d:ef:F:lh:Hnso:p:qStT:ux:X")) != EOF) { switch (c) { *************** *** 2812,2817 **** --- 2822,2830 ---- break; case 'H': settings.opt.html3 = 1; + break; + case 'X': + settings.opt.html3 = 'X'; break; case 'n': settings.useReadline = 0; diff -rc cvs/pgsql/src/interfaces/libpq/fe-print.c cvswork/pgsql/src/interfaces/libpq/fe-print.c *** cvs/pgsql/src/interfaces/libpq/fe-print.c Wed Oct 7 07:04:20 1998 --- cvswork/pgsql/src/interfaces/libpq/fe-print.c Thu Dec 31 21:38:26 1998 *************** *** 58,69 **** const int nFields, char **fieldNames, unsigned char *fieldNotNum, int *fieldMax, const int fieldMaxLen, FILE *fout); ! static char *do_header(FILE *fout, PQprintOpt *po, const int nFields, ! int *fieldMax, char **fieldNames, unsigned char *fieldNotNum, ! const int fs_len, PGresult *res); ! static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields, ! unsigned char *fieldNotNum, int *fieldMax, char *border, ! const int row_index); static void fill(int length, int max, char filler, FILE *fp); --- 58,84 ---- const int nFields, char **fieldNames, unsigned char *fieldNotNum, int *fieldMax, const int fieldMaxLen, FILE *fout); ! ! static ! char *do_header(FILE *fout, PQprintOpt *po, const int nFields, ! int *fieldMax, char **fieldNames, unsigned char *fieldNotNum, ! const int fs_len, PGresult *res); ! static ! void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields, ! unsigned char *fieldNotNum, int *fieldMax, char *border, ! const int row_index); ! ! static ! void do_header_xml(FILE *fout, PQprintOpt *po, const int nFields, ! int *fieldMax, char **fieldNames, ! unsigned char *fieldNotNum, ! const int fs_len, PGresult *res); ! static ! void output_row_xml(FILE *fout, PQprintOpt *po, const int nFields, ! char **fields, ! char **fieldNames, int *fieldMax, char *border, ! const int row_index); ! static void fill(int length, int max, char filler, FILE *fp); *************** *** 235,256 **** fputc('\n', fout); } } ! if (po->expanded && po->html3) { if (po->caption) ! fprintf(fout, "

%s

\n", po->caption); else fprintf(fout, ! "

" "Query retrieved %d rows * %d fields" ! "

\n", nTups, nFields); } for (i = 0; i < nTups; i++) { if (po->expanded) { ! if (po->html3) fprintf(fout, "
\n", po->tableOpt ? po->tableOpt : "", i); --- 250,275 ---- fputc('\n', fout); } } ! if (po->expanded && po->html3 == 1) { if (po->caption) ! fprintf(fout, "

%s

\n", po->caption); else fprintf(fout, ! "

" "Query retrieved %d rows * %d fields" ! "

\n", nTups, nFields); } for (i = 0; i < nTups; i++) { if (po->expanded) { ! if (po->html3 == 'X') ! fprintf(fout, ! "
%d
\n", ! po->tableOpt ? po->tableOpt : "", i); ! else if (po->html3) fprintf(fout, "
%d
\n", po->tableOpt ? po->tableOpt : "", i); *************** *** 266,272 **** } if (!po->expanded && (po->align || po->html3)) { ! if (po->html3) { if (po->header) { --- 285,306 ---- } if (!po->expanded && (po->align || po->html3)) { ! if (po->html3 == 'X') ! { ! fprintf(fout, "\n", ! "ISO-8859-1"); ! fprintf(fout, "\n", ! "pgsql"); ! fprintf(fout, "\n"); ! if (po->header) ! { ! fprintf(fout, ! "Retrieved %d rows * %d fields" ! "\n", ! nTups, nFields); ! } ! } ! else if (po->html3) { if (po->header) { *************** *** 286,296 **** fprintf(fout, "
%d
", po->tableOpt ? po->tableOpt : ""); } if (po->header) ! border = do_header(fout, po, nFields, fieldMax, fieldNames, ! fieldNotNum, fs_len, res); for (i = 0; i < nTups; i++) ! output_row(fout, po, nFields, fields, ! fieldNotNum, fieldMax, border, i); free(fields); if (border) free(border); --- 320,342 ---- fprintf(fout, "
", po->tableOpt ? po->tableOpt : ""); } if (po->header) ! { ! if (po->html3 == 'X') ! do_header_xml(fout, po, nFields, fieldMax, fieldNames, ! fieldNotNum, fs_len, res); ! else ! border = do_header(fout, po, nFields, fieldMax, fieldNames, ! fieldNotNum, fs_len, res); ! } for (i = 0; i < nTups; i++) ! { ! if (po->html3 == 'X') ! output_row_xml(fout, po, nFields, fields, ! fieldNames, fieldMax, NULL, i); ! else ! output_row(fout, po, nFields, fields, ! fieldNotNum, fieldMax, border, i); ! } free(fields); if (border) free(border); *************** *** 310,316 **** pqsignal(SIGPIPE, oldsigpipehandler); #endif } ! if (po->html3 && !po->expanded) fputs("
\n", fout); } } --- 356,364 ---- pqsignal(SIGPIPE, oldsigpipehandler); #endif } ! if (po->html3 == 'X') ! fputs("\n", fout); ! else if (po->html3 && !po->expanded) fputs("\n", fout); } } *************** *** 708,719 **** for (j = 0; j < nFields; j++) { char *s = PQfname(res, j); ! ! if (po->html3) ! { fprintf(fout, "%s", fieldNotNum[j] ? "left" : "right", fieldNames[j]); ! } else { int n = strlen(s); --- 756,769 ---- for (j = 0; j < nFields; j++) { char *s = PQfname(res, j); ! if (po->html3 == 'X') ! { ! } ! else if (po->html3) ! { fprintf(fout, "%s", fieldNotNum[j] ? "left" : "right", fieldNames[j]); ! } else { int n = strlen(s); *************** *** 738,743 **** --- 788,810 ---- } + void + do_header_xml(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax, + char **fieldNames, unsigned char *fieldNotNum, + const int fs_len, PGresult *res) + { + + int j; /* for loop index */ + fputs("\n", fout); + for (j = 0; j < nFields; j++) + { + fprintf(fout, "%s\n", + fieldNames[j]); + } + fputs("\n", fout); + } + + static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields, unsigned char *fieldNotNum, int *fieldMax, char *border, *************** *** 776,781 **** --- 843,867 ---- else if (po->standard) fprintf(fout, "\n%s", border); fputc('\n', fout); + } + + static void + output_row_xml(FILE *fout, PQprintOpt *po, const int nFields, char **fields, + char **fieldNames, int *fieldMax, char *border, + const int row_index) + { + + int field_index; /* for loop index */ + fprintf(fout, "\n", row_index + 1); + for (field_index = 0; field_index < nFields; field_index++) + { + char *p = fields[row_index * nFields + field_index]; + fprintf(fout, "%s\n", + fieldNames[field_index], p ? p : ""); + if (p) + free(p); + } + fputs("\n", fout); } diff -rc cvs/pgsql/src/interfaces/libpq/libpq-fe.h cvswork/pgsql/src/interfaces/libpq/libpq-fe.h *** cvs/pgsql/src/interfaces/libpq/libpq-fe.h Wed Oct 7 07:04:20 1998 --- cvswork/pgsql/src/interfaces/libpq/libpq-fe.h Thu Dec 31 19:05:38 1998 *************** *** 97,103 **** * count */ pqbool align; /* fill align the fields */ pqbool standard; /* old brain dead format */ ! pqbool html3; /* output html tables */ pqbool expanded; /* expand tables */ pqbool pager; /* use pager for output if needed */ char *fieldSep; /* field separator */ --- 97,103 ---- * count */ pqbool align; /* fill align the fields */ pqbool standard; /* old brain dead format */ ! char html3; /* output html tables */ pqbool expanded; /* expand tables */ pqbool pager; /* use pager for output if needed */ char *fieldSep; /* field separator */