Git

1 #include "tracklist.h"
3 #define MAXTRACKLENGTH 80
5 /* get available local tracks */
6 int zeRace_get_tracks(struct _tracklist **tracklist)
7 {
8   FILE *fic;
9   char line[MAXTRACKLENGTH];
10   struct _tracklist *tmp=NULL,*first=NULL;
12   *tracklist=NULL;
13   if ((fic=fopen("tracks/list.txt","rt"))==NULL)
14   {
15     fprintf(stderr,"can't open track list\n");
16     return 0;
17   }
18   while (!feof(fic))
19   {
20     tmp=(struct _tracklist *)malloc(sizeof(struct _tracklist));
21     if (first==NULL) first=tmp;
22     fgets(line,MAXTRACKLENGTH,fic);
23     tmp->name=(char *)malloc(strlen(line)+1);
24     strcpy(tmp->name,line);
25     tmp->name[strlen(tmp->name)-1]='\0';
26     fgets(line,MAXTRACKLENGTH,fic);
27     tmp->title=(char *)malloc(strlen(line)+1);
28     strcpy(tmp->title,line);
29     fgets(line,MAXTRACKLENGTH,fic);
30     tmp->author=(char *)malloc(strlen(line)+1);
31     strcpy(tmp->author,line);
32     fgets(line,MAXTRACKLENGTH,fic);
33     tmp->version=(char *)malloc(strlen(line)+1);
34     strcpy(tmp->version,line);
35     fgets(line,MAXTRACKLENGTH,fic);
36     tmp->x=atoi(line);
37     fgets(line,MAXTRACKLENGTH,fic);
38     tmp->y=atoi(line);
39     fgets(line,MAXTRACKLENGTH,fic);
40     tmp->a=atoi(line);
41     fgets(line,MAXTRACKLENGTH,fic);
42     tmp->best_time=atoi(line);
43     fgets(line,MAXTRACKLENGTH,fic);
44     tmp->best_pseudo=(char *)malloc(strlen(line)+1);
45     strcpy(tmp->best_pseudo,line);
46     tmp->full=(char *)malloc(strlen(line)+20);
47     sprintf(tmp->full,"tracks/%s.png",tmp->name);
48     tmp->function=(char *)malloc(strlen(line)+30);
49     sprintf(tmp->function,"tracks/%s_function.png",tmp->name);
50     tmp->prev=*tracklist;
51     if (tmp->prev) tmp->prev->next=tmp;
52     *tracklist=tmp;
53     /* skip one line */
54     fgets(line,MAXTRACKLENGTH,fic);
55   }
56   fclose(fic);
57   if (!tmp) { fprintf(stderr,"no circuits found !\n"); return 0; }
58   while (tmp->prev) tmp=tmp->prev;
59   tmp->prev=*tracklist;
60   (*tracklist)->next=tmp;
61   return 1;
62 }