~ubuntu-branches/ubuntu/wily/dctrl-tools/wily

« back to all changes in this revision

Viewing changes to tbl-dctrl/tbl-dctrl.c

  • Committer: Package Import Robot
  • Author(s): Antti-Juhani Kaijanaho, David Prévot, Antti-Juhani Kaijanaho
  • Date: 2013-05-07 23:16:00 UTC
  • mfrom: (17.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130507231600-qb8annjvc7l32oak
Tags: 2.23
[ David Prévot ]

* Fix charset in pt_BR program translation.

[ Antti-Juhani Kaijanaho ]

* Merge 2.22.1 and 2.22.2.
* Add a test case (tests/0021.{in,out,sh}) to verify that tbl-dctrl
  handles UTF-8 correctly.
   - As it requires the C.UTF-8 locale, build-depend on libc-bin >= 2.13
* Since mblen is unnecessarily marked warn_unused_result with
  _FORTIFY_SOURCE, (see bug #674917), causing spurious warnings upon
  mblen initialization calls, switch to using mbrlen in tbl-dctrl.c (a
  good idea in any case).
* Add -Wextra to non-package builds (and clean up the resulting warnings).
* lib/msg.c (msg_primitive): Write the period before the newline, not after!
* tests/0022.{out,err,fails}: New test case, for grep-dctrl
  --ignore-parse-errors
* tester.sh: Handle missing diffs gracefully.
* lib/fsaf.c and others: Remove mmap support (recognize but ignore --mmap).
  It was only complicating matters without giving much benefit.
* lib/fsaf.[ch]: Make fsaf_read an inline function (50 % speedup in my
  tests.)
* debian/control (Build-Depends): Remove versioned gcc
  Thanks to Jakub Wilk for pointing out the version spec was broken.
  It also turns out to be obsolete.
* Some code cleanup.
* debian/control: Add "Multi-Arch: foreign"
  Closes: 693474 (Add multiarch metadata)
  Reported by Wookey <wookey@wookware.org>.
* po/fi.po: Fix charset issue discovered by Jakub Wilk
  and reported by David Prévot, and delete obsolete entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  dctrl-tools - Debian control file inspection tools
2
 
    Copyright © 2005, 2006, 2007, 2008, 2009, 2010, 2011 Antti-Juhani Kaijanaho
 
2
    Copyright © 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Antti-Juhani Kaijanaho
3
3
 
4
4
    This program is free software; you can redistribute it and/or modify
5
5
    it under the terms of the GNU General Public License as published by
19
19
#include <argp.h>
20
20
#include <locale.h>
21
21
#include <stdlib.h>
 
22
#include <wchar.h>
22
23
#include "misc.h"
23
24
#include "msg.h"
24
25
#include "i18n.h"
35
36
const char * argp_program_bug_address = MAINTAINER;
36
37
 
37
38
static struct argp_option options[] = {
38
 
        { "delimiter",         'd', N_("DELIM"),    0, N_("Specify a delimiter.") },
39
 
        { "no-heading",        'H', 0,              0, N_("Do not print a table heading") },
40
 
        { "column",            'c', N_("SPEC"),     0, N_("Append the specified column.") },
41
 
        { "copying",           'C', 0,              0, N_("Print out the copyright license.") },
42
 
        { "errorlevel",        'l', N_("LEVEL"),    0, N_("Set debugging level to LEVEL.") },
43
 
        { "mmap",               OPT_MMAP, 0,        0, N_("Attempt mmapping input files") },
44
 
        { 0 }
 
39
        { "delimiter",         'd', N_("DELIM"),    0, N_("Specify a delimiter."), 0 },
 
40
        { "no-heading",        'H', 0,              0, N_("Do not print a table heading"), 0 },
 
41
        { "column",            'c', N_("SPEC"),     0, N_("Append the specified column."), 0 },
 
42
        { "copying",           'C', 0,              0, N_("Print out the copyright license."), 0 },
 
43
        { "errorlevel",        'l', N_("LEVEL"),    0, N_("Set debugging level to LEVEL."), 0 },
 
44
        { "mmap",               OPT_MMAP, 0,        0, N_("Attempt mmapping input files"), 0 },
 
45
        { 0, 0, 0, 0, 0, 0 }
45
46
};
46
47
 
47
48
#define MAX_FNAMES 4096
96
97
 
97
98
        size_t num_lines = 1;
98
99
 
99
 
        mblen(NULL, 0);
 
100
        mbstate_t mbs;
 
101
        memset(&mbs, 0, sizeof mbs);
100
102
        for (size_t i = 0; i < orig_len; /**/) {
101
103
                if (orig[i] == '\n') {
102
104
                        i++;
125
127
                        bpo = i;
126
128
                        bpr = len;
127
129
                }
128
 
                int n = mblen(orig + i, orig_len - i);
 
130
                int n = mbrlen(orig + i, orig_len - i, &mbs);
129
131
                if (n <= 0) break;
130
 
                for (size_t j = 0; j < n; j++) INSERT(orig[i+j]);
 
132
                for (int j = 0; j < n; j++) INSERT(orig[i+j]);
131
133
                i += n;
132
134
                ll++;
133
135
        }
161
163
                        } else if (j > 0) {
162
164
                                fputs(args->delim, stdout);
163
165
                        }
164
 
                        mblen(NULL, 0);
 
166
                        mbstate_t mbs;
 
167
                        memset(&mbs, 0, sizeof mbs);
165
168
                        size_t k;
166
169
                        size_t m = 0;
167
170
                        for (k = data[j].inx;
171
174
                                        k++;
172
175
                                        break;
173
176
                                }
174
 
                                int n = mblen(data[j].wrapped + k,
175
 
                                              data[j].wrapped_len - k);
 
177
                                int n = mbrlen(data[j].wrapped + k,
 
178
                                               data[j].wrapped_len - k,
 
179
                                               &mbs);
176
180
                                for (int l = 0; l < n; l++) {
177
181
                                        putchar(data[j].wrapped[k+l]);
178
182
                                }
282
286
                        n = n * 10 + (*p - '0');
283
287
                }
284
288
                if (err) message(L_IMPORTANT, 0, _("invalid column length"));
285
 
                col->column_width = n > 0 ? n : -1;
 
289
                col->column_width = n > 0 ? n : (size_t)-1;
286
290
                if (n == 0) args->need_preprocessing = 1;
287
291
                args->num_columns++;
288
292
        }
321
325
                break;
322
326
        case OPT_MMAP:
323
327
                debug_message("parse_opt: mmap", 0);
324
 
                fsaf_mmap = 1;
 
328
                /* ignore */
325
329
                break;
326
330
        case ARGP_KEY_END:
327
331
        case ARGP_KEY_ARGS:  case ARGP_KEY_INIT: case  ARGP_KEY_SUCCESS:
337
341
static char progdoc [] =
338
342
N_("tbl-dctrl -- tabularize Debian control files");
339
343
 
340
 
static struct argp argp = { options, parse_opt, 0, progdoc };
 
344
static struct argp argp = { options, parse_opt, 0, progdoc, 0, 0, 0 };
341
345
 
342
346
static size_t mbs_len(char const *mbs, size_t n, char const *fname)
343
347
{
344
348
        if (n == (size_t)(-1)) n = strlen(mbs);
345
349
        size_t mlen = 0;
346
350
        size_t len = 0;
347
 
        mblen(NULL, 0);
 
351
        mbstate_t mbstate;
 
352
        memset(&mbstate, 0, sizeof mbstate);
348
353
        for (size_t k = 0; k < n;/**/) {
349
354
                if (mbs[k] == '\n') {
350
355
                        if (len > mlen) mlen = len;
353
358
                        continue;
354
359
                }
355
360
                len++;
356
 
                int delta = mblen(mbs + k, n - k);
 
361
                int delta = mbrlen(mbs + k, n - k, &mbstate);
357
362
                if (delta <= 0) {
358
363
                        message(L_IMPORTANT, fname, 
359
364
                                _("bad multibyte character"));