char * url_from_user_input(const char *arg) { /* If it is already a URL, return the argument as is. */ if (has_scheme(arg) || !strcasecmp(arg, "about:blank")) return strdup(arg); Eina_Strbuf *buf = eina_strbuf_manage_new(eina_file_path_sanitize(arg)); /* Check if the path exists. */ if (ecore_file_exists(eina_strbuf_string_get(buf))) { /* File exists, convert local path to a URL. */ eina_strbuf_prepend(buf, "file://"); } else { /* The path does not exist, convert it to a URL by prepending http:// scheme: www.google.com -> http://www.google.com */ eina_strbuf_string_free(buf); eina_strbuf_append_printf(buf, "http://%s", arg); } char *url = eina_strbuf_string_steal(buf); eina_strbuf_free(buf); return url; }
EAPI Efreet_Desktop * efreet_desktop_uncached_new(const char *file) { Efreet_Desktop *desktop = NULL; char *tmp; EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); if (!ecore_file_exists(file)) return NULL; tmp = eina_file_path_sanitize(file); if (!tmp) return NULL; desktop = NEW(Efreet_Desktop, 1); if (!desktop) { free(tmp); return NULL; } desktop->orig_path = tmp; desktop->ref = 1; if (!efreet_desktop_read(desktop)) { efreet_desktop_free(desktop); return NULL; } return desktop; }
EAPI Efreet_Desktop * efreet_desktop_new(const char *file) { Efreet_Desktop *desktop = NULL; char *tmp; EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); tmp = eina_file_path_sanitize(file); if (!tmp) return NULL; desktop = efreet_cache_desktop_find(tmp); free(tmp); if (desktop) { desktop->ref++; if (!efreet_desktop_environment_check(desktop)) { efreet_desktop_free(desktop); return NULL; } return desktop; } return efreet_desktop_uncached_new(file); }
char *clean_dirpath(char *path) { int len; path = eina_file_path_sanitize(path); len = strlen(path); if (path[len-1] != '/') { path = realloc(path, len+2); path[len] = '/'; path[len+1] = '\0'; } return path; }
EAPI const char * efreet_icon_deprecated_user_dir_get(void) { const char *user; char *tmp; int len; if (efreet_icon_deprecated_user_dir) return efreet_icon_deprecated_user_dir; user = efreet_home_dir_get(); len = strlen(user) + strlen("/.icons") + 1; tmp = alloca(len); snprintf(tmp, len, "%s/.icons", user); tmp = eina_file_path_sanitize(tmp); efreet_icon_deprecated_user_dir = eina_stringshare_add_length(tmp, len - 1); free(tmp); return efreet_icon_deprecated_user_dir; }
int parse_cli(int argc, char **argv, Eina_List **filters, Bench_Step **bench, int *size, int *metric, int *strategy, char **path, int *winsize, int *verbose, int *help) { int i; int c; int option_index = 0; char *subopts, *value; char *remain; struct stat statbuf; Eina_List *new_filters = NULL; if (bench) *bench = 0; if (size) *size = 100; *metric = 0; *strategy = 0; *verbose = 0; if (winsize) *winsize = 0; if (help) *help = 0; if (path) *path = NULL; while ((c = getopt_long(argc, argv, "b:s:m:f:w:vh", long_options, &option_index)) != -1) { switch (c) { case 'b' : if (!bench) { printf("ERROR parsing command line: benchmark is not supported!\n"); return -1; } if (!optarg) { //*bench = create_bench_all(); } else { subopts = optarg; while (*subopts != '\0') { switch(getsubopt(&subopts, benchmarks, &value)) { case 0: *bench = bench_global; break; case 1: *bench = bench_pan; break; case 2: *bench = bench_eval; break; case 3: *bench = bench_redo; break; case 4: *bench = bench_s0; break; case 5: *bench = bench_s1; break; case 6: *bench = bench_s2; break; case 7: *bench = bench_s3; break; default: printf("ERROR parsing command line: unknown benchmark \"%s\"\n", value); return -1; } } } break; case 's' : if (!size) break; *size = atoi(optarg); if (*size < 1) { printf("ERROR parsing command line: require cache-size >= 1MB (was %s)\n", optarg); return -1; } break; case 'w' : if (winsize) { *winsize = atoi(optarg); if (*winsize == 0) { printf("ERROR parsing command line: require window-size > 0! (was %s)\n", optarg); return -1; } } else { printf("ERROR winsize not available!\n"); return -1; } case 'h' : if (help) *help = 1; else { printf("ERROR help not available!\n"); return 0; } break; case 'v' : (*verbose)++; break; case 'm' : subopts = optarg; while (*subopts != '\0') { switch(getsubopt(&subopts, strategies, &value)) { case 0: *metric = CACHE_F_RAND; break; case 1: *metric = CACHE_F_RAPX; break; case 2: *metric = CACHE_F_PROB; break; default: printf("ERROR parsing command line: unknown strategy \"%s\"\n", value); return -1; } } break; case 'f' : subopts = optarg; while (*subopts != '\0') { switch(getsubopt(&subopts, metrics, &value)) { case 0: *metric |= CACHE_M_LRU; break; case 1: *metric |= CACHE_M_DIST; break; case 2: *metric |= CACHE_M_TIME; break; case 3: *metric |= CACHE_M_HITN; break; default: printf("ERROR parsing command line: unknown metric \"%s\"\n", value); return 2; } } break; default : printf("Unkown option %c!\n", c); return -1; } } while (optind < argc) { assert(filters); new_filters = lime_filter_chain_deserialize(argv[optind]); if (*filters && new_filters) printf("FIXME append multiple filter chains!\n"); if (new_filters) *filters = new_filters; else { remain = eina_file_path_sanitize(argv[optind]); if (stat(remain, &statbuf)) { printf("ERROR parsing command line: %s is not a filter and %s does not exist\n", argv[optind], remain); return -1; } if (S_ISDIR(statbuf.st_mode)) { if (!path) { printf("ERROR parsing command line: %s: dir as argument not supported!\n", remain); return -1; } *path = clean_dirpath(argv[optind]); } else if (S_ISREG(statbuf.st_mode)) { if (!path) { printf("ERROR parsing command line: %s: file as argument not supported!\n", remain); return -1; } *path = remain; /*if (dir) { *dir = strdup(remain); for(i=strlen(remain)-1;i>0;i--) if ((*dir)[i] != '/') (*dir)[i] = '\0'; else break; }*/ } else printf("ERROR parsing command line: %s could not be parsed and %s is neither a regular file nor a directory\n", argv[optind], remain); } optind++; } return 0; }