Re: [Vala] Need Help with GLib.OptionEntry



Hi Karsten,

this is happening, because you left out the third field in each entry of your array, which corresponds to the 
option flags:
http://developer.gnome.org/glib/2.28/glib-Commandline-option-parser.html#GOptionFlags

I pasted your code here and had a close look on the compiler's output. Then you can see that the errors start 
with the filename.
So the compiler complains about a string (list), two booleans (interactive and conserve) and finally an 
integer (start).

The compiler is fine with the first two entries in your array (pre and post). The difference between the 
first two entries and the others is the member 'flags':

{ "post", 0, 1,<- this one .... }

So if you provide a field value for the other entries, then you're set:

{ "list", 'l', 0, ...},
{ "interactive", 'i', 0, ...},
{ "conserve", 'c', 0, ...},
{ "start", 's', 0, ...}


Hope this helped.

Best,

Gilzad


----- original Nachricht --------

Betreff: [Vala] Need Help with GLib.OptionEntry
Gesendet: Mo, 18. Apr 2011
Von: K. König<kkoenig posteo de>

Hi,

I write a program which need command line arguments. I want to
implement this feature with the command line parser of the GLib. I read
the C and the Vala reference of the related topics but get an error
with the C compiler. Maybe knows somebody what goes wrong.


Error messages:

error: incompatible types when initializing type ‘enum <anonymous>’
using type ‘char **’
error: incompatible types when initializing type ‘enum <anonymous>’
using type ‘gboolean *’
error: incompatible types when initializing type ‘enum <anonymous>’
using type ‘gboolean *’
error: incompatible types when initializing type ‘enum <anonymous>’
using type ‘gint *’


An here is the related code:

string pre;
string post;
string filename;
bool interactive;
bool conserve;
int start;

const OptionEntry[] entries = {
    { "pre", 0, 1, OptionArg.STRING, ref pre, "set prefix that will be
placed to the left of the number", "PREFIX" }, { "post", 0, 1,
OptionArg.STRING, ref post, "set postfix that will be placed to the
left of the number", "POSTFIX" }, { "list", 'l', OptionArg.FILENAME,
ref filename, "use a list of files instead of all files in the
directory", "LIST" }, { "interactive", 'i', OptionArg.NONE, ref
interactive, "choose which files should be renamed interactive",
null }, { "conserve", 'c', OptionArg.NONE, ref conserve, "conserve file
extension", null }, { "start", 's', OptionArg.INT, ref start, "set
startnumber", "START" } };

static int main(string[] args) {
    var opt_context = new OptionContext("- Options for simpleRenamer");

    opt_context.set_help_enabled(true);
    opt_context.add_main_entries(entries, null);

    try {
        opt_context.parse(ref args);
    }
    catch(OptionError error) {
        stdout.printf("%s", error.message);
    }

    return 0;
}


Regards,

Karsten
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list


--- original Nachricht Ende ----




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]