File: parse_logos.c

package info (click to toggle)
linuxlogo 6.0-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,052 kB
  • sloc: ansic: 4,461; sh: 380; makefile: 291; perl: 7
file content (151 lines) | stat: -rw-r--r-- 3,539 bytes parent folder | download
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#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 */
static 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 '%': /* I think %% works as well */
				fputc('\\',fff);
				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;
}

static void free_logo_memory(struct logo_info *logo_ptr) {
    free(logo_ptr->description);
    free(logo_ptr->name);
    free(logo_ptr->logo);
    free(logo_ptr->ascii_logo);
    free(logo_ptr);
}

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;

			/* Stupid fgets */
			temp_st[strlen(temp_st)-1]='\0';

			/* 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);
      
      /* Free memory allocated to current logo */
      free_logo_memory(logo_info_temp);
    }
  } 
  printf("\n");
  return 0;
}