Component tlmpprogram
Component index
Section index

Component tlmpprogram


Search

Type

Function

Summary

Initialization of a TLMP program

Description

This handles library initialisation (linuxconf-lib, messages databases, ...), arguments parsing and various other kitchen and sink stuff every program needs. For argument initialisation, it support short and long name option, using single or double quota. Short name may have an argument either separated or not from the option letter: -pval or -p val are valid. Long name option support argument passed using an equal sign or as a separated command line word: "--port=1234" or "--port 1234" are valid. The -- is used to end the option sequence. The rest is passed to the main() functag (or main_noarg is there is no other command line argument).

void init ()
int main (int argc, char *argv[])
int main_noarg ()
int onearg (const char *opt, const char *val)
void showerror (const char *msg)
void usage ()

Examples

sample / tlmpprogram component

Functags

void init () Optional

Allow you to perform task before main is called

This is called after the various libraries are initialised and messages are loaded. You usually call setproginfo and setarg from there

int main (int argc, char *argv[]) Optional

Main function called when there are extra arguments

int main_noarg () Optional

main function, when there are no argument

int onearg (const char *opt, const char *val) Optional

Called to validate every command line option

An argument started with --. It may be followed by a value. The function return -1 if the option is not known. It returns 0 if the option is valid. It returns 1 if the option has a value.

void showerror (const char *msg) Optional

Presents error message sent by tlmp_error

A TLMP program generally use tlmp_error() to report error messages to the user. By default, this is sent to stderr. A GUI program may want to present them differently. This tag allows you to do so.

void usage () Mandatory

Fhelpers

void setarg (const char letter, const char *name, const char *desc, const char *&val, bool mandatory)

Define one command line argument

This will be used to validate command line argument and to generate the default usage functag. No need to use the onearg functag, unless you have very special command line argument parsing.

void setarg (const char letter, const char *name, const char *desc, SSTRING &val, bool mandatory)

Define one command line argument

This will be used to validate command line argument and to generate the default usage functag. No need to use the onearg functag, unless you have very special command line argument parsing.

void setarg (const char letter, const char *name, const char *desc, SSTRINGS &val, bool mandatory)

Define one command line argument

This will be used to validate command line argument and to generate the default usage functag. No need to use the onearg functag, unless you have very special command line argument parsing. This option may be repeated several time since an SSTRINGS variable is collecting the values. The SSTRINGS variable may contain default values. Whenever one command line option is used, the values are lost and replaced by the command line. This allows a program to have defaults and let the user completly override them.

void setarg (const char letter, const char *name, const char *desc, int &val, bool mandatory)

Define one command line argument

This will be used to validate command line argument and to generate the default usage functag. No need to use the onearg functag, unless you have very special command line argument parsing.

void setarg (const char letter, const char *name, const char *desc, bool &val, bool mandatory)

Define one command line argument

This will be used to validate command line argument and to generate the default usage functag. No need to use the onearg functag, unless you have very special command line argument parsing.

void setdbconfname (const char *dbname)

Record the configuration database name to use

Normally the name of the program is used. When multiple programs are sharing the same configuration file (home/.tlmp/db.conf), each program must use this function.

void setgrouparg (const char *descrip)

Record a section title related to next setarg() argument definition

It is possible to split the presentation of the various command line option (when using --help) into section. Each section is named using this fhelper.

void setproginfo (const char *name, const char *version, const char *desc)

Set the program name, description and version

This information is used to implement the defaullt usage functag

void setproginfo (const char *name, int version, int release, const char *desc)

Set the program name, description and version