Debian Codegraph @

protolib/examples/fileTest.cpp

raw
1 // This examples tests and demonstrates a number of the
2 // ProtoFile features including directory iteration, etc.
3
4 #include "protoFile.h"
5 #include <stdio.h>
6 #ifdef WIN32
7 #include <windows.h> // for Sleep()
8 #else // UNIX
9 #include <unistd.h> // for sleep()
10 #endif // if/else WIN32/UNIX
11
12 // Usage: fileTest path1 [path2 path3 ...]
13
14 int main(int argc, char* argv[])
15 {
16
17 ProtoFile::PathList pathList;
18
19 for (int i = 1; i < argc; i++)
20 {
21 if (!pathList.AppendPath(argv[i]))
22 {
23 fprintf(stderr, "fileTest error: unable to append item\n");
24 return -1;
25 }
26 }
27
28 ProtoFile::PathList::PathIterator iterator(pathList, true);
29
30 // Note PathIterator also has GetNextDirectory() and GetNextPath() methods
31 // for other purposes
32
33 char path[PATH_MAX + 1];
34 while (iterator.GetNextFile(path))
35 {
36 const ProtoFile::Path* parentPath = iterator.GetCurrentPathItem();
37 printf("1st iteration to \"%s\" (parentPath: %s )\n", path, parentPath->GetPath());
38 }
39
40 fprintf(stderr, "fileTest: sleeping 5 seconds before 2nd iteration for updated files\n");
41
42 #ifdef WIN32
43 Sleep(5000);
44 #else // UNIX
45 sleep(5); // This provides an opportunity to touch a file to illustrate "updateOnly" iteration
46 #endif // if/else WIN32/UNIX
47
48 iterator.Reset();
49 while (iterator.GetNextFile(path))
50 printf("2nd iteration to \"%s\"\n", path);
51 iterator.Init(true);
52
53 } // end main()
54