Browse Source

Drop prog_name

Fixes SourceForge #3382125
Richard Laager 13 years ago
parent
commit
1c0abdfc85
4 changed files with 21 additions and 32 deletions
  1. 17 25
      src/docsis.c
  2. 3 4
      src/docsis_encode.c
  3. 0 1
      src/docsis_globals.h
  4. 1 2
      src/docsis_yy.y

+ 17 - 25
src/docsis.c

@@ -113,7 +113,7 @@ add_cmts_mic (unsigned char *tlvbuf, unsigned int tlvbuflen,
 	  else
 	    {
 	      if ( cp[0] == 64 ) {
-		printf("%s: warning: TLV64 (length > 255) not allowed in DOCSIS config files\n", prog_name);
+		printf("docsis: warning: TLV64 (length > 255) not allowed in DOCSIS config files\n");
 		cp = cp + (size_t) ntohs(*((unsigned short *)(cp+1))) + 3;
 	      } else {
 	      	cp = cp + cp[1] + 2;
@@ -134,11 +134,11 @@ add_cmts_mic (unsigned char *tlvbuf, unsigned int tlvbuflen,
 }
 
 #ifdef __GNUC__
-static void usage (char *prog_name) __attribute__((__noreturn__));
+static void usage () __attribute__((__noreturn__));
 #endif
 
 static void
-usage (char *prog_name)
+usage ()
 {
   printf ("DOCSIS Configuration File creator, version %s\n", VERSION);
   printf
@@ -147,19 +147,14 @@ usage (char *prog_name)
     ("Copyright (c) 2002,2003,2004,2005 Evvolve Media SRL, docsis@evvolve.com \n\n");
 
   printf
-    ("To encode a cable modem configuration file: \n\t %s -e <modem_cfg_file> <key_file> <output_file>\n",
-     prog_name);
+    ("To encode a cable modem configuration file: \n\t docsis -e <modem_cfg_file> <key_file> <output_file>\n");
   printf
-    ("To encode multiple cable modem configuration files: \n\t %s -m <modem_cfg_file1> ...  <key_file> <new_extension>\n",
-     prog_name);
+    ("To encode multiple cable modem configuration files: \n\t docsis -m <modem_cfg_file1> ...  <key_file> <new_extension>\n");
   printf
-    ("To encode a MTA configuration file: \n\t %s -p <mta_cfg_file> <output_file>\n",
-     prog_name);
+    ("To encode a MTA configuration file: \n\t docsis -p <mta_cfg_file> <output_file>\n");
   printf
-    ("To encode multiple MTA configuration files: \n\t %s -m -p <mta_file1> ...  <new_extension>\n",
-     prog_name);
-  printf ("To decode a CM or MTA config file: \n\t %s -d <binary_file>\n",
-	  prog_name);
+    ("To encode multiple MTA configuration files: \n\t docsis -m -p <mta_file1> ...  <new_extension>\n");
+  printf ("To decode a CM or MTA config file: \n\t docsis -d <binary_file>\n");
   printf
     ("\nWhere:\n<cfg_file>\t\t= name of text (human readable) cable modem or MTA \n\t\t\t  configuration file\n<key_file>\t\t= text file containing the authentication key \n\t\t\t  (shared secret) to be used for the CMTS MIC\n<output_file> \t\t= name of output file where the binary data will\n\t\t\t  be written to (if it does not exist it is created).\n<binary_file>\t\t= name of binary file to be decoded\n<new_extension>\t\t= new extension to be used when encoding multiple files\n");
   printf ("\nSee examples/*.cfg for configuration file format.\n");
@@ -179,17 +174,14 @@ main (int argc, char *argv[])
   unsigned int encode_docsis = FALSE, decode_bin = FALSE;
   int i;
 
-  memset (prog_name, 0, 255);
-  strncpy (prog_name, argv[0], 254);
-
   if (argc < 2 ) {
-	usage(prog_name);
+	usage();
 	exit (10);
   }
 
   if (!strcmp (argv[1], "-m") ){ /* variable number of args, encoding multiple files */
 	if (argc < 5 ) {
-		usage(prog_name);
+		usage();
 		exit (10);
 	}
     	extension_string = argv[argc-1];
@@ -204,21 +196,21 @@ main (int argc, char *argv[])
     	{
     	case 3:
       		if (strcmp (argv[1], "-d"))
-			usage (prog_name);
+			usage ();
       		decode_bin = TRUE;
       		config_file = argv[2];
       		break;
       		;;
     	case 4:
       		if (strcmp (argv[1], "-p"))
-			usage (prog_name);
+			usage ();
       		config_file = argv[2];
       		output_file = argv[3];
       		break;
       		;;
     	case 5:
       		if (strcmp (argv[1], "-e"))
-			usage (prog_name);
+			usage ();
       		encode_docsis = TRUE;
       		config_file = argv[2];
       		key_file = argv[3];
@@ -226,7 +218,7 @@ main (int argc, char *argv[])
       		break;
       		;;
     	default:
-      		usage (prog_name);
+		usage ();
       		exit (10);
     }
   }
@@ -235,7 +227,7 @@ main (int argc, char *argv[])
     {
       if ((kf = fopen (key_file, "r")) == NULL)
 	{
-	  printf ("%s: error: can't open keyfile %s\n", prog_name, key_file);
+	  printf ("docsis: error: can't open keyfile %s\n", key_file);
 	  exit (-5);
 	}
       keylen = fread (key, sizeof (unsigned char), 64, kf);
@@ -307,7 +299,7 @@ int encode_one_file ( char *input_file, char *output_file,
 
   if (!strcmp (input_file, output_file))
   {
-	printf ("%s: Error: source file is the same as destination file\n", prog_name);
+	printf ("docsis: Error: source file is the same as destination file\n");
 	return -1;
   }
 
@@ -350,7 +342,7 @@ int encode_one_file ( char *input_file, char *output_file,
   decode_main_aggregate (buffer, buflen);
   if ((of = fopen (output_file, "wb")) == NULL)
     {
-      printf ("%s: error: can't open output file %s\n", prog_name, output_file);
+      printf ("docsis: error: can't open output file %s\n", output_file);
       return -2;
     }
   fwrite (buffer, sizeof (unsigned char), buflen, of);

+ 3 - 4
src/docsis_encode.c

@@ -33,7 +33,6 @@
 #include <math.h>
 
 #include "docsis_common.h"
-#include "docsis_globals.h"
 #include "docsis_encode.h"
 #include "docsis_snmp.h"
 #include "ethermac.h"
@@ -57,7 +56,7 @@ int encode_uint ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr )
   helper = (union t_val *) tval;
   if ( sym_ptr->low_limit || sym_ptr->high_limit ) {
 	if ( helper->uintval < sym_ptr->low_limit || helper->uintval > sym_ptr->high_limit ) {
-		printf ("%s: at line %d, %s value %d out of range %hd-%hd\n ", prog_name,line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
+		printf ("docsis: at line %d, %s value %d out of range %hd-%hd\n ", line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
 		exit(-15);
 	}
   }
@@ -86,7 +85,7 @@ int encode_ushort ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
   helper = (union t_val *) tval;
   if ( sym_ptr->low_limit || sym_ptr->high_limit ) {
 	if ( helper->uintval < sym_ptr->low_limit || helper->uintval > sym_ptr->high_limit ) {
-		printf ("%s: at line %d, %s value %d out of range %hd-%hd\n ", prog_name,line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
+		printf ("docsis: at line %d, %s value %d out of range %hd-%hd\n ", line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
 		exit(-15);
 	}
   }
@@ -118,7 +117,7 @@ int encode_uchar ( unsigned char *buf, void *tval, struct symbol_entry *sym_ptr
 
   if ( sym_ptr->low_limit || sym_ptr->high_limit ) {
 	if ( helper->uintval < sym_ptr->low_limit || helper->uintval > sym_ptr->high_limit ) {
-		printf ("%s: at line %d, %s value %d out of range %hd-%hd\n ", prog_name,line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
+		printf ("docsis: at line %d, %s value %d out of range %hd-%hd\n ", line,sym_ptr->sym_ident,helper->uintval,sym_ptr->low_limit, sym_ptr->high_limit);
 		exit(-15);
 	}
   }

+ 0 - 1
src/docsis_globals.h

@@ -23,7 +23,6 @@
 #ifndef _DOCSIS_GLOBALS_H
 #define _DOCSIS_GLOBALS_H
 
-char prog_name[255];
 struct tlv *global_tlvtree_head;
 symbol_type *global_symtable;
 

+ 1 - 2
src/docsis_yy.y

@@ -37,7 +37,6 @@ extern unsigned int line; 	/* current line number, defined in a.l */
 extern struct tlv *global_tlvtree_head; /* Global list of all config TLVs */
 extern symbol_type *global_symtable;
 extern FILE *yyin;
-extern char prog_name[255];
 
 struct tlv *_my_tlvtree_head;
 
@@ -620,7 +619,7 @@ int parse_config_file ( char *file, struct tlv **parse_tree_result )
 
   if ( (cf = fopen ( file, "r" ))== NULL )
   {
-	printf ("%s: Can't open input file %s\n", prog_name, file );
+	printf ("docsis: Can't open input file %s\n", file );
 	return -1;
   }