commit ae3047cdcd3c7466ae7e3a30f757979b165e4e19
parent fac1799893c84c667680f196d0c7ccf0f1477e15
Author: ByteProject <stefan.vogt@byteproject.net>
Date: Mon, 26 Dec 2011 00:13:17 +0100
lots of code additions and changes, nearly ported
Diffstat:
M | ansilove/main.c | | | 294 | ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- |
1 file changed, 194 insertions(+), 100 deletions(-)
diff --git a/ansilove/main.c b/ansilove/main.c
@@ -22,142 +22,236 @@
#include "substr.h"
#endif
-// show usage
+// prototypes
+void showUsage(void);
+void loadPCBoard(void);
+void loadBinary(void);
+void loadArtworx(void);
+void loadIceDraw(void);
+void loadTundra(void);
+void loadXbin(void);
+void loadAnsi(void);
+
+// show how to properly set the command line flags
void showUsage(void)
{
- printf("USAGE: ansilove inputfile columns (.BIN only) font bits icecolors\n\n");
- printf(" Check the README to have details about supported options for each\n");
- printf(" file format.\n\n");
- printf("EXAMPLES: ansilove ansi.ans\n");
- printf(" ansilove ansi.ans 80x25 9 (80x25 font, 9-bit)\n");
- printf(" ansilove ansi.ans 80x25 thumbnail (80x25 font, thumbnail rendering)\n");
- printf(" ansilove ansi.ans 80x50 9 (80x50 font, 9-bit)\n");
- printf(" ansilove ansi.ans russian 9 (Russian font, 9-bit)\n");
- printf(" ansilove ansi.ans amiga (Amiga font)\n");
- printf(" ansilove pcboard.pcb\n");
- printf(" ansilove pcboard.pcb 80x25 9 (80x25 font, 9-bit)\n");
- printf(" ansilove binary.bin 160\n");
- printf(" ansilove binary.bin 160 80x25 9 (80x25 font, 9-bit)\n");
- printf(" ansilove binary.bin 160 80x50 9 (80x50 font, 9-bit)\n");
- printf(" ansilove adf.adf\n");
- printf(" ansilove idf.idf\n");
- printf(" ansilove tundra.tnd\n");
- printf(" ansilove tundra.tnd 80x25 9 (80x25 font, 9-bit)\n");
- printf(" ansilove xbin.xb\n\n");
-
- return EXIT_SUCCESS;
+ printf("USAGE:\n");
+ printf("ansilove inputfile outputfile columns (.BIN only) font bits icecolors\n\n");
+ printf("Check the README to have details about supported options for each\n");
+ printf("file format. Use flag '-s' for 'outputfile' to write a file to the same\n");
+ printf("path, with the same name and .png suffix appended.\n\n");
+ printf("EXAMPLES:\n");
+ printf("ansilove ansi.ans ansi.png\n");
+ printf("ansilove ansi.ans ansi.png 80x25 9 1 (80x25 font, 9-bit, iCE colors)\n");
+ printf("ansilove ansi.ans -s 80x25 thumbnail (80x25 font, thumbnail rendering)\n");
+ printf("ansilove ansi.ans ansi.png 80x50 9 (80x50 font, 9-bit)\n");
+ printf("ansilove ansi.ans -s russian 9 (Russian font, 9-bit)\n");
+ printf("ansilove ansi.ans ansi.png amiga (Amiga font)\n");
+ printf("ansilove pcboard.pcb pcboard.png\n");
+ printf("ansilove pcboard.pcb pcboard.png 80x25 9 (80x25 font, 9-bit)\n");
+ printf("ansilove binary.bin -s 160\n");
+ printf("ansilove binary.bin binary.png 160 80x25 9 1 (80x25 font, 9-bit, iCE colors)\n");
+ printf("ansilove binary.bin binary.png 160 80x50 9 (80x50 font, 9-bit)\n");
+ printf("ansilove adf.adf adf.png\n");
+ printf("ansilove idf.idf idf.png\n");
+ printf("ansilove tundra.tnd tundra.png\n");
+ printf("ansilove tundra.tnd -s 80x25 9 (80x25 font, 9-bit)\n");
+ printf("ansilove xbin.xb xbin.png\n\n");
+}
+
+void loadPCBoard(void)
+{
+ // params: input, output, font, bits, icecolors
+}
+
+void loadBinary(void)
+{
+ // params: input, output, columns, font, bits, icecolors
+}
+
+void loadArtworx(void)
+{
+ // params: input, output, bits
+}
+
+void loadIceDraw(void)
+{
+ // params: input, output, bits
+}
+
+void loadTundra(void)
+{
+ // params: input, output, font, bits
+}
+
+void loadXbin(void)
+{
+ // params: input, output, bits
+}
+
+void loadAnsi(void)
+{
+ // params: input, output, font, bits, icecolors
}
int main(int argc, char *argv[])
{
- printf("--------------------------------------------------\n");
+ printf("\n---------------------------------------------------------------------------\n");
printf("AnsiLove/C %s - copyright (C) 2011 Stefan Vogt\n", VERSION);
- printf("--------------------------------------------------\n\n");
-
- char columns[], font[], bits[], icecolors[];
- char input[] = argv[1];
- char output[];
- sprintf(output, "%s.png", argv[1]);
-
- // check input parameters
- char inputFileExtension[] = strtolower(substr(input, strlen(input)-4, 4));
+ printf("---------------------------------------------------------------------------\n\n");
- if (argc == 1) {
+ // we do this before anything else
+ if (argc <=2) {
showUsage();
+ return EXIT_SUCCESS;
}
- if (inputFileExtension == '.bin')
+ // declarations
+ char *input = argv[1];
+ char output[1000] = { 0 };
+ char columns[1000] = { 0 };
+ char font[1000] = { 0 };
+ char bits[1000] = { 0 };
+ char icecolors[1000] = { 0 };
+ char *fext;
+
+ // find last position of char '.' so we can determine the file extension
+ long index = strrchr(input, '.') - input;
+
+ // calculate size of the input string
+ long inpSize = strlen(input);
+
+ // generate size_t result we can pass to our substr() implementation
+ size_t result = inpSize - index;
+
+ // finally create the file extension string
+ fext = substr(input, inpSize - result, result);
+ fext = strtolower(fext);
+ if (fext == NULL) {
+ fext = "none";
+ }
+
+ // in case we got arguments for input, output and the '-s' flag is set
+ if (strcmp(argv[2], "-s") == 0)
{
- if (argv[2]) {
- columns = argv[2];
+ // make file name lowercase and append .png suffix
+ sprintf(output, "%s.png", strtolower(argv[1]));
+ }
+ else {
+ // so the user provided an alternate path / file name
+ sprintf(output, "%s", strtolower(argv[2]));
+ }
+
+ // check flags and apply them based on the file extension
+ if (strcmp(fext, ".bin") == 0)
+ {
+ // columns
+ if (argc >= 4) {
+ sprintf(columns, "%s", argv[3]);
+ }
+ else {
+ sprintf(columns, "%s", "160");
+ }
+ // font
+ if (argc >= 5) {
+ sprintf(font, "%s", argv[4]);
+ }
+ else {
+ sprintf(font, "%s", "80x25");
}
- if (argv[3]) {
- font = argv[3];
+ // bits
+ if (argc >= 6) {
+ sprintf(bits, "%s", argv[5]);
+ }
+ else {
+ sprintf(bits, "%s", "8");
+
}
- if (argv[4]) {
- bits = argv[4];
+ // iCE colors
+ if (argc >= 7) {
+ sprintf(icecolors, "%s", argv[6]);
}
- if (argv[5]) {
- icecolors = argv[5];
+ else {
+ sprintf(icecolors, "%s", "0");
}
}
else {
- if (argv[2]) {
- font = argv[2];
+ printf("file extension is: %s\n", fext);
+ // font
+ if (argc >= 4) {
+ sprintf(font, "%s", argv[3]);
}
- if (argv[3]) {
- bits = argv[3];
+ else {
+ sprintf(font, "%s", "80x25");
}
- if (argv[3]) {
- icecolors = argv[4];
+ // bits
+ if (argc >= 5) {
+ sprintf(bits, "%s", argv[4]);
+ }
+ else {
+ sprintf(bits, "%s", "8");
+ }
+ // iCE colors
+ if (argc >= 7) {
+ sprintf(icecolors, "%s", argv[5]);
+ }
+ else {
+ sprintf(icecolors, "%s", "0");
}
}
- if (strtolower(substr(input, strlen(input)-3, 3)) == '.xb') {
- inputFileExtension = '.xb';
- }
-
- if (bits == "thumbnail") {
- sprintf(output, "%s%s.png", argv[1], THUMBNAILS_TAG)
- bits = "thumbnail";
+ // in case the thumbnail flag is set, append THUMBNAILS_TAG
+ if (strcmp(bits, "thumbnail") == 0) {
+ sprintf(output, "%s%s.png", strtolower(argv[1]), THUMBNAILS_TAG);
}
+ // report all flags to the command line
printf("Input File: %s\n", input);
printf("Output File: %s\n", output);
printf("Columns (.BIN only): %s\n", columns);
printf("Font (.ANS/.BIN only): %s\n", font);
printf("Bits (.ANS/.BIN only): %s\n", bits);
printf("iCE Colors (.ANS/.BIN only): %s\n\n", icecolors);
-
- // create output file
- switch (inputFileExtension)
- {
- case '.pcb':
- load_pcboard(input,output,font,bits,icecolors);
- break;
-
- case '.bin':
- load_binary(input,output,columns,font,bits,icecolors);
- break;
-
- case '.adf':
- load_adf(input,output,bits);
- break;
-
- case '.idf':
- load_idf(input,output,bits);
- break;
-
- case '.tnd':
- load_tundra(input,output,font,bits);
- break;
-
- case '.xb':
- load_xbin(input,output,bits);
- break;
-
- default:
- load_ansi(input,output,font,bits,icecolors);
+
+ // create the output file by invoking the appropiate function
+ if (strcmp(fext, ".pcb") == 0) {
+ loadPCBoard();
}
-
- // display sauce informations
- input_file_sauce=load_sauce(input);
-
- if (input_file_sauce != NULL)
- {
- printf("Title: input_file_sauce[Title]\n");
- printf("Author: input_file_sauce[Author]\n");
- printf("Group: input_file_sauce[Group]\n");
- printf("Date: input_file_sauce[Date]\n");
- printf("Comment: input_file_sauce[Comment]\n\n");
+ else if (strcmp(fext, ".bin") == 0) {
+ loadBinary();
+ }
+ else if (strcmp(fext, ".adf") == 0) {
+ loadArtworx();
+ }
+ else if (strcmp(fext, ".idf") == 0) {
+ loadIceDraw();
+ }
+ else if (strcmp(fext, ".tnd") == 0) {
+ loadTundra();
+ }
+ else if (strcmp(fext, ".xb") == 0) {
+ loadXbin();
}
+ else {
+ loadAnsi();
+ }
+
+// Displaying SAUCE is disabled until we're done with porting ansilove.c!
+
+// // display sauce informations
+// input_file_sauce=load_sauce(input);
+//
+// if (input_file_sauce != NULL)
+// {
+// printf("Title: input_file_sauce[Title]\n");
+// printf("Author: input_file_sauce[Author]\n");
+// printf("Group: input_file_sauce[Group]\n");
+// printf("Date: input_file_sauce[Date]\n");
+// printf("Comment: input_file_sauce[Comment]\n\n");
+// }
// terminate program
printf("Successfully created output file\n\n");
return EXIT_SUCCESS;
}
-
-
-
-