diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 1c5df41ed..994f0f531 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -11,6 +11,7 @@ Author: 1985 Wayne A. Christopher /* Note: Must include shlwapi.h before ngspice header defining BOOL due * to conflict */ +#include #ifdef _WIN32 #include /* for definition of PathIsRelativeA() */ #pragma comment(lib, "Shlwapi.lib") @@ -1547,6 +1548,8 @@ struct inp_read_t inp_read( FILE *fp, int call_depth, const char *dir_name, !ciprefix("wrdata", buffer) && !ciprefix(".lib", buffer) && !ciprefix(".inc", buffer) && !ciprefix("codemodel", buffer) && + !ciprefix("osdi", buffer) && + !ciprefix("pre_osdi", buffer) && !ciprefix("echo", buffer) && !ciprefix("shell", buffer) && !ciprefix("source", buffer) && !ciprefix("cd ", buffer) && !ciprefix("load", buffer) && !ciprefix("setcs", buffer)) { @@ -2368,6 +2371,8 @@ static char *get_subckt_model_name(char *line) name = skip_non_ws(line); // eat .subckt|.model name = skip_ws(name); + + end_ptr = skip_non_ws(name); return copy_substring(name, end_ptr); @@ -2417,14 +2422,29 @@ static char *get_model_type(char *line) } -static char *get_adevice_model_name(char *line) +static char *get_adevice_model_name(char *line, struct nscope *scope) { - char *ptr_end, *ptr_beg; + char *beg_ptr, *end_ptr, *name; + int i = 0; - ptr_end = skip_back_ws(strchr(line, '\0'), line); - ptr_beg = skip_back_non_ws(ptr_end, line); + beg_ptr = skip_non_ws(line); /* eat device name */ + beg_ptr = skip_ws(beg_ptr); - return copy_substring(ptr_beg, ptr_end); + for (i = 0; i < 30; i++) { /* skip the terminals */ + end_ptr = skip_non_ws(beg_ptr); + name = copy_substring(beg_ptr, end_ptr); + if (inp_find_model(scope, name)){ + return name; + }else if (beg_ptr == end_ptr){ + break; + } + end_ptr = skip_ws(end_ptr); + beg_ptr = end_ptr; + + } + + + return NULL; } @@ -2643,7 +2663,7 @@ static void get_subckts_for_subckt(struct card *start_card, char *subckt_name, nlist_adjoin(used_subckts, inst_subckt_name); } else if (*line == 'a') { - char *model_name = get_adevice_model_name(line); + char *model_name = get_adevice_model_name( line, card->level); nlist_adjoin(used_models, model_name); } else if (has_models) { @@ -2729,7 +2749,7 @@ void comment_out_unused_subckt_models(struct card *start_card) nlist_adjoin(used_subckts, subckt_name); } else if (*line == 'a') { - char *model_name = get_adevice_model_name(line); + char *model_name = get_adevice_model_name(line, card->level); nlist_adjoin(used_models, model_name); } else if (has_models) { @@ -10065,9 +10085,12 @@ void inp_rem_unused_models(struct nscope *root, struct card *deck) /* num_terminals may be 0 for a elements */ if ((num_terminals != 0) || (*curr_line == 'a')) { char *elem_model_name; - if (*curr_line == 'a') - elem_model_name = get_adevice_model_name(curr_line); - else + if (*curr_line == 'a'){ + elem_model_name = get_adevice_model_name( curr_line, card->level); + if (!elem_model_name){ + continue; + } + }else elem_model_name = get_model_name(curr_line, num_terminals); /* ignore certain cases, for example @@ -10108,7 +10131,7 @@ void inp_rem_unused_models(struct nscope *root, struct card *deck) * only correct UTF-8. It also spots UTF-8 sequences that could cause * trouble if converted to UTF-16, namely surrogate characters * (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF). - * In addition we check for some ngspice-specific characters like µ etc.*/ + * In addition we check for some ngspice-specific characters like � etc.*/ #ifndef EXT_ASC static unsigned char* utf8_check(unsigned char *s) @@ -10118,12 +10141,12 @@ utf8_check(unsigned char *s) /* 0xxxxxxx */ s++; else if (*s == 0xb5) { - /* translate ansi micro µ to u */ + /* translate ansi micro � to u */ *s = 'u'; s++; } else if (s[0] == 0xc2 && s[1] == 0xb5) { - /* translate utf-8 micro µ to u */ + /* translate utf-8 micro � to u */ s[0] = 'u'; /* remove second byte */ unsigned char *y = s + 1; diff --git a/src/osdi/exported.txt b/src/osdi/exported.txt index 90009efce..242368ceb 100644 --- a/src/osdi/exported.txt +++ b/src/osdi/exported.txt @@ -1,7 +1,6 @@ { extern "C" { - osdi_init_log_message; - osdi_finish_log_message; + osdi_log; }; }; diff --git a/src/osdi/osdi.h b/src/osdi/osdi.h index e923ef1ff..3716dc101 100644 --- a/src/osdi/osdi.h +++ b/src/osdi/osdi.h @@ -42,11 +42,15 @@ #define EVAL_RET_FLAG_FINISH 4 #define EVAL_RET_FLAG_STOP 8 + +#define LOG_LVL_MASK 8 #define LOG_LVL_DEBUG 0 -#define LOG_LVL_INFO 1 -#define LOG_LVL_WARN 2 -#define LOG_LVL_ERR 3 -#define LOG_LVL_FATAL 4 +#define LOG_LVL_DISPLAY 1 +#define LOG_LVL_INFO 2 +#define LOG_LVL_WARN 3 +#define LOG_LVL_ERR 4 +#define LOG_LVL_FATAL 5 +#define LOG_FMT_ERR 16 #define INIT_ERR_OUT_OF_BOUNDS 1 @@ -161,6 +165,5 @@ typedef struct OsdiDescriptor { -extern FILE *osdi_init_log_message(void *handle, uint32_t lvl); -extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl); +extern void osdi_log(void *handle, char* msg, uint32_t lvl); diff --git a/src/osdi/osdiinit.c b/src/osdi/osdiinit.c index dbefa4666..17e29d1db 100644 --- a/src/osdi/osdiinit.c +++ b/src/osdi/osdiinit.c @@ -11,10 +11,12 @@ #include "ngspice/ngspice.h" #include "ngspice/typedefs.h" +#include "osdi.h" #include "osdidefs.h" #include #include +#include #include /* @@ -171,34 +173,39 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) { return OSDIinfo; } -extern FILE *osdi_init_log_message(void *handle_, uint32_t lvl) { +extern void osdi_log(void *handle_, char *msg, uint32_t lvl) { OsdiNgspiceHandle *handle = handle_; - switch (lvl) { + FILE *dst = stdout; + switch (lvl & LOG_LVL_MASK) { case LOG_LVL_DEBUG: - fprintf(stdout, "OSDI(debug) %s: ", handle->name); + printf("OSDI(debug) %s: ", handle->name); + break; + case LOG_LVL_DISPLAY: + printf("OSDI %s: ", handle->name); break; case LOG_LVL_INFO: - fprintf(stdout, "OSDI(info) %s: ", handle->name); + printf("OSDI(info) %s: ", handle->name); break; case LOG_LVL_WARN: - fprintf(stdout, "OSDI(warn) %s: ", handle->name); + fprintf(stderr, "OSDI(warn) %s: ", handle->name); + dst = stderr; break; case LOG_LVL_ERR: fprintf(stderr, "OSDI(err) %s: ", handle->name); - return stderr; + dst = stderr; + break; case LOG_LVL_FATAL: fprintf(stderr, "OSDI(fatal) %s: ", handle->name); - return stderr; + dst = stderr; + break; default: - fprintf(stdout, "OSDI(unkown) %s", handle->name); + fprintf(stderr, "OSDI(unkown) %s", handle->name); break; } - return stdout; -} -extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl) { - - NG_IGNORE(handle); - NG_IGNORE(stream); - NG_IGNORE(lvl); + if (lvl & LOG_FMT_ERR) { + fprintf(dst, "failed to format\"%s\"\n", msg); + } else { + fprintf(dst, "%s", msg); + } } diff --git a/src/osdi/osdiparam.c b/src/osdi/osdiparam.c index fdf0b12e4..b86210d12 100644 --- a/src/osdi/osdiparam.c +++ b/src/osdi/osdiparam.c @@ -115,7 +115,7 @@ extern int OSDImParam(int param, IFvalue *value, GENmodel *modelPtr) { } void *model = osdi_model_data(modelPtr); - void *dst = descr->access(model, model, (uint32_t)param, ACCESS_FLAG_SET); + void *dst = descr->access(NULL, model, (uint32_t)param, ACCESS_FLAG_SET); return osdi_write_param(dst, value, param, descr); } diff --git a/src/spicelib/parser/inp2a.c b/src/spicelib/parser/inp2a.c index 124504385..ba3c2a3da 100644 --- a/src/spicelib/parser/inp2a.c +++ b/src/spicelib/parser/inp2a.c @@ -53,9 +53,9 @@ void INP2A(CKTcircuit *ckt, INPtables *tab, struct card *current) { if (i >= 2) { txfree(INPgetMod(ckt, token, &thismodel, tab)); - /* check if using model binning -- pass in line since need 'l' and 'w' */ - if (!thismodel) - txfree(INPgetModBin(ckt, token, &thismodel, tab, line)); + /* /1* check if using model binning -- pass in line since need 'l' and 'w' *1/ */ + /* if (!thismodel) */ + /* txfree(INPgetModBin(ckt, token, &thismodel, tab, line)); */ if (thismodel) { INPinsert(&token, tab);