FUNCTIONS ^

char *dupstrn(char const *const source, size_t num_chars)

See dupstr, except that this version takes the number of characters to be copied. Easy for copying a string except the quotes.

char *dupstr(char const *const source)

The C89 standard does not define a strdup() in the C library, so define our own strdup. Function names beginning with "str" are reserved (I think), so make it dupstr, as that is what it does: duplicate a string.

FUNCTIONS ^

is_pir_directive

Returns a non-zero value if the specified name is a PIR directive.

XXX It might be worthwhile to enter the PIR directives as rules; this saves a lot of checking; these rules should just return TK_ANY.

*/ PARROT_PURE_FUNCTION PARROT_WARN_UNUSED_RESULT static int is_pir_directive(char const * const name) {

    /* maybe make this a hash or at least a binary search.
     * Or, make these "special" macros, and have them expand
     * to their own spelling. This would remove the need
     * for special code, such as this.
     */
    static char const * const directives[] = {
        ".arg",
        ".begin_call",
        ".begin_return",
        ".begin_yield",
        ".call",
        ".const",
        ".end",
        ".end_call",
        ".end_return",
        ".end_yield",
        ".file",
        ".get_results",
        ".globalconst",
        ".HLL",
        ".HLL_map",
        ".invocant",
        ".lex",
        ".line",
        ".loadlib",
        ".local",
        ".meth_call",
        ".namespace",
        ".nci_call",
        ".param",
        ".return",
        ".sub",
        ".tailcall",
        ".yield",
        NULL /* needed to easily write loops on this array */
    };

    /* iter is a pointer to constant pointers to constant chars. */
    char const * const *iter = directives;

    while (*iter != NULL) {
        if (STREQ(*iter, name))
            return 1;

        iter++;
    }
    return 0;
}
/*


parrot