annotate src/xs_support.c @ 660:b0743dc9165d

Change tabs to 4 spaces, everywhere.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Apr 2008 22:10:05 +0300
parents acaba070cf49
children 180d7a0250d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 Miscellaneous support functions
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
422
d2e6682d3ef8 Copyright year update
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
7 (C) Copyright 1999-2007 Tecnic Software productions (TNSP)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 (at your option) any later version.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 GNU General Public License for more details.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
412
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
19 You should have received a copy of the GNU General Public License along
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
20 with this program; if not, write to the Free Software Foundation, Inc.,
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
49
3518ca5c8b0f Support for compile-time big/little-endian optimizations in audio output
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
23 #include "xs_support.h"
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
24 #include <ctype.h>
202
fe684a2ccdc7 Reworking code.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
25
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
26
657
acaba070cf49 Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents: 634
diff changeset
27 guint16 xs_fread_be16(xs_file_t *f)
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
28 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
29 return (((guint16) xs_fgetc(f)) << 8) | ((guint16) xs_fgetc(f));
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
30 }
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
31
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
32
657
acaba070cf49 Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents: 634
diff changeset
33 guint32 xs_fread_be32(xs_file_t *f)
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
34 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
35 return (((guint32) xs_fgetc(f)) << 24) |
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
36 (((guint32) xs_fgetc(f)) << 16) |
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
37 (((guint32) xs_fgetc(f)) << 8) |
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
38 ((guint32) xs_fgetc(f));
516
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
39 }
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
40
c192468eb8ce Audacious VFS support functions finished.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
41
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
42 /* Load a file to a buffer, return 0 on success, negative value on error
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
43 */
657
acaba070cf49 Lots of cosmetic code cleanups; synced the de-gettextification from Audacious-SID, I suppose it makes some sense ...
Matti Hamalainen <ccr@tnsp.org>
parents: 634
diff changeset
44 gint xs_fload_buffer(const gchar *filename, guint8 **buf, size_t *bufSize)
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
45 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
46 xs_file_t *f;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
47 glong seekPos;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
48
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
49 /* Open file, get file size */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
50 if ((f = xs_fopen(filename, "rb")) == NULL)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
51 return -1;
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
52
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
53 xs_fseek(f, 0, SEEK_END);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
54 seekPos = xs_ftell(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
55
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
56 if (seekPos > 0) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
57 size_t readSize = seekPos;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
58 if (readSize >= *bufSize || *buf == NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
59 /* Only re-allocate if the required size > current */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
60 if (*buf != NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
61 g_free(*buf);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
62 *buf = NULL;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
63 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
64
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
65 *bufSize = seekPos;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
66
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
67 *buf = (guint8 *) g_malloc(*bufSize * sizeof(guint8));
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
68 if (*buf == NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
69 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
70 return -2;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
71 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
72 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
73
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
74 /* Read data */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
75 xs_fseek(f, 0, SEEK_SET);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
76 readSize = xs_fread(*buf, sizeof(guint8), *bufSize, f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
77 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
78
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
79 if (readSize != *bufSize)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
80 return -3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
81 else
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
82 return 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
83 } else {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
84 xs_fclose(f);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
85 return -4;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
86 }
527
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
87 }
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
88
fe8b41abd923 Now everything necessary should be using the VFS functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
89
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
90 /* Copy a string
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 */
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
92 gchar *xs_strncpy(gchar *pDest, const gchar *pSource, size_t n)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
94 const gchar *s;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
95 gchar *d;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
96 size_t i;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
97
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
98 /* Check the string pointers */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
99 if (!pSource || !pDest)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
100 return pDest;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
102 /* Copy to the destination */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
103 i = n;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
104 s = pSource;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
105 d = pDest;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
106 while (*s && (i > 0)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
107 *(d++) = *(s++);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
108 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
109 }
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
110
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
111 /* Fill rest of space with zeros */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
112 while (i > 0) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
113 *(d++) = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
114 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
115 }
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
116
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
117 /* Ensure that last is always zero */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
118 pDest[n - 1] = 0;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
119
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
120 return pDest;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
121 }
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
122
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
123
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
124 /* Copy a given string over in *ppResult.
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
125 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
126 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr)
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
127 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
128 /* Check the string pointers */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
129 if (!ppResult || !pStr)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
130 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
131
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
132 /* Allocate memory for destination */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
133 if (*ppResult)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
134 g_free(*ppResult);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
135 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
136 if (!*ppResult)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
137 return -2;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
138
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
139 /* Copy to the destination */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
140 strcpy(*ppResult, pStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
142 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
146 /* Concatenates a given string into string pointed by *ppResult.
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
147 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
148 gint xs_pstrcat(gchar **ppResult, const gchar *pStr)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
150 /* Check the string pointers */
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
151 if (!ppResult || !pStr)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
152 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
153
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
154 if (*ppResult != NULL) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
155 *ppResult = (gchar *) g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
156 if (*ppResult == NULL)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
157 return -1;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
158 strcat(*ppResult, pStr);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
159 } else {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
160 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
161 if (*ppResult == NULL)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
162 return -1;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
163 strcpy(*ppResult, pStr);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
164 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
166 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
170 /* Concatenate a given string up to given dest size or \n.
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
171 * If size max is reached, change the end to "..."
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
172 */
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
173 void xs_pnstrcat(gchar *pDest, size_t iSize, const gchar *pStr)
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
174 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
175 size_t i, n;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
176 const gchar *s;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
177 gchar *d;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
178
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
179 d = pDest;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
180 i = 0;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
181 while (*d && (i < iSize)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
182 i++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
183 d++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
184 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
185
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
186 s = pStr;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
187 while (*s && (*s != '\n') && (i < iSize)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
188 *d = *s;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
189 d++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
190 s++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
191 i++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
192 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
193
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
194 *d = 0;
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
195
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
196 if (i >= iSize) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
197 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
198 d--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
199 n = 3;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
200 while ((i > 0) && (n > 0)) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
201 *d = '.';
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
202 d--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
203 i--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
204 n--;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
205 }
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
206 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
207 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
208
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
209
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
210 /* Locate character in string
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
211 */
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
212 gchar *xs_strrchr(gchar *pcStr, const gchar ch)
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
213 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
214 gchar *lastPos = NULL;
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
215
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
216 while (*pcStr) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
217 if (*pcStr == ch)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
218 lastPos = pcStr;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
219 pcStr++;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
220 }
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
221
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
222 return lastPos;
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
223 }
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
224
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
225
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
226 void xs_findnext(const gchar *pcStr, size_t *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
228 while (pcStr[*piPos] && isspace(pcStr[*piPos]))
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
229 (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
233 void xs_findeol(const gchar *pcStr, size_t *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
235 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r'))
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
236 (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
634
a50428d6cc49 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 628
diff changeset
240 void xs_findnum(const gchar *pcStr, size_t *piPos)
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
241 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
242 while (pcStr[*piPos] && isdigit(pcStr[*piPos]))
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 657
diff changeset
243 (*piPos)++;
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
244 }
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
245