[Gambas-devel] Gambas-devel Digest, Vol 7, Issue 7

chintan rao chintanraoh at ...176...
Mon Jan 1 05:12:13 CET 2007


>
>
>
>
>
>
>
>
> ---------- Forwarded message ----------
> From: "chintan rao" <chintanraoh at ...176...>
> To: gambas-devel at lists.sourceforge.net
> Date: Sat, 30 Dec 2006 16:30:46 +0530
> Subject: [Gambas-devel] gb.options
> Hi
>
> I have made a component using  getopt function
>
> here is the GB_DESC
>   GB_DECLARE("GetOptions", sizeof(COPTIONS)),
>
>   GB_METHOD ( "_new", NULL, COPTIONS_new,
> "(Options)s[(Argument)String[];]" ),
>   GB_METHOD ( "_free", NULL, COPTIONS_free, NULL ),
>   GB_METHOD ( "_get" ,"v",COPTIONS_get,"(Option)s" ),
>   GB_METHOD ( "NextOption","s",COPTIONS_next,NULL ),
>   GB_METHOD ( "OptionArgument","s",COPTIONS_opt_arg,NULL ),
>   GB_METHOD ( "RestOfArgs","String[]",COPTIONS_rest,NULL ),
>   GB_METHOD ( "GetErrorOption","s",COPTIONS_invalid,NULL ),
>   GB_METHOD ( "GetArgument","String[]",COPTIONS_getarg,"(Option)s"),
>
>   GB_PROPERTY_READ ("CommandLineArgs","String[]",COPTIONS_cmdline),
>
> I have made it non-static which i think is right(hopefully).
>
> NextOption works like getopt function.
> OptionArgument is  optarg.
> GetErrorOption is optopt.
> RestOfArgs gives the remaining arguments after running getopt.


NextOption is NextValidOption

_get function does not follow getopt template
> for example
>
> DIM opt AS NEW GetOptions("h:elo") if argument not specify assumes agument
> as command line options
>
> Options["h"] -> returns the last argument associated with 'h' if any
> othewise returns 0
> Options["e"] -> returns 1 if the 'e' option is specified, and 0
> otherwise.
> Options["z"] -> returns 0



Options should be opt here

opt.GetArgument("h") returns all the arguments assosiated with 'h'
>
> opt.CommandLineArgs returns the command line options
>
> Example 1(getopt style)
>
> ' Gambas module file
>
> PUBLIC SUB Main()
>
>   DIM opt AS NEW GetOptions(":h:elo")
>   DIM c AS String
>   PRINT "command line args:\"" & opt.CommandLineArgs.Join(" ") & "\""
>
>     c = opt.NextValidOption()
>     PRINT opt.OptionArgument()
>
>     IF c = ""
>       BREAK
>     ENDIF
>     SELECT CASE c
>       CASE "h"
>         PRINT "option h" & " the corresponding argument is\"" &
> opt.OptionArgument() & "\""
>       CASE "e"
>         PRINT "option e"
>       CASE "l"
>         PRINT "option l"
>       CASE "o"
>         PRINT "option o"
>       CASE "?"
>         PRINT "error parsing the arguments"
>         PRINT "invalid option " & opt.GetErrorOption()
>       CASE ":"
>         PRINT "error parsing the arguments"
>         PRINT "no arguments to option " & opt.GetErrorOption()
>     END SELECT
>   WEND


Made mistake forget  while statement !!!! I am sorry for the trouble.
' Gambas module file

PUBLIC SUB Main()

DIM opt AS NEW GetOptions(":h:elo")
DIM c AS String
PRINT "command line args:\"" & opt.CommandLineArgs.Join(" ") & "\""
WHILE 1
c = opt.NextValidOption()
' PRINT opt.OptionArgument()
' PRINT "all options are here " & opt.GetAllOptions().Join(" ")
IF c = "" THEN BREAK
SELECT CASE c
CASE "h"
PRINT "option h" & " the corresponding argument is\"" & opt.OptionArgument()
& "\""
CASE "e"
PRINT "option e"
CASE "l"
PRINT "option l"
CASE "o"
PRINT "option o"
CASE "?"
PRINT "error parsing the arguments"
PRINT "invalid option " & opt.GetErrorOption()
CASE ":"
PRINT "error parsing the arguments"
PRINT "no arguments to option " & opt.GetErrorOption()
END SELECT
WEND
IF opt.RestOfArgs().Count <> 0
PRINT "Rest of the arguments are \"" & opt.RestOfArgs().Join(" ") & "\""
ENDIF
END







  IF opt.RestOfArgs().Count <> 0
>     PRINT "Rest of the arguments are \"" & opt.RestOfArgs().Join(" ") &
> "\""
>   ENDIF
>
> END
>
> Example 2 (using "_get")
>
> ' Gambas module file
>
> PUBLIC SUB Main()
>   DIM opt AS NEW GetOptions("hevo:")
>
>   IF opt["?"] = 1
>     PRINT "error parsing the arguments"
>   ENDIF
>
>   IF opt["h"] = 1
>     PRINT "Help"
>   ENDIF
>
>   IF opt["e"] = 1
>     PRINT "Execute"
>   ENDIF
>
>   IF opt["v"] = 1
>     PRINT "Verbose"
>   ENDIF
>
>   IF opt["o"] <> 1 AND opt["o"] <> 0
>       PRINT "Ouput to " & opt["o"]
>   ENDIF
>
> END
>
> I wonder should i return all the valid options found as a String[] all at
> once
>
> Hoping this interface is alright
> If there should be a static interface i think it should be for command
> line arguments in particular



Sorry for all the trouble!!!!
Hoping not to repeat next time.
Again is this is interface okay??I mean is it upto Gambas cool standards??

Chintan Rao H
OPEN at ...549...


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Gambas-devel mailing list
Gambas-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20070101/4ae69637/attachment.html>


More information about the Devel mailing list