/************************************************************************
*  Version 3.00  MANDELBROT - Self-Squared Dragon Generator  29-May-86  *
*  Commodore Amiga            Help Screens                     MAND4.C  *
*************************************************************************
*         Copyright (c) 1986, Robert S. French and R. J. Mical          *
* --------------------------------------------------------------------- *
*  This program has been placed in the public domain.  A limited        *
*  license is hereby granted for the unlimited use and distribution of  *
*  this program, provided it is not used for commercial or profit-      *
*  making purposes.  Thank you.                                         *
*************************************************************************
*  Author information:            | Name:   R. J. Mical                 *
*                                 | USnail: Commodore-Amiga, Inc.       *
*  Name:   Robert S. French       |         983 University Avenue       *
*  USnail: 2740 Frankfort Avenue  |         Los Gatos, CA  95030        *
*          Louisville, KY  40206  \-------------------------------------*
*  Phone:  (502) 897-5096              UUCP: ihnp4!ptsfa!well!french    *
*  ARPA:   French#Robert%d@LLL-MFE or RFrench@MIT-MULTICS               *
*************************************************************************
*  Please send any comments, suggestions, or bugs to one of the above   *
*  addresses.                                                           *
************************************************************************/

#include "mand.h"
#include "globals.h"


Help()
{
	FILE *help_fp;
	int i,opcount;
	char code[10],level[81],line[81],morehelp[10][30];

	help_fp = fopen(HELPNAME,"r");
	if (help_fp == 0) {
		printf("No help is available...sorry!\n");
		return(0);
	}

	for (EVER) {
		fgets(line,80,help_fp);
		if (*line == '>')
			break;
	}

	*level = 0;
	*code = 0;

	for (EVER) {
		printf("\fHelp Level: %s\n\n",(*level == 0) ? "Main" : level);
		for (EVER) {
			fgets(line,80,help_fp);
			if (*line == '/')
				break;
			printf("%s",line);
		}
		for (opcount=0;opcount<11;opcount++) {
			fgets(line,80,help_fp);
			if (*line == '.')
				break;
			line[strlen(line)-1] = 0;
			strcpy(morehelp[opcount],line);
		}
		if (opcount == 11) {
			printf("\n\nHelp file corruption: too many additional topics!\n\n");
			fclose(help_fp);
			return(0);
		}
		if (opcount == 0) {
			printf("\n\n                    -- End of help --\n");
			fclose(help_fp);
			return(0);
		}
		for (EVER) {
			printf("\nAdditional help is available on:\n");
			for (i=0;i<opcount;i++) {
				if ((i % 3) == 0)
					printf("\n");
				printf("%-25s",morehelp[i]);
			}
			printf("\n\nWhich topic would you like help on? ");
			rewind(stdout);
			fgets(line,80,stdout);
			rewind(stdout);
			line[strlen(line)-1] = 0;
			if (*line == 0) {
				printf("\n");
				fclose(help_fp);
				return(0);
			}
			for (i=0;i<opcount;i++)
				if (compare(line,morehelp[i]))
					break;
			if (i == opcount)
				printf("\nSorry!  Help is not available on that topic.\n");
			else
				break;
		}
		*line = i+'0';
		line[1] = 0;
		strcat(code,line);
		if (*level != 0)
			strcat(level,"/");
		strcat(level,morehelp[i]);
		for (EVER) {
			fgets(line,80,help_fp);
			if (*line == '>')
				if (strncmp(line+1,code,strlen(code)) == 0)
					break;
		}
	}
}

compare(s,t)
char *s,*t;
{
	while (*s)
		if (toupper(*s) != toupper(*t))
			return(0);
		else {
			s++;
			t++;
		}
	return(1);
}

AvailableCommands()
{
	FILE *help_fp;
	char line[81];

	help_fp = fopen(HELPNAME,"r");
	if (help_fp == 0) {
		printf("No help is available...sorry!\n");
		return(0);
	}

	printf("\f");

	for (EVER) {
		fgets(line,80,help_fp);
		if (*line == '>')
			break;
		printf("%s",line);
	}
	fclose(help_fp);
}

CurrentSettings()
{
	SHORT i, c;

	printf("\f             Description  Command  Current Value\n");
	printf("========================  =======  =============\n");
	printf("       Start Real (Left)   SR n:   ");
	prtflt(CNVFLT(MAKEFP(start_r)),stdout);
	printf("\n        End Real (Right)   ER n:   ");
	prtflt(CNVFLT(MAKEFP(end_r)),stdout);
	printf("\nStart Imaginary (Bottom)   SI n:   ");
	prtflt(CNVFLT(MAKEFP(start_i)),stdout);
	printf("\n     End Imaginary (Top)   EI n:   ");
	prtflt(CNVFLT(MAKEFP(end_i)),stdout);
	printf("\n");

	printf("         Function Number    F n:   %d\n", func_num);
	printf("   Max Examination Count   MC n:   %d\n", max_count);
	printf("               Color Set   CS n:   %d\n", color_set);
	if (color_set < 2) {
		printf("         Color Increment   CI n:   %d\n", color_inc);
		printf("            Color Offset   CO n:   %d\n", color_offset);
	}
	else
		for (i = 0; i < 32; i++) {
			if ((i % 6) == 0)
				printf("Col ");

			c = UserPalette[i];

			printf("%02d=%02d,%02d,%02d ", i, (c>>8) & 0xF, (c>>4) & 0xF, c & 0xF);
			if ((i % 6) == 5)
				printf("\n");
		}

		printf("\n");
	printf("              Color Mode   CM n:   %d\n", color_mode);
	printf("           Color Divisor   CD n:   %d\n", color_div);
	printf("            Color In Set   CT n:   %d\n", color_inset);
	printf("    Display Width/Height MX/Y n:   %d %d\n", max_x, max_y);
	printf("  Max pixel lines in mem   MM n:   %d\n\n",max_mem);
}
