There is an article in the blog that describes how to add a Debug header to a function. However, I think there is still a lot of work to be done. For example, the Code must be properly compiled, the file size cannot exceed BUF_SIZE for one-time reading, the function header is too simple, and multiple encoding format files are not supported. To address this huge workload, consider using existing open-source formatting tools similar to static code analysis to find a suitable solution. To address this requirement, the code using the Astyle formatting tool is improved based on version 2.03. The judgment condition is very simple: For C, except for extern "C" and struct, it is the start of the function, and extern "C" is generally used only in the header file; for C ++, apart from namespace, it is basically the beginning of the function (and namespace is generally used only in the header file -- this sentence is wrong, but when there is namespace, the {of the function is still formatted, so it is still available.) The struct and namespace still need to be manually deleted. Only a few lines of code are added, and the added code is surrounded by // add by zqb down and // add by zqb up annotations, respectively, indicating that the added code is used for debugging. The added code contains three sections:
Void ASConsole: formatFile (const string & fileName _) function. Section 1: [cpp] view plaincopyprint? // Add by zqb down out <"# include \" debug. h \ "\ r \ n"; linesOut ++; // add by zqb up // add by zqb downout <"# include \" debug. h \ "\ r \ n"; linesOut ++; // add by zqb up indicates the header file where the debugging macro is added.
Section 2:
// Add by zqb down if (nextLine = "{") {out <"\ r \ n" <"\ t" <"DEBUG; \ r \ n "; linesOut ++;} // add by zqb up // add by zqb downif (nextLine = "{") {out <"\ r \ n" <"\ t" <"DEBUG; \ r \ n"; linesOut ++ ;} // add by zqb up indicates the specific content of the debugging header.
Section 3:
// Add by zqb down filesAreIdentical = false; // add by zqb up // add by zqb downfilesAreIdentical = false; // add by zqb up no matter what conditions, are updated to new files.
[Note] 1. Compile the error: newline in constant: use notepad ++ to open ASLocalizer. cpp, format-> encode in UTF-8 format, save the file re-compile. The author uses the free Microsoft Visual C ++ 2008 Express Edition to compile the vs2008 version. Here is the download link for the project. 3. Restrictions: the standard format of ansi is required (the command line option is-A1), which is to take the first '{' of the function as the top line.