Print this page
12310 Add demangle(1) command
*** 19,28 ****
--- 19,29 ----
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <sys/ctype.h>
#include <sys/debug.h>
+ #include <sys/sysmacros.h>
#include <stdarg.h>
#include "demangle-sys.h"
#include "demangle_int.h"
#define DEMANGLE_DEBUG "DEMANGLE_DEBUG"
*** 29,51 ****
static pthread_once_t debug_once = PTHREAD_ONCE_INIT;
volatile boolean_t demangle_debug;
FILE *debugf = stderr;
static const char *
langstr(sysdem_lang_t lang)
{
! switch (lang) {
! case SYSDEM_LANG_AUTO:
! return ("auto");
! case SYSDEM_LANG_CPP:
! return ("c++");
! case SYSDEM_LANG_RUST:
! return ("rust");
! default:
return ("invalid");
}
}
static sysdem_lang_t
detect_lang(const char *str, size_t n)
{
--- 30,73 ----
static pthread_once_t debug_once = PTHREAD_ONCE_INIT;
volatile boolean_t demangle_debug;
FILE *debugf = stderr;
+ static struct {
+ const char *str;
+ sysdem_lang_t lang;
+ } lang_tbl[] = {
+ { "auto", SYSDEM_LANG_AUTO },
+ { "c++", SYSDEM_LANG_CPP },
+ { "rust", SYSDEM_LANG_RUST },
+ };
+
static const char *
langstr(sysdem_lang_t lang)
{
! size_t i;
!
! for (i = 0; i < ARRAY_SIZE(lang_tbl); i++) {
! if (lang == lang_tbl[i].lang)
! return (lang_tbl[i].str);
! }
return ("invalid");
+ }
+
+ boolean_t
+ sysdem_parse_lang(const char *str, sysdem_lang_t *langp)
+ {
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(lang_tbl); i++) {
+ if (strcmp(str, lang_tbl[i].str) == 0) {
+ *langp = lang_tbl[i].lang;
+ return (B_TRUE);
}
+ }
+
+ return (B_FALSE);
}
static sysdem_lang_t
detect_lang(const char *str, size_t n)
{