/* char-1f one-file character code output Copyright (C) 2016 MiNTed Games All Rights Reserved 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* one-file (1f) compile g++ -Wall -O3 -DVERSION=\"1.0.1\" -o char-1f char-1f.cpp ; \ g++ -Wall -O3 -DVERSION=\"1.0.1\" -DPRG_SIZE=`ls -l char-1f|cut -d \ -f 5` -DSRC_SIZE=`ls -l char-1f.cpp|cut -d \ -f 5` -o char-1f char-1f.cpp ; \ cat char-1f.cpp >> char-1f */ #include #include #include /* one-file source appendage */ //#define SRC_TYPE ".zip" // if its a ZIP appendage #define SRC_TYPE ".cpp" // if its a TEXT appendage #ifndef PRG_SIZE //#define PRG_SIZE 7783 // last checked binary size was ... #define PRG_SIZE 12345 // .. this should be close to actual #endif #ifndef SRC_SIZE // size of 1 text file or 1 zip file //#define SRC_SIZE 5077 // last checked source size was ... #define SRC_SIZE 12345 // .. affects binary size if too small #endif const long offset_1f = PRG_SIZE; // this has never been accurate (EXT4) const long sizeOf_1f = SRC_SIZE; // we use this (-sizeOf_1f) as offset void version_1f() { printf("char-1f (one-file) v%s\n", VERSION); } void output_1f(char *file_1f) { FILE *source_1f; char out_1f[1]; if (offset_1f == 12345 || sizeOf_1f == 12345) { version_1f(); printf("error: no source file or zip\n"); exit(32); }else{ source_1f = fopen(file_1f, "rb"); if (source_1f == NULL) { version_1f(); printf("error: cant open '%s'\n", file_1f); exit(32); } // fseek(source_1f, offset_1f + 223, SEEK_SET); // off by ? fseek(source_1f, -sizeOf_1f, SEEK_END); while(true) { if (!fread(out_1f, 1, 1, source_1f)) { fclose(source_1f); break; }else putchar((int) out_1f[0]); } } } int main(int argc, char *argv[]) { int d; long int x; if ( (argc == 1) || ( (argc > 1) && (strcmp("--help", argv[1]) == 0) ) ) { version_1f(); printf("Copyright 2016 MiNTed Games\n\n"); printf("Output character code info.\n\n"); printf("usage: char-1f [_option_||||]\n"); if (argc > 1) { printf("_option_:\n"); printf("\t-1f one-file (1f) source information\n"); printf("\t--help This help information\n"); printf("\t-v|--version Version information\n"); } printf("\n"); exit(0); } if ( (argc > 1 ) && ( (strcmp("-1f", argv[1]) == 0) || (strcmp("--1f", argv[1]) == 0) ) ) { version_1f(); printf("Copyright 2016 MiNTed Games\n"); printf("one-file (1f) source information.\n\n"); if (offset_1f == 12345 || sizeOf_1f == 12345) { printf("no source file or zip\n"); exit(32); }else{ printf("usage: char-1f _option_\n"); printf("_option_:\n"); printf("\t--src|--source output attached one-file (1f) source file\n"); printf("\t--src-size size of appended source (in bytes) (%d)\n", sizeOf_1f); printf("\t--src-type type of source appended (TXT/ZIP) (%s)\n", SRC_TYPE); printf("\n"); printf("To save one-file (1f) source to file use one of the following:\n"); printf("\tchar-1f --src > char-1f.cpp\n"); printf("\tchar-1f --src > char-1f.zip\n"); printf("\tchar-1f --src > char-1f`char-1f --src-type`\n"); printf("To verify one-file (1f) source file size:\n"); printf("\tchar-1f --src-size (match this to the size in a directory listing)\n"); printf("or use:\n"); printf("NAME=prog; if [ `ls -l $NAME-1f.cpp|cut -d \\ -f 5` = `./$NAME-1f --src-size` ]; then echo Verified; else echo Failed; fi\n"); printf("one-file (1f) options exit with status:\n"); printf("\t31 no error (0x1f)\n"); printf("\t32 an error occured (0x20)\n"); exit(31); } } if ( (argc > 1) && ( (strcmp("--source", argv[1]) == 0) || (strcmp("--src", argv[1]) == 0) ) ) { output_1f(argv[0]); exit(31); } if ( (argc > 1 ) && (strcmp("--src-type", argv[1]) == 0) ) { printf(SRC_TYPE); exit(31); } if ( (argc > 1 ) && (strcmp("--src-size", argv[1]) == 0) ) { printf("%d", SRC_SIZE); exit(31); } if ( (argc > 1) && ( (strcmp("--version", argv[1]) == 0) || (strcmp("-v", argv[1]) == 0) ) ) { version_1f(); exit(0); } d = 0; if (strncmp("0x",argv[1],2) == 0) { x = strtol(argv[1],NULL,16); printf("'%s': %d 0x%2x %04u \n", &x, x, x, x); }else{ d = atoi(argv[1]); if (d == 0) { d = argv[1][0]; printf("'%s': %d 0x%2x %04u \n", argv[1], d, d, d); }else{ printf("'%s': %d 0x%2x %04u \n", &d, d, d, d); } } return(0); }