int main(int ac, char **av, char **env) { char *line2; t_e e; (void)ac; (void)av; e.list = ft_env_cpy(env); signal(SIGQUIT, ft_signal); show_prompt(e.list); while (get_next_line(0, &(e.line)) == 1) { line2 = exange_tab_or_space(e.line); e.args = ft_strsplit(line2, ' '); if (e.args && e.args[0]) { if (ft_strchr(e.args[0], '/')) exec_absolu(e.line, e.list); else do_command(&(e.list), e.line); } free(e.line); show_prompt(e.list); free_char_array(e.args); } ft_putchar('\n'); return (0); }
int main(void) { char *line; char *line2; t_list *list; char **args; list = ft_env_cpy(); signal(SIGINT, ft_signal); show_prompt(list); while (get_next_line(0, &line) == 1) { line2 = exchange_tab_for_space(line); args = ft_strsplit(line2, ' '); if (args && args[0]) { if (ft_strchr(args[0], '/')) exec_absolu(line, list); else do_command(&list, line); } free(line); show_prompt(list); free_char_array(args); } ft_putchar('\n'); return (0); }
const char *xml_get_string_value(xmlDoc *doc, char *format, ...) { va_list ap; char str[4096]; va_start(ap, format); vsnprintf(str, 4095, format, ap); va_end(ap); int i,n; char **arr; int found = TRUE; split_into_array(str, '.', &n, &arr); xmlNode *cur = xmlDocGetRootElement(doc); // first item much match the name of the root if (strcmp(arr[0], (char*)cur->name)!=0) { // root node doesn't match -- return empty string strcpy(buf, ""); } else { // subsequent items specify the search path through the xml tree for (i=1; i<n; ++i) { char *elem; int k; extract_array_specifier(arr[i], &elem, &k); xmlNode *next = findNode(doc, cur, elem, k); if (!next) { // not found -- return NULL found = FALSE; strcpy(buf, ""); FREE(elem); break; } FREE(elem); cur = next; } } if (found) { assert(cur != NULL); xmlChar *ret = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); strncpy_safe(buf, (char*)ret, MAX_LEN-1); xmlFree(ret); } else { strcpy(buf, MAGIC_UNSET_STRING); } free_char_array(&arr, n); return buf; }
static void exec_absolu(char *line, t_list *list) { char **str; str = ft_strsplit(line, ' '); if (check_cmd(str[0])) ft_execve(str[0], str, list); else ft_erreur(line, ERR_NO_SUCH_FILE, 0); free_char_array(str); }
void ft_unsetenv(t_list **list, char *line) { char **cmp; cmp = ft_strsplit(line, ' '); if (char_array_size(cmp) >= 2) { list_remove(list, cmp[1]); } else ft_erreur(BUILTIN_UNSETENV, ERR_NOT_ENOUGH_ARGS, 0); free_char_array(cmp); }
void ft_cd(t_list **list, char *line) { char *pwd; char **argum; char *cwd; pwd = search(*list, "PWD="); argum = ft_strsplit(line, ' '); if (char_array_size(argum) == 1) ft_oldpwd(list, "HOME=", "PWD="); else if (char_array_size(argum) == 2) { if (ft_strcmp(argum[1], "-") == 0) { ft_putendl(search(*list, "OLDPWD=") + 7); ft_oldpwd(list, "OLDPWD=", "PWD="); } else reduc_cd(list, argum[1], pwd, cwd); } free_char_array(argum); }
void show_prompt(t_list *list) { char *pwd; char **path_components; char *prompt; int component_count; pwd = search(list, "PWD=") + 4; path_components = ft_strsplit(pwd, '/'); write(1, "[POKEMON] ", 10); component_count = char_array_size(path_components); if (component_count < 2) ft_putstr(pwd); else { prompt = join(path_components[component_count - 2], "/", path_components[component_count - 1]); ft_putstr(prompt); free(prompt); } write(1, " > ", 3); free_char_array(path_components); }
void free_base_tree_node(struct base_tree_node *n) { free_char_array(n->base_list); free(n); }
const char *xml_get_string_attribute(xmlDoc *doc, char *format, ...) { va_list ap; char str[4096]; va_start(ap, format); vsnprintf(str, 4095, format, ap); va_end(ap); int i,n; char **arr; int found = TRUE; split_into_array(str, '.', &n, &arr); xmlNode *cur = xmlDocGetRootElement(doc); // first item much match the name of the root if (strcmp(arr[0], (char*)cur->name)!=0) { // root node doesn't match -- return empty string strcpy(buf, ""); } else { // subsequent items specify the search path through the xml tree // all except the last one -- that is the attribute name for (i=1; i<n-1; ++i) { char *elem; int k; extract_array_specifier(arr[i], &elem, &k); xmlNode *next = findNode(doc, cur, elem, k); if (!next) { // not found -- return NULL found = FALSE; strcpy(buf, ""); FREE(elem); break; } FREE(elem); cur = next; } } if (found) { assert(cur != NULL); xmlChar *val = xmlGetProp(cur, (xmlChar*)(arr[n-1])); if (val) { strncpy_safe(buf, (char*)val, MAX_LEN-1); xmlFree(val); } else { // found the node, but it did not have the requested attribute found = FALSE; } } if (!found) { strcpy(buf, MAGIC_UNSET_STRING); } free_char_array(&arr, n); return buf; }
static void rgps_grid2cell(char *line, rgps_grid_t *grid, int nGrids, rgps_cell_t *cell, int nCells, dbf_header_t *dbf, FILE *fpOut) { char **col; int ii, nCols, nCoords=0, cell_id=0, obs_year; double obs_time, x_disp, y_disp; // Extract information from line split_into_array(line, ',', &nCols, &col); for (ii=0; ii<nCols; ii++) { if (dbf[ii].format == CSV_STRING) dbf[ii].sValue = STRDUP(col[ii]); else if (dbf[ii].format == CSV_DOUBLE) dbf[ii].fValue = atof(col[ii]); else if (dbf[ii].format == CSV_INTEGER) dbf[ii].nValue = atoi(col[ii]); if (strcmp_case(dbf[ii].shape, "CELL_ID") == 0) cell_id = dbf[ii].nValue; else if (strcmp_case(dbf[ii].shape, "OBS_YEAR") == 0) obs_year = dbf[ii].nValue; else if (strcmp_case(dbf[ii].shape, "OBS_TIME") == 0) { obs_time = dbf[ii].fValue; if (obs_year > grid[0].obs_year) obs_time += date_getDaysInYear(grid[0].obs_year); } else if (strcmp_case(dbf[ii].shape, "X_DISP") == 0) x_disp = dbf[ii].fValue; else if (strcmp_case(dbf[ii].shape, "Y_DISP") == 0) y_disp = dbf[ii].fValue; } free_char_array(&col, nCols); // Extract information from connectivity table int *grid_id = (int *) MALLOC(sizeof(int)*50); double *grid_order = (double *) MALLOC(sizeof(double)*50); size_t *p = (size_t *) MALLOC(sizeof(size_t)*50); for (ii=0; ii<nCells; ii++) { if (cell_id == cell[ii].cell_id) { grid_id[nCoords] = cell[ii].grid_id; grid_order[nCoords] = cell[ii].cell_id + (double) cell[ii].order / 100; nCoords++; } } gsl_sort_index(p, grid_order, 1, nCoords); double disp_mag = sqrt(x_disp*x_disp + y_disp*y_disp); // Extract grid information from motion product int kk, index; double diff, grid_time, birth_time, death_time; char image_id[30]; char *tmp = (char *) MALLOC(sizeof(char)*25); char *coordStr = (char *) MALLOC(sizeof(char)*50*nCoords); strcpy(coordStr, ""); for (kk=0; kk<nCoords; kk++) { index = -1; for (ii=0; ii<nGrids; ii++) { grid_time = grid[ii].obs_time; if (grid[ii].obs_year > grid[0].obs_year) grid_time += date_getDaysInYear(grid[0].obs_year); diff = fabs(grid_time - obs_time); if ((grid_id[p[kk]] == grid[ii].gpid) && (diff < 0.01)) { birth_time = grid[ii].birth_time; if (grid[ii].birth_year > grid[0].obs_year) birth_time += date_getDaysInYear(grid[0].obs_year); index = ii; } } if (index > 0 && birth_time <= grid_time) { sprintf(tmp, ",%.4f,%.4f", grid[index].x, grid[index].y); strcat(coordStr, tmp); strcpy(image_id, grid[index].image_id); } } // Check cell death time int n, cell_death_year; double cell_death_time; split_into_array(line, ',', &n, &col); for (ii=0; ii<nCells; ii++) { if (cell[ii].cell_id == atoi(col[0])) { cell_death_time = death_time = cell[ii].death_time; cell_death_year = cell[ii].death_year; if (cell[ii].death_year > cell[0].birth_year) death_time += date_getDaysInYear(cell[0].birth_year); if (cell[ii].death_year == -1) death_time = -1; } } if (death_time < 0 || obs_time < (death_time + 0.01)) { fprintf(fpOut, "%.6f,%s,%s,%s", obs_time, col[0], col[1], col[2]); fprintf(fpOut, ",%s,%d,%.6f", col[3], cell_death_year, cell_death_time); for (kk=4; kk<n; kk++) fprintf(fpOut, ",%s", col[kk]); fprintf(fpOut, ",%s,%.6f%s\n", image_id, disp_mag, coordStr); } free_char_array(&col, n); // Clean up FREE(grid_id); FREE(grid_order); FREE(p); FREE(tmp); FREE(coordStr); return; }
int main(int argc, char **argv) { dbf_header_t *header; extern int currArg; // Pre-initialized to 1 int n=0; char motion[512], deformation[512], connectivity[512], definition[512]; char cell[512], shape_type[25], line[1024], **col; // Parse command line if ((argc-currArg)<1) { printf("Insufficient arguments.\n"); usage(); } strcpy(motion, argv[currArg]); strcpy(deformation, argv[currArg+1]); strcpy(connectivity, argv[currArg+2]); strcpy(definition, argv[currArg+3]); strcpy(cell, argv[currArg+4]); asfSplashScreen(argc, argv); // Reading cell connectivity file asfPrintStatus("Reading cell connectivity file ...\n"); FILE *fp = FOPEN(connectivity, "r"); int ii, kk, nCells = 0; fgets(line, 1024, fp); while (fgets(line, 1024, fp)) nCells++; FCLOSE(fp); rgps_cell_t *cells = (rgps_cell_t *) MALLOC(sizeof(rgps_cell_t)*nCells); fp = FOPEN(connectivity, "r"); fgets(line, 1024, fp); for (ii=0; ii<nCells; ii++) { fgets(line, 1024, fp); chomp(line); split_into_array(line, ',', &n, &col); cells[ii].cell_id = atoi(col[0]); cells[ii].grid_id = atoi(col[1]); cells[ii].order = atoi(col[2]); free_char_array(&col, n); } FCLOSE(fp); // Reading cell definition file asfPrintStatus("Reading cell definition file ...\n"); fp = FOPEN(definition, "r"); fgets(line, 1024, fp); while (fgets(line, 1024, fp)) { chomp(line); split_into_array(line, ',', &n, &col); for (ii=0; ii<nCells; ii++) if (cells[ii].cell_id == atoi(col[0])) { cells[ii].birth_year = atoi(col[3]); cells[ii].birth_time = atof(col[4]); cells[ii].death_year = atoi(col[5]); cells[ii].death_time = atof(col[6]); } free_char_array(&col, n); } FCLOSE(fp); // Reading ice motion file asfPrintStatus("Reading ice motion file ...\n"); read_header_config("RGPS_LP_GRID", &header, &n, shape_type); fp = FOPEN(motion, "r"); int nGrids = 0; fgets(line, 1024, fp); chomp(line); while (fgets(line, 1024, fp)) nGrids++; FCLOSE(fp); rgps_grid_t *grid = (rgps_grid_t *) MALLOC(sizeof(rgps_grid_t)*nGrids); fp = FOPEN(motion, "r"); fgets(line, 1024, fp); for (ii=0; ii<nGrids; ii++) { fgets(line, 1024, fp); chomp(line); split_into_array(line, ',', &n, &col); for (kk=0; kk<n; kk++) { if (strcmp_case(header[kk].shape, "IMAGE_ID") == 0) strcpy(grid[ii].image_id, col[kk]); else if (strcmp_case(header[kk].shape, "GPID") == 0) grid[ii].gpid = atoi(col[kk]); else if (strcmp_case(header[kk].shape, "OBS_YEAR") == 0) grid[ii].obs_year = atoi(col[kk]); else if (strcmp_case(header[kk].shape, "OBS_TIME") == 0) grid[ii].obs_time = atof(col[kk]); else if (strcmp_case(header[kk].shape, "BIRTH_YEAR") == 0) grid[ii].birth_year = atoi(col[kk]); else if (strcmp_case(header[kk].shape, "BIRTH_TIME") == 0) grid[ii].birth_time = atof(col[kk]); else if (strcmp_case(header[kk].shape, "DEATH_YEAR") == 0) grid[ii].death_year = atoi(col[kk]); else if (strcmp_case(header[kk].shape, "DEATH_TIME") == 0) grid[ii].death_time = atof(col[kk]); else if (strcmp_case(header[kk].shape, "X_MAP") == 0) grid[ii].x = atof(col[kk]); else if (strcmp_case(header[kk].shape, "Y_MAP") == 0) grid[ii].y = atof(col[kk]); } free_char_array(&col, n); } FCLOSE(fp); // Reading ice deformation file asfPrintStatus("Converting ice deformation file ...\n"); read_header_config("RGPS_DP_GRID", &header, &n, shape_type); fp = FOPEN(deformation, "r"); FILE *fpOut = FOPEN(cell, "w"); fprintf(fpOut, "CELL_TIME,CELL_ID,STREAM,BIRTH_YEAR,BIRTH_TIME,DEATH_YEAR," "DEATH_TIME,N_OBS,OBS_YEAR,OBS_TIME,X_MAP,Y_MAP,LAT,LON,X_DISP,Y_DISP," "C_AREA,D_AREA,DTP,DUDX,DUDY,DVDX,DVDY,IMAGE_ID,DISP_MAG\n"); fgets(line, 1024, fp); // header line while (fgets(line, 1024, fp)) { chomp(line); rgps_grid2cell(line, grid, nGrids, cells, nCells, header, fpOut); } FCLOSE(fp); FCLOSE(fpOut); FREE(grid); FREE(cells); return(0); }
int cycle() { xmachine_memory_keratinocyte * xmemory = current_xmachine->xmachine_keratinocyte; char_array id_temp; char buffer[10]; /* find number of contacts/bonds*/ int contacts = get_num_xy_bonds() + get_num_z_bonds(); /* touching a wall counts as two contacts*/ if (get_x() == 0 || get_x() == substrate_width) { contacts += 2; } if (get_y() == 0 || get_y() == substrate_width) { contacts += 2; } if (contacts <= get_max_num_bonds(calcium_level)) { /* cell comes out of G0*/ set_cycle(get_cycle()+1); set_contact_inhibited_ticks(0); } else { /* cell enters G0*/ set_contact_inhibited_ticks(get_contact_inhibited_ticks()+1); } /* check to see if enough time has elapsed as to whether cell can divide*/ if (divide(get_type(), get_cycle())) { int new_cycle = start_new_cycle_postion(); double new_x = get_new_coord(get_x(), FALSE); double new_y = get_new_coord(get_y(), FALSE); double new_z = get_z(); double new_diff_noise_factor = 0.9 + (rnd()*0.2); double new_dir = rnd() * 2 * PI; double new_motility = (0.5 + (rnd() * 0.5)) * get_new_motility(get_type(), calcium_level); last_agent_id ++; /* generate a new ID*/ if (can_stratify(get_type(), calcium_level) && get_num_xy_bonds() >= MAX_NUM_LATERAL_BONDS) { new_z = get_new_coord(get_z(), TRUE); } xmemory->cycle = start_new_cycle_postion(); init_char_array(&id_temp); copy_char_array(&ID_CHAR, &id_temp); add_char(&id_temp, '.'); sprintf(buffer, "%d", SPLITS); add_char(&id_temp, buffer[0]); printf("new cell: %s\n", id_temp.array); add_keratinocyte_agent( /*get_id()+1,*/ ID, &id_temp, /*last_agent_id, id*/ 0, /* splits*/ get_type(), /* type*/ new_x, /* x*/ new_y, /* y*/ new_z, /* z*/ 0, /* force_x*/ 0, /* force_y*/ 0, /* force_z*/ 0, /* num_xy_bonds*/ 0, /* num_z_bonds*/ 0, /* num_stem_bonds*/ new_cycle, /* cycle*/ new_diff_noise_factor, /* diff_noise_factor*/ 0, /* dead_ticks*/ 0, /* contact_inhibited_ticks*/ new_motility, /* motility*/ new_dir, /* dir*/ get_range() /* range */ ); xmemory->splits++; free_char_array(&id_temp); } return 0; }