int is_entry(struct node * root,int a_entry) { if(root==NULL) return 0; else if(root->entry==a_entry) return 1; if(root->entry>a_entry) return is_entry(root->left,a_entry); return is_entry(root->right,a_entry); }
/* Kill ep, i.e free all memory it references, and reset to initial value */ void kill0(const char *e) { entree *ep = is_entry(e); if (!ep || EpSTATIC(ep)) pari_err(e_MISC,"can't kill that"); killep(ep); }
/* Wrapper around make_entry to check that filename exists and entry is in correct form. */ struct entry *read_entry(char *filename) { struct stat buf; if (!is_entry(filename) || kukka_stat(filename, &buf) < 0) { return NULL; } return make_entry(&buf, filename); }
void help(const char *s) { entree *ep = is_entry(s); if (ep && ep->help) pari_printf("%s\n",ep->help); else pari_printf("Function %s not found\n",s); }
/* If flag = 0 (default): check if s existed in 1.39.15 and print verbosely * the answer. * If flag > 0: silently return n+1 if function changed, 0 otherwise. * (where n is the index of s in whatnowlist). * If flag < 0: -flag-1 is the index in whatnowlist */ int whatnow(char *s, int flag) { int n; char *def; whatnow_t wp; entree *ep; if (flag < 0) { n = -flag; flag = 0; } else { if (flag && strlen(s)==1) return 0; /* special case "i" and "o" */ if (!is_identifier(s) || !is_entry_intern(s,funct_old_hash,NULL)) { if (flag) return 0; pari_err(talker,"as far as I can recall, this function never existed"); } n = 0; do def = (oldfonctions[n++]).name; while (def && strcmp(def,s)); if (!def) { int m=0; do def = (functions_oldgp[m++]).name; while (def && strcmp(def,s)); n += m - 1; } } wp=whatnowlist[n-1]; def=wp.name; if (def == SAME) { if (flag) return 0; pari_err(talker,"this function did not change"); } if (flag) return n; if (def == REMOV) pari_err(talker,"this function was suppressed"); if (!strcmp(def,"x*y")) { pariprintf(" %s is now called *.\n\n",s); pariprintf(" %s%s ===> %s%s\n\n",s,wp.oldarg,wp.name,wp.newarg); return 1; } ep = is_entry(wp.name); if (!ep) pari_err(bugparier,"whatnow"); pariputs("New syntax: "); term_color(c_ERR); pariprintf("%s%s ===> %s%s\n\n",s,wp.oldarg,wp.name,wp.newarg); term_color(c_HELP); print_text(ep->help); pariputc('\n'); term_color(c_NONE); return 1; }
static void varentries_unset(long v) { entree *ep = varentries[v]; if (ep) { hashentry *e = hash_remove_select(h_polvar, (void*)ep->name, (void*)v, _given_value); if (!e) pari_err_BUG("varentries_unset [unknown var]"); varentries[v] = NULL; pari_free(e); if (v <= nvar && is_entry(ep->name)) { killep(ep); return; } pari_free(ep); } }
static void help(const char *s0, int flag) { const long long_help = flag & h_LONG; long n; entree *ep; char *s = get_sep(s0); if (isdigit((int)*s)) { digit_help(s,flag); return; } if (flag & h_APROPOS) { external_help(s,-1); return; } /* Get meaningful answer on '\ps 5' (e.g. from <F1>) */ if (*s == '\\') { char *t = s+1; pari_skip_alpha(&t); *t = '\0'; } if (isalpha((int)*s)) { if (!strncmp(s, "default", 7)) { /* special-case ?default(dft_name), e.g. default(log) */ char *t = s+7; pari_skip_space(&t); if (*t == '(') { t++; pari_skip_space(&t); cut_trailing_garbage(t); if (pari_is_default(t)) { default_help(t,flag); return; } } } cut_trailing_garbage(s); } if (long_help && (n = ok_external_help(&s))) { external_help(s,n); return; } switch (*s) { case '*' : commands(-1); return; case '\0': menu_commands(); return; case '\\': slash_commands(); return; case '.' : member_commands(); return; } ep = is_entry(s); if (!ep) { if (pari_is_default(s)) default_help(s,flag); else if (long_help) external_help(s,3); else if (!cb_pari_whatnow || !cb_pari_whatnow(pariOut, s,1)) simple_help(s,"unknown identifier"); return; } if (EpVALENCE(ep) == EpALIAS) { pari_printf("%s is aliased to:\n\n",s); ep = do_alias(ep); } switch(EpVALENCE(ep)) { case EpVAR: if (!ep->help) { if (typ((GEN)ep->value)!=t_CLOSURE) simple_help(s, "user defined variable"); else { GEN str = closure_get_text((GEN)ep->value); if (typ(str) == t_VEC) pari_printf("%s =\n %Ps\n", ep->name, ep->value); } return; } break; case EpINSTALL: if (!ep->help) { simple_help(s, "installed function"); return; } break; case EpNEW: if (!ep->help) { simple_help(s, "new identifier"); return; }; break; default: /* built-in function */ if (!ep->help) pari_err_BUG("gp_help (no help found)"); /*paranoia*/ if (long_help) { external_help(ep->name,3); return; } } print_text(ep->help); }