~ubuntu-branches/ubuntu/utopic/linuxlogo/utopic

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <string.h>

#include "logo_types.h"
#include "load_logo.h"


    /* People can put all kind of strange and wonderful ascii */
    /* characters in a logo that would royally confuse printf */
int sanitize_print_string(char *string, FILE *fff) {
   
   int i;
   
   for(i=0;i<strlen(string);i++) {
      switch (string[i]) {
       case '\n': fputc('\\',fff);
                  fputc('n',fff);
                  break;
       case '\t': fputc('\\',fff);
	          fputc('t',fff);
	          break;
       case '\\': fputc('\\',fff);
	          fputc('\\',fff);
	          break;
       case '%':  fputc('\\',fff);  /* I think %% works as well */
	          fputc('%',fff);
	          break;
       case '\r': fputc('\\',fff);
	          fputc('r',fff);
	          break;
       case '"':  fputc('\\',fff);
	          fputc('"',fff);
	          break;
       case '\'': fputc('\\',fff);
	          fputc('\'',fff);
	          break;
       default:   fputc(string[i],fff);
      }
   }
   return 0;
}

int main(int argc, char **argv) {
 
    FILE *fff,*ggg;
 
    struct logo_info *logo_info_temp;
   
    char temp_st[BUFSIZ];
   
    int logo_number = 0;

#ifdef sun
    fff=fopen("logo_config.Solaris","r");   
#elif __sgi__
    fff=fopen("logo_config.Irix","r");
#elif __FreeBSD__
    fff=fopen("logo_config.BSD","r");
#else   
    fff=fopen("logo_config","r");
#endif   
    ggg=fopen("load_logos.h","w");

    printf("\nParsing logos from file \"logo_config\"...\n"); 
   
    if (ggg==NULL) {
       printf("\nError!  Cannot create load_logos.h!!!!\n\n");
       return 3;
    }
   
    if (fff==NULL) {
       printf("\nWarning!  No logo_config file exists!  No Logos will "
	      "be compiled in!\n\n");
       fprintf(ggg,"/* No logos configured */\n");
       fclose(ggg);
       return 4;
    }
    
    while (!feof(fff)) {
       if ( fgets(temp_st,BUFSIZ,fff) !=NULL) {
             /* Skip comments */
	  if (temp_st[0]=='#') break;
	  
	  temp_st[strlen(temp_st)-1]='\0';  /* Stupid fgets */
	  
	     /* Skip Empty lines in logo_config file */
	  if (strlen(temp_st)<1) break;
	  
          logo_info_temp=load_logo_from_disk(temp_st);
	  if (logo_info_temp==NULL) break;
	    
	  fprintf(ggg,"\t\t/* %s -- %s */\n",temp_st,logo_info_temp->description);
          fprintf(ggg,"\tnew_logo=calloc(1,sizeof(struct logo_info));\n");
	  
	  if (logo_number==0) {
	     fprintf(ggg,"\n\tlogo_info_head=new_logo;\n\n");  	     
	  } else {
	     fprintf(ggg,"\n\tlogo_info_tail->next_logo=new_logo;\n\n");
	  }
	  
	  fprintf(ggg,"\tnew_logo->description=strdup(\"%s\");\n",
		      logo_info_temp->description);
	  fprintf(ggg,"\tnew_logo->name=strdup(\"%s\");\n",logo_info_temp->name);
	  fprintf(ggg,"\tnew_logo->logo=strdup(\"");
	  sanitize_print_string(logo_info_temp->logo,ggg);
	  fprintf(ggg,"\");\n");
	  fprintf(ggg,"\tnew_logo->ysize=%d;\n",logo_info_temp->ysize);
	  fprintf(ggg,"\tnew_logo->ascii_logo=strdup(\"");
	  sanitize_print_string(logo_info_temp->ascii_logo,ggg);
	  fprintf(ggg,"\");\n");
	  fprintf(ggg,"\tnew_logo->ascii_ysize=%d;\n",
		      logo_info_temp->ascii_ysize);
	  fprintf(ggg,"\tnew_logo->sysinfo_position=%d;\n",
		      logo_info_temp->sysinfo_position);
	  fprintf(ggg,"\tnew_logo->next_logo=NULL;\n");
	  fprintf(ggg,"\tlogo_info_tail=new_logo;\n");
          logo_number++;
	  printf("+ Added logo %s containing \"%s\"\n",
		 temp_st,logo_info_temp->description);
       }
    } 
    printf("\n");
    return 0;
}