Next Previous Contents

7. Miscellaneous Functions

7.1 SLcurrent_time_string

Synopsis

Get the current time as a string

Usage

char *SLcurrent_time_string (void)

Description

The SLcurrent_time_string function uses the C library function ctime to obtain a string representation of the current date and time in the form

     "Wed Dec 10 12:50:28 1997"
However, unlike the ctime function, a newline character is not present in the string.

The returned value points to a statically allocated memory block which may get overwritten on subsequent function calls.

See Also

SLmake_string

7.2 SLatoi

Synopsis

Convert a text string to an integer

Usage

int SLatoi(unsigned char *str

Description

SLatoi parses the string str to interpret it as an integer value. Unlike atoi, SLatoi can also parse strings containing integers expressed in hexidecimal (e.g., "0x7F") and octal (e.g., "012".) notation.

See Also

SLang_guess_type

7.3 SLextract_list_element

Synopsis

Extract a substring of a delimited string

Usage

int SLextract_list_element (dlist, nth, delim, buf, buflen)

    char *dlist;
    unsigned int nth;
    char delim;
    char *buf;
    unsigned int buflen;

Description

SLextract_list_element may be used to obtain the nth element of a list of strings, dlist, that are delimited by the character delim. The routine copies the nth element of dlist to the buffer buf whose size is buflen characters. It returns zero upon success, or -1 if dlist does not contain an nth element.

Example

A delimited list of strings may be turned into an array of strings as follows. For conciseness, all malloc error checking has been omitted.

    int list_to_array (char *list, char delim, char ***ap)
    {
       unsigned int nth;
       char **a;
       char buf[1024];

       /* Determine the size of the array */
       nth = 0;
       while (0 == SLextract_list_element (list, nth, delim, buf, sizeof(buf)))
         nth++;

       ap = (char **) SLmalloc ((nth + 1) * sizeof (char **));
       nth = 0;
       while (0 == SLextract_list_element (list, nth, delim, buf, sizeof(buf)))
         {
             a[nth] = SLmake_string (buf);
             nth++;
         }
       a[nth] = NULL;
       *ap = a;
       return 0;
    }

See Also

SLmalloc, SLmake_string


Next Previous Contents