/********************************************************************* * filefind(): is a function made for retrieving the bbbs-pathname * * of a file in in a BBBS File/4 directory structure. * * The function uses the filedir.idx file made with the BFILEIDX * * parameter of BBBS. The function will NOT function with wildcards. * * * * The meaning of this function is to implement a Global Download * * function in BBBS, but I'll release this code now anyway. * * * * This source file is hereby released to the Public Domain by the * * author: Stig Johansen. * * I can be reached at these addresses: * * BBBSnet: Stig Johansen@47:1000/101 * * FidoNet: Stig Johansen@2:210/20 * * SigNet: Stig Johansen@27:1347/106 * * SkyNet: Stig Johansen@47:300:110 * * * * Have fun... and: release all of your source codes!!! * ********************************************************************** * 26/4-94 Ported to C by Murad Saeter! * * Returns: * * 0 - file not found * * 1 - file found * * 2 - error opening fileidx * **********************************************************************/ #define TEST #include #include int findfile(char *fname[], char path[]); int findfile(char *fname[], char path[]) { char name[50], str1[50], str2[50], str3[150], dir[150]; int stat, search, c; FILE *idx; strcpy(name, ""); stat=0; search=0; if((idx=fopen(path,"rt"))!=NULL) { while (1) { if (search==10) { search=0; switch (stat) { case 0: printf("|"); stat = 1; break; case 1: printf("/"); stat = 2; break; case 2: printf("-"); stat = 3; break; case 3: printf("\\"); stat = 0; break; } } else search++; fgets(str1, 50, idx); fgets(str2, 50, idx); if(fgets(str3, 150, idx)==NULL) { printf("\b"); return(0); } strcpy(name, str1); name[strlen(name)-1]='\x00'; if (strcmp(str3, "")) sscanf(str3, "%s", &dir); if(!strcmpi(name, *fname)) { printf("\b"); sprintf(*fname, "%s%s", dir, name); fclose(0); return(1); } printf("\b"); } } else return(2); } #if defined TEST int main(int argc, char *argv[]) { char *file[150], path[150]; int result; if(argc<3) { printf("Usage: filefind \n"); return(9); } strcpy(path, argv[1]); strcpy(*file, argv[2]); result=findfile(file, path); switch(result) { case 0: printf("not found\n"); break; case 1: printf("found: %s\n", *file); break; case 2: printf("error opening %s\n", path); break; } return(result); } #endif