bool edit_select_rep::semantic_active (path q) { if (as_string (eval ("(get-preference \"semantic editing\")")) == "on") { path p= semantic_root (q); //cout << subtree (et, p) << ", " << p << " -> " << end (et, p) << "\n"; tree mt= get_env_value (MODE, end (et, p)); tree lt= get_env_value (MODE_LANGUAGE (mt->label), end (et, p)); string lan= (is_atomic (lt)? lt->label: string ("std-math")); if (mt == "math" || (mt == "prog" && lan == "minimal")) return packrat_available_path (lan, subtree (et, p), q / p); } return false; }
bool edit_interface_rep::set_hybrid_footer (tree st) { // WARNING: update edit_dynamic_rep::activate_hybrid when updating this if (is_atomic (st)) if (is_func (subtree (et, path_up (tp, 2)), HYBRID, 1)) { string msg; // macro argument string name= st->label; path mp= search_upwards (MACRO); if (!is_nil (mp)) { tree mt= subtree (et, mp); int i, n= N(mt)-1; for (i=0; i<n; i++) if (mt[i] == name) { set_message (concat (kbd ("return"), ": insert argument ", name), "hybrid command"); return true; } } // macro application tree f= get_env_value (name); if (drd->contains (name) && (f == UNINIT)) set_message (concat (kbd ("return"), ": insert primitive ", name), "hybrid command"); else if (is_func (f, MACRO) || is_func (f, XMACRO)) set_message (concat (kbd ("return"), ": insert macro ", name), "hybrid command"); else if (f != UNINIT) set_message (concat (kbd ("return"), ": insert value ", name), "hybrid command"); else return false; return true; } return false; }
static int check_path(char **tab, t_shell *shell) { char *path; char sub_path[PWD_BUFFER_SIZE]; int index; path = get_env_value(ENV_PATH, shell->env); if (!path || !my_strlen(path)) return (0); index = 0; do { get_sub_path(path, sub_path, &index); my_strncat(sub_path, tab[0], PWD_BUFFER_SIZE); if (access(sub_path, F_OK | X_OK | R_OK) == 0) { exec(tab, NULL, sub_path); return (1); } else if (errno != ENOENT) { print_errno(sub_path); return (1); } } while (index < my_strlen(path)); return (0); }
/* Check for LC_ALL, LC_CTYPE, and LANG and use the first with a value to decide the defaults for 8-bit character input and output. Returns 1 if we set eight-bit mode. */ int _rl_init_eightbit () { /* If we have setlocale(3), just check the current LC_CTYPE category value, and go into eight-bit mode if it's not C or POSIX. */ #if defined (HAVE_SETLOCALE) char *t; /* Set the LC_CTYPE locale category from environment variables. */ t = setlocale (LC_CTYPE, ""); if (t && *t && (t[0] != 'C' || t[1]) && (STREQ (t, "POSIX") == 0)) { _rl_meta_flag = 1; _rl_convert_meta_chars_to_ascii = 0; _rl_output_meta_chars = 1; return (1); } else return (0); #else /* !HAVE_SETLOCALE */ char *lspec, *t; int i; /* We don't have setlocale. Finesse it. Check the environment for the appropriate variables and set eight-bit mode if they have the right values. */ lspec = get_env_value ("LC_ALL"); if (lspec == 0) lspec = get_env_value ("LC_CTYPE"); if (lspec == 0) lspec = get_env_value ("LANG"); if (lspec == 0 || (t = normalize_codeset (lspec)) == 0) return (0); for (i = 0; t && legal_lang_values[i]; i++) if (STREQ (t, legal_lang_values[i])) { _rl_meta_flag = 1; _rl_convert_meta_chars_to_ascii = 0; _rl_output_meta_chars = 1; break; } free (t); return (legal_lang_values[i] ? 1 : 0); #endif /* !HAVE_SETLOCALE */ }
bool edit_select_rep::semantic_select (path p, path& q1, path& q2, int mode) { if (!semantic_active (p)) return false; if (mode < 2 && get_preference ("semantic selections") != "on") return false; p= semantic_root (p); while (p != rp && !(p <= q1 && p <= q2)) p= semantic_root (path_up (p)); tree mt= get_env_value (MODE, end (et, p)); tree lt= get_env_value (MODE_LANGUAGE (mt->label), end (et, p)); string lan= (is_atomic (lt)? lt->label: string ("std-math")); path p1= q1 / p, p2= q2 / p; path cp= (p <= tp? tp / p: path ()); tree st= subtree (et, p); bool ret= packrat_select (lan, "Main", st, cp, p1, p2, mode); if (ret) { q1= p * p1; q2= p * p2; } return ret; }
char *key_to_value(t_list *env, char *key) { t_list *curr; curr = env; while (curr != NULL) { if (my_strcmp(get_env_key(curr->data), key) == 0) return (get_env_value(curr->data)); curr = curr->next; } return (NULL); }
void builtin_cd(t_env *c) { char *pwd; const char error[] = "cd: Too many arguments.\n"; if (c->ac > 2) write(1, error, sizeof(error) - 1); else if (c->ac == 1) { if ((pwd = get_env_value(c->my_env, "HOME"))) do_cd(c, pwd + 5); } else if (ft_strcmp(c->av[1], "-") == 0) { if (!(pwd = get_env_value(c->my_env, "OLDPWD"))) write(1, ": No such file or directory.\n", 29); else do_cd(c, pwd + 7); } else do_cd(c, c->av[1]); }
tree edit_typeset_rep::get_env_value (string var) { /* FIXME: tp is wrong (and consequently, crashes TeXmacs) * when we call this routine from inside the code which * is triggered by a button, for example. * * Test: fire TeXmacs, then open a new Graphics, then click * on the icon for going in spline mode. Then it crashes, * because we call (get-env-tree) from inside the Scheme. * If we call (get-env-tree-at ... (cDr (cursor-path))), * then it works. */ return get_env_value (var, tp); }
void raw_terminal_mode(t_sh *shell) { struct termios tattr; char *env_term; tcgetattr(STDIN_FILENO, &shell->default_termios); tcgetattr(STDIN_FILENO, &tattr); if ((env_term = get_env_value("TERM", shell->env))) { tattr.c_lflag &= ~(ECHO | ICANON); tattr.c_oflag &= (OPOST); tattr.c_cc[VMIN] = 1; tattr.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSADRAIN, &tattr); tgetent(NULL, env_term); } }
int main(int argc, char **argv, char **envp) { t_char *list; t_env **env; (void)argc; (void)argv; list = NULL; char_add(&list, char_new('-')); *(getactivelist()) = &list; env = ft_getenv(); *env = ft_load_env(envp); (ft_saved_env())->home = ft_strdup(get_env_value("HOME")); term_initiate(); ft_putstr_fd("$> ", *(gettty())); *(getcurpos()) = 3; show_prompt(&list, envp); return (0); }
int my_replace_key(char **expr, t_data *data) { int i; char *buffer; i = 0; if (!expr || !expr[0] || !data || !data->env) return (FAILURE); while (expr[i]) { if (expr[i][0] == '$') { if ((buffer = get_env_value(data->env, expr[i] + 1, NULL)) != NULL) expr[i] = buffer; } ++i; } return (SUCCESS); }
void do_cd(t_env *c, char *moveto) { char **tmp; char *oldtmp; char *tmpgetcwd; oldtmp = ft_strdup(get_env_value(c->my_env, "PWD") + 4); if (!try_cd(moveto, oldtmp)) return ; tmp = set_env_element(c->my_env, "OLDPWD", oldtmp); ft_tab_free(c->my_env); c->my_env = tmp; tmpgetcwd = getcwd(NULL, 0); tmp = set_env_element(c->my_env, "PWD", tmpgetcwd); free(tmpgetcwd); ft_tab_free(c->my_env); c->my_env = tmp; free(oldtmp); }
tree edit_select_rep::selection_get_env_value (string var) { if (!selection_active_any ()) return get_env_value (var); return get_env_value (var, selection_get_cursor_path ()); }
double edit_typeset_rep::get_env_double (string var) { return as_double (get_env_value (var)); }
int edit_typeset_rep::get_env_int (string var) { return as_int (get_env_value (var)); }
string edit_typeset_rep::get_env_string (string var) { return as_string (get_env_value (var)); }