Main Page | Class List | File List | Class Members | File Members

interface.c File Reference

#include "standard.h"
#include "interface.h"
#include <sys/types.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define STRLEN   256

Enumerations

enum  {
  Prompt, Run, Cont, Next,
  Quit
}

Functions

void prompt (void)
void get_input (void)
int white (char c)
void parse_input (void)
int equals (char *s1, char *s2)
void show_vars ()
char * rank (int x)
void show_score (void)
void print_commands (void)
void do_cmd (void)
void interface (void)

Variables

char line [STRLEN]
char lastline [STRLEN]
char cmd [STRLEN]
char arg [STRLEN]
int breakpoint = 0
int stop = 0
enum { ... }  mode
int Quit_Mux
int debug


Define Documentation

#define STRLEN   256
 

Definition at line 7 of file interface.c.


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
Prompt 
Run 
Cont 
Next 
Quit 

Definition at line 15 of file interface.c.

00015 { Prompt, Run, Cont, Next, Quit } mode;


Function Documentation

void do_cmd void   )  [static]
 

Definition at line 125 of file interface.c.

References arg, breakpoint, clrscr(), cmd, debug, equals(), get_clock(), mode, print_commands(), Quit_Mux, show_score(), show_vars(), and stop.

Referenced by interface().

00126 {
00127   char s[STRLEN];
00128   if (equals(cmd, "score")) {
00129     show_score();
00130   } 
00131   else if (equals(cmd, "xyzzy")) {
00132     if (debug)
00133       printf("Poof!\n");
00134     else
00135       printf("Nothing happens.\n"); 
00136   } 
00137   else if (equals(cmd, "clear")) {
00138     clrscr();
00139   } 
00140   else if (equals(cmd, "?")||equals(cmd, "h")||equals(cmd, "help")) {
00141     print_commands();
00142   } 
00143   else if (equals(cmd, "q")) {
00144     Quit_Mux = 1;
00145     mode = Quit;
00146   } 
00147   else if (equals(cmd, "quit")) {
00148     Quit_Mux = 1;
00149     mode = Quit;
00150   } 
00151   else if (equals(cmd, "set")) {
00152     show_vars();
00153   }
00154   else if (equals(cmd, "c")) {
00155     mode = Cont;
00156   } 
00157   else if (equals(cmd, "d")) {
00158     debug = atoi(arg);
00159     printf("debug set to %d\n", debug);
00160   }
00161   else if (equals(cmd, "b")) {
00162     if (arg[0]!='\0') {
00163       breakpoint = atoi(arg);
00164       printf("New breakpoint at clock=%d\n", breakpoint);
00165     } else {
00166       printf("Breakpoint not changed.\n");
00167     }
00168   } 
00169   else if (equals(cmd, "n")) {
00170     if (stop=atoi(arg))
00171       stop += get_clock();
00172     else
00173       stop += get_clock() + 1;
00174     mode = Next;
00175   }
00176 }

int equals char *  s1,
char *  s2
[static]
 

Definition at line 71 of file interface.c.

00072 {
00073   return (strcmp(s1,s2)==0);
00074 }

void get_input void   )  [static]
 

Definition at line 26 of file interface.c.

References line, and STRLEN.

Referenced by interface().

00027 {
00028   fgets(line, STRLEN, stdin);
00029   if (strlen(line)) {
00030     line[strlen(line)-1]='\0';
00031   }
00032 #ifdef DEBUG
00033   printf("line=\"%s\"\n", line);
00034 #endif  
00035 }

void interface void   ) 
 

Definition at line 179 of file interface.c.

References Cont, do_cmd(), error(), get_clock(), get_input(), mode, Next, parse_input(), Prompt, prompt(), Quit, and Run.

Referenced by main_loop().

00180 {
00181   switch (mode) {
00182     case Prompt: break;
00183     case Run:    break;
00184     case Cont:   
00185                  if (get_clock() == breakpoint)
00186                    mode = Prompt;
00187                  break;
00188     case Next:
00189                  if (get_clock() == stop)
00190                    mode = Prompt;
00191                  break;
00192     case Quit: 
00193                  break;
00194     default:
00195                 error("interface","invalid mode");
00196   }
00197 
00198   while (mode == Prompt) {
00199     prompt();
00200     get_input();
00201     parse_input();
00202     do_cmd();
00203   }
00204 }

void parse_input void   )  [static]
 

Definition at line 42 of file interface.c.

References arg, cmd, lastline, line, and white().

Referenced by interface().

00043 {
00044   int i=0,j=0,k=0;
00045 
00046   if ((line[0]=='\0') && (lastline[0]!='\0'))
00047     strcpy(line, lastline);
00048   else
00049     strcpy(lastline, line);
00050   
00051   cmd[0]='\0';
00052   arg[0]='\0';
00053 
00054   if (strlen(line)) {
00055     while (white(line[i]))
00056       i++;
00057     while ((!white(line[i])) && (line[i]!='\0'))
00058       cmd[j++]=line[i++];
00059     cmd[j]='\0';
00060     while (white(line[i]))
00061       i++;
00062     while (line[i]!='\0')
00063       arg[k++]=line[i++];
00064     arg[k]='\0';
00065 #ifdef DEBUG
00066     printf("cmd=\"%s\", arg=\"%s\"\n", cmd, arg);
00067 #endif
00068   }
00069 }

void print_commands void   )  [static]
 

Definition at line 112 of file interface.c.

Referenced by do_cmd().

00113 {
00114   printf("\nAvailable Commands:\n\n");
00115   printf("b <x>   = break when clock = x\n");
00116   printf("c       = continue until breakpoint\n");
00117   printf("d <l>   = set debug = l\n");
00118   printf("n <i>   = continue for i clock cycles\n");
00119   printf("r       = run continuously\n");
00120   printf("q       = quit\n");
00121   printf("\n");
00122 }

void prompt void   )  [static]
 

Definition at line 20 of file interface.c.

References get_clock(), and lastline.

Referenced by interface().

00021 {
00022   printf("mux_sim:%d [%s]> ", get_clock(), lastline);
00023   fflush(stdout);
00024 }

char* rank int  x  )  [static]
 

Definition at line 85 of file interface.c.

00086 {
00087   if (x >= 250)
00088     return (" Master MUXer");
00089   if (x >= 200)
00090     return (" MUX Engineer");
00091   if (x >= 150)
00092     return ("n ITU LBC Expert");
00093   if (x >= 100)
00094     return ("n ITU Technical Writer");  
00095   return(" Novice Adventurer");  
00096 }

void show_score void   )  [static]
 

Definition at line 99 of file interface.c.

References rank().

Referenced by do_cmd().

00100 {
00101   static int first = 1;
00102   int x;
00103   if (first) {
00104     time_t tloc;
00105     srand((int) time(&tloc));
00106     first=0;
00107   }
00108   x = rand() % 256;
00109   printf("Your score is %d points, which ranks you as a%s\n", x, rank(x));
00110 }

void show_vars  )  [static]
 

Definition at line 78 of file interface.c.

References debug.

Referenced by do_cmd().

00079 {
00080   printf("Variables:\n");
00081   printf("\tdebug = %d\n", debug);
00082 }

int white char  c  )  [static]
 

Definition at line 37 of file interface.c.

00038 {
00039   return ((c == ' ') || (c == '\t'));
00040 }


Variable Documentation

char arg[STRLEN] [static]
 

Definition at line 12 of file interface.c.

Referenced by do_cmd(), and parse_input().

int breakpoint = 0 [static]
 

Definition at line 13 of file interface.c.

Referenced by do_cmd().

char cmd[STRLEN] [static]
 

Definition at line 11 of file interface.c.

Referenced by do_cmd(), and parse_input().

int debug
 

Definition at line 23 of file main.c.

char lastline[STRLEN] [static]
 

Definition at line 10 of file interface.c.

Referenced by parse_input(), and prompt().

char line[STRLEN] [static]
 

Definition at line 9 of file interface.c.

Referenced by get_input(), and parse_input().

enum { ... } mode [static]
 

Referenced by do_cmd(), and interface().

int Quit_Mux
 

Definition at line 24 of file main.c.

Referenced by do_cmd(), and main_loop().

int stop = 0 [static]
 

Definition at line 14 of file interface.c.

Referenced by do_cmd().


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1