Exemple #1
0
char const *args_multiarg(int optchar)
{
    if (optchar)                                    // new option:
    {
        if (!str)
            str = (char *)string_str(&args.d_option); // use full string

        option = optchar;                           // save the option char
    }

    register char *pos = strchr(str, option);

    if (pos)
    {
        size_t idx = pos - str;
        *pos = ' ';                                 // this option has now
        // been processed.

        return args.d_optarg[idx];                  // return optionstr.
    }

    return PFAILED;                                 // or return PFAILED
    // in which case there was
    // no option argument
}
void p_insert_chartab_ostream(register Parser *pp, char const *txt)
{
    register String *sp = chartab_apply(txt);

    ostream_insert(pp->d_outs_ptr, string_str(sp));
    string_destructor(sp);
}
Exemple #3
0
char const *args_optarg(int optchar)
{
    register char const *opt = string_str(&args.d_option);
    register char const *pos = strchr(opt, optchar);

    return pos ? args.d_optarg[pos - opt] : 0;
}
Exemple #4
0
char const *s_state_insert(register State *sp, char const *key,
                                               char const *subst)
{
    while (*key)
    {
        register char const *cp;
                                        /* if key is in the set, switch to  */
        if ((cp = strchr(sp->d_str, *key)) != 0)         /*  that state  */
            sp = sp->d_next[cp - sp->d_str];
        else
        {                               /* if not, add a new state to the   */
            size_t last = string_length(&sp->d_set);      /*          set */

            string_addchar(&sp->d_set, (char)*key); /* add key's 1st char */
            sp->d_str = string_str(&sp->d_set); /* and set the state's ptr  */

                                                /* add a new state          */
            new_size(&sp->d_next, last + 1, last, sizeof(State *));
            sp = sp->d_next[last] = s_state_new();
        }
        key++;                          /* inspect the next key char        */
    }

                                        /* all key chars exhausted: insert  */
                                        /* replacement text                 */

    if (sp->d_replacement)              /* oops, it's already there         */
        return sp->d_replacement;       /* return the one found             */

    sp->d_replacement = new_str(subst);
    return 0;                           /* here 0 indicates SUCCESS         */
}
Exemple #5
0
string GLFuncs::getVersionFromStr(char* str) {
	string result;
	if (str == NULL) {
		result = "";
	}
	else {
		string string_str(str);
		regex re("^(\\d+)\\.(\\d+).*$");

		// This will return a string with an integer with the Major and minor part of the version.
		result = regex_replace(string_str, re, "$1$2");
	}
	return result;
}
Exemple #6
0
void do_stack(const char *dirpath)
{
    struct dirent *ent = NULL;
    DIR *dir;
    char path[BUFFSIZE];
    stack *dirs;
    string dirname;

    dirs = stack_new(sizeof(string));

    stack_push(dirs, string_str(dirpath));

    while (!stack_empty(dirs)) {
        stack_pop(dirs, &dirname);
        if (!dirname.data) continue;

        if ((dir = opendir(dirname.data)) == NULL) {
            snprintf(path, BUFFSIZE, "目录打开失败 '%s'", dirname.data);
            perror(path);
            continue;
        }

        while ((ent = readdir(dir)) != NULL) {
            snprintf(path, BUFFSIZE, "%s/%s", dirname.data, ent->d_name);
            if (ent->d_type & DT_REG) {
                calc_hash(path);
            } else if (ent->d_type & DT_DIR) {
                if (strcmp(ent->d_name, ".") != 0 &&
                    strcmp(ent->d_name, "..") != 0) {
                    stack_push(dirs, string_str(path));
                }
            }
        }
        closedir(dir);
    }
}
Exemple #7
0
HashItem *construct_tocentry(char const *key, char *rest)
{
    size_t level;
    char *section = string_firstword(&rest);

    if (!section)
    {
        message_error("incomplete tocentry");
        return 0;
    }
    string_strip(&rest);
                                                /* find the section's index */
    level = lines_find(section, section_levels, sizeofSectionLevels);

    if (level == UFAILED)                       /* no section given is err. */
    {
        message_error("unknown toc-section `%s'", section);
        free(section);
        return 0;
    }

    free(section);
                                            /* write <dd><dl> for deeper
                                               levels */
    for (; level > global.d_toclevel; ++global.d_toclevel)
        lines_add(&global.d_toc, "<dd><dl>");

                                            /* write </dl></dd> when returning
                                               to shallower levels */
    for (; level < global.d_toclevel; --global.d_toclevel)
        lines_add(&global.d_toc, "</dl></dd>");

                                            /* add a new entry              */
    lines_format(&global.d_toc,
                    "<dt>%s<a href=\"%s#l%u\">%s</a>%s</dt>",
                        toc_section[global.d_doctype][level][0],
                        string_str(&global.d_outName),
                        (unsigned)++s_lastLabelNr,
                        rest,
                        toc_section[global.d_doctype][level][1]);

    return hashitem_construct(VOIDPTR, "", (void *)s_lastLabelNr, root_nop);
}
Exemple #8
0
int main(int argc, char **argv)
{
    String *cmd = string_new(0);
    String *input = NULL;

    if (argc == 1)
    {
        fprintf(stderr,
            "Usage: %s [-s] prog [arg(s)]\n"
            "      -s: use system call, not std-input\n"
            "    prog: program or system call to execute\n"
            "  arg(s): optional arguments to prog\n"
            "Input to prog is read from stdin, unless -s was specified\n"
            "   (don't make this too long, it's stored in a String first)\n"
            "\n",
            argv[0]);

        exit(1);
    }

    bool syscall = !strcmp(argv[1], "-s");
    if (syscall)
    {
        argc--;
        argv++;
    }
    else
    {
        input = string_new(0);
        char buffer[100];

        fprintf(stderr, "Reading input from stdin...\n");

        while (fgets(buffer, 100, stdin))
            string_addstr(input, buffer);

        fprintf(stderr, "Input will be:\n"
                        "`%s'\n", string_str(input));
    }

    while (*++argv)
    {
        string_addstr(cmd, *argv);
        string_addchar(cmd, ' ');
    }


    fprintf(stderr, "Command will be:\n"
                        "`%s'\n", string_str(cmd));

    message_setseverity(MSG_ALL);
    message(MSG_NOTICE, "Creating Process");

    Process process;
    process_construct(&process, "process-demo", cmd,
                                                input);

    if (syscall)
        process_system(&process);
    else
        process_fork(&process);

    String const *out = process_output(&process);

    fprintf(stderr, "Output from process: '\n"
            "%s\n"
            "'\n", string_str(out));

    process_destroy(&process);

    return 0;
}
Exemple #9
0
int main (int argc, char **argv)
{
    char const *doctype;
    char const **ptr;

    args_data = postqueue_data = message_data;

    message_construct(argv[0]);
    args_construct(argc, argv, "?x:l:", 0);

    hashmap_construct(&symtab);
    lines_construct(&global.d_toc);
    lines_construct(&global.d_section);
    lines_add(&global.d_section, "");

    hashmap_constructText(&global.d_symbol, default_symbols);

    if (!args_ok() || args_nArgs() < 2)     /* check arguments */
        usage();

    if (args_nArgs() == 2)                  /* file name specified  */
    {
        global.d_out = stdout;
        global.d_noext = 0;
    }
    else
    {
        global.d_noext = file_rmExtension(args_arg(2));
        global.d_ext = file_extension(args_arg(2));
        if (!global.d_ext)
        {
            global.d_ext = new_str(args_optarg('x'));
            if (!global.d_ext)
                global.d_ext = "ypp";      /* Yodl Post Processor  */
        }
    }

    string_construct(&global.d_outName, 0);
    postqueue_construct(task);

    if (global.d_noext)
    {
        string_format(&global.d_outName, "%s.%s",
                            global.d_noext, global.d_ext);

        global.d_out = file_open(string_str(&global.d_outName), "w");
    }

    doctypes[sizeofDocType - 1] =
                    doctype = hashmap_textOf(&global.d_symbol, "documenttype");

    for
    (
        ptr = doctypes, global.d_doctype = 1;
            strcmp(doctype, *ptr);
                ptr++, global.d_doctype <<= 1
    )
        ;

    postqueue_process();

    fclose(global.d_out);
    return 0;
}