Blame src/mkerrcodes1.awk

Packit fc043f
# mkerrcodes.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 mkerrcodes.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 mkerrcodes.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 mkerrcodes.awk program.
Packit fc043f
#
Packit fc043f
# Certain portions of the mkerrcodes.awk source text are designed to be
Packit fc043f
# copied (in certain cases, depending on the input) into the output of
Packit fc043f
# mkerrcodes.awk.  We call these the "data" portions.  The rest of the
Packit fc043f
# mkerrcodes.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
# mkerrcodes.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 mkerrcodes.awk
Packit fc043f
# released by g10 Code GmbH.  When you make and distribute a modified version
Packit fc043f
# of mkerrcodes.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 an intermediate file that contains the following block
Packit fc043f
# for each error value symbol in the input file (example for EINVAL):
Packit fc043f
#
Packit fc043f
# #ifdef EINVAL
Packit fc043f
# EINVAL GPG_ERR_EINVAL
Packit fc043f
# #endif
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 mkerrcodes.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
      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 "\tGPG_ERR_" $errnoidx;
Packit fc043f
    print "#endif";
Packit fc043f
    print "#ifdef WSA" $errnoidx;
Packit fc043f
    print "WSA" $errnoidx "\tGPG_ERR_" $errnoidx;
Packit fc043f
    print "#endif";
Packit fc043f
}