static bool_t _process_parameters(int argc, char* argv[]) { int i = 1; char* prog = 0; bool_t eval = false; bool_t help = false; char* memp = 0; char* diri = 0; while(i < argc) { if(!memcmp(argv[i], "-", 1)) { if(!memcmp(argv[i] + 1, "e", 1)) { eval = true; _CHECK_ARG(argc, i, "-e: Expression expected.\n"); prog = argv[++i]; } else if(!memcmp(argv[i] + 1, "h", 1)) { help = true; #if _USE_MEM_POOL } else if(!memcmp(argv[i] + 1, "p", 1)) { _CHECK_ARG(argc, i, "-p: Memory pool threashold size expected.\n"); memp = argv[++i]; if(argc > i + 1) prog = argv[++i]; #endif /* _USE_MEM_POOL */ } else if(!memcmp(argv[i] + 1, "f", 1)) { _CHECK_ARG(argc, i, "-f: Importing directories expected.\n"); diri = argv[++i]; } else { _printf("Unknown argument: %s.\n", argv[i]); } } else { prog = argv[i]; } i++; } #if _USE_MEM_POOL if(memp) _POOL_THRESHOLD_BYTES = atoi(memp); #else /* _USE_MEM_POOL */ mb_unrefvar(memp); #endif /* _USE_MEM_POOL */ if(diri) _set_importing_directories(diri); if(eval) _evaluate_expression(prog); else if(prog) _run_file(prog); else if(help) _show_help(); else return false; return true; }
/** * Run initial preparations for the shell * **/ void init(int argc, char *argv[]) { int i; char* script; zshmode = 0; debug = 0; xflag = 0; fileflag = 0; // working directory cwd = (char*)malloc(500*sizeof(char)); getcwd(cwd, 500); // zsh prompt counter env_com_count = 1; // username and hostname env_username = getenv("USER"); gethostname(env_hostname, HOSTSIZE); // get term width struct winsize ws; ioctl(STDIN_FILENO, TIOCGWINSZ, &ws); env_tty_width = ws.ws_col; // setup background process handling proc_init(); // setup env variables env_init(); // set debug, xflag, and fileflag if (argc > 1) { for(i=1; i<argc; i++) { if(!strcmp(argv[i], "-d") && (i + 1) < argc ) { debug = !strcmp(argv[i+++1], "1"); dprint("debug mode activated"); } else if(!strcmp(argv[i], "-x")) { xflag = 1; } else if(!strcmp(argv[i], "-zsh")) { zshmode = 1; } else if(strcmp(argv[i-1], "-d") && !fileflag) { fileflag = 1; script = argv[i]; if(i+1 < argc) { int j; //printf("argc = %d\n", argc); for(j = i + 1; j < argc; j++) { char *tc = malloc(100 * sizeof(char)); //char *dollar = malloc(100 * sizeof(char)); //sprintf(dollar, "%s", ""); sprintf(tc, "%d", j-i); //strcat(dollar, tc); //strcat(dollar, "="); //strcat(dollar, argv[j]); //printf("dollar = %s\n", dollar); env_add(tc, argv[j]); //putenv(dollar); free(tc); //free(dollar); } } _run_file(script); } } } }