


# include <stdio.h>
# include <errno.h>
# include <string.h>
# include <stddef.h>
# include <sys/file.h>

# include "serv.h"
# include "../registrar/tables.h"
# include "../registrar/protocol.h"
# include "../registrar/return_codes.h"
# include "buffer.h"

#define   EOT   "\012.\015\012"
char       *mit_id_ptr;
char       *term_ptr;
char       *sort_columns_ptr;
int        rc;


main()
{
  buffer_t          in_head_buffer;
  buffer_t          in_buffer;
  buffer_t          out_buffer;
  message_header_t  out_header;
  static char       out_buff[200];
#define             OUT_BUFF_LEN  200

  char              reply[40];

  int        loc_buflen = 12;
  char       request_type;
  static char   in_buf[300];
  #define       IN_BUF_LEN   300

  #define DOT '.'

  char   first_field[6] = "first";
  char   sec_field[4]   = "sec";
  int     rc;

  static char    first_line[80];
  int     line_len = sizeof(first_line);

  printf( "\nEnter request type + parameters followed by CR,\n");
  printf( "or . to QUIT\n\n");
  printf("%s", EOM);  
  fflush(stdout);

  out_buff[199] = '\0';
  
  while(TRUE)
    {

      /* We'll initialize our in_buffer descriptor using already described */
      /* in_buf array                                                      */
      init_buf (&in_buffer, IN_BUF_LEN, in_buf);

      /* We'll read the whole buffer: */
      get_request_buf(&in_buffer);
      
      request_type = *( next_field (&in_buffer) );
      
      switch (request_type) {
	
      case BANNER:
	printf( "\nEnter request type + parameters followed by CR,\n\n");
	printf( "\nor . to QUIT\n\n");
	fflush(stdout);
	break;
	
      case BIO_RECORD:
	log_aline( "\nget unique BIO record\n\n");
	sprintf(reply, "get unique BIO record "); 
	break;
	
      case GRADE_HISTORY_TERM_DEF:
	log_aline( "\nget grade history for term(def)\n\n");
	sprintf( reply, " get grade history for term(def) ");
	break;
	
      case GRADE_HISTORY_ALL_DEF:
	log_aline( "\nget grade history for all terms(def)\n\n");
	sprintf (reply, "get grade history for all terms(def) ");
	break;
	
      case GRADE_HISTORY_TERM_SORT:
	log_aline( "\nget grade history for term(sort)\n\n");
	sprintf (reply, " get grade history for term(sort) ");
	break;
	
      case GRADE_HISTORY_ALL_SORT:
	log_aline( "\nget grade history for all terms(sort)\n\n");
	sprintf (reply, " get grade history for all terms(sort) ");
	break;
	
      case TERM_SUMMARY_ALL:
	log_aline( "\nget term summary for all terms\n\n");
	sprintf (reply, " get term summary for all terms ");
	break;
	
      case GRADES_TERM:
	log_aline( "\nget grades for term\n\n");
	sprintf (reply, " get grades for term ");
       	break;
	
      case GRADES_ALL:
	log_aline( "\nget grades for all terms\n\n");
	sprintf (reply, " get grades for all terms ");
	break;
	
      case AUDIT_STRIP:
	log_aline( "\nget audit strip\n\n");
	sprintf (reply, " get audit strip ");
	break;
	
      case SUBJECT_INFO:
	log_aline( "\nget subject info for a subject\n\n");
	sprintf (reply, " get subject info for a subject ");
	break;
	
      case UPDATED_BIO_RECORD:
	log_aline( "\nreceive updated BIO record\n\n");
	sprintf (reply, " receive updated BIO record ");
	break;

      case DOT:
	printf( "\nend of connection\n\n");
	goto dot;
	break;
      
      default:
	printf( "\nunrecognized record type %c\n\n",
		request_type);
	fflush(stdout);
      }

      out_header.buflen      = OUT_BUFF_LEN;
      out_header.return_code = OK;
      out_header.record_type = request_type;
      out_header.num_records = 4;
      init_buf (&out_buffer, OUT_BUFF_LEN, &out_buff[0]);
      append_header (&out_buffer, &out_header);
      append_field  (&out_buffer, &reply[0]);
      /*  append_eom    (&out_buffer);  */

      log_aline("Server: before writing the response\n");
      log_aline(out_buffer.bufptr);
      write (FILE_OUT, out_buffer. bufptr, OUT_BUFF_LEN);
      write (FILE_OUT, EOM, EOM_LEN);
      fflush(stdout);

    }
/*      
 * end of the loop till the end of connection - EOC
 */
 dot: ;;
 /* end of connection */

}









