File: info.c

package info (click to toggle)
msort 8.53-2.2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,360 kB
  • sloc: sh: 10,138; ansic: 10,031; makefile: 51
file content (348 lines) | stat: -rw-r--r-- 16,667 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/* Time-stamp: <2009-02-25 17:40:37 poser> */

/*
 * Copyright (C) 1993-2008 William J. Poser (billposer@alum.mit.edu).
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 3 of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "config.h"
#include "compdefs.h"

#include <stdlib.h>
#include <stdio.h>

#ifdef LOCALE_GETTEXT
#include <libintl.h>
#define _(x) gettext(x)
#else
#define _(x) (x)
#endif
#include "limits.h"
#ifdef HAVE_UNINUM_UNINUM_H
#include <uninum/unicode.h>
#include <uninum/uninum.h>
#else
#include "unicode.h"
#endif

#ifdef HAVE_GETOPT_LONG
void
PrintGeneralFlags(FILE *fp)
{
  fprintf(fp,_("General options:\n"));
  fprintf(fp,_("\tThe following two options must precede any sort order specifications.\n"));
  fprintf(fp,_("\t-B,--BMP\t\tNo characters fall outside the BMP.\n"));
  fprintf(fp,_("\t-p,--reserve-private-use-area\n\t\t\t\tDo not use the Private Use areas.\n"));
  fputc('\n',fp);
  fprintf(fp,_("\t-b,--block\t\tA record is terminated by two or more\n\t\t\t\tend-of-line characters.\n"));
  fprintf(fp,_("\t-l,--line\t\tA record consists of a single line\n"));
  fprintf(fp,_("\t-r,--record-separator <separator>\n\t\t\t\tA record is terminated by separator character\n"));
  fprintf(fp,_("\t-O,--fixed-size-record-size <bytes>\n\t\t\t\tA record consists of the specified number of bytes\n"));
	
  fputc('\n',fp);
  fprintf(fp,_("\t-d,--field-separators <character>+\n\t\t\t\tFields are delimited by the named character(s)\n"));
  fprintf(fp,_("\t-w,--whole-record\tSort on the entire text of the record\n"));
  fputc('\n',fp);	
  fprintf(fp,_("\t-a,--algorithm <algorithm>\n\t\t\t\tI(nsertionSort)\n"));
  fprintf(fp,_("\t\t\t\tM(ergeSort) \n"));
  fprintf(fp,_("\t\t\t\tQ(uickSort) \n"));
  fprintf(fp,_("\t\t\t\tS(hellSort)\n"));
  fprintf(fp,_("\t-M,--initial-maximum-records <records>\n\t\t\t\tSet initial maximum number of records \n"));
  fprintf(fp,_("\t-m,--line-end-carriage-return\n\t\t\t\tEnd of line is marked by Carriage Return (0x0D)\n"));
  fprintf(fp,_("\t-I,--invert-globally\tInvert sense of comparisons globally\n"));
  fprintf(fp,_("\t-Q,--check-only\t\tCheck whether input is sorted. Generate no output.\n\t\t\t\tExit status is 0 if input is sorted, 11 if not.\n"));
  fprintf(fp,_("\t-u,--unicode-normalization <Normalization Mode>\n"));
  fprintf(fp,_("\t\tc NFC  canonical decomposition then composition (default)\n"));
  fprintf(fp,_("\t\td NFD  canonical decomposition\n"));
  fprintf(fp,_("\t\tC NFKC compatibility decomposition then composition\n"));
  fprintf(fp,_("\t\tD NFKD compatibility decomposition\n"));
  fprintf(fp,_("\t\tn      no normalization\n"));
  fprintf(fp,_("\t-P,--random-seed <seed>\n"));
  fprintf(fp,_("\t-Z,--skip-first-record\n"));
  fprintf(fp,_("\t-1,--in  <Input File Name>\n"));
  fprintf(fp,_("\t-2,--out <Output File Name>\n"));
  fprintf(fp,_("\t-j,--suppress-log\tSuppress log output\n"));
  fprintf(fp,_("\t-q,--quiet\t\tBe quiet - do not chat while working\n"));
  fputc('\n',fp);				
}

void
PrintInformationalFlags(FILE *fp)
{
  fprintf(fp,_("Informational options:\n"));
  fprintf(fp,_("\t-h,--help\t\tPrint usage message\n"));
  fprintf(fp,_("\t-v,--version\t\tPrint version message\n"));
  fprintf(fp,_("\t-D,--defaults\t\tList defaults\n"));
  fprintf(fp,_("\t-F,--general-options\tList general command line flags\n"));
  fprintf(fp,_("\t-G,--gnu-equivalences\tList GNU sort equivalences\n"));
  fprintf(fp,_("\t-H,--informational-options\n\t\t\t\tList informational command line flags\n"));
  fprintf(fp,_("\t-K,--key-specific-options\n\t\t\t\tList key-specific command line flags\n"));
  fprintf(fp,_("\t-L,--limits\t\tList limits\n"));
#ifdef USE_UNINUM
  fprintf(fp,_("\t-N,--number-systems\tList the number systems supported\n"));
#endif
  fputc('\n',fp);
}

void PrintKeySpecificFlags(FILE *fp)
{
  fprintf(fp,_("Key specific options:\n"));
  fprintf(fp,_("\t-e,--character-range <m,n>\n\t\t\t\tSort on characters m through n\n"));
  fprintf(fp,_("\t-n,--position <POS>(,<POS>)\n\t\t\t\tSort on the position or range of positions\n"));
  fprintf(fp,_("\t-t,--tag <tag regexp>\tSort on the field with the specified tag\n"));
  fprintf(fp,_("\t-o,--optional <comparison>\n\t\t\t\tOptional: if absent compare as (<,=,>)\n"));
  fprintf(fp,_("\t-C,--fold-case\t\tFold case\n"));
  fprintf(fp,_("\t-z,--fold-case-turkic\tFold case with additional Turkic conversions\n"));
  fprintf(fp,_("\t-c,--comparison-type <comparison type>\n\t\t\t\tl(exicographic)\n"));
  fprintf(fp,_("\t\t\t\tN(umeric string)\n"));
  fprintf(fp,_("\t\t\t\tn(umeric)\n"));
  fprintf(fp,_("\t\t\t\th(ybrid)\n"));
  fprintf(fp,_("\t\t\t\ts(ize)\n"));
  fprintf(fp,_("\t\t\t\ta(ngle) - ddd:mm:ss(.sss) or ddd mm ss(.sss)\n"));
  fprintf(fp,_("\t\t\t\tD(omain name)\n"));
  fprintf(fp,_("\t\t\t\td(ate)\n"));
  fprintf(fp,_("\t\t\t\tm(onth)\n"));
  fprintf(fp,_("\t\t\t\tt(ime)\n"));
  fprintf(fp,_("\t\t\t\ti(so8601 date/time)\n"));
  fprintf(fp,_("\t\t\t\tr(andom)\n"));
#ifdef USE_UNINUM
  fprintf(fp,_("\t-y,--number-system <number system>\n"));
#endif
  fprintf(fp,_("\t-f,--date-format <date format>\n\t\t\t\tPermutation of y(m)d with separators\n"));
  fprintf(fp,_("\t-W,--sort-order-file-separators <file name>\n\t\t\t\tRead separators for sort order file.\n"));
  fprintf(fp,_("\t-S,--substitution-file <file name>\n\t\t\t\tRead substitutions from named file\n"));
#ifdef LOCALE_SORT_ORDER
  fprintf(fp,_("\t-s,--sort-order\t<file name|locale name|\"current\">\n"));
#else
  fprintf(fp,_("\t-s,--sort-order-file <file name>\n\t\t\t\tRead the sort order definition from <file name>.\n"));
#endif
  fprintf(fp,_("\t-T,--transformations <(d)(e)(s)>\n\t\t\t\tApply the specified transformations\n"));
  fprintf(fp,_("\t\t\t\t\td = strip diacritics\n\t\t\t\t\te = strip enclosures\n\t\t\t\t\ts = simplify style\n"));
  fprintf(fp,_("\t-x,--exclusion-file <file name>\n\t\t\t\tRead exclusions from named file\n"));
  fprintf(fp,_("\t-X,--exclude-characters <exclusions>\n\t\t\t\tExclude specified characters\n"));
  fprintf(fp,_("\t-i,--invert-locally\tInvert sense of comparisons\n"));
  fprintf(fp,_("\t-R,--reverse-key\tReverse characters of key\n"));
  fprintf(fp,_("\t-A,--first-char-only\tUse only the first character of the field\n"));
  fputc('\n',fp);				
}

void
PrintGNUEquivalences(FILE *fp)
{
  fprintf(fp,"GNU/BSD sort\t\t\t\tmsort\n");
  fprintf(fp,"-c,--check\t\t\t\t-Q,--check-only\n");
  fprintf(fp,"-f,--ignore-case\t\t\t-C,--fold-case\n");
  fprintf(fp,"-g,--general-numeric-sort\t\t-c n,--comparison-type n\n");
  fprintf(fp,"-M,--month-sort\t\t\t\t-c m,--comparison-type m\n");
  fprintf(fp,"-n,--numeric-sort\t\t\t-c N,--comparison-type N\n");
  fprintf(fp,"-r,--reverse\t\t\t\t-i,--invert-locally\n");
  fprintf(fp,"-s,--stable\t\t\t\t-a I,--algorithm I\n");
  fprintf(fp,"           \t\t\t\t-a M,--algorithm M\n");
  fprintf(fp,"-t <fs>,--field-separator <fs>\t\t-d <fs>,--field-separators <fs>\n");
  fprintf(fp,"-z,--zero-terminated\t\t\t-r \\000,--record-separator \\000\n");
  fputc('\n',fp);				
}
#else

void
PrintGeneralFlags(FILE *fp)
{
  fprintf(fp,_("\tThe following two options must precede any sort order specifications.\n"));
  fprintf(fp,_("\t-B                    No characters fall outside the BMP.\n"));
  fprintf(fp,_("\t-p                    Do not use the Private Use areas.\n"));
  fputc('\n',fp);
  fprintf(fp,_("\t-b                    A record is terminated by two or more\n\t\t\t\tend-of-line characters.\n"));
  fprintf(fp,_("\t-l                    A record consists of a single line\n"));
  fprintf(fp,_("\t-r <separator>        A record is terminated by separator character\n"));
  fprintf(fp,_("\t-O <bytes>            A record consists of the specified number of bytes\n"));
	
  fputc('\n',fp);
  fprintf(fp,_("\t-d <character>+       Fields are delimited by the named character(s)\n"));
  fprintf(fp,_("\t-w                    Sort on the entire text of the record\n"));
  fputc('\n',fp);	
  fprintf(fp,_("\t-a <algorithm>        I(nsertionSort)\n"));
  fprintf(fp,_("\t                      M(ergeSort) \n"));
  fprintf(fp,_("\t                      Q(uickSort) \n"));
  fprintf(fp,_("\t                      S(hellSort)\n"));
  fprintf(fp,_("\t-M <records>          Set initial maximum number of records \n"));
  fprintf(fp,_("\t-m                    End of line is marked by Carriage Return (0x0D)\n"));
  fprintf(fp,_("\t-I                    Invert sense of comparisons globally\n"));
  fprintf(fp,_("\t-P <seed>             Set the random number generator seed.\n"));
  fprintf(fp,_("\t-Z,--skip-first-record\n"));
  fprintf(fp,_("\t-1 <Input File Name>\n"));
  fprintf(fp,_("\t-2 <Output File Name>\n"));
  fprintf(fp,_("\t-j                    Suppress log output\n"));
  fprintf(fp,_("\t-q                    Be quiet - do not chat while working\n"));
  fprintf(fp,_("\t-u <Normalization Mode>\n"));
  fprintf(fp,_("\t\tc NFC  canonical decomposition then composition (default)\n"));
  fprintf(fp,_("\t\td NFD  canonical decomposition\n"));
  fprintf(fp,_("\t\tC NFKC compatibility decomposition then composition\n"));
  fprintf(fp,_("\t\tD NFKD compatibility decomposition\n"));
  fprintf(fp,_("\t\tn      no normalization\n"));
  fputc('\n',fp);				
}

void
PrintInformationalFlags(FILE *fp)
{
  fprintf(fp,_("General options:\n"));
  fprintf(fp,_("\t-h                    Print usage message\n"));
  fprintf(fp,_("\t-v                    Print version message\n"));
  fprintf(fp,_("\t-D                    List defaults\n"));
  fprintf(fp,_("\t-F                    List general command line flags\n"));
  fprintf(fp,_("\t-G                    List GNU equivalences\n"));
  fprintf(fp,_("\t-H                    List informational command line flags\n"));
  fprintf(fp,_("\t-K                    List key-specific command line flags\n"));
  fprintf(fp,_("\t-L                    List limits\n"));
#ifdef USE_UNINUM
  fprintf(fp,_("\t-N                    List available number systems\n"));
#endif
  fputc('\n',fp);				
}

PrintKeySpecificFlags(FILE *fp)
{
  fprintf(fp,_("Key specific options:\n"));
  fprintf(fp,_("\t-e <m,n>              Sort on characters m through n\n"));
  fprintf(fp,_("\t-n <POS>(,<POS>)      Sort on the position or range of positions\n"));
  fprintf(fp,_("\t-t <tag regexp>       Sort on the field with the specified tag\n"));
  fprintf(fp,_("\t-o <comparison>       Optional: if absent compare as (<,=,>)\n"));
  fprintf(fp,_("\t-C                    Fold case\n"));
  fprintf(fp,_("\t-c <key type>         l(exicographic)\n"));
  fprintf(fp,_("\t                      N(umeric string)\n"));
  fprintf(fp,_("\t                      n(umeric)\n"));
  fprintf(fp,_("\t                      h(ybrid)\n"));
  fprintf(fp,_("\t                      s(ize)\n"));
  fprintf(fp,_("\t                      a(ngle) - ddd:mm:ss(.sss) or ddd mm ss(.sss)\n"));
  fprintf(fp,_("\t                      D(omain name)\n"));
  fprintf(fp,_("\t                      d(ate)\n"));
  fprintf(fp,_("\t                      t(ime)\n"));
  fprintf(fp,_("\t                      i(so8601 date/time)\n"));
  fprintf(fp,_("\t                      r(andom)\n"));
  fprintf(fp,_("\t-f <date format>      Permutation of y(m)d with separators\n"));
  fprintf(fp,_("\t-W <file name>        Read separators for sort order file.\n"));
  fprintf(fp,_("\t-S <file name>        Read substitutions from named file\n"));
#ifdef LOCALE_SORT_ORDER
  fprintf(fp,_("\t-s <string>\n"));
  fprintf(fp,_("\t   If string is a file name, the sort order is read from the file.\n"));
  fprintf(fp,_("\t   If string is a locale name, the sort order for the locale is used.\n"));
  fprintf(fp,_("\t   If string is \"locale\", the sort order for the current locale is used.\n"));
#else
  fprintf(fp,_("\t-s <file name>        Read the sort order definition from <file name>.\n"));
#endif
  fprintf(fp,_("\t-x <file name>        Read exclusions from named file\n"));
  fprintf(fp,_("\t-X <exclusions>       Exclude specified characters\n"));
  fprintf(fp,_("\t-i                    Invert sense of comparisons\n"));
  fprintf(fp,_("\t-R                    Reverse characters of key\n"));
  fprintf(fp,_("\t-A                    Use only the first character of the field\n"));
  fputc('\n',fp);				
}

void
PrintGNUEquivalences(FILE *fp)
{
  fprintf(fp,"GNU/BSD sort\t\t\t\tmsort\n");
  fprintf(fp,"-c,--check\t\t\t\t-Q\n");
  fprintf(fp,"-f,--ignore-case\t\t\t-C\n");
  fprintf(fp,"-g,--general-numeric-sort\t\t-c n\n");
  fprintf(fp,"-M,--month-sort\t\t\t\t-c m\n");
  fprintf(fp,"-n,--numeric-sort\t\t\t-c N\n");
  fprintf(fp,"-r,--reverse\t\t\t\t-i\n");
  fprintf(fp,"-s,--stable\t\t\t\t-a I\n");
  fprintf(fp,"           \t\t\t\t-a M\n");
  fprintf(fp,"-t <fs>,--field-separator <fs>\t\t-d <fs>\n");
  fprintf(fp,"-z,--zero-terminated\t\t\t-r \\000\n");
  fputc('\n',fp);				
}

#endif
void
PrintDefaults(FILE *fp)
{

   fprintf(fp,_("Defaults:\n"));
   fprintf(fp,_("    Field terminator character(s)\n"));
   fprintf(fp,_("        Record = line               whitespace (space or tab)\n"));
   fprintf(fp,_("        Record = block              end-of-line\n"));
   fprintf(fp,_("    Key specification               whole record\n"));
   fprintf(fp,_("    Initial number of records       %4d\n"),DEFMAXRECORDS);
   fprintf(fp,_("    Presence of key                 obligatory\n"));
   fprintf(fp,_("    Record type                     double end-of-line terminated block\n"));
   fprintf(fp,_("    Skip first record               no\n"));
   fprintf(fp,_("    Sense of sort                   forward\n"));	
   fprintf(fp,_("    Date format                     y-m-d (International Date Format)\n"));
   fprintf(fp,_("    Sort order                      numerical Unicode order\n"));
   fprintf(fp,_("    Sort type                       lexicographic\n"));
   fprintf(fp,_("    Algorithm                       quicksort\n"));
   fprintf(fp,_("    Unicode normalization           NFC\n"));
   fprintf(fp,"\n");
}

#define BUFSIZE 128
void
PrintLimits(FILE *fp)
{
  char buf[BUFSIZE];

  fprintf(fp,_("Limits:\n"));
#ifdef HAVE_PRINTF_THSEP
  fprintf(fp,_("   Maximum length of numeric string key                       %'8d\n"),
	  MAXDOUBLELEN);
  fprintf(fp,_("   Number of multigraphs per key with no restrictions         %'8d\n"),
	  FUL_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of multigraphs per key (BMP only)                   %'8d\n"),
	  BMP_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of multigraphs per key (Private Use Areas reserved) %'8d\n"),
	  NPU_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of subparts of a hybrid key with locale collation   %'8s\n"),
	  "127");
#else
  fprintf(fp,_("   Maximum length of numeric string key                       %8d\n"),
	  MAXDOUBLELEN);
  fprintf(fp,_("   Number of multigraphs per key with no restrictions         %8d\n"),
	  FUL_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of multigraphs per key (BMP only)                   %8d\n"),
	  BMP_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of multigraphs per key (Private Use Areas reserved) %8d\n"),
	  NPU_MAXMULTIGRAPHS);
  fprintf(fp,_("   Number of subparts of a hybrid key with locale collation   %8s\n"),
	  "127");
#endif
  fprintf(fp,"\n");
}


void
PrintUsage(void)
{   extern char progname[];
	
   fprintf(stdout,"\n");
   fprintf(stdout,_("This program sorts text using arbitrary sort\norders on fields specified on the command-line.\n"));
   fprintf(stdout,_("Usage: %s <flags> (<input file name>)\n"),progname);
   fprintf(stdout,_("Type %s -F to obtain a list of global options.\n"),progname);
   fprintf(stdout,_("Type %s -H to obtain a list of informational options.\n"),progname);
   fprintf(stdout,_("Type %s -K to obtain a list of key-specific options.\n"),progname);
   fprintf(stdout,_("There is also a graphical interface called msg.\n\n"));
}

#ifdef USE_UNINUM
void PrintNumberSystems(FILE *fp) {
  char *ds;
  fprintf(fp,"The number systems available for numeric and numeric string keys are:\n");
  while (ds = ListNumberSystems(1,0)) fprintf(fp,"\t%s\n",ds);
  ListNumberSystems(0,0);
  while (ds = ListNumberSystems(1,1)) fprintf(fp,"\t%s\n",ds);
}
#endif