X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=string.h;h=922ba696d18ed4dded4d037bdfba3a96b23aabb3;hp=5a76c0495ea4b25d949bdd393caf060377622a71;hb=5967b31f0e4163a9be4ed5aeb01bd2c6377ffac8;hpb=7598d7747435c4de259df09bdb82911ff893113d diff --git a/string.h b/string.h index 5a76c049..922ba696 100644 --- a/string.h +++ b/string.h @@ -1,23 +1,61 @@ /* - * Copyright (C) 2006-2007 Andre Noll + * Copyright (C) 2006-2009 Andre Noll * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Licensed under the GPL v2. For licencing details see COPYING. */ /** \file string.h exported sybmols from string.c */ +/** Flags that change how content is printed into the buffer. */ +enum para_buffer_flags { + /** Prefix each buffer with its length. */ + PBF_SIZE_PREFIX = 1, +}; + +/** A string buffer used for para_printf(). */ +struct para_buffer { + /** The buffer. May be \p NULL. */ + char *buf; + /** The size of \a buf. */ + size_t size; + /** The maximal size this buffer may grow. Zero means unlimited. */ + size_t max_size; + /** \sa para_buffer_flags. */ + unsigned flags; + /** The next para_printf() will write at this offset. */ + size_t offset; + /** + * If an attempt to print into this buffer is made that would need to + * grow \a buf to a size larger than \a max_size, then this function is + * called. + */ + int (*max_size_handler)(char *buf, size_t size, void *private_data); + /** Passed to max_size_handler(). */ + void *private_data; +}; + +/** + * Write the contents of a status item to a para_buffer. + * + * \param b The para_buffer. + * \param n The number of the status item. + * \param f A format string. + * + * \return The return value of the underlying call to para_printf(). + */ +#define WRITE_STATUS_ITEM(b, n, f, ...) (\ +{ \ + int _ret; \ + if ((b)->flags & PBF_SIZE_PREFIX) { \ + _ret = para_printf((b), "%02x:" f, n, ## __VA_ARGS__); \ + } else { \ + _ret = para_printf((b), "%s: " f, status_item_list[(n)], \ + ## __VA_ARGS__); \ + } \ + _ret; \ +} \ +) + __must_check __malloc void *para_realloc(void *p, size_t size); __must_check __malloc void *para_malloc(size_t size); __must_check __malloc void *para_calloc(size_t size); @@ -25,13 +63,22 @@ __must_check __malloc char *para_strdup(const char *s); __must_check __malloc __printf_1_2 char *make_message(const char *fmt, ...); __must_check __malloc char *para_strcat(char *a, const char *b); __must_check __malloc char *para_dirname(const char *name); -__must_check __malloc char *para_basename(const char *name); -void chop(char* buf); -__must_check __malloc char *para_tmpname(void); -__must_check int para_mkstemp(char *template, mode_t mode); +__must_check char *para_basename(const char *name); +void chop(char *buf); __must_check __malloc char *para_logname(void); __must_check __malloc char *para_homedir(void); -__must_check unsigned split_args(char *args, char ***argv_ptr, const char *delim); __malloc char *para_hostname(void); -void valid_fd_012(void); - +__printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...); +/** Used for for_each_line() and for_each_line_ro(). */ +typedef int line_handler_t(char *, void *); +int for_each_line(char *buf, size_t size, line_handler_t *line_handler, + void *private_data); +int for_each_line_ro(char *buf, size_t size, line_handler_t *line_handler, + void *private_data); +int para_atoi64(const char *str, int64_t *result); +int para_atoi32(const char *str, int32_t *value); +int get_loglevel_by_name(const char *txt); +int read_size_header(const char *buf); +int create_argv(const char *buf, const char *delim, char ***result); +void free_argv(char **argv); +int para_regcomp(regex_t *preg, const char *regex, int cflags);