Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Argument parser

Andrewerr edited this page Feb 14, 2020 · 3 revisions

Argument parser

This page describes functions that interact with argument parser from libddos2. To use them in your module you need to do: #include <ddos2/arguments.h>

Types

You could use the following argument types:

  • ARG_BOOL – set to check whether argument is present in argv
  • ARG_INT – requires an int64_t number after it
  • ARG_STR – requires a string after it which would be represented as char* after parsing.

Functions

void arguments_begin(hashtable* _arguments)
This function is used by ddos2_begin. It initialises argument system.

void argument_add_compulsory(char* name, char* description, argtype type)
Creates argument that must be set unless help argument is set.

  • name – Name of argument. E.g. --my-very-important-arg
  • description – short description of what your argument does.
  • type – type of argument(ARG_BOOL,ARG_INT,ARG_STR).

void argument_add(char* name, char* description, argtype type, argvalue _default, bool has_default_value, bool is_help)

  • name – Name of argument. E.g. --my-very-important-arg
  • description – short description of what your argument does.
  • type – type of argument(ARG_BOOL,ARG_INT,ARG_STR).
  • _default – default value of an argument. If it there is no default value, use stub: argbool(false) or argint(0)
  • has_default_value – set to true if your function has default value
  • is_help – set to true if this argument should be hand

void argument_add_array(char* name, char* description, argtype type, bool compulsory)

  • name – Name of argument. E.g. --my-very-important-arg
  • description – short description of what your argument does.
  • type – type of argument(ARG_INT or ARG_STR).
  • _default – default value of an argument. If it there is no default value, use stub: argbool(false) or argint(0)
  • compulsory – whether argument requires at least one value to be passed into array bool argument_check(char *name) Checks whether argument with name was present.
  • name – name of the argument

argvalue argument_value_get(char *name) Gets value of the argument with name.

  • name – name of the argument

argvalue argument_value_get_s(char *name, argtype type) Gets value of argument and do check type of the argument. This function should be used while working with string arguments, so no pointer will lead to memory corruption.

  • name – name of the argument
  • type – expected type of value returned

bool argument_check(char* name) Checks that argument was supplied in the command line.

  • name – name of the argument
Clone this wiki locally