|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.55 2005/02/22 04:40:57 momjian Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.56 2005/06/09 15:27:27 momjian Exp $ |
7 | 7 | */
|
8 | 8 | #include "postgres_fe.h"
|
9 | 9 | #include "common.h"
|
@@ -992,6 +992,213 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
|
992 | 992 |
|
993 | 993 |
|
994 | 994 |
|
| 995 | +/*************************/ |
| 996 | +/* Troff -ms */ |
| 997 | +/*************************/ |
| 998 | + |
| 999 | + |
| 1000 | +static void |
| 1001 | +troff_ms_escaped_print(const char *in, FILE *fout) |
| 1002 | +{ |
| 1003 | + const char *p; |
| 1004 | + |
| 1005 | + for (p = in; *p; p++) |
| 1006 | + switch (*p) |
| 1007 | + { |
| 1008 | + case '\\': |
| 1009 | + fputs("\(rs", fout); |
| 1010 | + break; |
| 1011 | + default: |
| 1012 | + fputc(*p, fout); |
| 1013 | + } |
| 1014 | +} |
| 1015 | + |
| 1016 | + |
| 1017 | + |
| 1018 | +static void |
| 1019 | +print_troff_ms_text(const char *title, const char *const * headers, |
| 1020 | + const char *const * cells, const char *const * footers, |
| 1021 | +const char *opt_align, bool opt_barebones, unsigned short int opt_border, |
| 1022 | + FILE *fout) |
| 1023 | +{ |
| 1024 | + unsigned int col_count = 0; |
| 1025 | + unsigned int i; |
| 1026 | + const char *const * ptr; |
| 1027 | + |
| 1028 | + |
| 1029 | + /* print title */ |
| 1030 | + if (!opt_barebones && title) |
| 1031 | + { |
| 1032 | + fputs(".LP\n.DS C\n", fout); |
| 1033 | + troff_ms_escaped_print(title, fout); |
| 1034 | + fputs("\n.DE\n", fout); |
| 1035 | + } |
| 1036 | + |
| 1037 | + /* count columns */ |
| 1038 | + for (ptr = headers; *ptr; ptr++) |
| 1039 | + col_count++; |
| 1040 | + |
| 1041 | + /* begin environment and set alignments and borders */ |
| 1042 | + fputs(".LP\n.TS\n", fout); |
| 1043 | + if (opt_border == 2) |
| 1044 | + fputs("center box;\n", fout); |
| 1045 | + else |
| 1046 | + fputs("center;\n", fout); |
| 1047 | + |
| 1048 | + for (i = 0; i < col_count; i++) |
| 1049 | + { |
| 1050 | + fputc(*(opt_align + i), fout); |
| 1051 | + if (opt_border > 0 && i < col_count - 1) |
| 1052 | + fputs(" | ", fout); |
| 1053 | + } |
| 1054 | + fputs(".\n", fout); |
| 1055 | + |
| 1056 | + /* print headers and count columns */ |
| 1057 | + for (i = 0, ptr = headers; i < col_count; i++, ptr++) |
| 1058 | + { |
| 1059 | + if (!opt_barebones) |
| 1060 | + { |
| 1061 | + if (i != 0) |
| 1062 | + fputc('\t', fout); |
| 1063 | + fputs("\\fI", fout); |
| 1064 | + troff_ms_escaped_print(*ptr, fout); |
| 1065 | + fputs("\\fP", fout); |
| 1066 | + } |
| 1067 | + } |
| 1068 | + |
| 1069 | + if (!opt_barebones) |
| 1070 | + { |
| 1071 | + fputs("\n_\n", fout); |
| 1072 | + } |
| 1073 | + |
| 1074 | + /* print cells */ |
| 1075 | + for (i = 0, ptr = cells; *ptr; i++, ptr++) |
| 1076 | + { |
| 1077 | + troff_ms_escaped_print(*ptr, fout); |
| 1078 | + |
| 1079 | + if ((i + 1) % col_count == 0) |
| 1080 | + fputc('\n', fout); |
| 1081 | + else |
| 1082 | + fputc('\t', fout); |
| 1083 | + } |
| 1084 | + |
| 1085 | + fputs(".TE\n.DS L\n", fout); |
| 1086 | + |
| 1087 | + |
| 1088 | + /* print footers */ |
| 1089 | + |
| 1090 | + if (footers && !opt_barebones) |
| 1091 | + for (ptr = footers; *ptr; ptr++) |
| 1092 | + { |
| 1093 | + troff_ms_escaped_print(*ptr, fout); |
| 1094 | + fputc('\n', fout); |
| 1095 | + } |
| 1096 | + |
| 1097 | + fputs(".DE\n", fout); |
| 1098 | +} |
| 1099 | + |
| 1100 | + |
| 1101 | + |
| 1102 | +static void |
| 1103 | +print_troff_ms_vertical(const char *title, const char *const * headers, |
| 1104 | + const char *const * cells, const char *const * footers, |
| 1105 | +const char *opt_align, bool opt_barebones, unsigned short int opt_border, |
| 1106 | + FILE *fout) |
| 1107 | +{ |
| 1108 | + unsigned int col_count = 0; |
| 1109 | + unsigned int i; |
| 1110 | + const char *const * ptr; |
| 1111 | + unsigned int record = 1; |
| 1112 | + unsigned short current_format = 0; /* 0=none, 1=header, 2=body */ |
| 1113 | + |
| 1114 | + (void) opt_align; /* currently unused parameter */ |
| 1115 | + |
| 1116 | + /* print title */ |
| 1117 | + if (!opt_barebones && title) |
| 1118 | + { |
| 1119 | + fputs(".LP\n.DS C\n", fout); |
| 1120 | + troff_ms_escaped_print(title, fout); |
| 1121 | + fputs("\n.DE\n", fout); |
| 1122 | + } |
| 1123 | + |
| 1124 | + /* begin environment and set alignments and borders */ |
| 1125 | + fputs(".LP\n.TS\n", fout); |
| 1126 | + if (opt_border == 2) |
| 1127 | + fputs("center box;\n", fout); |
| 1128 | + else |
| 1129 | + fputs("center;\n", fout); |
| 1130 | + |
| 1131 | + /* basic format */ |
| 1132 | + if (opt_barebones) |
| 1133 | + fputs("c l;\n", fout); |
| 1134 | + |
| 1135 | + |
| 1136 | + /* count columns */ |
| 1137 | + for (ptr = headers; *ptr; ptr++) |
| 1138 | + col_count++; |
| 1139 | + |
| 1140 | + |
| 1141 | + /* print records */ |
| 1142 | + for (i = 0, ptr = cells; *ptr; i++, ptr++) |
| 1143 | + { |
| 1144 | + /* new record */ |
| 1145 | + if (i % col_count == 0) |
| 1146 | + { |
| 1147 | + if (!opt_barebones) |
| 1148 | + { |
| 1149 | + |
| 1150 | + if (current_format != 1) |
| 1151 | + { |
| 1152 | + if (opt_border == 2 && i > 0) |
| 1153 | + fputs("_\n", fout); |
| 1154 | + if (current_format != 0) |
| 1155 | + fputs(".T&\n", fout); |
| 1156 | + fputs("c s.\n", fout); |
| 1157 | + current_format = 1; |
| 1158 | + } |
| 1159 | + fprintf(fout, "\\fIRecord %d\\fP\n", record++); |
| 1160 | + } |
| 1161 | + if (opt_border >= 1) |
| 1162 | + fputs("_\n", fout); |
| 1163 | + } |
| 1164 | + |
| 1165 | + if (!opt_barebones) |
| 1166 | + { |
| 1167 | + if (current_format != 2) |
| 1168 | + { |
| 1169 | + if (current_format != 0) |
| 1170 | + fputs(".T&\n", fout); |
| 1171 | + if (opt_border != 1) |
| 1172 | + fputs("c l.\n", fout); |
| 1173 | + else |
| 1174 | + fputs("c | l.\n", fout); |
| 1175 | + current_format = 2; |
| 1176 | + } |
| 1177 | + } |
| 1178 | + |
| 1179 | + troff_ms_escaped_print(headers[i % col_count], fout); |
| 1180 | + fputc('\t', fout); |
| 1181 | + troff_ms_escaped_print(*ptr, fout); |
| 1182 | + fputc('\n', fout); |
| 1183 | + } |
| 1184 | + |
| 1185 | + fputs(".TE\n.DS L\n", fout); |
| 1186 | + |
| 1187 | + |
| 1188 | + /* print footers */ |
| 1189 | + |
| 1190 | + if (footers && !opt_barebones) |
| 1191 | + for (ptr = footers; *ptr; ptr++) |
| 1192 | + { |
| 1193 | + troff_ms_escaped_print(*ptr, fout); |
| 1194 | + fputc('\n', fout); |
| 1195 | + } |
| 1196 | + |
| 1197 | + fputs(".DE\n", fout); |
| 1198 | +} |
| 1199 | + |
| 1200 | + |
| 1201 | + |
995 | 1202 | /********************************/
|
996 | 1203 | /* Public functions */
|
997 | 1204 | /********************************/
|
@@ -1121,6 +1328,12 @@ printTable(const char *title,
|
1121 | 1328 | else
|
1122 | 1329 | print_latex_text(title, headers, cells, footers, align, opt->tuples_only, border, output);
|
1123 | 1330 | break;
|
| 1331 | + case PRINT_TROFF_MS: |
| 1332 | + if (opt->expanded) |
| 1333 | + print_troff_ms_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output); |
| 1334 | + else |
| 1335 | + print_troff_ms_text(title, headers, cells, footers, align, opt->tuples_only, border, output); |
| 1336 | + break; |
1124 | 1337 | default:
|
1125 | 1338 | fprintf(stderr, "+ Oops, you shouldn't see this!\n");
|
1126 | 1339 | }
|
|
0 commit comments