Cweed.exe
Cweed.exe is supplied as
a helpful tool to view and modify files.
It is designed only to modify whitespace.
Obviously, you use it at your own risk!
Download cweed2v2.exe self-extracting zip file.
Download cweed2v2.zip
zip file.
Cweed is a C source file weeder written in Win32Forth.
It
only changes whitespace (formatting) and does not otherwise change the content
of the file. This is analogous to weeding a garden, where the plants are left
untouched but the bits between may be seriously modified.
Cweed
is an experiment in specifying a coding standard in the form of an executable
program.
Cweed V2.2
2007 Dec 11........................................................................................................................... 1
1.1. Files used........................................................................................................................................ 1
1.2. Recompiling Cweed...................................................................................................................... 1
1.3. What Cweed shows you................................................................................................................. 2
1.4. What Cweed changes..................................................................................................................... 3
1.5. Cweed Help.................................................................................................................................... 5
1.6. Cweed options................................................................................................................................ 5
1.7. How Cweed works......................................................................................................................... 6
Cweed uses the following Forth source files :
files.f parses
the C file
menu.f the GUI
user menus
graphics.f some
Windows graphics support
help.f the help
text
Cweed.f the main load file (loads all of the others)
and :
Cweed.bmp the icon
bitmaps
Several
C files are also included to test the program.
Double
click on Win32For.exe to start the
Forth system.
This
needs the files Win32For.img, WinCon.dll and kernel.bin in the same directory.
Type
:
fload
cweed <cr>
The
executable Cweed.exe will be automatically created in the current directory.
Double
click on Cweed.exe to run it, or type
cweed
<cr>
at
the Forth "ok" prompt to run the program.
Shows
the characters in the selected file that most editors hide from you.
Numbers
of the following :
Tabs
( 0x09 )
Linefeeds
( 0x0A )
Pagebreaks
( 0X0C )
Carriage
returns ( 0x0D )
Control
characters ( 0 to 0x1F )
Del
characters ( 0x7F )
Characters
with bit 7 set ( 0x80 to 0xFF )
Shows
formatting features :
Double
slashes // single line C++ comments
Lines
with more than 80 characters
Lines
with only spaces
Lines
with trailing spaces
Two
blank lines in a row
“Floating
pointers” : “char* foo“ instead of
“char *foo”
Shows
the file format type : PC format, Unix format or unspecified.
Warns
if the last line of the file is not correctly terminated with a carriage return
and linefeed (PC format) or linefeed (Unix format).
Warns
if the file has 1000 or more lines.
Gives
a “Pass” or “Fail” summary
Shows
the file with comments. Use the up and down cursor keys, PageUp, PageDown, Home
and End to view the whole file.
Spaces,
carriage returns and tabs are displayed as special characters – this is what is
actually in the file, not a formatted interpretation of it.
Linefeeds
are not shown, as they are implied by a new line.
Files must be less than 16384 lines long, and each line must be less than 252 bytes long – this is to limit the size of the fixed line array that it needs.
Shows the file without comments and without unnecessary whitespace. Use the up and down cursor keys, PageUp, PageDown, Home and End to view the whole file.
All whitespace is reduced to one space (except linefeeds).
All /* ... */ and // comments are ignored.
This is what the C compiler sees.
Shows any lines with indentation errors.
Lines are either within a function’s parameter definition or not – different rules apply to each type.
“Parameter” indentation looks at all lines within the function to determine the correct tab position for the identifiers. Leading ‘*’s are dropped back before the tab position. The entire line is compared to the defined format.
“Normal” indentation uses ‘{‘ , ‘}’ , ‘(‘ and ‘)’ to define the correct indent level, provided these characters are not commented out. The indentation only applies to the first non-space character on the line.
/* ... */ comments have a less restrictive rule that the text must be indented at or beyond the calculated position. This allows “free-form” comments.
Show the number of each character in the file. If there are characters with bit 7 set a prompt is given to press any key to view them.
Clicking on buttons which are not marked “Select file “ or “Show...” will immediately change the selected file.
The cycle is : open file, change it, save it .
There is no query to confirm the overwrite unless the file has been changed by another program.
Click on “Restore” to put back the file originally opened by “Select file”.
If the file is too big, has too many lines or one or more lines that are too big for the internal buffers a warning will be displayed, and no changes will be made to the file. This is to protect zip and exe files etc from being mangled.
Please take a backup before using Cweed to change your file – it is believed to work, but it is a computer program.
Replace all tab characters ( 0x09 ) in the file by the correct number of spaces to align the following text to the next tab position. Each tab position is interpreted as 4 characters - the default value.
This will preserve the formatting for text editors with their tab value set to 4, and will remove all tabs.
Replace all tab characters ( 0x09 ) in the file by the correct number of spaces to align the following text to the next tab position. Each tab position is interpreted as 8 characters.
This will preserve the formatting for text editors with their tab value set to 8, and will remove all tabs. This is useful if the file has been edited using such an editor.
Removes
all trailing spaces (space characters that are between the last non-space
character and the end of the line). These characters have no meaning to C
compilers and just take up space in the file.
Converts
sequences of 2 or more blank lines into a single blank line.
These
extra lines have no meaning to C compilers and just take up space in the file.
Converts
C++ // single line comments to C style .* … *. Comments.
It
does not convert C++ comments that are embedded inside a /* … */ pair.
Note
that the following line, which is usually allowed by compilers :
// /* some doubly commented text */
will be converted
to :
/* /* some doubly commented text */ */
which is usually not
allowed. You must hand edit this yourself…
Replaces
all tabs by the equivalent 4 character tabs.
Removes
all trailing spaces.
Removes
all double blank lines.
Adds
a carriage return and linefeed or linefeed (depending on file format) to the
end of the file if the last line does not have them. Most text editors add
these for you, and most C compilers need them (they ignore the last line in the
file if it is not correctly terminated).
One
click and the file is weeded!
Adjusts
the indentation of each “normal” line and the format of the entire line inside
a function parameter list.
This
is not included in the “Weed” function because it is so complicated that it
cannot be guaranteed to be 100% accurate.
Type
ctrlI to ignore the
“parameter” list formatting errors and thus not try to fix them.
Removes
all carriage returns from the file.
Adds
a carriage return to the end of each line (having first removed all carriage
returns from the file).
Puts back the file originally opened by “Select file”.
There is no query to confirm the overwrite unless the file has been changed by another program.
There is currently one help screen. Click on “Help” to see the help screen.
There
are some control key indentation options listed in the indent help screen.
ctrlE allow an extra space inside a /* ... */
comment block.
Press
again to return to the normal state. Click on “Show indents” to see if the
extra space mode is active.
Default
:
/*
*
*
*/
With
extra space :
/*
*
*
*/
ctrlF
show Full indent details for each line
123 {1} (0) I+ 1 some text here
indicates line 123, {}indent level of 1, () indent level of 0, “normal” Indent state with correct formatting.
The indent level is incremented by one for each ‘{‘ or ‘(‘ and decremented by one for each ‘}’ or ‘)’ (provided these characters are not commented out).
Negative levels are indicated by {-} or (-).
P+ means “parameter” state (within a function parameter list)
I-
or P- means an indentation or formatting error.
The
‘1’ indicates within a /* ... */ comment block.
‘2’
indicates a single line comment ( // ) on this line.
‘|’
neither of the above.
ctrlH
enables the ctrlF full information mode
and displays the output of the line parser for “parameter” state formatting.
ctrlI ignores
all “parameter” state lines. This is useful if the “parameter” state formatter
does not do quite what you would like it to...
The
selected file is copied into the InputBuffer.
A
copy is made when the file is selected so that it can be restored.
The
file is then split up into lines and put into a LineArray buffer which has a
fixed length for each line. Each line has several attributes such as
indentation, comment status and length.
This
allows lines to be accessed by calculation, rather than searching.
A
line is a sequence of characters terminated by a linefeed character.
If
the last character in the line is a carriage return the line attribute is set
accordingly. Carriage returns are not stored in the line data.
Carriage
returns which are not followed by a linefeed are ignored.
A
global variable LineNumber allows LineStartPtr and LineLength to refer to the
current line.
DoLine
takes an execution token and performs that action on every character in the
current line.
DoLines
takes an execution token and performs that action on every line in the current
file.
An
output file buffer accumulates re-formatted lines in sequence, so that they can
be written back to the file.
Howerd
Oakford www.inventio.co.uk
Please give feedback and bug reports to : howerd@inventio.co.uk