PERFORCE change 159877 for review
Gabor Kovesdan
gabor at FreeBSD.org
Thu Mar 26 15:24:40 PDT 2009
http://perforce.freebsd.org/chv.cgi?CH=159877
Change 159877 by gabor at gabor_server on 2009/03/26 22:24:22
- /var/tmp is the default temp directory
- Support TMPDIR envvar
- Try to make manpage consistent with current behavior
- Return 2 on errors
- Use ENOTDIR libc message instead of custom error messages
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/newsort/file.c#3 edit
.. //depot/projects/soc2008/gabor_textproc/newsort/sort.1#2 edit
.. //depot/projects/soc2008/gabor_textproc/newsort/sort.c#4 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/newsort/file.c#3 (text+ko) ====
@@ -105,12 +105,12 @@
sprintf(tempfiles[tempno - 1], "%s" TMPPAT, tmpdir);
fd = mkstemp(tempfiles[tempno - 1]);
if ((file = fdopen(fd, "w")) == NULL)
- err(1, NULL);
+ err(2, NULL);
} else if (strcmp(fn, "-") == 0) {
return (stdout);
} else {
if((file = fopen(fn, mode)) == NULL)
- err(1, NULL);
+ err(2, NULL);
}
return (file);
@@ -150,7 +150,7 @@
return (bufsiz);
if (stat(fn, &st) != 0)
- err(1, NULL);
+ err(2, NULL);
if (st.st_size/OPT_SLICES < OPT_BUFSIZE)
return (OPT_BUFSIZE);
==== //depot/projects/soc2008/gabor_textproc/newsort/sort.1#2 (text+ko) ====
@@ -40,13 +40,11 @@
.Nd sort or merge text files
.Sh SYNOPSIS
.Nm sort
-.Op Fl bcdfHimnrSsuz
+.Op Fl bcdfghiMmnrSuVz
.Sm off
.Op Fl k\ \& Ar field1 Op , Ar field2
.Sm on
.Op Fl o Ar output
-.Op Fl R Ar char
-.Bk -words
.Op Fl T Ar dir
.Ek
.Op Fl t Ar char
@@ -78,11 +76,11 @@
.Em stderr .
.It Fl m , Fl Fl merge
Merge only; the input files are assumed to be pre-sorted.
+If they are not sorted the output order is undefined.
.It Fl o Ar output , Fl Fl output Ns = Ns Ar output
The argument given is the name of an
.Ar output
file to be used instead of the standard output.
-This file can be the same as one of the input files.
.It Fl S Ar size, Fl Fl buffer-size Ns = Ns Ar size
Use
.Ar size
@@ -116,38 +114,30 @@
the ordering options override
all global ordering options for that key.
.Bl -tag -width indent
+.It Fl b, Fl Fl ignore-leading-blanks
+Ignores the leading blank characters when comparing lines.
+The current setting of LC_TYPE might affect the concrete behavior.
.It Fl d , Fl Fl dictionary-order
Only blank space and alphanumeric characters
-.\" according
-.\" to the current setting of LC_CTYPE
are used in making comparisons.
+The current setting of LC_TYPE might affect the concrete behavior.
.It Fl f , Fl Fl ignore-case
Considers all lowercase characters that have uppercase
equivalents to be the same for purposes of comparison.
-.It Fl H
-Use a merge sort instead of a radix sort.
-This option should be used for files larger than 60Mb.
+.It Fl g, Fl Fl general-numeric-sort
+Sort by general numerical value.
.It Fl i , Fl Fl ignore-nonprinting
Ignore all non-printable characters.
+.It Fl M, Fl Fl month-sort
+Used to sort by month abbreviations.
+Unknown strings will come first then come month names in ascending
+order.
.It Fl n , Fl Fl numeric-sort
An initial numeric string, consisting of optional blank space, optional
minus sign, and zero or more digits (including decimal point)
-.\" with
-.\" optional radix character and thousands
-.\" separator
-.\" (as defined in the current locale),
is sorted by arithmetic value.
-(The
-.Fl n
-option no longer implies the
-.Fl b
-option.)
.It Fl r , Fl Fl reverse
Reverse the sense of comparisons.
-.It Fl s , Fl Fl stable
-Enable stable sort.
-Uses additional resources (see
-.Xr sradixsort 3 ) .
.El
.Pp
The treatment of field separators can be altered using these options:
@@ -192,13 +182,6 @@
.Cm \(pl Ns Ar pos1
and
.Fl Ns Ar pos2 .
-.It Fl R Ar char
-.Ar char
-is used as the record separator character.
-This should be used with discretion;
-.Fl R Aq Ar alphanumeric
-usually produces undesirable results.
-The default record separator is newline.
.It Fl t Ar char , Fl Fl field-separator Ns = Ns Ar char
.Ar char
is used as the field separator character.
==== //depot/projects/soc2008/gabor_textproc/newsort/sort.c#4 (text+ko) ====
@@ -64,7 +64,7 @@
wchar_t **list;
wchar_t field_sep = L' ';
char **tempfiles;
-char *tmpdir = "/tmp";
+char *tmpdir = "/var/tmp";
unsigned long sfield, lfield;
unsigned long long bufsiz = 0;
bool cflag;
@@ -123,6 +123,17 @@
setlocale(LC_ALL, "");
+ if ((sptr = getenv("TMPDIR")) != NULL) {
+ stat(sptr, &st);
+
+ if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ err(2, NULL);
+ }
+
+ tmpdir = sptr;
+ }
+
while (((c = getopt_long(argc, argv, OPTIONS, long_options, NULL)) != -1)) {
switch (c) {
case 'b':
@@ -152,19 +163,19 @@
sfield = strtoul(optarg, &eptr, 10);
if (((errno == ERANGE) && (sfield == ULONG_MAX)) ||
((errno == EINVAL) && (sfield == 0)))
- err(1, NULL);
+ err(2, NULL);
else if (eptr[0] != ',') {
errno = EINVAL;
- err(1, NULL);
+ err(2, NULL);
}
lfield = strtoul(&sptr[1], &eptr, 10);
if (((errno == ERANGE) && (lfield == ULONG_MAX)) ||
((errno == EINVAL) && (lfield == 0)))
- err(1, NULL);
+ err(2, NULL);
else if (eptr[0] != '\0') {
errno = EINVAL;
- err(1, NULL);
+ err(2, NULL);
}
} else {
char *eptr;
@@ -172,10 +183,10 @@
sfield = lfield = strtoul(optarg, &eptr, 10);
if (((errno == ERANGE) && (sfield == ULONG_MAX)) ||
((errno == EINVAL) && (sfield == 0)))
- err(1, NULL);
+ err(2, NULL);
else if (eptr[0] != '\0') {
errno = EINVAL;
- err(1, NULL);
+ err(2, NULL);
}
}
break;
@@ -200,7 +211,7 @@
case 'S':
bufsiz = strtoull(optarg, (char **)NULL, 10);
if ((errno == ERANGE) && (bufsiz == ULLONG_MAX))
- err(1, NULL);
+ err(2, NULL);
break;
case 't':
if (strlen(optarg) > 1)
@@ -210,7 +221,7 @@
if (field_sep == WEOF) {
errno = EINVAL;
- err(1, NULL);
+ err(2, NULL);
}
printf("field_sep = %lc\n", field_sep);
}
@@ -218,8 +229,10 @@
case 'T':
stat(optarg, &st);
- if (!S_ISDIR(st.st_mode))
- err(1, "argument is not a directory");
+ if (!S_ISDIR(st.st_mode)) {
+ errno = ENOTDIR;
+ err(2, NULL);
+ }
tmpdir = sort_malloc(sizeof(char) * (strlen(optarg) + 2));
strlcpy(tmpdir, optarg, strlen(optarg) + 1);
More information about the p4-projects
mailing list