mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-12 05:33:36 -04:00
Doxygenate src/util/
This commit is contained in:
parent
364485f6bb
commit
e530fbe8e2
@ -436,9 +436,9 @@ resize_window(int x, int y, int old_width, int old_height)
|
||||
#if 0
|
||||
unsigned char cmdline[16];
|
||||
sprintf(cmdline, "mode ");
|
||||
snprint(cmdline + 5, 5, x);
|
||||
ulongcat(cmdline + 5, NULL, x, 5, 0);
|
||||
strcat(cmdline, ",");
|
||||
snprint(cmdline + strlen(cmdline), 5, y);
|
||||
ulongcat(cmdline + strlen(cmdline), NULL, y, 5, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Base64 encode/decode implementation. */
|
||||
/** Base64 encode/decode implementation.
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -75,8 +76,13 @@ base64_decode(register unsigned char *in)
|
||||
return base64_decode_bin(in, strlen(in), NULL);
|
||||
}
|
||||
|
||||
/* base64_decode: @in string to decode
|
||||
* returns the string decoded (must be freed by the caller) */
|
||||
/** Decode a Base64 string.
|
||||
* @param in Input Base64 string
|
||||
* @param inlen Length of @a in, in bytes
|
||||
* @param[out] outlen Length of decoded string
|
||||
*
|
||||
* @returns the string decoded (must be freed by the caller)
|
||||
* or NULL if an error occurred (syntax error or out of memory) */
|
||||
unsigned char *
|
||||
base64_decode_bin(register unsigned char *in, int inlen, int *outlen)
|
||||
{
|
||||
|
@ -7,9 +7,10 @@
|
||||
|
||||
/* Bitfield operations: */
|
||||
|
||||
/** A vector of bits. The size is fixed at initialization time. */
|
||||
struct bitfield {
|
||||
unsigned int bitsize; /* Number of bits in the bitfield. */
|
||||
unsigned char bits[1]; /* Strawberry bitfields forever. */
|
||||
unsigned int bitsize; /**< Number of bits in the bitfield. */
|
||||
unsigned char bits[1]; /**< Strawberry bitfields forever. */
|
||||
};
|
||||
|
||||
#define foreach_bitfield_set(bit, bitfield) \
|
||||
@ -31,7 +32,7 @@ struct bitfield {
|
||||
/* +7 to round up to nearest byte. */
|
||||
#define get_bitfield_byte_size(bits) ((size_t) (((bits) + 7) / 8))
|
||||
|
||||
/* Allocate a bitfield containing @bits number of bits. */
|
||||
/** Allocate a bitfield containing @a bits number of bits. */
|
||||
static inline struct bitfield *
|
||||
init_bitfield(size_t bits)
|
||||
{
|
||||
@ -44,7 +45,7 @@ init_bitfield(size_t bits)
|
||||
return bitfield;
|
||||
}
|
||||
|
||||
/* Update @bitfield with the @size bytes from the @bits string in @bits. */
|
||||
/** Update @a bitfield with the @a bytesize bytes from the bit string in @a bits. */
|
||||
static inline void
|
||||
copy_bitfield(struct bitfield *bitfield,
|
||||
const unsigned char *bits, unsigned int bytesize)
|
||||
@ -54,7 +55,7 @@ copy_bitfield(struct bitfield *bitfield,
|
||||
memcpy(bitfield->bits, bits, bytesize);
|
||||
}
|
||||
|
||||
/* Test whether @bit is set in the bitfield. */
|
||||
/** Test whether @a bit is set in the @a bitfield. */
|
||||
static inline int
|
||||
test_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
{
|
||||
@ -69,7 +70,7 @@ test_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
return !!(bitfield->bits[byte_offset] & bit_offset);
|
||||
}
|
||||
|
||||
/* Set @bit in the bitfield. */
|
||||
/** Set @a bit in the @a bitfield. */
|
||||
static inline void
|
||||
set_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
{
|
||||
@ -84,7 +85,7 @@ set_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
bitfield->bits[byte_offset] |= bit_offset;
|
||||
}
|
||||
|
||||
/* Unset @bit in the bitfield. */
|
||||
/** Unset @a bit in the @a bitfield. */
|
||||
static inline void
|
||||
clear_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
{
|
||||
@ -99,6 +100,7 @@ clear_bitfield_bit(struct bitfield *bitfield, unsigned int bit)
|
||||
bitfield->bits[byte_offset] &= ~bit_offset;
|
||||
}
|
||||
|
||||
/** Count the set bits in @a bitfield. */
|
||||
static inline unsigned int
|
||||
get_bitfield_set_count(struct bitfield *bitfield)
|
||||
{
|
||||
@ -110,6 +112,7 @@ get_bitfield_set_count(struct bitfield *bitfield)
|
||||
return count;
|
||||
}
|
||||
|
||||
/** Count the unset bits in @a bitfield. */
|
||||
static inline unsigned int
|
||||
get_bitfield_cleared_count(struct bitfield *bitfield)
|
||||
{
|
||||
@ -121,6 +124,7 @@ get_bitfield_cleared_count(struct bitfield *bitfield)
|
||||
return count;
|
||||
}
|
||||
|
||||
/** Check whether all bits of @a bitfield are set. */
|
||||
static inline unsigned int
|
||||
bitfield_is_set(struct bitfield *bitfield)
|
||||
{
|
||||
@ -132,6 +136,7 @@ bitfield_is_set(struct bitfield *bitfield)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Check whether all bits of @a bitfield are unset. */
|
||||
static inline unsigned int
|
||||
bitfield_is_cleared(struct bitfield *bitfield)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef EL__UTIL_BOX_H
|
||||
#define EL__UTIL_BOX_H
|
||||
|
||||
/** A rectangular part of a drawing surface, such as the screen. */
|
||||
struct box {
|
||||
int x;
|
||||
int y;
|
||||
@ -28,7 +29,8 @@ col_is_in_box(struct box *box, int x)
|
||||
return (x >= box->x && x < box->x + box->width);
|
||||
}
|
||||
|
||||
/* Mainly intended for use with double-width characters. */
|
||||
/** Check whether a span of columns is in @a box.
|
||||
* Mainly intended for use with double-width characters. */
|
||||
static inline int
|
||||
colspan_is_in_box(struct box *box, int x, int span)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Color parser */
|
||||
/** Color parser
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -40,7 +41,7 @@ colors_list_reset(void)
|
||||
internal_pointer = color_specs;
|
||||
}
|
||||
|
||||
/* Returns a pointer to a struct that contains
|
||||
/** Returns a pointer to a struct that contains
|
||||
* current key and data pointers and increment
|
||||
* internal pointer.
|
||||
* It returns NULL when key is NULL. */
|
||||
|
@ -10,21 +10,23 @@ struct color_pair {
|
||||
|
||||
#define INIT_COLOR_PAIR(bg, fg) { bg, fg }
|
||||
|
||||
/* Decode the color string. */
|
||||
/* The color string can either contain '#FF0044' style declarations or
|
||||
/** Decode the color string.
|
||||
* The color string can either contain '@#FF0044' style declarations or
|
||||
* color names. */
|
||||
int decode_color(unsigned char *str, int slen, color_T *color);
|
||||
|
||||
/* Returns a string containing the color info. If no ``English'' name can be
|
||||
* found the hex color (#rrggbb) is returned in the given buffer. */
|
||||
/** Returns a string containing the color info. If no 'English' name can be
|
||||
* found the hex color (@#rrggbb) is returned in the given buffer. */
|
||||
const unsigned char *get_color_string(color_T color, unsigned char hexcolor[8]);
|
||||
|
||||
/* Translate rgb color to string in #rrggbb format. str should be a pointer to
|
||||
* a 8 bytes memory space. */
|
||||
/** Translate rgb color to string in @#rrggbb format.
|
||||
* @a str should be a pointer to an 8 bytes memory space. */
|
||||
void color_to_string(color_T color, unsigned char str[8]);
|
||||
|
||||
/* Fastfind lookup management. */
|
||||
/** @name Fastfind lookup management.
|
||||
* @{ */
|
||||
void init_colors_lookup(void);
|
||||
void free_colors_lookup(void);
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Conversion functions */
|
||||
/** Conversion functions
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -22,30 +23,33 @@
|
||||
|
||||
|
||||
|
||||
/* This function takes string @s and stores the @number (of a result width
|
||||
* @width) in string format there, starting at position [*@slen]. If the number
|
||||
* would take more space than @width, it is truncated and only the _last_
|
||||
* digits of it are inserted to the string. If the number takes less space than
|
||||
* @width, it is padded by @fillchar from left.
|
||||
* @base defined which base should be used (10, 16, 8, 2, ...)
|
||||
* @upper selects either hexa uppercased chars or lowercased chars.
|
||||
/** This function takes string @a s and stores the @a number (of a
|
||||
* result width @a width) in string format there, starting at position
|
||||
* [*@a slen]. If the number would take more space than @a width, it
|
||||
* is truncated and only the _last_ digits of it are inserted to the
|
||||
* string. If the number takes less space than @a width, it is padded
|
||||
* by @a fillchar from left.
|
||||
* @a base defined which base should be used (10, 16, 8, 2, ...)
|
||||
* @a upper selects either hexa uppercased chars or lowercased chars.
|
||||
*
|
||||
* A NUL char is always added at the end of the string. @s must point to a
|
||||
* sufficiently large memory space, at least *@slen + @width + 1.
|
||||
* A NUL char is always added at the end of the string. @a s must point
|
||||
* to a sufficiently large memory space, at least *@a slen + @a width + 1.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* @code
|
||||
* elinks_ulongcat(s, NULL, 12345, 4, 0, 10, 0) : s = "2345"
|
||||
* elinks_ulongcat(s, NULL, 255, 4, '*', 16, 1) : s = "**FF"
|
||||
* elinks_ulongcat(s, NULL, 123, 5, '0', 10, 0) : s = "00123"
|
||||
* @endcode
|
||||
*
|
||||
* Note that this function exists to provide a fast and efficient, however
|
||||
* still quite powerful alternative to sprintf(). It is optimized for speed and
|
||||
* is *MUCH* faster than sprintf(). If you can use it, use it ;-). But do not
|
||||
* get too enthusiastic, do not use it in cases where it would break i18n.
|
||||
*/
|
||||
/* The function returns 0 if OK or width needed for the whole number to fit
|
||||
* there, if it had to be truncated. A negative value signs an error. */
|
||||
*
|
||||
* @returns 0 if OK or width needed for the whole number to fit there,
|
||||
* if it had to be truncated. A negative value signs an error. */
|
||||
int inline
|
||||
elinks_ulongcat(unsigned char *s, unsigned int *slen,
|
||||
unsigned long number, unsigned int width,
|
||||
@ -103,7 +107,7 @@ elinks_ulongcat(unsigned char *s, unsigned int *slen,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Similar to elinks_ulongcat() but for long number. */
|
||||
/** Similar to elinks_ulongcat() but for @c long number. */
|
||||
int inline
|
||||
elinks_longcat(unsigned char *s, unsigned int *slen,
|
||||
long number, unsigned int width,
|
||||
@ -469,8 +473,8 @@ month2num(const unsigned char *str)
|
||||
}
|
||||
}
|
||||
|
||||
/* This function drops control chars, nbsp char and limit the number of consecutive
|
||||
* space chars to one. It modifies its argument. */
|
||||
/** This function drops control chars, nbsp char and limit the number
|
||||
* of consecutive space chars to one. It modifies its argument. */
|
||||
void
|
||||
clr_spaces(unsigned char *str)
|
||||
{
|
||||
@ -492,7 +496,7 @@ clr_spaces(unsigned char *str)
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
/* Replace invalid chars in @title with ' ' and trim all starting/ending
|
||||
/** Replace invalid chars in @a title with ' ' and trim all starting/ending
|
||||
* spaces. */
|
||||
void
|
||||
sanitize_title(unsigned char *title)
|
||||
@ -508,7 +512,7 @@ sanitize_title(unsigned char *title)
|
||||
trim_chars(title, ' ', NULL);
|
||||
}
|
||||
|
||||
/* Returns 0 if @url contains invalid chars, 1 if ok.
|
||||
/** Returns 0 if @a url contains invalid chars, 1 if ok.
|
||||
* It trims starting/ending spaces. */
|
||||
int
|
||||
sanitize_url(unsigned char *url)
|
||||
|
@ -17,23 +17,23 @@ is_safe_in_shell(unsigned char c)
|
||||
|
||||
long strtolx(unsigned char *, unsigned char **);
|
||||
|
||||
/* Convert a decimal number to hexadecimal (lowercase) (0 <= a <= 15). */
|
||||
/** Convert a decimal number to hexadecimal (lowercase) (0 <= @a a <= 15). */
|
||||
static inline unsigned char
|
||||
hx(register int a)
|
||||
{
|
||||
return a >= 10 ? a + 'a' - 10 : a + '0';
|
||||
}
|
||||
|
||||
/* Convert a decimal number to hexadecimal (uppercase) (0 <= a <= 15). */
|
||||
/** Convert a decimal number to hexadecimal (uppercase) (0 <= @a a <= 15). */
|
||||
static inline unsigned char
|
||||
Hx(register int a)
|
||||
{
|
||||
return a >= 10 ? a + 'A' - 10 : a + '0';
|
||||
}
|
||||
|
||||
/* Convert an hexadecimal char ([0-9][a-z][A-Z]) to
|
||||
* its decimal value (0 <= result <= 15)
|
||||
* returns -1 if parameter is not an hexadecimal char. */
|
||||
/** Convert an hexadecimal char ([0-9][a-z][A-Z]) to
|
||||
* its decimal value (0 <= result <= 15).
|
||||
* Returns -1 if parameter is not an hexadecimal char. */
|
||||
static inline int
|
||||
unhx(register unsigned char a)
|
||||
{
|
||||
@ -51,21 +51,23 @@ struct string *add_duration_to_string(struct string *string, long seconds);
|
||||
struct string *add_timeval_to_string(struct string *string, timeval_T *timeval);
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
/* Uses strftime() to add @fmt time format to @string. If @time is NULL
|
||||
* time(NULL) will be used. */
|
||||
/** Uses strftime() to format @a time according to @a format and adds
|
||||
* the result to @a string. If @a time is NULL, time(NULL) will be
|
||||
* used. */
|
||||
struct string *add_date_to_string(struct string *string,
|
||||
const unsigned char *format,
|
||||
const time_t *time);
|
||||
#endif
|
||||
|
||||
|
||||
/* Encoders: */
|
||||
/* They encode and add to the string. This way we don't need to first allocate
|
||||
/** @name Encoders:
|
||||
* They encode and add to the string. This way we don't need to first allocate
|
||||
* and encode a temporary string, add it and then free it. Can be used as
|
||||
* backends for encoder. */
|
||||
* backends for encoder.
|
||||
* @{ */
|
||||
|
||||
/* A simple generic encoder. Should maybe take @replaceable as a string so we
|
||||
* could also use it for adding shell safe strings. */
|
||||
/** A simple generic encoder. Should maybe take @a replaceable as a
|
||||
* string so we could also use it for adding shell safe strings. */
|
||||
struct string *
|
||||
add_string_replace(struct string *string, unsigned char *src, int len,
|
||||
unsigned char replaceable, unsigned char replacement);
|
||||
@ -73,36 +75,37 @@ add_string_replace(struct string *string, unsigned char *src, int len,
|
||||
#define add_optname_to_string(str, src, len) \
|
||||
add_string_replace(str, src, len, '.', '*')
|
||||
|
||||
/* Maybe a bad name but it is actually the real name, but you may also think of
|
||||
* it as adding the decoded option name. */
|
||||
/** Maybe a bad name but it is actually the real name, but you may
|
||||
* also think of it as adding the decoded option name. */
|
||||
#define add_real_optname_to_string(str, src, len) \
|
||||
add_string_replace(str, src, len, '*', '.')
|
||||
|
||||
/* Convert reserved chars to html &#xx;. This function copies bytes
|
||||
/** Convert reserved chars to html @&@#xx;. This function copies bytes
|
||||
* 0x80...0xFF unchanged, so the caller should ensure that the
|
||||
* resulting HTML will be parsed with the same charset as the original
|
||||
* string. (This function cannot use the   syntax for non-ASCII,
|
||||
* string. (This function cannot use the @&@#160; syntax for non-ASCII,
|
||||
* because HTML wants Unicode numbers there and this function does not
|
||||
* know the charset of the input data.) */
|
||||
struct string *add_html_to_string(struct string *string, const unsigned char *html, int htmllen);
|
||||
|
||||
/* Convert reserved or non-ASCII chars to html &#xx;. The resulting
|
||||
/** Convert reserved or non-ASCII chars to html @&@#xx;. The resulting
|
||||
* string can be correctly parsed in any charset where bytes
|
||||
* 0x20...0x7E match ASCII. */
|
||||
struct string *add_cp_html_to_string(struct string *string, int src_codepage,
|
||||
const unsigned char *html, int htmllen);
|
||||
|
||||
/* Escapes \ and " with a \ */
|
||||
/** Escapes @\ and " with a @\ */
|
||||
struct string *add_quoted_to_string(struct string *string, const unsigned char *q, int qlen);
|
||||
|
||||
/* Adds ', |len| bytes of |src| with all single-quotes converted to '\'',
|
||||
* and ' to |string|. */
|
||||
/** Adds ', @a len bytes of @a src with all single-quotes converted to '\'',
|
||||
* and ' to @a string. */
|
||||
struct string *add_shell_quoted_to_string(struct string *string,
|
||||
unsigned char *src, int len);
|
||||
|
||||
/* Escapes non shell safe chars with '_'. */
|
||||
struct string *add_shell_safe_to_string(struct string *string, unsigned char *cmd, int cmdlen);
|
||||
|
||||
/** @} */
|
||||
|
||||
/* These are fast functions to convert integers to string, or to hexadecimal string. */
|
||||
|
||||
@ -115,7 +118,7 @@ int elinks_longcat(unsigned char *s, unsigned int *slen, long number,
|
||||
unsigned int upper);
|
||||
|
||||
/* Type casting is enforced, to shorten calls. --Zas */
|
||||
/* unsigned long to decimal string */
|
||||
/** unsigned long to decimal string */
|
||||
#define ulongcat(s, slen, number, width, fillchar) \
|
||||
elinks_ulongcat((unsigned char *) (s), \
|
||||
(unsigned int *) (slen), \
|
||||
@ -125,7 +128,7 @@ int elinks_longcat(unsigned char *s, unsigned int *slen, long number,
|
||||
(unsigned int) 10, \
|
||||
(unsigned int) 0)
|
||||
|
||||
/* signed long to decimal string */
|
||||
/** signed long to decimal string */
|
||||
#define longcat(s, slen, number, width, fillchar) \
|
||||
elinks_longcat((unsigned char *) (s), \
|
||||
(unsigned int *) (slen), \
|
||||
@ -135,7 +138,7 @@ int elinks_longcat(unsigned char *s, unsigned int *slen, long number,
|
||||
(unsigned int) 10, \
|
||||
(unsigned int) 0)
|
||||
|
||||
/* unsigned long to hexadecimal string */
|
||||
/** unsigned long to hexadecimal string */
|
||||
#define ulonghexcat(s, slen, number, width, fillchar, upper) \
|
||||
elinks_ulongcat((unsigned char *) (s), \
|
||||
(unsigned int *) (slen), \
|
||||
@ -146,19 +149,15 @@ int elinks_longcat(unsigned char *s, unsigned int *slen, long number,
|
||||
(unsigned int) (upper))
|
||||
|
||||
|
||||
/* XXX: Compatibility only. Remove these at some time. --Zas */
|
||||
#define snprint(str, len, num) ulongcat(str, NULL, num, len, 0);
|
||||
#define snzprint(str, len, num) longcat(str, NULL, num, len, 0);
|
||||
|
||||
/* Return 0 if starting with jan, 11 for dec, -1 for failure.
|
||||
* @month must be a lowercased string. */
|
||||
/** Return 0 if starting with jan, 11 for dec, -1 for failure.
|
||||
* @a month must be a lowercased string. */
|
||||
int month2num(const unsigned char *month);
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Trim starting and ending chars equal to @c in string @s.
|
||||
* If @len != NULL, it stores new string length in pointed integer.
|
||||
* It returns @s for convenience. */
|
||||
/** Trim starting and ending chars equal to @a c in string @a s.
|
||||
* If @a len != NULL, it stores new string length in pointed integer.
|
||||
* It returns @a s for convenience. */
|
||||
static inline unsigned char *
|
||||
trim_chars(unsigned char *s, unsigned char c, int *len)
|
||||
{
|
||||
@ -174,7 +173,8 @@ trim_chars(unsigned char *s, unsigned char c, int *len)
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Convert uppercase letters in @string with the given @length to lowercase. */
|
||||
/** Convert uppercase letters in @a string with the given @a length to
|
||||
* lowercase. */
|
||||
static inline void
|
||||
convert_to_lowercase(unsigned char *string, int length)
|
||||
{
|
||||
@ -183,15 +183,15 @@ convert_to_lowercase(unsigned char *string, int length)
|
||||
string[length] = tolower(string[length]);
|
||||
}
|
||||
|
||||
/* This function drops control chars, nbsp char and limit the number of consecutive
|
||||
* space chars to one. It modifies its argument. */
|
||||
/** This function drops control chars, nbsp char and limit the number
|
||||
* of consecutive space chars to one. It modifies its argument. */
|
||||
void clr_spaces(unsigned char *str);
|
||||
|
||||
/* Replace invalid chars in @title with ' ' and trim all starting/ending
|
||||
/** Replace invalid chars in @a title with ' ' and trim all starting/ending
|
||||
* spaces. */
|
||||
void sanitize_title(unsigned char *title);
|
||||
|
||||
/* Returns 0 if @url contains invalid chars, 1 if ok.
|
||||
/** Returns 0 if @a url contains invalid chars, 1 if ok.
|
||||
* It trims starting/ending spaces. */
|
||||
int sanitize_url(unsigned char *url);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Environment variables handling */
|
||||
/** Environment variables handling
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -16,11 +17,11 @@
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
|
||||
/* Set @name environment variable to @value or a substring of it:
|
||||
/** Set @a name environment variable to @a value or a substring of it:
|
||||
* On success, it returns 0.
|
||||
* If @value is NULL and on error, it returns -1.
|
||||
* If @length >= 0 and smaller than true @value length, it will
|
||||
* set @name to specified substring of @value.
|
||||
* If @a value is NULL and on error, it returns -1.
|
||||
* If @a length >= 0 and smaller than true @a value length, it will
|
||||
* set @a name to specified substring of @a value.
|
||||
*/
|
||||
int
|
||||
env_set(unsigned char *name, unsigned char *value, int length)
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Error handling and debugging stuff */
|
||||
/** Error handling and debugging stuff
|
||||
* @file */
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE /* Needed for vasprintf() */
|
||||
|
@ -1,26 +1,27 @@
|
||||
#ifndef EL__UTIL_ERROR_H
|
||||
#define EL__UTIL_ERROR_H
|
||||
|
||||
|
||||
/* Here you will found a chunk of functions useful for error states --- from
|
||||
/** Error handling and debugging stuff
|
||||
* @file
|
||||
*
|
||||
* Here you will found a chunk of functions useful for error states --- from
|
||||
* reporting of various problems to generic error tests/workarounds to some
|
||||
* tools to be used when you got into an error state already. Some of the
|
||||
* functions are also useful for debugging. */
|
||||
|
||||
#ifndef EL__UTIL_ERROR_H
|
||||
#define EL__UTIL_ERROR_H
|
||||
|
||||
/* This errfile thing is needed, as we don't have var-arg macros in standart,
|
||||
* only as gcc extension :(. */
|
||||
extern int errline;
|
||||
extern const unsigned char *errfile;
|
||||
|
||||
/* @DBG(format_string) is used for printing of debugging information. It
|
||||
/** @c DBG(format_string) is used for printing of debugging information. It
|
||||
* should not be used anywhere in the official codebase (although it is often
|
||||
* lying there commented out, as it may get handy). */
|
||||
#undef DBG
|
||||
#define DBG errfile = __FILE__, errline = __LINE__, elinks_debug
|
||||
void elinks_debug(unsigned char *fmt, ...);
|
||||
|
||||
/* @WDBG(format_string) is used for printing of debugging information, akin
|
||||
/** @c WDBG(format_string) is used for printing of debugging information, akin
|
||||
* to DBG(). However, it sleep(1)s, therefore being useful when it is going
|
||||
* to be overdrawn or so. It should not be used anywhere in the official
|
||||
* codebase (although it is often lying there commented out, as it may get
|
||||
@ -29,7 +30,7 @@ void elinks_debug(unsigned char *fmt, ...);
|
||||
#define WDBG errfile = __FILE__, errline = __LINE__, elinks_wdebug
|
||||
void elinks_wdebug(unsigned char *fmt, ...);
|
||||
|
||||
/* @ERROR(format_string) is used to report non-fatal unexpected errors during
|
||||
/** @c ERROR(format_string) is used to report non-fatal unexpected errors during
|
||||
* the ELinks run. It tries to (not that agressively) draw user's attention to
|
||||
* the error, but never dumps core or so. Note that this should be used only in
|
||||
* cases of non-severe internal inconsistences etc, never as an indication of
|
||||
@ -39,7 +40,7 @@ void elinks_wdebug(unsigned char *fmt, ...);
|
||||
#define ERROR errfile = __FILE__, errline = __LINE__, elinks_error
|
||||
void elinks_error(unsigned char *fmt, ...);
|
||||
|
||||
/* @INTERNAL(format_string) is used to report fatal errors during the ELinks
|
||||
/** @c INTERNAL(format_string) is used to report fatal errors during the ELinks
|
||||
* run. It tries to draw user's attention to the error and dumps core if ELinks
|
||||
* is running in the CONFIG_DEBUG mode. */
|
||||
#undef INTERNAL
|
||||
@ -47,7 +48,7 @@ void elinks_error(unsigned char *fmt, ...);
|
||||
void elinks_internal(unsigned char *fmt, ...);
|
||||
|
||||
|
||||
/* @usrerror(format_string) is used to report user errors during a peaceful
|
||||
/** @c usrerror(format_string) is used to report user errors during a peaceful
|
||||
* ELinks run. It does not belong to the family above - it doesn't print code
|
||||
* location, beep nor sleep, it just wraps around fprintf(stderr, "...\n");. */
|
||||
void usrerror(unsigned char *fmt, ...);
|
||||
@ -55,16 +56,18 @@ void usrerror(unsigned char *fmt, ...);
|
||||
|
||||
#ifdef HAVE_VARIADIC_MACROS
|
||||
#ifdef CONFIG_DEBUG
|
||||
/* The LOG_*() macros can be used to log to a file, however, by default log
|
||||
/** The @c LOG_*() macros can be used to log to a file, however, by default log
|
||||
* messages are written to stderr. Set the following environment variables
|
||||
* to configure the log behavior:
|
||||
*
|
||||
* ELINKS_LOG - The path to the log file, it is opened for appending
|
||||
* ELINKS_MSG - A comma separated list containing "error", "warn",
|
||||
* "info" and/or "debug" which can be used to limit
|
||||
* what messages to emit to the log.
|
||||
* ELINKS_FILES - A comma separated list of which files names to
|
||||
* emit log messages from.
|
||||
* <dl>
|
||||
* <dt>ELINKS_LOG <dd>The path to the log file, it is opened for appending
|
||||
* <dt>ELINKS_MSG <dd>A comma separated list containing "error", "warn",
|
||||
* "info" and/or "debug" which can be used to limit
|
||||
* what messages to emit to the log.
|
||||
* <dt>ELINKS_FILES <dd>A comma separated list of which files names to
|
||||
* emit log messages from.
|
||||
* </dl>
|
||||
*/
|
||||
void
|
||||
elinks_log(unsigned char *msg, unsigned char *file, int line,
|
||||
@ -91,10 +94,10 @@ elinks_log(unsigned char *msg, unsigned char *file, int line,
|
||||
|
||||
|
||||
|
||||
/* This is our smart assert(). It is basically equivalent to if (x) INTERNAL(),
|
||||
/** This is our smart assert(). It is basically equivalent to if (x) INTERNAL(),
|
||||
* but it generates a uniform message and mainly does not do the test if we are
|
||||
* supposed to be lightning fast. Use it, use it a lot! And never forget the
|
||||
* recovery path, see below if_assert_failed. */
|
||||
* recovery path, see below ::if_assert_failed. */
|
||||
|
||||
#undef assert
|
||||
#ifdef CONFIG_FASTMEM
|
||||
@ -107,7 +110,7 @@ do { if (!assert_failed && (assert_failed = !(x))) { \
|
||||
#endif
|
||||
|
||||
|
||||
/* This is extended assert() version, it can print additional user-specified
|
||||
/** This is extended assert() version, it can print additional user-specified
|
||||
* message. Quite useful not only to detect that _something_ is wrong, but also
|
||||
* _how_ wrong is it ;-). Note that the format string must always be a regular
|
||||
* string, not a variable reference. Also, be careful _what_ will you attempt
|
||||
@ -152,29 +155,31 @@ void elinks_assertm(int x, unsigned char *fmt, ...)
|
||||
#endif /* HAVE_VARIADIC_MACROS */
|
||||
|
||||
|
||||
/* To make recovery path possible (assertion failed may not mean end of the
|
||||
/** Whether an assertion has failed and the failure has not yet been handled.
|
||||
* To make recovery path possible (assertion failed may not mean end of the
|
||||
* world, the execution goes on if we're outside of CONFIG_DEBUG and CONFIG_FASTMEM),
|
||||
* @assert_failed is set to true if the last assert() failed, otherwise it's
|
||||
* @c assert_failed is set to true if the last assert() failed, otherwise it's
|
||||
* zero. Note that you must never change assert_failed value, sorry guys.
|
||||
*
|
||||
* You should never test assert_failed directly anyway. Use if_assert_failed
|
||||
* You should never test @c assert_failed directly anyway. Use ::if_assert_failed
|
||||
* instead, it will attempt to hint compiler to optimize out the recovery path
|
||||
* if we're CONFIG_FASTMEM. So it should go like:
|
||||
*
|
||||
* @code
|
||||
* assertm(1 == 1, "The world's gonna blow up!");
|
||||
* if_assert_failed { schedule_time_machine(); return; } */
|
||||
|
||||
/* In-depth explanation: this restriction is here because in the CONFIG_FASTMEM mode,
|
||||
* assert_failed is initially initialized to zero and then not ever touched
|
||||
* if_assert_failed { schedule_time_machine(); return; }
|
||||
* @endcode
|
||||
*
|
||||
* In-depth explanation: this restriction is here because in the CONFIG_FASTMEM mode,
|
||||
* @c assert_failed is initially initialized to zero and then not ever touched
|
||||
* anymore. So if you change it to non-zero failure, your all further recovery
|
||||
* paths will get hit (and since developers usually don't test CONFIG_FASTMEM mode
|
||||
* extensively...). So better don't mess with it, even if you would do that
|
||||
* with awareness of this fact. We don't want to iterate over tens of spots all
|
||||
* over the code when we change one detail regarding CONFIG_FASTMEM operation.
|
||||
*
|
||||
* This is not that actual after introduction of if_assert_failed, but it's
|
||||
* This is not that actual after introduction of ::if_assert_failed, but it's
|
||||
* a safe recommendation anyway, so... ;-) */
|
||||
|
||||
extern int assert_failed;
|
||||
|
||||
#undef if_assert_failed
|
||||
@ -186,17 +191,18 @@ extern int assert_failed;
|
||||
|
||||
|
||||
|
||||
/* This will print some fancy message, version string and possibly do something
|
||||
* else useful. Then, it will dump core. */
|
||||
/** This will print some fancy message, version string and possibly do
|
||||
* something else useful. Then, it will dump core. */
|
||||
#ifdef CONFIG_DEBUG
|
||||
void force_dump(void);
|
||||
#endif
|
||||
|
||||
|
||||
/* This function does nothing, except making compiler not to optimize certains
|
||||
/** This function does nothing, except making compiler not to optimize certains
|
||||
* spots of code --- this is useful when that particular optimization is buggy.
|
||||
* So we are just workarounding buggy compilers. */
|
||||
/* This function should be always used only in context of compiler version
|
||||
* So we are just workarounding buggy compilers.
|
||||
*
|
||||
* This function should be always used only in context of compiler version
|
||||
* specific macros. */
|
||||
void do_not_optimize_here(void *x);
|
||||
|
||||
@ -219,11 +225,12 @@ void do_not_optimize_here(void *x);
|
||||
#endif
|
||||
|
||||
|
||||
/* This function dumps backtrace (or whatever similiar it founds on the stack)
|
||||
* nicely formatted and with symbols resolved to @f. When @trouble is set, it
|
||||
* tells it to be extremely careful and not use dynamic memory allocation
|
||||
* functions etc (useful in SIGSEGV handler etc). */
|
||||
/* Note that this function just calls system-specific backend provided by the
|
||||
/** This function dumps backtrace (or whatever similar it founds on the stack)
|
||||
* nicely formatted and with symbols resolved to @a f. When @a trouble is set,
|
||||
* it tells it to be extremely careful and not use dynamic memory allocation
|
||||
* functions etc (useful in SIGSEGV handler etc).
|
||||
*
|
||||
* Note that this function just calls system-specific backend provided by the
|
||||
* libc, so it is available only on some systems. CONFIG_BACKTRACE is defined
|
||||
* if it is available on yours. */
|
||||
#ifdef CONFIG_BACKTRACE
|
||||
@ -231,7 +238,7 @@ void do_not_optimize_here(void *x);
|
||||
void dump_backtrace(FILE *f, int trouble);
|
||||
#endif
|
||||
|
||||
/* This is needed for providing info about features when dumping core */
|
||||
/** This is needed for providing info about features when dumping core */
|
||||
extern unsigned char full_static_version[1024];
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,57 @@
|
||||
/* Very fast search_keyword_in_list. */
|
||||
/** Very fast search_keyword_in_list.
|
||||
* @file
|
||||
*
|
||||
*
|
||||
* It replaces bsearch() + strcasecmp() + callback + ...
|
||||
*
|
||||
* Following conditions should be met:
|
||||
*
|
||||
* - list keys are C strings.
|
||||
* - keys should not be greater than 255 characters, and optimally < 20
|
||||
* characters. It can work with greater keys but then memory usage will
|
||||
* grow a lot.
|
||||
* - each key must be unique and non empty.
|
||||
* - list do not have to be ordered.
|
||||
* - total number of unique characters used in all keys should be <= 128
|
||||
* - idealy total number of keys should be <= 512 (but see below)
|
||||
*
|
||||
* (c) 2003 Laurent MONIN (aka Zas)
|
||||
* Feel free to do whatever you want with that code.
|
||||
*
|
||||
*
|
||||
* These routines use a tree search. First, a big tree is composed from the
|
||||
* keys on input. Then, when searching we just go through the tree. If we will
|
||||
* end up on an 'ending' node, we've got it.
|
||||
*
|
||||
* Hm, okay. For keys { 'head', 'h1', 'body', 'bodyrock', 'bodyground' }, it
|
||||
* would look like:
|
||||
*
|
||||
* @verbatim
|
||||
* [root]
|
||||
* b h
|
||||
* o e 1
|
||||
* d a
|
||||
* Y D
|
||||
* g r
|
||||
* r o
|
||||
* o c
|
||||
* u K
|
||||
* D
|
||||
* @endverbatim
|
||||
*
|
||||
* (the ending nodes are upcased just for this drawing, not in real)
|
||||
*
|
||||
* To optimize this for speed, leafs of nodes are organized in per-node arrays
|
||||
* (so-called 'leafsets'), indexed by symbol value of the key's next character.
|
||||
* But to optimize that for memory, we first compose own alphabet consisting
|
||||
* only from the chars we ever use in the key strings. fastfind_info.uniq_chars
|
||||
* holds that alphabet and fastfind_info.idxtab is used to translate between it
|
||||
* and ASCII.
|
||||
*
|
||||
* Tree building: O((L+M)*N)
|
||||
* (L: mean key length, M: alphabet size,
|
||||
* N: number of items).
|
||||
* String lookup: O(N) (N: string length). */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -17,61 +70,12 @@
|
||||
|
||||
#ifdef USE_FASTFIND
|
||||
|
||||
/* It replaces bsearch() + strcasecmp() + callback + ...
|
||||
*
|
||||
* Following conditions should be met:
|
||||
*
|
||||
* - list keys are C strings.
|
||||
* - keys should not be greater than 255 characters, and optimally < 20
|
||||
* characters. It can work with greater keys but then memory usage will
|
||||
* grow a lot.
|
||||
* - each key must be unique and non empty.
|
||||
* - list do not have to be ordered.
|
||||
* - total number of unique characters used in all keys should be <= 128
|
||||
* - idealy total number of keys should be <= 512 (but see below)
|
||||
*
|
||||
* (c) 2003 Laurent MONIN (aka Zas)
|
||||
* Feel free to do whatever you want with that code. */
|
||||
|
||||
|
||||
/* These routines use a tree search. First, a big tree is composed from the
|
||||
* keys on input. Then, when searching we just go through the tree. If we will
|
||||
* end up on an 'ending' node, we've got it.
|
||||
*
|
||||
* Hm, okay. For keys { 'head', 'h1', 'body', 'bodyrock', 'bodyground' }, it
|
||||
* would look like:
|
||||
*
|
||||
* [root]
|
||||
* b h
|
||||
* o e 1
|
||||
* d a
|
||||
* Y D
|
||||
* g r
|
||||
* r o
|
||||
* o c
|
||||
* u K
|
||||
* D
|
||||
*
|
||||
* (the ending nodes are upcased just for this drawing, not in real)
|
||||
*
|
||||
* To optimize this for speed, leafs of nodes are organized in per-node arrays
|
||||
* (so-called 'leafsets'), indexed by symbol value of the key's next character.
|
||||
* But to optimize that for memory, we first compose own alphabet consisting
|
||||
* only from the chars we ever use in the key strings. @uniq_chars holds that
|
||||
* alphabet and @idxtab is used to translate between it and ASCII.
|
||||
*
|
||||
* Tree building: O((L+M)*N)
|
||||
* (L: mean key length, M: alphabet size,
|
||||
* N: number of items).
|
||||
* String lookup: O(N) (N: string length). */
|
||||
|
||||
|
||||
/* Define it to generate performance and memory usage statistics to stderr. */
|
||||
/** Define it to generate performance and memory usage statistics to stderr. */
|
||||
#if 0
|
||||
#define DEBUG_FASTFIND
|
||||
#endif
|
||||
|
||||
/* Define whether to use 32 or 64 bits per compressed element. */
|
||||
/** Define whether to use 32 or 64 bits per compressed element. */
|
||||
#if 1
|
||||
#define USE_32_BITS
|
||||
#endif
|
||||
@ -114,16 +118,16 @@
|
||||
#endif
|
||||
|
||||
struct ff_node {
|
||||
/* End leaf -> p is significant */
|
||||
/** End leaf -> p is significant */
|
||||
unsigned int e:END_LEAF_BITS;
|
||||
|
||||
/* Compressed */
|
||||
/** Compressed */
|
||||
unsigned int c:COMPRESSED_BITS;
|
||||
|
||||
/* Index in pointers */
|
||||
/** Index in pointers */
|
||||
unsigned int p:POINTER_INDEX_BITS;
|
||||
|
||||
/* Index in leafsets */
|
||||
/** Index in leafsets */
|
||||
unsigned int l:LEAFSET_INDEX_BITS;
|
||||
};
|
||||
|
||||
@ -141,7 +145,7 @@ struct ff_node_c {
|
||||
unsigned int p:POINTER_INDEX_BITS;
|
||||
unsigned int l:LEAFSET_INDEX_BITS;
|
||||
|
||||
/* Index of char when compressed. */
|
||||
/** Index of char when compressed. */
|
||||
unsigned int ch:COMP_CHAR_INDEX_BITS;
|
||||
};
|
||||
|
||||
@ -212,7 +216,7 @@ struct fastfind_info {
|
||||
} while (0)
|
||||
#define FF_DBG_comment(x, str) do { (x)->debug.comment = empty_string_or_(str); } while (0)
|
||||
|
||||
/* Update search stats. */
|
||||
/** Update search stats. */
|
||||
static void
|
||||
FF_DBG_search_stats(struct fastfind_info *info, int key_len)
|
||||
{
|
||||
@ -222,7 +226,7 @@ FF_DBG_search_stats(struct fastfind_info *info, int key_len)
|
||||
info->debug.itertmp = info->debug.iterations;
|
||||
}
|
||||
|
||||
/* Dump all stats. */
|
||||
/** Dump all stats. */
|
||||
static void
|
||||
FF_DBG_dump_stats(struct fastfind_info *info)
|
||||
{
|
||||
@ -296,7 +300,7 @@ init_fastfind(struct fastfind_index *index, enum fastfind_flags flags)
|
||||
return info;
|
||||
}
|
||||
|
||||
/* Return 1 on success, 0 on allocation failure */
|
||||
/** @returns 1 on success, 0 on allocation failure */
|
||||
static int
|
||||
alloc_ff_data(struct fastfind_info *info)
|
||||
{
|
||||
@ -315,7 +319,7 @@ alloc_ff_data(struct fastfind_info *info)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Add pointer and its key length to correspondant arrays, incrementing
|
||||
/** Add pointer and its key length to correspondant arrays, incrementing
|
||||
* internal counter. */
|
||||
static void
|
||||
add_to_ff_data(void *p, int key_len, struct fastfind_info *info)
|
||||
@ -327,7 +331,7 @@ add_to_ff_data(void *p, int key_len, struct fastfind_info *info)
|
||||
data->keylen = key_len;
|
||||
}
|
||||
|
||||
/* Return 1 on success, 0 on allocation failure */
|
||||
/** @returns 1 on success, 0 on allocation failure */
|
||||
static int
|
||||
alloc_leafset(struct fastfind_info *info)
|
||||
{
|
||||
@ -542,7 +546,7 @@ return_error:
|
||||
#undef ifcase
|
||||
|
||||
|
||||
/* This macro searchs for the key in indexed list */
|
||||
/** This macro searchs for the key in indexed list */
|
||||
#define FF_SEARCH(what) do { \
|
||||
int i; \
|
||||
\
|
||||
@ -729,14 +733,14 @@ struct list list[] = {
|
||||
|
||||
struct list *internal_pointer;
|
||||
|
||||
/* Reset internal list pointer */
|
||||
/** Reset internal list pointer */
|
||||
void
|
||||
reset_list(void)
|
||||
{
|
||||
internal_pointer = list;
|
||||
}
|
||||
|
||||
/* Returns a pointer to a struct that contains
|
||||
/** Returns a pointer to a struct that contains
|
||||
* current key and data pointers and increment
|
||||
* internal pointer.
|
||||
* It returns NULL when key is NULL. */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef EL__UTIL_FASTFIND_H
|
||||
#define EL__UTIL_FASTFIND_H
|
||||
|
||||
/* Whether to use these routines or not. */
|
||||
/** Whether to use these routines or not. */
|
||||
#ifndef CONFIG_SMALL
|
||||
#define USE_FASTFIND 1
|
||||
#else
|
||||
@ -17,39 +17,40 @@ struct fastfind_key_value {
|
||||
|
||||
enum fastfind_flags {
|
||||
FF_NONE = 0,
|
||||
FF_CASE_AWARE = 1, /* honour case when comparing */
|
||||
FF_COMPRESS = 2, /* compress nodes if possible */
|
||||
FF_CASE_AWARE = 1, /**< honour case when comparing */
|
||||
FF_COMPRESS = 2, /**< compress nodes if possible */
|
||||
};
|
||||
|
||||
struct fastfind_index {
|
||||
/* Description useful for debugging mode. */
|
||||
/** Description useful for debugging mode. */
|
||||
unsigned char *comment;
|
||||
/* Start over. */
|
||||
/** Start over. */
|
||||
void (*reset)(void);
|
||||
/* Get next struct fastfind_key_value in line. */
|
||||
/** Get next struct fastfind_key_value in line. */
|
||||
struct fastfind_key_value *(*next)(void);
|
||||
/* Internal reference */
|
||||
/** Internal reference */
|
||||
void *handle;
|
||||
};
|
||||
|
||||
#define INIT_FASTFIND_INDEX(comment, reset, next) \
|
||||
{ (comment), (reset), (next) }
|
||||
|
||||
/* Initialize and index a list of keys. */
|
||||
/* Keys are iterated using:
|
||||
* @index index info
|
||||
* @flags control case sensitivity, compression */
|
||||
/* This function must be called once and only once per list. */
|
||||
/* Failure is not an option, so call it at startup. */
|
||||
/** Initialize and index a list of keys.
|
||||
* Keys are iterated using:
|
||||
* @param index index info
|
||||
* @param flags control case sensitivity, compression
|
||||
*
|
||||
* This function must be called once and only once per list.
|
||||
* Failure is not an option, so call it at startup. */
|
||||
struct fastfind_index *fastfind_index(struct fastfind_index *index, enum fastfind_flags flags);
|
||||
|
||||
/* The main reason of all that stuff is here. */
|
||||
/* Search the index for @key with length @key_len using the
|
||||
* @index' handle created with fastfind_index(). */
|
||||
/** Search the index for @a key with length @a key_len using the
|
||||
* @a index' handle created with fastfind_index(). */
|
||||
void *fastfind_search(struct fastfind_index *index, unsigned char *key, int key_len);
|
||||
|
||||
/* Fastfind cleanup. It frees the index given by the @fastfind_handle. */
|
||||
/* Must be called once per list. */
|
||||
/** Fastfind cleanup. It frees the given @a index.
|
||||
* Must be called once per list. */
|
||||
void fastfind_done(struct fastfind_index *index);
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* File utilities */
|
||||
/** File utilities
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -283,7 +284,8 @@ safe_mkstemp(unsigned char *template)
|
||||
}
|
||||
|
||||
|
||||
/* The stat_* functions set the various attributes for directory entries. */
|
||||
/** @name The stat_* functions set the various attributes for directory entries.
|
||||
* @{ */
|
||||
|
||||
static inline void
|
||||
stat_type(struct string *string, struct stat *stp)
|
||||
@ -476,6 +478,8 @@ stat_date(struct string *string, struct stat *stp)
|
||||
add_to_string(string, " ");
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
static int
|
||||
compare_dir_entries(struct directory_entry *d1, struct directory_entry *d2)
|
||||
@ -488,8 +492,8 @@ compare_dir_entries(struct directory_entry *d1, struct directory_entry *d2)
|
||||
}
|
||||
|
||||
|
||||
/* This function decides whether a file should be shown in directory listing or
|
||||
* not. Returns according boolean value. */
|
||||
/** This function decides whether a file should be shown in directory
|
||||
* listing or not. @returns according boolean value. */
|
||||
static inline int
|
||||
file_visible(unsigned char *name, int get_hidden_files, int is_root_directory)
|
||||
{
|
||||
@ -510,9 +514,8 @@ file_visible(unsigned char *name, int get_hidden_files, int is_root_directory)
|
||||
return get_hidden_files;
|
||||
}
|
||||
|
||||
/* First information such as permissions is gathered for each directory entry.
|
||||
* All entries are then sorted and finally the sorted entries are added to the
|
||||
* @data->fragment one by one. */
|
||||
/** First information such as permissions is gathered for each directory entry.
|
||||
* All entries are then sorted. */
|
||||
struct directory_entry *
|
||||
get_directory_entries(unsigned char *dirname, int get_hidden)
|
||||
{
|
||||
@ -585,7 +588,7 @@ get_directory_entries(unsigned char *dirname, int get_hidden)
|
||||
return entries;
|
||||
}
|
||||
|
||||
/* Recursively create directories in a path. The last element in the path is
|
||||
/** Recursively create directories in @a path. The last element in the path is
|
||||
* taken to be a filename, and simply ignored */
|
||||
int
|
||||
mkalldirs(const unsigned char *path)
|
||||
|
@ -4,18 +4,18 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/** Data read about an entry in a directory.
|
||||
* The strings pointed to by this structure are in the system
|
||||
* charset (i.e. LC_CTYPE) and must be freed with mem_free(). */
|
||||
struct directory_entry {
|
||||
/* The strings pointed to by this structure are in the system
|
||||
* charset (i.e. LC_CTYPE) and must be freed with mem_free. */
|
||||
|
||||
/* The various attribute info collected with the stat_* functions. */
|
||||
/** The various attribute info collected with the @c stat_* functions. */
|
||||
unsigned char *attrib;
|
||||
|
||||
/* The full path of the dir entry. */
|
||||
/** The full path of the dir entry. */
|
||||
unsigned char *name;
|
||||
};
|
||||
|
||||
/* First information such as permissions is gathered for each directory entry.
|
||||
/** First information such as permissions is gathered for each directory entry.
|
||||
* All entries are then sorted. */
|
||||
struct directory_entry *
|
||||
get_directory_entries(unsigned char *dirname, int get_hidden_files);
|
||||
@ -24,37 +24,38 @@ int file_exists(const unsigned char *filename);
|
||||
int file_can_read(const unsigned char *filename);
|
||||
int file_is_dir(const unsigned char *filename);
|
||||
|
||||
/* Strips all directory stuff from @filename and returns the
|
||||
/** Strips all directory stuff from @a filename and returns the
|
||||
* position of where the actual filename starts */
|
||||
unsigned char *get_filename_position(unsigned char *filename);
|
||||
|
||||
/* Tilde is only expanded for the current users homedir (~/). */
|
||||
/* The returned file name is allocated. */
|
||||
/** Tilde is only expanded for the current users homedir (~/).
|
||||
* The returned file name is allocated. */
|
||||
unsigned char *expand_tilde(unsigned char *filename);
|
||||
|
||||
/* Generate a unique file name by trial and error based on the @fileprefix by
|
||||
* adding suffix counter (e.g. '.42'). */
|
||||
/* The returned file name is allocated if @fileprefix is not unique. */
|
||||
/*! \brief Generate a unique file name by trial and error based on the
|
||||
* @a fileprefix by adding suffix counter (e.g. '.42').
|
||||
*
|
||||
* The returned file name is allocated if @a fileprefix is not unique. */
|
||||
unsigned char *get_unique_name(unsigned char *fileprefix);
|
||||
|
||||
/* Checks various environment variables to get the name of the temp dir.
|
||||
/** Checks various environment variables to get the name of the temp dir.
|
||||
* Returns a filename by concatenating "<tmpdir>/<name>". */
|
||||
unsigned char *get_tempdir_filename(unsigned char *name);
|
||||
|
||||
/* Read a line from @file into the dynamically allocated @line, increasing
|
||||
* @line if necessary. Ending whitespace is trimmed. If a line ends
|
||||
* with "\" the next line is read too. */
|
||||
/* If @line is NULL the returned line is allocated and if file reading fails
|
||||
* @line is free()d. */
|
||||
/** Read a line from @a file into the dynamically allocated @a line,
|
||||
* increasing @a line if necessary. Ending whitespace is trimmed.
|
||||
* If a line ends with "\" the next line is read too.
|
||||
* If @a line is NULL the returned line is allocated and if file
|
||||
* reading fails @a line is free()d. */
|
||||
unsigned char *file_read_line(unsigned char *line, size_t *linesize,
|
||||
FILE *file, int *linenumber);
|
||||
|
||||
/* Safe wrapper for mkstemp().
|
||||
/** Safe wrapper for mkstemp().
|
||||
* It enforces permissions by calling umask(0177), call mkstemp(), then
|
||||
* restore previous umask(). */
|
||||
int safe_mkstemp(unsigned char *template);
|
||||
|
||||
/* Recursively create directories in a path. The last element in the path is
|
||||
/** Recursively create directories in @a path. The last element in the path is
|
||||
* taken to be a filename, and simply ignored */
|
||||
int mkalldirs(const unsigned char *path);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* Hashing infrastructure */
|
||||
/** Hashing infrastructure
|
||||
* @file */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@ -71,11 +72,12 @@ free_hash(struct hash **hashp)
|
||||
}
|
||||
|
||||
|
||||
/* I've no much idea about what to set here.. I think it doesn't matter much
|
||||
/** Initialization vector for the hash function.
|
||||
* I've no much idea about what to set here.. I think it doesn't matter much
|
||||
* anyway.. ;) --pasky */
|
||||
#define HASH_MAGIC 0xdeadbeef
|
||||
|
||||
/* Returns hash_item if ok, NULL if error. */
|
||||
/** @returns hash_item if ok, NULL if error. */
|
||||
struct hash_item *
|
||||
add_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen,
|
||||
void *value)
|
||||
@ -123,7 +125,8 @@ get_hash_item(struct hash *hash, unsigned char *key, unsigned int keylen)
|
||||
|
||||
#undef HASH_MAGIC
|
||||
|
||||
/* If key and/or value were dynamically allocated, think about freeing them.
|
||||
/** Delete @a item from @a hash.
|
||||
* If key and/or value were dynamically allocated, think about freeing them.
|
||||
* This function doesn't do that. */
|
||||
void
|
||||
del_hash_item(struct hash *hash, struct hash_item *item)
|
||||
@ -138,11 +141,14 @@ del_hash_item(struct hash *hash, struct hash_item *item)
|
||||
|
||||
#ifdef X31_HASH
|
||||
|
||||
/* Fast string hashing. */
|
||||
/** Fast string hashing.
|
||||
* @param k the key
|
||||
* @param length the length of the key
|
||||
* @param initval the previous hash, or an arbitrary value */
|
||||
static hash_value_T
|
||||
strhash(unsigned char *k, /* the key */
|
||||
unsigned int length, /* the length of the key */
|
||||
hash_value_T initval /* the previous hash, or an arbitrary value */)
|
||||
strhash(unsigned char *k,
|
||||
unsigned int length,
|
||||
hash_value_T initval)
|
||||
{
|
||||
const unsigned char *p = (const unsigned char *) k;
|
||||
hash_value_T h = initval;
|
||||
@ -260,10 +266,14 @@ strhash(unsigned char *k, /* the key */
|
||||
+ ((hash_value_T) (k[(a)+2])<<16) \
|
||||
+ ((hash_value_T) (k[(a)+3])<<24))
|
||||
|
||||
/** Hash an array of bytes.
|
||||
* @param k the key
|
||||
* @param length the length of the key
|
||||
* @param initval the previous hash, or an arbitrary value */
|
||||
static hash_value_T
|
||||
strhash(unsigned char *k, /* the key */
|
||||
unsigned int length, /* the length of the key */
|
||||
hash_value_T initval /* the previous hash, or an arbitrary value */)
|
||||
strhash(unsigned char *k,
|
||||
unsigned int length,
|
||||
hash_value_T initval)
|
||||
{
|
||||
int len;
|
||||
hash_value_T a, b, c;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "util/lists.h"
|
||||
|
||||
/* This should be hopefully always 32bit at least. I'm not sure what will
|
||||
/** This should be hopefully always 32bit at least. I'm not sure what will
|
||||
* happen when this will be of other length, but it should still work ok.
|
||||
* --pasky */
|
||||
typedef unsigned long hash_value_T;
|
||||
@ -18,9 +18,9 @@ struct hash_item {
|
||||
};
|
||||
|
||||
struct hash {
|
||||
unsigned int width; /* Number of bits - hash array must be 2^width long. */
|
||||
unsigned int width; /**< Number of bits - hash array must be 2^width long. */
|
||||
hash_func_T func;
|
||||
struct list_head hash[1]; /* Must be at end ! */
|
||||
struct list_head hash[1]; /**< Must be at end ! */
|
||||
};
|
||||
|
||||
struct hash *init_hash8(void);
|
||||
|
@ -14,7 +14,7 @@
|
||||
*
|
||||
* Fixing this would be a nice and needed janitorial project. */
|
||||
|
||||
/* Lists debugging
|
||||
/** Lists debugging.
|
||||
* Two unsigned int magic number will be put before and after the next and
|
||||
* prev pointers, these will be check on list operations.
|
||||
* Some pointers are set to specific values after action. */
|
||||
@ -81,7 +81,7 @@ do { \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Backend for list_magic_check() and list_magic_chkbool(). */
|
||||
/** Backend for list_magic_check() and list_magic_chkbool(). */
|
||||
#define list_magic_correct(x) ((x).magic1 == LISTMAGIC1 && (x).magic2 == LISTMAGIC2)
|
||||
|
||||
#define list_magic_check(x, where) \
|
||||
|