add menu properties -> Edit header/License text, to allow inserting header or license metadata into the sch/sym file.

This commit is contained in:
stefan schippers 2023-01-02 03:04:35 +01:00
parent cee4d218e2
commit 19757ddd8a
8 changed files with 60 additions and 23 deletions

View File

@ -621,6 +621,7 @@ void clear_drawing(void)
my_free(687, &xctx->schprop);
my_free(688, &xctx->schvhdlprop);
my_free(689, &xctx->version_string);
if(xctx->header_text) my_free(1654, &xctx->header_text);
my_free(690, &xctx->schverilogprop);
for(i=0;i<xctx->wires;i++)
{

View File

@ -1216,25 +1216,25 @@ int sym_vs_sch_pins()
int endfile;
char tag[1];
char filename[PATH_MAX];
char f_version[100];
n_syms = xctx->symbols;
for(i=0;i<n_syms;i++)
{
if( xctx->sym[i].type && !strcmp(xctx->sym[i].type,"subcircuit")) {
rects = xctx->sym[i].rects[PINLAYER];
get_sch_from_sym(filename, xctx->sym + i);
if(!stat(filename, &buf)) {
fd = fopen(filename, "r");
pin_cnt = 0;
endfile = 0;
xctx->file_version[0] = '\0';
f_version[0] = '\0';
while(!endfile) {
if(fscanf(fd," %c",tag)==EOF) break;
switch(tag[0]) {
case 'v':
load_ascii_string(&xctx->version_string, fd);
my_snprintf(xctx->file_version, S(xctx->file_version), "%s",
get_tok_value(xctx->version_string, "file_version", 0));
load_ascii_string(&tmp, fd);
my_snprintf(f_version, S(f_version), "%s",
get_tok_value(tmp, "file_version", 0));
break;
case 'E':
@ -1305,7 +1305,7 @@ int sym_vs_sch_pins()
load_ascii_string(&tmp, fd);
my_strncpy(name, tmp, S(name));
if(!strcmp(xctx->file_version,"1.0") ) {
if(!strcmp(f_version,"1.0") ) {
dbg(1, "sym_vs_sch_pins(): add_ext(name,\".sym\") = %s\n", add_ext(name, ".sym") );
my_strncpy(name, add_ext(name, ".sym"), S(name));
}
@ -1386,9 +1386,9 @@ int sym_vs_sch_pins()
break;
}
read_line(fd, 0); /* discard any remaining characters till (but not including) newline */
if(!xctx->file_version[0]) {
my_snprintf(xctx->file_version, S(xctx->file_version), "1.0");
dbg(1, "sym_vs_sch_pins(): no file_version, assuming file_version=%s\n", xctx->file_version);
if(!f_version[0]) {
my_snprintf(f_version, S(f_version), "1.0");
dbg(1, "sym_vs_sch_pins(): no file_version, assuming file_version=%s\n", f_version);
}
} /* while(!endfile) */
fclose(fd);

View File

@ -1486,18 +1486,16 @@ static void save_line(FILE *fd, int select_only)
static void write_xschem_file(FILE *fd)
{
size_t ty=0;
char *ptr;
if(xctx->version_string && (ptr = strstr(xctx->version_string, "xschem")) &&
(ptr - xctx->version_string < 50)) {
my_strdup2(59, &xctx->version_string, subst_token(xctx->version_string, "xschem", NULL));
}
my_strdup2(1183, &xctx->version_string, subst_token(xctx->version_string, "version", NULL));
my_strdup2(1184, &xctx->version_string, subst_token(xctx->version_string, "file_version", NULL));
ptr = xctx->version_string;
while(*ptr == ' ' || *ptr == '\t' || *ptr == '\n') ptr++; /* strip leading spaces */
fprintf(fd, "v {xschem version=%s file_version=%s\n%s}\n", XSCHEM_VERSION, XSCHEM_FILE_VERSION, ptr);
char *tmpstring = NULL;
size_t tmpstring_size;
char *header_ptr = xctx->header_text ? xctx->header_text : "";
tmpstring_size = strlen(header_ptr) + 100;
tmpstring = my_malloc(1652, tmpstring_size);
my_snprintf(tmpstring, tmpstring_size, "xschem version=%s file_version=%s\n%s",
XSCHEM_VERSION, XSCHEM_FILE_VERSION, header_ptr);
fprintf(fd, "v ");
save_ascii_string(tmpstring, fd, 1);
my_free(1653, &tmpstring);
if(xctx->schvhdlprop && !xctx->schsymbolprop) {
get_tok_value(xctx->schvhdlprop,"type",0);
@ -1839,6 +1837,7 @@ static void read_xschem_file(FILE *fd)
char tag[1];
int inst_cnt;
size_t ty=0;
char *ptr = NULL, *ptr2;
dbg(2, "read_xschem_file(): start\n");
inst_cnt = endfile = 0;
@ -1853,6 +1852,19 @@ static void read_xschem_file(FILE *fd)
if(xctx->version_string) {
my_snprintf(xctx->file_version, S(xctx->file_version), "%s",
get_tok_value(xctx->version_string, "file_version", 0));
if((ptr2 = strstr(xctx->version_string, "xschem")) && (ptr2 - xctx->version_string < 50)) {
my_strdup2(1655, &ptr, subst_token(xctx->version_string, "xschem", NULL));
}
my_strdup2(1656, &ptr, subst_token(ptr, "version", NULL));
my_strdup2(1657, &ptr, subst_token(ptr, "file_version", NULL));
ptr2 = ptr;
while(*ptr2 == ' ' || *ptr2 =='\t') ptr2++; /* strip leading spaces */
if(*ptr2 == '\n') ptr2++; /* strip leading newline */
my_strdup2(1658, &xctx->header_text, ptr2);
my_free(1659,&ptr);
}
dbg(1, "read_xschem_file(): file_version=%s\n", xctx->file_version);
break;

View File

@ -874,6 +874,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
if(help != 0 ) Tcl_SetResult(interp, "1",TCL_STATIC);
else Tcl_SetResult(interp, "0",TCL_STATIC);
}
else if(!strcmp(argv[2], "header_text")) {
if(xctx && xctx->header_text) {
Tcl_SetResult(interp, xctx->header_text, TCL_VOLATILE);
} else {
Tcl_SetResult(interp, "", TCL_VOLATILE);
}
}
break;
case 'i':
if(!strcmp(argv[2], "instances")) {
@ -2529,6 +2536,12 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(!strcmp(argv[2], "format")) {
my_strdup(1542, &xctx->format, argv[3]);
}
else if(!strcmp(argv[2], "header_text")) {
if(!xctx->header_text || strcmp(xctx->header_text, argv[3])) {
set_modify(1); xctx->push_undo();
my_strdup2(1660, &xctx->header_text, argv[3]);
}
}
else if(!strcmp(argv[2], "hide_symbols")) {
xctx->hide_symbols=atoi(argv[3]);
}

View File

@ -463,6 +463,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
xctx->schsymbolprop=NULL; /* symbol property string */
xctx->schverilogprop=NULL;/* verilog */
xctx->version_string = NULL;
xctx->header_text = NULL;
xctx->rectcolor= 4; /* this is the current layer when xschem started. */
xctx->currsch = 0;
xctx->ui_state = 0;

View File

@ -788,6 +788,7 @@ typedef struct {
char sch[CADMAXHIER][PATH_MAX];
int currsch;
char *version_string;
char *header_text; /* header text (license info) placed in the 'v' record after xschem/file version */
char current_name[PATH_MAX];
char file_version[100];
char *sch_path[CADMAXHIER];

View File

@ -5860,6 +5860,14 @@ proc build_widgets { {topwin {} } } {
$topwin.menubar.prop.menu add command -label "Edit" -command "xschem edit_prop" -accelerator Q
$topwin.menubar.prop.menu add command -label "Edit with editor" -command "xschem edit_vi_prop" -accelerator Shift+Q
$topwin.menubar.prop.menu add command -label "View" -command "xschem view_prop" -accelerator Ctrl+Shift+Q
$topwin.menubar.prop.menu add command -label "Edit Header/License text" \
-command {
set retval [xschem get header_text]
text_line {Header/License text:} 0
if { $rcode ne {}} {
xschem set header_text $retval
}
}
$topwin.menubar.prop.menu add command -background red -label "Edit file (danger!)" \
-command "xschem edit_file" -accelerator Alt+Q
$topwin.menubar.sym.menu add radiobutton -label "Show Symbols" \

View File

@ -1,6 +1,7 @@
v {xschem version=2.9.8 file_version=1.2}
v {xschem version=3.1.0 file_version=1.2
}
G {}
K {type=isource
K {type=isource_only_for_hspice
format="@name @@p @@m pwl(1) @@cp @@cm @TABLE"
template="name=G1 TABLE=\\"1 0 2 1m\\""
}