mirror of
https://github.com/simh/simh.git
synced 2026-01-11 23:52:58 +00:00
SCP: Define and use a global macro to stringify macro values
This commit is contained in:
parent
2dc0d099f2
commit
79714192b4
22
scp.c
22
scp.c
@ -10768,9 +10768,12 @@ return read_line_p (NULL, cptr, size, stream);
|
||||
#define RTLD_LOCAL 0
|
||||
#endif
|
||||
#define EDIT_DEFAULT_LIB "edit."
|
||||
#define SIM_HAVE_DLOPEN DLL
|
||||
#define SIM_DLOPEN_EXTENSION DLL
|
||||
#else /* !defined(_WIN32) */
|
||||
#define EDIT_DEFAULT_LIB "libedit."
|
||||
#if defined(SIM_HAVE_DLOPEN)
|
||||
#define SIM_DLOPEN_EXTENSION SIM_HAVE_DLOPEN
|
||||
#endif
|
||||
#endif /* defined(_WIN32) */
|
||||
|
||||
char *read_line_p (const char *prompt, char *cptr, int32 size, FILE *stream)
|
||||
@ -10796,15 +10799,13 @@ if (prompt && (!initialized)) {
|
||||
p_free_line = (free_line_func)&free;
|
||||
#endif
|
||||
#else /* !defined(HAVE_LIBEDIT) */
|
||||
#if defined(SIM_HAVE_DLOPEN)
|
||||
#if defined(SIM_DLOPEN_EXTENSION)
|
||||
if (!p_readline) { /* libedit not available at compile time, try OS shared object? */
|
||||
void *handle;
|
||||
|
||||
#define S__STR_QUOTE(tok) #tok
|
||||
#define S__STR(tok) S__STR_QUOTE(tok)
|
||||
handle = dlopen(EDIT_DEFAULT_LIB S__STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL);
|
||||
handle = dlopen(EDIT_DEFAULT_LIB __STR(SIM_DLOPEN_EXTENSION), RTLD_NOW|RTLD_GLOBAL);
|
||||
if (!handle)
|
||||
handle = dlopen(EDIT_DEFAULT_LIB S__STR(SIM_HAVE_DLOPEN) ".2", RTLD_NOW|RTLD_GLOBAL);
|
||||
handle = dlopen(EDIT_DEFAULT_LIB __STR(SIM_DLOPEN_EXTENSION) ".2", RTLD_NOW|RTLD_GLOBAL);
|
||||
if (handle) {
|
||||
p_readline = (readline_func)((size_t)dlsym(handle, "readline"));
|
||||
p_add_history = (add_history_func)((size_t)dlsym(handle, "add_history"));
|
||||
@ -10813,7 +10814,7 @@ if (prompt && (!initialized)) {
|
||||
p_free_line = (free_line_func)&free;
|
||||
}
|
||||
}
|
||||
#endif /* defined(SIM_HAVE_DLOPEN) */
|
||||
#endif /* defined(SIM_DLOPEN_EXTENSION) */
|
||||
#endif /* defined(HAVE_LIBEDIT) */
|
||||
}
|
||||
|
||||
@ -13849,10 +13850,7 @@ for (i=0; i < exp->size; i++) {
|
||||
int end_offs = ovector[2 * j + 1], start_offs = ovector[2 * j];
|
||||
|
||||
sprintf (env_name, "_EXPECT_MATCH_GROUP_%d", (int)j);
|
||||
if ((start_offs >= 0) && (end_offs >= start_offs))/* cover the potential case when no substring returned */
|
||||
memcpy (buf, &cbuf[start_offs], end_offs - start_offs);
|
||||
else
|
||||
start_offs = end_offs = 0; /* no substring is an empty string */
|
||||
memcpy (buf, &cbuf[start_offs], end_offs - start_offs);
|
||||
buf[end_offs - start_offs] = '\0';
|
||||
setenv (env_name, buf, 1); /* Make the match and substrings available as environment variables */
|
||||
sim_debug (exp->dbit, exp->dptr, "%s=%s\n", env_name, buf);
|
||||
@ -13861,7 +13859,7 @@ for (i=0; i < exp->size; i++) {
|
||||
char env_name[32];
|
||||
|
||||
sprintf (env_name, "_EXPECT_MATCH_GROUP_%d", (int)j);
|
||||
setenv (env_name, "", 1); /* Remove previous extra environment variables */
|
||||
unsetenv (env_name); /* Remove previous extra environment variables */
|
||||
}
|
||||
sim_exp_match_sub_count = ep->re_nsub;
|
||||
free (ovector);
|
||||
|
||||
@ -178,6 +178,11 @@ extern "C" {
|
||||
#define CONST const
|
||||
#endif
|
||||
|
||||
/* Stringify macro value */
|
||||
|
||||
#define __STR_QUOTE(tok) #tok
|
||||
#define __STR(tok) __STR_QUOTE(tok)
|
||||
|
||||
/* Length specific integer declarations */
|
||||
|
||||
/* Handle the special/unusual cases first with everything else leveraging stdints.h */
|
||||
|
||||
@ -6349,9 +6349,7 @@ uuid_gen (void *uuidaddr)
|
||||
void (*uuid_generate_c) (void *) = NULL;
|
||||
void *handle;
|
||||
|
||||
#define S__STR_QUOTE(tok) #tok
|
||||
#define S__STR(tok) S__STR_QUOTE(tok)
|
||||
handle = dlopen("libuuid." S__STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL);
|
||||
handle = dlopen("libuuid." __STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL);
|
||||
if (handle)
|
||||
uuid_generate_c = (void (*)(void *))((size_t)dlsym(handle, "uuid_generate"));
|
||||
if (uuid_generate_c)
|
||||
|
||||
@ -1261,8 +1261,6 @@ static void *hLib = 0; /* handle to Library */
|
||||
#endif
|
||||
static int lib_loaded = 0; /* 0=not loaded, 1=loaded, 2=library load failed, 3=Func load failed */
|
||||
|
||||
#define __STR_QUOTE(tok) #tok
|
||||
#define __STR(tok) __STR_QUOTE(tok)
|
||||
static const char* lib_name =
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
"wpcap.dll";
|
||||
@ -1280,8 +1278,6 @@ static char no_pcap[PCAP_ERRBUF_SIZE] =
|
||||
#else
|
||||
"libpcap." __STR(SIM_HAVE_DLOPEN) " failed to load, install libpcap to use pcap networking";
|
||||
#endif
|
||||
#undef __STR
|
||||
#undef __STR_QUOTE
|
||||
|
||||
/* define pointers to pcap functions needed */
|
||||
static void (*p_pcap_close) (pcap_t *);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user