fix a bug when pasting / ctrl-v into an empty schematic (instances not selected for moving)

This commit is contained in:
Stefan Frederik 2021-01-22 01:03:16 +01:00
parent 4fd65005a1
commit ac99227365
7 changed files with 96 additions and 9 deletions

View File

@ -96,6 +96,9 @@ void deps_default_init(void)
dep_add("libs/fs/getwd/*", find_fs_getwd);
dep_add("libs/fs/mkdir/*", find_fs_mkdir);
dep_add("libs/fs/_mkdir/*", find_fs__mkdir);
dep_add("libs/fs/utime/*", find_fs_utime);
dep_add("libs/fs/_utime/*", find_fs__utime);
dep_add("libs/fs/_utime64/*", find_fs__utime64);
dep_add("libs/fs/mkdtemp/*", find_fs_mkdtemp);
dep_add("libs/fs/mmap/*", find_fs_mmap);
dep_add("libs/fsmount/next_dev/*", find_fsmount_next_dev);

View File

@ -56,6 +56,9 @@ int find_fs__getcwd(const char *name, int logdepth, int fatal);
int find_fs_getwd(const char *name, int logdepth, int fatal);
int find_fs_mkdir(const char *name, int logdepth, int fatal);
int find_fs__mkdir(const char *name, int logdepth, int fatal);
int find_fs_utime(const char *name, int logdepth, int fatal);
int find_fs__utime(const char *name, int logdepth, int fatal);
int find_fs__utime64(const char *name, int logdepth, int fatal);
int find_fs_mkdtemp(const char *name, int logdepth, int fatal);
int find_fs_mmap(const char *name, int logdepth, int fatal);
int find_fsmount_next_dev(const char *name, int logdepth, int fatal);

View File

@ -576,6 +576,83 @@ int find_fs__mkdir(const char *name, int logdepth, int fatal)
return try_fail(logdepth, "libs/fs/_mkdir");
}
static int find_utime_impl(const char *name, int logdepth, int fatal,
const char* key, const char* funcname, const char* typename)
{
char test_c[1024+4096];
const char *test_c_templ =
NL "void puts_OK();"
NL "int main(int argc, char* argv[])"
NL "{"
NL " struct %s buf;"
NL " buf.actime = buf.modtime = 1610958044;"
NL " if (%s(\"%s\", &buf) == 0)"
NL " puts_OK();"
NL " return 0;"
NL "}"
NL "#include <stdio.h>"
NL "void puts_OK()"
NL "{"
NL " puts(\"OK\");"
NL "}"
NL;
const char* includes[] =
{
/* *NIX */
"#include <sys/types.h>\n#include <utime.h>",
/* windoz */
"#include <sys/utime.h>",
NULL
};
const char** inc;
char* tmpf;
tmpf = tempfile_new(".txt");
sprintf(test_c, test_c_templ, typename, funcname, tmpf);
require("cc/cc", logdepth, fatal);
report("Checking for %s... ", funcname);
logprintf(logdepth, "find_fs_%s: trying to find %s()...\n", funcname, funcname);
logdepth++;
for (inc=includes; *inc; ++inc)
{
if (try_icl(logdepth, key, test_c, *inc, NULL, NULL))
{
unlink(tmpf);
free(tmpf);
return 0;
}
}
unlink(tmpf);
free(tmpf);
return try_fail(logdepth, key);
}
int find_fs_utime(const char *name, int logdepth, int fatal)
{
return find_utime_impl(name, logdepth, fatal,
"libs/fs/utime", "utime", "utimbuf");
}
int find_fs__utime(const char *name, int logdepth, int fatal)
{
return find_utime_impl(name, logdepth, fatal,
"libs/fs/_utime", "_utime", "_utimbuf");
}
int find_fs__utime64(const char *name, int logdepth, int fatal)
{
return find_utime_impl(name, logdepth, fatal,
"libs/fs/_utime64", "_utime64", "__utimbuf64");
}
int find_fs_mkdtemp(const char *name, int logdepth, int fatal)
{
char *test_c =

View File

@ -1049,7 +1049,7 @@ int callback(int event, int mx, int my, KeySym key,
{
int mult;
remove_symbol(2);
link_symbols_to_instances(0);
link_symbols_to_instances(-1);
expandlabel("/RST", &mult);
expandlabel("/CCC[3:0]", &mult);
expandlabel("CCC[AA:BB:DD]", &mult);

View File

@ -947,7 +947,7 @@ void update_symbol(const char *result, int x)
may be out of sync wrt disk version */
if(copy_cell) {
remove_symbols();
link_symbols_to_instances(0);
link_symbols_to_instances(-1);
}
/* symbol reference changed? --> sym_number >=0, set prefix to 1st char
to use for inst name (from symbol template) */

View File

@ -426,7 +426,7 @@ void pop_undo(int redo)
my_strdup(222, &xctx->wire[i].prop_ptr, uslot[slot].wptr[i].prop_ptr);
}
link_symbols_to_instances(0);
link_symbols_to_instances(-1);
set_modify(1);
xctx->prep_hash_inst=0;
xctx->prep_hash_wires=0;

View File

@ -954,12 +954,16 @@ int save_schematic(const char *schname) /* 20171020 added return value */
return 0;
}
void link_symbols_to_instances(int from) /* from > 0 : linking symbols from pasted schematic / clipboard */
/* from == -1 --> link symbols to all instances, from 0 to instances-1 */
void link_symbols_to_instances(int from) /* from >= 0 : linking symbols from pasted schematic / clipboard */
{
int i;
int cond, i, merge = 1;
char *type=NULL;
int cond;
if(from < 0 ) {
from = 0;
merge = 0;
}
for(i = from; i < xctx->instances; i++) {
dbg(2, "link_symbols_to_instances(): inst=%d\n", i);
dbg(2, "link_symbols_to_instances(): matching inst %d name=%s \n",i, xctx->inst[i].name);
@ -967,7 +971,7 @@ void link_symbols_to_instances(int from) /* from > 0 : linking symbols from past
xctx->inst[i].ptr = match_symbol(xctx->inst[i].name);
}
for(i = from; i < xctx->instances; i++) {
if(from) select_element(i,SELECTED,1, 0); /* leave elements selected if a paste/copy from windows is done */
if(merge) select_element(i,SELECTED,1, 0); /* leave elements selected if a paste/copy from windows is done */
type=xctx->sym[xctx->inst[i].ptr].type;
cond= !type || !IS_LABEL_SH_OR_PIN(type);
if(cond) xctx->inst[i].flags|=2; /* ordinary symbol */
@ -1022,7 +1026,7 @@ void load_schematic(int load_symbols, const char *filename, int reset_undo) /* 2
fclose(fd); /* 20150326 moved before load symbols */
set_modify(0);
dbg(2, "load_schematic(): loaded file:wire=%d inst=%d\n",xctx->wires , xctx->instances);
if(load_symbols) link_symbols_to_instances(0);
if(load_symbols) link_symbols_to_instances(-1);
if(reset_undo) {
Tcl_VarEval(interp, "is_xschem_file ", xctx->sch[xctx->currsch], NULL);
if(!strcmp(tclresult(), "SYMBOL")) {
@ -1238,7 +1242,7 @@ void pop_undo(int redo)
fclose(fd);
#endif
dbg(2, "pop_undo(): loaded file:wire=%d inst=%d\n",xctx->wires , xctx->instances);
link_symbols_to_instances(0);
link_symbols_to_instances(-1);
set_modify(1);
xctx->prep_hash_inst=0;
xctx->prep_hash_wires=0;