From 2502208671265e8e02e14f25b9272d6f8ec5d490 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Sat, 20 Aug 2022 11:23:18 +0200 Subject: [PATCH] if a subcircuit has spiceprefix set in template string do not consider it as an attribute to dump in netlist as a subckt parameter (.subckt xxxx A B C spiceprefix=X) --- scconfig/src/gui/find_gl.c | 88 ++++++++++++++++++++++++++++++++++++++ scconfig/src/gui/find_gl.h | 2 + scconfig/src/gui/gui.c | 1 + src/token.c | 5 ++- 4 files changed, 94 insertions(+), 2 deletions(-) diff --git a/scconfig/src/gui/find_gl.c b/scconfig/src/gui/find_gl.c index fe9604b4..ca8ae232 100644 --- a/scconfig/src/gui/find_gl.c +++ b/scconfig/src/gui/find_gl.c @@ -333,3 +333,91 @@ int find_gui_wgl(const char *name, int logdepth, int fatal) if (try_icl(logdepth, node, test_c, "#include ", NULL, "-lopengl32")) return 0; return try_fail(logdepth, node); } + +static int accept_glfw(char *stdout_str) +{ + int major = 0, minor = 0, rev = 0; + char tmp[32]; + + if ((stdout_str[0] != 'O') || (stdout_str[1] != 'K')) + return 0; + + sscanf(stdout_str + 2, "%d %d %d", &major, &minor, &rev); + sprintf(tmp, "%d", major); put("libs/gui/glfw/ver/major", tmp); + sprintf(tmp, "%d", minor); put("libs/gui/glfw/ver/minor", tmp); + sprintf(tmp, "%d", rev); put("libs/gui/glfw/ver/rev", tmp); + + return 1; +} + +int find_glfw(const char *name, int logdepth, int fatal) +{ + const char *test_c = + NL "#include " + NL "int main()" + NL "{" + NL " int major = 0, minor = 0, rev = 0;" + NL " glfwGetVersion(&major, &minor, &rev);" + NL " if (major > 0)" + NL " printf(\"OK %d %d %d\\n\", major, minor, rev);" + NL " return 0;" + NL "}" + NL; + const char *node = "libs/gui/glfw", *ipr; + char freeglfw[4096]; + char **inc, *incs[] = {"", "#include ", NULL}; + char *cflags = NULL; + char *ldflags = NULL; + + incs[0] = freeglfw; + freeglfw[0] = 0; + + if (require("cc/cc", logdepth, fatal)) + return try_fail(logdepth, node); + + + report("Checking for glfw... "); + logprintf(logdepth, "find_glfw: running pkg-config...\n"); + logdepth++; + + if (run_pkg_config(logdepth, "glfw3", &cflags, &ldflags) == 0) { + if (try_icl_(logdepth, node, test_c, incs[1], cflags, ldflags, 1, accept_glfw) != 0) + goto success; + } + + if (require("libs/gui/gl/include_prefix", logdepth, fatal)) + return try_fail(logdepth, node); + ipr = get("libs/gui/gl/include_prefix"); + if (ipr == NULL) + return try_fail(logdepth, node); + + if (cflags != NULL) { + free(cflags); + cflags = NULL; + } + + if (ldflags != NULL) { + free(ldflags); + ldflags = NULL; + } + + logdepth--; + logprintf(logdepth, "find_glfw: manual tries...\n"); + logdepth++; + + sprintf(freeglfw, "#include <%s/glfw.h>", ipr); + ldflags = strclone("-lglfw"); + for(inc = incs; *inc != NULL; inc++) + if (try_icl_(logdepth, node, test_c, *inc, NULL, ldflags, 1, accept_glfw) != 0) + goto success; + free(ldflags); + + return try_fail(logdepth, node); + + success:; + if (cflags != NULL) + free(cflags); + if (ldflags != NULL) + free(ldflags); + return 0; +} diff --git a/scconfig/src/gui/find_gl.h b/scconfig/src/gui/find_gl.h index 7429f342..6dc21e96 100644 --- a/scconfig/src/gui/find_gl.h +++ b/scconfig/src/gui/find_gl.h @@ -5,3 +5,5 @@ int find_gl_fb_attachment(const char *name, int logdepth, int fatal); int find_glu(const char *name, int logdepth, int fatal); int find_glut(const char *name, int logdepth, int fatal); int find_gui_wgl(const char *name, int logdepth, int fatal); +int find_glfw(const char *name, int logdepth, int fatal); + diff --git a/scconfig/src/gui/gui.c b/scconfig/src/gui/gui.c index fc721b5a..385a6d8e 100644 --- a/scconfig/src/gui/gui.c +++ b/scconfig/src/gui/gui.c @@ -46,4 +46,5 @@ void deps_gui_init() dep_add("libs/gui/glu/*", find_glu); dep_add("libs/gui/glut/*", find_glut); dep_add("libs/gui/wgl/*", find_gui_wgl); + dep_add("libs/gui/glfw/*", find_glfw); } diff --git a/src/token.c b/src/token.c index 6dd35a04..3388a51a 100644 --- a/src/token.c +++ b/src/token.c @@ -490,6 +490,7 @@ const char *get_tok_value(const char *s,const char *tok, int with_quotes) } /* return template string excluding name=... and token=value where token listed in extra */ +/* drop spiceprefix attribute */ const char *get_sym_template(char *s,char *extra) { static char *result=NULL; @@ -546,7 +547,7 @@ const char *get_sym_template(char *s,char *extra) } else if(state==TOK_END) { value[value_pos]='\0'; - if((!extra || !strstr(extra, token)) && strcmp(token,"name")) { + if((!extra || !strstr(extra, token)) && strcmp(token,"name") && strcmp(token,"spiceprefix")) { memcpy(result+result_pos, value, value_pos+1); result_pos+=value_pos; } @@ -557,7 +558,7 @@ const char *get_sym_template(char *s,char *extra) } else if(state==TOK_ENDTOK || state==TOK_SEP) { if(token_pos) { token[token_pos]='\0'; - if((!extra || !strstr(extra, token)) && strcmp(token,"name")) { + if((!extra || !strstr(extra, token)) && strcmp(token,"name") && strcmp(token,"spiceprefix")) { memcpy(result+result_pos, token, token_pos+1); result_pos+=token_pos; result[result_pos++] = (char)c;