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:

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


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

    myp:=proc(x::numeric)
        piecewise(x>1,1*x,x>2,2*x,x>3,3*x,0);
    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

    {x}

by something like

    {result=x;}

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...