annotate console/libgnt/gntutils.c @ 14263:d7b40a686355

[gaim-migrate @ 16945] Don't call gethostbyname in a thread because it's not thread-safe. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 21 Aug 2006 05:49:20 +0000
parents 81648c6aa918
children fda9dc44807d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gntutils.h"
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3 void gnt_util_get_text_bound(const char *text, int *width, int *height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
4 {
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
5 const char *s = text, *last;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
6 int count = 1, max = 0;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
7 int len;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
8
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
9 /* XXX: ew ... everyone look away */
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
10 last = s;
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
11 if (s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
12 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
13 while (*s)
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
14 {
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
15 if (*s == '\n' || *s == '\r')
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
16 {
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
17 count++;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
18 len = g_utf8_pointer_to_offset(last, s);
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
19 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
20 max = len;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
21 last = s + 1;
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
22 }
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
23 s++;
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
24 }
14060
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
25
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
26 len = g_utf8_pointer_to_offset(last, s);
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
27 if (max < len)
81648c6aa918 [gaim-migrate @ 16678]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14059
diff changeset
28 max = len;
14059
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
29 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
30
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
31 if (height)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
32 *height = count;
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
33 if (width)
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
34 *width = max + (count > 1);
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
35 }
2d1b41e3cf0d [gaim-migrate @ 16674]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
36