static void sh_env(char **argv, char **env) { char **tab; if (argv[1] == NULL) print_env(env); else if (argv[1] != NULL && ft_strcmp(argv[1], "-i") == 0) { tab = (char**)ft_tabnew(2); tab[0] = NULL; tab[1] = NULL; exec_glob(argv + 2, tab); free_tab(tab); } else exec_glob(argv + 1, env); }
int exec_cmd(int under_glob, int under_until) { register int status; register char *p; int n; if((status = getrange()) <= ERROR) return( status ); status = ERROR9; switch( *lp++ ) { case 'i': laddr2 = prevln(laddr2); case 'a': status = append(laddr2, under_glob); break; case 'b': if(!under_glob && !under_until) status = branch(); break; case 'c': if((status = delete(laddr1, laddr2, SAVE)) == OK) status = append(prevln(laddr1), under_glob); break; case 'd': if((status = delete(laddr1, laddr2, SAVE)) == OK && nextln(curln) != 0) curln = nextln(curln); break; case 'e': if(lastln && dirty && *lp != 'e') { status = ERROR4; break; } if(*lp == 'e') ++lp; if(nladdrs == 0 && !under_glob && !under_until && (status = getfn()) == OK) { set_fn(curfile, lp); if(lastln != 0) delete(1, lastln, NOSAVE); num_delete_lines = 0; if((status = _read( lp, 0, 0)) == OK) { dirty = 0; if(lastln) curln = 1; } } lp = "\n"; break; case 'f': if(nladdrs == 0 && (status = getfn()) == OK) { set_fn(curfile, lp); putmsg(curfile); lp = "\n"; } change_state(CMD); break; case 'g': if(!under_glob) { if(*lp == '^') { ++lp; n = 0; } else n = 1; status = exec_glob(n, under_until); } break; case 'h': n = getint(); #ifndef __STDC__ while(n--) for(n1 = 0; n1 < 10; ++n1) time_slice(); #endif status = OK; break; case 'j': status = join(laddr2); break; case 'k': if((status = get_laddr_expr(&n)) == OK) status = kopy(n); break; case 'l': if(nladdrs == 0) status = learn(); break; case 'm': if((status = get_laddr_expr(&n)) == OK) status = move(n); break; case 'o': status = option(); break; case 'p': case 'P': status = prnt(laddr1, laddr2); break; case 'q': if(nladdrs==0 && !under_glob) { if((*lp=='\n' && !dirty) || *lp=='q' || lastln == 0) status = EOF; else status = ERROR4; } break; case 'r': if(!under_glob && !under_until && (status = getfn()) == OK) status = _read(lp, laddr2, 0); lp = "\n"; break; case 's': n = getint(); /* read occurance if present */ if((status=getpat()) == OK && (status=getsubst_str(tbuff)) == OK) status = substitute(tbuff, under_glob, n); break; case 't': case 'T': if(nladdrs == 0) status = translate(*(lp - 1) == 't'); break; case 'u': status = until(laddr1, laddr2, under_glob); break; case 'v': if(nladdrs <= 1) status = view(laddr1); break; case 'w': n = 0; if(*lp == 'w') { n |= 2; ++lp; } if(*lp == 'a') { n |= 1; ++lp; } if((status = getfn()) == OK) { if(nladdrs == 0) { if(curfile[0] == '\0') set_fn(curfile, lp); else { if((n & 2) == 0 && strcmp(curfile, lp) != 0) { for(p = lp ; *p ; ++p) if(*p == '$') goto ok; puterr(-19); lp = "\n"; break; } } ok: if((status = _write(lp, 1, lastln, n & 1, 0)) == OK) dirty = 0; } } else { status = _write(lp, laddr1, laddr2, n & 1, 0); } lp = "\n"; break; case 'x': if(!under_glob && !under_until && (status = getfn()) == OK) if(nladdrs == 0) status = exec_file(lp, under_glob, under_until); lp = "\n"; break; case 'y': status = yut(); break; case 'z': status = zap(); break; case '\n': --lp; /* put back newline for main */ if(laddr2 < 0 || laddr2 > lastln) status = lastln ? ERROR5 : OK; else { curln = laddr2; status = OK; } break; case ' ': case '\t': case CMD_CHAR: status = OK; break; case '=': dtoc(rbuff, laddr2); if(under_glob) prnt_screen(rbuff, 1); else putmsg(rbuff); status = OK; break; case '"': lp = "\n"; /* Ignore rest of line */ status = OK; break; case '!': if(escape_char == 0 || restrict_flag) { putmsg("Escape from ED inhibited"); status = NOTHING; } else status = exec_sys_cmd(under_glob, under_until); break; default: status = ERROR2; } return(status); }