/*
 * $Header: calencheck.c,v 2.3 91/03/27 16:44:57 billr Exp $
 *
 * calencheck.c - check for pending appts without the overhead
 *		  of the full blown calentool
 *
 * Copyright (C) 1989, 1991 Tektronix, Inc.
 *	All Rights Reserved
 * Permission is hereby granted to use and modify this file in source
 * or binary form as long as it is not sold for profit and this copyright
 * notice remains intact.
 */

/*
 * define NO_DEFAULTS if you don't need info looked up in the .defaults
 * file (saves memory by not linking in pixrect lib with SunOs > 4.0).
 */
#include <stdio.h>
#include <time.h>
#include <string.h>
//#include <sys/file.h>
#include "ct.h"

int read_only = 1;		/* no modifications allowed */
int n_tslots, otherfile = 0;
int include_old = 0, save_old = 0;
int new_entry = 0;
int start_hour = 0, end_hour = 24, n_slots;
int working_msg=0, nr_weekdays=5, locked=0; /* amiga: added */
struct tm current, today, closedate;
struct tm First, Last;
char *progname, *othername;
struct dayslot *slots;
struct weekrect week_boxes[7];
int show_future = 1;
int one_based = 0, version2 = 0;
int beep = 1;

/* AMIGA: getopt simulieren */
static char *optarg;
int getopt(int argc, char *argv[], char *x)
{
  static int Argc=1;
  int        res=EOF;

  if (Argc >= argc || argc == 1)
	  return EOF;
  while (argv[Argc][0] != '-') /* yes, an option */
    if (Argc >= argc)
		 Argc++;
	 else
		 return EOF;
	if (argv[Argc][0] == '-')
    {
      optarg = argv[Argc] + 2 /* == '-' ? NULL:argv[Argc+1])*/ ;
	   res = argv[Argc][1];
		Argc++;
/*		if (!optarg)
			Argc += 2;
		else
	      Argc++;
*/
    } 
	return res;
  } /* end func getopt */

void main(int argc, char *argv[])
 {
	int flag;
	extern char *optarg;
	
	if (progname = strrchr(*argv, '/'))
		progname++;
	else
		progname = *argv;

	start_hour = START_HOUR;
	end_hour = END_HOUR;

	get_today();	/* initial day is today */
	current = today;
	
	while ((flag = getopt(argc, argv, "f:S:s:")) != EOF)
		switch (flag) {
		    case 'f':   /* use this file */
			otherfile = 1;
			othername = optarg;
			break;

		    case 's':
			start_hour = atoi(optarg);
			if (start_hour > 23 || start_hour < 0)
				printf("start hour must be in range 0 - 23\n");
			break;

		    case 'S':
			end_hour = atoi(optarg);
			if (end_hour > 24 || end_hour < 1)
				printf("end hour must be in range 1 - 24\n");
			break;

		    case '?':
		    default:
			fprintf(stderr, "usage: %s [-f <appt_file>]", progname);
			fprintf(stderr, " [-s <starthour>]");
			fprintf(stderr, " [-S <endhour>]\n");
			exit(1);
		}

	err2console(TRUE);

	/*
	** setup number of slots and allocate memory for them
	*/
	if ( start_hour >= end_hour )
		err_rpt("Start Hour must be less than Stop Hour", FATAL);
	n_tslots = (end_hour - start_hour) * 2;
	n_slots = n_tslots + N_NOTESLOTS;
	/* make room for n_slot dayslot entries and week entries */
	if ((slots = (struct dayslot *)malloc(n_slots* sizeof(struct dayslot))) == NULL)
		err_rpt("Can't get enough storage for day slots", FATAL);

	do_files(FALSE);
	closedate = today;
	check_calendar();
	for (;;) {
		/* only check appointments every TIME_OUT minutes */
		Delay(TIME_OUT * 60);
		check_calendar();
	}
}

/* some stubs required by routines in common.c not used by calencheck */
//next_appt(i, j)
//int i, j;
//{
//}

draw_day_appts()
{
}

deactivate_slot(i, j)
int i, j;
{
}

int
put_aentry(f, a)
FILE *f;
struct appts_entry *a;
{
	return 0;
}

//working(i)
//int i;
//{
//}
