fswatch 项目教程
1. 项目的目录结构及介绍
fswatch 项目的目录结构如下:
fswatch/
├── AUTHORS
├── CMakeLists.txt
├── COPYING
├── ChangeLog
├── INSTALL
├── Makefile.am
├── NEWS
├── README
├── README.md
├── aclocal.m4
├── config.h.in
├── configure.ac
├── doc/
│ ├── Doxyfile.in
│ ├── Makefile.am
│ └── man/
│ ├── fswatch.1
│ └── fswatch.1.md
├── examples/
│ ├── Makefile.am
│ └── simple_monitor.cpp
├── m4/
│ ├── ax_append_flag.m4
│ ├── ax_c___attribute__.m4
│ ├── ax_check_compile_flag.m4
│ ├── ax_check_link_flag.m4
│ ├── ax_compiler_vendor.m4
│ ├── ax_cxx_compile_stdcxx.m4
│ ├── ax_gcc_func_attribute.m4
│ ├── ax_pthread.m4
│ ├── ax_require_defined.m4
│ ├── ax_valgrind_check.m4
│ └── libfswatch.m4
├── src/
│ ├── CMakeLists.txt
│ ├── Makefile.am
│ ├── libfswatch/
│ │ ├── CMakeLists.txt
│ │ ├── Makefile.am
│ │ ├── c++11/
│ │ ├── gettext.h
│ │ ├── libfswatch.h
│ │ ├── libfswatch.hpp
│ │ ├── libfswatch_exception.hpp
│ │ ├── libfswatch_map.hpp
│ │ ├── libfswatch_set.hpp
│ │ ├── libfswatch_string.hpp
│ │ ├── libfswatch_vector.hpp
│ │ ├── path_utils.cpp
│ │ ├── path_utils.hpp
│ │ ├── string_utils.cpp
│ │ ├── string_utils.hpp
│ │ ├── windows/
│ │ └── ...
│ └── fswatch/
│ ├── CMakeLists.txt
│ ├── Makefile.am
│ ├── fswatch.cpp
│ ├── fswatch.h
│ ├── fswatch_cmdline.cpp
│ ├── fswatch_cmdline.h
│ ├── fswatch_monitor.cpp
│ ├── fswatch_monitor.h
│ ├── fswatch_options.cpp
│ ├── fswatch_options.h
│ ├── fswatch_version.h
│ └── ...
└── tests/
├── CMakeLists.txt
├── Makefile.am
├── test_fswatch.cpp
└── ...
目录结构介绍
AUTHORS
,COPYING
,ChangeLog
,INSTALL
,NEWS
,README
,README.md
: 项目的基本文档文件。aclocal.m4
,config.h.in
,configure.ac
,Makefile.am
: 用于自动配置和构建项目的文件。doc/
: 包含项目的文档,如手册页 (man/
目录)。examples/
: 包含示例代码,如simple_monitor.cpp
。m4/
: 包含用于自动配置的 m4 宏文件。src/
: 包含项目的源代码,分为libfswatch
和fswatch
两个主要部分。tests/
: 包含项目的测试代码。
2. 项目的启动文件介绍
项目的启动文件是 src/fswatch/fswatch.cpp
。这个文件包含了 fswatch
命令行工具的主要实现。以下是该文件的一些关键部分:
#include "fswatch.h"
#include "fswatch_cmdline.h"
#include "fswatch_monitor.h"
#include "fswatch_options.h"
int main(int argc, char *argv[])
{
// 解析命令行参数
fswatch_cmdline cmdline;
if (!cmdline.parse(argc, argv)) {
return 1