~ubuntu-branches/debian/sid/postfix/sid

« back to all changes in this revision

Viewing changes to src/util/argv.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (1.1.41)
  • Revision ID: package-import@ubuntu.com-20140211074430-91tdwgjriazawdz4
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
/*      ARGV    *argv_alloc(len)
10
10
/*      ssize_t len;
11
11
/*
 
12
/*      ARGV    *argv_sort(argvp)
 
13
/*      ARGV    *argvp;
 
14
/*
12
15
/*      ARGV    *argv_free(argvp)
13
16
/*      ARGV    *argvp;
14
17
/*
38
41
/*      ssize_t pos;
39
42
/*      const char *arg;
40
43
/*
 
44
/*      void    argv_delete(argvp, pos, how_many)
 
45
/*      ARGV    *argvp;
 
46
/*      ssize_t pos;
 
47
/*      ssize_t how_many;
 
48
/*
41
49
/*      void    ARGV_FAKE_BEGIN(argv, arg)
42
50
/*      const char *arg;
43
51
/*
56
64
/*      length. The result is ready for use by argv_add(). The array
57
65
/*      is null terminated.
58
66
/*
 
67
/*      argv_sort() sorts the elements of argvp in place returning
 
68
/*      the original array.
 
69
/*
59
70
/*      argv_add() copies zero or more strings and adds them to the
60
71
/*      specified string array. The array is null terminated.
61
72
/*      Terminate the argument list with a null pointer. The manifest
79
90
/*      argv_replace_one() replaces one string at the specified
80
91
/*      position.
81
92
/*
 
93
/*      argv_delete() deletes the specified number of elements
 
94
/*      starting at the specified array position. The result is
 
95
/*      null-terminated.
 
96
/*
82
97
/*      ARGV_FAKE_BEGIN/END are an optimization for the case where
83
98
/*      a single string needs to be passed into an ARGV-based
84
99
/*      interface.  ARGV_FAKE_BEGIN() opens a statement block and
148
163
    return (argvp);
149
164
}
150
165
 
 
166
static int argv_cmp(const void *e1, const void *e2)
 
167
{
 
168
    const char *s1 = *(const char **) e1;
 
169
    const char *s2 = *(const char **) e2;
 
170
 
 
171
    return strcmp(s1, s2);
 
172
}
 
173
 
 
174
/* argv_sort - sort array in place */
 
175
 
 
176
ARGV   *argv_sort(ARGV *argvp)
 
177
{
 
178
    qsort(argvp->argv, argvp->argc, sizeof(argvp->argv[0]), argv_cmp);
 
179
    return (argvp);
 
180
}
 
181
 
151
182
/* argv_extend - extend array */
152
183
 
153
184
static void argv_extend(ARGV *argvp)
270
301
    myfree(argvp->argv[where]);
271
302
    argvp->argv[where] = mystrdup(arg);
272
303
}
 
304
 
 
305
/* argv_delete - remove string(s) from array */
 
306
 
 
307
void    argv_delete(ARGV *argvp, ssize_t first, ssize_t how_many)
 
308
{
 
309
    ssize_t pos;
 
310
 
 
311
    /*
 
312
     * Sanity check.
 
313
     */
 
314
    if (first < 0 || how_many < 0 || first + how_many > argvp->argc)
 
315
        msg_panic("argv_delete bad range: (start=%ld count=%ld)",
 
316
                  (long) first, (long) how_many);
 
317
 
 
318
    for (pos = first; pos < first + how_many; pos++)
 
319
        myfree(argvp->argv[pos]);
 
320
    for (pos = first; pos <= argvp->argc - how_many; pos++)
 
321
        argvp->argv[pos] = argvp->argv[pos + how_many];
 
322
    argvp->argc -= how_many;
 
323
}