/*******************************************************************
   *    version 1.0a
   *
   *    main.c
   *    Author: Elice Wu. Date: 5 June 1997
   *
   *    This module contains all of the Tcl_CreateCommand commands
   *    which will link C procedures to Tcl, ie. enabling Tcl
   *    to call C procedures as if they were Tcl commands.
   *
   *    This module also contains the call to start the initial
   *    Log in screen on the system.
   *
   ******************************************************************/
#include <stdio.h>
#include <stdlib.h>

#include "iface.h"

char SUBJECT[6] = "ab100";
int  ACCESS = 0;
char USER[10] = "ab100ab";

/* special hack to use Sun shared libraries */
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;

int Tcl_AppInit(Tcl_Interp* interp)
/*
    Input: interp is the TCL interpreted script
    Output: Returns an integer indicating with the initialisation was a success		   or failure.
    Pre-conditon: 
    Post-condition: 
    Description: initialise interpreter and link c functions to TCL module*/

     {
        int    status;

        status = Tcl_Init(interp);

        if (status != TCL_OK)
        {
            return TCL_ERROR;
        }

        /* Initialize Tk values. */
        status = Tk_Init(interp);

        if (status != TCL_OK)
        {
            return TCL_ERROR;
        }

	/* these are all of the Tcl_Create_Commands for each of the
	   procedures supplied by each of Student, Tutor, Lecturer,
	   Security, Global, and Help Modules. */

	Tcl_CreateCommand(interp, "Display_Student_GradeI",
		Display_Student_GradeI, NULL, NULL);

	Tcl_CreateCommand(interp, "Add_Student_Grades",
		Add_Student_Grades, NULL, NULL);

	/*******************************************************************
	 * and so on and so forth.... registering all of the C procedures
	 * so they can be called from the tcl/tk scripts.
	 ******************************************************************/

        return TCL_OK;
     }

int main(int argc, char** argv)
/*
    Input: Reference to the TCL script
    Output: The functionality of the program
    Pre-conditon: 
    Post-condition: 
    Description: This is the main program for the application
*/

     {

#ifdef TESTING  
         Tcl_EvalFile(interp, "../tcl/testdriv.tcl");
#else
         Tcl_EvalFile(interp, "../tcl/LogOn.tcl");
#endif

		Tk_MainLoop();
	} else {
		printf("Sorry toplevel window cannot be created\n");
	}

        char * new_argv[argc + 2];
        int i;
        
        /* copy argv to new_argv */
        for (i = 0; i < argc; i++)
                new_argv[i] = argv[i];
        
        /* extend argv by 1 element and add our script name */
        argc += 1;
        new_argv[argc - 1]="tcl/LogOn.tcl",
        new_argv[argc] = NULL;
        
        /* run Tk interpreter */
        Tk_Main(argc, new_argv, Tcl_AppInit);

	return 0;  
}

Return