From abea3f9064357be19edf96ff0aee6bdc751916be Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 13 Oct 2021 20:38:21 -0400 Subject: [PATCH] constify ncmenu_item/_section strings --- doc/man/man3/notcurses_menu.3.md | 6 +++--- include/notcurses/notcurses.h | 4 ++-- src/lib/internal.h | 35 -------------------------------- src/lib/menu.c | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/doc/man/man3/notcurses_menu.3.md b/doc/man/man3/notcurses_menu.3.md index 26921e4d1..a78225b00 100644 --- a/doc/man/man3/notcurses_menu.3.md +++ b/doc/man/man3/notcurses_menu.3.md @@ -16,10 +16,10 @@ struct ncplane; struct notcurses; struct ncmenu_section { - char* name; // utf-8 c string + const char* name; // utf-8 c string struct ncmenu_item { - char* desc; // utf-8 menu item, NULL for horizontal separator - ncinput shortcut; // shortcut, all should be distinct + const char* desc; // utf-8 menu item, NULL for horizontal separator + ncinput shortcut; // shortcut, all should be distinct }* items; int itemcount; }; diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 620b72432..ec4c8c00a 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -3519,12 +3519,12 @@ API void nctree_destroy(struct nctree* n); // a plane resize, menus will be automatically moved/resized. Elements can be // dynamically enabled or disabled at all levels (menu, section, and item), struct ncmenu_item { - char* desc; // utf-8 menu item, NULL for horizontal separator + const char* desc; // utf-8 menu item, NULL for horizontal separator ncinput shortcut; // shortcut, all should be distinct }; struct ncmenu_section { - char* name; // utf-8 c string + const char* name; // utf-8 c string int itemcount; struct ncmenu_item* items; ncinput shortcut; // shortcut, will be underlined if present in name diff --git a/src/lib/internal.h b/src/lib/internal.h index f65ccfd29..7b4324a60 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -182,28 +182,6 @@ typedef struct ncreel { ncreel_options ropts; // copied in ncreel_create() } ncreel; -// ncmenu_item and ncmenu_section have internal and (minimal) external forms -typedef struct ncmenu_int_item { - char* desc; // utf-8 menu item, NULL for horizontal separator - ncinput shortcut; // shortcut, all should be distinct - int shortcut_offset; // column offset with desc of shortcut EGC - char* shortdesc; // description of shortcut, can be NULL - int shortdesccols; // columns occupied by shortcut description - bool disabled; // disabled? -} ncmenu_int_item; - -typedef struct ncmenu_int_section { - char* name; // utf-8 c string - int itemcount; - ncmenu_int_item* items; // items, NULL iff itemcount == 0 - ncinput shortcut; // shortcut, will be underlined if present in name - int xoff; // column offset from beginning of menu bar - int bodycols; // column width of longest item - int itemselected; // current item selected, -1 for no selection - int shortcut_offset; // column offset within name of shortcut EGC - int enabled_item_count; // number of enabled items: section is disabled iff 0 -} ncmenu_int_section; - typedef struct ncfdplane { ncfdplane_callback cb; // invoked with fresh hot data ncfdplane_done_cb donecb; // invoked on EOF (if !follow) or error @@ -235,19 +213,6 @@ typedef struct ncreader { bool manage_cursor; // enable and place a virtual cursor } ncreader; -typedef struct ncmenu { - ncplane* ncp; - int sectioncount; // must be positive - ncmenu_int_section* sections; // NULL iff sectioncount == 0 - int unrolledsection; // currently unrolled section, -1 if none - int headerwidth; // minimum space necessary to display all sections - uint64_t headerchannels; // styling for header - uint64_t dissectchannels; // styling for disabled section headers - uint64_t sectionchannels; // styling for sections - uint64_t disablechannels; // styling for disabled entries - bool bottom; // are we on the bottom (vs top)? -} ncmenu; - typedef struct ncprogbar { ncplane* ncp; double progress; // on the range [0, 1] diff --git a/src/lib/menu.c b/src/lib/menu.c index 3c981f76d..d2663d9da 100644 --- a/src/lib/menu.c +++ b/src/lib/menu.c @@ -1,5 +1,40 @@ #include "internal.h" +// ncmenu_item and ncmenu_section have internal and (minimal) external forms +typedef struct ncmenu_int_item { + char* desc; // utf-8 menu item, NULL for horizontal separator + ncinput shortcut; // shortcut, all should be distinct + int shortcut_offset; // column offset with desc of shortcut EGC + char* shortdesc; // description of shortcut, can be NULL + int shortdesccols; // columns occupied by shortcut description + bool disabled; // disabled? +} ncmenu_int_item; + +typedef struct ncmenu_int_section { + char* name; // utf-8 c string + int itemcount; + ncmenu_int_item* items; // items, NULL iff itemcount == 0 + ncinput shortcut; // shortcut, will be underlined if present in name + int xoff; // column offset from beginning of menu bar + int bodycols; // column width of longest item + int itemselected; // current item selected, -1 for no selection + int shortcut_offset; // column offset within name of shortcut EGC + int enabled_item_count; // number of enabled items: section is disabled iff 0 +} ncmenu_int_section; + +typedef struct ncmenu { + ncplane* ncp; + int sectioncount; // must be positive + ncmenu_int_section* sections; // NULL iff sectioncount == 0 + int unrolledsection; // currently unrolled section, -1 if none + int headerwidth; // minimum space necessary to display all sections + uint64_t headerchannels; // styling for header + uint64_t dissectchannels; // styling for disabled section headers + uint64_t sectionchannels; // styling for sections + uint64_t disablechannels; // styling for disabled entries + bool bottom; // are we on the bottom (vs top)? +} ncmenu; + // Search the provided multibyte (UTF8) string 's' for the provided unicode // codepoint 'cp'. If found, return the column offset of the EGC in which the // codepoint appears in 'col', and the byte offset as the return value. If not