Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/menuc Conserve space: make ints to shorts and make O...



details:   https://anonhg.NetBSD.org/src/rev/7996480e0680
branches:  trunk
changeset: 452223:7996480e0680
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jun 22 20:44:54 2019 +0000

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

diffstat:

 usr.bin/menuc/mdb.c        |  38 +++++++++++++++++++-------------------
 usr.bin/menuc/menu_sys.def |   4 ++--
 2 files changed, 21 insertions(+), 21 deletions(-)

diffs (138 lines):

diff -r 75940ebe6a1f -r 7996480e0680 usr.bin/menuc/mdb.c
--- a/usr.bin/menuc/mdb.c       Sat Jun 22 19:47:27 2019 +0000
+++ b/usr.bin/menuc/mdb.c       Sat Jun 22 20:44:54 2019 +0000
@@ -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 @@
 /* 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 @@
 
        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 @@
 {
        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 @@
                (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 @@
                        );
 
        (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 @@
        /* 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 @@
        }
 
        /* 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 @@
                    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)
diff -r 75940ebe6a1f -r 7996480e0680 usr.bin/menuc/menu_sys.def
--- a/usr.bin/menuc/menu_sys.def        Sat Jun 22 19:47:27 2019 +0000
+++ b/usr.bin/menuc/menu_sys.def        Sat Jun 22 20:44:54 2019 +0000
@@ -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 @@
                                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);



Home | Main Index | Thread Index | Old Index