]> icculus.org git repositories - btb/d2x.git/blob - misc/strio.c
remove rcs tags
[btb/d2x.git] / misc / strio.c
1 /*
2  * strio.c: string/file manipulation functions by Victor Rachels
3  */
4
5 #ifdef HAVE_CONFIG_H
6 #include <conf.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include "cfile.h"
13 #include "strio.h"
14 //added on 9/16/98 by adb to add memory tracking for this module
15 #include "u_mem.h"
16 //end additions - adb
17
18 char *fgets_unlimited(PHYSFS_file *f)
19 {
20     int         mem = 256;
21     char        *word, *buf, *p;
22
23     MALLOC(word, char, mem);
24     p = word;
25
26     while (word && cfgets(p, mem, f) == word + mem) {
27         int i;
28         
29         // Make a bigger buffer, because it read to the end of the buffer.
30         buf = word;
31         mem *= 2;
32         MALLOC(word, char, mem);
33         for (i = 0; i < mem/2; i++)
34             word[i] = buf[i];
35         d_free(buf);
36         p = word + mem/2;
37     }
38     return word;
39 }
40
41 char* splitword(char *s, char splitchar)
42 {
43  int x,l,l2;
44  char *word;
45
46    for(l=0;s[l]!=0;l++);
47    for(x=0;s[x]!=splitchar&&x<l;x++);
48   l2=x;
49   s[x]=0;
50   word = (char *) d_malloc(sizeof(char) * (l2+1));
51    for(x=0;x<=l2;x++)
52     word[x]=s[x];
53
54    if(l==l2)
55     s[0]=0;
56    else
57     {
58      while(x<=l)
59       {
60        s[x-l2-1]=s[x];
61        x++;
62       }
63     }
64   return word;
65 }