Giter VIP home page Giter VIP logo

argsx's Introduction

GPLv3 License

ArgsX

Argsx is a easy to use command line option parser for C/C++ that support long and short option formats.

Overview

Long option interface

struct ax_lopt {
    char *name;	// Option
    int args;	// Required parameter ?
    char opt;	// Return value
}

struct ax_lopt longOpt[] = {{"one", ARGSX_NOARG, 1},
			    {"two", ARGSX_REQ_ARG, 2},
			    {"three", ARGSX_NOARG, 't'}};

Short option

Short option required string formatted in this way:

  1. Single character like 'l' -> Option that dosn't require additional parameter.
  2. Single character followed by ! like 't!' -> Option that require additional parameter.

For example, if your program require options 'a','b','c' without parameter and option 't' and 'e' with parameter you can write string like this: "abct!e!".

ArgsX function

    int ArgsX(
	int argc,                   // argc parameter
	char **argv,                // argv parameter
	char *opt,                  // pointer to short options string
	ax_lopt *lopt,              // pointer to long options struct
	unsigned short lopt_size,   // size of long options struct
	char tr                     // Trigger char Eg: '-'
	);

Put all together

struct ax_lopt longOpt[] = {{"one", ARGSX_NOARG, 1},
			    {"two", ARGSX_REQ_ARG, 2},
			    {"three", ARGSX_NOARG, 't'}};
    int opt;
    while((opt = ArgsX(argc, argv, "abct!e!", longOpt, sizeof(longOpt), '-')) != -1)
    {
      switch(opt)
      {
      	case 1:
	// --one
	break;
	case 2:
	// --two
	break;
        case 'a':
        break;
	case 'b':
        break;
        case 't':
        // -t or --three
        break;
        case ARGSX_BAD_OPT:
        break;
        case ARGSX_FEW_ARGS:
        break;
        case ARGSX_NONOPT:
        break;
      }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.