int print_s(t_data *data, va_list arg) { int i; char *str; if (data->len_mod == 8) return (print_ls(data, arg)); str = va_arg(arg, char *); if (!str) { ft_printstr("(null)", data); return (1); } if (data->prec != -1) i = data->field - ft_min(ft_strlen(str), data->prec); else i = data->field - ft_strlen(str); if ((data->flag & 4) != 0) ft_printstr(str, data); while (i-- > 0) ft_printchar(' ', data); if ((data->flag & 4) == 0) ft_printstr(str, data); return (1); }
int do_ls0(char *argv[]) { init_ls(); int retval = hw3_ops.readdir(get_cwd(), NULL, filler, 0, NULL); print_ls(); return retval; }
int main(int argc, char** argv){ //contains decimal point if(is_float(argv[1])){ char* end; errno = 0; double d = strtod(argv[1], &end); if(errno != 0 || *end != 0){ fprintf(stderr, "invalid floating point number %s\n", argv[1]); return -1; } fp_struct fps = dissect_double(d); print_fps(stdout, fps); } else { //no decimal point, treat as a long char* end; errno = 0; long l = strtol(argv[1], &end, 10); if(errno != 0 || *end != 0){ fprintf(stderr, "invalid long integer %s\n", argv[1]); return -1; } long_struct ls = dissect_long(l); print_ls(stdout, ls); } return 0; }
static int sort_argv(t_list **list, t_arg *arg_list) { t_list *reg_list; bool first; bool alone; first = 1; if (*list != NULL) print_fakelist(list); if (*list != NULL) { reg_list = get_reglist(list); if (reg_list != NULL) { print_ls(reg_list, arg_list); ft_lstdel(®_list, free_list); first = 0; } } alone = 0; if ((*list) != NULL && (*list)->next == NULL) alone = 1; if (*list != NULL) return (base_list(*list, arg_list, alone, first)); else return (0); }
int do_ls1(char *argv[]) { char path[128]; sprintf(path, "%s/%s", get_cwd(), argv[0]); init_ls(); int retval = hw3_ops.readdir(fix_path(path), NULL, filler, 0, NULL); print_ls(); return retval; }
int _lsdashl(char *path) { struct stat sb; int retval = hw3_ops.getattr(path, &sb); if (retval == 0) { init_ls(); if (S_ISDIR(sb.st_mode)) retval = hw3_ops.readdir(path, NULL, dashl_filler, 0, NULL); else retval = dashl_filler(NULL, path, &sb, 0); print_ls(); } return retval; }
void do_lsr(char *arg) { if (arg == NULL) { arg = "."; } struct stat sb; if (lstat(arg, &sb) < 0) { perror("lstat"); return; } if (!S_ISDIR(sb.st_mode)) { print_ls(arg); } else { print_lsr(arg); } }
/* --- Main --- */ int main( int argc, char *argv[] ) { char buf[MAX_LENGTH]; char * cmd_argv[MAX_LENGTH]; char separators[4]; int n; int pid; int res; int j; int ret; separators[0] = ' '; separators[1] = '\t'; separators[2] = '\n'; separators[3] = '\0'; print( strlen( startmsg ), startmsg ); while( 1 ) { bzero( buf, MAX_LENGTH ); print( strlen(prompt), prompt ); n = mystical_readline( MAX_LENGTH - 1, buf ); if (n == 0) { /* Empty result; this shouldn't happen. */ print( strlen(nothing), nothing ); continue; } else if( n >= MAX_LENGTH ) { /* line too big -- kernel declared that it clobbered memory */ print( strlen(too_long), too_long); exit(-1); } else if(buf[MAX_LENGTH - 1] != '\0') { /* Overflow -- kernel tapdanced on random memory! */ print( strlen(null_check), null_check ); exit(-1); } buf[n] = '\0'; j = 0; if( !(cmd_argv[j++] = strtok(buf, separators)) ) { continue; } if( (strcmp( cmd_argv[0], "exit" ) == 0) ) { print( strlen( exitmsg ), exitmsg ); exit(0); } if( (strcmp( cmd_argv[0], "ls" ) == 0 ) ) { print_ls(); continue; } while( (cmd_argv[j++] = strtok(NULL, separators)) ); pid = fork(); if( pid < 0 ) { print( sizeof( forkerrmsg ), forkerrmsg ); continue; } if( pid == 0 ) { exec( cmd_argv[0], cmd_argv ); exit(-1); } else { if( (ret = wait( &res )) < 0 ) { printf("\nshell: wait on prcess %d failed!\n", pid); } else { printf("\nshell: process %d finished with exit status %d\n", ret, res); } } } /* while loop */ }
/* * A simple walk of event sets: dispatch and print a event SET every 2 sec */ void walk_el(int update_time, int time_between, int verb) { struct el *el; struct es *es_hd; struct es *es; assert (g_el->next); assert (get_myid >= 0); print_el(); /* initialize link set, routing table, and routing table */ create_ls(); create_rt(); init_rt_from_n2h(); for (el = g_el->next ; el != g_el ; el = el->next) { assert(el); es_hd = el->es_head; assert (es_hd); int *updated = (int *) calloc(256, sizeof(int)); struct es *myCurrES = es_hd->next; while(myCurrES->ev != _es_null){ if(myCurrES->ev == _es_link){ if(get_myid() == myCurrES->peer0){ update_rte(myCurrES->peer1, myCurrES->cost, myCurrES->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(myCurrES->peer0, myCurrES->cost, myCurrES->peer0); updated[myCurrES->peer0] = 1; } }else if(myCurrES->ev == _td_link){ struct link *linkToTd = find_link(myCurrES->name); if(get_myid() == linkToTd->peer0){ update_rte(linkToTd->peer1, -1, linkToTd->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(linkToTd->peer0, -1, linkToTd->peer0); updated[myCurrES->peer0] = 1; } }else if(myCurrES->ev == _ud_link){ struct link *linkToUd = find_link(myCurrES->name); if(get_myid() == linkToUd->peer0){ update_rte(linkToUd->peer1, myCurrES->cost, linkToUd->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(linkToUd->peer0, myCurrES->cost, linkToUd->peer0); updated[myCurrES->peer0] = 1; } } myCurrES = myCurrES->next; } printf("[es] >>>>>>>>>> Dispatch next event set <<<<<<<<<<<<<\n"); for (es=es_hd->next ; es!=es_hd ; es=es->next) { printf("[es] Dispatching next event ... \n"); dispatch_event(es); } runDVA(updated, 1); sleep(3); printf("[es] >>>>>>> Start dumping data stuctures <<<<<<<<<<<\n"); print_n2h(); print_ls(); print_rt(); } }
int main() { int count; char *rest, *command_str, *param_str, *param2_str; //Inicializar terminal... devreq(KEYBOARD); devreq(SCREEN); devreq(TERMINAL); while(TRUE) { write(TERMINAL, PROMPT, strlen(PROMPT)); count = read_line(line_buffer, BUFF_LEN); if (count == -1) { while (read_line(line_buffer, BUFF_LEN) != 1); write_line("Line too long"); } else { line_buffer[count -1] = NULL; rest = skip_spaces(line_buffer); if (!*rest) { command_use_error(); continue; } command_str = get_word(&rest); rest = skip_spaces(rest); param_str = get_word(&rest); rest = skip_spaces(rest); if (strcmp(HELP, command_str) == 0) { print_shell_use(); } else if (strcmp(ECHO, command_str) == 0) { write_line(param_str); } else if (strcmp(PS, command_str) == 0) { //Imprimir informacion de programas en ejecucion print_ps(param_str); } else if (strcmp(LS, command_str) == 0) { //Imprimir lista de programas disponibles print_ls(param_str); } else if (strcmp(RUN, command_str) == 0) { //Ejecutar un programa en foreground do_run(param_str); } else if (strcmp(RUN_BG, command_str) == 0) { //Ejecutar un programa en background do_runbg(param_str); } else if (strcmp(NICE, command_str) == 0) { param2_str = get_word(&rest); //Cambiar prioridad de un proceso do_nice(param_str, param2_str); } else if (strcmp(KILL, command_str) == 0) { //Ejecutar un programa en background do_kill(param_str); } else command_use_error(); } } return 0; }