/* This file is in the public domain. */ #include #include #include #include "ecl-glue.h" #include "ecl-malloc.h" #include "csh.h" #include "extern.h" #define DEFAULT_HISTORY_SIZE 25 #define DEFAULT_KILLRING_SIZE 10 extern bool quitit; static char *ecl_alloc_short2str(Char *i) { int n; char *o; int j; for (n=0;i[n];n++) ; o = malloc(n+1); for (j=0;j a) { free(b); b = malloc((a=n+1)); } for (j=0;jvec[0]) return(1); s = v->vec[0]; for (i=0;s[i]&&s[i+1];i+=2) { (*cb)(s[i],s[i+1]); } return(0); } int ecl_history_size(void) { static const Char STReclhistory[] = { 'e', 'c', 'l', 'h', 'i', 's', 't', 'o', 'r', 'y', '\0' }; struct varent *v; v = adrof(&STReclhistory[0]); if (!v || !v->vec[0]) v = adrof(STRhistory); if (!v || !v->vec[0]) return(DEFAULT_HISTORY_SIZE); return(numeric_value(v->vec[0])); } int ecl_killring_size(void) { static const Char STReclkillring[] = { 'e', 'c', 'l', 'k', 'i', 'l', 'l', 'r', 'i', 'n', 'g', '\0' }; struct varent *v; v = adrof(&STReclkillring[0]); if (!v || !v->vec[0]) return(DEFAULT_KILLRING_SIZE); return(numeric_value(v->vec[0])); } unsigned char *ecl_cwd(void) { struct varent *v; v = adrof(STRcwd); if (!v || !v->vec[0]) return(0); return((void *)ecl_short2str(v->vec[0])); } int ecl_dotglob(void) { return(!!adrof(STRdotglob)); } int ecl_dotdotdotglob(void) { return(!!adrof(STRdotdotdotglob)); } int ecl_debug_completion(void) { static const Char STRecl_debug_completion[] = { 'e', 'c', 'l', '_', 'd', 'e', 'b', 'u', 'g', '_', 'c', 'o', 'm', 'p', 'l', 'e', 't', 'i', 'o', 'n', '\0' }; return(!!adrof(&STRecl_debug_completion[0])); } void dobind(Char **v, struct command *cmd __attribute__((__unused__))) { ecl_bind(ecl_short2blk(v)); } void dodisp(Char **v, struct command *cmd __attribute__((__unused__))) { ecl_disp(ecl_short2blk(v)); } void domacro(Char **v, struct command *cmd __attribute__((__unused__))) { ecl_macro(ecl_short2blk(v)); } const char *ecl_user_homedir(const char *user) { if (! *user) { Char *h; h = value(STRhome); return(h?ecl_short2str(h):0); } else { struct passwd *pw; pw = getpwnam(user); return(pw?pw->pw_dir:0); } } void ecl_user_home_scan(void (*each)(const char *, const char *)) { struct passwd *pw; setpwent(); while ((pw = getpwent())) (*each)(pw->pw_name,pw->pw_dir); endpwent(); } void ecl_check_locktty(void) { static int last = -1; int cur; cur = !!adrof(STRlocktty); if (cur != last) { last = cur; ecl_locktty_changed(cur); } } char **ecl_dollarsign_value(const char *name) { struct varent *v; char *e; char **rv; v = adrof(str2short(name)); if (v) return(ecl_short2blk(v->vec)); e = getenv(name); if (! e) return(0); rv = malloc(2*sizeof(char *)); rv[0] = strdup(e); rv[1] = 0; return(rv); } int ecl_keep_empty_history(void) { static const Char STRecl_keep_empty_history[] = { 'e', 'c', 'l', '_', 'k', 'e', 'e', 'p', '_', 'e', 'm', 'p', 't', 'y', '_', 'h', 'i', 's', 't', 'o', 'r', 'y', '\0' }; return(!!adrof(&STRecl_keep_empty_history[0])); } char *ecl_mark_display(void) { static const Char STRecl_mark_display[] = { 'e', 'c', 'l', '_', 'm', 'a', 'r', 'k', '_', 'd', 'i', 's', 'p', 'l', 'a', 'y', '\0' }; struct varent *v; v = adrof(&STRecl_mark_display[0]); if (!v || !v->vec[0]) return(0); return(ecl_short2str(v->vec[0])); }