#!/bin/sh

### 1f informer
### Copyright 2016 MiNTed Games
### GPL2

if [ "$1" = "--src-size" ]; then
	echo "5914"
	exit 31
fi

if [ "$1" = "--src-type" ]; then
	echo ".cpp"
	exit 31
fi

if [ ! "$1" = "--source" -a ! "$1" = "--src" ]; then
	echo "one-file (1f) Informer v1.0.1"
fi

if [ "$1" = "-v" -o "$1" = "--version" ]; then
	exit 0
fi

if [ "$1" = "-1f" -o "$1" = "--1f" ]; then
	echo "Copyright 2016 MiNTed Games"
	echo "one-file (1f) source information."
	echo ""
	echo "usage: one-file-1f _option_"
	echo "_option_:"
	echo "\t--src|--source output attached one-file (1f) source file"
	echo "\t--src-size     size of appended source (in bytes) (5914)"
	echo "\t--src-type     type of source appended (TEXT/ZIP) (.cpp)"
	echo ""
	echo "To save one-file (1f) source to file use one of the following:"
	echo "\tone-file-1f --src > _skel-1f.cpp"
#	echo "\tone-file-1f --src > _skel-1f.zip"
	echo "\tone-file-1f --src > _skel-1f\`one-file-1f --src-type\`"
	echo "To verify one-file (1f) source file size:"
	echo "\tone-file-1f --src-size  (match this to the size in a directory listing)"
	echo "or use:"
	echo "if [ \`ls -l _skel-1f.cpp|cut -d \  -f 5\` = \`./one-file-1f --src-size\` ]; then echo Verified; else echo Failed; fi"
	echo "one-file (1f) options exit with status:"
	echo "\t31	successful (0x1f)"
	echo "\t32	an error occured (0x20)"
	exit 31
fi

EXIT_1F=
DESC_1F=
HISTORY_1F=
DEPENDS_1F=
FIND_1F=
SOURCE_1F=
MAKE_1F=
EXAMPLE_1F=
SKELETON_1F=
FUTURE_1F=

if [ "$1" = "all" ]; then
DESC_1F=true
HISTORY_1F=true
DEPENDS_1F=true
FIND_1F=true
SOURCE_1F=true
MAKE_1F=true
EXAMPLE_1F=true
SKELETON_1F=true
FUTURE_1F=true
fi

if [ "$1" = "" -o "$1" = "--help" ]; then
	echo "Copyright 2016 MiNTed Games"
	echo "A DocBook that tells you about single file binaries with source appended"
	echo ""
	echo "usage: one-file-1f [_section_]"
	echo "_section_:"
	echo "	all        show all one-file (1f) information"
	echo "	desc       give a description of what one-file is"
	echo "	history    a little bit about how one-file came to be"
	echo "	depends    what does one-file depend on (nothing-ish)"
	echo "	find       tries to find all one-file (*-1f) programs"
	echo "	source     information on one-file (1f) source appendage"
	echo "	make       one-file (1f) compile make utility (not needed)"
	echo "	compile    how to make a one-file (1f) compile"
	echo "	options    a bit about standard command line options"
	echo "	example    an example of how to use a one-file (1f) compile"
	echo "	skeleton   about the embeded one-file (1f) .cpp source file"
	echo ""
	if [ "$1" = "--help" ]; then
		exit 0
	fi
	DESC_1F=true
	EXIT_1F=true
fi 

if [ "$1" = "desc" ]; then
	DESC_1F=true
fi

if [ "$DESC_1F" = "true" ]; then
	echo ""
	echo "Description"
	echo "==========="
	echo ""
	echo "  one-file (1f)   is any single file binary program with its source appended to that binary."
	echo "  one-file (1f)   is a physical manifestation of the KIS(S) principle:  Keep It Simple (Stupid)."
	echo "  one-file (1f)   is an example of how to cut down over-complicated development processes and packaging schemes which are far too common nowadays."
	echo "  one-file (1f)   binaries have appended to itself (copied onto the end), either a single TEXT source file or a single ZIP file containing multiple source files, possibly also a 'Makefile'."
	echo "  one-file (1f)   source can be extracted simple by piping the output of the applications '--source' switch to a named file (test-1f --src > test-1f.cpp)."
	echo "  one-file (1f)   source contain the required commands to succesfully output the source, compile and then reattach the source, in most cases without the use of a 'Makefile' or './configure' script."
	echo ""
	if [ "$EXIT_1F" = "true" ]; then
		exit 0
	fi
fi

if [ "$1" = "history" ]; then
	HISTORY_1F=true
fi

if [ "$HISTORY_1F" = "true" ]; then
	echo ""
	echo "History"
	echo "======="
	echo ""
	echo "  one-file (1f) was born from the now defunct SpASM32 32-bit Windows Assembler project of the late 1990's.   It was a self compiling editor and 32-bit Windows assembler with its own ASCII source file attached to the binary."
	echo "  Thats right you could send a SpASM32 generated binary to SpASM32 and it would read the source file  (not the binary),  then allow you to compile the binary,  automatically attaching the source."
	echo "  It was such a simple idea that worked so simply that it demanded implimenting where ever possible. Sadly the rest of the programming community did not seem to think so, and SpASM32 has been lost to history. However the principle lived on."
	echo "  I first used it to attach and extract the source of a DOS NASM (Netwide Assembler) compiled VESA mode interigator and VESA mode setter for a newly aquired 64M Voodoo 5000 (one of 2 brand new still in the box) in 2005-ish."
	echo "  Note that idea of attaching source and binary is not a new one. In the 1980's it was common for Spectrum BASIC files to contain inline machine code in REM or PRINT statements. During the 1970's and early 1980's, some CP/M (Z80 forerunner to DOS) programs contain source code mildly compressed (Squashed), some of which were attached in a similar way."
	echo "  Since 2010,  I have noticed that a lot of Linux/SunOS projects have failed to compile, or failed to be updated, mostly because of './configure' or 'Makefile' failures. Often it is the AutoTools (automake, autoconf, etc) processes,  which generates those to files, that fails."
	echo "  I also noticed the increasing convoluted complexity of OS filesystem layouts, their organisation, and default paths when building libraries and applications."
	echo "  Specifically I wanted a minimalist Debian based distro to boot a Raspberry Pi with Atari ST m68k-cross-tools installed and usable, optionaly without X Windows system install, but rather SDL framebuffer with GLES for graphics, sound, etc."
	echo "  Because of some of the missing parts for Atari MiNT, updated Ext2, Ext3 & Ext4 filesystems and tools, as well as some other modern filesystem drivers and tools, any cross-tools development requires Kernal 2.36 sources or earlier. Kernal 4.xx sources for Debian now DONT use any type of changable init system (requiring systemd instead)."
	echo "  With these development considerations, and the need to develop and test cross-platform, especially aging hardware, and the need for a smaller foot print, something simpler was needed.  An idea, dotOS,  combining simplified and cleaned up filesystem layout, NixOS version control package installation ideas, Package.fs management principles, all rooted in /.OS/, hidden on most systems by default."
	echo "  one-file (1f) programs fit well with dotOS and the need for AtariST statically linked binaries."
	echo ""
fi

if [ "$1" = "depends" ]; then
	DEPENDS_1F=true
fi

if [ "$DEPENDS_1F" = "true" ]; then
	echo ""
	echo "Dependancies"
	echo "============"
	echo ""
	echo "  If you are using Linux or Unix, or OS with a full set of command line tools, then a one-file (1f) depends on what you already have. However if command line tools are an option then the following is a minimum of what you need."
	echo ""
	echo "  You can use 'one-file (1f) compile' on any OS, for posix or GNU compatible systems you need:"
	echo "'g++'     compiler, usually GNU C++"
	echo "'ls'      where 'ls -l <file>' outputs size in bytes after the 5th space"
	echo "'cut'     used to cut the above 'ls' output between the 5th & 6th space"
	echo ""
	echo "  one-file (1f) scripts use the following command line tools:"
	echo "'/bin/sh' shell, or a link to 'bash', etc"
	echo "'['       or a link to 'test', for shell 'if-then' statements"
	echo "'echo'    optional, this is usually built into the shell"
	echo ""
	echo "  one-file (1f) scripts may use one or more the following:"
	echo "'which'   tells you where the first binary is if you dont provide the path"
	echo "'cat'     concatenates text out to the console, on Windows this is 'type'"
	echo "'find'    finds files in given path (sudo find / -name \"*sdl*\")"
	echo "'grep'    finds text in files (grep -n -R \"SDL_sound.h\" /usr/include/*)"
	echo "'make'    if you use a 'Makefile' or './configure' script"
	echo "          (maybe your one-file (1f) program has more than one source file)"
	echo ""
	echo "  On Windows, you can add 'Posix Commandline Tools', but better yet, install 'Cygwin' or 'MingGW'. If you install both of them, you will have cross-platform development for about 99% of platform architectures."
	echo "  Remember that one-file (1f) is a principle or idea, not a dictatorship, so if you have a simpler set of commands, or use a non-posix system, dont hesitate to change the one-file (1f) tools and source compiler command to suit your needs."
	echo "  Just remember to Keep It Simple (Stupid), do the changes in a way that allows most users of your system type to also use one-file (1f) compile development."
	echo ""
fi

if [ "$1" = "find" ]; then
	FIND_1F=true
fi

if [ "$FIND_1F" = "true" ]; then
	echo ""
	echo "Find *-1f"
	echo "========="
	echo ""
	echo "  We try and keep this simple. 'prog-1f' is defeinitely a one-file (1f) program called 'prog', but does it have source attached. We can check with:"
	echo "prog-1f --source   (this will tell you if there is no source)"
	echo "prog-1f --src-size (this will output '12345' if there is no source)"
	echo "prog-1f --version  (this should have '(one-file)' or '(1f)' in the output)"
	echo "prog-1f --1f       (confirmation beyond doubt, exits with 31 or 32)"
	echo "  Any one-file (1f) option will return 31 (0x1f) if successful, and 32 (0x20) if an error occured, making it easier than ever to detect a one-file (1f) program."
	echo ""
	echo "  Lets see what we can find (may output nothing):"
	ls *-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls *-1f' (programs or folders in the current directory)"
	ls --color=always *-1f
	fi
	ls *-1f.cpp >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls *-1f.cpp' (source in the current directory)"
	ls --color=always *-1f.cpp
	fi
	ls /bin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /bin/*-1f' (programs in /bin)"
	ls --color=always /bin/*-1f
	fi
	ls /sbin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /sbin/*-1f' (programs in /sbin)"
	ls --color=always /sbin/*-1f
	fi
	ls ~/bin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls ~/bin/*-1f' (programs in ~/bin)"
	ls --color=always ~/bin/*-1f
	fi
	ls /usr/bin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /usr/bin/*-1f' (programs in /usr/bin)"
	ls --color=always /usr/bin/*-1f
	fi
	ls /usr/zbin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /usr/sbin/*-1f' (programs in /usr/sbin)"
	ls --color=always /usr/sbin/*-1f
	fi
	ls /usr/local/bin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /usr/local/bin/*-1f' (programs in /usr/local/bin)"
	ls --color=always /usr/local/bin/*-1f
	fi
	ls /usr/local/sbin/*-1f >/dev/null 2>&1
	if [ $? = 0 ]; then
	echo "'ls /usr/local/sbin/*-1f' (programs in /usr/local/sbin)"
	ls --color=always /usr/local/sbin/*-1f
	fi
	echo "'find ~/ -name \"*-1f\"' (files or folders in the current user directory)"
	find ~/ -name "*-1f"
	echo ""
	echo "  The decision has been made to include a '-1f' switch argument. This will display text about the switches '--source', '--src', '--src-type', and '--src-size'. How to verify source (NAME=prog; if [ \`ls -l \$NAME-1f.cpp|cut -d \  -f 5\` = \`./\$NAME-1f --src-size\` ]; then echo Verified; else echo Failed; fi), and the basic principles of one-file (1f). Where to find more information about it (like this program), and where to find more programs+sources."
	echo ""
fi

if [ "$1" = "source" ]; then
	SOURCE_1F=true
fi

if [ "$SOURCE_1F" = "true" ]; then
	echo ""
	echo "Source"
	echo "======"
	echo ""
	echo "  There is a source file embeded in this program,  so all the following applies to this program as well."
	echo ""
	echo "  Any one-file (1f) program fully compiled  will have a source file appended to it.   The source contains code to output that source file to the console, which can be save to a file. Only TEXT files (usually .cpp) and ZIP (.zip) sources are attached, with the '--src-type' switch giving the required file extention."
	echo "  TEXT & ZIP are available on 99.9% of platform architectures. ZIP is only used if the one-file (1f) program  requires more than one source file,  or has extra data files. The ZIP may also contain a 'Makefile', possibly even a './configure' script, but these are NOT a requirement."
	echo "  The primary one-file (1f) source file contains a comment block at the top '/* one-file (1f) compile' that has all the commands used to compile the source and attach it to the binary.  It is multi-line shell code, so any line (without the last \) can be pasted into the command prompt to execute that part of the build process."
	echo "  'source-1f' gives you info about a one-file (1f) source file, including extracting this block to the console. 'make-1f' uses this block to compile, check file sizes, re-compile with sizes, then append source. 'make-1f' is just meant to be a mid-way point, before the need to use a full blown 'Makefile'."
	echo "  one-file (1f) sources do not have to do things the traditional way. Its intended to keep things simple (build wise) and easy to update or change (eg different compiler)."
	echo "  If you have a large set of fuctions outside your 'main' block, once they have been fully debugged you can place them in another file and use the 'include' to hack them back in place in your main source file.   This removes the need for a 'Makefile' or compiling multiple objects."
	echo "  one-file (1f) source should still be clean and well presented, with 'include's at the top,  'struct's and 'typedef's after that, then 'extern'als if you have a truely multi-file source build. Place 'const'ants in logical places after the 'include's, before the end of 'extern'als."
	echo ""
fi

if [ "$1" = "make" ]; then
	MAKE_1F=true
fi

if [ "$MAKE_1F" = "true" ]; then
	echo ""
	echo "Make"
	echo "===="
	echo ""
	echo "  'make-1f' can output a really clean, compact, and simple 'Makefile', when you get to the point that it makes things easier. Otherwise try your best NOT to use 'make', even if you end up creating and using your own 'make.sh' script,  make sure you can easily include it into a comment block (eg. /* one-file (1f) 'make.sh')."
	echo "  If you find a 'Makefile' easier, you can include that in into a comment block too (eg. /* one-file (1f) 'Makefile').   Rememeber that the idea of using a one-file (1f) system  is to have only one source file that can be attached to your  binary after it is compiled."
	echo "  But this simplicity is only useful if you can get your head around your code, so don't be afraid of making that next step and splitting things up.  Try doing it without a 'Makefile' first,  thus avoiding seperate object files and linking them."
	echo "  It is then only a small step to getting the files to function with the use of a 'Makefile',  usually just by adding a .h/.hpp header file for each new source file, containing the required 'extern's etc, and adding 'include's in your main source. "
	echo "  The 'Makefile' generated by  'make-1f' is a straight copy  of the one used by Parallel Realities in their first C++ cross-platform (Linux/Unix) game, Project: Starfighter. After 10 Years it is still a pleasure to use, easy to adjust, and compatible with current systems."
	echo ""
fi

if [ "$1" = "compile" ]; then
	COMPILE_1F=true
fi

if [ "$COMPILE_1F" = "true" ]; then
	echo ""
	echo "Compile"
	echo "======="
	echo ""
	echo ""
	echo ""
fi

if [ "$1" = "options" ]; then
	OPTIONS_1F=true
fi

if [ "$OPTIONS_1F" = "true" ]; then
	echo ""
	echo "Options"
	echo "======="
	echo ""
	echo "  Having used DOS for a long time, and using Linux style command line interface for quite a few years, it is a real pain in the ass when a program does not have '-v/---version' and '--help' switches,  especially if it does not have a 'man' page."
	echo "  Without passing any options a program should show usage at least, and if its a 'new fangled thing' a general outline or description (like this program does). The '--help' switch should give you info related to program use."
	echo "  If your program has a massive amount of switches  that need explanations to be useful,  dont be afraid to provide a condensed help page too,  for when people become familiar with your program.   './configure' understands this concept and provides '--help=short' for that reason."
	echo "  This is one reason why the one-file switch ('--1f') is provided,  to seperate out non-program related source options, along with related explanations and help. There is no rule that says you are required to ONLY have one command line options page, so if your program does some other things besides its main function,  its OK to seperate off all those other options into seperate help pages (eg. '--help-other')."
	echo "  Any help text output should be formated (with space padding) to look good in  80 columns,  but not limit line length to 80 columns.  There is a technique for formatting multi-line text to 40 columns, however this more useful on older 8bit micros."
	echo "  If your program deals with many file formats,  providing a '--formats' switch detailing them is a major boon, essential if you want people to be able to find your app on the net, and it deals with graphics or sound. Allowing a '--format' switch to provide details of the files passed on the command line make it all the more usable, especially if its a sound program, combined with a '--no-audio' switch to output file details only, makes your program exponetially more usable."
	echo "  If your program does things quietly, provide a '-V/--verbose' switch for those times when people want a bit more infomaton. Or if it regularly outputs info,  provide a '--quite' switch exiting with a value other than zero (0) when its not successful.   Basically the more flexible your command line usage is, the more people will be able find uses for your program,  especially when its NOT a text or console app."
	echo "  There is also nothing stopping you from using command pipes and/or signals to provide access and control while your program is running, instead of stopping or killing it, and restarting with different options."
	echo "  Lastly, there is nothing more painful than a cool console app  that won't run outside (X) Windows.  If your program uses a graphics library that also works in a windowing environment, DONT include code that binds your program to that environment, otherwise it is NOT a console app. This often happens by accident, with the addition of some new functionality, but usually it can be done another way that does NOT involve binding your once useful program to a specific windowing  environment."
	echo ""
fi

if [ "$1" = "example" ]; then
	EXAMPLE_1F=true
fi

if [ "$EXAMPLE_1F" = "true" ]; then
	echo ""
	echo "Example"
	echo "======="
	echo ""
	echo ""
	echo ""
fi

if [ "$1" = "skeleton" ]; then
	SKELETON_1F=true
fi

if [ "$1" = "--source" -o "$1" = "--src" -o "$SKELETON_1F" = "true" ]; then
	if [ "$NAME" = "" ]; then
		NAME=_skel
	fi
	if [ "$SKELETON_1F" = "true" ]; then
		echo ""
		echo "Skeleton Code"
		echo "============="
		echo ""
	fi
	cat <<EOF
/*
$NAME-1f
one-file (1f) skeleton code base
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 $NAME-1f $NAME-1f.cpp ; \\
g++ -Wall -O3 -DVERSION=\"1.0.1\" -DPRG_SIZE=\`ls -l $NAME-1f|cut -d \  -f 5\` -DSRC_SIZE=\`ls -l $NAME-1f.cpp|cut -d \  -f 5\` -o $NAME-1f $NAME-1f.cpp ; \\
cat $NAME-1f.cpp >> $NAME-1f
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/*
	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 7370 	// 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 5893 	// 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("$NAME (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[])
{
	/* place used variables here */
	int j, argDone;

	/* this is the begining of commandline argument processing */

	if ( (argc == 1) || ( (argc > 1) && (strcmp("--help", argv[1]) == 0) ) )
	{
		version_1f();
		printf("Copyright 2016 MiNTed Games\n\n");
		printf("one-file (1f) skeleton code base.\n\n");
		printf("usage: $NAME-1f [_option_|<char>|<hex>|<unicode>|<ascii>]\n");
		if (argc > 1)
		{
			printf("_option_:");
			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: $NAME-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("\t$NAME-1f --src > $NAME-1f.cpp\n");
			printf("\t$NAME-1f --src > $NAME-1f.zip\n");
			printf("\t$NAME-1f --src > $NAME-1f\`$NAME-1f --src-type\`\n");
			printf("To verify one-file (1f) source file size:\n");
			printf("\t$NAME-1f --src-size  (match this to the size in a directory listing)\n");
			printf("or use:\n");
			printf("NAME=$NAME; 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);
	}

	/* the rest of your argv[] processing goes here */
/*	sdlPlay_init(); j = 0;
	for (int i = 1; i < argc; i++)
	{
		argDone = 0;
		if (strcmp(argv[i], "--loop") == 0)
		{
			i++;
			if (i == argc)
				{ printf("error: --loop needs a number\n"); exit(1); }
			sdlPlay.loop = atoi(argv[i]);
			argDone = 1;
		}
		if (argDone == 0)
		{
			strcpy(sdlPlay.playList[j], argv[i]);
			j++;
		}

	}
	sdlPlay.playlist = j;
*/
	/* place your while(true) loop here (if you have one) */
/*	section = 0;
	while (true)
	{
		// non-blocking (shows high CPU usage)
		// should be event driven, but this is faster
		switch(section)
		{
			case 0:
				section = getAudioFile();
				break;
			case 1:
				section = isPlaying();
				break;
			case 2:
				section = playLoop();
				break;
			case 5:
				section = playMusic();
				break;
			case 6:
				section = playMod();
				break;
			case 7:
				section = playSound();
				break;
			case 9:
				sdlPlay.next++;
				section = 0;
				break;
		}
	}
*/
	/* this is the end, .. my friend, the end */
	return(0);
}
EOF
	if [ "$SKELETON_1F" = "" ]; then
		exit 31
	fi

	echo "<< snip >>"
	echo ""
	echo "  Some commented parts above are present only if you want to get slightly more complex things going straight away. They are optional, and should probably be deleted from your final source immediately if you dont intend to use them."
	echo "  They are examples of the actual code that is used in 'sdlPlay-1f' to process arguments, and run the main (non-blocking) loop."
	echo ""
	echo "  You can save the above skeleton directly to a file using:"
	echo "one-file-1f --src > _skel-1f.cpp"
	echo "  or if you already know what your program is going to be called:"
	echo "NAME=_name_here_ one-file-1f --source > \$NAME-1f.cpp"
	echo "  NOTE: if you use the second style, then 'one-file-1f --src-size' will only match if NAME is 5 letters long (FYI: there are 21 references changed)."
	echo ""
	echo "  Thats it, enjoy programming, one-file (1f) style ..."
	echo ""
fi

if [ "$1" = "future" ]; then
	FUTURE_1F=true
fi

if [ "$FUTURE_1F" = "true" ]; then
	echo ""
	echo "Future"
	echo "======"
	echo ""
	echo "  It depends on how useful one-file (1f) programs are, weather or not there will be a need for 'lib-1f' as it were. It does mean releasing your source code into the wilds of the net, and not being able to control its evolution outside what you yourself provide."
	echo "  But it does enable the possibility of providing OS level extensions that makes using an OS a bit more fun, flexible and friendly, all at the same time."
	echo "  The current future of one-file (1f) is to provide a bunch of console programs that do things you currently need a full KDE, GNOME or other, now 'over the top' windowing system to do.  If it works, 'dotOS' will be able to boot on multiple architectures from the same device, and moving to a new/different architechture is a breeze once you have a compiler for it."
	echo "  In addition to those console programs are other console 'mini-utilities', like character code output, command line calculator, a font viewer that can also output fonts to PNG, a 'image-font' creator,  useful for many (SDL/SDL2) games and graphics libraries (GuiChan) or programs (Grafx2)."
	echo "  Basically lots of console programs that can be easily controled from somewhere else, like a non-(X)Windows based desktop. If a one-file (1f) source .cpp file is correctly assembled, it makes adding that functionality to a greater project that much easier, and changing it is even easier again."
	echo ""
	echo "  The future is so bright, I gotta wear 'shades-1f' ..."
	echo ""
fi

exit 0
