new build system (taken from Trigger Rally -- tnx, boys!)
[syren.git] / src / syren_str.h
blob4d89652b0b7e5ca1bcab46ebade622b09eec7c86
1 /*
2 Syren -- a lightweight downloader for Linux/BSD/Win/MacOSX
3 inspired by Axel Copyright 2001-2002 Wilmer van der Gaast
4 version 0.0.6 (atomic alien)
5 coded by Ketmar // Avalon Group
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License with
18 the Debian GNU/Linux distribution in file /usr/doc/copyright/GPL;
19 if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 Suite 330, Boston, MA 02111-1307 USA
23 Syren string manipulation package
25 #ifndef _SYREN_STR_H
26 #define _SYREN_STR_H
28 #include "syren_os.h"
29 #include "syren_common.h"
32 char *SySPrintfEx (int addonBytes, const char *fmt, ...);
33 #define SySPrintf(fmt, ...) SySPrintfEx(0, fmt, __VA_ARGS__)
36 /* src can be NULL; maxlen < 0: maxlen = strlen(src?src:"") */
37 char *SyStrNew (const char *src, int maxlen);
38 #define SyStrDup(str) SyStrNew(str, -1)
39 #define SyStrNewEmpty() SyStrNew(NULL, -1)
40 void SyStrFree (char *str);
43 /* key/value lists */
44 typedef struct _TSyKVListItem TSyKVListItem;
45 struct _TSyKVListItem {
46 TSyKVListItem *next;
47 char *key;
48 char *value;
49 char *ustr; /* for configs (descr); autofree */
50 void *udata; /* for configs/cookies */
51 int uidata; /* for configs/cookies */
54 typedef struct {
55 TSyKVListItem *first;
56 TSyKVListItem *last;
57 int count;
58 int casesens;
59 } TSyKVList;
62 TSyKVList *SyKVListNew (void);
63 void SyKVListFree (TSyKVList *lst);
64 void SyKVListClear (TSyKVList *lst);
65 TSyKVListItem *SyKVListFind (TSyKVList *lst, const char *key);
66 TSyResult SyKVListDelete (TSyKVList *lst, const char *key);
67 TSyKVListItem *SyKVListSet (TSyKVList *lst, const char *key, const char *value, int *newKey);
70 /* trim [dynamic] string "in-place" */
71 void SyStrTrim (char *s);
73 /* return NULL or new string */
74 char *SyURLDecode (const char *s);
75 /* return NULL or new string */
76 char *SyURLEncode (const char *s);
78 /* return NULL or new string */
79 char *SyBuildAuthStr (const char *user, const char *pass);
82 typedef enum {
83 SY_PROTO_UNKNOWN=-1,
84 SY_PROTO_HTTP=0,
85 SY_PROTO_FTP=1,
86 SY_PROTO_HTTPS=2,
88 SY_PROTO_DEFAULT=SY_PROTO_HTTP
89 } TSyProto;
90 #define SY_PROTO_DEFAULT_STR "http"
93 typedef struct {
94 TSyProto proto;
95 char *protostr;
96 char *user, *pass;
97 char *host;
98 int port; TSyBool defaultPort;
99 char *dir, *file, *query, *anchor;
100 } TSyURL;
103 TSyURL *SyURLNew (void);
104 void SyURLFree (TSyURL *url);
105 void SyURLClear (TSyURL *url);
106 TSyResult SyURLParse (TSyURL *dest, const char *urlstr);
107 TSyURL *SyURLClone (const TSyURL *src);
109 #ifdef SY_STR_URL2STR
110 /* return NULL or new string */
111 char *SyURL2StrEx (TSyURL *url, TSyBool userpass, TSyBool hidepass);
112 /* return NULL or new string */
113 char *SyURL2Str (TSyURL *url);
114 #endif
117 /* -1: error */
118 int64_t SyStr2Long (const char *s);
119 /* -1: error */
120 int SyStr2Int (const char *s);
122 TSyResult SyLong2Str (char *dest, int64_t num);
125 #ifdef SY_STR_ADDON
126 /* dest: at least 26 chars */
127 /* returns len */
128 int SyLong2StrComma (char *dest, int64_t num);
130 /* dest: at least 10 bytes */
131 void SySize2Str (char *dest, int64_t size);
133 /* dest: at least 10 bytes */
134 void SyTime2Str (char *dest, int value);
135 #endif
138 #endif