Index: trunk/src/libcschem/cnc_text_dyn.c =================================================================== --- trunk/src/libcschem/cnc_text_dyn.c (revision 2012) +++ trunk/src/libcschem/cnc_text_dyn.c (revision 2013) @@ -47,11 +47,26 @@ return &hdr->attr; } +static const char *get_filename(csch_sheet_t *sheet) +{ + const char *sep, *fn = sheet->hidlib.filename; + + if (fn == NULL) + return ""; + + sep = strrchr(fn, '/'); + if (sep != NULL) + return sep+1; /* basename */ + + return fn; +} + static int csch_text_render_str_cb(void *ctx, gds_t *s, const char **input) { const csch_text_t *text = ctx; const csch_attribs_t *attrs; char *end, key[128], *path; + const char *val = NULL; size_t len; end = strchr(*input, '%'); @@ -63,6 +78,11 @@ key[len] = '\0'; *input += len+1; + if (strcmp(key, "filename") == 0) { + val = get_filename(text->hdr.sheet); + goto append; + } + path = key; attrs = get_attribs(&path, text); @@ -69,12 +89,16 @@ if ((path[0] == 'A') && (path[1] == '.')) { path+=2; if (attrs != NULL) { - const char *val = csch_attrib_get_str(attrs, path); - if (val != NULL) - gds_append_str(s, val); + val = csch_attrib_get_str(attrs, path); + goto append; } } return 0; + + append:; + if (val != NULL) + gds_append_str(s, val); + return 0; }