int my_printf(int fd, char *str, ...) { va_list ap; t_fonct *tab; t_print pri; pri.fd = fd; tab = NULL; tab = init_struct(tab); pri.i = 0; if (str == NULL || tab == NULL) return (-1); va_start(ap, str); while (pri.i < my_strlen(str)) { if (str[pri.i] == '%') pri.i = print_fct(ap, tab, str, pri); else my_putchar_in(fd, str[pri.i]); pri.i++; } va_end(ap); free(tab); return (0); }
double ft_atof(char *num) { t_atof a; int i; i = 0; if (!num || !*num) return (0); init_struct(&a); get_sign(&num, &a); while (num[i] != '\0') { if (num[i] >= '0' && num[i] <= '9') get_int(num[i], &a); else if (num[i] == '.') { if (a.fraction) return (a.sign * (a.integer_part + a.fraction_part / a.divisor)); else a.fraction = 1; } else return (a.sign * (a.integer_part + a.fraction_part / a.divisor)); i++; } return (a.sign * (a.integer_part + a.fraction_part / a.divisor)); }
void pipe_in_list(char **tmp, t_list *list, int **pipe_fd, int nb_pipe) { t_command *command; int fd[2]; int i; int j; i = 0; j = 0; if ((command = malloc(sizeof(t_command))) == NULL) exit (0); init_struct(command); while (nb_pipe > 0) { add_pipe(pipe_fd, command, fd, j); command->data = my_str_to_wordtab(tmp[i++], ' '); my_insert_pushfront(list, command); command->input = fd[0]; j += 2; nb_pipe -= 1; } command->output = -1; command->data = my_str_to_wordtab(tmp[i], ' '); my_insert_pushfront(list, command); }
int main(int argc, char **argv) { char *line; t_check check; t_cells *cells; cells = NULL; line = NULL; FT_INIT(int, verif, 1); init_struct(&check, argc, argv); while (verif) { verif = get_next_line(0, &line); if (!check_lemin(line, &check, &cells)) { ft_putstr("ERROR\n"); free_chaine(&check.start_list, &check); return (-1); } if (verif) { ft_putendl(line); ft_memdel((void*)&line); } } free_chaine(&check.start_list, &check); return (1); }
int main(int argc, char **argv) { t_struck s; t_pc *proc; unsigned long long i[3]; if (argc == 1) ft_usage(); init_struct(&s); proc = NULL; check_valid_file(&s, argv, 0); map_gen(&s, &proc, -1, i); s.pro = &proc; if (s.rep & GRAPH) { init_graph(&s); mlx_hook(s.img.win, 2, (1l << 0), key_functions, &s); mlx_hook(s.img.menu, 2, (1l << 0), key_functions, &s); s.rep ^= STOP; mlx_loop_hook(s.img.mlx, aff_graph, &s); mlx_loop(s.img.mlx); } else launching_vm(&s); return (0); }
char *fget_next_line(FILE *fd) { t_struct tbl; static char buf[BUF_SIZE]; static int i = 0; static int lu = 0; if (!init_struct(&tbl)) return (0); while (1) { if (i >= lu) { lu = (int)fread(buf, 1, BUF_SIZE, fd); if (lu == 0) return ((tbl.s[0]) ? (end_of(tbl.s, tbl.j)) : (0)); i = 0; } if ((tbl.j + 1) == tbl.taille) realloc_s(&tbl); if (buf[i] == '\n' || !buf[i]) { i++; return (end_of(tbl.s, tbl.j)); } tbl.s[tbl.j++] = buf[i++]; } }
int check_format(const char *format) { t_struct form; int i; i = 0; init_struct(&form); while ((check_options(format[i], &form)) == 1) i++; while ((check_minimal_large(format[i], &form)) == 1) i++; if (format[i] == '.') { form.prec = 0; while ((check_precision(format[++i], &form)) == 1) continue; } while (format[i] == 'h' || format[i] == 'l' || format[i] == 'j' || format[i] == 'z') { check_size_modifier(format + i, &form); i++; if ((&form)->hh > 0 || (&form)->ll > 0) i++; } check_type(format[i]) == 1 ? (&form)->type = format[i] : 0; return (check_block(ft_strsub(format, 0, i + 1), &form)); }
int main(int ac, char **av) { t_params p; t_dlist *dirs_to_open; t_dlist *nav; t_dlist *dir_files; t_colors *colors; dir_files = NULL; init_struct(&p); get_linked_lists(&dirs_to_open, &p, ac, av); nav = dirs_to_open; while (nav) { if (nav->before != NULL || nav->next != NULL) ft_print_twostr(nav->content, ":\n"); get_da_list(&dir_files, &p, nav->content); if_forest_params(&dir_files, nav, &p, 1); ft_dlstdel(&dir_files, del_struct); if (nav->next) ft_putchar('\n'); nav = nav->next; } ft_dlstdel(&nav, NULL); if (p.colors) free(p.colors_tab); return (0); }
void init_lum_shadow(t_all *infos, t_object *object, t_pixel *pixel, t_eye *eye) { t_spot *tmp_spot; t_coord pt_inter; t_coord v_norm; t_eye eye_tmp; double shadow; init_struct(eye, &eye_tmp, &pt_inter, pixel); lum_shadow(infos, &pt_inter, object, pixel); tmp_spot = infos->spots; shadow = 0; while (tmp_spot != NULL) { new_eye_posi(&eye_tmp, tmp_spot, &pt_inter); if (calc_obj(infos->objects, object, &eye_tmp) > 0) shadow += ((double) WIN(tmp_spot->intensity, 0, 100)) / SHADOW_FACTOR; tmp_spot = tmp_spot->next; } set_shadows(pixel, &shadow); if (object->reflexion > 0 && ++infos->travels < TRAVEL_LIMIT) { calc_vector_n(object, &pt_inter, &v_norm); init_reflection(&eye_tmp, eye, &v_norm, &pt_inter); reflection(infos, object, pixel, &eye_tmp); } }
int main() { // Allocate space for the structs struct point p1; struct point p2; // Initialize the structs by passing them to init_struct // Notice that we pass a pointer to init_struct init_struct(&p1, 4, 5); init_struct(&p2, 6, 7); // Print the values of p1 and p2: printf("P1's values: %d, %d\n", p1.x, p1.y); printf("P2's values: %d, %d\n", p2.x, p2.y); return 0; }
int main() { init_struct(st, "This is str", 10, 20); func(); printf("Use GDB\n"); return 0; }
int main(int argc, char **argv) { t_cloud data; init_struct(&data); if (argc != 2) error_fdf("fdf"); parser(argv, &data); draw_points(data.start_node, &data); mlx_hook(data.win, 2, (1L << 0), distrib_key, &data); mlx_loop(data.mlx); return (0); }
int init_value(t_all *all, char **tab) { char *str; if ((all->objects = malloc(sizeof(t_object) * get_size(tab))) == NULL) return (put_error_int("Error : malloc failed\n")); init_struct(all, get_size(tab)); get_window(all, tab[0]); get_name(all, tab[1]); get_eye(all, tab[3]); init_get_object(all, tab + 5); init_get_light(all, tab + 5); /* printf("name %s eyex %G eyey%G eyez%G X%d Y%d\n", all->my.name, all->eye.x, all->eye.y, all->eye.z, all->my.x_size, all->my.y_size); */ }
void add_after (nei_list* node, int rank, int coord_x, int coord_y, int bix, int bsx, int biy, int bsy){ nei_list *nn = (nei_list*) malloc (sizeof(nei_list)); if (nn != NULL){ nn->rank = rank; nn->point = init_struct(coord_x, coord_y); nn->inter = init_borne(bix, bsx, biy, bsy); nn->prev = node; nn->next = node->next; node->next->prev = nn; node->next = nn; } }
int main(int ac, char **av) { t_p4 *p4; p4 = NULL; if (error_usage(ac, av) == -1) return (-1); ft_putendl("\n\tWelcome to puissance 4"); ft_putendl(""); p4 = init_struct(p4, av); put_gameboard(p4); whoplaysfirst(p4); return (0); }
void run(double nbMesures, double moyArith, double moyHarmo, double ecTy) { bool _end = false; t_variable _var; t_result _res; double nbAdd = 0; int n; char p[SIZE_BUFFER]; memset(p, '\0', SIZE_BUFFER); init_struct(&_var, &_res, nbMesures, moyArith, moyHarmo, ecTy); while (!_end) { nbAdd = write(1, "indtast din vaerdi : ", 21); n = read(0, p, SIZE_BUFFER - 1); p[n - 1] = '\0'; if (n > 1 && n < SIZE_BUFFER) { if (strncmp("ende", p, n) == 0) _end = true; else if (verif_number(p)) { nbAdd = atof(p); moy_arith(&_var, &_res, nbAdd); moy_quadra(&_var, &_res, nbAdd); moy_harmo(&_var, &_res, nbAdd); ec_type(&_var, &_res, nbAdd); printresult(&_res); usleep(500); } } memset(p, '\0', SIZE_BUFFER); init_struct(&_var, &_res, _res.newNbMesures, _res.newMoyArith, _res.newMoyHarmo, _res.newEcTy); } }
int main(int ac, char **av, char **env) { t_utils utils; char *path_history; ac = (int)ac; av = (char **)av; path_history = create_path_history(); init_struct(&utils); add_history_to_list(&(utils.history)); check_env(&utils, env); my_read(&utils); add_history_to_file(path_history, utils.history); my_free(&utils); return (utils.my_exit); }
static int init_rw_queue(struct zcopy_hash_table * zht, struct map_addr_info * addrinfo, pthread_mutex_t ** lock, int read) { int err = -1; int i = 0; init_struct(zht, addrinfo); if(rw_disabled(read)) return 0; addrinfo->map_size = read ? zc.rx_size : zc.wx_size ; addrinfo->ht_map_size = read ? zc.rx_ht_size : zc.wx_ht_size; addrinfo->map_flag = read ? ZCOPY_MAP_RX : ZCOPY_MAP_WX; addrinfo->ht_map_flag = read ? ZCOPY_MAP_HT_RX : ZCOPY_MAP_HT_WX; err = mmap_rw_mem(addrinfo); if(err) goto err; err = init_queue_info(zht, addrinfo, read); if(err) goto err; *lock = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t) * zc.thread_num); if(*lock == NULL) { E("lock malloc memory failed.\n"); err = -1; goto err; } for(i = 0; i < zc.thread_num; ++i) { if((err = pthread_mutex_init(&(*lock)[i], NULL)) != 0) { E("pthread mutex init failed.\n"); goto err; } } D("%s: skb_count %llu, hash_count %u, bucket_count_per_queue %u.\n", read ? "read" : "write", zht->ht->zkb_count, \ zht->ht->hash_count, zht->ht->bucket_count_per_queue); return 0; err: release_rw_mem(zht, addrinfo); return err; }
int main(int ac, char **av) { t_serv serv; struct sockaddr_in sin; struct sockaddr_in csin; if (ac != 2) { write(2, "Usage : ./serveur port\n", 24); exit(EXIT_FAILURE); } serv.sin = &sin; serv.csin = &csin; serv.port = atoi(av[1]); init_serv(&serv, getprotobyname("TCP")); init_struct(&serv); get_clients(&serv); xclose(serv.s); return (EXIT_SUCCESS); }
/*----------------------------------------------------------------------------------------------------------- * * FUNCTION: read_from_server * * PROGRAMMER/DESIGNER: Martin Minkov * * INTERFACE: void read_from_server(int msg_id, long clientPID) * int msg_id: The ID of the message queue * long clientPID: The PID of the running client process * * RETURNS: void * * NOTES: Calls a blocking reading call on the message queue. Once data is read, the * function will print any information to the user via the console. If the server * sends an error message or end of file message, the program will exit and * prompt the user for another file name. * * ---------------------------------------------------------------------------------------------------------*/ void read_from_server(int msg_id, long clientPID) { long pid = clientPID, result, flag = 0; msgbuf *msg = { 0 }; msg = init_struct(msg); while ((result = read_message (msg_id, pid, msg)) != -1) { printf("%s", msg->msg_data); if (((strstr(msg->msg_data, ERROR)) != NULL) || (msg->msg_done == 1)) { flag = 1; } if (flag == 1) { free(msg); break; } } }
int init_value(t_all *all, char **tab) { all->nb_obj = get_size(tab); if ((all->objects = malloc(sizeof(t_object) * get_size(tab))) == NULL) return (put_error_int("Error : malloc failed\n")); init_struct(all, get_size(tab)); write(1, "\n", 1); get_window(all, tab[0]); write(1, "Z", 1); get_name(all, tab[1]); write(1, "Q", 1); get_eye(all, tab[3]); write(1, "S", 1); init_get_object(all, tab + 5); write(1, "D", 1); init_get_light(all, tab + 5); write(1, "W", 1); write(1, "\n", 1); return (0); }
int mbis(int ac, char **av) { t_rt *core; render = 0; redraw = 0; if (!(core = my_xmalloc(sizeof(t_rt)))) return (-1); core->cluster = 1; core->save = NULL; if (ac >= 3 && (check_save_opt(&av[2], core))) { free(core); return (-1); } if (init_struct(core, av[1]) == -1 || mlx_node(core) == -1) return (1); free_rt(core); return (0); }
int main(int argc, char **argv) { t_stack *stack; char *tmp; int size; if (argc < 2) error_fn(argv[0], 0); if (argc == 2) tmp = argv[1]; if (argc > 2) tmp = get_string(argc, argv); check_string(tmp, argc); init_struct(&stack, tmp, argc); size = get_tab(tmp, stack); init_stack_b(stack, size); if ((size == 1 || check_sort_tab(stack, size) == 0)) ft_putstr(""); else size > 80 ? quick_sort(stack, size) : bubble_sort(stack, size); free_stack(stack); return (0); }
/*----------------------------------------------------------------------------------------------------------- * * FUNCTION: main * * PROGRAMMER/DESIGNER: Martin Minkov * * INTERFACE: int main(int argc, char* argv[]) * * RETURNS: int - If the function failed or succeeded * * NOTES: Initializes the message queue that will be used for communication between the * client and server. If a user specified a command line argument, it is assumed * that they want higher priority, so the value will be stored in the message * data structure. * * ---------------------------------------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int msg_id; key_t key = 0; msgbuf *msg = { 0 }; msg = init_struct(msg); signal(SIGINT, cleanup_client); //Check if priority was assigned if (argc == 2) { msg->msg_priority = atoi(argv[1]); } else { msg->msg_priority = 1; } //Create message queue msg_id = create_queue(key); read_file_name(msg_id, msg); return 0; }
int main(int argc, char **argv) { t_env *env; if (argc > 1 && argc <= 3) { env = (t_env *)malloc(sizeof(t_env)); if (ft_strcmp(argv[1], "/dev/random") == 0) return (0); read_that_file(argv[1], env); if (init_struct(env) == 0 || env->map == NULL ) { ft_putstr("d1\n"); return (0); } if (argc == 3) check_argv(argv[2], env); mlx_key_hook(env->win, ft_key_hook, env); mlx_expose_hook(env->win, expose_hook, env); mlx_do_sync(env->mlx); mlx_loop(env->mlx); } return (0); }
int main(int argc, char **argv) { int fd; t_cloud data; t_node nodes; init_struct(&data); if (argc <= 1 || argc >= 3) return (argc <= 1 ? error("Too few arguments") : error("Too many arguments")); if (argc != 2) return (error("Error parameters")); if ((fd = open(argv[1], O_RDONLY)) == -1) return (error("Error open file")); if (!parser(fd, &data, &nodes)) return (error("Parsing Error")); close(fd); draw_points(data.start_node, &data); mlx_hook(data.win, 2, (1L << 0), distrib_key, &data); // mlx_key_hook(data.win, distrib_key, &data); mlx_loop(data.mlx); return (0); }
// ------------------------------------------------------------------ // Funcion que realiza un post al WS // ------------------------------------------------------------------ int PostToWS(const char *url, const char *postData, char result[2048]) { char tmp[1024]; char tmpb[1024]; int exitStatus = 0; CURL* curl; CURLcode res; struct WritePOST wtext; struct ReadPOST rtext; init_struct(&rtext); /* Headers */ struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Accept: application/json"); headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, "charsets: utf-8"); // Parameters for call wtext.ptr = postData; wtext.sizeleft = strlen(postData); /* Initialise libcurl */ curl_global_init(CURL_GLOBAL_ALL); /* Get a curl handle */ curl = curl_easy_init(); if(curl) { //printf("%s", url); /* First set the URL that is about to receive our POST. */ curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); /* Now specify we want to POST data */ curl_easy_setopt(curl, CURLOPT_POST, 1L); /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* pointer to pass to our read function */ curl_easy_setopt(curl, CURLOPT_READDATA, &wtext); /* get verbose debug output please */ //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* Set the expected POST size. If you want to POST large amounts of data, consider CURLOPT_POSTFIELDSIZE_LARGE */ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)wtext.sizeleft); /* we want to use our own write function */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); /* pointer to pass to our write function */ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &rtext); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); if(res) { sprintf(tmp, "ERROR: %s", curl_easy_strerror(res)); printf("%s\n", tmp); exitStatus = 0; } else { if(rtext.ptr != NULL) { if(strlen(rtext.ptr) > 0) { sprintf(result, "%s", rtext.ptr); // Imprimir resultados del WS printf("\nA: %s\n", result); } else { printf("\nA: if(strlen(rtext.ptr) > 0) es falso"); } free(rtext.ptr); } exitStatus = 1; } /* always cleanup */ curl_easy_cleanup(curl); } else { exitStatus = 0; } /* Return the exit status */ return exitStatus; }
int mat_fill_info (struct reglist * rl, mxArray ** D) { int i; mxArray * map; mxArray * board; mxArray * regblock; mxArray * tmp; mxClassID mat_class; int numchan; init_struct (rl, D); for (i=0; i<rl->num_regblocks; i++) { map = mxGetField (*D, 0, rl->r[i].rb.map); if (map == NULL) return -1; board = mxGetField (map, 0, rl->r[i].rb.board); if (board == NULL) return -1; regblock = mxCreateStructMatrix(1, 1, sizeof(fieldnames)/sizeof(char *), fieldnames); switch (rl->r[i].rb.typeword & GCP_REG_TYPE) { case GCP_REG_UINT: tmp = mxCreateString("uint32"); break; case GCP_REG_INT: tmp = mxCreateString("int32"); break; case GCP_REG_USHORT: tmp = mxCreateString("uint16"); break; case GCP_REG_SHORT: tmp = mxCreateString("int16"); break; case GCP_REG_UCHAR: tmp = mxCreateString("uint8"); break; case GCP_REG_CHAR: tmp = mxCreateString("int8"); break; case GCP_REG_FLOAT: tmp = mxCreateString("single"); break; case GCP_REG_DOUBLE: tmp = mxCreateString("double"); break; /* Just treat UTC times as a UINT64, for now. */ case GCP_REG_UTC: tmp = mxCreateString("utc"); break; default: PR ("Skipping register of type 0x%lx.\n", rl->r[i].rb.typeword & GCP_REG_TYPE); tmp = mxCreateString("unknown"); } mxSetField (regblock, 0, "class", tmp); tmp = mxCreateDoubleScalar (rl->r[i].rb.spf); mxSetField (regblock, 0, "spf", tmp); tmp = mxCreateDoubleScalar (rl->r[i].rb.nchan); mxSetField (regblock, 0, "nchan", tmp); tmp = mxCreateLogicalScalar (rl->r[i].rb.spf > 1); mxSetField (regblock, 0, "is_fast", tmp); tmp = mxCreateLogicalScalar (rl->r[i].rb.do_arc); mxSetField (regblock, 0, "do_arc", tmp); mxSetField (board, 0, rl->r[i].rb.regblock, regblock); } return 0; }