Multi-Edit's Top Bar Image - Click here to Return to the Home Page spacer image for website layout News regarding our IDE -click this image- Products of MESI Page -click this image- Support Avenues, Forums, Emails etc. -click this image- Purchase Online -click this image- Resources, Downloads, Zips for Mult-Edit -click this image- Company NFO -click this image- Website Sitemap -click this image-

Using the LDFILES macro

Loading a file into memory from a macro is a very common thing to do. In the CMACWIN reference we have a note on the LOAD_FILE function. It begins: "NOTE: We recommend the use of the LDFILES macro in the macro file MESYS instead of using the LOAD_FILE operation." Unfortunately, we don't give you much more info than that. This document will show you how to make effective use of the LDFILES macro.

This LDFILES macro has been around since the early days of the DOS version of Multi-Edit, and still uses the command-line style of parameter passing. The LOAD_FILE internal function is very primitive: it simply loads a file into a window. It doesn't do any configuration for the file, it doesn't set the tabs, or any of the other filename extension specific configuration items, and it can't handle creating windows or loading multiple files. LDFILES was created to handle all of these things and more. It can find a file on the path when no directory is specified. It will load multiple files and create new windows. It calls the macro EXT_SETUP to process extensions specific configuration.

NOTE: There are times when LOAD_FILE is appropriate. If you are loading a temporary file, or any file that will not be displayed, than LOAD_FILE may make more sense than LDFILES. Why go through all the extra processing if it isn't needed?

The basic use of LDFILES is simple: You put the name of the file you want to load in Return_Str, and then perform a RM("LDFILES"). Normally you will also have to pass some parameters to LDFILES, and we will go into those. The number of files loaded is returned in Return_Int, however, Return_Int is always at least 1. To check the success of the operation, use Error_Level. If Error_Level is non-zero, then an error occurred. A complete description of the parameters and return values follows the examples.

Example 1 - Load a file into the current window, check for error

        Return_Str = "C:\TEST.TXT";
        RM("LDFILES");
        if(Error_Level)
        {
          // Process errors here.  If we don't process the error, then
          // the default error dialog will be popped up after this
          // macro is exited.  If we do process the error, then we
          // need to be sure to set Error_Level back to zero.
        }
Example 2 - Load a file into a new window.
        Return_Str = "C:\TEST.TXT";
        RM("LDFILES /CW=1");
        if(Error_Level)
        {
          // Process errors here.
        }
Example 3 - Load multiple files with a wildcard. Only load the first one into a new window if the current window is NOT empty. When done, switch back to the window we started in.
        int OriginalWindow = Window_Id;

        Return_Str = "*.TXT";
        RM("LDFILES /CW=2");
          // The current window is not necessarily the one we started with
        Switch_Win_Id( OriginalWindow );
          // Now process errors, etc.
Example 4 - Load multiple files from a file list. This one will be a complete macro. The file list would look like this:

        c:\test\wow.txt
        c:\what\something.s
        d:\where\more.c
        ....

NOTE: You can use the /FTO= parameter in the file list itself to override the file types of specific files. For example:

/FTO=2 c:\test\wow.txt
int LoadFilesFromList( str ListFileName = mparm_str )
  //  Allow the list file to passed on the command line
  //  Return TRUE (non-zero) if the function succeeds.
{
  int Result = FALSE;

  int OrigRefresh = Refresh;    // Save the refresh
  refresh = FALSE;              // and disable it

  int OrigWindow = Window_Id;   // Save off the original window id

  Error_Level = 0;              // Clear Error_Level in case it was
                                // not previously cleaned up

  Create_Window;                // Create a temporary window to
                                // load our list file into

  int ListWindow = Window_Id;   // Store the id of our list file window

  Load_File( ListFileName );    // Load the list file
  if(!Error_Level)              // If no error, load the files in
  {                             // the list.  Always create new
                                // window.  Pass the Window_Id of the
                                // list window using /TAG=
    RM("LDFILES /CW=1/TAG=" + str(Window_Id));

    if(!Error_Level)            // If no error occurred, then reset
    {                           // OrigWindow, so that we stay in
      OrigWindow = Window_Id;   // the window of the first file loaded

      Result = TRUE;            // We have succeeded!
    }
  }
                                // Switch back to our list window
                                // Remember, the current window may
  Switch_Win_Id( ListWindow );  // have changed during the LDFILES

  Delete_Window;                // Destroy the list window

  Switch_Win_Id( OrigWindow );  // Switch back to the original window
                                // or the first loaded file (if the
                                // LDFILES succeeded)

  Refresh = OrigRefresh;        // Restore refresh

  return( Result );
}

LDFILES documentation

Parameters: Return_Str = the filename;

  • /LC=n This parameter is a little awkward to understand. Basically, if it is 0 then the first file will be loaded into the current window. If it is non-zero, then new windows will be created. Return_Int will return the number of files loaded + the number passed with /LC=.

  • /MC=n The max number of files allowed to be loaded. Only applies to wildcards and file lists.

  • /NW=1 Do not allow wildcards.

  • /NC=1 Do not check to see if a file is already loaded. Normally LDFILES checks to see if the specified file is already loaded and prompts the user for re-loading.

  • /PRE= Will pass this parameter to EXTSETUP

  • /CW=
    1. Create new window immediately, regardless of /LC=.
    2. Create new window ONLY if the current window is NOT empty.

  • /NHA=1 No History Add - don't add files to history list.

  • /DE=1 Use default extension if applicable. This allows you to pass a filename without an extension, and LDFILES will use the default extension list (configured in Edit Settings) to find the file.

  • /RO=1 Open files read-only (no modifications allowed)

  • /FTO=x Filetype override
    0 = Use defaults for extension
    1 = DOS
    2 = UNIX
    3 = Binary /BRL=x record length
    255 = Leave line_term i nator values alone

  • /TAG= id Load using tag list in specified window id A tag list is a list of files to load, where there is one filename per line. You pass the window_id of the window that contains the list. IMPORTANT: we are using Window_Id here, not Cur_Window (the window order number). Also, /TAG does not support locating files in their default directories. The file's path must be specified, or must be the current directory.

  • /OEM=x
    0 = Use Default
    1 = Ansi
    2 = Oem

  • /NRL=1 Do not reload or prompt for already loaded files. If the specified file already exists, do not reload it, and do not prompt, just switch to it.

  • /XL=1 Do XLoad_File instead of Load_File. XLoad_File does not try to load any of the file into memory, it just opens the file. The file will get loaded into memory when it is accessed or displayed. This is not used often.

  • /NR=1 Do not modify Window redraw flag ( Windows only ). Normally redraw is turned off, all files are loaded, and then redraw is restored so that the screen can be repainted.

  • /FN=str Filename to load. This overrides Return_Str.

  • /NB=1 Do not do any special brief window processing

Returns:
The number of files loaded is returned in Return_Int, however, Return_Int is always at least 1. To check the success of the operation, use Error_Level. If Error_Level is non-zero, then an error occurred. If you use /LC=1 (or > 0), or /CW=1, or use a tag list, then new windows will be created even if the file load fails (you get the "File not found, new file assumed" message).

Also, Global integer Load_Count will be set to /LC=nn + the number of files loaded.