map<string,int> buildGrammer(const char * options, int words, int sntc){ ofstream grammer,kws; grammer.open (grammer_path); kws.open(keyword_path); map<string,int> elems; stringstream ss(options); string item; int n = 0; grammer << "#JSGF V1.0;\ngrammar options;\npublic <word> = (<option> | <garbage>+)+;\npublic <option> = \n"; while (getline(ss, item, '\n')) { elems[item]=n++; kws << item; kws << " /"; if (item.length() > 10){ kws << "1e-"; kws << sntc; kws <<"/"; } else { kws << "1e-"; kws << words; kws <<"/"; } kws << "\n"; grammer << item; grammer << "|"; } long pos = grammer.tellp(); grammer.seekp (pos-1); grammer << ";\n<garbage> = GARBAGE;"; grammer.close(); kws.clear(); return elems; }