diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2014-04-14 16:28:51 +0200 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2014-04-14 16:28:51 +0200 | 
| commit | ece02b618b414244ef8247bd727e30e664249f77 (patch) | |
| tree | 1df8fda0e149afad66f131cddbbe5077589b123b /src | |
| parent | ad285742e9f2111e4ae3d05deb41bfebbce58025 (diff) | |
Use new path_is_url helper instead of repeated strncmp chains
Diffstat (limited to 'src')
| -rw-r--r-- | src/filelist.c | 6 | ||||
| -rw-r--r-- | src/imlib.c | 6 | ||||
| -rw-r--r-- | src/thumbnail.c | 4 | ||||
| -rw-r--r-- | src/utils.c | 9 | ||||
| -rw-r--r-- | src/utils.h | 1 | 
5 files changed, 13 insertions, 13 deletions
| diff --git a/src/filelist.c b/src/filelist.c index e06c6de..28bab93 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -211,11 +211,7 @@ void add_file_to_filelist_recursively(char *origpath, unsigned char level)  		if (path[len - 1] == '/')  			path[len - 1] = '\0'; -		if ((!strncmp(path, "http://", 7)) -				|| (!strncmp(path, "https://", 8)) -				|| (!strncmp(path, "ftp://", 6)) -				|| (!strncmp(path, "file://", 7))) { -			/* Its a url */ +		if (path_is_url(path)) {  			D(("Adding url %s to filelist\n", path));  			filelist = gib_list_add_front(filelist, feh_file_new(path));  			/* We'll download it later... */ diff --git a/src/imlib.c b/src/imlib.c index 36de346..60cb267 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -242,11 +242,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file)  	if (!file || !file->filename)  		return 0; -	/* Handle URLs */ -	if ((!strncmp(file->filename, "http://", 7)) -			|| (!strncmp(file->filename, "https://", 8)) -			|| (!strncmp(file->filename, "ftp://", 6)) -			|| (!strncmp(file->filename, "file://", 7))) { +	if (path_is_url(file->filename)) {  		image_source = SRC_HTTP;  		if ((tmpname = feh_http_load_image(file->filename)) == NULL) diff --git a/src/thumbnail.c b/src/thumbnail.c index f2c8476..ed2a16b 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -602,9 +602,7 @@ char *feh_thumbnail_get_name_uri(char *name)  	char *cwd, *uri = NULL;  	/* FIXME: what happens with http, https, and ftp? MTime etc */ -	if ((strncmp(name, "http://", 7) != 0) && -	    (strncmp(name, "https://", 8) != 0) && (strncmp(name, "ftp://", 6) != 0) -	    && (strncmp(name, "file://", 7) != 0)) { +	if (!path_is_url(name)) {  		/* make sure it's an absoulte path */  		/* FIXME: add support for ~, need to investigate if it's expanded diff --git a/src/utils.c b/src/utils.c index 037010e..bd189d3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -143,6 +143,15 @@ char *estrjoin(const char *separator, ...)  	return string;  } +char path_is_url(char *path) { +	if ((!strncmp(path, "http://", 7)) +			|| (!strncmp(path, "https://", 8)) +			|| (!strncmp(path, "ftp://", 6)) +			|| (!strncmp(path, "file://", 7))) +		return 1; +	return 0; +} +  /* free the result please */  char *feh_unique_filename(char *path, char *basename)  { diff --git a/src/utils.h b/src/utils.h index a619a4c..cd00a33 100644 --- a/src/utils.h +++ b/src/utils.h @@ -36,6 +36,7 @@ char *_estrdup(char *s);  void *_emalloc(size_t n);  void *_erealloc(void *ptr, size_t n);  char *estrjoin(const char *separator, ...); +char path_is_url(char *path);  char *feh_unique_filename(char *path, char *basename);  char *ereadfile(char *path); | 
