void expand(char expr[], char expanded[]) { char start, end; int current_expr, current_expand; char c, before, after; current_expr = current_expand = 0; while (expr[current_expr] != '\0') { before = current_expr > 0 ? expr[current_expr -1] : ' '; after = expr[current_expr + 1]; if (expr[current_expr] == EXPANDER) { /* Char before and after the expander must be alpha or digit */ if (current_expr > 0 && aredigits(before, after)) { for (c = before + 1; c < after; ++c) { expanded[current_expand++] = c; } } else { expanded[current_expand++] = EXPANDER; } } else { expanded[current_expand++] = expr[current_expr]; } ++current_expr; } expanded[current_expand] = '\0'; }
bool Satori::Save(bool isOnUnload) { GetSender().next_event(); // メンバ変数を里々変数化 for (std::map<int, string>::iterator it=reserved_talk.begin(); it!=reserved_talk.end() ; ++it) variables[string("次から")+itos(it->first)+"回目のトーク"] = it->second; // 起動時間累計を設定 variables["ゴースト起動時間累計秒"] = uitos(posix_get_current_sec() - sec_count_at_load + sec_count_total,"%lu"); // (互換用) variables["ゴースト起動時間累計ミリ秒"] = uitos((posix_get_current_sec() - sec_count_at_load + sec_count_total)*1000,"%lu"); variables["ゴースト起動時間累計(ms)"] = uitos((posix_get_current_sec() - sec_count_at_load + sec_count_total)*1000,"%lu"); if ( isOnUnload ) { secure_flag = true; (void)GetSentence("OnSatoriUnload"); } string theFullPath = mBaseFolder + "satori_savedata.tmp"; std::ofstream out(theFullPath.c_str()); bool temp = GetSender().is_validated(); GetSender().validate(); GetSender().sender() << "saving " << theFullPath << "... " ; GetSender().validate(temp); if ( !out.is_open() ) { GetSender().sender() << "failed." << std::endl; return false; } string line = "*セーブデータ"; string data; out << ENCODE(line) << std::endl; for (strmap::const_iterator it=variables.begin() ; it!=variables.end() ; ++it) { string str = zen2han(it->first); if ( str[0]=='S' && aredigits(str.c_str()+1) ) { continue; } if ( str == "今回は喋らない" || str == "今回は会話時サーフェス戻し" || str == "今回は会話時サーフィス戻し" || str == "今回は自動アンカー" ) { continue; } data = it->second; replace(data,"φ","φφ"); replace(data,"(","φ("); replace(data,")","φ)"); m_escaper.unescape_for_dic(data); string line = string("$")+it->first+"\t"+data; // 変数を保存 out << ENCODE(line) << std::endl; } for (std::map<string, std::vector<Word> >::const_iterator i=mAppendedWords.begin() ; i!=mAppendedWords.end() ; ++i ) { if ( ! i->second.empty() ) { out << std::endl << ENCODE( string("@") + i->first ) << std::endl; for (std::vector<Word>::const_iterator j=i->second.begin() ; j!=i->second.end() ; ++j ) { out << ENCODE( *j ) << std::endl; } } } out.flush(); out.close(); GetSender().sender() << "ok." << std::endl; //バックアップ string realFullPath = mBaseFolder + "satori_savedata." + (fEncodeSavedata?"sat":"txt"); string realFullPathBackup = mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"sat":"txt"); #ifdef POSIX unlink(realFullPathBackup.c_str()); rename(realFullPath.c_str(),realFullPathBackup.c_str()); rename(theFullPath.c_str(),realFullPath.c_str()); #else ::DeleteFile(realFullPathBackup.c_str()); ::MoveFile(realFullPath.c_str(),realFullPathBackup.c_str()); ::MoveFile(theFullPath.c_str(),realFullPath.c_str()); #endif //いらないほうを消す string delFullPath = mBaseFolder + "satori_savedata." + (fEncodeSavedata?"txt":"sat"); string delFullPathBackup = mBaseFolder + "satori_savebackup." + (fEncodeSavedata?"txt":"sat"); #ifdef POSIX unlink(delFullPath.c_str()); unlink(delFullPathBackup.c_str()); #else ::DeleteFile(delFullPath.c_str()); ::DeleteFile(delFullPathBackup.c_str()); #endif return true; }
bool Satori::Translate(string& ioScript) { if ( ioScript.empty() ) return false; const bool is_OnTranslate = (mRequestID=="OnTranslate"); // さくらスクリプトとそれ以外を分割して処理を加える vector<string> vec; string acum; bool content=false; // 文に中身があるのか bool is_first_question = true; // 選択分岐記録の消去処理用。 int last_speaker=0; const char* p = ioScript.c_str(); while (*p) { string c=get_a_chr(p); // 全角半角問わず一文字取得し、pを一文字すすめる if ( c=="\\" || c=="%" ) { if (*p=='\\'||*p=='%') { // エスケープされた\, % acum += c + *p++; continue; } const char* start=p; string cmd="",opt=""; while (!_ismbblead(*p) && (isalpha(*p)||isdigit(*p)||*p=='!'||*p=='*'||*p=='&'||*p=='?'||*p=='_')) ++p; cmd.assign(start, p-start); if (*p=='[') { const char* opt_start = ++p; while (*p!=']') { if (p[0]=='\\' && p[1]==']') // エスケープされた] ++p; p += _ismbblead(*p) ? 2 : 1; } opt.assign(opt_start, p++ -opt_start); } // 選択分岐ラベルに対する特殊処理 if ( !is_OnTranslate && cmd=="q" && opt!="" && count(opt, ",")>0 && mRequestID!="OnHeadlinesense.OnFind") { // 選択分岐があるスクリプトであれば、その初回で選択分岐記録をクリア if ( is_first_question ) { question_record.clear(); is_first_question = false; } // 選択分岐を記録 { strvec vec; split(opt, ",", vec); if ( vec.size()==1 ) // countとsplitの罠。 vec.push_back(""); // string label=vec[0], id=vec[1]; if ( false == compare_head(id, "On") ) { // Onで始まるものはOnChoiceSelectを経由されないため、対象外とする int count = question_record.size()+1; question_record[id] = pair<int,string>(count, label); // ラベルIDに書き戻し opt = label+","+id+byte1_dlmt+label+byte1_dlmt+itos(count); for (int i=2;i<vec.size();++i) opt += string(",") + vec[i]; } } } else if ( cmd=="0" || cmd=="h" ) { last_speaker=0; } else if ( cmd=="1" || cmd=="u" ) { last_speaker=1; } else if ( cmd=="p" && aredigits(opt) ) { last_speaker=stoi(opt); if ( mIsMateria || last_speaker<=1 ) { cmd = (opt=="0") ? "0" : "1"; opt = ""; } } else if ( cmd=="s" && !opt.empty() ) { last_talk_exiting_surface[last_speaker]=stoi(opt); } else if ( cmd.size()==2 && cmd[0]=='s' && isdigit(cmd[1]) ) { last_talk_exiting_surface[last_speaker]=cmd[1]-'0'; } if ( !acum.empty() ) vec.push_back(acum); if ( opt=="" ) vec.push_back(c + cmd); else vec.push_back(c + cmd + "[" + opt + "]"); acum=""; static set<string> nc_cmd; // 有効と数えないさくらスクリプト群 static bool initialized=false; if (!initialized) { initialized=true; nc_cmd.insert("0"); nc_cmd.insert("1"); nc_cmd.insert("h"); nc_cmd.insert("u"); nc_cmd.insert("p"); nc_cmd.insert("n"); nc_cmd.insert("w"); nc_cmd.insert("_w"); nc_cmd.insert("e"); } if ( nc_cmd.find(cmd)==nc_cmd.end() ) content = true; } else { content = true; acum += c; } } if ( !acum.empty() ) vec.push_back(acum); if (!content) return false; // 中身の無いスクリプト(実行してもしなくても一緒)と判断。 ioScript=""; for (vector<string>::iterator i=vec.begin() ; i!=vec.end() ; ++i) { if ( i->at(0)!='\\' && i->at(0)!='%' ) { // さくらスクリプト以外の文への処理 // アンカー挿入 if ( !is_OnTranslate ) for ( set<string>::iterator j=anchors.begin() ; j!=anchors.end() ; ++j ) replace(*i, *j, string("\\_a[")+*j+"]"+*j+"\\_a"); } ioScript += *i; } // 事後置き換え辞書を適用 if ( !is_OnTranslate ) for ( strmap::iterator di=replace_after_dic.begin() ; di!=replace_after_dic.end() ; ++di ) replace(ioScript, di->first, di->second); diet_script(ioScript); // ラストダイエット // エスケープしてあった文字を戻す m_escaper.unescape(ioScript); return true; }
bool Satori::system_variable_operation(string key, string value, string* result) { // mapにしようよ。 if ( key == "喋り間隔" ) { talk_interval = zen2int(value); if ( talk_interval<3 ) talk_interval=0; // 3未満は喋らない // 喋りカウント初期化 int dist = static_cast<int>(talk_interval*(talk_interval_random/100.0)); talk_interval_count = ( dist==0 ) ? talk_interval : (talk_interval-dist)+(random(dist*2)); return true; } if ( key == "喋り間隔誤差" ) { talk_interval_random = zen2int(value); if ( talk_interval_random>100 ) talk_interval_random=100; if ( talk_interval_random<0 ) talk_interval_random=0; // 喋りカウント初期化 int dist = int(talk_interval*(talk_interval_random/100.0)); talk_interval_count = ( dist==0 ) ? talk_interval : (talk_interval-dist)+(random(dist*2)); return true; } if ( key =="見切れてても喋る" ) { is_call_ontalk_at_mikire= (value=="有効"); return true; } if ( key == "今回は喋らない" ) { return_empty=(value=="有効"); return true; } if ( key == "スクリプトの一番頭" ) { header_script = value; return true; } if ( key == "呼び出し回数制限" ) { m_nest_limit = zen2int(value); if ( m_nest_limit < 0 ) { m_nest_limit = 0; } return true; } if ( key == "ジャンプ回数制限" ) { m_jump_limit = zen2int(value); if ( m_jump_limit < 0 ) { m_jump_limit = 0; } return true; } if ( key == "スコープ切り換え時" ) { append_at_scope_change = zen2han(value); return true; } if ( key == "さくらスクリプトによるスコープ切り換え時" ) { append_at_scope_change_with_sakura_script = zen2han(value); return true; } if ( key == "トーク開始時" ) { append_at_talk_start = zen2han(value); return true; } if ( key == "トーク終了時" ) { append_at_talk_end = zen2han(value); return true; } if ( key == "選択肢開始時" ) { append_at_choice_start = zen2han(value); return true; } if ( key == "選択肢終了時" ) { append_at_choice_end = zen2han(value); return true; } if ( key == "会話時サーフェス戻し" || key == "会話時サーフィス戻し" ) { if ( value == "有効" ) { surface_restore_at_talk = SR_NORMAL; } else if ( value == "強制" ) { surface_restore_at_talk = SR_FORCE; } else { surface_restore_at_talk = SR_NONE; } return true; } if ( key == "今回は会話時サーフェス戻し" || key == "今回は会話時サーフィス戻し" ) { if ( value == "有効" ) { surface_restore_at_talk_onetime = SR_NORMAL; } else if ( value == "強制" ) { surface_restore_at_talk_onetime = SR_FORCE; } else { surface_restore_at_talk_onetime = SR_NONE; } return true; } if ( key == "自動アンカー" ) { if ( value == "有効" ) { auto_anchor_enable = true; auto_anchor_enable_onetime = auto_anchor_enable; } else { auto_anchor_enable = false; auto_anchor_enable_onetime = auto_anchor_enable; } return true; } if ( key == "今回は自動アンカー" ) { if ( value == "有効" ) { auto_anchor_enable_onetime = true; } else { auto_anchor_enable_onetime = false; } return true; } if ( compare_head(key, "サーフェス加算値") && aredigits(key.c_str() + const_strlen("サーフェス加算値")) ) { int n = zen2int(key.c_str() + const_strlen("サーフェス加算値")); surface_add_value[n]= zen2int(value); variables[string()+"デフォルトサーフェス"+itos(n)] = value; next_default_surface[n] = zen2int(value); if ( !is_speaked_anybody() ) default_surface[n]=next_default_surface[n]; return true; } if ( compare_head(key, "デフォルトサーフェス") && aredigits(key.c_str() + const_strlen("デフォルトサーフェス")) ) { int n = zen2int(key.c_str() + const_strlen("デフォルトサーフェス")); next_default_surface[n]= zen2int(value); if ( !is_speaked_anybody() ) default_surface[n]=next_default_surface[n]; return true; } if ( compare_head(key, "BalloonOffset") && aredigits(key.c_str() + const_strlen("BalloonOffset")) ) { int n = stoi(key.c_str() + const_strlen("BalloonOffset")); BalloonOffset[n] = value; validBalloonOffset[n] = true; return true; } if ( key == "トーク中のなでられ反応") { insert_nade_talk_at_other_talk= (value=="有効"); return true; } if ( key == "なでられ持続秒数") { nade_valid_time_initializer = zen2int(value); return true; } if ( key == "なでられ反応回数") { nade_sensitivity = zen2int(value); return true; } if ( key == "デバッグ" ) { fDebugMode = (value=="有効"); return true; } if ( key == "Log" ) { Sender::validate(value=="有効"); return true; } if ( key == "RequestLog" ) { fRequestLog = (value=="有効"); return true; } if ( key == "OperationLog" ) { fOperationLog = (value=="有効"); return true; } if ( key == "ResponseLog" ) { fResponseLog = (value=="有効"); return true; } if ( key == "自動挿入ウェイトの倍率" ) { rate_of_auto_insert_wait= zen2int(value); rate_of_auto_insert_wait = min(1000, max(0, rate_of_auto_insert_wait)); variables["自動挿入ウェイトの倍率"] = int2zen(rate_of_auto_insert_wait); return true; } if ( key == "自動挿入ウェイトタイプ" ) { if ( value == "一般" ) { type_of_auto_insert_wait = 2; variables["自動挿入ウェイトタイプ"] = "一般"; } else if ( value == "無効" ) { type_of_auto_insert_wait = 0; variables["自動挿入ウェイトタイプ"] = "無効"; } else /* if ( value == "里々" ) */ { type_of_auto_insert_wait = 1; variables["自動挿入ウェイトタイプ"] = "里々"; } return true; } if ( key == "辞書フォルダ" ) { strvec words; split(value, ",",dic_folder); reload_flag=true; return true; } if ( key == "セーブデータ暗号化" ) { fEncodeSavedata = (value=="有効"); return true; } if ( compare_head(key,"単語群「") && compare_tail(key,"」の重複回避") ) { variables.erase(key); words.setOC( string(key.c_str()+8, key.length()-8-12), value ); return true; } if ( compare_head(key,"文「") && compare_tail(key,"」の重複回避") ) { variables.erase(key); talks.setOC( string(key.c_str()+4, key.length()-4-12), value ); return true; } if ( key == "次のトーク" ) { variables.erase(key); int count=1; while ( reserved_talk.find(count) != reserved_talk.end() ) ++count; reserved_talk[count] = value; sender << "次回のランダムトークが「" << value << "」に予\x96\xf1されました。" << endl; return true; } if ( compare_head(key,"次から") && compare_tail(key,"回目のトーク") ) { variables.erase(key); int count = zen2int( string(key.c_str()+6, key.length()-6-12) ); if ( count<=0 ) { sender << "トーク予\x96\xf1、設定値がヘンです。" << endl; } else { while ( reserved_talk.find(count) != reserved_talk.end() ) ++count; reserved_talk[count] = value; sender << count << "回後のランダムトークが「" << value << "」に予\x96\xf1されました。" << endl; } return true; } if ( key=="トーク予\x96\xf1のキャンセル" ) { if ( value=="*" ) reserved_talk.clear(); else for (map<int, string>::iterator it=reserved_talk.begin(); it!=reserved_talk.end() ; ) if ( value == it->second ) reserved_talk.erase(it++); else ++it; return true; } if ( key == "SAORI引数の計算" ) { if (value=="有効") mSaoriArgumentCalcMode = SACM_ON; else if (value=="無効") mSaoriArgumentCalcMode = SACM_OFF; else mSaoriArgumentCalcMode = SACM_AUTO; return true; } if ( key == "辞書リロード" && value=="実行") { variables.erase(key); reload_flag=true; return true; } if ( key == "手動セーブ" && value=="実行") { variables.erase(key); if ( is_dic_loaded ) { this->Save(); } return true; } if ( key == "自動セーブ間隔" ) { mAutoSaveInterval = zen2int(value); mAutoSaveCurrentCount = mAutoSaveInterval; if ( mAutoSaveInterval > 0 ) sender << "" << itos(mAutoSaveInterval) << "秒間隔で自動セーブを行います。" << endl; else sender << "自動セーブは行いません。" << endl; return true; } if ( key == "全タイマ解除" && value=="実行") { variables.erase(key); for (strintmap::const_iterator i=timer.begin();i!=timer.end();++i) variables.erase(i->first + "タイマ"); timer.clear(); return true; } if ( key == "教わること" ) { variables.erase(key); teach_genre=value; if ( result != NULL ) *result += "\\![open,teachbox]"; return true; } if ( key.size()>6 && compare_tail(key, "タイマ") ) { string name(key.c_str(), strlen(key.c_str())-6); /*if ( sentences.find(name) == sentences.end() ) { result = string("※ タイマ終了時のジャンプ先 *")+name+" がありません ※"; // セーブデータ復帰時を考慮 } else */{ int sec = zen2int(value); if ( sec < 1 ) { variables.erase(key); if ( timer.find(name)!=timer.end() ) { timer.erase(name); sender << "タイマ「" << name << "」の予\x96\xf1がキャンセルされました。" << endl; } else sender << "タイマ「" << name << "」は元から予\x96\xf1されていません。" << endl; } else { timer[name] = sec; sender << "タイマ「" << name << "」が" << sec << "秒後に予\x96\xf1されました。" << endl; } } return true; } if ( key == "引数区切り追加" && value.size()>0 ) { variables.erase(key); mDelimiters.insert(value); return true; } if ( key == "引数区切り削除" && value.size()>0 ) { variables.erase(key); mDelimiters.erase(value); return true; } if ( compare_head(key, "Value") && aredigits(key.c_str() + 5) ) { variables.erase(key); if(value!=""){ mResponseMap[string()+"Reference"+key.substr(5)] = value; }else{ mResponseMap.erase(string()+"Reference"+key.substr(5)); } return true; } return false; }
int Satori::SentenceToSakuraScriptInternal(const strvec &vec,string &result,string &jump_to,ptrdiff_t &ip) { // 再帰管理 static int nest_count=0; ++nest_count; //DBG(sender << "enter SentenceToSakuraScriptInternal, nest-count: " << nest_count << ", vector_size: " << vec.size() << endl); if ( m_nest_limit > 0 && nest_count > m_nest_limit ) { sender << "呼び出し回数超過" << endl; --nest_count; return 0; } static const int basewait=3; strvec::const_iterator it = vec.begin(); std::advance(it,ip); for ( ; it != vec.end() ; ++it) { const char* p = it->c_str(); //DBG(sender << nest_count << " '" << p << "'" << endl); if ( it==vec.begin() && strncmp(p, "→", 2)==0 ) { p+=2; updateGhostsInfo(); // ゴースト情報を更新 if ( ghosts_info.size()>=2 ) { // そもそも自分以外にゴーストはいるのか。 string temp = p; vector<strmap>::iterator i=ghosts_info.begin(); ++i; // 自分は飛ばす for ( ; i!=ghosts_info.end() ; ++i ) { string name = (*i)["name"]; sender << "ghost: " << name <<endl; if ( compare_head(temp, name) ) {// 相手を特定 mCommunicateFor = name; p += mCommunicateFor.size(); break; } } if ( i==ghosts_info.end() ) { // 特定しなかった場合 // ランダム //int n = random(ghosts_info.size()-1))+1; //assert( n>=1 && n < ghosts_info.size()); mCommunicateFor = (ghosts_info[1])["name"]; // あかん、隣で起動している〜〜にならん } } } // 選択肢 \q?[id,string] if ( strncmp(p, "_", 2)==0 ) { if ( strlen(p)>1023 ) continue; char buf[1024]; strncpy(buf, p+2, sizeof(buf) / sizeof(buf[0])); char* choiced = buf; char* id = (char*)strstr_hz(buf, "\t"); // 選択肢ラベルとジャンプ先の区切り result += append_at_choice_start; if ( id == NULL ) { string str=UnKakko(choiced); //result += string("\\q")+itos(question_num++)+"["+str+"]["+str+"]"; result += "\\q["+str+","+str+"]"; } else { *id++='\0'; while ( *id=='\t' ) ++id; // 選択肢ラベルとジャンプ先の区切り //result += string("\\q")+itos(question_num++)+"["+UnKakko(id)+"]["+UnKakko(choiced)+"]"; result += "\\q["+UnKakko(choiced)+","+UnKakko(id)+"]"; } result += append_at_choice_end; continue; } // ちょっと微妙な存在意義。 if ( strncmp(p, "\\s", 2)==0 ) { if ( !is_speaked(speaker) ) { if ( surface_changed_before_speak.find(speaker) == surface_changed_before_speak.end() ) { surface_changed_before_speak.insert(map<int,bool>::value_type(speaker,is_speaked_anybody()) ); } } } // ジャンプ if ( strncmp(p, ">", 2)==0 || strncmp(p, "≫", 2)==0 ) { strvec words; split(p+2, "\t", words, 2); // ジャンプ先とジャンプ条件の区切り if ( words.size()>=2 ) { string r; if ( !calculate(words[1], r) ) break; if ( zen2int(r) == 0 ) { sender << "*計算結果が0だったため、続行します。" << endl; continue; } } if ( words.size() >= 1 ) { jump_to = UnKakko(words[0].c_str(),false,true); } else { jump_to.erase(); } if ( strncmp(p, "≫", 2)==0 ) { ip = std::distance(vec.begin(),it) + 1; --nest_count; return 2; } else { ip = std::distance(vec.begin(),it) + 1; --nest_count; return 1; } } // 変数を設定 if ( strncmp(p, "$", 2)==0 ) { const char* v; string value; bool do_calc=false; p+=2; if ( (v=strstr_hz(p, "\t"))!=NULL ) { // 変数名と変数に設定する内容の区切り value = UnKakko(v+1,false,true); } else if ( (v=strstr_hz(p, "="))!=NULL || (v=strstr_hz(p, "="))!=NULL ) { value = UnKakko(v+((*v=='=') ? 1 : 2),false,true); do_calc=true; } else { //v = p+strlen(p); //value=""; result += "\\n※ $による変数代入文には、タブによる区切りか、=による計算式が必要です ※\\n\\n[half]'" + value +"'"; break; } string key(p, v-p); key = UnKakko(key.c_str(),false,true); if ( key=="" ) { result += "$"; // $そのまま表示 speaked_speaker.insert(speaker); } else if ( aredigits(zen2han(key)) ) { sender << "$" << key << " 数字のみの変数名は扱えません." << endl; erase_var(key); // 存在抹消 } else if ( value=="" ) { sender << "$" << key << "/cleared." << endl; erase_var(key); // 存在抹消 system_variable_operation(key, "", &result);//存在抹消したものがシステム変数かも! } else { bool isOverwritten; bool isSysValue; // "0"は代入先を先に参照する時、エラーを返さないように。 string *pstr = GetValue(key,isSysValue,true,&isOverwritten,"0"); if ( do_calc ) { if ( !calculate(value, value) ) break; if ( aredigits(value) ) { value = int2zen(stoi(value)); } } sender << "$" << key << "=" << value << "/" << (isOverwritten ? "written." : "overwritten.")<< endl; if ( pstr ) { *pstr = value; } system_variable_operation(key, value, &result); } continue; } // 通常処理 while ( p[0] != '\0' ) { string c=get_a_chr(p); // 全角半角問わず一文字取得し、pを一文字すすめる if ( c=="(" ) { // 何かを取得・挿入 character_wait_exec; result += KakkoSection(p); } else if ( c=="\xff" ) { //内部特殊表現 c=get_a_chr(p); if ( c=="\x01" ) { //0xff0x01=スコープ切り替え 後に半角数値が1文字続く c=get_a_chr(p); int speaker_tmp = stoi(c.c_str()); if ( is_speaked(speaker) && speaker != speaker_tmp ) { result += append_at_scope_change; chars_spoken += 2; } speaker = speaker_tmp; character_wait_clear(2); if ( speaker == 0 ) { result += "\\0"; } else if ( speaker == 1 ) { result += "\\1"; } else { result += "\\p[" + c + "]"; } } } else if ( c==":" ) { // スコープ切り替え - ここは二人を想定。 if ( is_speaked(speaker) ) { result += append_at_scope_change; chars_spoken += 2; } speaker = (speaker==0) ? 1 : 0; character_wait_clear(2); result += (speaker ? "\\1" : "\\0"); } else if ( c=="\\" || c=="%" ) { // さくらスクリプトの解釈、というか解釈のスキップ。 if (*p=='\\'||*p=='%') { // エスケープされた\, % result += c + *p++; continue; } const char* start=p; string cmd="",opt=""; while (!_ismbblead(*p) && (isalpha(*p)||isdigit(*p)||*p=='!'||*p=='-'||*p=='*'||*p=='&'||*p=='?'||*p=='_')) ++p; cmd.assign(start, p-start); if ( cmd == "_?" || cmd == "_!" ) { //エスケープ処理 この間に自動タグ挿入はしない const char* e1 = strstr(p,"\\_?"); if ( ! e1 ) { e1 = strstr(p,"\\_!"); } if ( e1 ) { character_wait_exec; result += c; result += cmd; opt.assign(p,e1-p+3); opt = UnKakko(opt.c_str()); p = e1 + 3; //endtag result += opt; continue; } } if (*p=='[') { const char* opt_start = ++p; while (*p!=']') { if (p[0]=='\\' && p[1]==']') // エスケープされた] ++p; p += _ismbblead(*p) ? 2 : 1; } opt.assign(opt_start, p++ -opt_start); opt=UnKakko(opt.c_str()); } if ( cmd=="n" ) { // 改行 character_wait_clear(2); } else if ( ( (cmd=="0" || cmd=="h") && speaker==1) || ( (cmd=="1" || cmd=="u") && speaker==0) ) { // スコープ切り替え if ( is_speaked(speaker) ) { result += append_at_scope_change_with_sakura_script; chars_spoken += 2; } speaker = stoi(cmd); character_wait_clear(2); } else if ( cmd=="p" && aredigits(opt) ) { int spktmp = stoi(opt); if ( speaker != spktmp ) { // スコープ切り替えonSSP/CROW if ( is_speaked(speaker) ) { result += append_at_scope_change_with_sakura_script; chars_spoken += 2; } speaker = spktmp; character_wait_clear(2); } } else if ( cmd=="s" ) { //サーフィス切り替えの前にウェイトは済ませておくこと character_wait_exec; } else if ( cmd=="_q" ) { if ( ! is_quick_section ) { //これからクイックセクションなのでウエイトを全部消化 character_wait_exec; } is_quick_section = ! is_quick_section; } if ( opt!="" ) { //sender << "ss_cmd: " << c << "," << cmd << "," << opt << endl; result += c + cmd + "[" + opt + "]"; } else { //sender << "ss_cmd: " << c << "," << cmd << endl; result += c + cmd; } //result += string(start, p-start); } else { // 通常の一文字 character_wait_exec; speaked_speaker.insert(speaker); result += c; chars_spoken += c.size(); if ( c=="。" || c=="、" ) { character_wait_clear(c=="、"?1:2); } } } character_wait_clear(2); result += "\\n"; } //DBG(sender << "leave SentenceToSakuraScriptInternal, nest-count: " << nest_count << endl); --nest_count; return 0; }