Delete the unnecessary ERR and ERRC lines in makefiles, add some functionality
to error code script: it can now find untranslatable function codes (usually
because the function is static and not defined in a header: occasionally because
of a typo...) and unreferenced function and reason codes. To see this try:
perl util/mkerr.pl -recurse -debug
Also fixed some typos in crypto/pkcs12 that this found :-)
Also tidy up some error calls that had to be all on one line: the old error
script couldn't find codes unless the call was all on one line.
diff --git a/CHANGES b/CHANGES
index bc74b8b..4a0d597 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,7 +13,8 @@
      aren't needed for error creation any more) and do a better job of
      translating function codes into names. The old 'ASN1 error code imbedded
      in a comment' is no longer necessary and it doesn't use .err files which
-     have now been deleted.
+     have now been deleted. Also the error code call doesn't have to appear all
+     on one line (which resulted in some large lines...).
      [Steve Henson]
 
   *) Change #include filenames from <foo.h> to <openssl/foo.h>.
diff --git a/crypto/Makefile.ssl b/crypto/Makefile.ssl
index dbb1950..e4a0c22 100644
--- a/crypto/Makefile.ssl
+++ b/crypto/Makefile.ssl
@@ -20,8 +20,6 @@
  
 CFLAGS= $(INCLUDE) $(CFLAG) -DCFLAGS="\"$(CC) $(CFLAG)\"" -DPLATFORM="\"$(PLATFORM)\""
 
-ERR=crypto
-ERRC=cpt_err
 
 LIBS=
 
diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl
index 7c9c5d7..284a989 100644
--- a/crypto/asn1/Makefile.ssl
+++ b/crypto/asn1/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=asn1
-ERRC=asn1_err
 GENERAL=Makefile README
 TEST=
 APPS=
diff --git a/crypto/bio/Makefile.ssl b/crypto/bio/Makefile.ssl
index a80b449..1d7f83c 100644
--- a/crypto/bio/Makefile.ssl
+++ b/crypto/bio/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=bio
-ERRC=bio_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/bn/Makefile.ssl b/crypto/bn/Makefile.ssl
index b36475d..fffd150 100644
--- a/crypto/bn/Makefile.ssl
+++ b/crypto/bn/Makefile.ssl
@@ -19,8 +19,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=bn
-ERRC=bn_err
 GENERAL=Makefile
 TEST=bntest.c exptest.c
 APPS=
diff --git a/crypto/buffer/Makefile.ssl b/crypto/buffer/Makefile.ssl
index d7ef1a4..4904761 100644
--- a/crypto/buffer/Makefile.ssl
+++ b/crypto/buffer/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=buffer
-ERRC=buf_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/comp/Makefile.ssl b/crypto/comp/Makefile.ssl
index dccd2ec..89620a8 100644
--- a/crypto/comp/Makefile.ssl
+++ b/crypto/comp/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=comp
-ERRC=comp_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/conf/Makefile.ssl b/crypto/conf/Makefile.ssl
index 54feb66..28f7f61 100644
--- a/crypto/conf/Makefile.ssl
+++ b/crypto/conf/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=conf
-ERRC=conf_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/dh/Makefile.ssl b/crypto/dh/Makefile.ssl
index a74c128..8fc3fe8 100644
--- a/crypto/dh/Makefile.ssl
+++ b/crypto/dh/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=dh
-ERRC=dh_err
 GENERAL=Makefile
 TEST= dhtest.c
 APPS=
diff --git a/crypto/dsa/Makefile.ssl b/crypto/dsa/Makefile.ssl
index 6292943..850229d 100644
--- a/crypto/dsa/Makefile.ssl
+++ b/crypto/dsa/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=dsa
-ERRC=dsa_err
 GENERAL=Makefile
 TEST=dsatest.c
 APPS=
diff --git a/crypto/evp/Makefile.ssl b/crypto/evp/Makefile.ssl
index 8761307..b74ad11 100644
--- a/crypto/evp/Makefile.ssl
+++ b/crypto/evp/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=evp
-ERRC=evp_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/objects/Makefile.ssl b/crypto/objects/Makefile.ssl
index 8accd34..eca0223 100644
--- a/crypto/objects/Makefile.ssl
+++ b/crypto/objects/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=objects
-ERRC=obj_err
 GENERAL=Makefile README
 TEST=
 APPS=
diff --git a/crypto/pem/Makefile.ssl b/crypto/pem/Makefile.ssl
index 44dc6c5..5470df3 100644
--- a/crypto/pem/Makefile.ssl
+++ b/crypto/pem/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=pem
-ERRC=pem_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/pkcs12/Makefile.ssl b/crypto/pkcs12/Makefile.ssl
index 4d1aac3..b4d5a53 100644
--- a/crypto/pkcs12/Makefile.ssl
+++ b/crypto/pkcs12/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=pkcs12
-ERRC=pk12err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c
index 3e203a1..b5858d1 100644
--- a/crypto/pkcs12/p12_add.c
+++ b/crypto/pkcs12/p12_add.c
@@ -91,7 +91,7 @@
 {
 	PKCS12_SAFEBAG *bag;
 	if (!(bag = PKCS12_SAFEBAG_new())) {
-		PKCS12err(PKCS12_F_PKCS12_MAKE_SAFEBAG, ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG,ERR_R_MALLOC_FAILURE);
 		return NULL;
 	}
 	bag->type = OBJ_nid2obj(NID_keyBag);
@@ -128,12 +128,12 @@
 {
 	PKCS7 *p7;
 	if (!(p7 = PKCS7_new())) {
-		PKCS12err(PKCS12_F_PKCS12_PACK_P7_DATA, ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
 		return NULL;
 	}
 	p7->type = OBJ_nid2obj(NID_pkcs7_data);
 	if (!(p7->d.data = ASN1_OCTET_STRING_new())) {
-		PKCS12err(PKCS12_F_PKCS12_PACK_P7_DATA, ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE);
 		return NULL;
 	}
 	
diff --git a/crypto/pkcs12/p12_attr.c b/crypto/pkcs12/p12_attr.c
index 220d7a6..0bd91e3 100644
--- a/crypto/pkcs12/p12_attr.c
+++ b/crypto/pkcs12/p12_attr.c
@@ -151,7 +151,8 @@
 	unsigned char *uniname;
 	int ret, unilen;
 	if (!asc2uni(name, &uniname, &unilen)) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_ASC,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	ret = PKCS12_add_friendlyname_uni (bag, uniname, unilen);
@@ -169,34 +170,40 @@
 	/* Zap ending double null if included */
 	if(!name[namelen - 1] && !name[namelen - 2]) namelen -= 2;
 	if (!(fname = ASN1_TYPE_new ())) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_UNI,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	fname->type = V_ASN1_BMPSTRING;
 	if (!(bmp = ASN1_BMPSTRING_new())) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_UNI,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	if (!(bmp->data = Malloc (namelen))) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_UNI,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	memcpy (bmp->data, name, namelen);
 	bmp->length = namelen;
 	fname->value.bmpstring = bmp;
 	if (!(attrib = X509_ATTRIBUTE_new ())) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_UNI,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	attrib->object = OBJ_nid2obj(NID_friendlyName);
 	if (!(attrib->value.set = sk_new(NULL))) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME,ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	sk_push (attrib->value.set, (char *)fname);
 	attrib->set = 1;
 	if (!bag->attrib && !(bag->attrib = sk_new (NULL))) {
-		PKCS12err(PKCS12_F_ADD_FRIENDLYNAME_UNI, ERR_R_MALLOC_FAILURE);
+		PKCS12err(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,
+							ERR_R_MALLOC_FAILURE);
 		return 0;
 	}
 	sk_push (bag->attrib, (char *)attrib);
diff --git a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c
index 2e9c31d..d1c35ea 100644
--- a/crypto/pkcs12/p12_mutl.c
+++ b/crypto/pkcs12/p12_mutl.c
@@ -123,15 +123,15 @@
 	if (!md_type) md_type = EVP_sha1();
 	if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
 				 	PKCS12_ERROR) {
-		PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_SETUP_ERROR);
+		PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
 		return 0;
 	}
 	if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
-		PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_GENERATION_ERROR);
+		PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
 		return 0;
 	}
 	if (!(ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
-		PKCS12err(PKCS12_F_PKCS12_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
+		PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
 						return 0;
 	}
 	return 1;
diff --git a/crypto/pkcs12/pk12err.c b/crypto/pkcs12/pk12err.c
index c02ff00..1649245 100644
--- a/crypto/pkcs12/pk12err.c
+++ b/crypto/pkcs12/pk12err.c
@@ -65,13 +65,14 @@
 #ifndef NO_ERR
 static ERR_STRING_DATA PKCS12_str_functs[]=
 	{
-{ERR_PACK(0,PKCS12_F_ADD_FRIENDLYNAME,0),	"ADD_FRIENDLYNAME"},
-{ERR_PACK(0,PKCS12_F_ADD_FRIENDLYNAME_ASC,0),	"ADD_FRIENDLYNAME_ASC"},
-{ERR_PACK(0,PKCS12_F_ADD_FRIENDLYNAME_UNI,0),	"ADD_FRIENDLYNAME_UNI"},
 {ERR_PACK(0,PKCS12_F_PARSE_BAGS,0),	"PARSE_BAGS"},
+{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME,0),	"PKCS12_ADD_FRIENDLYNAME"},
+{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC,0),	"PKCS12_add_friendlyname_asc"},
+{ERR_PACK(0,PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI,0),	"PKCS12_add_friendlyname_uni"},
 {ERR_PACK(0,PKCS12_F_PKCS12_ADD_LOCALKEYID,0),	"PKCS12_add_localkeyid"},
 {ERR_PACK(0,PKCS12_F_PKCS12_CREATE,0),	"PKCS12_create"},
 {ERR_PACK(0,PKCS12_F_PKCS12_DECRYPT_D2I,0),	"PKCS12_decrypt_d2i"},
+{ERR_PACK(0,PKCS12_F_PKCS12_FRIENDLYNAME_ASC,0),	"PKCS12_FRIENDLYNAME_ASC"},
 {ERR_PACK(0,PKCS12_F_PKCS12_GEN_MAC,0),	"PKCS12_gen_mac"},
 {ERR_PACK(0,PKCS12_F_PKCS12_I2D_ENCRYPT,0),	"PKCS12_i2d_encrypt"},
 {ERR_PACK(0,PKCS12_F_PKCS12_INIT,0),	"PKCS12_init"},
@@ -122,17 +123,46 @@
 
 #endif
 
-void ERR_load_PKCS12_strings(void)
+#ifdef PKCS12_LIB_NAME
+static ERR_STRING_DATA PKCS12_lib_name[]=
+        {
+{0	,PKCS12_LIB_NAME},
+{0,NULL}
+	};
+#endif
+
+
+int PKCS12_lib_error_code=0;
+
+void ERR_load_PKCS12_strings()
 	{
 	static int init=1;
 
+	if (PKCS12_lib_error_code == 0)
+		PKCS12_lib_error_code=ERR_get_next_error_library();
+
 	if (init)
 		{
 		init=0;
 #ifndef NO_ERR
-		ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_functs);
-		ERR_load_strings(ERR_LIB_PKCS12,PKCS12_str_reasons);
+		ERR_load_strings(PKCS12_lib_error_code,PKCS12_str_functs);
+		ERR_load_strings(PKCS12_lib_error_code,PKCS12_str_reasons);
 #endif
 
+#ifdef PKCS12_LIB_NAME
+		PKCS12_lib_name->error = ERR_PACK(PKCS12_lib_error_code,0,0);
+		ERR_load_strings(0,PKCS12_lib_name);
+#endif;
 		}
 	}
+
+void ERR_PKCS12_error(function,reason,file,line)
+int function;
+int reason;
+char *file;
+int line;
+	{
+	if (PKCS12_lib_error_code == 0)
+		PKCS12_lib_error_code=ERR_get_next_error_library();
+	ERR_PUT_error(PKCS12_lib_error_code,function,reason,file,line);
+	}
diff --git a/crypto/pkcs12/pkcs12.h b/crypto/pkcs12/pkcs12.h
index 4dd0d28..4ba27db 100644
--- a/crypto/pkcs12/pkcs12.h
+++ b/crypto/pkcs12/pkcs12.h
@@ -321,10 +321,10 @@
 /* Error codes for the PKCS12 functions. */
 
 /* Function codes. */
-#define PKCS12_F_ADD_FRIENDLYNAME			 100
-#define PKCS12_F_ADD_FRIENDLYNAME_ASC			 101
-#define PKCS12_F_ADD_FRIENDLYNAME_UNI			 102
 #define PKCS12_F_PARSE_BAGS				 103
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME		 100
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC		 127
+#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI		 102
 #define PKCS12_F_PKCS12_ADD_LOCALKEYID			 104
 #define PKCS12_F_PKCS12_CREATE				 105
 #define PKCS12_F_PKCS12_DECRYPT_D2I			 106
@@ -333,16 +333,14 @@
 #define PKCS12_F_PKCS12_INIT				 109
 #define PKCS12_F_PKCS12_KEY_GEN_ASC			 110
 #define PKCS12_F_PKCS12_KEY_GEN_UNI			 111
-#define PKCS12_F_PKCS12_MAKE_SAFEBAG			 112
+#define PKCS12_F_PKCS12_MAKE_KEYBAG			 112
 #define PKCS12_F_PKCS12_MAKE_SHKEYBAG			 113
 #define PKCS12_F_PKCS12_PACK_P7DATA			 114
 #define PKCS12_F_PKCS12_PACK_P7ENCDATA			 115
-#define PKCS12_F_PKCS12_PACK_P7_DATA			 116
 #define PKCS12_F_PKCS12_PACK_SAFEBAG			 117
 #define PKCS12_F_PKCS12_PARSE				 118
 #define PKCS12_F_PKCS12_PBE_CRYPT			 119
 #define PKCS12_F_PKCS12_PBE_KEYIVGEN			 120
-#define PKCS12_F_PKCS12_PKCS12_SET_MAC			 121
 #define PKCS12_F_PKCS12_SETUP_MAC			 122
 #define PKCS12_F_PKCS12_SET_MAC				 123
 #define PKCS12_F_PKCS8_ADD_KEYUSAGE			 124
diff --git a/crypto/pkcs7/Makefile.ssl b/crypto/pkcs7/Makefile.ssl
index 65e4459..e81cb1b 100644
--- a/crypto/pkcs7/Makefile.ssl
+++ b/crypto/pkcs7/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=pkcs7
-ERRC=pkcs7err
 GENERAL=Makefile README
 TEST=
 APPS=
diff --git a/crypto/rsa/Makefile.ssl b/crypto/rsa/Makefile.ssl
index 1af5d61..cd90ff5 100644
--- a/crypto/rsa/Makefile.ssl
+++ b/crypto/rsa/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=rsa
-ERRC=rsa_err
 GENERAL=Makefile
 TEST=rsa_oaep_test.c
 APPS=
diff --git a/crypto/x509/Makefile.ssl b/crypto/x509/Makefile.ssl
index 1d4cd05..90ff87c 100644
--- a/crypto/x509/Makefile.ssl
+++ b/crypto/x509/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=x509
-ERRC=x509_err
 GENERAL=Makefile README
 TEST=
 APPS=
diff --git a/crypto/x509v3/Makefile.ssl b/crypto/x509v3/Makefile.ssl
index 4e12faa..a46f10a 100644
--- a/crypto/x509v3/Makefile.ssl
+++ b/crypto/x509v3/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=x509v3
-ERRC=v3err
 GENERAL=Makefile README
 TEST=
 APPS=
diff --git a/rsaref/Makefile.ssl b/rsaref/Makefile.ssl
index 1b16b88..002513f 100644
--- a/rsaref/Makefile.ssl
+++ b/rsaref/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=rsaref
-ERRC=rsar_err
 GENERAL=Makefile
 TEST=
 APPS=
diff --git a/ssl/Makefile.ssl b/ssl/Makefile.ssl
index a4211ac..c51454f 100644
--- a/ssl/Makefile.ssl
+++ b/ssl/Makefile.ssl
@@ -15,8 +15,6 @@
 
 CFLAGS= $(INCLUDES) $(CFLAG)
 
-ERR=ssl
-ERRC=ssl_err
 GENERAL=Makefile README
 TEST=ssltest.c
 APPS=
diff --git a/util/mkerr.pl b/util/mkerr.pl
index 062619d..0293b0b 100644
--- a/util/mkerr.pl
+++ b/util/mkerr.pl
@@ -167,6 +167,8 @@
 # oddly named structure BIO_F_CTX which needs to be ignored.
 # If a code doesn't exist in list compiled from headers then mark it
 # with the value "X" as a place holder to give it a value later.
+# Store all function and reason codes found in %ufcodes and %urcodes
+# so all those unreferenced can be printed out.
 
 
 foreach $file (@source) {
@@ -174,16 +176,19 @@
 	next if exists $cskip{$file};
 	open(IN, "<$file") || die "Can't open source file $file\n";
 	while(<IN>) {
-		if(/(([A-Z0-9]+)_F_[A-Z0-9_]+)/) {
+		if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
 			next unless exists $csrc{$2};
 			next if($1 eq "BIO_F_BUFFER_CTX");
+			$ufcodes{$1} = 1;
 			if(!exists $fcodes{$1}) {
 				$fcodes{$1} = "X";
 				$fnew{$2}++;
 			}
+			$notrans{$1} = 1 unless exists $ftrans{$3};
 		}
 		if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
 			next unless exists $csrc{$2};
+			$urcodes{$1} = 1;
 			if(!exists $rcodes{$1}) {
 				$rcodes{$1} = "X";
 				$rnew{$2}++;
@@ -353,8 +358,6 @@
 		$fn = $1;
 		if(exists $ftrans{$fn}) {
 			$fn = $ftrans{$fn};
-		} else {
-			push @notrans, $i;
 		}
 		print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
 	}
@@ -452,9 +455,35 @@
 
 }
 
-if($debug && defined(@notrans)) {
+if($debug && defined(%notrans)) {
 	print STDERR "The following function codes were not translated:\n";
-	foreach(@notrans)
+	foreach(sort keys %notrans)
+	{
+		print STDERR "$_\n";
+	}
+}
+
+# Make a list of unreferenced function and reason codes
+
+foreach (keys %fcodes) {
+	push (@funref, $_) unless exists $ufcodes{$_};
+}
+
+foreach (keys %rcodes) {
+	push (@runref, $_) unless exists $urcodes{$_};
+}
+
+if($debug && defined(@funref) ) {
+	print STDERR "The following function codes were not referenced:\n";
+	foreach(sort @funref)
+	{
+		print STDERR "$_\n";
+	}
+}
+
+if($debug && defined(@runref) ) {
+	print STDERR "The following reason codes were not referenced:\n";
+	foreach(sort @runref)
 	{
 		print STDERR "$_\n";
 	}