-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
140 lines (121 loc) · 2.66 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#if 0
#include <unistd.h>
#include <getopt.h>
#endif
#if !defined(AMIGA) && !defined(__mac_os)
#include <malloc.h>
#endif
#include <string.h>
#include <signal.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#if defined(__mac_os)
#include <types.h>
#include <Speech.h>
#else
#include <sys/types.h>
#endif
#include "megahal.h"
//#if defined(DEBUG)
//#include "debug.h"
//#endif
/* extern errorfp;
extern statusfp;
*/
/* extern noprompt;
extern nowrap;
extern nobanner;
extern typing_delay;
extern speech;
extern quiet;
*/
#if 0
static struct option long_options[] = {
{"no-prompt", 0, NULL, 'p'},
{"no-wrap", 0, NULL, 'w'},
{"no-banner", 0, NULL, 'b'},
{"help", 0, NULL, 'h'},
{0, 0, 0, 0}
};
#endif
void usage()
{
puts("usage: megahal [-[pqrgwbh]]\n" \
"\t-h : show usage\n" \
"\t-p : inhibit prompts\n" \
"\t-q : quiet mode (no replies) enabled at start\n" \
"\t-r : inhibit progress display\n" \
"\t-g : inhibit initial greeting\n" \
"\t-b : inhibit banner display at startup\n");
}
/*===========================================================================*/
/*
* Function: Main
*
* Purpose: Initialise everything, and then do an infinite loop. In
* the loop, we read the user's input and reply to it, and
* do some housekeeping task such as responding to special
* commands.
*/
int megahal (int argc, char **argv)
{
char *input=NULL;
char *output=NULL;
// int c, fd;
int option_index = 0;
#if 0
while(1)
{
if((c = getopt_long(argc, argv, "hpwb", long_options,
&option_index)) == -1)
break;
switch(c) {
case 'p':
megahal_setnoprompt();
break;
case 'w':
megahal_setnowrap();
break;
case 'b':
megahal_setnobanner();
break;
case 'h':
usage();
return 0;
}
}
#endif
/*
* Do some initialisation
*/
megahal::initialize();
/*
* Create a dictionary which will be used to hold the segmented
* version of the user's input.
*/
/*
* Load the default MegaHAL personality.
*/
output = megahal::initial_greeting();
megahal::output(output);
/*
* Read input, formulate a reply and display it as output
*/
while(1) {
input = megahal::input("> ");
/*
* If the input was a command, then execute it
*/
if (megahal::command(input) != 0)
continue;
output = megahal::do_reply(input, 1);
megahal::output(output);
}
megahal::cleanup();
exit(0);
}