User:ConradPino/White Space Problem

From Project JEDI Wiki
Jump to navigationJump to search

Problem Statement

The Delphi IDE editor is sloppy about trailing white space whereas TextPad is not and TextPad has file search features Delphi 6 does not.

Everytime I edit a Project JEDI source file TextPad cleans up white space that adds to svn diff output adding to change verification labor.

ChristianWimmer 15:55, 1 February 2010 (UTC):

The whitespace and tab problem is a problem that will always exist because Delphi doesn't care and there is no easy way to prevent it.
Conrad has written an application that can solve this problem. However, the application contains static paths and cannot be changed easily for different situations (e.g. only *.inc files in several directories)

Proposed Solution

Remove extraneous white space from all source files with an automated process.

ChristianWimmer 15:55, 1 February 2010 (UTC):

Thus I have the following suggestion:
1. The application JEDIedit should get command line parameters that define :
a) file locations (separated by semiclon) and include sub folders
b) make a backup (*.bck)
c) type of files (e.g. *.pas;*.inc)
d) prompt on replace file
2. Add a help to show the commands and how to use
This application removes all unnecessary tabs and trailing whitespaces.
Copyright 2010 (c) JEDI API, written by Conrad ...

Usage:
JEDIedit [/ext "extension[;extension]"] [/b] [/d] [/y] [files[ paths]]

Parameters:
 files - A list of files that should be processed. (Files or folders that contains spaces must be enclosed with quotation marks) 
 paths - A list of paths that should be processed. (Files or folders that contains spaces must be enclosed with quotation marks)
 /ext  - A semicolon separated list of extensions that should be used to find files in given paths.
         Use quotation marks (") on this parameter if there are spaces in an extension.
 /b    - Creates backup files for each replaced file (<name>001.bck)
 /d    - Iterates through all sub folders of the given paths.
 /y    - The application prompts on each file that is changed. This parameter automatically picks yes (process file).

Examples
  JEDIedit /ext *.pas;*.inc /d ".\source JEDI\JwaWindows.pas" .\tools\source
    This command processes JwaWindows.pas and all pas and inc files in the folder .\tools\source and its children.
In this way we can provide an exe file that is called by a batch file. Such batch files are located in the different JEDI folders and thus it would be easy to adapt or change. Furthermore people just call this batch file before they commit changes (I think this can be done automatically with SVN on client side).
Developer annotations:
  • [files[ paths]] In fact this parameter is a parameter that is recognized as several parameters by Delphi. Since a whitespace separates these parameters they are all recognized as files or paths. No other parameter (like /ext, /b) can be used.
  • [*.pas;*.inc] I think this format can be put into FindFirst. I don't remember though. Of course it can be adapted so it would be easier to program.

Add Comments There

Comments moved to talk page.

program JEDIedit

JEDIedit Subversion Repository

JEDIedit Help

The command "JEDIedit --help" displays:

Greetings Earthling! Take me to your Leader.

JEDIedit (option|file|directory)*

   --backup-file           Enables file backups, for example:
   -b                      file Unit.pas becomes Unit.~pas and
   /b                      modfied file content becomes Unit.pas.

   --directories           Enables fully recursive directory search.
   -d
   /d

   --extensions exts       File extensions to select where "exts" can be:
   -e exts                     pas
   /e exts                     dpr,inc,pas
                               "pas"
                               "dpr,inc,pas"

   --ini-file filename     Reads INI filename instead of JEDIedit.ini and
   -i filename             may be used alone or combined with --ini-section.
   /i filename

   --ini-section thisone   Reads INI section thisone instead of Default and
   -j thisone              may be used alone or combined with --ini-file.
   /j thisone

   --root-paths pathlist   Replace INI file RootPaths value where pathlist is
   -r pathlist             comma seperated possibly enclosed in double quotes
   /r pathlist             and one path is sufficient.  This value is ignored
                           when file or directories appear on command line.

   --tab-replace           Enables Tab Replacement feature.
   -t+
   /t+
   -t
   /t

   --no-tab-replace        Disables Tab Replacement feature.
   -t-
   /t-

   --tab-report            Enables Tab Reporting feature.
   -u+
   /u+
   -u
   /u

   --no-tab-report         Disables Tab Reporting feature.
   -t-
   /t-

   --tab-spacing number    Tab Replacement feature spaces tabbed text number
   -v number               columns apart.
   /v number

   --yes-prompt            Prompt for yes confirmation prior to saving changed
   -y                      files; pressing Enter key alone or any text begining
   /y                      with letter Y or y followed by Enter key saves changes.

   --help                  Display this help message.
   -?
   /?

JEDIedit Features

JEDIedit implements the following features.

Extra White Space Removal

White space is removed from the following locations:

  • every line: spaces and control charcters (including tabs, form feeds, etc.) after last printable character
  • begin of file: blank lines until first non-blank line
  • end of file: blank lines until last non-blank line

Tab Replacement

Tab Replacement is optional and enabled by default. This feature replaces all signficant tabs with spaces while preserving vertical character alignment. Trailing tabs are discarded during Extra White Space Removal.

Tab Replacement depends upon the TabReplace and TabSpacing configuration values (see below).

Tab Reporting

Tab reporting is optional and disabled by default. Tab Reporting runs when Tab Replacement is disabled.

Tab Reporting depends upon the TabReplace and TabSpacing configuration values (see below).

Changed File Backups

When enabled from the command line the orginal file renamed in place.

Changed File Save Prompting

When enabled from the command line JEDIedit prompts the user to confirm saving the changed file.

JEDIedit Configuration

JEDIedit.ini Or Custom INI File

Upon the first run JEDIedit write these defaults to JEDIedit.ini or the Custom INI File specified by the "--ini-file Custom.ini" command line option:

[Default]
RootPaths="..\jedi-apilib","..\..\..\..\..\jedi-apilib"
Extensions="dpr","inc","pas"
Includes="jwapi\trunk","jwscl\trunk"
Excludes="jwapi\trunk\Examples","jwscl\trunk\examples","jwscl\trunk\unittests"
SkipDirs="CVS",".svn"
TabReplace=1
TabReports=0
TabSpacing=2

JEDIedit.ini Or Custom INI File Sections

JEDIedit support just one default section JEDIedit.ini or Custom INI File named Default.

The "--ini-section" command line option supports an arbitray number beyond the default; by example:

--ini-section SectionNameNoSpaces
--ini-section "Section Name With Spaces"

File Selection Configuration

The File Selection Configuration values are quoted, comma delimited lists used to build FileList The resultant FileList is used to apply all supported features.

File Selection From INI File

An INI File may perform File Section as follows:

Key Name Description
RootPaths Search RootPaths in listed order until first directory is found which then becomes the RootPath. When no RootPaths values exist then FileList shall be empty.
Includes Specifies subdirectories relative to RootPath to be searched. When no Includes subdirectory values exist then FileList shall be empty.
Excludes Specifies subdirectories relative to RootPath to be ignored. When no Excludes subdirectory values exist then FileList shall be unchanged.
Extensions Specifies file extensions to process; all other file extensions are removed from FileList. The blank file extension may work but is untested.
SkipDirs Specifies subdirectory names to skip during directory enumeration; a convenience for skipping revision control software data directories and similar uses. SkipDirs are ignored at all directory depths.
File Selection From Command Line

The following File Selection Command Line Options are implemented:

Option Aliases Description
--ini-file Custom.ini -i /i Default JEDIedit.ini file is replaced by Custom.ini file.
--ini-section CustomSection -j /j The default or specified INI File section read shall be [Custom Section] instead of [Default].
--root-paths jwapi\trunk -r /r Shall replace the INI FIle RootPaths value.
--extensions dpr,pas,txt -e /e Shall replace the INI FIle Extensions value.
Unit1.pas Unit2.pas ReadMe.txt Shall be the FileList; INI File values RootPaths Includes Excludes shall be ignored. The default or specified file extensions shall be ignored.
Directory1 Directory2 Directory3 Specified directories shall be enumerated to build FileList; INI File values RootPaths Includes Excludes shall be ignored. The default or specified file extensions shall apply.
Directory1 File1 DirectoryN FileN FileList shall be the union of the specified files and enumerated directories. The file and directory rules specified above shall apply respectively.
--directories -d /d Specifies recursive directory enumeration.

Tab Replacement Configuration

Tab Replacement Control From INI File

The Tab Replacement Configuration values are integers as follows:

Key Name Description
TabReplace Enables or disables this feature. Valid values are 1 (enabled) and 0 (disabled). The first run defaults this value to enabled.
TabSpacing Specifies the tab stop spacing when this feature is enabled. Valid values are positive integers greater than zero. The first run defaults this value to two (2).
Tab Replacement Control Command Line

The following Tab Replacement Command Line Options are implemented:

Option Aliases Description
--tab-replace -t+ /t+ -t /t Enables this feature.
--no-tab-replace -t- /t- Disables this feature.
--tab-spacing number -v /v Specifies the tab stop spacing when this feature is enabled.

Tab Reporting Configuration

Tab Reporting Control From INI File

The Tab Reporting Configuration value is an integer as follows:

Key Name Description
TabReports Enables or disables this feature. Valid values are 1 (enabled) and 0 (disabled). The first run defaults this value to disabled.
Tab Reporting Control Command Line

The following Tab Reporting Command Line Options are implemented:

Option Aliases Description
--tab-report -u+ /u+ -u /u Enables this feature.
--no-tab-report -u- /u- Disables this feature.

Test Cases

Compiling Tests

Which compiling test cases are sufficient?

Regression Tests

Since Subversion can prove there are no semantic changes, are regression tests necessary?

ChristianWimmer 18:08, 1 February 2010 (UTC):

A basic recompilation of the JEDI API packages are sufficient. If this works it should be fine.
There is no way to test all functions though.

Conrad T. Pino 18:46, 1 February 2010 (UTC):

I can't complete recompilation without hacking the code, remember TStringList.OwnsObjects thread?
See program JEDIcomp Revision 875.
ChristianWimmer 22:18, 3 February 2010 (UTC) Just ignore JwsclPathSimulation. I also have removed Ownsobject from JwsclKnownSids. So it should work fine.

Subversion Proof

svn diff -x -w ignores almost all white space differences.