home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / LharcUUCP0_22.lha / LharcUUCP / source / RCS / ScanDir.c,v < prev   
Encoding:
Text File  |  1993-12-08  |  8.1 KB  |  343 lines

  1. head    0.5;
  2. access;
  3. symbols;
  4. locks
  5.     simons:0.5; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 0.5
  10. date    93.12.08.17.15.53;    author simons;    state Exp;
  11. branches;
  12. next    0.4;
  13.  
  14. 0.4
  15. date    93.12.08.17.08.46;    author simons;    state Exp;
  16. branches;
  17. next    0.3;
  18.  
  19. 0.3
  20. date    93.12.04.21.55.27;    author simons;    state Exp;
  21. branches;
  22. next    0.2;
  23.  
  24. 0.2
  25. date    93.12.04.21.52.40;    author simons;    state Exp;
  26. branches;
  27. next    0.1;
  28.  
  29. 0.1
  30. date    93.12.04.20.45.42;    author simons;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @Subroutines handling directory scanning.
  37. @
  38.  
  39.  
  40. 0.5
  41. log
  42. @InitScanDir() didn't reallocate the buffer in an overflow sitation,
  43. causing a system crash. :-) This is fixed now.
  44. @
  45. text
  46. @/*
  47.  *      $Filename: ScanDir.c $
  48.  *      $Revision: 0.4 $
  49.  *      $Date: 1993/12/08 17:08:46 $
  50.  *
  51.  *      Copyright (C) 1993 by Peter Simons <simons@@peti.GUN.de>
  52.  *
  53.  *      This program is free software; you can redistribute it and/or
  54.  *      modify it under the terms of the GNU General Public License as
  55.  *      published by the Free Software Foundation; either version 2 of
  56.  *      the License, or (at your option) any later version.
  57.  *
  58.  *      This program is distributed in the hope that it will be useful,
  59.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  60.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  61.  *      General Public License for more details.
  62.  *
  63.  *      You should have received a copy of the GNU General Public License
  64.  *      along with this program; if not, write to the Free Software
  65.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  66.  *
  67.  *      $Id: ScanDir.c,v 0.4 1993/12/08 17:08:46 simons Exp simons $
  68.  *
  69.  * ------------------------------ log history ----------------------------
  70.  * $Log: ScanDir.c,v $
  71.  * Revision 0.4  1993/12/08  17:08:46  simons
  72.  * AmigaOS's filesystem used to have a bug in versions earlier than 40.x,
  73.  * that may cause corrupted blocks and even crashes if files are deleted
  74.  * or renamed while the ExNext()-scan is in progress. Therefore I changed
  75.  * the directory scan. Now, the directory is read completly and all names
  76.  * buffered.
  77.  * Thanks to Frank Bergknecht <frank@@dino.dinoco.de> for drawing my
  78.  * attention to this.
  79.  *
  80.  * Revision 0.3  1993/12/04  21:55:27  simons
  81.  * ScanNextFil's buffers must be static, since the other routine accesses
  82.  * them.
  83.  *
  84.  * Revision 0.2  1993/12/04  21:52:40  simons
  85.  * The routines are working. ScanNextFile() buffers one the file currently
  86.  * locked and returns the previous one, so can I change the filename
  87.  * returned by the routine without losing the flow.
  88.  *
  89.  * Revision 0.1  1993/12/04  20:45:42  simons
  90.  * System dependant routines! Will need some work to port them.
  91.  */
  92.  
  93.  
  94. /************************************* includes ***********/
  95. #include <stdlib.h>
  96. #include <string.h>
  97. #include <dos.h>
  98.  
  99. /************************************* defines ************/
  100.  
  101. /************************************* prototypes *********/
  102.  
  103. /************************************* global variables ***/
  104. static const char __RCSId[] = "$Id: ScanDir.c,v 0.4 1993/12/08 17:08:46 simons Exp simons $";
  105.  
  106. static char *flnarray, *flnarray_current;
  107. static int flnarray_size = 2048;
  108.  
  109. extern int _OSERR;
  110.  
  111. /************************************* subroutines ********/
  112. int InitDirScan(char *flnpattern)
  113. {
  114.         while (flnarray = malloc(flnarray_size)) {
  115.                 if (getfnl(flnpattern,flnarray,flnarray_size,0) != -1) {
  116.                         flnarray_current = flnarray;
  117.                         return 1;
  118.                 }
  119.                 else {
  120.                         if (_OSERR)
  121.                                 return 0;
  122.                         else {
  123.                                 free(flnarray);
  124.                                 flnarray_size += 1024;
  125.                         }
  126.                 }
  127.         }
  128.         return 0;
  129. }
  130.  
  131.  
  132. char *ScanNextFile(void)
  133. {
  134.         char *name;
  135.  
  136.         if (!(*flnarray_current))
  137.                 return NULL;
  138.  
  139.         name = flnarray_current;
  140.         while (*(flnarray_current++))
  141.                 ;
  142.  
  143.         return name;
  144. }
  145.  
  146.  
  147. void EndDirScan(void)
  148. {
  149.         free(flnarray);
  150.         flnarray_size = 4096;
  151. }
  152.  
  153. @
  154.  
  155.  
  156. 0.4
  157. log
  158. @AmigaOS's filesystem used to have a bug in versions earlier than 40.x,
  159. that may cause corrupted blocks and even crashes if files are deleted
  160. or renamed while the ExNext()-scan is in progress. Therefore I changed
  161. the directory scan. Now, the directory is read completly and all names
  162. buffered.
  163. Thanks to Frank Bergknecht <frank@@dino.dinoco.de> for drawing my
  164. attention to this.
  165. @
  166. text
  167. @d3 2
  168. a4 2
  169.  *      $Revision: 0.3 $
  170.  *      $Date: 1993/12/04 21:55:27 $
  171. d22 1
  172. a22 1
  173.  *      $Id: ScanDir.c,v 0.3 1993/12/04 21:55:27 simons Exp simons $
  174. d26 9
  175. d59 1
  176. a59 1
  177. static const char __RCSId[] = "$Id: ScanDir.c,v 0.3 1993/12/04 21:55:27 simons Exp simons $";
  178. d62 1
  179. a62 1
  180. static int flnarray_size = 4096;
  181. d69 8
  182. a76 6
  183.         if (flnarray = malloc(flnarray_size)) {
  184.                 do {
  185.                         if (getfnl(flnpattern,flnarray,flnarray_size,0) != -1) {
  186.                                 flnarray_current = flnarray;
  187.                                 return 1;
  188.                         }
  189. d78 2
  190. a79 6
  191.                                 if (_OSERR)
  192.                                         return 0;
  193.                                 else {
  194.                                         free(flnarray);
  195.                                         flnarray_size += 1024;
  196.                                 }
  197. d81 1
  198. a81 1
  199.                 } while (1);
  200. @
  201.  
  202.  
  203. 0.3
  204. log
  205. @ScanNextFil's buffers must be static, since the other routine accesses
  206. them.
  207. @
  208. text
  209. @d3 2
  210. a4 2
  211.  *      $Revision: 0.2 $
  212.  *      $Date: 1993/12/04 21:52:40 $
  213. d22 1
  214. a22 1
  215.  *      $Id: ScanDir.c,v 0.2 1993/12/04 21:52:40 simons Exp simons $
  216. d26 4
  217. a36 1
  218.  *
  219. d41 1
  220. d43 1
  221. a43 3
  222.  
  223. #include <dos/dos.h>
  224. #include <proto/dos.h>
  225. d50 1
  226. a50 1
  227. static const char __RCSId[] = "$Id: ScanDir.c,v 0.2 1993/12/04 21:52:40 simons Exp simons $";
  228. d52 2
  229. a53 4
  230. BPTR lock = 0;
  231. struct FileInfoBlock fib;
  232. char token[64];
  233. int first_time = 0;
  234. d55 2
  235. d58 1
  236. a58 1
  237. int InitDirScan(char *dirname, char *pattern)
  238. d60 5
  239. a64 6
  240.         int success = 0;
  241.         if (lock = Lock(dirname, ACCESS_READ)) {
  242.                 if (Examine(lock, &fib)) {
  243.                         if (ParsePatternNoCase(pattern, token, 64) == 1) {
  244.                                 success = 1;
  245.                                 first_time = 1;
  246. d66 9
  247. a74 1
  248.                 }
  249. d76 1
  250. a76 2
  251.  
  252.         return success;
  253. d82 1
  254. a82 1
  255.         static char scannedname[108], filename[108], filename2[108];
  256. d84 2
  257. a85 11
  258.         if (first_time) {
  259.                 do {
  260.                         if (ExNext(lock, &fib))
  261.                                 strcpy(filename, fib.fib_FileName);
  262.                         else
  263.                                 filename[0] = '\0';
  264.  
  265.                 } while (filename[0] && !MatchPatternNoCase(token, filename));
  266.                 strcpy(scannedname, filename);
  267.                 first_time = 0;
  268.         }
  269. d87 3
  270. a89 8
  271.         do {
  272.                 if (ExNext(lock, &fib))
  273.                         strcpy(filename, fib.fib_FileName);
  274.                 else
  275.                         filename[0] = '\0';
  276.         } while (filename[0] && !MatchPatternNoCase(token, filename));
  277.         strcpy(filename2, scannedname);
  278.         strcpy(scannedname, filename);
  279. d91 1
  280. a91 1
  281.         return (filename2[0]) ? filename2 : NULL;
  282. d97 2
  283. a98 4
  284.         if (lock) {
  285.                 UnLock(lock);
  286.                 lock = 0;
  287.         }
  288. @
  289.  
  290.  
  291. 0.2
  292. log
  293. @The routines are working. ScanNextFile() buffers one the file currently
  294. locked and returns the previous one, so can I change the filename
  295. returned by the routine without losing the flow.
  296. @
  297. text
  298. @d3 2
  299. a4 2
  300.  *      $Revision: 0.1 $
  301.  *      $Date: 1993/12/04 20:45:42 $
  302. d22 1
  303. a22 1
  304.  *      $Id: ScanDir.c,v 0.1 1993/12/04 20:45:42 simons Exp simons $
  305. d26 5
  306. d48 1
  307. a48 1
  308. static const char __RCSId[] = "$Id: ScanDir.c,v 0.1 1993/12/04 20:45:42 simons Exp simons $";
  309. d74 1
  310. a74 2
  311.         static char scannedname[108];
  312.         char filename[108], filename2[108];
  313. @
  314.  
  315.  
  316. 0.1
  317. log
  318. @System dependant routines! Will need some work to port them.
  319. @
  320. text
  321. @d3 2
  322. a4 2
  323.  *      $Revision$
  324.  *      $Date$
  325. d22 1
  326. a22 1
  327.  *      $Id$
  328. d25 4
  329. a28 1
  330.  * $Log$
  331. d33 2
  332. a35 1
  333. #include <exec/memory.h>
  334. a36 1
  335. #include <proto/exec.h>
  336. d43 1
  337. a43 2
  338. static const char __RCSId[] = "$Id$";
  339.  
  340. d45 4
  341. d51 53
  342. @
  343.