FS#8961 - Anti-Aliased Fonts.
[kugel-rb/myfork.git] / utils / MTP / beastpatcher / main.c
blobf5150bbbab45f03fdfcedf498dd187aacd97e820
1 /*
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * $Id$
11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met:
18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
21 * * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ****************************************************************************/
40 #include <stdio.h>
41 #include <string.h>
42 #include "beastpatcher.h"
43 #include "mtp_common.h"
45 #if defined(__WIN32__) || defined(_WIN32)
46 #include <windows.h>
47 #include "../MTP_DLL/MTP_DLL.h"
48 #endif
50 #ifdef WITH_BOOTOBJS
51 #define VERSION "1.0 with v1 bootloader"
52 #else
53 #define VERSION "1.0"
54 #endif
56 enum actions {
57 NONE,
58 INSTALL,
59 SEND,
60 HELP
63 static void print_usage(void)
65 fprintf(stderr,"Usage: beastpatcher [action]\n");
66 fprintf(stderr,"\n");
67 fprintf(stderr,"Where [action] is one of the following options:\n");
68 #ifdef WITH_BOOTOBJS
69 fprintf(stderr," -i, --install <bootloader.bin>\n");
70 #else
71 fprintf(stderr," -i, --install bootloader.bin\n");
72 #endif
73 fprintf(stderr," -s, --send nk.bin\n");
74 fprintf(stderr," -h, --help\n");
75 fprintf(stderr,"\n");
76 #ifdef WITH_BOOTOBJS
77 fprintf(stderr,"With bootloader file omitted the embedded one will be used.\n");
78 fprintf(stderr,"\n");
79 #endif
83 int main(int argc, char* argv[])
85 int res = 0;
86 char yesno[4];
87 int i;
88 unsigned char* bootloader = NULL;
89 unsigned char* firmware = NULL;
90 #ifdef WITH_BOOTOBJS
91 int action = INSTALL;
92 #else
93 int action = NONE;
94 #endif
96 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
97 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
98 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
100 i = 1;
101 while(i < argc) {
102 if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
103 action = HELP;
105 else if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--install") == 0) {
106 action = INSTALL;
107 if(((i + 1) < argc) && argv[i + 1][0] != '-') {
108 bootloader = argv[++i];
110 #ifndef WITH_BOOTOBJS
111 else {
112 action = NONE;
114 #endif
116 else if(((strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--send") == 0)
117 && (i + 1) < argc)) {
118 action = SEND;
119 firmware = argv[++i];
121 i++;
124 if(action == NONE) {
125 print_usage();
126 res = -1;
128 else if(action == HELP) {
129 print_usage();
130 res = 0;
132 else if(action == SEND) {
133 res = sendfirm(firmware);
135 else if(action == INSTALL) {
136 res = beastpatcher(bootloader);
137 /* don't ask for enter if started with command line arguments */
138 if(argc == 1) {
139 printf("\nPress ENTER to exit beastpatcher: ");
140 fgets(yesno,4,stdin);
143 return res;