/*====================================================== * get_indent -- screen indent for treeview display *====================================================*/ static INT get_indent (void) { INT indent = getlloptint("GedcomDisplayIndent", 6); if (indent<0 || indent>9) indent = 6; return indent; }
/*========================================================== * annotate_with_supplemental -- Expand any references that have REFNs * This converts, eg, "@S25@" to "<1850.Census>" * Used for editing *========================================================*/ void annotate_with_supplemental (NODE node, RFMT rfmt) { BOOLEAN expand_refns = (getlloptint("ExpandRefnsDuringEdit", 0) > 0); BOOLEAN annotate_pointers = (getlloptint("AnnotatePointers", 0) > 0); NODE child=0; CACHEEL cel = node->n_cel; struct tag_node_iter nodeit; if (cel) lock_cache(cel); /* ensure node doesn't fall out of cache */ /* annotate all descendant nodes */ begin_node_it(node, &nodeit); while ((child = next_node_it_ptr(&nodeit)) != NULL) { annotate_node(child, expand_refns, annotate_pointers, rfmt); } if (cel) unlock_cache(cel); }
/*=============================================+ * vprog_error -- Report a run time program error * node: current parsed node * fmt, args: printf style message * ...: printf style varargs * Prints error to the stdout-style curses window * and to the report log (if one was specified in config file) * Always includes line number of node, if available * Only includes file name if not same as previous error * Returns static buffer with one-line description *============================================*/ static STRING vprog_error (PNODE node, STRING fmt, va_list args) { INT num; STRING rptfile; ZSTR zstr=zs_newn(256); static char msgbuff[100]; if (rpt_cancelled) return _("Report cancelled"); rptfile = getlloptstr("ReportLog", NULL); if (node) { STRING fname = irptinfo(node)->fullpath; INT lineno = iline(node)+1; /* Display filename if not same as last error */ if (!eqstr(vprog_prevfile, fname)) { llstrsets(vprog_prevfile, sizeof(vprog_prevfile), uu8, fname); zs_apps(zstr, _("Report file: ")); zs_apps(zstr, fname); zs_appc(zstr, '\n'); vprog_prevline = -1; /* force line number display */ } /* Display line number if not same as last error */ if (vprog_prevline != lineno) { vprog_prevline = lineno; if (progparsing) zs_appf(zstr, _("Parsing Error at line %d: "), lineno); else zs_appf(zstr, _("Runtime Error at line %d: "), lineno); } } else { zs_apps(zstr, _("Aborting: ")); } zs_appvf(zstr, fmt, args); llwprintf("\n"); llwprintf(zs_str(zstr)); ++progerror; /* if user specified a report error log (in config file) */ if (rptfile && rptfile[0]) { FILE * fp = fopen(rptfile, LLAPPENDTEXT); if (fp) { if (progerror == 1) { LLDATE creation; get_current_lldate(&creation); fprintf(fp, "\n%s\n", creation.datestr); } fprintf(fp, "%s", zs_str(zstr)); fprintf(fp, "\n"); fclose(fp); } } if ((num = getlloptint("PerErrorDelay", 0))) sleep(num); zs_free(&zstr); return msgbuff; }
/*================================================== * pre_codesets_hook -- code to run just before initializing codesets * For MS-Windows user config of console codepages *================================================*/ static void pre_codesets_hook (void) { #ifdef WIN32 /* On MS-Windows, attempt to set any requested non-standard codepage */ /* Do this now, before init_codesets below */ INT i = getlloptint("ConsoleCodepage", 0); if (i) { w_set_oemout_codepage(i); w_set_oemin_codepage(i); } #endif }
/*=================================================== * update_useropts -- Set any global variables * dependent on user options *=================================================*/ void update_useropts (VPTR uparm) { uparm = uparm; /* unused */ if (suppress_reload) return; /* deal with db-specific options */ /* includes setting int_codeset */ if (def_lldb) update_db_options(); /* in case user changed any codesets */ init_codesets(); /* in case user changed locale (need int_codeset already set) */ uilocale(); /* in case user changed codesets */ /* TODO: Isn't this superfluous, as it was called in update_db_options above ? */ transl_load_xlats(); strupdate(&illegal_char, getlloptstr("IllegalChar", 0)); nodechk_enable(!!getlloptint("nodecheck", 0)); }
/*========================================================== * resolve_refn_links -- Resolve and check all links in node tree * This converts, eg, "<1850.Census>" to "@S25@" *========================================================*/ INT resolve_refn_links (NODE node) { INT unresolved = 0; BOOLEAN annotate_pointers = (getlloptint("AnnotatePointers", 0) > 0); NODE child=0; CACHEEL cel = node ? node->n_cel: 0; struct tag_node_iter nodeit; if (!node) return 0; if (cel) lock_cache(cel); /* ensure node doesn't fall out of cache */ /* resolve all descendant nodes */ begin_node_it(node, &nodeit); while ((child = next_node_it_ptr(&nodeit)) != NULL) { if (!resolve_node(child, annotate_pointers)) ++unresolved; } if (cel) unlock_cache(cel); return unresolved; }
/*================================================+ * evaluate_ufunc -- Evaluate user defined function * node: [in] parsed node of function definition * stab: [in] function's symbol table * eflg: [out] error flag *===============================================*/ PVALUE evaluate_ufunc (PNODE node, SYMTAB stab, BOOLEAN *eflg) { STRING procname = (STRING) iname(node); PNODE func, arg, parm; SYMTAB newstab = NULL; PVALUE val=NULL; INTERPTYPE irc; INT count=0; *eflg = TRUE; /* find func in local or global table */ func = get_proc_node(procname, irptinfo(node)->functab, gfunctab, &count); if (!func) { if (!count) prog_error(node, _("Undefined func: %s"), procname); else prog_error(node, _("Ambiguous call to func: %s"), procname); goto ufunc_leave; } newstab = create_symtab_proc(procname, stab); arg = (PNODE) iargs(node); parm = (PNODE) iargs(func); while (arg && parm) { BOOLEAN eflg=TRUE; PVALUE value = evaluate(arg, stab, &eflg); if (eflg) { if (getlloptint("FullReportCallStack", 0) > 0) prog_error(node, "In user function %s()", procname); return INTERROR; } insert_symtab(newstab, iident(parm), value); arg = inext(arg); parm = inext(parm); } if (arg || parm) { prog_error(node, "``%s'': mismatched args and params\n", procname); goto ufunc_leave; } irc = interpret((PNODE) ibody(func), newstab, &val); switch (irc) { case INTRETURN: case INTOKAY: #ifdef DEBUG llwprintf("Successful ufunc call -- val returned was "); show_pvalue(val); llwprintf("\n"); #endif *eflg = FALSE; goto ufunc_leave; case INTBREAK: case INTCONTINUE: case INTERROR: break; } if (getlloptint("FullReportCallStack", 0) > 0) prog_error(node, "In user function %s()", procname); *eflg = TRUE; delete_pvalue(val); val=NULL; ufunc_leave: if (newstab) { remove_symtab(newstab); newstab = NULL; } return val; }
/*=================================== * valid_indi_tree -- Validate person tree * indi1: [IN] person to validate * pmsg: [OUT] error message, if any * orig: [IN] person to match - may be NULL * rtn: FALSE for bad * Should be replaced by valid_indi(RECORD,...) ? *=================================*/ BOOLEAN valid_indi_tree (NODE indi1, STRING *pmsg, NODE orig) { NODE name1, refn1, sex1, body1, famc1, fams1, node; NODE name0, refn0, sex0, body0, famc0, fams0; INT isex, num; STRING *keys, ukey; if (!indi1) { *pmsg = _(qSbademp); return FALSE; } if (nestr("INDI", ntag(indi1))) { *pmsg = _(qSbadin0); return FALSE; } if (nsibling(indi1)) { *pmsg = _(qSbadmul); return FALSE; } split_indi_old(indi1, &name1, &refn1, &sex1, &body1, &famc1, &fams1); if (getlloptint("RequireNames", 0) && !name1) { *pmsg = _("This person record does not have a name line."); goto bad2; } for (node = name1; node; node = nsibling(node)) { if (!valid_name(nval(node))) { *pmsg = _(qSbadenm); goto bad2; } } name0 = refn0 = sex0 = body0 = famc0 = fams0 = NULL; if (orig) split_indi_old(orig, &name0, &refn0, &sex0, &body0, &famc0, &fams0); if (orig && !iso_nodes(indi1, orig, FALSE, FALSE)) { *pmsg = _(qSbadind); goto bad1; } if (!iso_nodes(famc1, famc0, FALSE, TRUE)) { *pmsg = _(qSbadfmc); goto bad1; } if (!iso_nodes(fams1, fams0, FALSE, TRUE)) { *pmsg = _(qSbadfms); goto bad1; } isex = val_to_sex(sex0); if (!fams0) isex = SEX_UNKNOWN; if (isex != SEX_UNKNOWN && isex != val_to_sex(sex1)) { *pmsg = _(qSbadparsex); goto bad1; } ukey = (refn1 ? nval(refn1) : NULL); get_refns(ukey, &num, &keys, 'I'); if (num > 1 || (num == 1 && (!orig || nestr(keys[0], rmvat(nxref(indi1)))))) { *pmsg = _(qSbadirefn); goto bad1; } if (orig) join_indi(orig, name0, refn0, sex0, body0, famc0, fams0); join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1); return TRUE; bad1: if (orig) join_indi(orig, name0, refn0, sex0, body0, famc0, fams0); bad2: join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1); return FALSE; }