Wildfilew.vdm macro

Wildfilew.vdm
Multi file processing macro

Wildfilew.vdm macro lets you to perform search, search and replace or run a command or another macro on large number of files.

For details on using Wildfilew, see the following topics:

General:
Multi file processing
User interface:
Fields common to all main dialogs
Additional fields in Full Dialog
Search dialog
Replace dialog
Command dialog
Macro dialog
Options dialog
Advanced:
Starting Wildfilew.vdm
Creating Wildfile aware macros


Wildfilew - Multi File Processing

Multi file processing

WILDFILE is probably the most useful macro supplied with VEDIT. It lets you perform a search, search and replace or run a command or another macro on an entire group of files. The group of files may be specified using the wildcards "?" and "*". These files will be searched in any desired directory and, optionally, in all subdirectories. The primary use of WILDFILE is to search for all occurrences of a word (variable name, etc.) in a large group of files. For example, you might want to view all occurrences of the word "printf" in all the ".C" files.

Since VEDIT can edit any file, including binary files such as ".EXE" executables, you can search through all files in a directory by specifying "*.*" without worrying about what kind of files they are. "*.*" will also search any "hidden" files.

WILDFILE can also perform global replacements on many files. For example, you might have misspelled "parallel" as "parralel" in a group of ".TXT" files.

WILDFILE can also run a second macro on a group of files. For example, the PRINT.VDM macro could be run on all of your ".TXT" files.

Wildfilew.vdm is GUI (graphical user interface) version of WILDFILE. Another versioin, wildfile.vdm, prompts for all parameters with a DOS-like command lines.

Notes:

  • The files specified for processing with WILDFILE can include any files that are already open in VEDIT. This way you can perform an operation, such as searching through many files, without having to worry about which files are currently open for editing.
  • All files on the entire drive can be processed with "c:\*.*". (It may take several minutes to process this command, and many minutes to scan all files.)

Using Wildfilew.vdm

To start Wildfilew.vdm, select "Wildfile wizard" from "Misc" menu, or click the toolbar button Run Wildfile.

When Wildfilew.vdm is started, Search dialog is opened by default. Optionally, you can configure Wildfilew to remember the dialog that was last used, see "Options".

For description of each field in the dialog, see the links below.

Fields common to all main dialogs
Additional fields in Full Dialog
Search dialog


Fields common to all main dialogs

The following fields and controls are common to all main dialogs (Search, Replace, Command and Macro):

Fields common to all dialogs

Search dialog, 'Simple Dialogs' version.
Fields common to all main dialogs are marked here
with red border.

The following fields and buttons are the same in Search, Replace, Command and Macro dialogs:

Files:
Enter filenames or filters (with wildcards) here. Multiple filenames or filters can be entered by separating them with commas. You can enter absolute path, or relative path (relative to the directory in Directory field below), but normally you would just enter filenames or filters.
If Files field is empty, the search or other operation is done on current file only.
Directory:
The base directory for filenames and relative paths above. You can change the directory by editing this field, or visually by clicking on the Browse button.
- Click to change directory (see above). Then navigate to the directory you want and click OK.
Search subdirectories
- Check this box to search specified files in all subdirectories of the specified directories.
- Click this button to start executing the operation.
- Cancel operation and exit macro.
- Expand dialog to include more options (Full dialog). The button turns into [Less <<] button. Click [Less <<] button to remove the extra buttons (simple dialog).

Related topics:

Additional fields in Full Dialog
Search dialog
Wildfile - Multi file processing


Additional fields in Full Dialog

Extra fields in full dialogs

Additional fields in Full Dialogs are marked here
with red border.

These buttons are added to the bottom of Seach, Replace, Command or Macro dialog when full dialog is displayed. To show full dialog, click [More >>] button. If you select Full Dialog option in the Options, full dialog is displayed by default when you start Wildfile.

- Displays/closes search results (search.tmp). If the file is not already open, it is opened. If it is open but not on top, it is moved on top. If it is already on top, it is closed.
- Opens Wildfilew optioins dialog.
- Displays help for Wildfilew

Buttons in the bottom row:

- Selects dialog for "Search" operation
- Selects dialog for "Search and Replace" operation
- Selects dialog for "Command" operation (enter direct command to execute for each file)
- Selects dialog for "Macro" operation (execute a macro for each file)

Related topics:

Search dialog
Replace dialog
Fields common to all main dialogs


Search dialog

These fields and options are available in the Seach dialog (in addition to the common options):

Search dialog, 'Simple Dialogs' version.

Search:
String or pattern to be searched. - If a block is highlighted, it is used as search string.
- If no block highlighted, this field may be initially empty or it may contain previous string used by wildfilew, or previous string used in any search (current search string). This can be selected from the options dialog.
- If you leave this field empty, previous search string is used.
Case sensitive
- check this box for case sensitive search (upper case and lower case characters are considered different characters).
Word
- check this to search whole words only.
Skip comments
- check this to ignore search strings that occur inside comments. Currently only recognizes C and C++ comments (although thes works with many other languages, too, for example Java and Vedit macros.)
Search mode:
Simple | - Silmple string search, no codes
Pattern | - Use Vedit pattern matching codes
Regular Expressions | - Use Regular Expressions, minimal length
Reg Exp (Max) | - Use Regular Expressions, maximal length
Display matched lines as:
Visual / edit | - When occurrence found, go to edit mode. Press Visual Exit to continue search.
List with filenames | - Create list of search results with filenames and line numbers.
Extract w/o filenames | - Create list of lines containing searched string. No filenames or line numbers included.
List filenames only; | - List names of filens that contain the search string.
- Click this button to go to Search & Replace dialog box. Any options you have entered so far will be retained.
- Expand dialog into Full Dialog. For additional options available in full dialog, see Additional fields in Full Dialog.

Search results

If you select "List with filenames" in "Display matched lines as" section, Wildfilew.vdm creates file search.tmp for the search results. The file is opened in an edit window. The file displays full pathname of each file where the search string was found, followed by all the lines where the string was found.

Double-click on the line in this listing. This opens the corresponding file and moves cursor to the line where the string was found.

You can save search.tmp with different filename if you want to keep the search results for later use. This way you can have multiple search results in different windows.

Note: Wildfilew.vdm creates a double-click event macro if you do not have one already loaded. If you do already have a double-click event macro loaded, it is not overwritten. If you want to replace your old event macro with the one created by Wildfilew.vdm, you must manually empty text register 116 before running Wildfilew.

Related topics:

Replace dialog
Fields common to all main dialogs
Additional fields in Full Dialog


Replace dialog

These fields and options are available in the Replace dialog (in addition to the common options):

Replace dialog, 'Simple Dialogs' version.

Search:
String or pattern to be searched. - If a block is highlighted, it is used as search string.
- If no block highlighted, this field may be initially empty or it may contain previous string used by wildfilew, or previous string used in any search (current search string). This can be selected from the options dialog.
- If you leave this field empty, previous search string is used.
Replace:
String or pattern that replaces the searched string. - This field may be initially empty or it may contain previous string used by wildfilew, or previous string used in any replace (current replace string). This can be selected from the options dialog.
- If you leave this field empty, the searched string is replaced with nothing.
Case sensitive
- check this box for case sensitive search.
Word
- check this to search whole words only.
Skip comments
- check this to ignore search strings that occur inside comments. Currently only recognizes C and C++ comments (although these work with many other languages, too, for example Java and Vedit macros.)
Search mode:
Simple | - Silmple string search, no codes
Pattern | - Use Vedit pattern matching codes
Regular Expressions | - Use Regular Expressions, minimal length
Reg Exp (Max) | - Use Regular Expressions, maximal length
Display matched lines as:
Confirm each replace | - When occurrence found, the location is displayed and user is prompted for options (see below).
List with filenames | - Create list of search results (after each replace done) with filenames and line numbers.
- Click this button to go back to Search dialog box. Any options you have entered so far will be retained.
- Expand dialog into Full Dialog. For additional options available in full dialog, see Additional fields in Full Dialog.

Confirm each replace

Assuming you selected "Confirm each replace" option, VEDIT will start searching the files until it finds the first occurrence of the search string. Similar to the {SEARCH, Replace} function, it will then highlight the text and prompt with Replace options.

Replace prompt
Replace this occurrence and search for the next occurrence showing the Replace options again.
Don't replace this occurrence; search for the next occurrence showing the Replace options again. You can selectively make some replacements skipping others.
Replace this occurrence and all remaining occurrences without any additional prompts.
Replace this occurrence and then cancel the process.
Enter Visual Mode in which you can make any desired editing changes. The bottom of the screen will prompt you to press to search for the next occurrence or to cancel the process.
Don't replace this occurrence; cancel the process.
NOTE: We highly suggest making a few selective replacements before selecting [All] for a global replacement. Otherwise, a mistakenly entered search or replace string could corrupt many, many files.

Related topics:

Command dialog
Search dialog
Fields common to all main dialogs
Additional fields in Full Dialog


Command dialog

Command dialog opens when you click Command button on the bottom row of any Full Dialog. This option allows you to execute a macro command sequenc once for each file specified.

These fields and options are available in the Command dialog (in addition to the common options):

Command dialog, 'Simple Dialogs' version.

Open as read-only
- The file is opened in read-only mode. Speeds up the operation somewhat, and protects file from accidental changes.
Enter your command sequence in the 3rd text box (below "Enter single line Vedit command sequence...")
You may enter one or more Vedit macro language commands, separated with spaces. Wildfile then executes this command sequence on each file.
Pause after each screenful.
- If your command displays something and you have selected many files, the text might scroll out of display before you can read it. If you chec this checkbox, the display is stopped after each screenful of text and you are prompted to continue execution.

Related topics:

Macro dialog
Fields common to all main dialogs
Additional fields in Full Dialog


Macro dialog

Macro dialog opens when you click Macro button on the bottom row of any Full Dialog. This option allows you to run any Vedit macro once for each file specified.

These fields and options are available in the Macro dialog (in addition to the common options):

Macro dialog, 'Simple Dialogs' version.

Open as read-only
- The file is opened in read-only mode. Speeds up the operation somewhat, and protects file from accidental changes.
Macro file:
- Enter full path to the macro to be executed on each file. Alternatively, you can use the "Browse" button.
Browse
- Click this button to interactively browse for the macro to be executed.
Pause after each screenful.
- If your command displays something and you have selected many files, the text might scroll out of display before you can read it. If you chec this checkbox, the display is stopped after each screenful of text and you are prompted to continue execution.

Related topics:

Options dialog
Command dialog
Fields common to all main dialogs
Additional fields in Full Dialog


Options dialog

Options dialog opens when you click Options button on any Full Dialog. Here you can set options and default values to control the operation of Wildfilew.vdm macro.

Options dialog

Start Wildfilew at:
Select which dialog opens initially when you start Wildfilew.vdm.
Default dialog type:
Select if the initial dialog is Simple or Full dialog. (However, you can switch between Simple and Full dialog at any time by clicking "More >>" and "<< Less" buttons on each dialog.)
Simple dialog contains the options you would normally need to perform the operation.
Full Dialog has some additional buttons for selecting advanced operations (command, macro), help etc.
Default directory:
Selects which directory is filled in the "Directory" field initially when you start Wildfilew.
  • Current Directory is the value remembered by Windows. On Vedit, you can change current directory e.g. by checking "Change directory" tickbox in the File Open dialog box.
  • Current File's directory is the directory where the file in currently active edit window is located. This is ofthen the most convenient option, and it allows to easily change the initial directory by switching to appropriate file in Vedit before calling Wildfilew.
  • Last used by Wildfile: this option defaults to the directory you had chosen in the previous run of Wildfilew.
Default search/replace strings:
Selects which directory is filled in the "Search" and "Replace" fields initially when you start Wildfilew. However, if a block is highlighted, it is used as default "Search" string regardless of this setting.
  • Empty- the fields are empty
  • Current search/replace strings- Last strings used either in Wildfilew or in normal search operation
  • Last used by Wildfilew- Remembers your last strings used in Wildfile
Default search options:
Selects the initial settings for the option tickboxes and radio buttons in "Search" and "Replace" dialogs.
  • Config settings are the default Search options settings you have selected in Config menu.
  • Last used by Wildfilew remembers your last selections.

Save selected options and to return to previous dialog.
Discard any changes and return to previous dialog.
Show this help page.

Related topics:

Wildfile - Multi file processing


Starting Wildfilew.vdm

Normal call

You can call Wildfilew.vdm with menu command "Misc" → "Load/exec user macro",
or by adding the following command User menu:

  Call_File(100,"wildfilew.vdm")

Wildfilew.vdm then starts and reads default settings from file wildfilw.ini in the Vedit USER-MAC directory. These settings define the options (which dialog to show by default, which directory to use by default etc.), and it also stores the values you have entered in each input field to be used as default on the next run.

After executing, Wildfilew.vdm stores the options and imput values to wildfilw.ini again.

Choosing the .ini file

By default, the wildfilw.ini file is load from Vedit USER-MAC directory. However, you may select different .ini file when calling Wildfilew.vdm.

Put the name of the file in text register 40 and then call label "set_ini".
Or call label "read_ini" if you want not to save the changes in .ini file.

(Note: normally the .ini file is always saved, overwriting the old file, so you will lose any comments you may have in the file.)

Example:
RS(40,"mywf.ini") Call_File(100,"wildfilew.vdm","set_ini")

This is mainly intented for calling wildfilew.vdm from command line or .bat file, but you can for example put the commands in User menu so that you can have different settings for some special purpose.

Calling Wildfilew.vdm from .BAT file

You can call Wildfilew.vdm from a .BAT file to automate your tasks.

Create a dedicated .ini file that selects the operation to perform and input values to be used (for example, "mywf.ini"). Then choose this file as .ini file when calling wildfilew.vdm from a .bat file.

If you have setting opt_dialog=0 in the .ini file, the dialog boxes are not displayed and wildfilew.vdm is executed without user intervention.

Example of command line in .bat file:
c:\vedit\vpw -c'RS(40,"mywf.ini") Call_File(100, "wildfilew.vdm", "read_ini")'

Related topics:

Wildfile - Multi file processing


Creating Wildfilew aware macros

Most of Vedit macros can be called from Wildfilew.vdm. However, making your macros wildfile aware gives you more possibilities. Here is some technical information about Wildfilew.vdm.

Register usage

Numeric registers

Wildfilew.vdm uses numeric registers #41 to #97. Wildfilew pushes these register in stack before calling user macro. These registers can be used by user macro, but their values are not retainet on successive calls of user macro.

Registers #0 to #39 are not used by Wildfilew. These registers can be used by user macro to pass information between successive calls.

Some registers have special meaning and can be used in user macro:
#60 - contains number of files to be processed.
#61 - buffer that contains search.tmp (for listing output)
#98 - flags for passing information between Wildfilew and user macro (see below).
#99 - when Wildfilew is running, contains value 0x57495C44 ("WILD")
Register #98 contains several flags for passing information between Wildfilew and user macro. (Flags are represented here as mask values):
Wildfile sets:
0x00 = First call to user macro (Wildfile resets #98 at the beginning)
0x02 = Last file being processed
User macro sets:
0x01 = First call done (set by user macro if needed)
0x02 = Stop processing more files
0x04 = Do not show end dialog
0x08 = Do not close current file
0x10 = Search.tmp was used, do not close it.

For more information of the special registers, see below.

Text registers

User macro should only use free text registers in range 10 to 99 (use Reg_Free to check for free text registers). Any text registers used must be emptied at the end.

Passing information between Wildfilew.vdm and user macro

Usually, the macro should be made such way that it can be called either directly or from Wildfilew.vdm. This may require different operation in case macro is called from Wildfile (and thus multiple files are being processed). In addition, Wildfilew allows controlling some functions of Wildfilew from user macro.

Check if macro was called from Wildfilew

If numerig register #99 has value 0x57495C44 ("WILD"), the macro was called from Wildfile. You can check this e.g. with the following command:

if (#99==0x57495C44) {
   // Wildfile is running
}

Check if first or last call to user macro

If the user macro collects information from multiple files, it is necessary to do some initializations on the first call and store or display results on the last call. You can check if this is the firs call or last call by checking value of numreg #98. Example:

if (#98 == 0) {
    // first call, do initializations etc.
    #98 = 1   // initializations have been done
}

if (#98 == 2) {
    // last call, display results etc.
}

Examples

Some of the supplied macros can be used as an example of how to create Wildfile aware macros.

Count2.vdm is a simple example. You enter a search string in a dialog box and the macro then counts how many times the string occurs in the file. The result is displayed on status line. If you call the macro directly, it counts the strings in current file only. If you call the macro from Wildfile, the strings are counted in all the specified files. The dialog box is only displayed once in the beginning.

C_paren.vdm is a more complex example of Wildfile aware macro is. It checks that all the parentheses in C file(s) are balanced. Just like count2.vdm, it can be called either directly or from Wildfile.

Related topics:

Macro dialog