/***********************************************************************\
*               BBSADD By S.K.Lindsay aka Linds - Terradome             *
*************************************************************************
* Sorry The codes a bit messy, I have only been doing C for 4 days, be  *
* prepared to see a lot of code from me, I am determined to make a name *
* for my self in the Amiga world. This file should compile no problems  *
* on any C package on any computer (The escape codes may cockup a bit   *
* on the PC etc.) as I have only used standard input and output         *
* functions. If you have any questions, problems or anything  please    *
* contact me, I want connections worldwide, I want code-swappers, demo  *
* writers, tracker writers, grapix artists, C programmers etc. to all   *
* contact me, I * WILL * reply to ANYONE who writes, As it stands at    *
* the moment I am only O.K at C, I can't do a lot of things so I would  *
* like help of anyone or everyone who can help me get good. Also I may  *
* not be too hot myself yet, but I know a lot of people so if you have  *
* a problem on any computer or a piece of hardware, software etc. write *
* to me and tell me what it is and the chances are I will know someone  *
* that can help you.                                                    *
*                                                                       *
*   Contact address : 146 High St West, Coatham, Redcar, Cleveland,     *
*                     TS10 1SD. England.                                *
*                                                                       *
*  If you prefer to phone then contact me on +44 (0642) 475394 and ask  *
*  for Steven (Don't ask for linds or you will be hung up on!!)         *
\***********************************************************************/

#include <stdio.h>

void syntax();
void info();

main(int argc, char *argv[])
{
  FILE *in, *in2, *out;
  int c, working=0, loop=0;

	printf("\n[1m[4mBBSADD[0m by [1m[32mLINDS [0m- [33m[3m[1mTERRADOME[0m\n\n");

	if (argc <2)
	{
		info();
		exit();
	}
	
	if (argc >4)
	{
		printf("[1mError : [0m[32mToo many arguments.[0m\n");
		syntax();
		exit();
	}
	
	if (argc != 4)
	{
		printf("[1mError : [0m[32mNot enough arguments.[0m\n");
		syntax();
		exit();
	}

	if ((in = fopen(argv[1],"r")) == NULL) {
		printf ("[1mError :[0m[32m Can't load source1 textfile %s\n\n[0m",argv[1]);
		exit();
	}
	
	if ((in2 = fopen(argv[2],"r")) == NULL) {
		printf ("[1mError :[0m[32m Can't load source2 textfile %s\n\n[0m",argv[2]);
		fclose(in); exit();
	}

  if ((out = fopen(argv[3],"w")) == NULL) {
    printf ("[1mError :[0m[32m Can't save destination %s\n\n[0m",argv[3]);
    fclose(in); fclose(in2); exit();
  }

  while ( working == NULL ) {
  if((c=getc(in)) == EOF) {
    printf("[1mSource1 Textfile Read Ok.[0m\n"); working=1; }

  if ( working == NULL ) {
  if((putc(c,out)) == EOF) {
	  printf("[1mError :[0m[32m Disk Write Error.\n\n[0m"); working=2; } }
  }

  fclose (in);

  if (working == 1) {
  for (loop=0; loop<2; loop++) {
  if((putc(10,out)) == EOF) {
    printf("[1mError :[0m[32m Disk Write Error.\n\n[0m"); working=2; }
  } }

  while (working == 1 ) {
  if((c=getc(in2)) == EOF) {
    printf("[1mSource2 Textfile Read OK.\n[0m"); working=3; }

  if ( working == 1 ) {
  if((putc(c,out)) == EOF) {
    printf("[1mError :[0m[32m Disk Write Error.\n\n[0m"); working=2; } }
  }

  fclose(in2);

  if (working == 3)
    printf("[1mFile Written Correctly, Bye, Bye![0m\n\n");
  
  exit();
}

void syntax()
{
	printf ("\n[1m[33m  Syntax : [0m[1mBBSADD[0m[32m <source1> <source2> <destination>[0m\n\n");
}

void info()
{
	printf ("BBSADD will merge a textfile to the top of another textfile\n");
	printf ("and place a one line gap inbetween them. This was originally\n");
	printf ("intended for Sysops who wish to put the logo and info of there\n");
  printf ("BBS at the top of textfiles to be downloaded from there systems\n");
  printf ("(thus the name), But it can be used to merge any textfiles together.\n");
  printf ("example : differant manuals for the safe product, BBS lists, jokes etc.\n");
  printf ("If it is useful to you send me some good C source code and I will send\n");
  printf ("you some back!\n");
  printf ("\n[1mAddress : [0m[1m[32m[41m146 High St West, Coatham, Redcar, Cleveland, TS10 1SD, England.\n[0m");
	syntax();
	printf ("Hope it's useful, Greets to [1mPete[0m, [1mFudge[0m, [1mSteve[0m and [1mPazza[0m\n\n");
}
