Info Node: (aalib.info)Parsing of command line options
(aalib.info)Parsing of command line options
Parsing of command line options
-------------------------------
AA-lib works at many different output devices so it can be
initialized with many different options. Somebody might want to change
the defaults. This can be done using command line options. This is
done using function `aa_parseoptions' that uses `argc/argv' variables
and parses options for AA-lib. The options for AA-lib are removed
during parsing from `argc/argv' so call to aa_parseoptions can preceede
the normal command line options parsing code done by your program.
`aa_help' variable contains help about options parsed by
`aa_parseoptions'.
int aa_parseoptions(aa_hardwareparams *P,
aa_renderparams *R,
int *ARGC, char **ARGV);
First parameter is used for AA-lib initialization. It specifies the
hardware parameters you require and is altered by `aa_parseoptions'. It
is expected that your program will define his prefered parameters
first, call `aa_parseoptions' and then alter it only when necessary to
make program working correctly. If you don't brother about the hardware
specification, you may use `aa_defparams' variable in both places (here
and as passed to `aa_init' function familly). You may also pass NULL
to use defaults (aa_defparams variable).
The second argument is set of parameters for rendering. It works in
similar way as the first parameters. Both of this variables will be
explained later. Use NULL to force defaults (aa_defrenderparams).
Fuction returns: `1' if OK or `0' on error.
The function returns 1 on sucess and 0 on failure.
#include <stdio.h>
#include <aalib.h>
aa_context *context;
void main(int argc, char **argv)
{
if(!aa_parseoptions(NULL, NULL, &argc, argv) || argc!=1) {
printf("Usage: %s [options]\n"
"Options:\n"
"%s", argv[0], aa_help);
exit(1);
}
context = aa_autoinit(&aa_defparams);
if(context == NULL) {
fprintf(stderr,"Cannot initialize AA-lib. Sorry\n");
exit(2);
}
...
aa_close(context);
}
Note that options are parsed from command line and also from
`AAOPTS' enviroment variable. This makes possible to set parameters for
all AA-Lib programs. If you pass `NULL' as `argc/argv' only the
enviroment variable is parsed.
Variable `aa_help' contains help string similiar to this one:
-driver select driver
available drivers:linux slang X11
-kbddriver select keyboard driver
available drivers:slang X11
-kbddriver select mouse driver
available drivers:X11 gpm
Size options:
-width set width
-height set height
-minwidth set minimal width
-minheight set minimal height
-maxwidth set maximal width
-maxheight set maximal height
-recwidth set recomended width
-recheight set recomended height
Attributes:
-dim enable usage of dim (half bright) attribute
-bold enable usage of bold (double bright) attribute
-reverse enable usage of reverse attribute
-normal enable usage of normal attribute
-boldfont enable usage of boldfont attrubute
-no<attr> disable (i.e -nobold)
Font rendering options:
-extended use all 256 characters
-eight use eight bit ascii
-font <font> select font(This option have effect just on hardwares
where aalib is unable to determine current font
available fonts:vga8 vga9 mda14 vga14 X8x13 X8x16
X8x13bold vgagl8 line
Rendering options:
-inverse enable inverse rendering
-noinverse disable inverse rendering
-bright <val> set bright (0-255)
-contrast <val>set contrast (0-255)
-gamma <val> set gamma correction value(0-1)
Ditherng options:
-nodither disable dithering
-floyd_steinberg floyd steinberg dithering
-error_distribution error distribution dithering
-random <val> set random dithering value(0-inf)