/* Convert uri to path and call run_by_path() */ gboolean run_by_uri(const gchar *uri, gchar **errmsg) { gboolean retval; gchar *tmp, *tmp2; gchar *scheme; gchar *cmd; scheme=get_uri_scheme((EscapedPath *) uri); if(!scheme) { *errmsg=g_strdup_printf(_("'%s' is not a valid URI"), uri); return FALSE; } if(strcmp(scheme, "file")==0) { tmp=get_local_path((EscapedPath *) uri); if(tmp) { tmp2=pathdup(tmp); retval=run_by_path(tmp2); if(!retval) *errmsg=g_strdup_printf(_("%s not accessable"), tmp); g_free(tmp2); g_free(tmp); } else { retval=FALSE; *errmsg=g_strdup_printf(_("Non-local URL %s"), uri); } } else if((cmd=choices_find_xdg_path_load(scheme, "URI", SITE))) { DirItem *item; item=diritem_new(scheme); diritem_restat(cmd, item, NULL); run_with_args(cmd, item, uri); retval=TRUE; /* we hope... */ diritem_free(item); g_free(cmd); } else { retval=FALSE; *errmsg=g_strdup_printf(_("%s: no handler for %s"), uri, scheme); } g_free(scheme); return retval; }
static void drop_box_drag_data_received(GtkWidget *drop_box, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint drag_info, guint32 time) { GList *uris = NULL; guchar *path = NULL; gboolean success = FALSE; if (!selection_data->data) goto err; /* Timeout? */ uris = uri_list_to_glist(selection_data->data); if (g_list_length(uris) != 1) { delayed_error(_("Sorry, you need to drop exactly one file " "onto the drop area.")); goto err; } path = get_local_path((EscapedPath *) uris->data); if (!path) { delayed_error( _("Sorry, I can't use '%s' because it's not a local " "file."), (guchar *) uris->data); goto err; } if (!file_exists(path)) { delayed_error(_("Can't access '%s':\n%s"), path, g_strerror(errno)); goto err; } g_signal_emit_by_name(drop_box, "path_dropped", path); success = TRUE; err: if (path) g_free(path); if (uris) g_list_free(uris); gtk_drag_finish(context, success, FALSE, time); /* Failure */ }
/* Execute this program, passing all the URIs in the list as arguments. * URIs that are files on the local machine will be passed as simple * pathnames. The uri_list should be freed after this function returns. */ void run_with_files(const char *path, GList *uri_list) { const char **argv; int argc = 0, i; struct stat info; MIME_type *type; if (stat(path, &info)) { delayed_error(_("Program %s not found - deleted?"), path); return; } argv = g_malloc(sizeof(char *) * (g_list_length(uri_list) + 2)); if (S_ISDIR(info.st_mode)) argv[argc++] = make_path(path, "AppRun"); else argv[argc++] = path; while (uri_list) { const EscapedPath *uri = uri_list->data; char *local; local = get_local_path(uri); if (local) argv[argc++] = local; else argv[argc++] = unescape_uri(uri); uri_list = uri_list->next; } argv[argc++] = NULL; type = type_from_path(argv[0]); if (type && type == application_x_desktop) { run_desktop(argv[0], argv + 1, home_dir); } else { rox_spawn(home_dir, argv); } for (i = 1; i < argc; i++) g_free((gchar *) argv[i]); g_free(argv); }
/* * return the path of the file * search first globally, then locally */ char * get_path(const char *dir, const char *file) { FILE *fd; char *filename = NULL; filename = get_full_path(dir, file); DEBUG_MSG(D_DEBUG, "get_path: %s", filename); fd = fopen(filename, FOPEN_READ_BIN); if (fd == NULL) { SAFE_FREE(filename); filename = get_local_path(dir, file); DEBUG_MSG(D_DEBUG, "get_path: dropping to %s", filename); } else { fclose(fd); } return filename; }
FILE * open_data(char *dir, char *file, char *mode) { FILE *fd; char *filename = NULL; filename = get_full_path(dir, file); DEBUG_MSG("open_data (%s)", filename); fd = fopen(filename, mode); if (fd == NULL) { SAFE_FREE(filename); filename = get_local_path(file); DEBUG_MSG("open_data dropping to %s", filename); fd = fopen(filename, mode); /* don't check the fd, it is done by the caller */ } SAFE_FREE(filename); return fd; }
int main(int argc, char *argv[]) { int did_explicit_auth = 0; int follow_mode = 0; time_t stoptime; signed char c; int setAindex, setBindex; // funcindex; FILE *setA = NULL; FILE *setB = NULL; char setApath[CHIRP_PATH_MAX]; char setBpath[CHIRP_PATH_MAX]; char *LIST_FILE_NAME = "set.list"; char setAfilename[CHIRP_PATH_MAX]; char setBfilename[CHIRP_PATH_MAX]; int len = CHIRP_PATH_MAX; struct chirp_matrix *mat = NULL; int mathost, matpath; double *resbuff = NULL; int numels; int cntr; // Variables defined by Li int i; // for multiprocess calculation int numOfMovingElements, numOfStableElements; //int setACount, setBCount; int setAPos, setBPos; long setAStartPos; //long setBStartPos; int x1, y1, x2, y2, topLeftX, topLeftY; // [x1,y1]-start position, [x2,y2]-end position, the sub matrix we compute in a round int x_rel, y_rel; double threshold; double threshold_min = 0; double threshold_max = 1; double threshold_interval = 0.2; int count_thresholds; int count_genuine = 0; int count_impostar = 0; //int count_fa = 0; //int count_fr = 0; double (*roc_data)[3]; int subject_equal; // ~Variables defined by Li int w, h, e, n; w = 10; h = 10; e = 8; n = 1; x1 = y1 = x2 = y2 = -1; topLeftX = topLeftY = 0; debug_config(argv[0]); while((c = getopt(argc, argv, "a:b:d:ft:vhw:i:e:n:x:y:p:q:r:s:X:Y:c:")) > -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'b': buffer_size = atoi(optarg); break; case 'd': debug_flags_set(optarg); break; case 'f': follow_mode = 1; break; case 't': timeout = string_time_parse(optarg); break; case 'w': w = atoi(optarg); break; case 'i': h = atoi(optarg); break; case 'e': e = atoi(optarg); break; case 'n': n = atoi(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; case 'x': numOfStableElements = atoi(optarg); break; case 'y': numOfMovingElements = atoi(optarg); break; case 'p': x1 = atoi(optarg); break; case 'q': y1 = atoi(optarg); break; case 'r': x2 = atoi(optarg); break; case 's': y2 = atoi(optarg); break; case 'X': topLeftX = atoi(optarg); break; case 'Y': topLeftY = atoi(optarg); break; case 'c': //numOfCores = atoi(optarg); break; } } cctools_version_debug(D_DEBUG, argv[0]); if(!did_explicit_auth) auth_register_all(); if((argc - optind) < 4) { fprintf(stderr, "after all options, you must have: setA setB function mathost matpath\n"); exit(0); } stoptime = time(0) + timeout; setAindex = optind; setBindex = optind + 1; mathost = optind + 2; matpath = optind + 3; // Set threshhold min, max and interval threshold_min = 0; threshold_max = 1; threshold_interval = 0.01; // Initialize result array - roc_data count_thresholds = (threshold_max - threshold_min) / threshold_interval + 1; roc_data = malloc(count_thresholds * 3 * sizeof(double)); if(!roc_data) { fprintf(stderr, "Cannot initialize result buffer!\n"); exit(1); } for(i = 0, threshold = threshold_min; i < count_thresholds; i++, threshold += threshold_interval) { roc_data[i][0] = threshold; } // Load matrix to be verified printf("X1,X2,Y1,Y2: %i,%i,%i,%i\n", x1, x2, y1, y2); mat = chirp_matrix_open(argv[mathost], argv[matpath], stoptime); if(mat == NULL) { fprintf(stderr, "No such matrix. Fail.\n"); exit(1); } printf("Start loading matrix ... \n"); printf("Width, height: %d, %d\n\n", chirp_matrix_width(mat), chirp_matrix_height(mat)); numels = (x2 - x1 + 1) * (y2 - y1 + 1); resbuff = (double *) malloc(numels * sizeof(double)); double *pilot_resbuff; pilot_resbuff = resbuff; // TODO get_range function can get at most 10*10 matrix a time (actually it can get more) /** for(j=0; j<y2-y1+1; j++) { for(i=0; i<x2-x1+1; i++) { int matrtn = chirp_matrix_get_range( mat, x1+i, y1+j, 1, 1, pilot_resbuff, stoptime); //(x2-x1+1), (y2-y1+1), resbuff, stoptime ); printf("%.2f\t", (*pilot_resbuff)); if(matrtn == -1) printf("return mat error @ [%d, %d]!!\n", x1+i, y1+j); pilot_resbuff++; } printf("\n"); }*/ int matrtn = chirp_matrix_get_range(mat, x1, y1, x2 - x1 + 1, y2 - y1 + 1, resbuff, stoptime); //(x2-x1+1), (y2-y1+1), resbuff, stoptime ); if(matrtn == -1) { fprintf(stderr, "return mat error @ [%d, %d], width: %d; height: %d!\n", x1, y1, x2 - x1 + 1, y2 - y1 + 1); exit(1); } printf("*******end of loading matrix********\n\n"); // Get local path for data sets directories if(get_local_path(setApath, argv[setAindex], stoptime) != 0 || get_local_path(setBpath, argv[setBindex], stoptime) != 0) { fprintf(stderr, "Paths to data sets are invalid!\n"); exit(1); } // setA and setB each contains a list of file names that points to the data files char setAlistfile[CHIRP_PATH_MAX]; char setBlistfile[CHIRP_PATH_MAX]; strcpy(setAlistfile, setApath); strcat(setAlistfile, LIST_FILE_NAME); if((setA = fopen(setAlistfile, "r")) == NULL) { fprintf(stderr, "Cannot open data set A list file - %s!\n", setAlistfile); exit(1); } strcpy(setBlistfile, setBpath); strcat(setBlistfile, LIST_FILE_NAME); if((setB = fopen(setBlistfile, "r")) == NULL) { fprintf(stderr, "Cannot open data set B list file - %s!\n", setBlistfile); exit(1); } // Initialize position parameters and allocate memory for storing results of a block (sub matrix) x_rel = y_rel = 0; // relative to the sub-matrix we are actually working on // Go forward until line x1 in Set A list file for(i = 0; i < x1 && !feof(setA); i++) { fgets(setAfilename, len, setA); } if(i < x1) { fprintf(stderr, "Set A has less then x1 elements!\n"); exit(1); } setAStartPos = ftell(setA); // Go forward until line y1 in Set B list file for(i = 0; i < y1 && !feof(setB); i++) { fgets(setBfilename, len, setB); } if(i < y1) { fprintf(stderr, "Set B has less then x1 elements!\n"); exit(1); } //setBStartPos = ftell(setB); debug(D_CHIRP, "Matrix data:\n"); // start loop fgets(setBfilename, len, setB); if(setBfilename != NULL) { size_t last = strlen(setBfilename) - 1; if(setBfilename[last] == '\n') setBfilename[last] = '\0'; } for(setBPos = y1; !feof(setB) && setBPos <= y2; setBPos++) { // Set B - column of matrix // Go directly to line y1 in Set B list file fseek(setA, setAStartPos, SEEK_SET); fgets(setAfilename, len, setA); if(setAfilename != NULL) { size_t last = strlen(setAfilename) - 1; if(setAfilename[last] == '\n') setAfilename[last] = '\0'; } setAPos = x1; for(setAPos = x1; !feof(setA) && setAPos <= x2; setAPos++) { // Set A- row of matrix // Threshhold comparison cntr = ((setBPos - y1) * (x2 - x1 + 1)) + (setAPos - x1); subject_equal = isSubjectIdEqual(setAfilename, setBfilename); if(subject_equal == 1) { // A genuine match for(threshold = threshold_max, i = count_thresholds - 1; 1 - resbuff[cntr] < threshold; threshold -= threshold_interval, i--) { // False reject roc_data[i][1] += 1; } count_genuine++; } else if(subject_equal == 0) { // A impostar match for(threshold = threshold_min, i = 0; 1 - resbuff[cntr] >= threshold; threshold += threshold_interval, i++) { // False accept roc_data[i][2] += 1; } count_impostar++; } else { fprintf(stderr, "Cannot resolve filename in either %s or %s!\n", setAfilename, setBfilename); exit(1); } debug(D_CHIRP, "%.2f\t", resbuff[cntr]); fgets(setAfilename, len, setA); if(setAfilename != NULL) { size_t last = strlen(setAfilename) - 1; if(setAfilename[last] == '\n') setAfilename[last] = '\0'; } } debug(D_CHIRP, "\n"); fgets(setBfilename, len, setB); if(setBfilename != NULL) { size_t last = strlen(setBfilename) - 1; if(setBfilename[last] == '\n') setBfilename[last] = '\0'; } } printf("\n**********************************************************************\n"); // Printf roc_data debug(D_CHIRP, "ROC raw data format: Threshold | False reject count | False accept count\n"); for(i = 0; i < count_thresholds; i++) { debug(D_CHIRP, "%.2f\t%.2f\t%.2f;\t", roc_data[i][0], roc_data[i][1], roc_data[i][2]); } debug(D_CHIRP, "\n"); // Transform roc_data to ROC curve data for(i = 0; i < count_thresholds; i++) { roc_data[i][1] = 1 - (roc_data[i][1] / count_genuine); // 1 - FRR roc_data[i][2] = roc_data[i][2] / count_impostar; // FAR } // Printf roc_data debug(D_CHIRP, "ROC curve data format: Threshold | 1 - False reject rate | False accept rate\n"); for(i = 0; i < count_thresholds; i++) { debug(D_CHIRP, "%.2f\t%.2f\t%.2f;\t", roc_data[i][0], roc_data[i][1], roc_data[i][2]); } debug(D_CHIRP, "\n"); // Write to dat file for gnuplot's use FILE *roc_data_fp; //char roc_line[20]; roc_data_fp = fopen("roc.dat", "w"); for(i = 0; i < count_thresholds; i++) { fprintf(roc_data_fp, "%.2f\t%.2f\n", roc_data[i][1], roc_data[i][2]); // 1 - FRR, FAR } fclose(roc_data_fp); free(resbuff); debug(D_CHIRP, "%d comparisons in the matrix are tested! Genuine matches: %d\t Impostar matches: %d\n\n", cntr + 1, count_genuine, count_impostar); printf("\nROC curve data generation completed successfully!\n%d comparisons in the matrix are tested!\n", cntr + 1); return 0; }