/*=gfunc len * * what: get count of values * * exparg: ag-name, name of AutoGen value * * doc: If the named object is a group definition, then "len" is * the same as "count". Otherwise, if it is one or more text * definitions, then it is the sum of their string lengths. * If it is a single text definition, then it is equivalent to * @code{(string-length (get "ag-name"))}. =*/ SCM ag_scm_len(SCM obj) { int len = entry_length(ag_scm2zchars(obj, "ag value")); return AG_SCM_INT2SCM(len); }
/*=gfunc count * * what: definition count * * exparg: ag-name, name of AutoGen value * * doc: Count the number of entries for a definition. * The input argument must be a string containing the name * of the AutoGen values to be counted. If there is no * value associated with the name, the result is an SCM * immediate integer value of zero. =*/ SCM ag_scm_count(SCM obj) { int ent_len = count_entries(ag_scm2zchars(obj, "ag object")); return AG_SCM_INT2SCM(ent_len); }
/*=gfunc low_lim * * what: get lowest value index * * exparg: ag-name, name of AutoGen value * * doc: Returns the lowest index associated with an array of definitions. =*/ SCM ag_scm_low_lim(SCM obj) { tDefEntry* pE; ag_bool x; pE = findDefEntry(ag_scm2zchars(obj, "ag value"), &x); /* * IF we did not find the entry we are looking for * THEN return zero * ELSE we have the low index. */ if (pE == NULL) return AG_SCM_INT2SCM(0); return AG_SCM_INT2SCM((int)pE->index); }
/*=gfunc high_lim * * what: get highest value index * * exparg: ag-name, name of AutoGen value * * doc: * * Returns the highest index associated with an array of definitions. * This is generally, but not necessarily, one less than the * @code{count} value. (The indexes may be specified, rendering a * non-zero based or sparse array of values.) * * This is very useful for specifying the size of a zero-based array * of values where not all values are present. For example: * * @example * tMyStruct myVals[ [+ (+ 1 (high-lim "my-val-list")) +] ]; * @end example =*/ SCM ag_scm_high_lim(SCM obj) { tDefEntry* pE; ag_bool isIndexed; pE = findDefEntry(ag_scm2zchars(obj, "ag value"), &isIndexed); /* * IF we did not find the entry we are looking for * THEN return zero * ELSE search the twin list for the high entry */ if (pE == NULL) return AG_SCM_INT2SCM(0); if (isIndexed) return AG_SCM_INT2SCM((int)pE->index); if (pE->pEndTwin != NULL) pE = pE->pEndTwin; return AG_SCM_INT2SCM((int)pE->index); }
/*=gfunc time_string_to_number * * what: duration string to seconds * general_use: * exparg: time_spec, string to parse * * doc: Convert the argument string to a time period in seconds. * The string may use multiple parts consisting of days, hours * minutes and seconds. These are indicated with a suffix of * @code{d}, @code{h}, @code{m} and @code{s} respectively. * Hours, minutes and seconds may also be represented with * @code{HH:MM:SS} or, without hours, as @code{MM:SS}. =*/ SCM ag_scm_time_string_to_number(SCM time_spec) { extern time_t parse_duration(char const * in_pz); char const * pz; time_t time_period; if (! AG_SCM_STRING_P(time_spec)) return SCM_UNDEFINED; pz = AG_SCM_CHARS(time_spec); time_period = parse_duration(pz); return AG_SCM_INT2SCM((int)time_period); }
/*=gfunc format_arg_count * * what: count the args to a format * general_use: * * exparg: format, formatting string * * doc: "Sometimes, it is useful to simply be able to figure out how many\n" * "arguments are required by a format string. For example, if you\n" * "are extracting a format string for the purpose of generating a\n" * "macro to invoke a printf-like function, you can run the\n" * "formatting string through this function to determine how many\n" * "arguments to provide for in the macro. e.g. for this extraction\n" * "text:\n" * "@example\n\n" * " /" "*=fumble bumble\n" * " * fmt: 'stumble %s: %d\\n'\n" * " =*" "/\n" * "@end example\n\n" * "@noindent\n" * "You may wish to generate a macro:\n" * "@example\n\n" * " #define BUMBLE(a1,a2) printf_like(something,(a1),(a2))\n" * "@end example\n\n" * "@noindent\n" * "You can do this by knowing that the format needs two arguments.\n" =*/ SCM ag_scm_format_arg_count(SCM fmt) { char* pzFmt = ag_scm2zchars(fmt, zFormat); int ct = 0; for (;;) { switch (*(pzFmt++)) { case NUL: goto scanDone; case '%': if (*pzFmt == '%') pzFmt++; else ct++; } } scanDone:; return AG_SCM_INT2SCM(ct); }