| 1 |
chuckv |
2930 |
|
| 2 |
|
|
#include <stdio.h> |
| 3 |
|
|
#include <string.h> |
| 4 |
|
|
#include <dirent.h> |
| 5 |
|
|
#include <sys/param.h> |
| 6 |
|
|
#include <sys/stat.h> |
| 7 |
chuckv |
2933 |
#include "getfile.h" |
| 8 |
chuckv |
2930 |
|
| 9 |
|
|
struct dirent **namelist; |
| 10 |
|
|
char* mydir; |
| 11 |
chuckv |
2933 |
int mynode; |
| 12 |
|
|
//int nfiles(char* dirname[MAXPATHLEN + 1]); |
| 13 |
chuckv |
2930 |
|
| 14 |
chuckv |
2943 |
int amber_rst(const struct dirent * dir); |
| 15 |
|
|
//int alphasort(struct direct **d1, struct direct **d2); |
| 16 |
chuckv |
2930 |
|
| 17 |
chuckv |
2933 |
int nfiles(char* dirname[MAXPATHLEN + 1],int extension) |
| 18 |
chuckv |
2930 |
{ |
| 19 |
|
|
int nfiles; |
| 20 |
|
|
mydir = (char*)dirname; |
| 21 |
chuckv |
2933 |
mynode = extension; |
| 22 |
chuckv |
2943 |
nfiles = scandir(".", &namelist, amber_rst, alphasort); |
| 23 |
chuckv |
2930 |
return(nfiles); |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
chuckv |
2943 |
char* getfilename(int which) { |
| 27 |
|
|
char* fname; |
| 28 |
chuckv |
2930 |
int i; |
| 29 |
|
|
|
| 30 |
chuckv |
2943 |
fname = namelist[which]->d_name; |
| 31 |
|
|
printf("Getfilename filename is: %s\n",fname); |
| 32 |
|
|
return fname; |
| 33 |
chuckv |
2933 |
/* |
| 34 |
chuckv |
2930 |
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 |
chuckv |
2933 |
*/ |
| 41 |
chuckv |
2930 |
} |
| 42 |
|
|
|
| 43 |
|
|
int |
| 44 |
|
|
amber_rst(const struct dirent * dir) |
| 45 |
|
|
{ |
| 46 |
|
|
|
| 47 |
|
|
struct stat buf; |
| 48 |
|
|
char filename[MAXPATHLEN + 1]; |
| 49 |
chuckv |
2943 |
|
| 50 |
chuckv |
2930 |
char *base, *exten; |
| 51 |
|
|
char *dot = "."; |
| 52 |
chuckv |
2943 |
char extenpattern[5]; |
| 53 |
chuckv |
2933 |
|
| 54 |
chuckv |
2943 |
sprintf(filename, "%s/%s",".", dir->d_name); |
| 55 |
|
|
|
| 56 |
chuckv |
2930 |
|
| 57 |
|
|
if (stat(filename, &buf) != 0) |
| 58 |
|
|
{ |
| 59 |
|
|
return (0); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
if (buf.st_mode & S_IFDIR) |
| 63 |
|
|
{ |
| 64 |
|
|
return (0); |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
|
sprintf(filename, "%s", dir->d_name); |
| 68 |
|
|
base = (char*)strtok(filename, "."); |
| 69 |
|
|
exten=strtok(NULL,"\0"); |
| 70 |
chuckv |
2933 |
sprintf(extenpattern,"%i",mynode); |
| 71 |
chuckv |
2930 |
|
| 72 |
|
|
|
| 73 |
chuckv |
2943 |
if (exten!=NULL && !strcasecmp(exten,extenpattern)) |
| 74 |
|
|
{ |
| 75 |
|
|
printf("found extension %s\n",dir->d_name); |
| 76 |
|
|
return (1); |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
return (0); |
| 80 |
|
|
|
| 81 |
chuckv |
2930 |
} |
| 82 |
|
|
|