Some instructions for how to handle the <foo.h> => <openssl/foo.h>
[openssl.git] / crypto / err / err_genc.pl
index 6733cfe..af4d515 100644 (file)
@@ -1,6 +1,8 @@
 #!/usr/local/bin/perl
 
-($#ARGV == 1) || die "usage: $0 <header file> <output C file>\n";
+if ($ARGV[0] eq "-s") { $static=1; shift @ARGV; }
+
+($#ARGV == 1) || die "usage: $0 [-s] <header file> <output C file>\n";
 open(IN,"<$ARGV[0]") || die "unable to open $ARGV[0]:$!\n";
 open(STDOUT,">$ARGV[1]") || die "unable to open $ARGV[1]:$!\n";
 
@@ -53,24 +55,92 @@ close(IN);
 
 foreach (sort keys %out)
        {
-       print "static ERR_STRING_DATA ${_}[]=\n\t{\n";
+       print "static ERR_STRING_DATA ${_}\[\]=\n\t{\n";
        print $out{$_};
        print "{0,NULL},\n";
        print "\t};\n\n";
+       }
+print "#endif\n";
+
+if ($static)
+       { $lib="ERR_LIB_$type"; }
+else
+       { 
+       print <<"EOF";
+
+#ifdef ${type}_LIB_NAME
+static ERR_STRING_DATA ${type}_lib_name[]=
+        {
+{0     ,${type}_LIB_NAME},
+{0,NULL}
+       };
+#endif
+
+EOF
+       $lib="${type}_lib_error_code"; 
+
+
+
        }
 
-print "void ERR_load_${type}_strings()\n";
-print "\t{\n";
-print "\tstatic int init=1;\n\n";
-print "\tif (init)\n";
-print "\t\t{\n";
-print "\t\tinit=0;\n";
-print "\t\tERR_load_strings(ERR_LIB_$type,${type}_str_functs);\n"
-       if $Func;
-print "\t\tERR_load_strings(ERR_LIB_$type,${type}_str_reasons);\n"
-       if $Reas;
-print "\t\t}\n";
-print "\t}\n";
+$str="";
+$str.="#ifndef NO_ERR\n";
+$str.="\t\tERR_load_strings($lib,${type}_str_functs);\n" if $Func;
+$str.="\t\tERR_load_strings($lib,${type}_str_reasons);\n" if $Reas;
+$str.="#endif\n";
+
+if (!$static)
+       {
+print <<"EOF";
+
+int ${type}_lib_error_code=0;
+
+void ERR_load_${type}_strings()
+       {
+       static int init=1;
+
+       if (${type}_lib_error_code == 0)
+               ${type}_lib_error_code=ERR_get_next_error_library();
+
+       if (init)
+               {
+               init=0;
+$str
+#ifdef ${type}_LIB_NAME
+               ${type}_lib_name->error = ERR_PACK(${type}_lib_error_code,0,0);
+               ERR_load_strings(0,${type}_lib_name);
+#endif;
+               }
+       }
+
+void ERR_${type}_error(function,reason,file,line)
+int function;
+int reason;
+char *file;
+int line;
+       {
+       if (${type}_lib_error_code == 0)
+               ${type}_lib_error_code=ERR_get_next_error_library();
+       ERR_PUT_error(${type}_lib_error_code,function,reason,file,line);
+       }
+EOF
+       }
+else # $static
+       {
+       print <<"EOF";
+
+void ERR_load_${type}_strings()
+       {
+       static int init=1;
+
+       if (init)
+               {
+               init=0;
+$str
+               }
+       }
+EOF
+       }
 
 sub header
        {
@@ -140,8 +210,9 @@ sub header
 EOF
 
        print "#include <stdio.h>\n";
-       print "#include \"err.h\"\n";
-       print "#include \"$header\"\n";
+       print "#include <openssl/err.h>\n";
+       print "#include <openssl/$header>\n";
        print "\n/* BEGIN ERROR CODES */\n";
+       print "#ifndef NO_ERR\n";
        }