#include <>
#include <>
#include <>
#include <>
#include <>
#include <>
#define PACKAGE "forvavo"
/* recursion */
void recdir(char *dir);
int main(int argc, char *argv[]) {
if(argc != 2)
fprintf(stderr, "%s [directory]\n", PACKAGE), exit(EXIT_FAILURE);
else {
printf("\n");
printf(" \n");
printf(" \n");
printf(" \n");
printf("\n");
recdir(argv[1]);
printf("\n");
printf("\n");
}
return 0;
}
void recdir(char *dir) {
DIR *dp;
FILE *fp;
char *ptr;
char line[1024];
struct dirent *entry;
struct stat statbuf;
if((dp = opendir(dir)) == NULL) {
fprintf(stderr, "Cannot open directory: %s\n", dir);
return;
}
chdir(dir);
while((entry = readdir(dp)) != NULL) {
stat(entry->d_name, &statbuf);
if(S_ISDIR(statbuf.st_mode)) {
if(strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0)
continue;
printf("\n
%s
\n", entry->d_name);printf("
- \n"); recdir(entry->d_name); } else { if((fp = fopen(entry->d_name, "r")) == NULL) perror(PACKAGE); else { while((fgets(line, 1024, fp)) != NULL) { if(strncmp(line, "URL=", 4) == 0) { printf("
- for(ptr = line, ptr += 4; *ptr; ptr++)
if(*ptr != '\n' && *ptr != '\r') printf("%c", *ptr);
printf("\">%s\n", entry->d_name);
} /* while */
} /* else */
fclose(fp);
} /* else *
Read more: http://cmagical.blogspot.com/2010_02_14_archive.html#ixzz0xgXu6hTq
Under Creative Commons License: Attribution Non-Commercial No Derivatives
No comments:
Post a Comment