better atof_spice() suffix checking, set xctx->current_dirname to $PWD when creating an empty new tab (untitled schematic)

This commit is contained in:
Stefan Frederik 2022-10-13 16:45:27 +02:00
parent f7738329a5
commit 7c60f37f54
2 changed files with 16 additions and 5 deletions

View File

@ -315,15 +315,20 @@ double atof_spice(const char *s)
int n;
double a = 0.0, mul=1.0;
char lower_s[100];
char suffix[100];
const char *p;
if(!s) return 0.0;
my_strncpy(lower_s, s, S(lower_s));
strtolower(lower_s);
n = sscanf(lower_s, "%lf", &a);
if(n == 1) {
p = strpbrk(lower_s, "tgmkunpfa");
if(!p) mul = 1.0;
n = sscanf(lower_s, "%lf%s", &a, suffix);
if(n == 0) {
return 0.0;
} else if(n == 1) {
mul = 1.0;
} else {
p = strpbrk(suffix, "tgmkunpfa");
if(p != suffix ) mul = 1.0;
else if(*p == 't') mul=1e12;
else if(*p == 'g') mul=1e9;
else if(*p == 'm') {

View File

@ -2209,8 +2209,14 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2
}
if(stat(name, &buf)) break;
}
my_snprintf(xctx->sch[xctx->currsch], S(xctx->sch[xctx->currsch]), "%s/%s", pwd_dir, name);
my_strncpy(xctx->current_name, name, S(xctx->current_name));
if(getenv("PWD")) {
/* $env(PWD) better than pwd_dir as it does not dereference symlinks */
my_strncpy(xctx->current_dirname, getenv("PWD"), S(xctx->current_dirname));
} else {
my_strncpy(xctx->current_dirname, pwd_dir, S(xctx->current_dirname));
}
my_snprintf(xctx->sch[xctx->currsch], S(xctx->sch[xctx->currsch]), "%s/%s", xctx->current_dirname, name);
if(reset_undo) set_modify(0);
}
check_collapsing_objects();