File: filewalk.h

package info (click to toggle)
bsign 0.4.5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, sarge, squeeze, wheezy
  • size: 420 kB
  • ctags: 648
  • sloc: cpp: 3,021; ansic: 344; makefile: 295; sh: 219
file content (118 lines) | stat: -rw-r--r-- 3,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* filewalk.h		-*- C++ -*-
     $Id: filewalk.h,v 1.6 2002/01/17 23:56:05 elf Exp $

   written by Marc Singer
   14 Jan 2002

   This file is part of the project BSIGN.  See the file README for
   more information.

   Copyright (C) 2002 The Buici Company

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.

   -----------
   DESCRIPTION
   -----------

   A wrapper around FTS with support for inclusion and exclusion.  It
   is important to note that the include, exclude and insert functions
   accept and store character pointers without copying the data.  This
   is because the intended use is with parsing command line arguments.
   Callers that cannot cope with this must copy strings before passing
   them to FileWalk.


*/

#if !defined (__FILEWALK_H__)
#    define   __FILEWALK_H__

/* ----- Includes */

#include <fts.h>		/* glibc2 header, required */
#include <limits.h>
#include <sys/stat.h>


/* ----- Types */

class FileWalk {
public:

  typedef struct {
    int cMax;
    int cUsed;
    char** rgsz;
  } List;

protected:

  const char* m_szFileCurrent;
  struct stat* m_pStat;
  
  struct stat m_stat;		// Stat buffer when we need one

		// --- FTS enumeration
  FTS* m_pfts;			// Pointer to fts object
  FTSENT* m_pent;		// Pointer to last returned file object
  List m_listInclude;		// Funky list used to include roots
  List m_listExclude;		// Funky list used to exclude

  		// --- Explicit enumeration
  List m_listInsert;		// Funky list used to store explicit pathnames
  int m_cCurrent;		// Index of this current item in inserted list 

		// --- File source enumeration
  const char* m_szPathSource;	// Read filenames from a file
  FILE* m_fp;			// Buffered I/O handle for reading filenames
  char m_szFilename[PATH_MAX + 1]; // Last read filename

  bool is_excluded (void);
  void release_this (void);
  void zero (void) {
    bzero (this, sizeof (*this)); m_cCurrent = -1; }

  const char* next_insert (void);
  const char* next_fts (void);
  const char* next_source (void);

public:
  FileWalk () { zero (); }
  ~FileWalk () { release_this (); }

  void exclude (const char* sz);
  void include (const char* sz);
  void insert  (const char* sz);
  void source  (const char* szPath) { m_szPathSource = szPath; }

  bool is_ready (void);
  bool is_only_one (void);
  const char* next (void);
  const char* current (void) {
    return m_szFileCurrent; }
  struct stat* stat (void) {
    return m_pStat; }

};

/* ----- Globals */

/* ----- Prototypes */



#endif  /* __FILEWALK_H__ */