Compile and Run the Application
Now that the application is fully implemented, it’s time to build and run it to verify that everything works as expected.
We’ll create a dedicated cmake-build directory inside the project root. This is a common and recommended CMake practice: it keeps generated build files separate from your source code and makes the command-line workflow clean and predictable.
Building the Project
Create the build directory and initialize the CMake build system:
$ mkdir cmake-build $ cmake . -B cmake-build ... -- Build files have been written to: ~/htmlstats/cmake-build
CMake configures the project, detects your compiler, and generates all required build files inside
cmake-build.Build the application:
$ cmake --build cmake-build [ 1%] Building CXX object RegEx.cpp.o [ 3%] Building CXX object Compiler.cpp.o ... [100%] Linking CXX executable htmlstats [100%] Built target htmlstats
Once this step completes without errors, the executable is ready to run.
Run the application without arguments:
$ ./cmake-build/htmlstats/htmlstats Usage: ./cmake-build/htmlstats/htmlstats <html-file>
You should see a usage message, confirming that the application starts correctly and expects an HTML file as input.
Retrieving an HTML File
To test the application, you’ll need an HTML file. You can create a small one yourself, but for a quick test it’s easiest to download an existing page using curl or wget.
Download an HTML file:
$ curl https://erbsland.dev > page.html ... or ... $ wget https://erbsland.dev -O page.html
Either command will save the downloaded page as page.html in your current directory.
Run the Application with the HTML File
Now run the application again, this time passing the HTML file as a command-line argument:
$ ./cmake-build/htmlstats/htmlstats page.html
Scanning file
Tag Statistics:
59 div
38 span
29 a
15 meta
(...)
Attribute Statistics:
134 class
17 href
10 rel
7 content
(...)
Success! 🎉 The application scanned the HTML file, counted tags and attributes using the Erbsland Regular Expression Library, and printed the statistics to the console.
From here, you can experiment with different HTML files, adjust the regular expressions, or extend the program with additional analysis logic.