CommExtract - Release Notes


Copyright 2024 by The Software Samurai.
On the web: http://www.SoftwareSam.us/
Software released under GNU GPL3, and documentation released under FDL1.3
This document describes version 0.0.02 of CommExtract.


Description

Description: Extract C++ comment lines from a source file, then remove the comment token (//) and leading/trailing whitespace, to create plain text which can then be inserted into the documentation for that project. The author has found this to be a useful tool, in that his development style for a new project is to write the comments first. The code is then written to implement the project described in those comments. This is ALSO the approach all of our students are encouraged to use for their class projects. The practical result of this approach is that the project documentation essentially writes itself. This is done by copying the bulk of the source code comments to a ReadMe file or to a Texinfo documentation file. However, it is rather tedious to manually remove the C++ comment tokens, so this simple utility performs that task automagically.

This application was designed under Fedora Linux and is built using the GNU C compiler,
version 13.3.1 or higher (C++11 support required).
If you are not using GCC, then verify that your compiler fully supports the C++11 standard.


Building From Source



Operational Overview

The CommExtract application is controlled via command-line options. No direct user interaction is required.

Output is written to the specified target file, and may optionally be echoed to the terminal window.

This application relies on our gString text-analysis tool for parsing the source data and reformatting the data for output. For a full discussion of the gString class, please see the documentation for the author's NcDialog API package, or the stand-alone gString text-analysis-and-formatting package. gString Documentation


Command-line Options

Invocation:    comex ––src=NAME ––beg=n [––end=n | ––cnt=n] [OPTIONS]




Notes on the current release of “CommExtract”

  1. Because this is a smelly old hack and not a production-worthy application, we assume that the user IS the owner of the source and target files and of the directory in which they live. This simplifies the access-validation process. For a more robust validatation of file access, see our FileMangler application.
  2. It is expected (but not enforced) that source and target files are in the current working directory (CWD). It would be rather dangerous to create and/or truncate a target file at some random position in the filesystem.
               Beware!
  3. The actual reformatting of the text data is handled by the gString class. The gString source included in this package is also available as a stand-alone package and well as being integrated into our NcDialog API library. Please see: gString Documentation
  4. If the source data contains ASCII Tab characters (0x09): first, don't ever use tabs in source code, and second, the columns of the output will be misaligned. Sorry about that :)
  5. Terminal Configuration:
    1. The width of the I/O streams are set the first time they are used. The wide input/output streams are accessed through the ‘wcin’ and ‘wcout’ classes, respectively. The narrow input/output streams are accessed through the ‘cin’ and ‘cout’ classes, respectively. Narrow streams are not used in this application.
      (Editorial: No application written in the current century should use narrow-stream I/O.)
    2. The terminal's “locale” determines the character encoding used, and the primary language expected. This determines the way the terminal will handle certain text formatting — for instance, currency symbols and number formats. It is important to understand that if the application does not explicitly set the desired locale, the so-called “C-locale” is used. The C-locale restricts the character set to an ASCII superset (7-8-bit characters), and is unacceptable for any serious application. Besides, it is so easy to implement that it can be added to any application in under five minutes. See the setLocale method for details.
  6. The file ‘create_archive.pl’ is included in this package only as an example of using Perl to perform file-management chores. Your humble author is certainly no expert in the Perl language, but the code provides examples for some simple constructs. ‘create_archive.pl’ is used during the development process to verify the state of conditional-compilation declarations, to extract the application version number and to create the distribution archive.
  7. Data Processing Logic:
    For each source line in the specified range:
    1. Scan over leading whitespace. If first non-whitespace characters are not  “//” , skip the line.
    2. If first non-whitespace is  “//” , i.e. a C++ comment:
      1. If “//” is followed by ‘*’, include it in sequence to be deleted.
      2. If “//” or “//*” is followed by a space, include it in sequence to be deleted, (2, 3 or 4 characters, total).
    3. If the line ends with a trailing ‘*’, remove it.
    4. Strip whitespace:
      1. If the ‘wspAll’ flag is set, strip both leading and trailing whitespace.
      2. Else, strip trailing whitespace only. (maintains vertical column alignment)
    5. Append a single space to the end of the line.
    6. Write the reformatted text to the output file.
  8. Note: The application change log is located in the header of “CommExtract.cpp”.


  These notes are adapted from the “README” file included with the application archive.
  Thank you, and we hope you enjoy using this application!  — Software Sam