ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/runParallel/getfile.c
Revision: 2956
Committed: Wed Jul 19 16:08:12 2006 UTC (17 years, 11 months ago) by chuckv
Content type: text/plain
File size: 1638 byte(s)
Log Message:
Added fork() and wait() so we can loop through multiple jobs.

File Contents

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