Giter VIP home page Giter VIP logo

libccmd's Introduction

                                    libccmd

This is libccmd, a library for command handling in C.

This library allows you to easily implement commands in your software. These
commands can be used to control your interface, either through keybindings, IPC,
readline, or any other UI you can get command strings from.

STATUS

Currently polishing this for its initial release.

API

See include/ccmd.h, or refer to your system copy.

ccmd_init
    Takes an array of ccmd_def_t and returns a ccmd_t *

ccmd_free 
    Frees a ccmd_t

ccmd_exec/ccmd_execv/ccmd_execl
    Matches and executes commands, then returns a ccmd_res_t *

ccmd_join/ccmd_split/ccmd_argv_free
    Utility functions for working with argument vectors

ccmd_result
    Utility function to produce a ccmd_res_t in command handlers

EXAMPLE

This example uses ccmd_exec to run the cmd_echo function.

    #define _POSIX_C_SOURCE 200809L
    #include "ccmd.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>

    static ccmd_res_t *cmd_echo(int argc, char **argv) {
        for (int i = 0; i < argc; ++i) {
            printf("%s\n", argv[i]);
        }
        return ccmd_result(0, NULL);
    }

    ccmd_def_t commands[] = {
        { "echo", cmd_echo }
    };

    int main(int argc, char **argv) {
        ccmd_t *ccmd = ccmd_init(ccmds(commands));
        ccmd_res_t *res = ccmd_exec(ccmd, "echo foo bar baz");
        if (!res) {
            fprintf(stderr, "No such command: %s\n", argv[1]);
            return 1;
        }
        int exit = res->exit;
        free(res);
        return exit;
    }

INSTALLATION

    $ mkdir build && cd build
    $ ../configure
    $ make
    # make install

Use ../configure --help for assistance.

libccmd's People

Contributors

ddevault avatar

Watchers

 avatar  avatar

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.