-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrifunct.c
126 lines (111 loc) · 2.5 KB
/
rifunct.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
typedef struct
{
short int game;
char rom[13];
unsigned int crc32;
unsigned int crcs[6];
int size;
} ex_romid_t;
int checkfile(char *fn)
{
//struct ffblk f;
//int st = findfirst(fn, &f, FA_ARCH|FA_DIREC|FA_RDONLY);
//int st = findfirst(fn, &f);
//if (st) return -1;
//return f.ff_attrib;
FILE *fp;
fp = fopen(fn, "r");
if (fp == NULL) {
return -1;
} else {
return 1;
}
return access(fn);
};
int is_directory(char *fn)
{
// struct dirent **files;
// int file_select();
// if (scandir(fn, &files, file_select, alphasort) > 0) return 1;
return 0;
};
void upper_case(char *str)
{
int i, l = strlen(str);
for (i=0;i!=l;i++) if ((str[i]>='a')&&(str[i]<='z')) str[i]-=32;
};
void upper_case_2(char *str)
{
int i, l = strlen(str);
for (i=0;i!=l;i++) {
if ((str[i]>='a')&&(str[i]<='z')) str[i]-=32;
if (str[i] == '_') str[i] = ' ';
};
};
/*
int get_file_size(char *fn)
{
struct find_t f;
if (_dos_findfirst(fn, _A_NORMAL|_A_RDONLY, &f)) return -1;
return f.size;
};
*/
int get_file_size(char *filename)
{
struct stat st;
if (stat(filename, &st) == 0)
return st.st_size;
fprintf(stderr, "Cannot determine size of %s: \n",
filename);
return -1;
};
void get_zipfilename(char *s, char *d)
{
int i, ss, ee = strlen(s);
while (s[ee]!='.') ee--;
ss = ee - 1;
while ((s[ss]!='/')&&(s[ss]!='\\')&&(ss)) ss--;
if ((s[ss]=='/')||(s[ss]=='\\')) ss++;
for (i=0;i!=(ee-ss);i++) d[i] = s[ss + i];
d[i] = 0;
};
void get_dirname(char *s, char *d)
{
int i, ss, ee = strlen(s);
while ((s[ee]!='/')&&(s[ee]!='\\')) ee--;
ss = ee - 1;
while ((s[ss]!='/')&&(s[ss]!='\\')&&(ss)) ss--;
if ((s[ss]=='/')||(s[ss]=='\\')) ss++;
for (i=0;i!=(ee-ss);i++) d[i] = s[ss + i];
d[i] = 0;
};
void get_filename(char *s, char *d)
{
int i, ss, ee = strlen(s);
ss = ee - 1;
while ((s[ss]!='/')&&(s[ss]!='\\')&&(ss)) ss--;
if ((s[ss]=='/')||(s[ss]=='\\')) ss++;
for (i=0;i!=(ee-ss);i++) d[i] = s[ss + i];
d[i] = 0;
};
int hex2int(char *crcstr)
{
int s = 0, i, v = 0, m = 1;
char d;
do {
s++;
} while ((crcstr[s]!=0)&&(crcstr[s]!=' '));
s--;
for (i=s;i>=0;i--) {
if (crcstr[i]>='a') crcstr[i]-=32;
d = crcstr[i];
if ((d>='0') && (d<='9')) v+=m*(int)(d-'0');
if ((d>='A') && (d<='F')) v+=m*(10+(int)(d-'A'));
m = m * 16;
};
return v;
};