File: load_logo.c

package info (click to toggle)
linuxlogo 5.11-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 856 kB
  • sloc: ansic: 3,165; sh: 370; makefile: 289; perl: 7
file content (92 lines) | stat: -rw-r--r-- 2,296 bytes parent folder | download | duplicates (5)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "logo_types.h"

    /* Loads a logo from disk */
struct logo_info *load_logo_from_disk(char *filename) {

   struct logo_info *new_logo;
   int logo_start=0,ascii_logo_start=0;
   int ascii_size=0,size=0;
   char temp_st[BUFSIZ];
   FILE *fff;
      
   new_logo=calloc(1,sizeof(struct logo_info));

   if (new_logo==NULL) {
      printf("Error allocating memory!\n");
      return NULL;
   }
	
   fff=fopen(filename,"r");
   if (fff==NULL) {
      printf("Error loading logo: %s\n",filename);
      return NULL;
   }
   
   new_logo->logo=NULL;
   new_logo->ascii_logo=NULL;
   
   while (!feof(fff)) {
      fgets(temp_st,BUFSIZ,fff);
      
      if (!strncmp(temp_st,"END_LOGO",8)) logo_start=0;
      if (!strncmp(temp_st,"END_ASCII_LOGO",14)) ascii_logo_start=0;
      
      if (logo_start) {
	 size+=strlen(temp_st);
	 
	 if (new_logo->logo==NULL) {
	    new_logo->logo=strdup(temp_st);
	 }
	 else {
	    new_logo->logo=realloc(new_logo->logo,size+1);
	    strncat( new_logo->logo,temp_st,strlen(temp_st));
	 }
	 
	 new_logo->ysize++;
      }
      
      if (ascii_logo_start) {
         ascii_size+=strlen(temp_st);
	 
	 if (new_logo->ascii_logo==NULL) {
	    new_logo->ascii_logo=strdup(temp_st);
	 }
	 else {
	    new_logo->ascii_logo=realloc(new_logo->ascii_logo,ascii_size+1);
	    strncat( new_logo->ascii_logo,temp_st,strlen(temp_st));
	 }
	 new_logo->ascii_ysize++;
      }
      
      if (!strncmp(temp_st,"BEGIN_ASCII_LOGO",16)) ascii_logo_start=1;
      if (!strncmp(temp_st,"BEGIN_LOGO",10)) logo_start=1;
      
      if ( (!ascii_logo_start) && (!logo_start) ) {
	 if (!strncmp(temp_st,"SYSINFO_POSITION",16)) {
	    if (!strncmp(temp_st+17,"bottom",6)) {
	       new_logo->sysinfo_position=SYSINFO_BOTTOM;
	    }
	    if (!strncmp(temp_st+17,"right",5)) {
	       new_logo->sysinfo_position=SYSINFO_RIGHT;
	    }
	 }
	 if (!strncmp(temp_st,"DESCRIPTION_STRING",18)) {
	    new_logo->description=strdup(temp_st+19);
	    new_logo->description[strlen(new_logo->description)-1]=0;
	 }
	 if (!strncmp(temp_st,"NAME",4)) {
	    new_logo->name=strdup(temp_st+5);
	    new_logo->name[strlen(new_logo->name)-1]=0;
	 }
      }
   }
   
   new_logo->next_logo=NULL;
 
   fclose(fff);
   
   return new_logo;   
}