Created
March 15, 2011 16:56
-
-
Save pr4v33n/871027 to your computer and use it in GitHub Desktop.
read integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct_jobInfo *parseJobs(struct_jobInfo *numbers) { | |
char pattern[] = "/.dm/*.*.dm"; | |
glob_t globbuf; | |
FILE *file; | |
unsigned int i=0, n=0; | |
long long unsigned size; | |
char buffer[256]; | |
size = (sizeof(struct struct_jobInfo) * MAXJOBS); | |
numbers = calloc(size, 1); | |
glob(pattern, 0, NULL, &globbuf); | |
for (i = 0; i < globbuf.gl_pathc; i++) { | |
if ((file = fopen(globbuf.gl_pathv[i], "r")) != NULL) { | |
while (fscanf(file, "%s\n", buffer) == 1) { | |
numbers[n].commandNumberRows = 1; | |
char *p = buffer; | |
errno = 0; | |
numbers[n].commandNumberRows = strtoull(buffer, &p, 10); | |
if((errno != 0) || (p == buf) || (*p != 0)) { | |
continue; | |
} | |
n++; | |
if (n >= MAXJOBS) { | |
size = (size * 2) ; | |
numbers = realloc(numbers, size); | |
} | |
} | |
fclose(file); | |
//remove file so it is not able to be parsed again | |
//remove(globbuf.gl_pathv[i]); | |
} | |
} | |
/*Debug: print out collected jobs*/ | |
printf("Collected Job Id's:\n"); | |
for (i = 0; i < n; i++) { | |
printf("%llu\n", numbers[i].commandNumberRows); | |
} | |
/*free mallocs*/ | |
globfree(&globbuf); | |
if( n < MAXJOBS) { | |
numbers[n+1].commandNumberRows=0; | |
} | |
else{ | |
size += (sizeof(struct struct_jobInfo) * MAXJOBS); | |
numbers = realloc(numbers, size); | |
numbers[n+1].commandNumberRows=0; | |
} | |
return numbers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment