~ubuntu-branches/ubuntu/trusty/linuxlogo/trusty

« back to all changes in this revision

Viewing changes to load_logo.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-06-20 09:19:00 UTC
  • mfrom: (4.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080620091900-4xzuv7c7ntxvs7wt
Tags: 5.03-4
* Adding patch to fix FTBFS on s390x.
* Updating to standards 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include "logo_types.h"
 
5
 
 
6
    /* Loads a logo from disk */
 
7
struct logo_info *load_logo_from_disk(char *filename) {
 
8
 
 
9
   struct logo_info *new_logo;
 
10
   int logo_start=0,ascii_logo_start=0;
 
11
   int ascii_size=0,size=0;
 
12
   char temp_st[BUFSIZ];
 
13
   FILE *fff;
 
14
      
 
15
   new_logo=calloc(1,sizeof(struct logo_info));
 
16
 
 
17
   if (new_logo==NULL) {
 
18
      printf("Error allocating memory!\n");
 
19
      return NULL;
 
20
   }
 
21
        
 
22
   fff=fopen(filename,"r");
 
23
   if (fff==NULL) {
 
24
      printf("Error loading logo: %s\n",filename);
 
25
      return NULL;
 
26
   }
 
27
   
 
28
   new_logo->logo=NULL;
 
29
   new_logo->ascii_logo=NULL;
 
30
   
 
31
   while (!feof(fff)) {
 
32
      fgets(temp_st,BUFSIZ,fff);
 
33
      
 
34
      if (!strncmp(temp_st,"END_LOGO",8)) logo_start=0;
 
35
      if (!strncmp(temp_st,"END_ASCII_LOGO",14)) ascii_logo_start=0;
 
36
      
 
37
      if (logo_start) {
 
38
         size+=strlen(temp_st);
 
39
         
 
40
         if (new_logo->logo==NULL) {
 
41
            new_logo->logo=strdup(temp_st);
 
42
         }
 
43
         else {
 
44
            new_logo->logo=realloc(new_logo->logo,size+1);
 
45
            strncat( new_logo->logo,temp_st,strlen(temp_st));
 
46
         }
 
47
         
 
48
         new_logo->ysize++;
 
49
      }
 
50
      
 
51
      if (ascii_logo_start) {
 
52
         ascii_size+=strlen(temp_st);
 
53
         
 
54
         if (new_logo->ascii_logo==NULL) {
 
55
            new_logo->ascii_logo=strdup(temp_st);
 
56
         }
 
57
         else {
 
58
            new_logo->ascii_logo=realloc(new_logo->ascii_logo,ascii_size+1);
 
59
            strncat( new_logo->ascii_logo,temp_st,strlen(temp_st));
 
60
         }
 
61
         new_logo->ascii_ysize++;
 
62
      }
 
63
      
 
64
      if (!strncmp(temp_st,"BEGIN_ASCII_LOGO",16)) ascii_logo_start=1;
 
65
      if (!strncmp(temp_st,"BEGIN_LOGO",10)) logo_start=1;
 
66
      
 
67
      if ( (!ascii_logo_start) && (!logo_start) ) {
 
68
         if (!strncmp(temp_st,"SYSINFO_POSITION",16)) {
 
69
            if (!strncmp(temp_st+17,"bottom",6)) {
 
70
               new_logo->sysinfo_position=SYSINFO_BOTTOM;
 
71
            }
 
72
            if (!strncmp(temp_st+17,"right",5)) {
 
73
               new_logo->sysinfo_position=SYSINFO_RIGHT;
 
74
            }
 
75
         }
 
76
         if (!strncmp(temp_st,"DESCRIPTION_STRING",18)) {
 
77
            new_logo->description=strdup(temp_st+19);
 
78
            new_logo->description[strlen(new_logo->description)-1]=0;
 
79
         }
 
80
         if (!strncmp(temp_st,"NAME",4)) {
 
81
            new_logo->name=strdup(temp_st+5);
 
82
            new_logo->name[strlen(new_logo->name)-1]=0;
 
83
         }
 
84
      }
 
85
   }
 
86
   
 
87
   new_logo->next_logo=NULL;
 
88
 
 
89
   fclose(fff);
 
90
   
 
91
   return new_logo;   
 
92
}