[译]包括文件层次结构查看器
By robot-v1.0
本文链接 https://www.kyfws.com/applications/include-file-hierarchy-viewer-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 12 分钟阅读 - 5903 个词 阅读量 0[译]包括文件层次结构查看器
原文地址:https://www.codeproject.com/Articles/3478/Include-File-Hierarchy-Viewer
原文作者:Chris Richardson
译文由本站 robot-v1.0 翻译
前言
A tool to view the include file hierarchy of your source code.
查看源代码的包含文件层次结构的工具.
介绍(Introduction)
我已经看到许多人询问实用程序以查看树的结构(I’ve seen many people ask about utilities to view the tree of) #include
d文件的源代码.我想我以前在CodeProject或在CodeGuru都已经看过其中之一,但是我似乎找不到.由于我真的很喜欢文本处理,因此我自己编写了自己的文本.我想到的是一个快速的多线程(d files in their source code. I think I’ve seen one of these before, either here at CodeProject or maybe at CodeGuru, but I can’t seem to find it. Since I really enjoy text processing, I took it upon myself to write my own. What I’ve come up with is a fast, multi-threaded) #include
树生成器.(tree generator.)
特征(Features)
- 搜索多个目录(Search multiple directories) .(.)
- 搜索从VC6/VC7项目或工作空间加载的文件(Search files loaded from VC6/VC7 projects or workspaces) .(.)
- 在树形控件中查看和搜索输出(View and search the output in a tree control) .(.)
- 以XML格式保存和重新加载搜索结果(Save and reload search results in XML format) .(.)
搜索多个目录(Searching multiple directories)
如您在上面的屏幕快照中所见,在生成树之前,需要填写一些字段.我认为这很不言自明,但是我将在此处解释这些字段,以防万一有人认为不是.(As you can see in the screenshot above, there are a few fields to fill in before you can generate the tree. I think it’s pretty self-explanatory, but I will explain the fields here just in case some think it’s not.)
-
**搜寻(Search in)**输入您要搜索的目录列表.您可以一次输入多个目录,可以使用分号将它们分开.或者,可以选择使用浏览按钮(" …")从标准Shell浏览器中选择目录.该组合框将存储最近搜索的目录,因此,如果您愿意,还可以从下拉列表中选择一个目录.(Type in a list of directories you want to search. You can enter multiple directories at one time by separating them with semi-colons. Or, optionally, use the browse button ("…") to pick a directory from the standard Shell Browser. This combo box will store the recently searched directories, so you can also select a directory from the drop-down list if you like.)
-
**文件遮罩(File mask)**输入您要搜索的文件掩码列表.您可以一次输入多个文件掩码,方法是使用分号将它们分开.该组合框将存储最近使用的文件掩码,因此,如果您愿意,还可以从下拉列表中选择一个掩码.(Type in a list of file masks you want to search for. You can enter multiple file masks at one time by separating them with semi-colons. This combo box will store the recently used file masks, so you can also select a mask from the drop-down list if you like.)
-
**包括(Includes)**输入外部头文件所在的目录列表.您可以一次输入多个包含目录,方法是用分号将它们分开.同样,可以在此字段中输入环境变量,软件将在运行时对其进行扩展.为此,只需在变量前加上'%‘字符(即%INCLUDE)即可.(Type in a list of directories where external header files reside. You can enter multiple include directories at one time by separating them with semicolons. Also, it’s possible to enter an environment variable in this field, which the software will expand at runtime. To do this, simply prefix the variable with a ‘%’ character (i.e. %INCLUDE).)
-
**递归子目录(Recurse subdirectories)**如果希望程序通过输入的目录的子目录递归,请设置此复选框.(Set this check box if you want the program to recurse through subdirectories of the directories you entered.)
搜索从VC6/VC7工作区或项目加载的文件(Searching files loaded from VC6/VC7 workspaces or projects)
搜索工作空间或项目时,不必输入与搜索目录时一样多的信息,但仍必须加载项目或工作空间,指定文件掩码并选择配置.该软件将读取与预处理有关的设置,例如其他包含目录和预处理器定义.此外,VC6项目阅读器将读取VC6包含目录的注册表,而VC7项目阅读器将读取VC7包含目录的注册表,这意味着,如果您已经配置了VC6或VC7,则无需配置此目录程序.(When searching a workspace or project, you don’t have to input as much information as when searching a directory, but you still have to load a project or workspace, specify a file mask, and select a configuration. The software will read settings related to preprocessing, such as additional include directories, and preprocessor definitions. Also, the VC6 project reader will read the registry for the VC6 include directories, and the VC7 project reader will read the registry for the VC7 include directories, which means if you have VC6 or VC7 configured already, you don’t have to configure this program as well.)
**注意:(Note:)**工作区和项目加载尚不完美,但是我已经在各种场景中对其进行了测试,并且对我来说效果很好.最大的问题是准确解释项目设置,但仍然存在问题.(The workspace and project loading isn’t perfect yet, but I have tested it in a variety of scenarios, and it works well for me. The biggest problem is accurately interpreting the project settings, which there are still issues with.)
-
**工作空间(Workspace)**输入您要加载的工作空间或项目的路径.或者,可以选择使用浏览按钮(" …")从标准"文件打开"对话框中选择一个工作区.该组合框将存储最近搜索的工作区,因此,您也可以根据需要从下拉列表中选择一个最近的条目.(Type in the path to the workspace or project you want to load. Or, optionally, use the browse button ("…") to pick a workspace from the standard File Open dialog box. This combo box will store the recently searched workspaces, so you can also select a recent entry from the drop-down list if you like.)
-
**加载工作区(Load workspace)**单击此按钮可以加载选定的工作区或项目,因此您可以选择配置.如果您在单击之前未加载工作区(Click this button to load the selected workspace or project, so you can select a configuration. If you don’t load the workspace before you click)开始(Start),包含查找器将使用在每个项目中找到的第一个配置.(, the Include Finder will use the first configuration found in each project.)
-
**文件遮罩(File mask)**输入您要搜索的文件掩码列表.您可以一次输入多个文件掩码,方法是使用分号将它们分开.该组合框将存储最近使用的文件掩码,因此,如果您愿意,还可以从下拉列表中选择一个掩码.(Type in a list of file masks you want to search for. You can enter multiple file masks at one time by separating them with semi-colons. This combo box will store the recently used file masks, so you can also select a mask from the drop-down list if you like.)
-
**组态(Configuration)**选择一个项目配置.您选择的配置将确定使用哪些预处理程序包括目录,以及使用哪些预处理程序定义.(Select a project configuration. The configuration you select will determine which preprocessor include directories are used, and also which preprocessor definitions are used.)
其他选择(Other options)
- **解析预处理器宏(Parse preprocessor macros)**现在可以解析预处理器宏,并且此标志用于打开和关闭该功能.由于解析可能不是100%准确的(相对于编译器而言),因此我留给您选择.(There is now the capability to parse the preprocessor macros, and this flag is used to turn that feature on and off. Since the parsing may not be 100% accurate (with respect to the compiler), I leave this as a choice to you.)
输入一些有效数据后,请点击(Once you’ve entered some valid data, click)**开始(Start)**程序将开始搜索.搜索是在单独的线程中完成的,因此您将看到按钮的文本变为"(and the program will start the search. The searching is done in a separate thread, so you will see the button’s text turn to “)停止(Stop)"(” once you click)开始(Start).要停止搜索,只需单击(. To stop the search, simply click)**停止(Stop)**然后线程将退出,将(and the thread will quit, turning the)**停止(Stop)**按钮回到(button back into the)**开始(Start)**按钮.(button.)
查看和搜索输出(Viewing and searching the output)
输出显示在标准Win32树形控件中,使用MFC的(The output is shown in a standard Win32 tree control, using MFC’s) CTreeCtrl
.每个源文件完成后,程序将使用源文件和所有文件填充树(. As each source file is completed, the program populates the tree with the source file and all the files) #include
d.您会注意到树中使用了一些图标来表示项目的属性.这是对它们的解释:(d by it. You will notice that there are a few icons used in the tree that denote properties of the item. Here’s an explanation of them:)
此图标用于表示常规文件.(This icon is used to denote a regular file.)
此图标用于表示文件实例不是当前(直接或间接)包含在当前源文件中的.(This icon is used to denote that the instance of the file is not the first time it was included by the current source file (either directly or indirectly).)
此图标用于表示无法在指定的包含路径中找到该文件.(This icon is used to denote that the file could not be found along the specified include paths.)
此图标用于表示该文件已被递归包含.(This icon is used to denote that the file has been recursively included.)
要在树中搜索特定文件,请选择(To search the tree for a particular file, select the)**找…(Find…)**菜单项,或单击(menu item, or click)**F3(F3)**搜索下一个出现的字符串.(to search for the next occurrence of a string.)
保存和还原数据(Saving and restoring the data)
如果您点击(If you click on the)**救(Save)**工具栏图标,或选择(toolbar icon, or select the)**保存结果…(Save Results…)**菜单项,将提示您输入要保存的文件名.结果以XML格式保存,如下所示.(menu item, you will be prompted to enter a file name to save to. The results are saved in XML format like the sample shown below.)
示例XML输出(使用IE查看)(Sample XML output (viewed with IE))
保存XML文件后,您可以点击(Once you have saved an XML file, you can click the)**打开(Open)**工具栏图标,或选择(toolbar icon, or select the)**打开…(Open…)**菜单项以选择要重新加载的文件. XML树将重新加载到"包含查找器"中.(menu item to select a file to reload. The XML tree will be reloaded into the Include Finder.)
关于代码(About the code)
**注意:(Note:)**在我的工作中,我们有一种编码标准,这是匈牙利符号的一种形式.我还在这个项目中使用了这个标准.这是我过去几年一直在使用的,而且我喜欢它,但这不是本文或代码的重点,所以请不要为此而烦恼.(At my work we have a coding standard which is a form of Hungarian notation. I’ve also used this standard in this project. It’s what I’ve been using for the past few years, and I like it, but that’s not the point of the article or the code, so please don’t flame me for it.)
我试图将程序的核心代码与接口尽可能地分开,以便有人重用有趣的部分.由于自第一个版本以来,代码的大小已大大增加,因此我决定省略对类的描述.如果您对使用该代码感兴趣,可以在它们顶部的标题中找到每个文件的内容的描述.(I’ve tried to keep the core code of the program as separated from the interface as possible, so that it will be easy for someone to reuse the interesting portions. Since the code has grown substantially in size since the first version, I decided to omit descriptions of the classes. If you are interested in using the code, you can find a description of what’s in each file in the headers at the top of them.)
致谢(Acknowledgements)
我要感谢以下人员:(I’d like to thank the following people:)
- 内维尔`弗兰克斯(Neville Franks) 给他寄给我(for sending me his).dsp(.dsp*)*/(*/*)*.dsw(*.dsw*)*阅读代码,这有助于使它们的解析更可靠.(*reading code, which helped make the parsing of them more robust.*)
- .S.Rod.(.S.Rod.) 为了他(for his) VC7-> VC6项目转换器(VC7->VC6 Project Converter) 代码,我将其用作解析(code, which I used as a starting point for parsing the).sln(.sln*)*和(*and*)*.vcproj(*.vcproj*)*格式.(*formats.*)
- 克里斯汀`韦格纳(Kristen Wegner) 为了她(for her) 帕格(PugXml) 解析器.(parser.)
去做(To Do)
- 在内核之外制作一个静态库是很巧妙的,因此可以在Developer Studio加载项以及当前使用的外部工具中使用该内核.(It would be neat to make a static library out of the core, thereby making it possible to use the core in a Developer Studio add-in, as well as the external tool that it currently is.)
- 预处理程序宏处理可能会更好.(The preprocessor macro handling could be better.)
- 解释项目设置也可能更好.(Interpreting the project settings could also be better.)
- 我试图干净地编写代码,但是我确定它仍然可以进行一些清理.(I’ve tried to write the code cleanly, but I’m sure it could still use some clean-up.)
- 那些想使用代码的文档?(Documentation for those who would like to use the code?)
历史(History)
-
一月7(January 7)日(th),2003年-初始版本.(, 2003 - Initial release.)
-
一月27(January 27)日(th),2003(, 2003)
- 新增了阅读功能(Added the capability to read).dsp(.dsp*)*/(*/*)*.dsw(*.dsw*)*/(*/*)*.vcproj(*.vcproj*)*/(*/*)*.sln(*.sln*)*文件.(*files.*)
- 添加了一个解析预处理器宏的选项.(Added an option to parse preprocessor macros.)
- 添加了一次搜索多个目录的功能.(Added the capability to search multiple directories at once.)
- 添加了一个选项,以仅显示找不到的文件.(Added an option to show only files which couldn’t be found.)
- 新增了对在环境变量中输入环境变量的支持(Added support for entering environment variables in the)**包括(Includes)**领域.(field.)
- 添加了从磁盘加载保存的XML文件的功能.(Added the capability to load a saved XML file from disk.)
- 添加了选择用于查看源文件的自定义程序的功能.(Added the capability to select a custom program for viewing source files.)
- 添加了双击树中的叶节点以打开文件的功能.(Added the capability to double-click a leaf node in the tree to open the file.)
- 添加了在树中搜索指定字符串的功能.(Added the capability to search the tree for specified strings.)
- 添加(Added)
CMMFStream
类,大大提高了解析性能.(class, which improved parsing performance greatly.)
-
二月24(February 24)日(th),2003年(错误修复)-感谢Medved,Oliver Wahl和Andreas Saurwin提醒我和/或显示这些错误的补丁.(, 2003 (bug fixes) - Thanks to Medved, Oliver Wahl, and Andreas Saurwin for alerting me to, and/or showing patches for these bugs.)
CMMFStream
会错误地处理零长度的文件.(would incorrectly handle files with zero length.)CParser::FindFullPath
有一个错误使它在某些情况下可以找到不正确的文件.(had a bug which made it find the incorrect file in certain cases.)CLexer
错误地处理了可能在二进制文件中找到的某些字符.(incorrectly handled certain characters that could be found in binary files.)CLexer
错误地处理了\ r \ n奇怪组合的文件,从而导致崩溃.(incorrectly handled files which had a strange combination of \r\n, which caused a crash.)
-
7月30日(July 30)日(th),2003年(错误修复和一些更改,可以在没有IE Shell更新的情况下在NT 4上运行)(, 2003 (bug fixes and some changes to run on NT 4 without IE shell update))
- 修复了一个错误(Fixed a bug where)
FindFullPath
会错误地处理两个具有相同名称但路径不同的文件. -感谢Oliver Wahl.(would incorrectly handle two files with the same name but in different paths. - Thanks to Oliver Wahl.) - 修复了无法读取项目设置中包含括号的包含目录的错误. -感谢EvanKeats.(Fixed a bug where bracketed include directories from project settings weren’t read. - Thanks to EvanKeats.)
- 删除了使用(Removed the use of)
SHGetSpecialFolderPath
并替换为(and replaced it with)SHGetSpecialFolderLocation
/(/)SHGetPathFromIDList
. -感谢brownfox和Hemal Shah.(. - Thanks to brownfox and Hemal Shah.)
- 修复了一个错误(Fixed a bug where)
免责声明和版权(Disclaimer and copyright)
尽管在开发此软件时已格外小心,但所提供的软件没有任何可靠性,信息准确性或操作正确性的保证.对于使用此软件可能造成的任何损坏,我概不负责.使用此软件的风险完全由您自己承担.克里斯`理查森(Chris Richardson)版权所有2003.(Although great care has gone into developing this software, it is provided without any guarantee of reliability, accuracy of information, or correctness of operation. I am not responsible for any damages that may occur as a result of using this software. Use this software entirely at your own risk. Copyright 2003, Chris Richardson.)
最后的笔记(Final notes)
任何反馈或错误报告将不胜感激.如果您喜欢或不喜欢我提供的文章,代码或程序,请告诉我原因.(Any feedback or bug reports will be greatly appreciated. If you do or do not like the article, the code, or the program I’ve provided, please tell me why.)
感谢您抽出宝贵的时间阅读我的文章.希望您喜欢它,也希望"发现查找器"有用.(Thanks for taking the time to read my article. I hope you enjoyed it, and I hope you find the Include Finder useful.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Windows Win2K MFC Visual-Studio Dev 新闻 翻译