update preproc 5

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


If all went correctly, you now have a datesub.dll file. I'm sure you can guess on how it should be used, but for the sake of being complete,

C:\MyProjects\datesub> eui -p eui:datesub.dll thedate.eui 

On such a simple file and such a simple pre-processor, you probably are not going to notice a speed difference but as things grow and as the pre-processor gets more complicated, compiling to a shared library is your best option.

Advanced Examples

Finish datesub.ex

Before we move totally away from our datesub.ex example, let's finish it off by adding some finishing touches and making use of optional parameters. Again, please go back and look at the Shared Library version of datesub.ex before continuning so that you can see how we have changed things.

-- datesub.ex 
include std/cmdline.e  -- command line parsing 
include std/datetime.e -- now() and format() 
include std/io.e       -- read_file() and write_file() 
include std/map.e      -- map accessor functions (get()) 
include std/search.e   -- match_replace() 
sequence cmdopts = { 
    { "f", 0, "Date format", { NO_CASE, HAS_PARAMETER, "format" } } 
public function preprocess(sequence inFileName, sequence outFileName, 
        sequence options={}) 
    map opts = cmd_parse(cmdopts, options) 
    sequence content = read_file(inFileName) 
    content = match_replace("@DATE@", content, format(now(), map:get(opts, 
    write_file(outFileName, content) 
    return 0 
end function 
ifdef not EUC_DLL then 
    cmdopts = { 
        { "i", 0, "Input filename", { NO_CASE, MANDATORY, HAS_PARAMETER, 
"filename"} }, 
        { "o", 0, "Output filename", { NO_CASE, MANDATORY, HAS_PARAMETER, 
"filename"} } 
    } & cmdopts 
    map opts = cmd_parse(cmdopts) 
    preprocess(map:get(opts, "i"), map:get(opts, "o"), 
        "-f " & map:get(opts, "f", "%Y-%m-%d")) 
end ifdef 

Here we simply used cmdline.e to handle the command line parsing for us giving out command line program a nice interface, such as parameter validation and an automatic help screen. At the same time we also added a parameter for the date format to use. This is optional and if not supplied, %Y-%m-%d is used.

The final version of datesub.ex and thedate.ex are located in the demo/preproc directory of your Euphoria installation.

Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu