/* * This part was written by Harald Kipp * * Bug reports to * * harald@os2point.ping.de * harald@sesam.com * Fido: 2:2448/434 * */ #define OS2 #define INCL_DOSFILEMGR #include #include #include /************************************************************************/ /* */ /************************************************************************/ static int longcmp(long *x, long *y) { if(*x > *y) return(1); else if(*x < *y) return(-1); return(0); } /************************************************************************/ /* */ /************************************************************************/ int scan_dir(char *path, long low_msg, long high_msg, long art_array[], int max_arts) { long artnum; HDIR hdir = HDIR_CREATE; int sOff = sizeof(FILEFINDBUF) - CCHMAXPATHCOMP + 1; PFILEFINDBUF paffb = malloc(12288); PFILEFINDBUF pffb; int cffb = 255; int rc; int i; int num_arts = 0; char *tmplt = malloc(CCHMAXPATH); strcpy(tmplt, path); strcat(tmplt, "\\*"); if((rc = DosFindFirst2(tmplt, &hdir, 0, paffb, 12288, &cffb, 1, 0L)) == 0) { while (!rc && cffb) { pffb = paffb; for(i = 0; i < cffb; i++) { artnum = atol(pffb->achName); if (artnum) { if(high_msg) { if(artnum >= low_msg && artnum <= high_msg) art_array[num_arts++] = artnum; } else art_array[num_arts++] = artnum; if(num_arts >= max_arts) break; } pffb = (PFILEFINDBUF)((char *)pffb + sOff + pffb->cchName); } if(num_arts >= max_arts) break; cffb = 255; rc = DosFindNext(hdir, paffb, 12288, &cffb); } DosFindClose(hdir); qsort(art_array, num_arts, sizeof(long), longcmp); } free(paffb); free(tmplt); return (num_arts); } /************************************************************************/ /* */ /************************************************************************/ int scan_minmax(char *path, long *plo, long *phi) { long artnum; HDIR hdir = HDIR_CREATE; int sOff = sizeof(FILEFINDBUF) - CCHMAXPATHCOMP + 1; PFILEFINDBUF paffb = malloc(12288); PFILEFINDBUF pffb; int cffb = 255; int rc; int i; int num_arts = 0; char *tpl = malloc(strlen(path) + 3); *plo = 1; *phi = 0; strcat(strcpy(tpl, path), "\\*"); if((rc = DosFindFirst2(tpl, &hdir, 0, paffb, 12288, &cffb, 1, 0L)) == 0) { while (!rc && cffb) { pffb = paffb; for(i = 0; i < cffb; i++) { if((artnum = atol(pffb->achName)) > 0) { if(num_arts++) { if(artnum > *phi) *phi = artnum; else if(artnum < *plo) *plo = artnum; } else *plo = *phi = artnum; } pffb = (PFILEFINDBUF)((char *)pffb + sOff + pffb->cchName); } cffb = 255; rc = DosFindNext(hdir, paffb, 12288, &cffb); } DosFindClose(hdir); } free(paffb); free(tpl); return (num_arts); }