#include <stdio.h>
#include <string.h>
#include <ctype.h>

extern void computer(void)
{
  int i,q;
  char o,c;
  char n[32],p[32],s[32];
  char *w[32];
  
  printf("\n\n\nWelcome to the Data Com Network service\n\nLog in name : ");
  gets(n);
  i=0;
  
  while(n[i] != '\0')
  {
    n[i] = toupper(n[i]);
    i++;
  }
  
  if (strcmp(n,"S.CARTER")==0){
    printf("Password  :");
    gets(p);
    i=0;
  
    while(p[i] != '\0')
    {
      p[i] = toupper(p[i]);
      i++;
    }
    c = -1;
    if(strcmp(p,"WIBBLE")==0){
      while(q!=1)
      {
      printf("Welcome to the network\n\nSecurity Restriction Level 5\n\nUser Options :\n\n        Operational Status  (1)\n        Personnal Log       (2)\n        Exit                (3)\n\n-->");
      
      gets(s);
      i=0;
      
      while(s[i] != '\0')
      {
        s[i] = toupper(s[i]);
        i++;
      }
      
      split(s,w,32);
      
      if ((strcmp(w[0],"OPERATIONAL")==0) && (strcmp(w[1],"STATUS")==0))
        operation_status();
      if ((strcmp(w[0],"PERSONNAL")==0) && (strcmp(w[1],"LOG")==0))
        printf("Warning!  System error 324.  Please contanct Network Administration for further help\n");
      if (strcmp(w[0],"EXIT")==0)
        q=1;
      }
    }
    else
      printf("Wrong Password.  Access Denied.\n");
  }
   else
   printf("User not known!\n\nAccess Denied\n");
}
 
operation_status()
{
  extern status_flags[];
  extern char *comp_op[];
  extern char *exits[];
  int i,c,q,o;
  char s[32];
  char *w[32];
  
  q=0;
  while(q != 1)
  {
  
  printf("\n\nOption  :  Operational Status\n\nPower  :\n          Auxiliary : ");
  if(status_flags[0]==1)
    printf("ON\n");
  else
    printf("OFF\n");
  printf("               Main : ");
  if(status_flags[1]==1)
    printf("ON\n");
  else
    printf("OFF\n");
  printf("            Network : ");
  if (status_flags[2]==1)
    printf("ON\n");
  else
    printf("OFF\n");
  printf("       Enviromental : ");
  if (status_flags[3]==1)
    printf("ON\n");
  else
    printf("OFF\n");
  printf("           Security : ");
  if (status_flags[4]==1)
    printf("ON\n");
  else
    printf("OFF\n\n-->");
  
  gets(s);
  i=0;
  
  while(s[i] != '\0')
  {
    s[i] = toupper(s[i]);
    i++;
  }
  
  split(s,w,32);
  
  c=-1;
  
  if(strcmp(w[0],"TURN")==0){
    if(strcmp(w[2],"ON")==0)
      o=1;
    if(strcmp(w[2],"OFF")==0)
      o=0;
    for(i=0;i<=4;i++){
      if(strcmp(w[1],comp_op[i])==0)
        c=i;  
    }
    if(c==0){
      if(o==0){
        printf("Powering Down Stand by generator\n");
        status_flags[0]=0;
      }
      if(o==1){
        printf("Powering up stand by generator\n");
        status_flags[0]=1;
      }
    }
                
    if(c==1){
      if(status_flags[5]==1){
        if(o=1){
          status_flags[1]=1;
          printf("Main Power Initialised\n");
        }
        else 
        {
          status_flags[1]=0;
          printf("Main Power Off\n");
        }
      }
      else
        printf("System Error 31!  RCV-DATA CARRIER NOT FOUND.\n");
    }
    
    if(c==2)
      printf("WARNING!  OPERATION CANCELLED.  CLOSURE OF THE NETWORK IS NOT ADVISEABLE FROM THIS TERMINAL!\n");
      
    if(c==3)
      printf("\nSystem Error!  Signal terminated at &4310432\n");
      
    if(c==4){
      if(status_flags[0]==1){
        if(o==0){
          printf("Security Block cancled\n");
          exits[107]="NSW";
          exits[99]="ES";
          status_flags[4]=0;
        }
        else if(o==1){
          status_flags[4]=1;
          exits[107]="NW";
          exits[99]="E";
          printf("Security Block in place\n");
        }
      }
    }
    
    if(c==-1)
      printf("Unknown Command\n");
      
  }
  if(strcmp(w[0],"EXIT")==0)
    q=1;
  }
}

personnal_log()
{
  int c,i,q;
  char s[32];
  char *w[32];
  extern char *log[];
  extern int date[];
  
  q=0;
  
  while(q!=1)
  {
  
    printf("\n\nPersonal Logs for July :");
    for(i=0;i<=8;i++)
      printf("  %d July 3243	\n",date[i]);
  
    printf("(1)  Read Log   (2)  Write Log    (3)  Exit\n\n-->");
    gets(s);
    i=0;
  
    while(s[i]!='\0')
    {
      s[i] = toupper(s[i]);
      i++;
    }
  
    split(s,w,32);
  
    if(strcmp(w[0],"READ")==0){
      printf("\nEnter date to read   -->");
      c=getchar();
      printf("\n%s\n",log[c]);
    }
    if(strcmp(w[0],"WRITE")==0)
      printf("System Error: Carrier terminated at &342FA3B2");
  
    if(strcmp(w[0],"EXIT")==0)
      q=1;
    
  }
}
