File: utils.h

package info (click to toggle)
cronosii 0.2.2.23.1-3.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,416 kB
  • ctags: 2,009
  • sloc: ansic: 28,566; sh: 2,548; makefile: 565; sed: 93
file content (220 lines) | stat: -rw-r--r-- 4,794 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*  Cronos II
 *  Copyright (C) 2000-2001 Pablo Fernndez Navarro
 *
 *  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-1307, USA.
 */
#ifndef UTILS_H
#define UTILS_H

#ifdef __cplusplus
extern "C" {
#endif

#if USE_GNOME
#  include <gnome.h>
#else
#  include <gtk/gtk.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CONFIG_FILE g_strconcat (getenv ("HOME"), ROOT, CONFIG, NULL)

#define CHAR(obj)		((char *) obj)

#define ALLOC(size)		g_malloc0(size)
#define CHARALLOC(size)		g_new0 (char, size+1)

#define PTHREAD2_NEW		g_new0 (Pthread2, 1)
#define PTHREAD3_NEW		g_new0 (Pthread3, 1)
#define PTHREAD2(obj)		((Pthread2 *) obj)
#define PTHREAD3(obj)		((Pthread3 *) obj)
#define PTHREAD4(obj)		((Pthread4 *) obj)

#define strne(x,y)		(!streq (x,y))
#define strnne(x,y,z)		(!strneq (x,y,z))
#define strcasene(x,y)		(!strcaseeq (x,y))
#define strncasene(x,y,z)	(!strncaseeq (x,y,z))

typedef void *(*PthreadFunc)	(void*);
#define PTHREAD_FUNC(f)		((PthreadFunc) f)

typedef guint32 gunichar;

typedef struct {
  gpointer v1;
  gpointer v2;
} Pthread2;

typedef struct {
  gpointer v1;
  gpointer v2;
  gpointer v3;
} Pthread3;

typedef struct {
  gpointer v1;
  gpointer v2;
  gpointer v3;
  gpointer v4;
} Pthread4;

char *
str_get_word						(guint8 word_n, const char *str, char ch);

char *
str_caps_lock_on					(const char *str);

char *
str_strip						(char *str, char ch);

char *
str_strip_enclosed					(const char *str, char open, char close);

gboolean
str_utf8_validate					(const gchar *str, gint max_len, const gchar **end);

char *
str_strip_non_utf8					(char *str);

gboolean
strcaseeq						(const char *fst, const char *snd);

gboolean
strncaseeq						(const char *fst, const char *snd, int length);

gboolean
streq							(const char *fst, const char *snd);

gboolean
strneq							(const char *fst, const char *snd, int length);

void
str_unquote						(char **str);

char *
str_get_line						(const char *str);

char *
str_replace						(const char *or_string, const char *se_string,
    							 const char *re_string);

const char *
strcasestr						(const char *_string, const char *_find);

char *
str_replace_all						(const char *or_string, const char *se_string,
    							 const char *re_string);

int
find_string						(const char *haystack, const char *needle);

char *
str_get_mail_address					(const char *to);

char *
strstrcase						(char *haystack, char *needle);

char *
strip_common_subject_prefixes				(char *string);

gboolean
c2_file_exists						(const char *file);

/* Returns the next word in the "fd" pointer */
char *
fd_get_word						(FILE *fd);

/* Returns the next line in the "fd" pointer */
char *
fd_get_line						(FILE *fd);

/* Returns true if path is a directory */
gboolean
fd_is_dir		(char *path);

/* 
 * Moves backward (!"forward") or "forward" ("forward") in the fd pointer "fp" searching for the character "c"
 * "cant" times and leaving the pointer before (!"next") or after ("next") "c"
 */
gboolean
fd_move_to	(FILE *fp, int c, guint8 cant,  gboolean forward, gboolean next);

const char *
pixmap_get_icon_by_mime_type	(const char *mime_type);

/* Returns the path to a tmp file */
char *
cronos_tmpfile						(void);

int
fd_bin_cp						(const char *strfrm, const char *strdst);

/* Copy a file to other */
gboolean
fd_cp							(char *str_frm, char *str_dst);

/* Moves a file to other */
gboolean
fd_mv							(char *str_frm, char *str_dst);

typedef struct {
  gint day_of_week;
  gint day;
  gint month;
  gint year;
  gint hour;
  gint minute;
  gint second;
  gdouble original_tz_offset;
  gint bestguess;
} date_t;

date_t
parse_date						(char *datestr);

date_t
adjust_date_t_for_timezone				(date_t date);

date_t
parse_rfc822_date					(GList *tokens);

date_t
parse_bestguess_date					(GList *tokens);

gint
get_days_in_month					(gint month, gint year);

gint
weekday_toi						(gchar *string);

gint
month_toi						(gchar *string);

gdouble
rfc1123_timezone_tod					(gchar *timezonestring);

GList *
g_list_strtok						(char *string, char *delimeters);

char *
cronos_system						(const char *string);

#ifdef __cplusplus
}
#endif

#endif