void mysh(char **env) { t_envp envp; t_sh_token *token; t_glob_def def; if (!(init_def(&def))) return; msh_init_env(&envp, env); while (42) { token = parsed_entry(&def); if (token && token->up) process_entry(token, &envp); free_sh_token(token); } }
t_point parse_pipe(Hash *h, int level) { char chars[MAX_NAME_LENGTH]; char *c = chars; int whitespaces = 1; // cetli jsme whitespace? int first = 1; int is_def = 0; int is_close_tag = 0; Cons all = {NIL, NIL}; Cons *l = &all; t_point s = NIL; while ((c - chars) < MAX_NAME_LENGTH && (*c = read_char()) != EOF) { if (is_whitespace(*c) || (is_close_tag = (*c == CLOSE_TAG))) { if (whitespaces && !is_close_tag) continue; *c = '\0'; whitespaces = 1; if (first && ((is_def = (strcmp(chars, "def") == 0)) || (strcmp(chars, "lambda") == 0))) { if (is_close_tag) ERROR(SYNTAX_ERROR); if (is_def) { // is def if (!read_word(chars, 0)) ERROR(SYNTAX_ERROR); init_def(h, chars, level); } else { // is lambda return kontext_params(init_def(h, NULL, level), level); } break; } // c is not empy if (c != chars) { l->b = create_token(h, chars, level); if (first) { l->a = l->b; l->b = NIL; } else { l->b = pnew_List(l->b); l = next(l); } } if (is_close_tag) break; c = chars; first = 0; continue; } // nacitame dal if (!whitespaces) { c++; continue; } switch (*c) { case '\'': s = parse_char(); break; case '"': s = parse_string(); break; case OPEN_TAG: s = parse_pipe(h, level); break; default: c++; whitespaces = 0; continue; } if (s != NIL) { if (first) { l->a = s; l->b = NIL; first = 0; } else { l->b = pnew_List(s); l = next(l); } s = NIL; } } if ((c - chars) >= MAX_NAME_LENGTH) ERROR(SYNTAX_ERROR); if (all.b == NIL && !is_Func(all.a)) return all.a; else return pnew_Thunk(all.a, get_Cons(all.b)); }