Enable code2html to correctly highlight all C++98 features (keywords) and ensure the project compiles and runs reliably on Linux.
The project had several issues prohibiting compilation and correct execution on Linux.
[MODIFY] cppparse.cpp
- Feature: Updated
mainto accept command-line arguments (argv[1]) instead of hardcodingCppParser.cpp. - Fix: Adjusted
#include "cppparse.h"andkeywords/cpp.kwdto match Linux case-sensitive filenames.
[MODIFY] cppparse.h
- Fix: Changed
#include "parser.h"to match filename case. - Fix: Corrected destructor to avoid memory corruption/core dump by deleting individual char arrays in
keyWordsinstead of the array of pointers.
[MODIFY] parser.h
- Fix: Increased
MAX_KEYWORDfrom 64 to 256 to prevent buffer overflow (segmentation fault) when loading the larger C++98 keyword set. - Fix: Added
virtualkeyword to comment handling methods for correct polymorphism.
[MODIFY] parser.cpp
- Fix: Commented out duplicate
mainfunction (conflicted withcppparse.cpp). - Fix: Repaired syntax errors (broken comments, invalid scope operators
Parser: :) caused by file corruption. - Fix: corrected logic in
keyMatchto properly resetkeyIndexand ensure all paths return a value.
[MODIFY] keywords/cpp.kwd
- Added all missing C++98 keywords:
asm,auto,catch,const_cast,continue,dynamic_cast,explicit,export,extern,goto,inline,mutable,namespace,operator,private,protected,public,register,reinterpret_cast,static,static_cast,template,throw,try,typedef,typeid,typename,virtual,volatile,wchar_t.
- Compile:
g++ parser.cpp cppparse.cpp -o code2html - Test Execution:
- Created
tests/test_cpp98.cppwith all C++98 keywords. - Ran
./code2html tests/test_cpp98.cpp. - Validated output
tests/test_cpp98.cpp.htmlcontains correct syntax highlighting.
- Created