line |
true |
false |
branch |
436
|
0 |
1 |
if(!nobanner)
|
468
|
0 |
1 |
if (log != 0)
|
491
|
0 |
0 |
if (log != 0)
|
529
|
0 |
0 |
if(!quiet)
|
542
|
0 |
0 |
if (noprompt)
|
576
|
0 |
0 |
printf("MegaHAL typing is now %s.\n", typing_delay?"on":"off");
|
580
|
0 |
0 |
printf("MegaHAL speech is now %s.\n", speech?"on":"off");
|
641
|
0 |
0 |
if(words->size<=1) return(UNKNOWN);
|
650
|
0 |
0 |
for(i=0; isize-1; ++i)
|
654
|
0 |
0 |
if(words->entry[i].word[words->entry[i].length - 1] == '#') {
|
658
|
0 |
0 |
for(j = 0; j < COMMAND_SIZE; ++j)
|
659
|
0 |
0 |
if(wordcmp(command[j].word, words->entry[i + 1]) == 0) {
|
712
|
0 |
0 |
if(input==NULL) {
|
714
|
0 |
0 |
if(input==NULL) {
|
744
|
0 |
0 |
if((char)(c)=='\n') {
|
745
|
0 |
0 |
if(finish==TRUE) break;
|
760
|
0 |
0 |
if(input==NULL) {
|
772
|
0 |
0 |
while(isspace(input[length-1])) --length;
|
790
|
0 |
0 |
if(errorfp!=stderr) fclose(errorfp);
|
792
|
0 |
0 |
if(filename==NULL) return(TRUE);
|
795
|
0 |
0 |
if(errorfp==NULL) {
|
852
|
0 |
0 |
if(statusfp!=stdout) fclose(statusfp);
|
853
|
0 |
0 |
if(filename==NULL) return(FALSE);
|
855
|
0 |
0 |
if(statusfp==NULL) {
|
928
|
0 |
0 |
if(bit==NULL) (void)status("MegaHAL: %s\n", formatted);
|
929
|
0 |
0 |
while(bit!=NULL) {
|
947
|
71 |
1 |
for(i=0; i<(int)strlen(string); ++i) {
|
948
|
56 |
15 |
if(isalpha(string[i])) {
|
949
|
1 |
55 |
if(start==TRUE) string[i]=(char)toupper((int)string[i]);
|
953
|
68 |
3 |
if((i>2)&&(strchr("!.?", string[i-1])!=NULL)&&(isspace(string[i])))
|
|
0 |
68 |
if((i>2)&&(strchr("!.?", string[i-1])!=NULL)&&(isspace(string[i])))
|
|
0 |
0 |
if((i>2)&&(strchr("!.?", string[i-1])!=NULL)&&(isspace(string[i])))
|
969
|
20117 |
350 |
for(i=0; i<(int)strlen(string); ++i) string[i]=(char)toupper((int)string[i]);
|
988
|
0 |
0 |
if(bit==NULL) (void)status("User: %s\n", formatted);
|
989
|
0 |
0 |
while(bit!=NULL) {
|
1008
|
0 |
0 |
if(formatted==NULL) {
|
1010
|
0 |
0 |
if(formatted==NULL) {
|
1017
|
0 |
0 |
if(formatted==NULL) {
|
1024
|
0 |
0 |
for(i=0; i<(int)strlen(output); ++i) {
|
1025
|
0 |
0 |
if((l==0)&&(isspace(output[i]))) continue;
|
|
0 |
0 |
if((l==0)&&(isspace(output[i]))) continue;
|
1029
|
0 |
0 |
if(!nowrap)
|
1030
|
0 |
0 |
if(l>=width)
|
1031
|
0 |
0 |
for(c=j-1; c>0; --c)
|
1032
|
0 |
0 |
if(formatted[c]==' ') {
|
1038
|
0 |
0 |
if((j>0)&&(formatted[j-1]!='\n')) {
|
|
0 |
0 |
if((j>0)&&(formatted[j-1]!='\n')) {
|
1067
|
5959 |
1323 |
if(found==TRUE) goto succeed;
|
1077
|
2 |
1321 |
if(dictionary->index==NULL) {
|
1084
|
0 |
1323 |
if(dictionary->index==NULL) {
|
1092
|
2 |
1321 |
if(dictionary->entry==NULL) {
|
1098
|
0 |
1323 |
if(dictionary->entry==NULL) {
|
1109
|
0 |
1323 |
if(dictionary->entry[dictionary->size-1].word==NULL) {
|
1113
|
8061 |
1323 |
for(i=0; i
|
1119
|
444657 |
1323 |
for(i=(dictionary->size-1); i>position; --i)
|
1154
|
4526 |
307635 |
if(dictionary->size==0) {
|
1179
|
155724 |
1577663 |
if(compar==0) {
|
1182
|
446781 |
1130882 |
} else if(compar>0) {
|
1183
|
51889 |
394892 |
if(max==middle) {
|
1189
|
100022 |
1030860 |
if(min==middle) {
|
1222
|
149765 |
155114 |
if(found==TRUE) return(dictionary->index[position]);
|
1240
|
1227514 |
563897 |
bound=MIN(word1.length,word2.length);
|
1242
|
2490362 |
190581 |
for(i=0; i
|
1243
|
1600830 |
889532 |
if(toupper(word1.word[i])!=toupper(word2.word[i]))
|
1246
|
30239 |
160342 |
if(word1.length
|
1247
|
3973 |
156369 |
if(word1.length>word2.length) return(1);
|
1261
|
3 |
2714 |
if(dictionary==NULL) return;
|
1262
|
2710 |
4 |
if(dictionary->entry!=NULL) {
|
1266
|
0 |
2714 |
if(dictionary->index!=NULL) {
|
1277
|
1 |
0 |
if(model==NULL) return;
|
1278
|
0 |
0 |
if(model->forward!=NULL) {
|
1281
|
0 |
0 |
if(model->backward!=NULL) {
|
1284
|
0 |
0 |
if(model->context!=NULL) {
|
1287
|
0 |
0 |
if(model->dictionary!=NULL) {
|
1301
|
0 |
0 |
if(tree==NULL) return;
|
1303
|
0 |
0 |
if(tree->tree!=NULL) {
|
1304
|
0 |
0 |
if(level==0) progress("Freeing tree", 0, 1);
|
1305
|
0 |
0 |
for(i=0; ibranch; ++i) {
|
1309
|
0 |
0 |
if(level==0) progress(NULL, i, tree->branch);
|
1311
|
0 |
0 |
if(level==0) progress(NULL, 1, 1);
|
1345
|
0 |
10 |
if(dictionary==NULL) {
|
1370
|
1316 |
1 |
for(i=0; isize; ++i) {
|
1391
|
0 |
0 |
for(i=0; i
|
1410
|
8038 |
1316 |
for(i=0; i
|
1428
|
0 |
0 |
if(word.word==NULL) {
|
1432
|
0 |
0 |
for(i=0; i
|
1454
|
0 |
49892 |
if(node==NULL) {
|
1471
|
0 |
0 |
if(node!=NULL) free(node);
|
1487
|
0 |
1 |
if(model==NULL) {
|
1496
|
0 |
1 |
if(model->context==NULL) {
|
1525
|
91476 |
15246 |
for(i=(model->order+1); i>0; --i)
|
1526
|
80976 |
10500 |
if(model->context[i-1]!=NULL)
|
1543
|
922020 |
153670 |
for(i=(model->order+1); i>0; --i)
|
1544
|
782880 |
139140 |
if(model->context[i-1]!=NULL)
|
1569
|
80976 |
0 |
if((node->count<65535)) {
|
1595
|
879470 |
0 |
if(found_symbol==TRUE) found=node->tree[i];
|
1621
|
31086 |
49890 |
if(found_symbol==TRUE) {
|
1648
|
36816 |
13074 |
if(tree->tree==NULL) {
|
1654
|
0 |
49890 |
if(tree->tree==NULL) {
|
1663
|
40767 |
49890 |
for(i=tree->branch; i>position; --i)
|
1695
|
36816 |
923630 |
if(node->branch==0) {
|
1708
|
910556 |
2858112 |
if(compar==0) {
|
1711
|
1204832 |
1653280 |
} else if(compar>0) {
|
1712
|
9466 |
1195366 |
if(max==middle) {
|
1718
|
3608 |
1649672 |
if(min==middle) {
|
1746
|
60882 |
10147 |
for(i=0; i<=model->order; ++i) model->context[i]=NULL;
|
1764
|
0 |
350 |
if(words->size<=(model->order)) return;
|
1772
|
7273 |
350 |
for(i=0; isize; ++i) {
|
1791
|
7273 |
350 |
for(i=words->size-1; i>=0; --i) {
|
1821
|
0 |
1 |
if(filename==NULL) return;
|
1824
|
0 |
1 |
if(file==NULL) {
|
1836
|
398 |
0 |
while(!feof(file)) {
|
1838
|
1 |
397 |
if(fgets(buffer, 1024, file)==NULL) break;
|
1839
|
48 |
349 |
if(buffer[0]=='#') continue;
|
1870
|
0 |
1 |
if(file==NULL) {
|
1875
|
1316 |
1 |
for(i=0; isize; ++i) {
|
1876
|
8038 |
1316 |
for(j=0; jentry[i].length; ++j)
|
1896
|
1 |
0 |
if(filename==NULL) filename=(char *)malloc(sizeof(char)*1);
|
1903
|
0 |
1 |
if(filename==NULL) error("save_model","Unable to allocate filename");
|
1906
|
0 |
1 |
if(filename==NULL) return;
|
1910
|
0 |
1 |
if(file==NULL) {
|
1941
|
2 |
49890 |
if(level==0) progress("Saving tree", 0, 1);
|
1942
|
49890 |
49892 |
for(i=0; ibranch; ++i) {
|
1946
|
2630 |
47260 |
if(level==0) progress(NULL, i, node->branch);
|
1948
|
2 |
49890 |
if(level==0) progress(NULL, 1, 1);
|
1968
|
0 |
0 |
if(node->branch==0) return;
|
1971
|
0 |
0 |
if(node->tree==NULL) {
|
1976
|
0 |
0 |
if(level==0) progress("Loading tree", 0, 1);
|
1977
|
0 |
0 |
for(i=0; ibranch; ++i) {
|
1982
|
0 |
0 |
if(level==0) progress(NULL, i, node->branch);
|
1984
|
0 |
0 |
if(level==0) progress(NULL, 1, 1);
|
2000
|
0 |
1 |
if(filename==NULL) return(FALSE);
|
2004
|
1 |
0 |
if(file==NULL) {
|
2011
|
0 |
0 |
if(strncmp(cookie, COOKIE, strlen(COOKIE))!=0) {
|
2047
|
0 |
350 |
if(strlen(input)==0) return;
|
2059
|
7273 |
20117 |
if(boundary(input, offset)) {
|
2063
|
350 |
6923 |
if(words->entry==NULL)
|
2068
|
0 |
7273 |
if(words->entry==NULL) {
|
2077
|
350 |
6923 |
if(offset==(int)strlen(input)) break;
|
2089
|
0 |
350 |
if(isalnum(words->entry[words->size-1].word[0])) {
|
2090
|
0 |
0 |
if(words->entry==NULL)
|
2094
|
0 |
0 |
if(words->entry==NULL) {
|
2103
|
349 |
1 |
else if(strchr("!.?", words->entry[words->size-1].word[words->entry[words->size-1].length-1])==NULL) {
|
2120
|
7273 |
20117 |
if(position==0)
|
2123
|
350 |
19767 |
if(position==(int)strlen(string))
|
2126
|
99 |
19668 |
if(
|
2127
|
99 |
0 |
(string[position]=='\'')&&
|
2128
|
99 |
0 |
(isalpha(string[position-1])!=0)&&
|
2133
|
12424 |
7244 |
if(
|
2134
|
99 |
12325 |
(position>1)&&
|
2135
|
99 |
0 |
(string[position-1]=='\'')&&
|
2136
|
99 |
0 |
(isalpha(string[position-2])!=0)&&
|
2141
|
15323 |
4246 |
if(
|
2142
|
3283 |
12040 |
(isalpha(string[position])!=0)&&
|
2147
|
4246 |
12040 |
if(
|
2148
|
3632 |
614 |
(isalpha(string[position])==0)&&
|
2153
|
8 |
12646 |
if(isdigit(string[position])!=isdigit(string[position-1]))
|
2170
|
0 |
0 |
for(i=0; isize; ++i) free(words->entry[i].word);
|
2172
|
0 |
0 |
if(grt->size>0) (void)add_word(words, grt->entry[rnd(grt->size)]);
|
2204
|
1 |
0 |
if(output_none==NULL) {
|
2206
|
1 |
0 |
if(output_none!=NULL)
|
2210
|
1 |
0 |
if(dummy == NULL) dummy = new_dictionary();
|
2212
|
1 |
0 |
if(dissimilar(words, replywords) == TRUE) output = make_output(replywords);
|
2226
|
6 |
2355 |
if((surprise>max_surprise)&&(dissimilar(words, replywords)==TRUE)) {
|
|
5 |
1 |
if((surprise>max_surprise)&&(dissimilar(words, replywords)==TRUE)) {
|
2231
|
2360 |
1 |
} while((time(NULL)-basetime)
|
2252
|
6 |
1 |
if(words1->size!=words2->size) return(TRUE);
|
2253
|
15 |
1 |
for(i=0; isize; ++i)
|
2254
|
0 |
15 |
if(wordcmp(words1->entry[i], words2->entry[i])!=0) return(TRUE);
|
2274
|
1 |
0 |
if(keys==NULL) keys=new_dictionary();
|
2275
|
0 |
1 |
for(i=0; isize; ++i) free(keys->entry[i].word);
|
2278
|
15 |
1 |
for(i=0; isize; ++i) {
|
2286
|
0 |
15 |
for(j=0; jsize; ++j)
|
2287
|
0 |
0 |
if(wordcmp(swp->from[j], words->entry[i])==0) {
|
2291
|
15 |
0 |
if(c==0) add_key(model, keys, words->entry[i]);
|
2294
|
1 |
0 |
if(keys->size>0) for(i=0; isize; ++i) {
|
|
15 |
1 |
if(keys->size>0) for(i=0; isize; ++i) {
|
2297
|
0 |
15 |
for(j=0; jsize; ++j)
|
2298
|
0 |
0 |
if(wordcmp(swp->from[j], words->entry[i])==0) {
|
2302
|
15 |
0 |
if(c==0) add_aux(model, keys, words->entry[i]);
|
2320
|
0 |
15 |
if(symbol==0) return;
|
2321
|
8 |
7 |
if(isalnum(word.word[0])==0) return;
|
2323
|
0 |
7 |
if(symbol!=0) return;
|
2325
|
0 |
7 |
if(symbol!=0) return;
|
2342
|
0 |
15 |
if(symbol==0) return;
|
2343
|
8 |
7 |
if(isalnum(word.word[0])==0) return;
|
2345
|
7 |
0 |
if(symbol==0) return;
|
2365
|
1 |
2361 |
if(replies==NULL) replies=new_dictionary();
|
2382
|
2362 |
24780 |
if(start==TRUE) symbol=seed(model, keys);
|
2384
|
27142 |
0 |
if((symbol==0)||(symbol==1)) break;
|
|
24780 |
2362 |
if((symbol==0)||(symbol==1)) break;
|
2390
|
2362 |
22418 |
if(replies->entry==NULL)
|
2394
|
0 |
24780 |
if(replies->entry==NULL) {
|
2422
|
2362 |
0 |
if(replies->size>0) for(i=MIN(replies->size-1, model->order); i>=0; --i) {
|
|
12216 |
2362 |
if(replies->size>0) for(i=MIN(replies->size-1, model->order); i>=0; --i) {
|
2435
|
24756 |
0 |
if((symbol==0)||(symbol==1)) break;
|
|
22394 |
2362 |
if((symbol==0)||(symbol==1)) break;
|
2440
|
0 |
22394 |
if(replies->entry==NULL)
|
2444
|
0 |
22394 |
if(replies->entry==NULL) {
|
2452
|
327401 |
22394 |
for(i=replies->size; i>0; --i) {
|
2489
|
0 |
2361 |
if(words->size<=0) return((float)0.0);
|
2492
|
47140 |
2361 |
for(i=0; isize; ++i) {
|
2495
|
10517 |
36623 |
if(find_word(keys, words->entry[i])!=0) {
|
2499
|
50001 |
2584 |
for(j=0; jorder; ++j) if(model->context[j]!=NULL) {
|
|
52585 |
10517 |
for(j=0; jorder; ++j) if(model->context[j]!=NULL) {
|
2508
|
10517 |
0 |
if(count>0.0) entropy-=(float)log(probability/(float)count);
|
2516
|
47140 |
2361 |
for(i=words->size-1; i>=0; --i) {
|
2519
|
10517 |
36623 |
if(find_word(keys, words->entry[i])!=0) {
|
2523
|
46589 |
5996 |
for(j=0; jorder; ++j) if(model->context[j]!=NULL) {
|
|
52585 |
10517 |
for(j=0; jorder; ++j) if(model->context[j]!=NULL) {
|
2532
|
10517 |
0 |
if(count>0.0) entropy-=(float)log(probability/(float)count);
|
2538
|
1499 |
862 |
if(num>=8) entropy/=(float)sqrt(num-1);
|
2539
|
0 |
2361 |
if(num>=16) entropy/=(float)num;
|
2559
|
1 |
5 |
if(output_none==NULL) output_none=malloc(40);
|
2561
|
1 |
5 |
if(output==NULL) {
|
2563
|
0 |
1 |
if(output==NULL) {
|
2569
|
0 |
6 |
if(words->size==0) {
|
2570
|
0 |
0 |
if(output_none!=NULL)
|
2576
|
150 |
6 |
for(i=0; isize; ++i) length+=words->entry[i].length;
|
2579
|
0 |
6 |
if(output==NULL) {
|
2581
|
0 |
0 |
if(output_none!=NULL)
|
2587
|
150 |
6 |
for(i=0; isize; ++i)
|
2588
|
380 |
150 |
for(j=0; jentry[i].length; ++j)
|
2617
|
297216 |
49536 |
for(i=0; i<=model->order; ++i)
|
2618
|
272225 |
24991 |
if(model->context[i]!=NULL)
|
2621
|
0 |
49536 |
if(node->branch==0) return(0);
|
2628
|
87594 |
41634 |
while(count>=0) {
|
2635
|
8532 |
79062 |
if(
|
2636
|
2102 |
6430 |
(find_word(keys, model->dictionary->entry[symbol])!=0)&&
|
2637
|
2102 |
0 |
((used_key==TRUE)||
|
2638
|
7902 |
630 |
(find_word(aux, model->dictionary->entry[symbol])==0))&&
|
2645
|
40163 |
39529 |
i=(i>=(node->branch-1))?0:i+1;
|
2662
|
58009 |
7902 |
for(i=0; isize; ++i)
|
2663
|
630 |
57379 |
if(wordcmp(dictionary->entry[i], word)==0)
|
2685
|
0 |
2362 |
if(model->context[0]->branch==0) symbol=0;
|
2688
|
2361 |
1 |
if(keys->size>0) {
|
2692
|
2361 |
0 |
if(
|
2693
|
2361 |
0 |
(find_word(model->dictionary, keys->entry[i])!=0)&&
|
2700
|
0 |
0 |
if(i==keys->size) i=0;
|
2701
|
0 |
0 |
if(i==stop) return(symbol);
|
2720
|
0 |
1 |
if(list==NULL) {
|
2742
|
0 |
0 |
if(list->from==NULL) {
|
2744
|
0 |
0 |
if(list->from==NULL) {
|
2750
|
0 |
0 |
if(list->to==NULL) {
|
2752
|
0 |
0 |
if(list->to==NULL) {
|
2759
|
0 |
0 |
if(list->from==NULL) {
|
2765
|
0 |
0 |
if(list->to==NULL) {
|
2793
|
0 |
1 |
if(filename==NULL) return(list);
|
2796
|
1 |
0 |
if(file==NULL) return(list);
|
2798
|
0 |
0 |
while(!feof(file)) {
|
2800
|
0 |
0 |
if(fgets(buffer, 1024, file)==NULL) break;
|
2801
|
0 |
0 |
if(buffer[0]=='#') continue;
|
2818
|
1 |
0 |
if(swap==NULL) return;
|
2820
|
0 |
0 |
for(i=0; isize; ++i) {
|
2846
|
0 |
3 |
if(filename==NULL) return(list);
|
2849
|
3 |
0 |
if(file==NULL) return(list);
|
2851
|
0 |
0 |
while(!feof(file)) {
|
2853
|
0 |
0 |
if(fgets(buffer, 1024, file)==NULL) break;
|
2854
|
0 |
0 |
if(buffer[0]=='#') continue;
|
2857
|
0 |
0 |
if((string!=NULL)&&(strlen(string)>0)) {
|
|
0 |
0 |
if((string!=NULL)&&(strlen(string)>0)) {
|
2882
|
0 |
0 |
if(typing_delay==FALSE) {
|
2890
|
0 |
0 |
for(i=0; i<(int)strlen(string)-1; ++i) typein(string[i]);
|
2914
|
0 |
0 |
if((!isalnum(c))&&((rnd(100))
|
|
0 |
0 |
if((!isalnum(c))&&((rnd(100))
|
2927
|
0 |
1 |
if(sig!=0) warn("ignore", "MegaHAL received signal %d", sig);
|
2962
|
1 |
103794 |
if(flag==FALSE) {
|
3155
|
0 |
0 |
if(speech==FALSE) return;
|
3187
|
6 |
4298 |
if((done*100/total==100)&&(first==FALSE)) return(TRUE);
|
|
2 |
4 |
if((done*100/total==100)&&(first==FALSE)) return(TRUE);
|
3193
|
3902 |
400 |
if(done*100/total==last) {
|
3194
|
7 |
3895 |
if((done==0)&&(first==FALSE)) {
|
|
4 |
3 |
if((done==0)&&(first==FALSE)) {
|
3212
|
4 |
396 |
if(last==100) {
|
3227
|
0 |
0 |
for(j=0; j
|
3239
|
1 |
0 |
if(filename==NULL) filename=(char *)malloc(sizeof(char)*1);
|
3246
|
0 |
1 |
if(filename==NULL) error("load_personality","Unable to allocate filename");
|
3252
|
0 |
1 |
if(strcmp(directory, DEFAULT)!=0) {
|
3255
|
0 |
0 |
if(file==NULL) {
|
3258
|
0 |
0 |
if(file==NULL) {
|
3292
|
1 |
0 |
if(load_model(filename, *model)==FALSE) {
|
3316
|
1 |
0 |
if(directory == NULL) {
|
3318
|
0 |
1 |
if(directory == NULL) {
|
3325
|
1 |
0 |
if(last == NULL) {
|
3329
|
0 |
1 |
if((command == NULL)||((position+2)>=command->size)) {
|
|
0 |
0 |
if((command == NULL)||((position+2)>=command->size)) {
|
3334
|
0 |
0 |
if(directory == NULL)
|
3350
|
3 |
0 |
if(words == NULL) return;
|
3352
|
0 |
0 |
if(words->entry != NULL)
|
3353
|
0 |
0 |
for(i=0; isize; ++i) free_word(words->entry[i]);
|