From f449c0a95327fd4e60a5b9d3c9d50fae0f8d835a Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 30 Dec 2007 23:33:12 +0000 Subject: [PATCH] Comment changes. --- lib/silcutil/silcbitops.h | 28 +++-- lib/silcutil/silcbuffmt.h | 14 +-- lib/silcutil/silcfileutil.h | 8 +- lib/silcutil/silcfsm.h | 4 +- lib/silcutil/silcmemory.h | 6 +- lib/silcutil/silcregex.h | 206 ++++++++++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+), 26 deletions(-) create mode 100644 lib/silcutil/silcregex.h diff --git a/lib/silcutil/silcbitops.h b/lib/silcutil/silcbitops.h index 86073b6f..87bc85eb 100644 --- a/lib/silcutil/silcbitops.h +++ b/lib/silcutil/silcbitops.h @@ -93,7 +93,7 @@ * DESCRIPTION * * Set bit number `bit' in the `bitmap' of size of `bitmap_size'. Returns - * FALSE on error. + * FALSE on error and sets silc_errno. * ***/ SilcBool silc_bit_set(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, @@ -109,7 +109,7 @@ SilcBool silc_bit_set(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, * DESCRIPTION * * Clear bit number `bit' in the `bitmap' of size of `bitmap_size'. - * Returns FALSE on error. + * Returns FALSE on error and sets silc_errno. * ***/ SilcBool silc_bit_clear(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, @@ -125,7 +125,7 @@ SilcBool silc_bit_clear(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, * DESCRIPTION * * Toggle bit number `bit' in the `bitmap' of size of `bitmap_size'. - * Returns FALSE on error. + * Returns FALSE on error and sets silc_errno. * ***/ SilcBool silc_bit_toggle(volatile unsigned long *bitmap, @@ -141,7 +141,8 @@ SilcBool silc_bit_toggle(volatile unsigned long *bitmap, * DESCRIPTION * * Set bit number `bit' in the `bitmap' of size of `bitmap_size' and - * return the value before setting. Returns -1 on error. + * return the value before setting. Returns -1 on error and sets + * silc_errno. * ***/ int silc_bit_test_and_set(volatile unsigned long *bitmap, @@ -157,7 +158,8 @@ int silc_bit_test_and_set(volatile unsigned long *bitmap, * DESCRIPTION * * Clear bit number `bit' in the `bitmap' of size of `bitmap_size' and - * return the value before setting. Returns -1 on error. + * return the value before setting. Returns -1 on error and sets + * silc_errno. * ***/ int silc_bit_test_and_clear(volatile unsigned long *bitmap, @@ -173,7 +175,8 @@ int silc_bit_test_and_clear(volatile unsigned long *bitmap, * DESCRIPTION * * Toggle bit number `bit' in the `bitmap' of size of `bitmap_size' and - * return the value before setting. Returns -1 on error. + * return the value before setting. Returns -1 on error and sets + * silc_errno. * ***/ int silc_bit_test_and_toggle(volatile unsigned long *bitmap, @@ -188,7 +191,8 @@ int silc_bit_test_and_toggle(volatile unsigned long *bitmap, * * DESCRIPTION * - * Returns the value of the bit number `bit' or -1 on error. + * Returns the value of the bit number `bit' or -1 on error and sets + * silc_errno. * ***/ int silc_bit_get(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, @@ -203,7 +207,8 @@ int silc_bit_get(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, * DESCRIPTION * * Returns the bit number of the first set bit in the `bitmap' of size - * of `bitmap_size'. Returns -1 on error or when there were no set bits. + * of `bitmap_size'. Returns -1 on error or when there were no set bits + * and sets silc_errno. * ***/ int silc_bit_ffs(volatile unsigned long *bitmap, SilcUInt32 bitmap_size); @@ -217,7 +222,8 @@ int silc_bit_ffs(volatile unsigned long *bitmap, SilcUInt32 bitmap_size); * DESCRIPTION * * Returns the bit number of the first zero bit in the `bitmap' of size - * of `bitmap_size'. Returns -1 on error or when there were no zero bits. + * of `bitmap_size'. Returns -1 on error or when there were no zero bits + * and sets silc_errno. * ***/ int silc_bit_ffz(volatile unsigned long *bitmap, SilcUInt32 bitmap_size); @@ -233,7 +239,7 @@ int silc_bit_ffz(volatile unsigned long *bitmap, SilcUInt32 bitmap_size); * * Returns the bit number of the next set bit in the `bitmap' of size * of `bitmap_size' starting at bit `offset'. Returns -1 on error or - * when there were no more set bits. + * when there were no more set bits and sets silc_errno. * ***/ int silc_bit_fns(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, @@ -250,7 +256,7 @@ int silc_bit_fns(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, * * Returns the bit number of the next zero bit in the `bitmap' of size * of `bitmap_size' starting at bit `offset'. Returns -1 on error or - * when there were no more zero bits. + * when there were no more zero bits and sets silc_errno. * ***/ int silc_bit_fnz(volatile unsigned long *bitmap, SilcUInt32 bitmap_size, diff --git a/lib/silcutil/silcbuffmt.h b/lib/silcutil/silcbuffmt.h index 6e530f54..4668f7f9 100644 --- a/lib/silcutil/silcbuffmt.h +++ b/lib/silcutil/silcbuffmt.h @@ -123,7 +123,7 @@ typedef int (*SilcBufferUnformatFunc)(SilcStack stack, SilcBuffer buffer, * Formats a buffer from a variable argument list. Returns -1 if the * system is out of memory and the length of the formatted buffer otherwise. * The buffer is enlarged automatically during formatting, if it doesn't - * already have enough space. + * already have enough space. Sets silc_errno in case of error. * * EXAMPLE * @@ -182,7 +182,7 @@ int silc_buffer_format(SilcBuffer dst, ...); * * Same as silc_buffer_format but uses `stack' to allocate the memory. * if `stack' is NULL reverts back to silc_buffer_format call. Returns - * -1 if system is out of memory. + * -1 if system is out of memory. Sets silc_errno in case of error. * * Note that this call consumes the `stack'. The caller should push the * stack before calling the function and pop it later. @@ -215,7 +215,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap); * * Same as silc_buffer_format_vp but uses `stack' to allocate the memory. * if `stack' is NULL reverts back to silc_buffer_format_vp call. Returns - * -1 if system is out of memory. + * -1 if system is out of memory. Sets silc_errno in case of error. * * Note that this call consumes the `stack'. The caller should push the * stack before calling the function and pop it later. @@ -232,7 +232,8 @@ int silc_buffer_sformat_vp(SilcStack stack, SilcBuffer dst, va_list ap); * DESCRIPTION * * Unformats a buffer from a variable argument list. Returns -1 on error - * and the length of the unformatted buffer otherwise. + * and the length of the unformatted buffer otherwise. Sets silc_errno + * in case of error. * * EXAMPLE * @@ -309,7 +310,8 @@ int silc_buffer_sunformat_vp(SilcStack stack, SilcBuffer src, va_list ap); * be end with SILC_STRFMT_END argument. This allows that a string in * the list can be NULL, in which case it is skipped. This automatically * allocates the space for the buffer data but `dst' must be already - * allocated by the caller. Returns -1 if system is out of memory. + * allocated by the caller. Returns -1 if system is out of memory and + * sets silc_errno. * * EXAMPLE * @@ -335,7 +337,7 @@ int silc_buffer_strformat(SilcBuffer dst, ...); * allocates the space for the buffer data but `dst' must be already * allocated by the caller. This function is equivalent to * silc_buffer_strformat but allocates memory from `stack'. Returns -1 - * if system is out of memory. + * if system is out of memory and sets silc_errno. * * Note that this call consumes the `stack'. The caller should push the * stack before calling the function and pop it later. diff --git a/lib/silcutil/silcfileutil.h b/lib/silcutil/silcfileutil.h index 151f45a4..b3b0312c 100644 --- a/lib/silcutil/silcfileutil.h +++ b/lib/silcutil/silcfileutil.h @@ -58,7 +58,7 @@ int silc_file_open(const char *filename, int flags); * Opens a file indicated by the filename `filename' with flags indicated * by `flags'. The argument `mode' specifies the permissions to use in * case a new file is created. The `flags' are defined in open(2). - * Returns the opened file descriptor or -1 on error. + * Returns the opened file descriptor or -1 on error and sets silc_errno. * ***/ int silc_file_open_mode(const char *filename, int flags, int mode); @@ -72,7 +72,7 @@ int silc_file_open_mode(const char *filename, int flags, int mode); * DESCRIPTION * * Reads data from file descriptor `fd' to `buf'. Returns the amount of - * bytes read, 0 on EOF or -1 on error. + * bytes read, 0 on EOF or -1 on error and sets silc_errno. * ***/ int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len); @@ -86,7 +86,7 @@ int silc_file_read(int fd, unsigned char *buf, SilcUInt32 buf_len); * DESCRIPTION * * Writes `buffer' of length of `len' to file descriptor `fd'. Returns - * the amount of bytes written, 0 on EOF or -1 on error. + * the amount of bytes written, 0 on EOF or -1 on error and sets silc_errno. * ***/ int silc_file_write(int fd, const char *buffer, SilcUInt32 len); @@ -100,7 +100,7 @@ int silc_file_write(int fd, const char *buffer, SilcUInt32 len); * DESCRIPTION * * Closes file descriptor previously opened with silc_file_open(). - * Returns 0 on success or -1 on error. + * Returns 0 on success or -1 on error and sets silc_errno. * ***/ int silc_file_close(int fd); diff --git a/lib/silcutil/silcfsm.h b/lib/silcutil/silcfsm.h index 503b8f43..3b1a0d4b 100644 --- a/lib/silcutil/silcfsm.h +++ b/lib/silcutil/silcfsm.h @@ -405,7 +405,7 @@ do { \ * is the caller's scheduler and the FSM will be run in the scheduler. * If `schedule' is NULL this will call silc_schedule_get_global to try * get global scheduler. Returns NULL on error or if system is out of - * memory. + * memory and sets silc_errno. * * EXAMPLE * @@ -487,7 +487,7 @@ SilcBool silc_fsm_init(SilcFSM fsm, * then the thread will actually be executed in real thread, if platform * supports them. The `thread_context' is delivered to every state * function in the thread. Returns NULL on error or if the system is out - * of memory. + * of memory and sets silc_errno. * * NOTES * diff --git a/lib/silcutil/silcmemory.h b/lib/silcutil/silcmemory.h index 7dc60062..ddcf8bc1 100644 --- a/lib/silcutil/silcmemory.h +++ b/lib/silcutil/silcmemory.h @@ -44,7 +44,7 @@ * * Allocates memory of `size' bytes and returns pointer to the allocated * memory area. Free the memory by calling silc_free. Returns NULL on - * error. + * error and sets silc_errno. * ***/ void *silc_malloc(size_t size); @@ -60,7 +60,7 @@ void *silc_malloc(size_t size); * Allocates memory of for an array of `items' elements of `size' bytes * and returns pointer to the allocated memory area. The memory area is * also zeroed. Free the memory by calling silc_free. Returns NULL on - * error. + * error and sets silc_errno. * ***/ void *silc_calloc(size_t items, size_t size); @@ -127,7 +127,7 @@ void *silc_memdup(const void *ptr, size_t size); * DESCRIPTION * * Duplicates the string indicated by `str' and returns the duplicated - * string. Returns NULL on error. + * string. Returns NULL on error and sets silc_errno. * ***/ char *silc_strdup(const char *str); diff --git a/lib/silcutil/silcregex.h b/lib/silcutil/silcregex.h new file mode 100644 index 00000000..7fac2ac2 --- /dev/null +++ b/lib/silcutil/silcregex.h @@ -0,0 +1,206 @@ +/* + + regexpr.h + + Author: Tatu Ylonen + + Copyright (c) 1991 Tatu Ylonen, Espoo, Finland + + Permission to use, copy, modify, distribute, and sell this software + and its documentation is hereby granted without fee, provided that the + above copyright notice appears in all source code copies, the name of + Tatu Ylonen is not used to advertise products containing this software + or a derivation thereof, and all modified versions are clearly marked + as such. + + This software is provided "as is" without express or implied warranty. + + Created: Thu Sep 26 17:15:36 1991 ylo + Last modified: Fri Jan 3 12:05:45 1992 ylo + + The SILC Regex API by Pekka Riikonen, under the same license as the original + code. + +*/ + +/****h* silcutil/SILC Regular Expression Interface + * + * DESCRIPTION + * + * SILC regular expression interface provides Unix and POSIX compliant + * regular expression compilation and matching. + * + * EXAMPLE + * + * SilcRegexStruct reg; + * + * // Compile regular expression + * if (!silc_regex_compile(®, "foo[0-9]*", 0)) + * error; + * + * // Match string against the compiled regex + * if (!silc_regex_match(®, "foo20", 0, NULL, 0)) + * no_match; + * + * // Free the compiled regular expression + * silc_regex_free(®); + * + ***/ + +#ifndef SILCREGEX_H +#define SILCREGEX_H + +/****s* silcutil/SilcRegexAPI/SilcRegex + * + * NAME + * + * typedef struct { ... } *SilcRegex, SilcRegexStruct; + * + * DESCRIPTION + * + * The regular expression context. This context is given as argument + * to all silc_regex_* functions. It is usually statically allocated + * but can be dynamically allocated by silc_malloc. + * + ***/ +typedef struct SilcRegexObject { + char *buffer; /* compiled pattern */ + int allocated; /* allocated size of compiled pattern */ + int used; /* actual length of compiled pattern */ + char *fastmap; /* fastmap[ch] is true if ch can start pattern */ + char *translate; /* translation to apply during comp/match */ + char fastmap_accurate; /* true if fastmap is valid */ + char can_be_null; /* true if can match empty string */ + char uses_registers; /* registers used and need to be initialized */ + char anchor; /* anchor: 0=none 1=begline 2=begbuf */ +} *SilcRegex, SilcRegexStruct; + +/****s* silcutil/SilcRegexAPI/SilcRegexMatch + * + * NAME + * + * typedef struct { ... } *SilcRegexMatch, SilcRegexMatchStruct; + * + * DESCRIPTION + * + * The regular expression match context that provides information on the + * found match. It provides the start offset and end offset of the + * found match. + * + * SOURCE + */ +typedef struct SilcRegexMatchObject { + int start; /* Start offset of region */ + int end; /* End offset of region */ +} *SilcRegexMatch, SilcRegexMatchStruct; +/***/ + +/****d* silcutil/SilcRegexAPI/SilcRegexFlags + * + * NAME + * + * typedef enum { ... } SilcRegexFlags; + * + * DESCRIPTION + * + * Regular expression feature flags. + * + * SOURCE + */ +typedef enum { + SILC_REGEX_FLAG_DEFAULT = 0, +} SilcRegexFlags; +/***/ + +/****f* silcutil/SilcRegexAPI/silc_regex_compile + * + * SYNOPSIS + * + * SilcBool silc_regex_compile(SilcRegex regexp, const char *regex, + * SilcRegexFlags flags); + * + * DESCRIPTION + * + * Compiles the regular expression string `regex'. The `regexp' is a + * pre-allocated regular expression context. The `flags' define + * various feature flags. This function must be called before the + * silc_regex_match can be used to find matches. + * + * Returns TRUE after the compilation is completed. Returns FALSE on + * error and sets silc_errno. + * + ***/ +SilcBool silc_regex_compile(SilcRegex regexp, const char *regex, + SilcRegexFlags flags); + +/****f* silcutil/SilcRegexAPI/silc_regex_compile + * + * SYNOPSIS + * + * SilcBool silc_regex_match(SilcRegex regexp, const char *string, + * SilcUInt32 num_match, SilcRegexMatch match, + * SilcRegexFlags flags); + * + * DESCRIPTION + * + * Finds one or more matches from the `string' using the pre-compiled + * regular expression `regexp'. It must be compiled by calling the + * silc_regex_compile before calling this function. The `flags' defines + * various feature flags. + * + * If only one match is needed the `num_match' may be set to 0 and the + * `match' is set to NULL. If multiple matches (substrings) are needed the + * `num_match' defines the size of the `match' array, where each of the + * matches (with parenthesized regular expression) will be stored. The + * `match' provides information on where the match was found in `string', + * providing the start offset and end offset of the match. Unused entires + * in the array will have -1 as the offset values. + * + * Returns TRUE if the string matched the regular expression or FALSE + * if it did not match or error occurred. The silc_errno will indicate + * the error. The silc_errno is set to SILC_ERR_NOT_FOUND if the regular + * expression did not match. + * + * EXAMPLE + * + * // Find first match (check if string matches) + * if (!silc_regex_match(®, "foo20", 0, NULL, 0)) + * no_match; + * + * // Find multiple matches, one by one + * SilcRegexMatchStruct match; + * + * while (silc_regex_match(®, string, 1, &match, 0)) { + * match_string = silc_memdup(string + match.start, + * match.end - match.start); + * string += match.end; + * } + * + * // Parse URI into its components, available in the match[] array + * SilcRegexStruct reg; + * SilcRegexMatchStruct match[7]; + * + * silc_regex_compile(®, "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)", 0); + * silc_regex_match(®, "http://example.com/page.html", 7, match, 0); + * + ***/ +SilcBool silc_regex_match(SilcRegex regexp, const char *string, + SilcUInt32 num_match, SilcRegexMatch match, + SilcRegexFlags flags); + +/****f* silcutil/SilcRegexAPI/silc_regex_free + * + * SYNOPSIS + * + * void silc_regex_free(SilcRegex regexp); + * + * DESCRIPTION + * + * Free's the compiled regular expression context `regexp'. This must + * be called even if `regexp' is statically allocated. If the + * silc_regex_compile has been called this function must be called. + * + ***/ +void silc_regex_free(SilcRegex regexp); + +#endif /* SILCREGEX_H */ -- 2.24.0