void alias0(const char *s, const char *old) { entree *ep, *e; GEN x; ep = fetch_entry(old); e = fetch_entry(s); if (EpVALENCE(e) != EpALIAS && EpVALENCE(e) != EpNEW) pari_err(e_MISC,"can't replace an existing symbol by an alias"); freeep(e); x = newblock(2); x[0] = evaltyp(t_STR)|_evallg(2); /* for getheap */ gel(x,1) = (GEN)ep; e->value=x; e->valence=EpALIAS; }
static void commands(long n) { long i; entree *ep; char **t_L; pari_stack s_L; pari_stack_init(&s_L, sizeof(*t_L), (void**)&t_L); for (i = 0; i < functions_tblsz; i++) for (ep = functions_hash[i]; ep; ep = ep->next) { long m; switch (EpVALENCE(ep)) { case EpVAR: if (typ((GEN)ep->value) == t_CLOSURE) break; /* fall through */ case EpNEW: continue; } m = ep->menu; if (m == n || (n < 0 && m && m <= MAX_SECTION)) pari_stack_pushp(&s_L, (void*)ep->name); } pari_stack_pushp(&s_L, NULL); print_fun_list(t_L, term_height()-4); pari_stack_delete(&s_L); }
/* do we add () at the end of completed word? (is it a function?) */ static int add_paren(pari_rl_interface *rl, int end) { entree *ep; const char *s; if (end < 0 || (*rl->line_buffer)[end] == '(') return 0; /* not from command_generator or already there */ ep = do_alias(current_ep); /* current_ep set in command_generator */ if (EpVALENCE(ep) < EpNEW) { /* is it a constant masked as a function (e.g Pi)? */ s = ep->help; if (!s) return 1; while (is_keyword_char(*s)) s++; return (*s != '='); } switch(EpVALENCE(ep)) { case EpVAR: return typ((GEN)ep->value) == t_CLOSURE; case EpINSTALL: return 1; } return 0; }
long fetch_user_var(const char *s) { entree *ep = fetch_entry(s); long v; switch (EpVALENCE(ep)) { case EpVAR: return varn((GEN)initial_value(ep)); case EpNEW: break; default: pari_err(e_MISC, "%s already exists with incompatible valence", s); } v = pari_var_create(ep); ep->valence = EpVAR; ep->value = initial_value(ep); return v; }
void print_all_user_fun(int member) { pari_sp av = avma; long iL = 0, lL = 1024; GEN L = cgetg(lL+1, t_VECSMALL); entree *ep; int i; for (i = 0; i < functions_tblsz; i++) for (ep = functions_hash[i]; ep; ep = ep->next) { const char *f; int is_member; if (EpVALENCE(ep) != EpVAR || typ((GEN)ep->value)!=t_CLOSURE) continue; f = ep->name; is_member = (f[0] == '_' && f[1] == '.'); if (member != is_member) continue; if (iL >= lL) { GEN oL = L; long j; lL *= 2; L = cgetg(lL+1, t_VECSMALL); for (j = 1; j <= iL; j++) gel(L,j) = gel(oL,j); } L[++iL] = (long)ep; } if (iL) { setlg(L, iL+1); L = gen_sort(L, NULL, &cmp_epname); for (i = 1; i <= iL; i++) { ep = (entree*)L[i]; pari_printf("%s =\n %Ps\n\n", ep->name, ep->value); } } avma = av; }
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); }