]> cygwin.com Git - cygwin-apps/setup.git/blame - find.cc
2003-10-23 Jerry D. Hedden <jerry@hedden.us>
[cygwin-apps/setup.git] / find.cc
CommitLineData
23c9e63c 1/*
b401ef47 2 * Copyright (c) 2002, Robert Collins.
23c9e63c
DD
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
b401ef47 13 * Rewritten by Robert Collins <rbtcollins@hotmail.com>
23c9e63c
DD
14 *
15 */
16
17/* The purpose of this file is to doa recursive find on a given
18 directory, calling a given function for each file found. */
19
b24c88b3
RC
20#if 0
21static const char *cvsid =
22 "\n%%% $Id$\n";
23#endif
8507f105 24
b401ef47 25#include "find.h"
23c9e63c 26#include "win32.h"
23c9e63c
DD
27#include <stdlib.h>
28
b401ef47 29//#include "port.h"
23c9e63c 30
3c054baf 31#include "String++.h"
b401ef47
RC
32#include "FindVisitor.h"
33#include <stdexcept>
34
6625e635
RC
35using namespace std;
36
b401ef47
RC
37Find::Find(String const &starting_dir) : _start_dir (starting_dir), h(INVALID_HANDLE_VALUE)
38{
39}
3c054baf 40
b401ef47
RC
41Find::~Find()
42{
43 if (h != INVALID_HANDLE_VALUE && h)
44 FindClose (h);
45}
23c9e63c 46
b401ef47
RC
47void
48Find::accept (FindVisitor &aVisitor)
23c9e63c
DD
49{
50 WIN32_FIND_DATA wfd;
b401ef47
RC
51 if (_start_dir.size() > _MAX_PATH)
52 throw new length_error ("starting dir longer than _MAX_PATH");
23c9e63c 53
b401ef47 54 h = FindFirstFile ((_start_dir + "/*").cstr_oneuse(), &wfd);
23c9e63c
DD
55
56 if (h == INVALID_HANDLE_VALUE)
b401ef47
RC
57 return;
58
59 String basePath = _start_dir + "/";
23c9e63c 60
b24c88b3
RC
61 do
62 {
63 if (strcmp (wfd.cFileName, ".") == 0
64 || strcmp (wfd.cFileName, "..") == 0)
65 continue;
23c9e63c 66
b401ef47
RC
67 /* TODO: make a non-win32 file and dir info class and have that as the
68 * visited node
69 */
b24c88b3 70 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
b401ef47 71 aVisitor.visitDirectory (basePath, &wfd);
b24c88b3 72 else
b401ef47 73 aVisitor.visitFile (basePath, &wfd);
b24c88b3
RC
74 }
75 while (FindNextFile (h, &wfd));
23c9e63c 76}
This page took 0.042745 seconds and 5 git commands to generate.