/*			USERS		module 1
    "us1.c"
					contents = Add routine
*/
/*=============================================================================
			INCLUDES
*/
/*
#define		debug1		0
*/
#define		OVERLAY
#include	"users.os"
#include	"standard.inc"

#define		EXTERNal	0

#include	"users.dat"

/*=============================================================================
			HISTORY

date		9 February 1984
person		tpl

ver	0
rev	0
mod	b
patch	5


 ver / rev
"""""""""""
    0/0

     mod  patch
    """"""""""""
	a6		30 January 1984		tpl
		.RELEASED TO SOFTWARE TEST.

	a0		16 December 1983	tpl
		.Create this file from us0b.c.

*/
/*page*/
/*=============================================================================
				ROUTINES
*/
/*---------------------------------------------------------------------------*/
#ifdef OVERLAY
ovmain ()
#else
Add()
#endif
{
  int	free_entry;
  struct users_entry u_entry;
  struct config_entry c_entry;
  CHAR	duplicate = TRUE;
  CHAR	fake;
  register CHAR		j, i, length;

    if( (free_entry = First_Free_Entry()) == 0xff )
    {
	putz("The Users Table is full.\n\
 To Add another entry you must delete one.\n");
	return;
    }

    Reset_Entry( &u_entry, &c_entry );

/* Name setting.	*/

    putz("\n\nAdd an entry into the Users Table.\n\n");
    printz("Adding entry %d.\n\n", free_entry + 1);
    putz("Press RETURN to go back to main menu.\n\n");

    while ( duplicate )
    {
	clear( input_buffer, Lname, SPACE);
	putz("Enter new user name -->                (8 characters maximum)");
	repchar(BS,37);
	if( (length = Tintostring( input_buffer, Lname, FALSE)) == 0 )
	{
	    putz("\n");
	    return;
	}
	else
	{
	    strUpper(input_buffer);
/* Don't want '\0'.Allows duplicate name to be found using all chars of name.*/
	    input_buffer[length] = SPACE;

	    if ( Is_Dup_Users_Entry( input_buffer ) == NuserTblEntries )
		duplicate = FALSE;
	    else
		printz("%c        That name already exists.\n",BELL);

	}/*else*/

    } /* while duplicate */

    putz("\n");
    blockmv( u_entry.name, input_buffer, Lname);

/* Password setting.	*/

    clear( input_buffer, Lpassword, SPACE);
    printz("Enter Password      -->                (6 characters maximum)");
    repchar(BS,37);
    length = Tintostring( input_buffer, Lpassword, TRUE);
    strUpper(input_buffer);
    input_buffer[length] = SPACE;
    blockmv( u_entry.password, input_buffer, Lpassword);

/* Operating System setting.	*/

    if ( (u_entry.op_sys = Read_Op_Sys(RETNOTOK)) == CPMsys )
		/* Set the type of cpm wanted.	*/
    {
	input_buffer[0] = Do_Menu( &cpm_type , RETNOTOK );
	u_entry.op_sys |= input_buffer[0] - '0'; /* ascii to hex conversion. */


/* Ask if HiMEM or Full Service O.S. desired.	*/
	putz("\n");
	u_entry.flags = Read_OS_Kind(RETNOTOK);

    } /* if CPM */

/* Default Partition Assignments setting.	*/

    Read_Assignments( &u_entry, &c_entry, free_entry, RETNOTOK);

/* Log In Command setting.	*/

    clear( input_buffer, LtypeAhead, SPACE );


    putz("\n");
    putz("Enter commands to be automatically executed upon login.\n");
    putz("31 character maximum.  Press RETURN at end of string.\n");
    putz("Use BACKSPACE or DELETE to edit commands.  Press @ before\n");
    putz("entering RETURN, BACKSPACE, DELETE, or @ into commands.\n");
    putz("--> ");

    length = C_intostring( input_buffer, LtypeAhead+1, TRUE);

    c_entry.size_type_ahead = length;

    blockmv( c_entry.type_ahead, input_buffer, LtypeAhead);
    putz("\n\n");

/* Ask if entry is what user wants. If so, put in table. If not, don't.	*/

    if ( Ask_if_entry_OK( &u_entry, &c_entry ) )
    {
	blockmv( &users_table[ free_entry ], &u_entry,
						sizeof( struct users_entry ));
	blockmv( &config_table[ free_entry], &c_entry,
						sizeof( struct config_entry ));
	changes_made = TRUE;	/* Mark global flag that change was made. */
    }

} /* Add */

/*---------------------------------------------------------------------------*/

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
