Module Name:    src
Committed By:   christos
Date:           Sat Jun 22 20:44:55 UTC 2019

Modified Files:
        src/usr.bin/menuc: mdb.c menu_sys.def

Log Message:
Conserve space: make ints to shorts and make OPT_NOMENU 0 instead of -1
so we don't require initializing it.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/menuc/mdb.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/menuc/menu_sys.def

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/menuc/mdb.c
diff -u src/usr.bin/menuc/mdb.c:1.51 src/usr.bin/menuc/mdb.c:1.52
--- src/usr.bin/menuc/mdb.c:1.51	Mon Feb 25 15:47:37 2019
+++ src/usr.bin/menuc/mdb.c	Sat Jun 22 16:44:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: mdb.c,v 1.51 2019/02/25 20:47:37 martin Exp $	*/
+/*	$NetBSD: mdb.c,v 1.52 2019/06/22 20:44:54 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -41,7 +41,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mdb.c,v 1.51 2019/02/25 20:47:37 martin Exp $");
+__RCSID("$NetBSD: mdb.c,v 1.52 2019/06/22 20:44:54 christos Exp $");
 #endif
 
 
@@ -55,7 +55,7 @@ __RCSID("$NetBSD: mdb.c,v 1.51 2019/02/2
 /* Data */
 #undef MAX
 #define MAX 1000
-static int menu_no = 0;
+static int menu_no = 1;	/* Menu 0 is unused (means no menu) */
 static id_rec *menus[MAX];
 
 /* Other defines */
@@ -75,7 +75,7 @@ get_menu(char *name)
 
 	if (temp == NULL) {
 		if (menu_no < MAX) {
-			temp = (id_rec *)malloc(sizeof(id_rec));
+			temp = calloc(1, sizeof(id_rec));
 			temp->id = strdup(name);
 			temp->info = NULL;
 			temp->menu_no = menu_no;
@@ -98,7 +98,7 @@ check_defined(void)
 {
 	int i;
 
-	for (i = 0; i < menu_no; i++)
+	for (i = 1; i < menu_no; i++)
 		if (!menus[i]->info)
 			yyerror ("Menu '%s' undefined.", menus[i]->id);
 }
@@ -177,28 +177,28 @@ write_menu_file(char *initcode)
 		(void)fprintf(out_file,
 		"	const char	*opt_exp_name;\n");
 	(void)fprintf(out_file,
-		"	int		opt_menu;\n"
-		"	int		opt_flags;\n"
+		"	short		opt_menu;\n"
+		"	short		opt_flags;\n"
 		"	int		(*opt_action)(menudesc *, void *);\n"
 		"};\n\n"
+		"#define OPT_NOMENU	0\n"
 		"#define OPT_SUB	1\n"
 		"#define OPT_ENDWIN	2\n"
 		"#define OPT_EXIT	4\n"
 		"#define OPT_IGNORE	8\n"
-		"#define OPT_NOSHORT	16\n"
-		"#define OPT_NOMENU	-1\n\n"
+		"#define OPT_NOSHORT	16\n\n"
 		"struct menudesc {\n"
 		"	const char	*title;\n");
 	if (do_expands)
 		(void)fprintf(out_file,
 		"	const char	*exp_title;\n");
 	(void)fprintf(out_file,
-		"	int		y, x;\n"
-		"	int		h, w;\n"
-		"	int		mopt;\n"
-		"	int		numopts;\n"
-		"	int		cursel;\n"
-		"	int		topline;\n"
+		"	short		y, x;\n"
+		"	short		h, w;\n"
+		"	short		mopt;\n"
+		"	short		numopts;\n"
+		"	short		cursel;\n"
+		"	short		topline;\n"
 		"	menu_ent	*opts;\n"
 		"	WINDOW		*mw;\n"
 		"	WINDOW		*sv_mw;\n"
@@ -253,7 +253,7 @@ write_menu_file(char *initcode)
 			);
 
 	(void)fprintf(out_file, "\n/* Menu names */\n");
-	for (i = 0; i < menu_no; i++)
+	for (i = 1; i < menu_no; i++)
 		(void)fprintf(out_file, "#define MENU_%s\t%d\n",
 		    menus[i]->id, i);
 
@@ -280,7 +280,7 @@ write_menu_file(char *initcode)
 	/* data definitions */
 
 	/* func defs */
-	for (i = 0; i < menu_no; i++) {
+	for (i = 1; i < menu_no; i++) {
 		if (do_expands && strlen(menus[i]->info->expact.code)) {
 			(void)fprintf(out_file, "/*ARGSUSED*/\n"
 			    "static void menu_%d_expact(menudesc *menu, void *arg)\n{\n", i);
@@ -321,7 +321,7 @@ write_menu_file(char *initcode)
 	}
 
 	/* optentX */
-	for (i = 0; i < menu_no; i++) {
+	for (i = 1; i < menu_no; i++) {
 		if (menus[i]->info->numopt > 53) {
 			(void)fprintf(stderr, "Menu %s has "
 				"too many options.\n",
@@ -372,7 +372,7 @@ write_menu_file(char *initcode)
 		    menu_no);
 
 	(void)fprintf(out_file, "static struct menudesc menu_def[] = {\n");
-	for (i = 0; i < menu_no; i++) {
+	for (i = 1; i < menu_no; i++) {
 		(void)fprintf(out_file,
 			"\t{%s,", menus[i]->info->title);
 		if (do_expands)

Index: src/usr.bin/menuc/menu_sys.def
diff -u src/usr.bin/menuc/menu_sys.def:1.69 src/usr.bin/menuc/menu_sys.def:1.70
--- src/usr.bin/menuc/menu_sys.def:1.69	Fri Apr 12 11:59:34 2019
+++ src/usr.bin/menuc/menu_sys.def	Sat Jun 22 16:44:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: menu_sys.def,v 1.69 2019/04/12 15:59:34 martin Exp $	*/
+/*	$NetBSD: menu_sys.def,v 1.70 2019/06/22 20:44:54 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -764,7 +764,7 @@ process_menu(int num, void *arg)
 				break;
 		}
 
-		if (opt->opt_menu != -1) {
+		if (opt->opt_menu != OPT_NOMENU) {
 			if (!(opt->opt_flags & OPT_SUB)) {
 				num = opt->opt_menu;
 				wclear(m->mw);

Reply via email to