-
Notifications
You must be signed in to change notification settings - Fork 0
/
newvalidtype.c
68 lines (54 loc) · 1.18 KB
/
newvalidtype.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
validtype.c
takes a string, and checks the suffix
if changetype=1, returns suffix in **suffix
if changetype=2, also checks second suffix
returns 0 if nothing found,
or if valid type found, returns length of extension (tiff=4, bmp=3, etc...)
*/
#include "ourdefs.h"
int validtype(const char *filename, const char *ssufixx ,char **suffix, int changetype){
int r;
int s;
int i;
char copy[BUFFER];
r=0;
s=strlen(filename);
for(i=0;i<s;i++)
copy[i]=tolower(filename[i]);
copy[i]=0;
if ((s>4)&&(last(filename,"jpg")))
r=3;
if ((s>4)&&(last(filename,"gif")))
r=3;
if ((s>4)&&(last(filename,"png")))
r=3;
if ((s>4)&&(last(filename,"bmp")))
r=3;
if ((s>4)&&(last(filename,"tif")))
r=3;
if ((s>5)&&(last(filename,"anpg")))
r=4;
if ((s>5)&&(last(filename,"avif")))
r=4;
if ((s>5)&&(last(filename,"jpeg")))
r=4;
if ((s>5)&&(last(filename,"webp")))
r=4;
if ((s>5)&&(last(filename,"tiff")))
r=4;
if ((r>0)&&(changetype==1)) // also copy to suffix
{
strcpy(*suffix,filename+s-r);
// for (i=0;i<r;i++)
// *suffix[i]=filename[s-r+i];
// *suffix[i]=0;
}
if ((r>0)&&(changetype==2)) // also check presuffix
{
strcpy(copy,filename);
copy[s-r-1]=0;
r*=(1-last(ssufixx,copy));
}
return(r);
}