File: strutl.h

package info (click to toggle)
cdebconf 0.182
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,668 kB
  • sloc: ansic: 16,289; sh: 547; makefile: 438; sql: 52; perl: 13
file content (90 lines) | stat: -rw-r--r-- 2,844 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/** 
 * @brief strutl.c
 * @brief misc. routines for string handling
 */

#ifndef _STRUTL_H_
#define _STRUTL_H_

#include <stdarg.h>
#include <string.h>
#include "question.h"

#include "debian-installer/macros.h"

/* Does this compiler support sentinel checking? */
#if DI_GNUC_PREREQ(4,0)
#  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
#else
#  define ATTRIBUTE_SENTINEL
#endif

#define STRESCAPE_822      0
#define STRESCAPE_QUOTE    1
#define STRESCAPE_CAPB     2

/**
 * @brief strcmp with explicit start/stop 
 * @param s1, e1 start and stop of first string
 * @param s2, e2 start and stop of second string
 * @return -1, 0, 1 as for strcmp
 */
int strcountcmp(const char *s1, const char *e1, const char *s2, const char *e2);

/**
 * @brief Strips leading and trailing spaces from a string; also 
 *        strips trialing newline characters from the string
 * @param buf string to strip
 */
char *strstrip(char *buf);

/**
 * @brief Converts a string to lowercase
 * @param buf string to convert
 */
char *strlower(char *buf);

/**
 * @brief concatenates arbitrary number of strings to a buffer, with 
 *        bounds checking
 * @param buf output buffer
 * @param len Length of buffer
 * @param ... one or or strings to concatenate (end with NULL)
 */
void strvacat(char *buf, size_t len, ...)
#if defined(__GNUC__) && __GNUC__ >= 4
	__attribute__((sentinel))
#endif
	;
int strparsecword(char **inbuf, char *outbuf, size_t maxlen);
int strparsequoteword(char **inbuf, char *outbuf, size_t maxlen);
int strgetargc(const char *inbuf);
int strchoicesplit(const char *inbuf, char **argv, size_t maxnarg);
int strchoicesplitsort(const char *origbuf, const char *transbuf, const char *listorder, char **oargv, char **targv, int *tindex, size_t maxnarg);
int strcmdsplit(char *inbuf, char **argv, size_t maxnarg);
void strunescape(const char *inbuf, char *outbuf, const size_t maxlen, const int quote);
void strescape(const char *inbuf, char *outbuf, const size_t maxlen, const int quote);
char *unescapestr(const char *in);
char *escapestr(const char *in);
int strwrap(const char *str, const int width, char *lines[], int maxlines);
int strlongest(char **strs, int count);

size_t strwidth(const char *width);
int strpad(char *what, size_t maxsize);
int strtruncate (char *what, size_t maxsize);

typedef const char * (* lookup_function)(const char * name, void * user_data);
#define LOOKUP_FUNCTION(F) ((lookup_function) F)
char * strexpand(const char * src, lookup_function func, void * user_data);

#define STRALIGN_TAB          "\t"
#define STRALIGN_ALIGN_CENTER "\x0e"
#define STRALIGN_ALIGN_RIGHT  "\x0f"
int stralign(char **strs, int count);

char *strjoinv(const char *sep, va_list ap);
char *strjoin(const char *sep, ...) ATTRIBUTE_SENTINEL;

char *strreplace(const char *src, const char *from, const char *to);

#endif