Blame sysdeps/gnu/errlist.awk

Packit 6c4009
# Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# errno.texi contains lines like:
Packit 6c4009
# @deftypevr Macro int ENOSYS
Packit 6c4009
# @errno{ENOSYS, 78, Function not implemented}
Packit 6c4009
# Descriptive paragraph...
Packit 6c4009
# @end deftypevr
Packit 6c4009
Packit 6c4009
BEGIN {
Packit 6c4009
Packit 6c4009
    # Here we list the E* names that might be duplicate names for the
Packit 6c4009
    # same integer value on some systems.  This causes the code below
Packit 6c4009
    # to generate ``#if defined (ALIAS) && ALIAS != ORIGINAL'' in the code,
Packit 6c4009
    # so the output does not presume that these are in fact aliases.
Packit 6c4009
    # We list here all the known potential cases on any system,
Packit 6c4009
    # so that the C source we produce will do the right thing based
Packit 6c4009
    # on the actual #define'd values it's compiled with.
Packit 6c4009
    alias["EWOULDBLOCK"]= "EAGAIN";
Packit 6c4009
    alias["EDEADLOCK"]	= "EDEADLK";
Packit 6c4009
    alias["ENOTSUP"]	= "EOPNOTSUPP";
Packit 6c4009
Packit 6c4009
    print "/* This file is generated from errno.texi by errlist.awk.  */"
Packit 6c4009
    print "";
Packit 6c4009
    print "#include <errno.h>";
Packit 6c4009
    print "#include <libintl.h>";
Packit 6c4009
    print "";
Packit 6c4009
    print "#ifndef ERR_REMAP";
Packit 6c4009
    print "# define ERR_REMAP(n) n";
Packit 6c4009
    print "#endif";
Packit 6c4009
    print "";
Packit 6c4009
Packit 6c4009
    print "#if !defined EMIT_ERR_MAX && !defined ERRLIST_NO_COMPAT";
Packit 6c4009
    print "# include <errlist-compat.h>";
Packit 6c4009
    print "#endif";
Packit 6c4009
    print "#ifdef ERR_MAX";
Packit 6c4009
    print "# define ERRLIST_SIZE ERR_MAX + 1";
Packit 6c4009
    print "#else"
Packit 6c4009
    print "# define ERR_MAX 0";
Packit 6c4009
    print "# define ERRLIST_SIZE";
Packit 6c4009
    print "#endif";
Packit 6c4009
Packit 6c4009
    print "const char *const _sys_errlist_internal[ERRLIST_SIZE] =";
Packit 6c4009
    print "  {";
Packit 6c4009
    print "    [0] = N_(\"Success\"),"
Packit 6c4009
  }
Packit 6c4009
Packit 6c4009
/^@errno\{/ \
Packit 6c4009
  {
Packit 6c4009
    etext = $3;
Packit 6c4009
    for (i = 4; i <= NF; ++i)
Packit 6c4009
      etext = etext " " $i;
Packit 6c4009
    etext = substr(etext, 1, length(etext)-1)
Packit 6c4009
    e = substr($1, 8, length($1)-8)
Packit 6c4009
    errno = substr($2, 1, length($2)-1) + 0
Packit 6c4009
    if (alias[e])
Packit 6c4009
      printf "#if defined (%s) && %s != %s\n", e, e, alias[e];
Packit 6c4009
    else
Packit 6c4009
      printf "#ifdef %s\n", e;
Packit 6c4009
    errnoh = 4;
Packit 6c4009
    desc="";
Packit 6c4009
    next;
Packit 6c4009
  }
Packit 6c4009
errnoh == 4 && $1 == "@end" && $2 == "deftypevr" \
Packit 6c4009
  {
Packit 6c4009
    printf "/*%s */\n", desc;
Packit 6c4009
    printf "    [ERR_REMAP (%s)] = N_(\"%s\"),\n", e, etext;
Packit 6c4009
    printf "# if %s > ERR_MAX\n", e;
Packit 6c4009
    print  "# undef ERR_MAX";
Packit 6c4009
    printf "# define ERR_MAX %s\n", e;
Packit 6c4009
    print  "# endif";
Packit 6c4009
    print "#endif";
Packit 6c4009
    errnoh = 0;
Packit 6c4009
    next;
Packit 6c4009
  }
Packit 6c4009
errnoh == 4 \
Packit 6c4009
  {
Packit 6c4009
    # This magic tag in C comments gets them copied into libc.pot.
Packit 6c4009
    desc = desc "\nTRANS" ($0 != "" ? " " : "") $0; next
Packit 6c4009
  }
Packit 6c4009
END {
Packit 6c4009
  print "  };";
Packit 6c4009
  print "";
Packit 6c4009
  print "#define NERR \\";
Packit 6c4009
  print "  (sizeof _sys_errlist_internal / sizeof _sys_errlist_internal [0])";
Packit 6c4009
  print "const int _sys_nerr_internal = NERR;"
Packit 6c4009
  print "";
Packit 6c4009
  print "#if IS_IN (libc) && !defined ERRLIST_NO_COMPAT";
Packit 6c4009
  print "# include <errlist-compat.c>";
Packit 6c4009
  print "#endif";
Packit 6c4009
  print "";
Packit 6c4009
  print "#ifdef EMIT_ERR_MAX";
Packit 6c4009
  print "void dummy (void)"
Packit 6c4009
  print "{ asm volatile (\" @@@ %0 @@@ \" : : \"i\" (ERR_REMAP (ERR_MAX))); }"
Packit 6c4009
  print "#endif";
Packit 6c4009
}