1 |
#ifdef __sun__ |
2 |
|
3 |
#include <stdio.h> |
4 |
#include <string.h> |
5 |
#include <sys/types.h> |
6 |
#include <sys/stat.h> |
7 |
#include <sys/dir.h> |
8 |
#include <sys/param.h> |
9 |
#include <sys/stat.h> |
10 |
|
11 |
struct direct **namelist; |
12 |
char* mydir; |
13 |
|
14 |
|
15 |
int alphasort(struct direct **d1, struct direct **d2); |
16 |
|
17 |
int amber_rst(const struct direct * dir); |
18 |
|
19 |
int nfiles(dirname) |
20 |
char* dirname[MAXPATHLEN + 1]; |
21 |
{ |
22 |
int nfiles; |
23 |
mydir = (char*)dirname; |
24 |
nfiles = scandir((char*)dirname, &namelist, pot_only, alphasort); |
25 |
return(nfiles); |
26 |
} |
27 |
|
28 |
void getfilename(int* which, char* fname, int flen) { |
29 |
char* filename; |
30 |
int i; |
31 |
|
32 |
filename = namelist[*which - 1]->d_name; |
33 |
|
34 |
for (i = 0; i < strlen(filename); i++) { |
35 |
fname[i] = filename[i]; |
36 |
} |
37 |
for (i = strlen(filename); i < flen; i++) { |
38 |
fname[i] = 0; |
39 |
} |
40 |
flen = strlen(filename); |
41 |
} |
42 |
|
43 |
int |
44 |
amber_rst(const struct direct * dir) |
45 |
{ |
46 |
|
47 |
struct stat buf; |
48 |
char filename[MAXPATHLEN + 1]; |
49 |
char *base, *exten; |
50 |
char *dot = "."; |
51 |
|
52 |
sprintf(filename, "%s/%s", mydir, dir->d_name); |
53 |
|
54 |
if (stat(filename, &buf) != 0) |
55 |
{ |
56 |
return (0); |
57 |
} |
58 |
|
59 |
if (buf.st_mode & S_IFDIR) |
60 |
{ |
61 |
return (0); |
62 |
} |
63 |
|
64 |
sprintf(filename, "%s", dir->d_name); |
65 |
base = (char*)strtok(filename, "."); |
66 |
exten=strtok(NULL,"\0"); |
67 |
|
68 |
if (strcasecmp(exten, "pot")) |
69 |
{ |
70 |
return (0); |
71 |
} |
72 |
return (1); |
73 |
|
74 |
} |
75 |
|
76 |
#endif /* __sun__ */ |
77 |
|
78 |
#ifdef __linux__ |
79 |
|
80 |
#include <stdio.h> |
81 |
#include <string.h> |
82 |
#include <dirent.h> |
83 |
#include <sys/param.h> |
84 |
#include <sys/stat.h> |
85 |
|
86 |
struct dirent **namelist; |
87 |
char* mydir; |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
int pot_only(const struct dirent * dir); |
93 |
|
94 |
int nfiles(dirname) |
95 |
char* dirname[MAXPATHLEN + 1]; |
96 |
{ |
97 |
int nfiles; |
98 |
mydir = (char*)dirname; |
99 |
nfiles = scandir((char*)dirname, &namelist, pot_only, alphasort); |
100 |
return(nfiles); |
101 |
} |
102 |
|
103 |
void getfilename_(int* which, char* fname, int flen) { |
104 |
char* filename; |
105 |
int i; |
106 |
|
107 |
filename = namelist[*which - 1]->d_name; |
108 |
|
109 |
for (i = 0; i < strlen(filename); i++) { |
110 |
fname[i] = filename[i]; |
111 |
} |
112 |
for (i = strlen(filename); i < flen; i++) { |
113 |
fname[i] = 0; |
114 |
} |
115 |
flen = strlen(filename); |
116 |
} |
117 |
|
118 |
int |
119 |
amber_rst(const struct dirent * dir) |
120 |
{ |
121 |
|
122 |
struct stat buf; |
123 |
char filename[MAXPATHLEN + 1]; |
124 |
char *base, *exten; |
125 |
char *dot = "."; |
126 |
|
127 |
sprintf(filename, "%s/%s", mydir, dir->d_name); |
128 |
|
129 |
if (stat(filename, &buf) != 0) |
130 |
{ |
131 |
return (0); |
132 |
} |
133 |
|
134 |
if (buf.st_mode & S_IFDIR) |
135 |
{ |
136 |
return (0); |
137 |
} |
138 |
|
139 |
sprintf(filename, "%s", dir->d_name); |
140 |
base = (char*)strtok(filename, "."); |
141 |
exten=strtok(NULL,"\0"); |
142 |
|
143 |
if (strcasecmp(exten, "pot")) |
144 |
{ |
145 |
return (0); |
146 |
} |
147 |
return (1); |
148 |
|
149 |
} |
150 |
|
151 |
#endif /*__Linux__*/ |