// 
// smeg - A satellite modelling and prediction tool
// Copyright (C) 1999  Tom Rothamel
// 
// 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; see the file COPYING.  If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.

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

#define INT 1
#define FLOAT 2
#define STRING 3


struct setable {
	char *name;
	int type;
	void *ptr;
};

double lat = 40.9037;
double lon = -73.3455;
double alt = 0;
double minele = 0;
double bigstep = 60;

extern char *lesscmd;
extern char *printcmd;

setable setlist[] = {
	{"lat", FLOAT, &lat},
	{"latitude", FLOAT, &lat},
	{"lon", FLOAT, &lon},
	{"longitude", FLOAT, &lon},
	{"alt", FLOAT, &alt},
	{"altitude", FLOAT, &alt},
	{"minelev", FLOAT, &minele},
	{"bigstep", FLOAT, &bigstep},
	{"pager", STRING, &lesscmd},
	{"lesscmd", STRING, &lesscmd},
	{"printcmd", STRING, &printcmd},
	{NULL, 0, NULL}
};
	

void Set(char *name, char *value) {
	setable *slp;

	slp = setlist;

	while (slp->name) {
		if(!strcasecmp(slp->name, name)) break;
		slp++;
	}

	if (!slp->name) {
		fprintf(stderr, "Error: '%s' is not settable.\n", name);
		return;
	}
	
	switch(slp->type) {
	case INT:
		*(int *) slp->ptr = atoi(value);
		break;
	case FLOAT:
		*(double *) slp->ptr = atof(value);
		break;
	case STRING:
		*(char **) slp->ptr = value;
	}	

}

void ShowLocation() {
	fprintf(out, "The current location is:\n");
	fprintf(out, "\tLatitude:  %.4f %c\n", fabs(lat), (lat < 0) ? 'S' : 'N');
	fprintf(out, "\tLongitude: %.4f %c\n", fabs(lon), (lon < 0) ? 'W' : 'E');
	fprintf(out, "\tAltitude: %.4f\n", alt);
}

	
		
