summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-05-02 02:45:43 +0000
committerJim Meyering <jim@meyering.net>1996-05-02 02:45:43 +0000
commit389c4049b337a8e9a241544c1d33ac1292bbb0e8 (patch)
tree0cb204e371031acc180805b9a2d3789833a1c6e1
parenta9ec4db8f2f2fde750a9bf5fb67e13d33442a451 (diff)
downloadcoreutils-389c4049b337a8e9a241544c1d33ac1292bbb0e8.tar.xz
(parse_ls_color, usage): Remove support for alternate spellings:
--colours and LS_COLOURS. (parse_ls_color): Reverse sense of test for LS_COLORS environment variable and return -- save a level of indentation on a 100+-line block.
-rw-r--r--src/ls.c172
1 files changed, 87 insertions, 85 deletions
diff --git a/src/ls.c b/src/ls.c
index 8afbbf798..a5641d0b4 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1303,114 +1303,116 @@ parse_ls_color (void)
struct col_ext_type *ext; /* Extension we are working on */
struct col_ext_type *ext2; /* Extra pointer */
+ if ((p = getenv ("LS_COLORS")) == NULL || *p == '\0')
+ return;
+
+ ext = NULL;
strcpy (label, "??");
- if (((p = getenv ("LS_COLORS")) != NULL && *p != '\0'))
+
+ /* This is an overly conservative estimate, but any possible
+ LS_COLORS string will *not* generate a color_buf longer than
+ itself, so it is a safe way of allocating a buffer in
+ advance. */
+ buf = color_buf = xstrdup (p);
+
+ state = 1;
+ while (state > 0)
{
- buf = color_buf = xstrdup (p);
- /* This is an overly conservative estimate, but any possible
- LS_COLORS string will *not* generate a color_buf longer than
- itself, so it is a safe way of allocating a buffer in
- advance. */
-
- state = 1;
- while (state > 0)
+ switch (state)
{
- switch (state)
+ case 1: /* First label character */
+ switch (*p)
{
- case 1: /* First label character */
- switch (*p)
- {
- case ':':
- ++p;
- break;
-
- case '*':
- /* Allocate new extension block and add to head of
- linked list (this way a later definition will
- override an earlier one, which can be useful for
- having terminal-specific defs override global). */
+ case ':':
+ ++p;
+ break;
- ext = (struct col_ext_type *)
- xmalloc (sizeof (struct col_ext_type));
- ext->next = col_ext_list;
- col_ext_list = ext;
+ case '*':
+ /* Allocate new extension block and add to head of
+ linked list (this way a later definition will
+ override an earlier one, which can be useful for
+ having terminal-specific defs override global). */
- ++p;
- ext->ext.string = buf;
+ ext = (struct col_ext_type *)
+ xmalloc (sizeof (struct col_ext_type));
+ ext->next = col_ext_list;
+ col_ext_list = ext;
- state = (ext->ext.len =
- get_funky_string (&buf, &p, 1)) < 0 ? -1 : 4;
- break;
+ ++p;
+ ext->ext.string = buf;
- case '\0':
- state = 0; /* Done! */
- break;
+ state = (ext->ext.len =
+ get_funky_string (&buf, &p, 1)) < 0 ? -1 : 4;
+ break;
- default: /* Assume it is file type label */
- label[0] = *(p++);
- state = 2;
- break;
- }
+ case '\0':
+ state = 0; /* Done! */
break;
- case 2: /* Second label character */
- if (*p)
- {
- label[1] = *(p++);
- state = 3;
- }
- else
- state = -1; /* Error */
+ default: /* Assume it is file type label */
+ label[0] = *(p++);
+ state = 2;
break;
+ }
+ break;
+
+ case 2: /* Second label character */
+ if (*p)
+ {
+ label[1] = *(p++);
+ state = 3;
+ }
+ else
+ state = -1; /* Error */
+ break;
- case 3: /* Equal sign after indicator label */
- state = -1; /* Assume failure... */
- if (*(p++) == '=')/* It *should* be... */
+ case 3: /* Equal sign after indicator label */
+ state = -1; /* Assume failure... */
+ if (*(p++) == '=')/* It *should* be... */
+ {
+ for (ind_no = 0; indicator_name[ind_no] != NULL; ++ind_no)
{
- for (ind_no = 0; indicator_name[ind_no] != NULL; ++ind_no)
+ if (strcmp (label, indicator_name[ind_no]) == 0)
{
- if (strcmp (label, indicator_name[ind_no]) == 0)
- {
- color_indicator[ind_no].string = buf;
- state = ((color_indicator[ind_no].len =
- get_funky_string (&buf, &p, 0)) < 0 ?
- -1 : 1);
- break;
- }
+ color_indicator[ind_no].string = buf;
+ state = ((color_indicator[ind_no].len =
+ get_funky_string (&buf, &p, 0)) < 0 ?
+ -1 : 1);
+ break;
}
- if (state == -1)
- error (0, 0, _("unrecognized prefix: %s"), label);
}
- break;
+ if (state == -1)
+ error (0, 0, _("unrecognized prefix: %s"), label);
+ }
+ break;
- case 4: /* Equal sign after *.ext */
- if (*(p++) == '=')
- {
- ext->seq.string = buf;
- state = (ext->seq.len =
- get_funky_string (&buf, &p, 0)) < 0 ? -1 : 1;
- }
- else
- state = -1;
- break;
+ case 4: /* Equal sign after *.ext */
+ if (*(p++) == '=')
+ {
+ ext->seq.string = buf;
+ state = (ext->seq.len =
+ get_funky_string (&buf, &p, 0)) < 0 ? -1 : 1;
}
+ else
+ state = -1;
+ break;
}
+ }
- if (state < 0)
- {
- struct col_ext_type *e;
+ if (state < 0)
+ {
+ struct col_ext_type *e;
- error (0, 0,
- _("unparsable value for LS_COLORS environment variable"));
- free (color_buf);
- for (e = col_ext_list; e != NULL ; /* empty */)
- {
- ext2 = e;
- e = e->next;
- free (ext2);
- }
- print_with_color = 0;
+ error (0, 0,
+ _("unparsable value for LS_COLORS environment variable"));
+ free (color_buf);
+ for (e = col_ext_list; e != NULL ; /* empty */)
+ {
+ ext2 = e;
+ e = e->next;
+ free (ext2);
}
+ print_with_color = 0;
}
}