The CScan project is provided as open source code. Feel free to use it in your own private or open source projects. Further copyright and license details will be specified when the project is ready for use.
Comments, suggestions, contributions and error reports are welcome (VBDis@aol.com).
uScanC.pas (eventually renamed into uCScan.pas) exports the following:
function ScanFile(const fn: string): TFile;
function nextTokenC: eToken;
function TokenText(const t: RPreToken): string;
function TokenString(fFirst: boolean = False): string;
var
ScanToken: RPreToken;
ScanString: string; //for symbols, string literals...
ScanSym: TSymbol; //for symbols
fVerbose: boolean; //log source lines?
uTokenC.pas defines the preprocessor token record:
type
RPreToken = record
eToken = (<enum>)
eTokenAttrs = (<enum>)
uTables.pas exports:
type
eSymbolKind = (<enum>) //subject to removal
TSymbol = class(TDictEntry)
TSymList = class(TDict)
var
Symbols: TSymList;
StringTable: TStringList;
uFiles.pas exports:
type
TFile = class(TStringList)
TFileList = class(THashList)
var
fIncludeOnlyOnce: boolean; //include files only once?
Files: TFileList;
IncludePath: TStringList;
function AddIncludeDir(dir: string): integer;
uUI.pas contains the GUI interface:
type
eLogKind = (<enum>)
TLog = procedure(const msg: string; kind: eLogKind = lkProgress)
of object;
var
Log: TLog;
Before I forget to mention this, a GUI application ($APPTYPE GUI) has to supply a callback method in the uUI.Log variable. This method will receive all diagnostic output from the scanner. See fScanLog for a possible implementation of such a method.
Specify to the preprocessor the directories, where #included header files shall be searched. These directories later are searched in the order of the calls to AddIncludeDir.
Every path shall end with a '\', but otherwise a backslash is automatically appended. Even '/' can be used for directory separators, because all file names are internally unified to lower case and '\' separators.
There exist several token classes, which you'll have to treat differently. The simple cases are:
Some of the remaining token kinds are used internally by the scanner/preprocessor. You may have to recognize the following token kinds:
The related declarations may be moved into the uTokenC unit in the next version...
The wintest.c file contains some #defines which are required to process windows.h. These and other symbols normally are provided by the C compiler, but since CScan is not a compiler you may want to use your own standard root files. In a future CScan version it shall be possible to specify the search directories and other settings by a #pragma, then all adaptations can be made in the root file(s), without recompiling the applications. Then the root file can be used like an INI or Make file, with the option to #include further files with commonly used settings. Yes, I'm too lazy to implement command line argument handling myself ;-)
I hope that some last-minute changes don't cause trouble...
The next project is the implementation of an data type converter, from C to Pascal/Delphi. This project now has become part of WinScan, the FlexScan project was not updated accordingly. During the development of this project some more missing features will be implemented in the scanner, making it a really usable library package. I plan to only implement a very rudimentary framework around the scanner myself, just sufficient to debug the scanner. Feel free to contribute your own more elaborated framework, with a handler for command line switches or options dialogs etc.
My final project will be a C to Pascal cross compiler, which may require the addition of some more features to the scanner. This cross compiler can be extended with back-ends for other languages or compilers, and possibly with front-ends for languages other than C. But I don't plan to implement such extensions myself, please contact me if you want to implement such extensions yourself, so that I can provide the according documentation and assistance. I could imagine that the Delphi back-end can be extended into back-end for Borland Pascal, FreePascal or VisualPascal, and I'm willing to coordinate all further development in these directions.
DoDi
(Dr. H.-P. Diettrich, February 2004)