/*
nspirelinuxloader - A in-place Linux bootloader for TI-Nspire calculator
Copyright (C) 2011 Daniel Tang
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
int main(int argc, char** argv)
{
FILE *fi, *fo;
int c, i;
if (argc != 3) {
printf("failed\n");
return 1;
}
if ((fi = fopen(argv[1], "rb")) == 0)
{
printf("failed\n");
return 1;
}
if ((fo = fopen(argv[2], "w")) == 0)
{
printf("failed\n");
return 1;
}
if ((c = fgetc(fi)) != EOF) {
fprintf(fo, "char payload[] = { \n", argv[3]);
fprintf(fo, c<16 ? " 0x%x" : " 0x%x", (unsigned char)c);
}
i = 1;
while ((c = fgetc(fi)) != EOF) {
if (i < 12)
fprintf(fo, c<16 ? ", 0x%x" : ", 0x%x", (unsigned char)c);
else {
fprintf(fo, c<16 ? ",\n 0x%x" : ",\n 0x%x", (unsigned char)c);
i = 0;
}
i++;
}
fprintf(fo, " };\n");
printf("converted %s\n", argv[1]);
return 0;
}