1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Streamline some nval(3) and related flaggery

In the olden days, ksh used the hash(3) library to store variables,
aliases, functions, etc. For many years, it's been using the cdt(3)
library instead. But the low-level nv_search() name-value tree
lookup function was still repurposing some bit flags from the old
hash API for its options, though that API is otherwise unused.

So we were still including the entire obsolete <hash.h> API just
to use two repurposed HASH_* bit flags for nv_search(). This commit
makes nv_search() repurpose some flags from <nval.h> instead.

This commit should not change ksh's behaviour.

src/cmd/ksh93/sh/nvdisc.c:
- Make nv_search() use NV_NOSCOPE instead of HASH_NOSCOPE and
  NV_REF instead of HASH_BUCKET.
- The HASH_SCOPE flag was also passed to some nv_search() calls,
  but nv_search() ignores it, so that flag is deleted from those.
- Document nv_search() in a comment.

src/cmd/ksh93/include/name.h:
- Move NV_UNATTR to nval.h to join the other nv_open() options
  there. (re: 1184b2ad)

src/cmd/ksh93/include/nval.h:
- Since we no longer use HASH_* macros, do not include <hash.h>.
- Remove unused NV_NOASSIGN macro, defined to 0. This was there
  for "backward compatibility" since before 1995; long enough.

src/cmd/ksh93/include/shell.h:
- Bump SH_VERSION due to the nv_search() API change (even though no
  changes were made to the APIs documented in nval.3 or shell.3).

All other changed files:
- Update to match the flaggery changes.
This commit is contained in:
Martijn Dekker 2022-07-20 04:10:57 +02:00
parent 60b3e3a28d
commit 1884f57a74
21 changed files with 74 additions and 69 deletions

View file

@ -32,7 +32,6 @@
#include <ast.h>
#include <cdt.h>
#include <option.h>
#include <hash.h>
typedef struct Namval Namval_t;
typedef struct Namfun Namfun_t;
@ -174,7 +173,6 @@ struct Namval
#define NV_ADD 8
/* add node if not found */
#define NV_ASSIGN NV_NOFREE /* assignment is possible */
#define NV_NOASSIGN 0 /* backward compatibility */
#define NV_NOARRAY 0x200000 /* array name not possible */
#define NV_IARRAY 0x400000 /* for indexed array */
#define NV_NOREF NV_REF /* don't follow reference */
@ -184,6 +182,7 @@ struct Namval
#define NV_NOSCOPE 0x80000 /* look only in current scope */
#define NV_NOFAIL 0x100000 /* return 0 on failure, no msg */
#define NV_NODISC NV_IDENT /* ignore disciplines */
#define NV_UNATTR 0x800000 /* unset attributes before assignment */
#define NV_GLOBAL 0x20000000 /* create global variable, ignoring local scope */
#define NV_FUNCT NV_IDENT /* option for nv_create */