mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2024-11-24 13:53:07 +01:00
"Break" mimetype only once
This commit is contained in:
parent
3cfc0b2611
commit
8f2b3a403b
@ -81,15 +81,9 @@ static void break_mimetype(char *mimetype, char **type, char **subtype)
|
|||||||
*subtype = &s[1];
|
*subtype = &s[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MIMETYPE_MAX 64
|
static Preview *find_preview(const char *type, const char *subtype, const char *ext, size_t *i)
|
||||||
|
|
||||||
static Preview *find_preview(const char *mimetype, const char *ext, size_t *i)
|
|
||||||
{
|
{
|
||||||
Preview *p;
|
Preview *p;
|
||||||
char mimetype_c[MIMETYPE_MAX], *t, *s;
|
|
||||||
|
|
||||||
strncpy(mimetype_c, mimetype, MIMETYPE_MAX - 1);
|
|
||||||
break_mimetype(mimetype_c, &t, &s);
|
|
||||||
|
|
||||||
for (; *i < previews.len; (*i)++) {
|
for (; *i < previews.len; (*i)++) {
|
||||||
p = previews.list[*i];
|
p = previews.list[*i];
|
||||||
@ -97,10 +91,10 @@ static Preview *find_preview(const char *mimetype, const char *ext, size_t *i)
|
|||||||
if (p->ext && strcmpnull(p->ext, ext) != 0)
|
if (p->ext && strcmpnull(p->ext, ext) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (p->type && strcmpnull(p->type, t) != 0)
|
if (p->type && strcmpnull(p->type, type) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (p->subtype && strcmpnull(p->subtype, s) != 0)
|
if (p->subtype && strcmpnull(p->subtype, subtype) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -182,9 +176,13 @@ int preview_run(const char *ext, const char *mimetype, PreviewArgs *pa)
|
|||||||
Preview *p;
|
Preview *p;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int exitcode;
|
int exitcode;
|
||||||
|
char mimetype_c[MIMETYPE_MAX], *t, *s;
|
||||||
|
|
||||||
|
strncpy(mimetype_c, mimetype, LEN(mimetype_c) - 1);
|
||||||
|
break_mimetype(mimetype_c, &t, &s);
|
||||||
|
|
||||||
run:
|
run:
|
||||||
p = find_preview(mimetype, ext, &i);
|
p = find_preview(t, s, ext, &i);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
puts("ctpv: no previews found");
|
puts("ctpv: no previews found");
|
||||||
return ERR;
|
return ERR;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
|
#define MIMETYPE_MAX 64
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name, *ext, *type, *subtype, *script;
|
char *name, *ext, *type, *subtype, *script;
|
||||||
int priority;
|
int priority;
|
||||||
|
Loading…
Reference in New Issue
Block a user