File: logoread2.c

package info (click to toggle)
nwutil 1.4-3
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 132 kB
  • ctags: 86
  • sloc: ansic: 1,176; makefile: 63
file content (105 lines) | stat: -rw-r--r-- 2,128 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
#include <stdio.h>
#include <getopt.h>
#include "flashlogo.h"

//#define DEBUG

int main(int argc, char **argv)
{
	FILE *outputfile;
	int fsize = flashsize();
	struct logoblock2 logo;
	int c;
		
#ifdef DEBUG
	if (sizeof(struct logoblock) != 65536)
	{
		fprintf(stderr, "%s: bad logo structure size... recompile? (%i)\n", argv[0], sizeof(struct logoblock));
		exit(1);
	}
#endif

	while (1)
	{
		static struct option long_options[] =
		{
			{ "help", 0, 0, 'h' },
			{ "version", 0, 0, 'v' },
			{ 0, 0, 0, 0 }
		};
		
		c = getopt_long(argc, argv, "", long_options, NULL);
		
		if (c == -1)
			break;
			
		switch (c)
		{
		case 'h':
			printf(	"Usage: %s [OPTIONS]... [FILE]\n"
				"Read the current startup graphic behaviour and optionally write the startup\n"
				"graphic to FILE.\n"
				"\n"
				"      --help                  display this help and exit.\n"
				"      --version               output version information and exit.\n"
				"\n", argv[0]);
			exit(1);
		case 'v':
			printf("logoread2 1.00\n");
			exit(1);
		case '?':
			fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
			exit(1);
		}
	}
			
	if (fsize < 0)
	{
		fprintf(stderr, "%s: unable to access flash device.\n", argv[0]);
		exit (1);
	}
	
	printf("Flash size: %i bytes.\n", fsize);

	printf("Checking for GIF logo block presence... ");
	
//	flashread((char *)&logo, fsize-128*1024, 65536);
	flashread((char *)&logo, fsize-62*1024, 65536-2*1024);
	if (logo.magic != LB_MAGIC)
	{
		printf("not found; use logowrite2 to write logo.\n");
		exit(1);
	} else
		printf("Found.\n\n");

	printf("Options set:\n");
	
	if (logo.flags & LB_SHOWGIF)
		printf("\t* Display user GIF file\n");
	
	if (logo.flags & LB_SHOWNW)
		printf("\t* Display NetWinder logo\n");
	
	if (!logo.flags)
		printf("\t* None\n");
		
	printf("\nCoordinates for user logo display: (%u, %u)\n\n", logo.x, logo.y);
	
	if (logo.flags & LB_SHOWGIF)
	{
		outputfile = fopen(argv[optind], "wb");
	
		if (outputfile)
		{
			printf("Saving logo... ");
	
			fwrite(&(logo.data2), logo.size, 1, outputfile);
			fclose(outputfile);
	
			printf("Done.\n");
		}
	}
	
	return 0;
}