3
3
*
4
4
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
5
5
*
6
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.32 2008/05/08 19:11:36 momjian Exp $
6
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.33 2008/05/09 05:25:04 tgl Exp $
7
7
*
8
8
* XXX this file does not really belong in psql/. Perhaps move to libpq?
9
9
* It also seems that the mbvalidate function is redundant with existing
@@ -205,12 +205,15 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
205
205
* pg_wcssize takes the given string in the given encoding and returns three
206
206
* values:
207
207
* result_width: Width in display characters of the longest line in string
208
- * result_height: Number of newlines in display output
209
- * result_format_size: Number of bytes required to store formatted representation of string
208
+ * result_height: Number of lines in display output
209
+ * result_format_size: Number of bytes required to store formatted
210
+ * representation of string
211
+ *
212
+ * This MUST be kept in sync with pg_wcsformat!
210
213
*/
211
- int
212
- pg_wcssize (unsigned char * pwcs , size_t len , int encoding , int * result_width ,
213
- int * result_height , int * result_format_size )
214
+ void
215
+ pg_wcssize (unsigned char * pwcs , size_t len , int encoding ,
216
+ int * result_width , int * result_height , int * result_format_size )
214
217
{
215
218
int w ,
216
219
chlen = 0 ,
@@ -241,6 +244,14 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
241
244
linewidth += 2 ;
242
245
format_size += 2 ;
243
246
}
247
+ else if (* pwcs == '\t' ) /* Tab */
248
+ {
249
+ do
250
+ {
251
+ linewidth ++ ;
252
+ format_size ++ ;
253
+ } while (linewidth % 8 != 0 );
254
+ }
244
255
else if (w < 0 ) /* Other control char */
245
256
{
246
257
linewidth += 4 ;
@@ -266,7 +277,7 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
266
277
}
267
278
if (linewidth > width )
268
279
width = linewidth ;
269
- format_size += 1 ;
280
+ format_size += 1 ; /* For NUL char */
270
281
271
282
/* Set results */
272
283
if (result_width )
@@ -275,14 +286,13 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
275
286
* result_height = height ;
276
287
if (result_format_size )
277
288
* result_format_size = format_size ;
278
-
279
- return width ;
280
289
}
281
290
282
291
/*
283
- * Filter out unprintable characters, companion to wcs_size.
284
- * Break input into lines based on \n. lineptr[i].ptr == NULL
285
- * indicates the end of the array.
292
+ * Format a string into one or more "struct lineptr" lines.
293
+ * lines[i].ptr == NULL indicates the end of the array.
294
+ *
295
+ * This MUST be kept in sync with pg_wcssize!
286
296
*/
287
297
void
288
298
pg_wcsformat (unsigned char * pwcs , size_t len , int encoding ,
@@ -309,7 +319,7 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
309
319
linewidth = 0 ;
310
320
lines ++ ;
311
321
count -- ;
312
- if (count = = 0 )
322
+ if (count < = 0 )
313
323
exit (1 ); /* Screwup */
314
324
315
325
/* make next line point to remaining memory */
@@ -346,14 +356,14 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
346
356
if (encoding == PG_UTF8 )
347
357
sprintf ((char * ) ptr , "\\u%04X" , utf2ucs (pwcs ));
348
358
else
349
-
359
+ {
350
360
/*
351
361
* This case cannot happen in the current code because only
352
362
* UTF-8 signals multibyte control characters. But we may need
353
363
* to support it at some stage
354
364
*/
355
365
sprintf ((char * ) ptr , "\\u????" );
356
-
366
+ }
357
367
ptr += 6 ;
358
368
linewidth += 6 ;
359
369
}
@@ -370,7 +380,7 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
370
380
lines -> width = linewidth ;
371
381
* ptr ++ = '\0' ; /* Terminate formatted string */
372
382
373
- if (count = = 0 )
383
+ if (count < = 0 )
374
384
exit (1 ); /* Screwup */
375
385
376
386
(lines + 1 )-> ptr = NULL ; /* terminate line array */
0 commit comments