Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.145.12.100
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/3/root/proc/self/root/usr/share/doc/re2c/examples/c/submatch/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/3/root/proc/self/root/usr/share/doc/re2c/examples/c/submatch/parse_options.re
// re2c $INPUT -o $OUTPUT -i
#include <assert.h>
#include <stdio.h>
#include <string>
#include <vector>

typedef std::vector<std::pair<std::string, std::string> > unknown_t;

struct options_t {
    std::string date;
    std::string path;
    std::string format;
    std::string limit;
    bool verbose;
};

static void show(const options_t &o, const unknown_t &u) {
    fprintf(stderr, "\noptions:\n");
    fprintf(stderr, "  date:    %s\n", o.date.c_str());
    fprintf(stderr, "  path:    %s\n", o.path.c_str());
    fprintf(stderr, "  format:  %s\n", o.format.c_str());
    fprintf(stderr, "  limit:   %s\n", o.limit.c_str());
    fprintf(stderr, "  verbose: %s\n", o.verbose ? "yes" : "no");

    fprintf(stderr, "\nunknown:\n");
    unknown_t::const_iterator i = u.begin(), e = u.end();
    for (; i != e; ++i) {
        fprintf(stderr, "  %s: '%s'\n", i->first.c_str(), i->second.c_str());
    }
}

static void bad_arg(const char *k, const char *v, const char *e) {
    fprintf(stderr, "bad argument '%.*s' to option %.*s\n",
        (int) (e - v), v, (int) (v - k), k);
}

static int lex(const char *s) {
    options_t o;
    unknown_t u;
    const char *m, *k, *v;
    /*!stags:re2c format = 'const char *@@;'; */

    for (;;) {
    /*!re2c
        re2c:define:YYCTYPE = char;
        re2c:define:YYCURSOR = s;
        re2c:define:YYMARKER = m;
        re2c:yyfill:enable = 0;
        re2c:tags = 1;

        end    = "\x00";
        sp     = [ \t\n\r];
        eq     = "=";
        wsp    = sp*;
        char   = [^=] \ end;
        ochar  = char \ sp;
        pchar  = ochar \ [/];
        str    = ["] (char \ ["] | [\]["])* ["];
        opt    = ochar+;
        arg    = ochar* | str;
        date   = [0-9]{2} "/" [0-9]{2} "/" [0-9]{4};
        path   = pchar* ("/" pchar*)*;
        format = str;
        limit  = [0-9]+ [BKMG]?;

        *   { fprintf(stderr, "error: %s\n", s); return 1; }
        end { show(o, u); return 0; }
        wsp { continue; }

        "-v" | "--verbose"              { o.verbose = true; continue; }
        ("-l" | "--limit"  eq) @v limit { o.limit  = std::string(v, s); continue; }
        ("-f" | "--format" eq) @v str   { o.format = std::string(v, s); continue; }
        ("-d" | "--date"   eq) @v date  { o.date   = std::string(v, s); continue; }
        ("-p" | "--path"   eq) @v path  { o.path   = std::string(v, s); continue; }

        @k ("--" ("limit" | "format" | "date" | "path") | "-" [lfdp]) @v eq? arg {
            bad_arg(k, v, s);
            continue;
        }
        [-]{1,2} @k opt @v eq? arg {
            u.push_back(std::make_pair(std::string(k, v), std::string(v, s)));
            continue;
        }
    */
    }
}

int main() {
    assert(lex("-v --limit=8K -d08/08/1985 -p/usr/src/linux "
        "--format=\"%s\" --limit -f=3 --verbos --d\"19th May\"") == 0);
    return 0;
}

Anon7 - 2022
AnonSec Team