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!

(* except the Block to File conversion)

 

Cweed V4.1   2012 Mar 13 Now with support for C++, Lint and with Folder Scan, and works under Windows7! And NumName human readable hash values…

 

Download cweed4v1.exe self-extracting zip file.

 

Download cweed4v1.zip zip file.

 

New in V4.1

Minor bug fixes in Folder Report and new NumName.txt file “monsoons-megabyte”

New in V4.0

Fixed lack of update when the Cweed window is covered, added NumName text feature to give the file MD5 hash a human readable form – see NumName.f for details.The NumName.txt file list of words is now precompiled.

New in V3.4

Fixed lack of update when the Cweed window is covered, added NumName text feature to give the file MD5 hash a human readable form – see NumName.f for details.

New in V3.3

Added Windows7 support in the Win32Forth supplied in the Cweed package, also made the window re-paint after it is covered by another window.

New in V3.2

Fix to non comment block lines being indented if they start with a ‘*’.

Folder report added – select a file, then click on Show Folder to perform a scan of all C, C++ and header files in the containing folder.

V3.21 fixes a bug in the number of tabs reported in Show Folder

 

New in V3.1

Lint report shows numbers of “//lint –save” and “//lint –restore”  strings in the file.

Also checks for “-e” after a “–restore” and a one or more spaces between the “//” and “lint”.

 

New in V3.0

Bug fixes to namespace indentation.

Adding 2-space indentation for public: , private: and protected: .

Adding CRC32 and MD5 values for the file.

Block comments indented by one space.

Configuration options are now at the top of file Cweed.f .

 

 

Cweed V4.1   2011 Mar 13

 

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 V4.1   2011 Mar 13.................................................................................................................................... 1

1.1.     Files used.................................................................................................................................................. 1

1.2.     Recompiling Cweed............................................................................................................................... 1

1.3.     What Cweed shows you........................................................................................................................ 2

1.4.     What Cweed changes............................................................................................................................ 4

1.5.     Cweed Help............................................................................................................................................. 6

1.6.     Cweed options......................................................................................................................................... 6

1.7.     How Cweed works.................................................................................................................................. 7

1.8.     New in V2.3............................................................................................................................................. 8

1.9.     New in V2.4............................................................................................................................................. 8

1.10.       New in V3.0......................................................................................................................................... 8

1.11.       New in V3.1......................................................................................................................................... 8

1.12.       New in V3.2......................................................................................................................................... 8

1.13.       New in V3.3......................................................................................................................................... 8

1.14.       New in V4.0......................................................................................................................................... 8

1.1.     New in V4.1............................................................................................................................................. 8

 

1.1.      Files used

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.

 

1.2.      Recompiling Cweed

 

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.

 

Configration options are at the start of the file Cweed.f .

 

1.3.      What Cweed shows you

 

1.3.1.   Show info

 

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”

Lint Saves/Restores  shows numbers of “//lint –save” and “//lint –restore”  strings in the file.

If there is an error, shows a line number and

a) if there is an “-e” after a “–restore”

b) if there are one or more spaces between the “//” and “lint”.

c) shows if the order of save/restore is wrong (lint stack underflow)

 

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.

 

Hexadecimal Sum of the characters in the file.

 

Hexadecimal CRC32 of the file as per

 [ISO-3309]

 International Organization for Standardization,

 "Information Processing Systems--Data Communication High-Level Data Link

  Control Procedure--Frame Structure", IS 3309, October 1984, 3rd Edition.

 

MD5 hash of the file.

 

Gives a “Pass” or “Fail” summary for characters in the file, file size and line length.

 

Gives a summary of indentation errors, or ‘pass’ if none.

 

1.3.2.   Show file +

 

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.

1.3.3.   Show file -

 

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.

 

1.3.4.   Show indents

 

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 can have a less restrictive rule that the text must be indented at or beyond the calculated position. This allows “free-form” comments. See Files.f : IndentOK?  AllowGreaterThan ;

1.3.5.   Show #

 

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.

 

1.4.      What Cweed changes

 

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.

 

1.4.1.   Replace tabs : 4

 

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.

 

1.4.2.   Replace tabs : 8

 

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.

1.4.3.   -Trailing

 

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.

1.4.4.   -2 Blanks

 

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.

1.4.5.   // to /*  */

 

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…

 

1.4.6.   Weed

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!

1.4.7.   Fix indents

 

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.

1.4.8.   PC->Unix

 

Removes all carriage returns from the file.

 

1.4.9.   Unix->PC

 

Adds a carriage return to the end of each line (having first removed all carriage returns from the file).

1.4.10.Restore

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.

1.5.       Cweed Help

There is currently one help screen. Click on “Help” to see the help screen.

1.6.      Cweed options

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) /*- c- d- s- I-+ GC 0 NS 4 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 (-).

For the following a ‘+’ means active, a ‘-‘ means not active or not found

/*- means this line is not within a /* … */ comment block

c-  means this line has ‘case’ as its first word

d-  means this line has ‘#define’ as its first word

s- means this line has a class specifier ( public:, private: or protected: ) as its first word.

I- means an indentation or formatting error. ( I+ means no error )

 

GC x  indicates a GetCurrentIndent value of x ( in characters)

NS x  indicates a NameSpace Indent value of x ( in characters)

 

The ‘1’ indicates within a /* ... */ comment block.

‘2’ indicates a single line comment ( // ) on this line.

‘|’ neither of the above.

 

1.7.      How Cweed works

 

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.

 

1.8.      New in V2.3

Added BlocksToFile conversion function : if you open an old-style Forth block file (with 64 character lines) Cweed will not be able to copy the file into its line buffer. Press ‘ctrlR’ and click on OK to add a CRLF pair after every 64 characters and save this as your-original-filename.f .

 

1.9.      New in V2.4

Changed the file filter from “*.c” to “*.c*” which then includes C++ source files.

Modified the “Fix Indents” function to not indent a ‘{‘ when the keyword “namespace” appears at the start of a line. This is to save whitespace at the start of every program line if a C++ namespace is used.

Also tidied up the “Show Indents” function – it now checks for brackets on the last line of the file.

1.10.  New in V3.0

Bug fixes to namespace indentation.

Adding 2-space indentation for public: , private: and protected: .

Adding CRC32 and MD5 values for the file.

Block comments indented by one space.

Configuration options are now at the top of file Cweed.f .

1.11.  New in V3.1

Lint report shows numbers of “//lint –save” and “//lint –restore”  strings in the file. Also checks for “-e” after a “–restore” and a one or more spaces between the “//” and “lint”.

1.12.  New in V3.2

Fix to non comment block lines being indented if they start with a ‘*’.

Folder report added – select a file, then click on Show Folder to perform a scan of all C, C++ and header files in the containing folder.

1.13.  New in V3.3

Added Windows7 support in the Win32Forth supplied in the Cweed package, also made the window re-paint after it is covered by another window.

1.14.  New in V4.0

Fixed lack of update when the Cweed window is covered, added NumName text feature to give the file MD5 hash a human readable form – see NumName.f for details.The NumName.txt file list of words is now precompiled.

1.1.      New in V4.1

Minor bug fixes in Folder Report and new NumName.txt file “monsoons-megabyte”

 

 

 

 

 

Howerd Oakford                                                                    www.inventio.co.uk