/* Handle aliases for locale names Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
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. */
#ifdef _LIBC /* Rename the non ANSI C functions. This is required by the standard because some ANSI C functions will require linking with this object
file and the name space must not be polluted. */ # define strcasecmp __strcasecmp #endif
/* For those loosing systems which don't have `alloca' we have to add
some additional code emulating it. */ #ifdef HAVE_ALLOCA /* Nothing has to be done. */ # define ADD_BLOCK(list, address) /* nothing */ # define FREE_BLOCKS(list) /* nothing */ #else struct block_list
{ void *address; struct block_list *next;
}; # define ADD_BLOCK(list, addr) \ do { \ struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ /* If we cannot get a free block we cannot add the new element to \
the list. */ if (newp != NULL) { \
newp->address = (addr); \
newp->next = (list); \
(list) = newp; \
} \
} while (0) # define FREE_BLOCKS(list) \ do { \ while (list != NULL) { \ struct block_list *old = list; \
list = list->next; \
free (old); \
} \
} while (0) # undef alloca # define alloca(size) (malloc (size)) #endif/* have alloca */
added = 0; while (!feof (fp))
{ /* It is a reasonable approach to use a fix buffer here because a) we are only interested in the first two fields b) these fields must be usable as file names and so must not be that long
*/ char buf[BUFSIZ]; char *alias; char *value; char *cp;
cp = buf; /* Ignore leading white space. */ while (isspace (cp[0]))
++cp;
/* A leading '#' signals a comment line. */ if (cp[0] != '\0' && cp[0] != '#')
{
alias = cp++; while (cp[0] != '\0' && !isspace (cp[0]))
++cp; /* Terminate alias name. */ if (cp[0] != '\0')
*cp++ = '\0';
/* Now look for the beginning of the value. */ while (isspace (cp[0]))
++cp;
if (cp[0] != '\0')
{ char *tp;
size_t len;
value = cp++; while (cp[0] != '\0' && !isspace (cp[0]))
++cp; /* Terminate value. */ if (cp[0] == '\n')
{ /* This has to be done to make the following test for the end of line possible. We are looking for
the terminating '\n' which do not overwrite here. */
*cp++ = '\0';
*cp = '\n';
} elseif (cp[0] != '\0')
*cp++ = '\0';
if (nmap >= maxmap)
extend_alias_table ();
/* We cannot depend on strdup available in the libc. Sigh! */
len = strlen (alias) + 1;
tp = (char *) malloc (len); if (tp == NULL)
{
FREE_BLOCKS (block_list); return added;
}
memcpy (tp, alias, len);
map[nmap].alias = tp;
/* Possibly not the whole line fits into the buffer. Ignore
the rest of the line. */ while (strchr (cp, '\n') == NULL)
{
cp = buf; if (fgets (buf, BUFSIZ, fp) == NULL) /* Make sure the inner loop will be left. The outer loop
will exit at the `feof' test. */
*cp = '\n';
}
}
/* Should we test for ferror()? I think we have to silently ignore
errors. --drepper */
fclose (fp);
do
{ /* I know this seems to be odd but the tolower() function in
some systems libc cannot handle nonalpha characters. */
c1 = isupper (*p1) ? tolower (*p1) : *p1;
c2 = isupper (*p2) ? tolower (*p2) : *p2; if (c1 == '\0') break;
++p1;
++p2;
} while (c1 == c2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.