update preproc 4

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...


... back to index page OE documentation

.ex, a compiled Euphoria program, .exe or even a compiled Euphoria DLL file, .dll. The only requirements are that it must accept the two command line options, -i and -o described above and exit with a ZERO status code on success or non-ZERO on failure.

The DLL file (or shared library on Unix) has a real benefit in that with each file that needs to be pre-processed does not require a new process to be spawned as with an executable or a Euphoria script. Once you have the pre-processor written and functioning, it's easy to convert your script to use the more advanced, better performing shared library. Let's do that now with our datesub.ex pre-processor. Take a moment to review the code above for the datesub.ex program before continuing. This will allow you to more easily see the changes that we make here.

-- datesub.ex 
include std/datetime.e -- now() and format() 
include std/io.e       -- read_file() and write_file() 
include std/search.e   -- match_replace() 
public function preprocess(sequence inFileName, sequence outFileName, 
        sequence options={}) 
    sequence content = read_file(inFileName) 
    content = match_replace("@DATE@", content, format(now())) 
    write_file(outFileName, content) 
    return 0 
end function 
ifdef not EUC_DLL then 
    sequence cmds = command_line() 
    sequence inFileName, outFileName 
    for i = 3 to length(cmds) do 
        switch cmds[i] do 
            case "-i" then 
                inFileName = cmds[i+1] 
            case "-o" then 
                outFileName = cmds[i+1] 
        end switch 
    end for 
    preprocess(inFileName, outFileName) 
end ifdef 

It's beginning to look a little more like a well structured program. You'll notice that we took the actual pre-processing functionality out the the top level program making it into an exported function named preprocess. That function takes three parameters:

  1. inFileName - filename to read from
  2. outFileName - filename to write to
  3. options - options that the user may wish to pass on verbatim to the pre-processor

It should return 0 on no error and non-zero on an error. This is to keep a standard with the way error levels from executables function. In that convention, it's suggested that 0 be OK and 1, 2, 3, etc... indicate different types of error conditions. Although the function could return a negative number, the main routine cannot exit with a negative number.

To use this new process, we simply translate it through euc,

C:\MyProjects\datesub> euc -dll datesub.ex 
Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu