]> icculus.org git repositories - btb/d2x.git/blob - misc/strio.c
fixed opengl credits, scores
[btb/d2x.git] / misc / strio.c
1 /* $Id: strio.c,v 1.3 2003-02-18 20:35:35 btb Exp $ */
2 /*
3  * strio.c: string/file manipulation functions by Victor Rachels
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include <conf.h>
8 #endif
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "strio.h"
13 //added on 9/16/98 by adb to add memory tracking for this module
14 #include "u_mem.h"
15 //end additions - adb
16
17 char* fsplitword(FILE *f, char splitchar)
18 {
19  int x,y,mem,memx;
20  char *word,*buf;
21   memx=1;
22   mem=memx*256;
23   word=(char *) d_malloc(sizeof(char) * mem);
24   x=0;
25   word[x]=fgetc(f);
26    while(word[x]!=splitchar && !feof(f))
27     {
28      x++;
29       if(x==mem)
30        {
31         buf=word;
32         memx*=2;
33         mem=memx*256;
34         word=(char *) d_malloc(sizeof(char) * mem);
35          for(y=0;y<x;y++)
36           word[y]=buf[y];
37         d_free(buf);
38        }
39      word[x]=fgetc(f);
40     }
41   word[x]=0;
42   return word;
43 }
44
45 char* splitword(char *s, char splitchar)
46 {
47  int x,l,l2;
48  char *word;
49
50    for(l=0;s[l]!=0;l++);
51    for(x=0;s[x]!=splitchar&&x<l;x++);
52   l2=x;
53   s[x]=0;
54   word = (char *) d_malloc(sizeof(char) * (l2+1));
55    for(x=0;x<=l2;x++)
56     word[x]=s[x];
57
58    if(l==l2)
59     s[0]=0;
60    else
61     {
62      while(x<=l)
63       {
64        s[x-l2-1]=s[x];
65        x++;
66       }
67     }
68   return word;
69 }