File: strio.c

package info (click to toggle)
d1x-rebirth 0.58.1-1.2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, sid
  • size: 5,876 kB
  • sloc: ansic: 95,642; asm: 1,228; ada: 364; objc: 243; python: 121; cpp: 118; makefile: 23
file content (56 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (2)
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
/**strio.c: string/file manipulation functions by Victor Rachels **/
#include <stdio.h>
#include <stdlib.h>

#include "physfsx.h"
#include "strio.h"
#include "u_mem.h"

char *fgets_unlimited(PHYSFS_file *f)
{
    int		mem = 256;
    char	*word, *buf, *p;

    MALLOC(word, char, mem);
    p = word;

    while (word && PHYSFSX_fgets(p, mem, f) == word + mem) {
        int i;
        
        // Make a bigger buffer, because it read to the end of the buffer.
        buf = word;
        mem *= 2;
        MALLOC(word, char, mem);
        for (i = 0; i < mem/2; i++)
            word[i] = buf[i];
        d_free(buf);
        p = word + mem/2;
    }
    return word;
}

char* splitword(char *s, char splitchar)
{
 int x,l,l2;
 char *word;

   for(l=0;s[l]!=0;l++);
   for(x=0;s[x]!=splitchar&&x<l;x++);
  l2=x;
  s[x]=0;
  word = (char *) d_malloc(sizeof(char) * (l2+1));
   for(x=0;x<=l2;x++)
    word[x]=s[x];

   if(l==l2)
    s[0]=0;
   else
    {
     while(x<=l)
      {
       s[x-l2-1]=s[x];
       x++;
      }
    }
  return word;
}