Blame src/mkerrnos.awk

Packit fc043f
# mkerrnos.awk
Packit fc043f
# Copyright (C) 2003, 2004 g10 Code GmbH
Packit fc043f
# 
Packit fc043f
# This program is free software; you can redistribute it and/or
Packit fc043f
# modify it under the terms of the GNU General Public License as
Packit fc043f
# published by the Free Software Foundation; either version 2 of
Packit fc043f
# the License, or (at your option) any later version.
Packit fc043f
#
Packit fc043f
# This program is distributed in the hope that it will be useful,
Packit fc043f
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit fc043f
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit fc043f
# General Public License for more details.
Packit fc043f
#
Packit fc043f
# You should have received a copy of the GNU General Public License
Packit fc043f
# along with this program; if not, write to the Free Software
Packit fc043f
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
Packit fc043f
#
Packit fc043f
# As a special exception, g10 Code GmbH gives unlimited permission to
Packit fc043f
# copy, distribute and modify the C source files that are the output
Packit fc043f
# of mkerrnos.awk.  You need not follow the terms of the GNU General
Packit fc043f
# Public License when using or distributing such scripts, even though
Packit fc043f
# portions of the text of mkerrnos.awk appear in them.  The GNU
Packit fc043f
# General Public License (GPL) does govern all other use of the material
Packit fc043f
# that constitutes the mkerrnos.awk program.
Packit fc043f
#
Packit fc043f
# Certain portions of the mkerrnos.awk source text are designed to be
Packit fc043f
# copied (in certain cases, depending on the input) into the output of
Packit fc043f
# mkerrnos.awk.  We call these the "data" portions.  The rest of the
Packit fc043f
# mkerrnos.awk source text consists of comments plus executable code
Packit fc043f
# that decides which of the data portions to output in any given case.
Packit fc043f
# We call these comments and executable code the "non-data" portions.
Packit fc043f
# mkerrnos.h never copies any of the non-data portions into its output.
Packit fc043f
#
Packit fc043f
# This special exception to the GPL applies to versions of mkerrnos.awk
Packit fc043f
# released by g10 Code GmbH.  When you make and distribute a modified version
Packit fc043f
# of mkerrnos.awk, you may extend this special exception to the GPL to
Packit fc043f
# apply to your modified version as well, *unless* your modified version
Packit fc043f
# has the potential to copy into its output some of the text that was the
Packit fc043f
# non-data portion of the version that you started with.  (In other words,
Packit fc043f
# unless your change moves or copies text from the non-data portions to the
Packit fc043f
# data portions.)  If your modification has such potential, you must delete
Packit fc043f
# any notice of this special exception to the GPL from your modified version.
Packit fc043f
Packit fc043f
# This script outputs a source file that does define the following
Packit fc043f
# symbols:
Packit fc043f
#
Packit fc043f
# static const int err_code_to_errno[];
Packit fc043f
# A mapping of gpg_err_code_t numbers to system errno.  The index of an
Packit fc043f
# error code in the table can be obtained after removing the system error
Packit fc043f
# code indication bit.
Packit fc043f
#
Packit fc043f
# The input file is a list of possible system errors in the column errnoidx
Packit fc043f
# (defaults to 2).
Packit fc043f
#
Packit fc043f
# Comments (starting with # and ending at the end of the line) are removed,
Packit fc043f
# as is trailing whitespace.
Packit fc043f
Packit fc043f
BEGIN {
Packit fc043f
  FS="[\t]+";
Packit fc043f
  header = 1;
Packit fc043f
  if (errnoidx == 0)
Packit fc043f
    errnoidx = 2;
Packit fc043f
Packit fc043f
  print "/* Output of mkerrnos.awk.  DO NOT EDIT.  */";
Packit fc043f
  print "";
Packit fc043f
}
Packit fc043f
Packit fc043f
/^#/ { next; }
Packit fc043f
Packit fc043f
header {
Packit fc043f
  if ($1 ~ /^[0-9]/)
Packit fc043f
    {
Packit fc043f
      print "#include <errno.h>";
Packit fc043f
      print "#ifdef _WIN32";
Packit fc043f
      print "#include <winsock2.h>";
Packit fc043f
      print "#endif";
Packit fc043f
      print "";
Packit fc043f
      print "static const int err_code_to_errno [] = {";
Packit fc043f
      header = 0;
Packit fc043f
    }
Packit fc043f
  else
Packit fc043f
    print;
Packit fc043f
}
Packit fc043f
Packit fc043f
!header {
Packit fc043f
  sub (/\#.+/, "");
Packit fc043f
  sub (/[ 	]+$/, ""); # Strip trailing space and tab characters.
Packit fc043f
Packit fc043f
  if (/^$/)
Packit fc043f
    next;
Packit fc043f
Packit fc043f
    print "#ifdef " $errnoidx;
Packit fc043f
    print "  " $errnoidx ",";
Packit fc043f
    print "#else";
Packit fc043f
    print "#ifdef WSA" $errnoidx;
Packit fc043f
    print "  WSA" $errnoidx ",";
Packit fc043f
    print "#else"; 
Packit fc043f
    print "  0,";
Packit fc043f
    print "#endif";
Packit fc043f
    print "#endif";
Packit fc043f
}
Packit fc043f
END {
Packit fc043f
  print "};";
Packit fc043f
}