/* Save the current encoding configuration */ void save_config_encode() { char filename[100], directory[100]; struct encodingoptions *point; FILE *fp; sprintf(filename,"%s/%s/%s",getenv("HOME"),".studio/", encodeconfigfile); sprintf(directory,"%s/%s",getenv("HOME"),".studio/"); if (chk_dir(directory) == 0) { fprintf(stderr,"cant open config file %s\n",filename); return; } unlink(filename); /* write new one... */ fp = fopen(filename,"w"); if (NULL == fp) { fprintf(stderr,"cant open config file %s\n",filename); return; } /* Save common things like: filenames, preview, ... */ save_common(fp); /* Save the working options of the encoding parameters */ point = &encoding; save_section(fp,point,"MPEG1"); point = &encoding2; save_section(fp,point,"MPEG2"); point = &encoding_gmpeg; save_section(fp,point,"GENERIC"); point = &encoding_vcd; save_section(fp,point,"VCD"); point = &encoding_svcd; save_section(fp,point,"SVCD"); point = &encoding_dvd; save_section(fp,point,"DVD"); point = &encoding_yuv2lav; save_section(fp,point,"YUV2LAV"); save_machine_data(fp,"Machinenames"); save_script_data(fp,"Scriptdata"); if (verbose) printf("Configuration of the encoding options saved\n"); fclose(fp); }
static void save_options() { char filename[256]; FILE *fd; int i, numchans; int x,y,w,h; sprintf(filename, "%s/%s", getenv("HOME"), ".studio"); chk_dir(filename); sprintf(filename, "%s/%s/%s.tv-conf",getenv("HOME"),".studio", tv_config_file); fd = fopen(filename, "w"); if (!fd) { printf("WARNING: cannot open config file: %s\n", filename); return; } gdk_window_get_size(window->window, &w, &h); gdk_window_get_origin(window->window, &x, &y); fprintf(fd, "[StudioTV]\n"); fprintf(fd, "default_port = %d\n", port); fprintf(fd, "default_width = %d\n", w); fprintf(fd, "default_height = %d\n", h); fprintf(fd, "default_x = %d\n", x); fprintf(fd, "default_y = %d\n", y); fprintf(fd, "default_encoding_id = %d\n", encoding_id); #ifdef OSS fprintf(fd, "default_mixer_dev = %s\n", mixer_dev); fprintf(fd, "default_audio_src = %d\n", audio_src); #endif #ifdef HAVE_LIRC fprintf(fd, "default_lirc_dev = %s\n", lirc_dev); for(i=0;i<RC_NUM_KEYS;i++) fprintf(fd, "remote_control_key_%d = %s\n", i, remote_buttons[i]); #endif if (channels) { numchans = 0; for (i=0;channels[i];i++) { fprintf(fd, "channel_frequency_%d = %d\n", i, channels[i]->frequency); fprintf(fd, "channel_name_%d = %s\n", i, channels[i]->name); numchans = i; } fprintf(fd, "num_chans = %d\n", numchans+1); } fclose(fd); if (verbose) g_print("Configuration saved to %s\n", filename); }
/*========================================== * path search (x0,y0)->(x1,y1) * wpd: path info will be written here * flag: &1 = easy path search only * cell: type of obstruction to check for *------------------------------------------*/ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell) { register int i, j, x, y, dx, dy; struct map_data *md; struct walkpath_data s_wpd; if (wpd == NULL) wpd = &s_wpd; // use dummy output variable if (!map[m].cell) return false; md = &map[m]; #ifdef CELL_NOSTACK //Do not check starting cell as that would get you stuck. if (x0 < 0 || x0 >= md->xs || y0 < 0 || y0 >= md->ys) #else if (x0 < 0 || x0 >= md->xs || y0 < 0 || y0 >= md->ys /*|| md->getcellp(md,x0,y0,cell)*/) #endif return false; // Check destination cell if (x1 < 0 || x1 >= md->xs || y1 < 0 || y1 >= md->ys || md->getcellp(md,x1,y1,cell)) return false; if (flag&1) { // Try finding direct path to target // Direct path goes diagonally first, then in straight line. // calculate (sgn(x1-x0), sgn(y1-y0)) dx = ((dx = x1-x0)) ? ((dx<0) ? -1 : 1) : 0; dy = ((dy = y1-y0)) ? ((dy<0) ? -1 : 1) : 0; x = x0; // Current position = starting cell y = y0; i = 0; while( i < ARRAYLENGTH(wpd->path) ) { wpd->path[i] = walk_choices[-dy + 1][dx + 1]; i++; x += dx; // Advance current position y += dy; if( x == x1 ) dx = 0; // destination x reached, no longer move along x-axis if( y == y1 ) dy = 0; // destination y reached, no longer move along y-axis if( dx == 0 && dy == 0 ) break; // success if( md->getcellp(md,x,y,cell) ) break; // obstacle = failure } if( x == x1 && y == y1 ) { // easy path successful. wpd->path_len = i; wpd->path_pos = 0; return true; } return false; // easy path unsuccessful } else { // !(flag&1) // A* (A-star) pathfinding // We always use A* for finding walkpaths because it is what game client uses. // Easy pathfinding cuts corners of non-walkable cells, but client always walks around it. BHEAP_STRUCT_VAR(node_heap, open_set); // 'Open' set // FIXME: This array is too small to ensure all paths shorter than MAX_WALKPATH // can be found without node collision: calc_index(node1) = calc_index(node2). // Figure out more proper size or another way to keep track of known nodes. struct path_node tp[MAX_WALKPATH * MAX_WALKPATH]; struct path_node *current, *it; int xs = md->xs - 1; int ys = md->ys - 1; int len = 0; memset(tp, 0, sizeof(tp)); // Start node i = calc_index(x0, y0); tp[i].parent = NULL; tp[i].x = x0; tp[i].y = y0; tp[i].g_cost = 0; tp[i].f_cost = heuristic(x0, y0, x1, y1); tp[i].flag = SET_OPEN; heap_push_node(&open_set, &tp[i]); // Put start node to 'open' set for(;;) { int e = 0; // error flag // Saves allowed directions for the current cell. Diagonal directions // are only allowed if both directions around it are allowed. This is // to prevent cutting corner of nearby wall. // For example, you can only go NW from the current cell, if you can // go N *and* you can go W. Otherwise you need to walk around the // (corner of the) non-walkable cell. int allowed_dirs = 0; int g_cost; if (BHEAP_LENGTH(open_set) == 0) { BHEAP_CLEAR(open_set); return false; } current = BHEAP_PEEK(open_set); // Look for the lowest f_cost node in the 'open' set BHEAP_POP(open_set, NODE_MINTOPCMP, swap_ptr); // Remove it from 'open' set x = current->x; y = current->y; g_cost = current->g_cost; current->flag = SET_CLOSED; // Add current node to 'closed' set if (x == x1 && y == y1) { BHEAP_CLEAR(open_set); break; } if (y < ys && !md->getcellp(md, x, y+1, cell)) allowed_dirs |= DIR_NORTH; if (y > 0 && !md->getcellp(md, x, y-1, cell)) allowed_dirs |= DIR_SOUTH; if (x < xs && !md->getcellp(md, x+1, y, cell)) allowed_dirs |= DIR_EAST; if (x > 0 && !md->getcellp(md, x-1, y, cell)) allowed_dirs |= DIR_WEST; #define chk_dir(d) ((allowed_dirs & (d)) == (d)) // Process neighbors of current node // TODO: Processing order affects chosen path if there is more than one path with same cost. // In few cases path found by server will be different than path found by game client. if (chk_dir(DIR_SOUTH)) e += add_path(&open_set, tp, x, y-1, g_cost + MOVE_COST, current, heuristic(x, y-1, x1, y1)); // (x, y-1) 4 if (chk_dir(DIR_SOUTH|DIR_WEST) && !md->getcellp(md, x-1, y-1, cell)) e += add_path(&open_set, tp, x-1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y-1, x1, y1)); // (x-1, y-1) 3 if (chk_dir(DIR_WEST)) e += add_path(&open_set, tp, x-1, y, g_cost + MOVE_COST, current, heuristic(x-1, y, x1, y1)); // (x-1, y) 2 if (chk_dir(DIR_NORTH|DIR_WEST) && !md->getcellp(md, x-1, y+1, cell)) e += add_path(&open_set, tp, x-1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y+1, x1, y1)); // (x-1, y+1) 1 if (chk_dir(DIR_NORTH)) e += add_path(&open_set, tp, x, y+1, g_cost + MOVE_COST, current, heuristic(x, y+1, x1, y1)); // (x, y+1) 0 if (chk_dir(DIR_NORTH|DIR_EAST) && !md->getcellp(md, x+1, y+1, cell)) e += add_path(&open_set, tp, x+1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y+1, x1, y1)); // (x+1, y+1) 7 if (chk_dir(DIR_EAST)) e += add_path(&open_set, tp, x+1, y, g_cost + MOVE_COST, current, heuristic(x+1, y, x1, y1)); // (x+1, y) 6 if (chk_dir(DIR_SOUTH|DIR_EAST) && !md->getcellp(md, x+1, y-1, cell)) e += add_path(&open_set, tp, x+1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y-1, x1, y1)); // (x+1, y-1) 5 #undef chk_dir if (e) { BHEAP_CLEAR(open_set); return false; } } for (it = current; it->parent != NULL; it = it->parent, len++); if (len > sizeof(wpd->path)) { return false; } // Recreate path wpd->path_len = len; wpd->path_pos = 0; for (it = current, j = len-1; j >= 0; it = it->parent, j--) { dx = it->x - it->parent->x; dy = it->y - it->parent->y; wpd->path[j] = walk_choices[-dy + 1][dx + 1]; } return true; } // A* end return false; }
void test24a() { /* Test normal operations. */ int fd3, fd4, fd5; DIR *dirp; int j, ret, fd, flags; struct stat st1, st2; int stat_loc; time_t time1; subtest = 1; System("rm -rf ../DIR_24/*"); if ((fd = dup(0)) != 3) e(1); /* dup stdin */ close(fd); /* free the fd again */ errno= 0; dirp = opendir("/"); /* open "/" */ if (dirp == ((DIR *) NULL)) e(2); /* has to succseed */ if (errno != 0) e(3); /* success implies errno didn't change */ if ((fd = dup(0)) <= 2) e(4); /* dup stdin */ if (fd > 3) { /* if opendir() uses fd 3 */ flags = fcntl(3, F_GETFD); /* get fd fags of 3 */ if (!(flags & FD_CLOEXEC)) e(5); /* it should be closed on */ } /* exec..() calls */ close(fd); /* free the fd again */ ret = closedir(dirp); /* close, we don't need it */ if (ret == -1) e(6); /* closedir () unsucces full */ if (ret != 0) e(7); /* should be 0 or -1 */ if ((fd = dup(0)) != 3) e(8); /* see if next fd is same */ close(fd); /* free the fd again */ System("rm -rf foo; mkdir foo"); Chdir("foo"); System("touch f1 f2 f3 f4 f5"); /* make f1 .. f5 */ System("rm f[24]"); /* creat `holes' in entrys */ Chdir(".."); if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(9); /* open foo */ chk_dir(dirp); /* test if foo's ok */ for (j = 0; j < 10; j++) { errno = j * 47 % 7; /* there should */ if (readdir(dirp) != DIRENT0) e(10); /* be nomore dir */ if (errno != j * 47 % 7) e(11); /* entrys */ } rewinddir(dirp); /* rewind foo */ chk_dir(dirp); /* test foosok */ for (j = 0; j < 10; j++) { errno = j * 23 % 7; /* there should */ if (readdir(dirp) != DIRENT0) e(12); /* be nomore dir */ if (errno != j * 23 % 7) e(13); /* entrys */ } if ((fd4 = creat("foo/f4", 0666)) <= 2) e(14); /* Open a file. */ System("rm foo/f4"); /* Kill entry. */ rewinddir(dirp); /* Rewind foo. */ if ((fd3 = open("foo/f3", O_WRONLY)) <= 2) e(15); /* Open more files. */ if ((fd5 = open("foo/f5", O_WRONLY)) <= 2) e(16); if (write(fd3, "Hello", 6) != 6) e(17); if (write(fd4, "Hello", 6) != 6) e(18); /* write some data */ if (close(fd5) != 0) e(19); chk_dir(dirp); for (j = 0; j < 10; j++) { errno = j * 101 % 7; /* there should */ if (readdir(dirp) != DIRENT0) e(20); /* be nomore dir */ if (errno != j * 101 % 7) e(21); /* entrys */ } if (close(fd4) != 0) e(22); /* shouldn't matter */ if (close(fd3) != 0) e(23); /* when we do this */ if (closedir(dirp) != 0) e(24); /* close foo again */ Chdir("foo"); if ((dirp = opendir(".//")) == ((DIR *) NULL)) e(25); /* open foo again */ Chdir(".."); chk_dir(dirp); /* foosok? */ for (j = 0; j < 10; j++) { errno = (j * 101) % 7; /* there should */ if (readdir(dirp) != DIRENT0) e(26); /* be nomore dir */ if (errno != (j * 101) % 7) e(27); /* entrys */ } if (closedir(dirp) != 0) e(28); /* It should be closable */ stat("foo", &st1); /* get stat */ time(&time1); while (time1 >= time((time_t *)0)) ; if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(29); /* open, */ if (readdir(dirp) == DIRENT0) e(30); /* read and */ stat("foo", &st2); /* get new stat */ if (st1.st_atime > st2.st_atime) e(31); /* st_atime check */ switch (fork()) { case -1: printf("Can't fork\n"); break; case 0: rewinddir(dirp); /* rewind childs dirp */ if (readdir(dirp) == DIRENT0) e(32); /* read should be ok */ if (closedir(dirp) != 0) e(33); /* close child'd foo */ exit(0); /* 0 stops here */ default: if (wait(&stat_loc) == -1) e(34); /* PARENT wait()'s */ break; } if (closedir(dirp) != 0) e(35); /* close parent's foo */ }
void command_line_options( int argc, char *argv[] ) { int n, changed, tmp_port; //, sizechanged,w,h; char *optstr = NULL; //, *sizetmp; char config_dir[256]; verbose = FALSE; //sizechanged = 0; changed = 0; tmp_port = 0; while( (n=getopt(argc,argv,"p:c:s:hvdt")) != EOF) { switch(n) { case 'h': usage(); break; case 'v': version(); break; case 'p': tmp_port = atoi(optarg); break; case 'c': if (strlen(optarg) != 0) { optstr = strdup(optarg); changed = 1; } break; /* case 's': if (strlen(optarg) != 0) { sizetmp = strdup(optarg); if (2 != sscanf(sizetmp,"%dx%d",&w,&h)) g_print("Wrong values for width/height\n"); else sizechanged = 1; } break;*/ case 't': tmp_port = -1; break; case 'd': verbose = TRUE; break; } } if (changed == 1) { sprintf(studioconfigfile, "%s.conf", optstr); sprintf(editlist_filename, "%s_editlist.eli",optstr); } else { sprintf(studioconfigfile, "studio.conf"); sprintf(editlist_filename, "studio_editlist.eli"); } sprintf(config_dir, "%s/.studio", getenv("HOME")); chk_dir(config_dir); if (verbose && changed) g_print("Configuration Filename: %s\n", studioconfigfile); /* Load basic configuration */ load_config(); if (tmp_port != 0) { port = tmp_port; save_config(); } /* if (sizechanged != 0) { tv_width = w; tv_height = h; save_config(); } else if (tv_width == 0 && tv_height == 0) { tv_width = 192; tv_height = 144; }*/ }
static void load_options(int *width, int *height, int *x, int *y) { char *val; int i, num=0, tot; char filename[256]; char value_get[256]; sprintf(filename, "%s/%s", getenv("HOME"), ".studio"); chk_dir(filename); sprintf(filename, "%s/%s/%s.tv-conf",getenv("HOME"),".studio", tv_config_file); cfg_parse_file(filename); port = cfg_get_int("StudioTV", "default_port"); if (width) *width = cfg_get_int("StudioTV", "default_width"); if (height) *height = cfg_get_int("StudioTV", "default_height"); if (x) *x = cfg_get_int("StudioTV", "default_x"); if (y) *y = cfg_get_int("StudioTV", "default_y"); if ((encoding_id = cfg_get_int("StudioTV", "default_encoding_id"))==-1) encoding_id = 0; #ifdef OSS if (!mixer_dev) mixer_dev = cfg_get_str("StudioTV", "default_mixer_dev"); if (!mixer_dev) mixer_dev = "/dev/mixer"; audio_src = cfg_get_int("StudioTV", "default_audio_src"); #endif #ifdef HAVE_LIRC if (!lirc_dev) lirc_dev = cfg_get_str("StudioTV", "default_lirc_dev"); if (!lirc_dev) lirc_dev = "/dev/lircd"; for(num=0;num<RC_NUM_KEYS;num++) { sprintf(value_get, "remote_control_key_%d", num); remote_buttons[num] = cfg_get_str("StudioTV",value_get); if (!remote_buttons[num]) remote_buttons[num] = "none"; } #endif if ((tot = cfg_get_int("StudioTV", "num_chans")) < 1) return; if (channels) { for (i=0;channels[i];i++) free(channels[i]); free(channels); } channels = (Channel**)malloc(sizeof(Channel*)*(tot+1)); for(num=0;num<tot;num++) { sprintf(value_get, "channel_frequency_%d", num); i = cfg_get_int("StudioTV",value_get); sprintf(value_get, "channel_name_%d", num); val = cfg_get_str("StudioTV",value_get); channels[num] = (Channel*)malloc(sizeof(Channel)); channels[num]->frequency = i; sprintf(channels[num]->name, val); } channels[tot] = NULL; if (verbose) g_print("Configuration loaded from %s\n", filename); }