/usr/lib/Wt/examples/hangman/Dictionary.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
*
* See the LICENSE file for terms of use.
*/
#include <Wt/WApplication>
#include <Wt/WStringUtil>
#include "Dictionary.h"
#include <fstream>
#include <iostream>
#include <time.h>
#include <stdlib.h>
std::wstring RandomWord(Dictionary dictionary)
{
std::ifstream dict;
if (dictionary == DICT_NL) {
dict.open((Wt::WApplication::appRoot() + "dict-nl.txt").c_str());
} else { // english is default
dict.open((Wt::WApplication::appRoot() + "dict.txt").c_str());
}
std::string retval;
int numwords = 0;
while(dict) {
getline(dict, retval);
numwords++;
}
dict.clear();
dict.seekg(0);
srand(time(0));
int selection = rand() % numwords; // not entirely uniform, but who cares?
while(selection--) {
getline(dict, retval);
}
getline(dict, retval);
for(unsigned int i = 0; i < retval.size(); ++i)
if(retval[i] < 'A' || retval[i] > 'Z')
std::cout << "word " << retval
<< " contains illegal data at pos " << i << std::endl;
return Wt::widen(retval);
}
|