Question: Extend Maple CodeGeneration[C] with piecewise function

I want to extend the Maple CodeGeneration[C] by a handler for the piecewise function (no idea why it is not included).
To this end I did:

    LanguageDefinition:-Define("NewC", extend="C",
        AddFunction("piecewise", anything::numeric,
                local i;
                for i from 3 to _npassed-2 by 2 do
                    Printer:-Print("else if(",_passed[i],"){",_passed[i+1],"}");
                end do;
            end proc,

Note that I am using if else statements in favour of case statements on puropose.
Here is an example code to translate:    

    end proc:
    Translate(myp, language="NewC");

The output is

    void myp (double x)
        if(0.1e1 < x){x}else if(0.2e1 < x){0.2e1 * x}else if(0.3e1 < x){0.3e1 * x}else{0};

For a valid C-routine I obviously need to replace the curly brackets like


by something like


and analogous for the others. I could do this by hand by modifying the strings in the above AddFunction statement. But then the variable name result is not known to the code generator, so there will not be any declaration nor will the value of result be returned as needed to match the routine myp or any more complicated procedure in which the result of piecewise may be assigned to some other variable or used in computations. So how do I treat this properly in the CodeGeneration routines? I.e. how can I get a valid variable name etc.

Please Wait...