bool IsFloat (const char *str) { const char *pt; if (*str == '+' || *str == '-') str++; if (*str == '.') { pt = str; } else { pt = IsNum (str); if (pt == NULL) return false; } if (*pt == '.') { pt = IsNum (pt+1); if (pt == NULL) return false; } if (*pt == 'e' || *pt == 'E') { pt++; if (*pt == '+' || *pt == '-') pt++; pt = IsNum (pt); } return pt != NULL && *pt == 0; }
void GasSysDlg::OnDeleteItem() { //删除所选项 int nIndex; POSITION pos = m_permCListCtrl.GetFirstSelectedItemPosition(); nIndex = m_permCListCtrl.GetNextSelectedItem(pos); // 获取引索项。m_nIndex的值为用户在列表框中选中的行号 if(nIndex !=-1) { m_permCListCtrl.DeleteItem(nIndex); int num = _ttoi(m_numPermSys); if(IsNum(m_numPermSys)) { num = num -1; } m_numPermSys.Format(_T("%d"),num); UpdateData(FALSE); } pos = m_tempCListCtrl.GetFirstSelectedItemPosition(); nIndex = m_tempCListCtrl.GetNextSelectedItem(pos); // 获取引索项。m_nIndex的值为用户在列表框中选中的行号 if(nIndex!=-1) { m_tempCListCtrl.DeleteItem(nIndex); int num = _ttoi(m_numTempSys); if(IsNum(m_numTempSys)) { num = num -1; } m_numTempSys.Format(_T("%d"),num); UpdateData(FALSE); } }
// Convert the string to an integer list LIST *StrToIntList(char *str, bool sorted) { LIST *o; TOKEN_LIST *t; o = NewIntList(sorted); t = ParseTokenWithoutNullStr(str, " ,/;\t"); if (t != NULL) { UINT i; for (i = 0;i < t->NumTokens;i++) { char *s = t->Token[i]; if (IsEmptyStr(s) == false) { if (IsNum(s)) { InsertIntDistinct(o, ToInt(s)); } } } FreeToken(t); } return o; }
void P_ParseAnimatedDoor(FScanner &sc) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny; FDoorAnimation anim; TArray<FTextureID> frames; bool error = false; FTextureID v; sc.MustGetString(); anim.BaseTexture = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); if (!anim.BaseTexture.Exists()) { error = true; } while (sc.GetString ()) { if (sc.Compare ("opensound")) { sc.MustGetString (); anim.OpenSound = sc.String; } else if (sc.Compare ("closesound")) { sc.MustGetString (); anim.CloseSound = sc.String; } else if (sc.Compare ("pic")) { sc.MustGetString (); if (IsNum (sc.String)) { v = anim.BaseTexture + (atoi(sc.String) - 1); } else { v = TexMan.CheckForTexture (sc.String, FTexture::TEX_Wall, texflags); if (!v.Exists() && anim.BaseTexture.Exists() && !error) { sc.ScriptError ("Unknown texture %s", sc.String); } frames.Push (v); } } else { sc.UnGet (); break; } } if (!error) { anim.TextureFrames = new FTextureID[frames.Size()]; memcpy (anim.TextureFrames, &frames[0], sizeof(FTextureID) * frames.Size()); anim.NumTextureFrames = frames.Size(); DoorAnimations.Push (anim); } }
void GasSysDlg::OnEnKillfocusTempesysNumEdit() { //int oldNum = _ttoi(m_numTempSys); UpdateData(TRUE); //if(m_numPermSys.IsEmpty()) return; //if(oldNum == _ttoi(m_numTempSys)) return; if(IsNum(m_numTempSys)) SetTempItems(_ttoi(m_numTempSys)); }
bool GraphFile::IsMatrixFile(std::string filename) const { std::ifstream file_stream; file_stream.open(filename); AssertOrDie(static_cast<bool>(file_stream), "Error: can't open " + filename); // First line is the name of the experiment, and is arbitrary std::string line; getline(file_stream, line); // Second line is the number of rows and columns std::getline(file_stream, line); StringTokens line_tokens = Split(line, " \t"); if (line_tokens.size() != 2 || !IsNum(line_tokens[0]) || !IsNum(line_tokens[1])) { return false; } size_t rows = std::stoi(line_tokens[0]), cols = std::stoi(line_tokens[1]); size_t row_number = 0; while (std::getline(file_stream, line)) { ++row_number; if (row_number > rows) { return false; } line_tokens = Split(line, " \t"); if (line_tokens.size() != cols) { return false; } for (std::string token : line_tokens) { if (!IsNum(token) && token.compare("?") != 0 && token.compare("*") != 0) { return false; } } } if (row_number != rows) { return false; } file_stream.close(); return true; }
void GasSysDlg::OnEnKillfocusPermsysNumEdit() { //int oldNum = _ttoi(m_numPermSys); UpdateData(TRUE); //if(m_numPermSys.IsEmpty()) return; //if(oldNum == _ttoi(m_numPermSys)) return; if(IsNum(m_numPermSys)) SetPermItems(_ttoi(m_numPermSys)); //m_permRecords = m_permDataModel.GetRecords(); }
TTm TJsonVal::GetTm() const { EAssert(IsStr() || IsNum()); if (IsStr()) { const TStr& TmStr = GetStr(); return TTm::GetTmFromWebLogDateTimeStr(TmStr, '-', ':', '.', 'T'); } else { return TTm::GetTmFromMSecs(TTm::GetWinMSecsFromUnixMSecs(GetInt64())); } }
/* 名称|运转|备注 名称|运转|备注 */ void GasSysDlg::OnInitList() { initList(m_permCListCtrl,m_permDataModel); initList(m_tempCListCtrl,m_tempDataModel); ArrayVector datasVector; //获取地面系统数据 ReportDataHelper::ReadDatas(PERMENT_OBJCT_NAME,datasVector,3); m_numPermSys = _T(""); m_permRecords.clear(); if(datasVector.size() > 0) { setRecord(m_permRecords,datasVector,m_numPermSys); } datasVector.clear(); //获取井下系统数据 ReportDataHelper::ReadDatas(TEMPGAS_OBJCT_NAME,datasVector,3); m_numTempSys = _T(""); m_tempRecords.clear(); if(datasVector.size() > 0) { setRecord(m_tempRecords,datasVector,m_numTempSys); } UpdateData(FALSE); if(IsNum(m_numPermSys)) { SetPermItems(_ttoi(m_numPermSys)); } if(IsNum(m_numTempSys)) { SetTempItems(_ttoi(m_numTempSys)); } }
bool GraphFile::IsAdjacencyListFile(std::string filename) const { std::ifstream file_stream; file_stream.open(filename); AssertOrDie(static_cast<bool>(file_stream), "Error: can't open " + filename); // First line should be number of vertices std::string line; getline(file_stream, line); if (!IsNum(line)) { return false; } size_t order = std::stoi(line); // Next lines should be adjacency lists size_t line_number = 0; std::set< StringPair > edges_seen; while (std::getline(file_stream, line)) { ++line_number; if (line_number > order) { return false; } StringTokens line_tokens = Split(line, " \t"); if (line_tokens.empty()) { return false; } std::string vertex = line_tokens[0]; for (size_t i = 1; i < line_tokens.size(); ++i) { StringPair edge(vertex, line_tokens[i]); if (edges_seen.find(edge) != edges_seen.end()) { return false; } edges_seen.insert(edge); } } if (line_number != order) { return false; } // Check edge symmetry for (auto e : edges_seen) { StringPair f(e.second, e.first); if (edges_seen.find(f) == edges_seen.end()) { return false; } } file_stream.close(); return true; }
int main(void) { char str[100]; int count=0; /* while(str!=NULL) { printf("input a intger: "); scanf("%s[^\n]",str); if(IsNum(str)) { int m=atoi(str); printf("It has %d '1'\n",Bget1(m)); break; } else { printf("Input error,try again!\n"); if(count>MAX) { printf("Sorry,illegal input exceeds the maximum limit,bye!\n"); exit(0); } continue; } count++; } */ do{ count++; if(count > 1 && count < MAX) { printf("Your input is not a intger! Try again:\n"); } if(count>MAX) { printf("Sorry,illegal input exceeds the maximum limit,bye!\n"); exit(0); } printf("input a intger: "); scanf("%s[^\n]",str); }while(!IsNum(str)); int m=atoi(str); printf("It has %d '1'\n",Bget1(m)); return 0; }
FTextureID FTextureManager::ParseFramenum (FScanner &sc, FTextureID basepicnum, int usetype, bool allowMissing) { const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny; FTextureID framenum; sc.MustGetString (); if (IsNum (sc.String)) { framenum = basepicnum + (atoi(sc.String) - 1); } else { framenum = CheckForTexture (sc.String, usetype, texflags); if (!framenum.Exists() && !allowMissing) { sc.ScriptError ("Unknown texture %s", sc.String); } } return framenum; }
int Format(char* num) { int i = 0; int f=1000000; char c; int result = 0; while ((c=*(num+i))!='\0') { if (IsNum(c)) { result += f*(c - '0'); f /= 10; } if (IsCharacter(c)) { result += f*(maps[c - 'A']); f /= 10; } i++; } return result; }
static void m_reply(struct Luser *lptr, struct NickInfo *nptr, int ac, char **av) { struct MemoInfo *from; struct Memo *memoptr; struct NickInfo *master, *realptr; char *memotext; int index, ii; if (!nptr) return; if (ac < 3) { notice(n_MemoServ, lptr->nick, "Syntax: REPLY <index> <text>"); notice(n_MemoServ, lptr->nick, ERR_MORE_INFO, n_MemoServ, "REPLY"); return; } if (!(from = FindMemoList(nptr->nick))) { notice(n_MemoServ, lptr->nick, "You have no recorded memos"); return; } index = IsNum(av[1]); if ((index < 0) || (index > from->memocnt)) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is an invalid index", av[1]); return; } master = realptr = NULL; for (memoptr = from->memos; memoptr; memoptr = memoptr->next) { if (memoptr->index == index) { if (!(realptr = FindNick(memoptr->sender))) { notice(n_MemoServ, lptr->nick, ERR_NOT_REGGED, av[2]); return; } master = GetMaster(realptr); assert(master != 0); if (!(master->flags & NS_MEMOS)) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is rejecting all memos", master->nick); return; } break; } } if (!master || !realptr) return; if (ac >= 3) { memotext = (char *) MyMalloc(strlen("[Re]: ") + strlen(av[2]) + 1); ircsprintf(memotext, "[Re]: %s", av[2]); ii = 3; while (ii < ac) { memotext = (char *) MyRealloc(memotext, strlen(memotext) + strlen(av[ii]) + (2 * sizeof(char))); strcat(memotext, " "); strcat(memotext, av[ii]); ii++; } } else memotext = MyStrdup(""); index = StoreMemo(master->nick, memotext, lptr); if (index) { notice(n_MemoServ, lptr->nick, "Memo has been recorded for [\002%s\002]", master->nick); /* * It was sent to a nickname - check if they are online * and notify them */ if ((master->flags & NS_MEMONOTIFY) && (realptr->flags & NS_IDENTIFIED) && FindClient(realptr->nick)) { notice(n_MemoServ, realptr->nick, "You have a new memo from \002%s\002 (#%d)", lptr->nick, index); notice(n_MemoServ, realptr->nick, "Type \002/msg %s READ %d\002 to read it", n_MemoServ, index); } } /* if (index) */ MyFree(memotext); } /* m_reply() */
int CTranCmn::fnAPP_IBK_MANAGEMENT_InputProc() { CString ManagerOpPassword("00000000"); CString KtLinKusOpPassword("0000"); CString strReturn(""); CString strTmp(""); int nGetCnt = 0; CString strAcceptLen("0"); ///////////////////////////////////////////////////////////////////////////// Accept.AuthFlag = 0; ///////////////////////////////////////////////////////////////////////////// m_pDevCmn->fnSCR_DisplayScreen(3200, K_30_WAIT, PIN_MENU_MODE1); // 환경 업체선택 strReturn = m_pDevCmn->fstrSCR_GetKeyString(); if (strReturn == "NICE") { ManagerOpPassword.Format("%8.8s", GetDate()); Accept.AuthFlag = 1; strAcceptLen = "8"; } else if (strReturn == "KT LINKUS") { KtLinKusOpPassword = "******"; Accept.AuthFlag = 2; strAcceptLen = "4"; } else if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_TIMEOVER) fnAPP_CancelProc(T_TIMEOVER); else if (strReturn == S_INPUTOVER) fnAPP_CancelProc(T_INPUTOVER); else { fnAPP_CancelProc(T_INPUTOVER); } while (TRUE) { if(nGetCnt > 2) fnAPP_CancelProc(T_INPUTOVER); m_pDevCmn->fnSCR_DisplayString(1, strAcceptLen); // #0115 m_pDevCmn->fnSCR_DisplayScreen(3202, K_30_WAIT, PIN_NUMERIC_MODE); strReturn = m_pDevCmn->fstrSCR_GetKeyString(); if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_TIMEOVER) fnAPP_CancelProc(T_TIMEOVER); else if (strReturn == S_INPUTOVER) fnAPP_CancelProc(T_INPUTOVER); else if (strReturn == S_CLEAR) { nGetCnt++; continue; } else { if (Accept.AuthFlag == 2) { if (strReturn == KtLinKusOpPassword) { break; } else { nGetCnt++; continue; } } else { if (strReturn == ManagerOpPassword) { break; } else { nGetCnt++; continue; } } } } strReturn = ""; ///////////////////////////////////////////////////////////////////////////// memset(Accept.JiroElecNum, '0', sizeof(Accept.JiroElecNum)); // 환경점검내용 ///////////////////////////////////////////////////////////////////////////// //#N0214 strTmp = IniGetStr(_TRANS_INI, TRANS_SEC, "IBK_MANAGEMENT_INFO","00000000000000"); //#N0199 환경점검 이전 내용 표시 //#N0213 환경점검 시 초기 상태 무조건 비정상 //strTmp = "11111111111111"; //#N0214 m_pDevCmn->fnSCR_DisplayString(1, strTmp); m_pDevCmn->fnSCR_DisplayScreen(3201, K_120_WAIT, PIN_MENU_MODE1); // 환경점검내용 strReturn = m_pDevCmn->fstrSCR_GetKeyString(); if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_TIMEOVER) fnAPP_CancelProc(T_TIMEOVER); else if (strReturn == S_INPUTOVER) fnAPP_CancelProc(T_INPUTOVER); else if ((strReturn.GetLength() != 14) || // 자료검증 (!IsNum(strReturn.GetBuffer(0), strReturn.GetLength())) ) fnAPP_CancelProc(T_INPUTERROR); else { Accept.JiroElecNumSize = strReturn.GetLength(); memcpy(Accept.JiroElecNum, strReturn.GetBuffer(0), strReturn.GetLength()); strTmp.Empty(); strTmp = strReturn; IniSetStr(_TRANS_INI, TRANS_SEC, "IBK_MANAGEMENT_INFO", strReturn.GetBuffer(0)); //#N0199 환경점검 이전 내용 표시 -> #N0214 } strReturn = ""; ///////////////////////////////////////////////////////////////////////////// Accept.TelNumSize = 0; // 직원번호 memset(Accept.TelNum, ' ', sizeof(Accept.TelNum)); // 직원번호 ///////////////////////////////////////////////////////////////////////////// m_pDevCmn->fnSCR_DisplayScreen(3203, K_30_WAIT, PIN_NUMERIC_MODE); //// 직원번호 strReturn = m_pDevCmn->fstrSCR_GetKeyString(); if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_CANCEL) fnAPP_CancelProc(T_CANCEL); else if (strReturn == S_TIMEOVER) fnAPP_CancelProc(T_TIMEOVER); else if (strReturn == S_INPUTOVER) fnAPP_CancelProc(T_INPUTOVER); else if ((!strReturn.GetLength()) || // 자료검증 (strReturn.GetLength() > sizeof(Accept.TelNum)) || (!IsNum(strReturn.GetBuffer(0), strReturn.GetLength())) || (IsZero(strReturn.GetBuffer(0), strReturn.GetLength()))) fnAPP_CancelProc(T_INPUTERROR); else { Accept.TelNumSize = strReturn.GetLength(); memcpy(Accept.TelNum, strReturn.GetBuffer(0), strReturn.GetLength()); IniSetStr(_TRANS_INI, TRANS_SEC, "IBK_MANAGEMENT_INFO", strTmp); //#N0199 환경점검 이전 내용 표시 } return T_OK; }
int IsNumorAlpha(char c){ if(IsAlpha(c) || IsNum(c)){ return 1; } return 0; }
void Dialog_List_Undo::OnOK() { UpdateData(); if(!(m_strcost.IsEmpty())) { if(!IsNum(m_strcost)) { MessageBox("成本输入必须为数字,请重新输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_COST)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_COST))->SetSel(0, -1); return; } if(atof(m_strcost)>10000000) { MessageBox("成本超过上限一千万,请重新输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_COST)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_COST))->SetSel(0, -1); return; } } if(!(m_payment.IsEmpty())) { if(!IsNum(m_payment)) { MessageBox("已付金额输入必须为数字,请重新输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_PAYMENT)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_PAYMENT))->SetSel(0, -1); return; } if(atof(m_payment)>10000000) { MessageBox("已付金额超过上限一千万,请重新输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_PAYMENT)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_PAYMENT))->SetSel(0, -1); return; } } if(m_strreason.IsEmpty()) { MessageBox("销单原因不能为空,请输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_REASON)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_REASON))->SetSel(0, -1); return; } int len = m_strreason.GetLength(); if(len>=255) { MessageBox("销单原因不能超过255个字,请重新输入","提示",MB_OK); (CEdit*)GetDlgItem(IDC_EDIT_REASON)->SetFocus(); ((CEdit*)GetDlgItem(IDC_EDIT_REASON))->SetSel(0, -1); return; } CDialog_Login2 login2; login2.m_permission = DEL_LIST; if (login2.DoModal()!=IDOK) { return; } Dialog_progress *dlgpro; dlgpro=new Dialog_progress(); dlgpro->Create(IDD_DIALOG_PROGRESS); if(g_openprocess) dlgpro->ShowWindow(SW_SHOW); else dlgpro->ShowWindow(SW_HIDE); CString sql; MYSQL myCont; MYSQL_RES *result; //MYSQL_ROW sql_row; mysql_init(&myCont); if(mysql_real_connect(&myCont,g_MysqlConnect.host,g_MysqlConnect.user,g_MysqlConnect.pswd,g_MysqlConnect.table,g_MysqlConnect.port,NULL,0)) { dlgpro->setpos(500); mysql_query(&myCont, "SET NAMES GBK"); //设置编码格式,否则在cmd下无法显示中文 sql = "select * from undolist where listid='" + m_listid +"'"; if(mysql_query(&myCont,sql)!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } dlgpro->setpos(600); result=mysql_store_result(&myCont);//保存查询到的数据到result if(result) { unsigned __int64 num = mysql_num_rows(result);//行数 if(num>=1) { //修改记录 dlgpro->setpos(700); sql.Format("update undolist set reason=\"%s\",cost=\"%s\",payment=\"%s\",undotime=\"%s\",department=\"%s\" where listid=\"%s\" ",m_strreason,m_strcost,m_payment,m_strtime,m_strdepartment,m_listid); int ret = mysql_query(&myCont,sql); if(ret!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } sql.Format("update schedule set undolist=%d where listid=\"%s\" ",1,m_listid); ret = mysql_query(&myCont,sql); dlgpro->setpos(900); if(ret!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } if(result!=NULL) mysql_free_result(result);//释放结果资源 mysql_close(&myCont);//断开连接 dlgpro->endpos(); MessageBox("销单成功","提示",MB_OK); CDialog::OnOK(); return; } } else { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } dlgpro->setpos(700); sql.Format("select * from schedule where listid=\"%s\" ",m_listid); if(mysql_query(&myCont,sql)!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } dlgpro->setpos(800); result=mysql_store_result(&myCont);//保存查询到的数据到result if(result) { dlgpro->setpos(950); unsigned __int64 num = mysql_num_rows(result);//行数 if(num!=1)// { MessageBox("无此订单或未下单","提示",MB_OK); if(result!=NULL) mysql_free_result(result);//释放结果资源 mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } } else { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } sql.Format("insert into undolist values (\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")", m_listid,m_strreason,m_strcost,m_payment,m_strtime,m_strdepartment); if(mysql_query(&myCont,sql)!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } dlgpro->setpos(900); sql.Format("update schedule set undolist=%d where listid=\"%s\" ",1,m_listid); int ret = mysql_query(&myCont,sql); if(ret!= 0) { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } dlgpro->setpos(980); } else { const char *error = mysql_error(&myCont); CString str; str.Format("数据库错误(%s)",error); MessageBox(str,"提示",MB_OK); mysql_close(&myCont);//断开连接 dlgpro->endpos(); return; } if(result!=NULL) mysql_free_result(result);//释放结果资源 mysql_close(&myCont);//断开连接 dlgpro->endpos(); MessageBox("销单成功","提示",MB_OK); CDialog::OnOK(); }
void CodeWriter::WriteCom(trivec tvec) { m_sCom = tvec.first; m_sArg1 = tvec.second.first; m_sArg2 = tvec.second.second; if(m_sCom == "push") { if(m_sArg1 == "constant") { // @2 // D=A // @SP // A=M // M=D (*sp) = 2 // @SP // M=M-1 (sp = sp-1) m_ofs << "@" << m_sArg2 << endl; m_ofs << "D=A" << endl; m_ofs << "@" << SP << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; } else if(m_sArg1 == "static") { if(IsNum(m_sArg2)) m_ofs << "@" << STATIC(0) + stol(m_sArg2) << endl; else cout << "push a symbol address of static segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << SP << endl; m_ofs << "M=D" << endl; } else if( m_sArg1 == "local") { //@LCL (push local 2) //A=M //A=A+1 //A=A+1 //DO IT TWICE //D=M //@SP //A=M //M=D m_ofs << "@" << "LCL" << endl; m_ofs << "A=M" << endl; if(IsNum(m_sArg2)) { int n = stol(m_sArg2); for(int i=0;i<n;++i) m_ofs << "A=A+1" << endl; } else cout << "push a symbol address of local,temp,argument segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << SP << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; } else if(m_sArg1 == "argument" ) { //@ARG (push argument 2) //A=M //A=A+1 //A=A+1 //DO IT TWICE //D=M //@SP //A=M //M=D m_ofs << "@" << "ARG" << endl; m_ofs << "A=M" << endl; if(IsNum(m_sArg2)) { int n = stol(m_sArg2); for(int i=0;i<n;++i) m_ofs << "A=A+1" << endl; } else cout << "push a symbol address of local,temp,argument segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << SP << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; } else if (m_sArg1 == "this") { //@ARG (push argument 2) //A=M //A=A+1 //A=A+1 //DO IT TWICE //D=M //@SP //A=M //M=D m_ofs << "@" << "THIS" << endl; m_ofs << "A=M" << endl; if(IsNum(m_sArg2)) { int n = stol(m_sArg2); for(int i=0;i<n;++i) m_ofs << "A=A+1" << endl; } else cout << "push a symbol address of local,temp,argument segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << SP << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; } else if (m_sArg1 == "that" ) { //@THAT (push argument 2) //A=M //A=A+1 //A=A+1 //DO IT TWICE //D=M //@SP //A=M //M=D m_ofs << "@" << "THAT" << endl; m_ofs << "A=M" << endl; if(IsNum(m_sArg2)) { int n = stol(m_sArg2); for(int i=0;i<n;++i) m_ofs << "A=A+1" << endl; } else cout << "push a symbol address of local,temp,argument segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << SP << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; } } //switch(m_Arg1) else if(m_sCom == "pop") { if(m_sArg1 == "static") // pop static 1 { // @SP // D=M // @STATIC+2 // M=D // D=D-1 stack pointer deccrement // @SP // M=D m_ofs << "@SP" << endl; m_ofs << "D=M" << endl; if(IsNum(m_sArg2)) m_ofs << "@" << STATIC(0) + stol(m_sArg2) << endl; else cout << "pop a symbol address" << endl; m_ofs << "M=D" << endl; m_ofs << "D=D-1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=D" << endl; } else if(m_sArg1 == "constant") { // pop constant 2 // @SP // D=M // D=D-1 // @SP // M=D m_ofs << "@SP" << endl; m_ofs << "D=M" << endl; m_ofs << "D=D-1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=D" << endl; } else if( m_sArg1 == "local") { // pop local 2 // @SP // A=M // A=A+1 // D=M // @LCL // A=M // A=A+1 // A=A+1 //twice // M=D m_ofs << "@" << "ARG" << endl; m_ofs << "A=M" << endl; if(IsNum(m_sArg2)) { int n = stol(m_sArg2); for(int i=0;i<n;++i) m_ofs << "A=A+1" << endl; } else cout << "push a symbol address of local,temp,argument segment" << endl; m_ofs << "D=M" << endl; m_ofs << "@" << "SP" << endl; m_ofs << "a=m" << endl; m_ofs << "m=d" << endl; // } }// (pop) else if(m_sCom == "add") { //@SP //A=M //A=A+1 //D=M get mem(stackpointer) //A=A+1 //D=D+M add *sp+*(sp+1) //M=D save into *(sp+1) //@SP //M=M+1 sp = sp +1 m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=D+M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; } else if(m_sCom == "sub") { //@SP //A=M //A=A+1 (SP -> first unallocated mem) //D=M get mem(stackpointer) //A=A+1 //D=M-D sub *(sp+1)-*(sp) //M=D save into *(sp+1) //@SP //M=M+1 sp = sp +1 m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M-D" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; // } else if(m_sCom == "neg") { //@SP //A=M //A=A+1 //M=-M m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "M=-M" << endl; } else if(m_sCom == "eq") { // @SP // A=M // A=A+1 // D=M // A=A+1 // D=M-D // @TRUE100 // D;JEQ //D=0;JUMP TRUE // @SP // M=M+1 // @SP // M=M+1 // @0 // D=A PUSH 0 // @SP // M=D // @SP // M=M-1 // @END100 // 0;JMP // (TRUE100) // @SP // M=M+2 // @65535 // D=A PUSH 1111 1111 1111 1111 // @SP // M=M-1 // (END100) m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M-D" << endl; m_ofs << "@TRUE" << m_truetag << endl; m_ofs << "D;JEQ" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@0" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "@END" << m_endtag << endl; m_ofs << "0;JMP" << endl; m_ofs << "(TRUE" << m_truetag++ << ")" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@65535" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "(END" << m_endtag++ << ")" << endl; } else if (m_sCom == "gt" ) { // @SP // A=M // A=A+1 // D=M // A=A+1 // D=M-D // @TRUE100 // D;JGT //D=0;JUMP TRUE // @SP // M=M+2 // @0 // D=A PUSH 0 // @SP // M=D // @SP // M=M-1 // @END100 // 0;JMP // (TRUE100) // @SP // M=M+2 // @65535 // D=A PUSH 1111 1111 1111 1111 // @SP // M=M-1 // (END100) m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M-D" << endl; m_ofs << "@TRUE" << m_truetag << endl; m_ofs << "D;JGT" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@0" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "@END" << m_endtag << endl; m_ofs << "0;JMP" << endl; m_ofs << "(TRUE" << m_truetag++ << ")" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@65535" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "(END" << m_endtag++ << ")" << endl; } else if (m_sCom == "lt" ) { // @SP // A=M // A=A+1 // D=M // A=A+1 // D=M-D // @TRUE100 // D;JLT //D=0;JUMP TRUE // @SP // M=M+2 // @0 // D=A PUSH 0 // @SP // M=D // @SP // M=M-1 // @END100 // 0;JMP // (TRUE100) // @SP // M=M+2 // @65535 // D=A PUSH 1111 1111 1111 1111 // @SP // M=M-1 // (END100) m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M-D" << endl; m_ofs << "@TRUE" << m_truetag << endl; m_ofs << "D;JLT" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@0" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "@END" << m_endtag << endl; m_ofs << "0;JMP" << endl; m_ofs << "(TRUE" << m_truetag++ << ")" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; m_ofs << "@65535" << endl; m_ofs << "D=A" << endl; m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M-1" << endl; m_ofs << "(END" << m_endtag++ << ")" << endl; } else if (m_sCom == "and") { //@SP //A=M //A=A+1 (SP -> first unallocated mem) //D=M get mem(stackpointer) //A=A+1 //D=M-D sub *(sp+1)-*(sp) //M=D save into *(sp+1) //@SP //M=M+1 sp = sp +1 m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=D&M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; } else if (m_sCom == "or") { //@SP //A=M //A=A+1 (SP -> first unallocated mem) //D=M get mem(stackpointer) //A=A+1 //D=M-D sub *(sp+1)-*(sp) //M=D save into *(sp+1) //@SP //M=M+1 sp = sp +1 m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "D=D|M" << endl; m_ofs << "M=D" << endl; m_ofs << "@SP" << endl; m_ofs << "M=M+1" << endl; } else if(m_sCom == "not") { //@SP //A=M //A=A+1 //M=!M m_ofs << "@SP" << endl; m_ofs << "A=M" << endl; m_ofs << "A=A+1" << endl; m_ofs << "M=!M" << endl; } }// WriteCom
// InnerParse is poorly named; it really just accepts any character not handled in the calling function // and determines the token type for unknown right-hand tokens. void InnerParse( const char c, char& StrMark, Array< char >& TokenString, const int LineCount, SToken::ETokenType& InOutTokenType, bool* OutClosedString = NULL ) { switch( InOutTokenType ) { case SToken::ET_None: // Determine the type of the RHS from the first character // (Can change from int to float later, on finding a . or f) if( IsNum( c ) || c == '-' ) { InOutTokenType = SToken::ET_Int; TokenString.PushBack( c ); } else if( IsBool( c ) ) { InOutTokenType = SToken::ET_Bool; TokenString.PushBack( c ); } else if( c == '\"' || c == '\'' ) { InOutTokenType = SToken::ET_String; StrMark = c; } else if( c == '.' ) { InOutTokenType = SToken::ET_Float; TokenString.PushBack( c ); } else { PRINTF( "Unexpected character %c in undetermined token at line %d\n", c, LineCount ); WARNDESC( "Unexpected character in undetermined token" ); } break; case SToken::ET_Name: case SToken::ET_Context: case SToken::ET_Macro: TokenString.PushBack( c ); break; case SToken::ET_Bool: TokenString.PushBack( c ); break; case SToken::ET_Int: if( c == '.' ) { InOutTokenType = SToken::ET_Float; } else { ASSERT( IsNum( c ) ); } TokenString.PushBack( c ); break; case SToken::ET_Float: ASSERT( IsNum( c ) || c == 'f' ); TokenString.PushBack( c ); break; case SToken::ET_String: if( c == StrMark ) { TokenString.PushBack( '\0' ); if( OutClosedString ) { *OutClosedString = true; } } else { TokenString.PushBack( c ); } break; default: WARNDESC( "Unexpected token" ); break; } }
static int dparse(char *line, int linenum, int rehash) { struct Directive *dptr; int larc; /* line arg count */ char *larv[PARAM_MAX]; /* holds line arguements */ char *lineptr, *tmp; int ret, ii, pcnt; ret = 2; /* * We can't use SplitBuf() to break up the line, since * it doesn't handle quotes etc. - do it manually */ larc = 0; for (lineptr = line; *lineptr; lineptr++) { if (larc >= PARAM_MAX) { fatal(1, "%s:%d Too many parameters (max: %d)", SETPATH, linenum, PARAM_MAX); ret = 0; break; } if (!lineptr || !*lineptr) break; while (*lineptr && IsSpace(*lineptr)) lineptr++; if (!*lineptr) break; tmp = lineptr; if (*lineptr == '"') { /* we encountered a quote */ /* advance past quotation mark */ tmp++; lineptr++; /* * Now advance lineptr until we hit another quotation mark, * or the end of the line */ while (*lineptr && (*lineptr != '"')) { /* * If they want to include double quotes, they can * put a \" inside the quoted string, so advance * lineptr past it twice, once for the '\' and once * for the '"'. */ if (*lineptr == '\\') lineptr++; lineptr++; } if (!*lineptr) { /* we hit EOL without reaching another quotation mark */ fatal(1, "%s:%d Unterminated quote", SETPATH, linenum); ret = 0; break; } *lineptr = '\0'; } /* if (*lineptr == '"') */ else { /* * Advance lineptr until we hit a space */ while (*lineptr && !IsSpace(*lineptr)) lineptr++; if (*lineptr) *lineptr = '\0'; } larv[larc++] = tmp; } /* for (lineptr = line; *lineptr; lineptr++) */ if (!ret || !larc) return (ret); if (!(dptr = FindDirective(larv[0]))) { fatal(1, "%s:%d Unknown directive [%s] (ignoring)", SETPATH, linenum, larv[0]); return (1); } if (rehash && (dptr->flag == D_NORUNTIME)) { /* * SETPATH is being parsed during a rehash, and we * hit a non-run time configurable option, ignore it */ return (2); } pcnt = 1; for (ii = 0; ii < PARAM_MAX; ii++, pcnt++) { if (!dptr->param[ii].type) break; /* * Now assign our variable (dptr->param[ii].ptr) to the * corresponding larv[] slot */ if ((dptr->param[ii].type != PARAM_SET) && (pcnt >= larc)) { fatal(1, "%s:%d Not enough arguements to [%s] directive", SETPATH, linenum, dptr->name); return (0); } #if 0 /* * There should be code which check for too many arguments for * PARAM_SET - because of bugs in previous HybServ1 code I am leaving * this code under undef, but it _should_ go into distribution once. * However, I don't wont to break old `save -conf' files. -kre */ if ((dptr->param[ii].type == PARAM_SET) && (pcnt > 1)) { fatal(1, "%s:%d Too many arguments for [%s] directive", SETPATH, linenum, dptr->name); return 0; } #endif switch (dptr->param[ii].type) { case PARAM_STRING: { if ((*(char **) dptr->param[ii].ptr) != NULL) { /* * If this is a rehash, make sure we free the old * string before allocating a new one. If this * is NOT a rehash, we should never get here, because * ClearDirectives() would have already zeroed * all ptr fields of directives[] */ MyFree(*(char **) dptr->param[ii].ptr); } *(char **) dptr->param[ii].ptr = MyStrdup(larv[pcnt]); break; } case PARAM_INT: { int value; value = IsNum(larv[pcnt]); if (!value) { fatal(1, "%s:%d Invalid integer", SETPATH, linenum); ret = 0; break; } /* * We have to call atoi() anyway since IsNum() would * have returned 1 if larv[pcnt] was "0", but IsNum() * is a good way of making sure we have a valid integer */ *(int *) dptr->param[ii].ptr = atoi(larv[pcnt]); break; } case PARAM_TIME: { long value; value = timestr(larv[pcnt]); /* Now, let us consider this a bit. Function timestr() will try to * extract as much data as it can. And sometimes we actually * _want_ to put 0 in time field to turn off that feature. So we * will have it turned off whether it has garbage there, or is 0. * Sounds OK, does it? -kre */ /* if (!value) { fatal(1, "%s:%d Invalid time format", SETPATH, linenum); ret = 0; break; } */ *(long *) dptr->param[ii].ptr = value; break; } case PARAM_SET: { *(int *) dptr->param[ii].ptr = 1; break; } case PARAM_PORT: { int value; value = IsNum(larv[pcnt]); if (!value) { fatal(1, "%s:%d Invalid port number (must be between 1 and 65535)", SETPATH, linenum); ret = 0; break; } value = atoi(larv[pcnt]); if ((value < 1) || (value > 65535)) { fatal(1, "%s:%d Invalid port number (must be between 1 and 65535)", SETPATH, linenum); ret = 0; break; } *(int *) dptr->param[ii].ptr = value; break; } default: { /* we shouldn't get here */ fatal(1, "%s:%d Unknown parameter type [%d] for directive [%s]", SETPATH, linenum, dptr->param[ii].type, dptr->name); ret = 0; break; } } /* switch (dptr->param[ii].type) */ } /* for (ii = 0; ii < PARAM_MAX; ii++, pcnt++) */ return (ret); } /* dparse() */
bool FCajunMaster::LoadBots () { FScanner sc; FString tmp; bool gotteam = false; int loaded_bots = 0; bglobal.ForgetBots (); tmp = M_GetCajunPath(BOTFILENAME); if (tmp.IsEmpty()) { DPrintf ("No " BOTFILENAME ", so no bots\n"); return false; } sc.OpenFile(tmp); while (sc.GetString ()) { if (!sc.Compare ("{")) { sc.ScriptError ("Unexpected token '%s'\n", sc.String); } botinfo_t *newinfo = new botinfo_t; bool gotclass = false; memset (newinfo, 0, sizeof(*newinfo)); newinfo->info = copystring ("\\autoaim\\0\\movebob\\.25"); for (;;) { sc.MustGetString (); if (sc.Compare ("}")) break; switch (sc.MatchString (BotConfigStrings)) { case BOTCFG_NAME: sc.MustGetString (); appendinfo (newinfo->info, "name"); appendinfo (newinfo->info, sc.String); newinfo->name = copystring (sc.String); break; case BOTCFG_AIMING: sc.MustGetNumber (); newinfo->skill.aiming = sc.Number; break; case BOTCFG_PERFECTION: sc.MustGetNumber (); newinfo->skill.perfection = sc.Number; break; case BOTCFG_REACTION: sc.MustGetNumber (); newinfo->skill.reaction = sc.Number; break; case BOTCFG_ISP: sc.MustGetNumber (); newinfo->skill.isp = sc.Number; break; case BOTCFG_TEAM: { char teamstr[16]; BYTE teamnum; sc.MustGetString (); if (IsNum (sc.String)) { teamnum = atoi (sc.String); if (!TeamLibrary.IsValidTeam (teamnum)) { teamnum = TEAM_NONE; } } else { teamnum = TEAM_NONE; for (unsigned int i = 0; i < Teams.Size(); ++i) { if (stricmp (Teams[i].GetName (), sc.String) == 0) { teamnum = i; break; } } } appendinfo (newinfo->info, "team"); mysnprintf (teamstr, countof(teamstr), "%d", teamnum); appendinfo (newinfo->info, teamstr); gotteam = true; break; } default: if (stricmp (sc.String, "playerclass") == 0) { gotclass = true; } appendinfo (newinfo->info, sc.String); sc.MustGetString (); appendinfo (newinfo->info, sc.String); break; } } if (!gotclass) { // Bots that don't specify a class get a random one appendinfo (newinfo->info, "playerclass"); appendinfo (newinfo->info, "random"); } if (!gotteam) { // Same for bot teams appendinfo (newinfo->info, "team"); appendinfo (newinfo->info, "255"); } newinfo->next = bglobal.botinfo; newinfo->lastteam = TEAM_NONE; bglobal.botinfo = newinfo; loaded_bots++; } Printf ("%d bots read from %s\n", loaded_bots, BOTFILENAME); return true; }
static void m_forward(struct Luser *lptr, struct NickInfo *nptr, int ac, char **av) { struct MemoInfo *from, *target; struct Memo *memoptr = NULL; struct Memo *fromptr; char *to; /* who the memo is sent to */ int index, cnt; char buf[MAXLINE]; struct NickInfo *master, *realptr; #ifdef CHANNELSERVICES struct ChanInfo *ci = NULL; #endif if (!nptr) return; if (ac < 3) { notice(n_MemoServ, lptr->nick, "Syntax: FORWARD <index|ALL> <nick/channel>"); notice(n_MemoServ, lptr->nick, ERR_MORE_INFO, n_MemoServ, "FORWARD"); return; } if (!(from = FindMemoList(nptr->nick))) { notice(n_MemoServ, lptr->nick, "You have no recorded memos"); return; } index = IsNum(av[1]); if ((index < 0) || (index > from->memocnt) || (!index && (irccmp(av[1], "ALL") != 0))) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is an invalid index", av[1]); return; } master = realptr = NULL; if (*av[2] == '#') { #ifndef CHANNELSERVICES notice(n_MemoServ, lptr->nick, "Channel services are disabled"); return; #else if (!(ci = FindChan(av[2]))) { notice(n_MemoServ, lptr->nick, ERR_CH_NOT_REGGED, av[2]); return; } if (!HasAccess(ci, lptr, CA_AUTOOP)) { notice(n_MemoServ, lptr->nick, "AutoOp access is required to forward a memo to [\002%s\002]", ci->name); return; } to = ci->name; #endif } else { /* it was sent to a nickname */ if (!(realptr = FindNick(av[2]))) { notice(n_MemoServ, lptr->nick, ERR_NOT_REGGED, av[2]); return; } master = GetMaster(realptr); assert(master != 0); if (!(master->flags & NS_MEMOS)) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is rejecting all memos", realptr->nick); return; } to = master->nick; } if (!(target = FindMemoList(to))) { target = MakeMemoList(); target->name = MyStrdup(to); AddMemoList(target); } else if (from == target) { /* * If we let someone forward memos to themselves, * the below loop will never end, eventually malloc()'ing too * much and crashing - head it off at the pass */ notice(n_MemoServ, lptr->nick, "You cannot forward memos to yourself"); return; } if (MaxMemos && (target->memocnt >= MaxMemos)) { notice(n_MemoServ, lptr->nick, "%s has reached the maximum memo limit, and cannot receive more", to); return; } cnt = 0; for (fromptr = from->memos; fromptr; fromptr = fromptr->next) { if (!index || (fromptr->index == index)) { memset(&buf, 0, MAXLINE); target->memocnt++; target->newmemos++; cnt++; memoptr = MakeMemo(); memoptr->sender = MyStrdup(lptr->nick); memoptr->sent = current_ts; memoptr->index = target->memocnt; strcpy(buf, "[Fwd]: "); strncat(buf, fromptr->text, MAXLINE - 8); memoptr->text = MyStrdup(buf); AddMemo(target, memoptr); if (MaxMemos && (target->memocnt >= MaxMemos)) break; } } if (!index) ircsprintf(buf, "All memos have"); else ircsprintf(buf, "Memo #%d has", index); notice(n_MemoServ, lptr->nick, "%s been forwarded to [\002%s\002]", buf, target->name); if (master && realptr) { /* * It was sent to a nickname - check if they are online * and notify them */ if ((master->flags & NS_MEMONOTIFY) && (realptr->flags & NS_IDENTIFIED) && FindClient(realptr->nick)) { notice(n_MemoServ, realptr->nick, "You have %d new forwarded memo%s from \002%s\002", cnt, (cnt == 1) ? "" : "s", memoptr->sender); notice(n_MemoServ, realptr->nick, "Type \002/msg %s LIST\002 to view %s", n_MemoServ, (cnt == 1) ? "it" : "them"); } } /* if (master && realptr) */ #ifdef CHANNELSERVICES else { struct Channel *chptr; /* * It was sent to a channel - notify every AOP or higher */ if ((ci) && (chptr = FindChannel(target->name))) { struct ChannelUser *cu; struct NickInfo *tmpn; for (cu = chptr->firstuser; cu; cu = cu->next) { if (FindService(cu->lptr)) continue; tmpn = GetLink(cu->lptr->nick); if (HasAccess(ci, cu->lptr, CA_AUTOOP)) { if (tmpn) { if (!(tmpn->flags & NS_MEMOS) || !(tmpn->flags & NS_MEMONOTIFY)) continue; } notice(n_MemoServ, cu->lptr->nick, "%d new forwarded channel memo%s from \002%s\002", cnt, (cnt == 1) ? "" : "s", memoptr->sender); notice(n_MemoServ, cu->lptr->nick, "Type \002/msg %s LIST %s\002 to view %s", n_MemoServ, chptr->name, (cnt == 1) ? "it" : "them"); } } } } /* else */ #endif /* CHANNELSERVICES */ } /* m_forward() */
static void m_undel(struct Luser *lptr, struct NickInfo *nptr, int ac, char **av) { struct MemoInfo *mi; struct Memo *memoptr; char istr[MAXLINE]; int index; if (!nptr) return; if (ac < 2) { notice(n_MemoServ, lptr->nick, "Syntax: UNDEL [channel] <index|all>"); notice(n_MemoServ, lptr->nick, ERR_MORE_INFO, n_MemoServ, "UNDEL"); return; } if (ac >= 3) { #ifdef CHANNELSERVICES struct ChanInfo *ci; #endif #ifndef CHANNELSERVICES notice(n_MemoServ, lptr->nick, "Channel services are disabled"); return; #else if (!(ci = FindChan(av[1]))) { notice(n_MemoServ, lptr->nick, ERR_CH_NOT_REGGED, av[1]); return; } if (!HasAccess(ci, lptr, CA_SUPEROP)) { notice(n_MemoServ, lptr->nick, "SuperOp access is required to undelete memos for [\002%s\002]", ci->name); return; } if (!(mi = FindMemoList(ci->name))) { notice(n_MemoServ, lptr->nick, "There are no recorded memos for [\002%s\002]", ci->name); return; } index = IsNum(av[2]); #endif /* CHANNELSERVICES */ } else { if (!(mi = FindMemoList(nptr->nick))) { notice(n_MemoServ, lptr->nick, "You have no recorded memos"); return; } index = IsNum(av[1]); } if ((index < 0) || (index > mi->memocnt) || (!index && (irccmp(av[(ac >= 3) ? 2 : 1], "ALL") != 0))) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is an invalid index", av[(ac >= 3) ? 2 : 1]); return; } for (memoptr = mi->memos; memoptr; memoptr = memoptr->next) { if (!index || (memoptr->index == index)) memoptr->flags &= ~MS_DELETE; } if (index) ircsprintf(istr, "Memo #%d has", index); else strcpy(istr, "All memos have"); if (ac >= 3) notice(n_MemoServ, lptr->nick, "%s been unmarked for deletion for [\002%s\002]", istr, av[1]); else notice(n_MemoServ, lptr->nick, "%s been unmarked for deletion", istr); } /* m_undel() */
static void m_read(struct Luser *lptr, struct NickInfo *nptr, int ac, char **av) { struct MemoInfo *mi; int index; struct Memo *memoptr; char istr[10]; if (!nptr) return; if (ac < 2) { notice(n_MemoServ, lptr->nick, "Syntax: READ [channel] <index|all>"); notice(n_MemoServ, lptr->nick, ERR_MORE_INFO, n_MemoServ, "READ"); return; } if (ac >= 3) { #ifdef CHANNELSERVICES struct ChanInfo *ci; #endif #ifndef CHANNELSERVICES notice(n_MemoServ, lptr->nick, "Channel services are disabled"); return; #else if (!(ci = FindChan(av[1]))) { notice(n_MemoServ, lptr->nick, ERR_CH_NOT_REGGED, av[1]); return; } if (!HasAccess(ci, lptr, CA_AUTOOP)) { notice(n_MemoServ, lptr->nick, "AutoOp access is required to read memos for [\002%s\002]", ci->name); return; } if (!(mi = FindMemoList(ci->name))) { notice(n_MemoServ, lptr->nick, "There are no recorded memos for [\002%s\002]", ci->name); return; } index = IsNum(av[2]); #endif /* CHANNELSERVICES */ } else { if (!(mi = FindMemoList(nptr->nick))) { notice(n_MemoServ, lptr->nick, "You have no recorded memos"); return; } index = IsNum(av[1]); } if ((index < 0) || (index > mi->memocnt) || (!index && (irccmp(av[(ac >= 3) ? 2 : 1], "ALL") != 0))) { notice(n_MemoServ, lptr->nick, "[\002%s\002] is an invalid index", av[(ac >= 3) ? 2 : 1]); return; } for (memoptr = mi->memos; memoptr; memoptr = memoptr->next) { if (!index || (memoptr->index == index)) { notice(n_MemoServ, lptr->nick, "Memo #%d from %s (sent %s ago):", memoptr->index, memoptr->sender, timeago(memoptr->sent, 1)); notice(n_MemoServ, lptr->nick, memoptr->text); if (ac < 3) { /* only mark nickname memos as read - not channel memos */ if (!(memoptr->flags & MS_READ)) mi->newmemos--; memoptr->flags |= MS_READ; } } } if (index) ircsprintf(istr, "%d", index); else strcpy(istr, "ALL"); if (ac >= 3) notice(n_MemoServ, lptr->nick, "To delete, type \002/msg %s DEL %s %s", n_MemoServ, av[1], istr); else notice(n_MemoServ, lptr->nick, "To delete, type \002/msg %s DEL %s", n_MemoServ, istr); } /* m_read() */
bool GraphFile::IsDimacsFile(std::string filename) const { std::ifstream file_stream; file_stream.open(filename); AssertOrDie(static_cast<bool>(file_stream), "Error: can't open " + filename); bool problem_line_seen = false; size_t vertices = 0, edges = 0; std::set< StringPair > edges_seen; std::set< std::string > vertices_seen; std::string line; while (std::getline(file_stream, line)) { StringTokens line_tokens = Split(line, " \t"); if (line_tokens.empty() || line_tokens[0].length() != 1) { return false; } switch (line_tokens[0][0]) { case 'c': { break; } case 'e' : { if (!problem_line_seen || line_tokens.size() != 3 || !IsNum(line_tokens[1]) || !IsNum(line_tokens[2])) { return false; } std::string u = line_tokens[1], v = line_tokens[2]; if (edges_seen.find(StringPair(u, v)) != edges_seen.end()) { return false; } vertices_seen.insert(u); vertices_seen.insert(v); edges_seen.insert(StringPair(u, v)); edges_seen.insert(StringPair(v, u)); break; } case 'p' : { if (problem_line_seen || line_tokens.size() != 4 || !IsNum(line_tokens[2]) || !IsNum(line_tokens[3]) ) { return false; } problem_line_seen = true; vertices = std::stoi(line_tokens[2]); edges = std::stoi(line_tokens[3]); break; } default: { return false; } } } if (2*edges != edges_seen.size() || vertices > vertices_seen.size() || !problem_line_seen) { return false; } file_stream.close(); return true; }
char *inputd(char *form, char *title, char *defstr, int keys, int frame, int mask, int bhelp, int cols, int tmo, int debounce) { int exs,eys,wxs,wxw,wys,wyw,i,j,xp,yp; char trnd[2]={0,0},tch; int act_key=-1, last_key=-1, b_key=-1, run=1, ipos=0; time_t t1,t2,tm1; char knum[12][2]={"1","2","3","4","5","6","7","8","9"," ","0"}; char kalp[12][5]={"+-*/","abcä","def","ghi","jkl","mnoö","pqrs","tuvü","wxyz","","_,.;"}; epos=-1; cpos=0; kpos=0; first=1; time(&tm1); if(cols>25) { cols=25; } if(cols<1) { cols=1; } format=form; estr=strdup(form); cnt=strlen(form); RenderString("X", 310, 250, 20, LEFT, BIG, CMC); i=GetStringLen(title)+10; j=((cnt>cols)?cols:cnt)*exsz; if(j>i) { i=j; } if(keys) { j=3*bxsz; if(j>i) { i=j; } } wxw=i+2*xbrd; i=(((cnt-1)/cols)+1)*eysz; if(keys) { i+=4*bysz; } wyw=((keys)?4:2)*ybrd+i; wxs=((ex-sx)-wxw)/2; wys=(((ey-sy)-wyw)+hsz)/2; exs=wxs+(wxw-((cnt>cols)?cols:cnt)*exsz)/2; eys=wys+ybrd; *estr=0; *rstr=0; j=0; for(i=0; i<strlen(format); i++) { tch=format[i]; if(IsInput(tch)) { if(epos==-1) { epos=i; } if(defstr && j<strlen(defstr)) { estr[i]=defstr[j++]; } else { estr[i]=' '; } } else { estr[i]=format[i]; } } estr[i]=0; RenderBox(wxs-2, wys-hsz-2, wxs+wxw+2, wys+wyw+2, radius, CMH); RenderBox(wxs, wys-hsz, wxs+wxw, wys+wyw, radius, CMC); RenderBox(wxs, wys-hsz, wxs+wxw, wys, radius, CMH); RenderString(title, wxs, wys-15, wxw, CENTER, BIG, CMHT); if(keys) { int bxs=wxs+(wxw-(3*bxsz))/2; int bys=((wys+wyw)-2*ybrd)-4*bysz; for(i=0; i<11; i++) { if(i!=9) { RenderBox(bxs+(i%3)*bxsz, bys+(i/3)*bysz, bxs+((i%3)+1)*bxsz, bys+((i/3)+1)*bysz, radius, COL_MENUCONTENT_PLUS_4); RenderBox(bxs+(i%3)*bxsz+2, bys+(i/3)*bysz+2, bxs+((i%3)+1)*bxsz-2, bys+((i/3)+1)*bysz-2, radius, CMC); RenderString(knum[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz/2, bxsz, CENTER, MED, CMCIT); RenderString(kalp[i], bxs+(i%3)*bxsz, bys+(i/3)*bysz+bysz-8, bxsz, CENTER, SMALL, CMCIT); } } RenderCircle(bxs,wys+wyw-ybrd-8,'R'); RenderString("Groß/Klein",bxs+15,wys+wyw-ybrd+5,3*bxsz,LEFT,SMALL,CMCIT); RenderCircle(bxs+3*bxsz-GetStringLen("löschen")-15,wys+wyw-ybrd-8,'Y'); RenderString("löschen",bxs,wys+wyw-ybrd+5,3*bxsz,RIGHT,SMALL,CMCIT); } while(run) { for(i=0; i<cnt; i++) { xp=i%cols; yp=i/cols; if(frame && IsInput(format[i])) { RenderBox(exs+xp*exsz, eys+5+yp*eysz, exs+(xp+1)*exsz, eys+(yp+1)*eysz, radius, COL_MENUCONTENT_PLUS_4); } RenderBox(exs+xp*exsz+1, eys+5+yp*eysz+1, exs+(xp+1)*exsz-1, eys+(yp+1)*eysz-1, radius, (epos==i)?CMCS:CMC); *trnd=(mask && format[i]==NUM && IsNum(estr[i]))?'*':estr[i]; RenderString(trnd, exs+xp*exsz+2, eys+yp*eysz+tys, exsz-2, CENTER, MED, (epos==i)?CMCST:(IsInput(format[i]))?CMCT:CMCIT); } memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres); time(&t1); i=-1; while(i==-1) { i=GetRCCode(); if(i!=-1) { tmo=0; if(i==b_key) { usleep(debounce*1000); while((i=GetRCCode())!=-1); } b_key=i; } time(&t2); if(tmo) { if((t2-tm1)>=tmo) { i=RC_HOME; } } if((((format[epos]!=NUM) && (format[epos]!=HEX)) || ((format[epos]==HEX)&&(strlen(hcod[cpos])>1))) && ((t2-t1)>ndelay) && last_key>=0) { act_key=i=-2; b_key=-3; NextPos(); } } act_key=i; switch(act_key) { case RC_0: SetCode(0); break; case RC_1: SetCode(1); break; case RC_2: SetCode(2); break; case RC_3: SetCode(3); break; case RC_4: SetCode(4); break; case RC_5: SetCode(5); break; case RC_6: SetCode(6); break; case RC_7: SetCode(7); break; case RC_8: SetCode(8); break; case RC_9: SetCode(9); break; case RC_RIGHT: NextPos(); act_key=-2; break; case RC_LEFT: PrevPos(); act_key=-2; break; case RC_PLUS: ipos=epos; while(IsInput(format[ipos+1]) && ((ipos+1)<cnt)) { ++ipos; } while(ipos>epos) { estr[ipos]=estr[ipos-1]; --ipos; } estr[epos]=' '; act_key=-1; break; case RC_MINUS: ipos=epos+1; while(IsInput(format[ipos]) && (ipos<cnt)) { estr[ipos-1]=estr[ipos]; ++ipos; } estr[ipos-1]=' '; act_key=-1; break; case RC_OK: run=0; break; case RC_MUTE: memset(lfb, TRANSP, 720*576); usleep(500000L); while(GetRCCode()!=-1) { usleep(100000L); } while(GetRCCode()!=RC_MUTE) { usleep(500000L); } while((act_key=GetRCCode())!=-1) { usleep(100000L); } break; case RC_UP: if(epos>=cols) { epos-=cols; if(!IsInput(format[epos])) { NextPos(); } } else { epos=cnt-1; if(!IsInput(format[epos])) { PrevPos(); } } act_key=-2; break; case RC_DOWN: if(epos<=(cnt-cols)) { epos+=cols; if(!IsInput(format[epos])) { NextPos(); } } else { epos=0; if(!IsInput(format[epos])) { NextPos(); } } act_key=-2; break; case RC_HOME: free(estr); estr=NULL; *rstr=0; run=0; break; case RC_RED: if(IsAlpha(estr[epos])) { estr[epos]^=0x20; } act_key=-2; break; case RC_YELLOW: epos=-1; for(i=0; i<strlen(format); i++) { if(IsInput(format[i])) { if(epos==-1) { epos=i; } estr[i]=' '; } } act_key=-2; break; case RC_HELP: if(bhelp) { sprintf(estr,"?"); run=0; } break; default: act_key=-2; break; } last_key=act_key; } if(estr) { j=0; for(i=0; i<strlen(format); i++) { if(IsInput(format[i])) { rstr[j++]=estr[i]; } } rstr[j]=0; free(estr); } ReTransform_Msg(rstr); return tstr; }
bool GraphFile::IsNexusMRPFile(std::string filename) const { std::ifstream file_stream; file_stream.open(filename); AssertOrDie(static_cast<bool>(file_stream), "Error: can't open " + filename); // Line 1: #NEXUS std::string line; std::getline(file_stream, line); StringTokens line_tokens = Split(line, " \t"); if (line_tokens.size() != 1 || line_tokens[0].compare("#nexus") != 0) { return false; } // Line 2: Begin Data; do { std::getline(file_stream, line); line_tokens = Split(line, " \t"); } while (line_tokens.empty()); line_tokens = Split(line, " \t;"); if (line_tokens.size() != 2 || line_tokens[0].compare("begin") != 0 || line_tokens[1].compare("data") != 0) { return false; } // Line 3: Dimensions ntax = 3, nchar = 3; do { std::getline(file_stream, line); line_tokens = Split(line, " \t"); } while (line_tokens.empty()); line_tokens = Split(line, " \t=;"); if (line_tokens.size() != 5 || line_tokens[0].compare("dimensions") != 0 || line_tokens[1].compare("ntax") != 0 || !IsNum(line_tokens[2]) || line_tokens[3].compare("nchar") != 0 || !IsNum(line_tokens[4])) { return false; } size_t rows = std::stoi(line_tokens[2]); size_t cols = std::stoi(line_tokens[4]); // Line 4: Format datatype=standard symbols="01" Missing=?; do { std::getline(file_stream, line); line_tokens = Split(line, " \t"); } while (line_tokens.empty()); line_tokens = Split(line, " \t=;"); if (line_tokens.size() != 7 || line_tokens[0].compare("format") != 0 || line_tokens[1].compare("datatype") != 0 || line_tokens[2].compare("standard") != 0 || line_tokens[3].compare("symbols") != 0 || line_tokens[4].compare("\"01\"") != 0 || line_tokens[5].compare("missing") != 0 || line_tokens[6].size() != 1) { return false; } char missing_char = line_tokens[6][0]; // Line 5: Matrix do { std::getline(file_stream, line); line_tokens = Split(line, " \t"); } while (line_tokens.empty()); line_tokens = Split(line, " \t"); if (line_tokens.size() != 1 || line_tokens[0].compare("matrix")) { return false; } // Matrix lines: taxon_name 0101? size_t row = 0; while (std::getline(file_stream, line) && line.compare(";") != 0) { ++row; line_tokens = Split(line, " \t"); if (line_tokens.size() != 2 || line_tokens[1].length() != cols || row > rows || !IsTwoStateTaxon(line_tokens[1], missing_char)) { return false; } } // Last line: end; std::getline(file_stream, line); line_tokens = Split(line, " \t;"); if (line_tokens.size() != 1 || line_tokens[0].compare("end") != 0) { return false; } // Whitespace while (std::getline(file_stream, line)) { line_tokens = Split(line, " \t"); if (!line_tokens.empty()) { return false; } } file_stream.close(); return true; }
// // G_ParseMapInfo // Parses the MAPINFO lumps of all loaded WADs and generates // data for wadlevelinfos and wadclusterinfos. // void G_ParseMapInfo (void) { int lump, lastlump = 0; level_pwad_info_t defaultinfo; level_pwad_info_t *levelinfo; int levelindex; cluster_info_t *clusterinfo; int clusterindex; DWORD levelflags; while ((lump = W_FindLump ("MAPINFO", &lastlump)) != -1) { SetLevelDefaults (&defaultinfo); SC_OpenLumpNum (lump, "MAPINFO"); while (SC_GetString ()) { switch (SC_MustMatchString (MapInfoTopLevel)) { case MITL_DEFAULTMAP: SetLevelDefaults (&defaultinfo); ParseMapInfoLower (MapHandlers, MapInfoMapLevel, &defaultinfo, NULL, 0); break; case MITL_MAP: // map <MAPNAME> <Nice Name> levelflags = defaultinfo.flags; SC_MustGetString (); if (IsNum (sc_String)) { // MAPNAME is a number, assume a Hexen wad int map = atoi (sc_String); sprintf (sc_String, "MAP%02d", map); SKYFLATNAME[5] = 0; HexenHack = true; // Hexen levels are automatically nointermission // and even lighting and no auto sound sequences levelflags |= LEVEL_NOINTERMISSION | LEVEL_EVENLIGHTING | LEVEL_SNDSEQTOTALCTRL; } levelindex = FindWadLevelInfo (sc_String); if (levelindex == -1) { levelindex = numwadlevelinfos++; wadlevelinfos = (level_pwad_info_t *)Realloc (wadlevelinfos, sizeof(level_pwad_info_t)*numwadlevelinfos); } levelinfo = wadlevelinfos + levelindex; memcpy (levelinfo, &defaultinfo, sizeof(*levelinfo)); uppercopy (levelinfo->mapname, sc_String); SC_MustGetString (); ReplaceString (&levelinfo->level_name, sc_String); // Set up levelnum now so that the Teleport_NewMap specials // in hexen.wad work without modification. if (!strnicmp (levelinfo->mapname, "MAP", 3) && levelinfo->mapname[5] == 0) { int mapnum = atoi (levelinfo->mapname + 3); if (mapnum >= 1 && mapnum <= 99) levelinfo->levelnum = mapnum; } ParseMapInfoLower (MapHandlers, MapInfoMapLevel, levelinfo, NULL, levelflags); break; case MITL_CLUSTERDEF: // clusterdef <clusternum> SC_MustGetNumber (); clusterindex = FindWadClusterInfo (sc_Number); if (clusterindex == -1) { clusterindex = numwadclusterinfos++; wadclusterinfos = (cluster_info_t *)Realloc (wadclusterinfos, sizeof(cluster_info_t)*numwadclusterinfos); memset (wadclusterinfos + clusterindex, 0, sizeof(cluster_info_t)); } clusterinfo = wadclusterinfos + clusterindex; clusterinfo->cluster = sc_Number; ParseMapInfoLower (ClusterHandlers, MapInfoClusterLevel, NULL, clusterinfo, 0); break; } } SC_Close (); } }
static void ParseMapInfoLower (MapInfoHandler *handlers, const char *strings[], level_pwad_info_t *levelinfo, cluster_info_t *clusterinfo, DWORD flags) { int entry; MapInfoHandler *handler; byte *info; info = levelinfo ? (byte *)levelinfo : (byte *)clusterinfo; while (SC_GetString ()) { if (SC_MatchString (MapInfoTopLevel) != -1) { SC_UnGet (); break; } entry = SC_MustMatchString (strings); handler = handlers + entry; switch (handler->type) { case MITYPE_IGNORE: break; case MITYPE_EATNEXT: SC_MustGetString (); break; case MITYPE_INT: SC_MustGetNumber (); *((int *)(info + handler->data1)) = sc_Number; break; case MITYPE_FLOAT: SC_MustGetFloat (); *((float *)(info + handler->data1)) = sc_Float; break; case MITYPE_COLOR: { SC_MustGetString (); std::string string = V_GetColorStringByName (sc_String); if (string.length()) { *((DWORD *)(info + handler->data1)) = V_GetColorFromString (NULL, string.c_str()); } else { *((DWORD *)(info + handler->data1)) = V_GetColorFromString (NULL, sc_String); } } break; case MITYPE_MAPNAME: SC_MustGetString (); if (IsNum (sc_String)) { int map = atoi (sc_String); sprintf (sc_String, "MAP%02d", map); } strncpy ((char *)(info + handler->data1), sc_String, 8); break; case MITYPE_LUMPNAME: SC_MustGetString (); uppercopy ((char *)(info + handler->data1), sc_String); break; case MITYPE_SKY: SC_MustGetString (); // get texture name; uppercopy ((char *)(info + handler->data1), sc_String); SC_MustGetFloat (); // get scroll speed //if (HexenHack) //{ // *((fixed_t *)(info + handler->data2)) = sc_Number << 8; //} //else //{ // *((fixed_t *)(info + handler->data2)) = (fixed_t)(sc_Float * 65536.0f); //} break; case MITYPE_SETFLAG: flags |= handler->data1; break; case MITYPE_SCFLAGS: flags = (flags & handler->data2) | handler->data1; break; case MITYPE_CLUSTER: SC_MustGetNumber (); *((int *)(info + handler->data1)) = sc_Number; if (HexenHack) { cluster_info_t *clusterH = FindClusterInfo (sc_Number); if (clusterH) clusterH->flags |= CLUSTER_HUB; } break; case MITYPE_STRING: SC_MustGetString (); ReplaceString ((const char **)(info + handler->data1), sc_String); break; case MITYPE_CSTRING: SC_MustGetString (); strncpy ((char *)(info + handler->data1), sc_String, handler->data2); *((char *)(info + handler->data1 + handler->data2)) = '\0'; break; } } if (levelinfo) levelinfo->flags = flags; else clusterinfo->flags = flags; }
//原本想只做检查,不转换成实际数据,但要做检查,同样需要检查实际值,所以干脆全部做完 bool CLogicThread::CheckInstinctParam(CTaskDialog* Dialog,CClause* Clause, vector<tstring>& ParamList){ int64 InstinctID = Clause->m_MemoryID; assert(InstinctID !=0); if(Clause->m_Param != NULL){ delete Clause->m_Param; Clause->m_Param = NULL; } switch(InstinctID){ case INSTINCT_DEFINE_INT64: case INSTINCT_DEFINE_FLOAT64: { tstring s = GetParam(ParamList); NumType type = IsNum(s); if(type == NOT_NUM){ //Error = "The param is not a num."; Clause->m_MemoryID = ERROR_5; return false; } if(type == INT_NUM){ int64 t = _ttoi64(s.c_str()); Clause->m_Param = new eINT(t); } else { TCHAR* endptr = NULL; float64 f = _tcstod(s.c_str(),&endptr); Clause->m_Param = new eFLOAT(f); } } break; case INSTINCT_DEFINE_STRING : { if( ParamList.size()!=1 ){ //Error = "the param more than one or lose param"; Clause->m_MemoryID = ERROR_3; return false; } tstring s = ParamList[0]; //int i=0; //while(isspace(s[i]) && ++i < s.size()); //提出空格 //s = s.substr(i,s.size()-1); Clause->m_Param = new eSTRING(s); } break; case INSTINCT_USE_OPERATOR: { if(ParamList.size() == 1){ tstring s = ParamList[0]; s=TriToken(s); if (s.size()==1) { TCHAR ch = s[0]; switch(ch){ case _T('+'): case _T('-'): case _T('*'): case _T('/'): case _T('%'): case _T('>'): case _T('<'): case _T('!'): case _T('&'): case _T('~'): case _T('|'): case _T('^'): Clause->m_Param = new eSTRING(s); return true; default: break; } }else{ if( s == _T(">=") || s == _T("<=") || s == _T("!=") || s == _T("&&") || s == _T("==") || s == _T("<<") || s == _T(">>") || s == _T("||") ) { Clause->m_Param = new eSTRING(s); return true; } } }else if (ParamList.size() == 2)//==如果没有被加引号会被视为两个字符串 { tstring s = ParamList[0]; s += ParamList[1]; s=TriToken(s); if( s == _T(">=") || s == _T("<=") || s == _T("!=") || s == _T("&&") || s == _T("==") || s == _T("<<") || s == _T(">>") || s == _T("||") ) { Clause->m_Param = new eSTRING(s); return true; } } //Error = "the param more than one or lose param"; Clause->m_MemoryID = ERROR_3; return false; } break; case INSTINCT_USE_RESISTOR: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when use resistor"; Clause->m_MemoryID = ERROR_3; return false; } tstring s = ParamList[0]; NumType type = IsNum(s); if(type == NOT_NUM || type == FLOAT_NUM){ //Error = "The param must be a int num."; Clause->m_MemoryID = ERROR_6; return false; } int64 t = _ttoi64(s.c_str()); if(t<0){ //Error = "The param must be > 0 "; Clause->m_MemoryID = ERROR_7; return false; } Clause->m_Param = new eINT(t); } break; case INSTINCT_USE_INDUCTOR: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when use inductor/capacitor"; Clause->m_MemoryID = ERROR_3; return false; }; tstring Name = ParamList[0]; Name = GetLogicElementName(Name); if (Dialog->FindInductor(Name) || CheckNameInInputed(INSTINCT_USE_INDUCTOR,Name,Clause,false)) { Clause->m_MemoryID = ERROR_22; return false; } Clause->m_Param = new eSTRING(Name); } break; case INSTINCT_USE_CAPACITOR: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when use inductor/capacitor"; Clause->m_MemoryID = ERROR_3; return false; } tstring Name = ParamList[0]; Name = GetLogicElementName(Name); if (Dialog->FindInductor(Name) || CheckNameInInputed(INSTINCT_USE_CAPACITOR,Name,Clause,false)) { Clause->m_MemoryID = ERROR_22; return false; } Clause->m_Param = new eSTRING(Name); } break; case INSTINCT_USE_DIODE: { if( ParamList.size()!=1 ){ //Error = "the param more than one or lose param when use diode"; Clause->m_MemoryID = ERROR_3; return false; } tstring s = ParamList[0]; NumType type = IsNum(s); if(type == NOT_NUM || type == FLOAT_NUM){ //Error = "The param must be a int num."; Clause->m_MemoryID = ERROR_6; return false; } int64 t = _ttoi64(s.c_str()); Clause->m_Param = new eINT(t); } break; case INSTINCT_REFERENCE_CAPACITOR: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } tstring Name = ParamList[0]; if (!Dialog->FindCapacitor(Name) && !CheckNameInInputed(INSTINCT_USE_CAPACITOR,Name,Clause,true)) { Clause->m_MemoryID = ERROR_21; return false; } Clause->m_Param = new eSTRING(Name); } break; case INSTINCT_REFERENCE_INDUCTOR: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } tstring Name = ParamList[0]; if (!Dialog->FindInductor(Name) && !CheckNameInInputed(INSTINCT_USE_INDUCTOR,Name,Clause,true)) { Clause->m_MemoryID = ERROR_21; return false; } Clause->m_Param = new eSTRING(Name); } break; case INSTINCT_SET_LABEL: case INSTINCT_GOTO_LABEL: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when using SET LABEL or GOTO LABEL command"; Clause->m_MemoryID = ERROR_3; return false; } tstring LabelName = ParamList[0]; LabelName = GetLogicElementName(LabelName); Clause->m_Param = new eSTRING(LabelName); } break; case INSTINCT_VIEW_PIPE: break; case INSTINCT_INPUT_NUM: case INSTINCT_INPUT_TEXT: { if( ParamList.size() !=1 ){ Clause->m_MemoryID = ERROR_3; return false; } tstring LabelName = ParamList[0]; LabelName = TriToken(LabelName); Clause->m_Param = new eSTRING(LabelName); } break; case INSTINCT_WAIT_SECOND: { if(ParamList.size()==0){ Clause->m_Param = NULL; } else if( ParamList.size()==1 ){ tstring s = ParamList[0]; NumType type = IsNum(s); if(type == NOT_NUM){ //Error = "The param must be a num."; Clause->m_MemoryID = ERROR_5; return false; } TCHAR* endptr = NULL; float64 f = _tcstod(s.c_str(),&endptr); Clause->m_Param = new eFLOAT(f); }else{ //Error = "the param more than one or lose param when use diode"; Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_TABLE_CREATE: { if( ParamList.size() !=1 ){ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; }; tstring Name = ParamList[0]; Name = GetLogicElementName(Name); if (Dialog->m_NamedTableList.HasName(Dialog,Name) || CheckNameInInputed(INSTINCT_TABLE_CREATE,Name,Clause,false)) { Clause->m_MemoryID = ERROR_22; return false; } Clause->m_Param = new eSTRING(Name); } break; case INSTINCT_TABLE_FOCUS: { if (ParamList.size() == 0) //动态版本 { return true; } else if( ParamList.size() ==1 ){ //静态版本 tstring Name = ParamList[0]; Clause->m_Param = new eSTRING(Name); }else{ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_TABLE_IMPORT: case INSTINCT_TABLE_EXPORT: case INSTINCT_TABLE_INSERT_DATA: case INSTINCT_TABLE_GET_DATA: case INSTINCT_TABLE_REMOVE_DATA: case INSTINCT_TABLE_GET_SIZE: case INSTINCT_TABLE_CLOSE: case INSTINCT_TABLE_MODIFY_DATA: { if (ParamList.size()!=0) { Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_USE_LOGIC: { tstring Name; if (ParamList.size()==0) { Clause->m_MemoryID = ERROR_3; return false; } else if(ParamList.size()==1){ Name = ParamList[0]; } else{ Name = GetParam(ParamList); } Name = TriToken(Name); tstring::size_type pos = Name.find(_T(':')); if (pos== tstring::npos) { pos = Name.find(_T(':')); } if (pos != tstring::npos) { Clause->m_Param = new eSTRING(Name.substr(0,pos)); }else{ Clause->m_Param = new eSTRING(Name); } } break; case INSTINCT_FOCUS_LOGIC: { if (ParamList.size() == 0) //动态版本 { return true; } else if( ParamList.size() ==1 ){ //静态版本 tstring Name = ParamList[0]; Clause->m_Param = new eSTRING(Name); }else{ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_INSERT_LOGIC: { if( ParamList.size() !=1 ){ Clause->m_MemoryID = ERROR_3; return false; } tstring InsertLogicName = ParamList[0]; Clause->m_Param = new eSTRING(InsertLogicName); } break; case INSTINCT_REMOVE_LOGIC: case INSTINCT_GET_DATE: case INSTINCT_GET_TIME: case INSTINCT_OUTPUT_INFO: { if (ParamList.size() !=0) { Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_START_OBJECT: { tstring Name = GetParam(ParamList); Name = TriToken(Name); if (Name.size()==0) { Clause->m_MemoryID = ERROR_3; return false; } vector<CObjectData> ObjectList; int n = Dialog->FindObject(Name,ObjectList); if (!n) { Dialog->RuntimeOutput(0,_T("Warning: not find object(%s)"),Name.c_str()); } Clause->m_Param = new eSTRING(Name); return true; } break; case INSTINCT_FOCUS_OBJECT: { if (ParamList.size() == 0) //动态版本 { return true; } else if( ParamList.size() ==1 ){ //静态版本 tstring Name = ParamList[0]; Clause->m_Param = new eSTRING(Name); }else{ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_NAME_OBJECT: { /* if( ParamList.size() !=1 ){ Clause->m_MemoryID = ERROR_3; return false; } tstring Name = ParamList[0]; Name = TriToken(Name); //检查名字是否唯一 if (Dialog->m_NamedObjectList.HasName(Dialog,Name) || CheckNameInInputed(INSTINCT_NAME_OBJECT,Name,Clause,false)) { Clause->m_MemoryID = ERROR_24; return false; } Clause->m_Param = new eSTRING(Name); */ if (ParamList.size() ==1) { tstring Name = ParamList[0]; Name = TriToken(Name); Clause->m_Param = new eSTRING(Name); } else if( ParamList.size() !=0 ){ //Error = "the param more than one or lose param when reference element"; Clause->m_MemoryID = ERROR_3; return false; } } break; case INSTINCT_USE_OBJECT: case INSTINCT_CLOSE_OBJECT: case INSTINCT_GET_OBJECT_DOC: case INSTINCT_ASK_PEOPLE: break; case INSTINCT_THINK_LOGIC : { tstring LogicName; if (ParamList.size()==0) { Clause->m_MemoryID = ERROR_3; return false; } else if(ParamList.size()==1){ LogicName= ParamList[0]; } else{ LogicName = GetParam(ParamList); } LogicName = TriToken(LogicName); tstring::size_type pos = LogicName.find(_T(':')); if (pos== tstring::npos) { pos = LogicName.find(_T(':')); } if (pos != tstring::npos) { LogicName = LogicName.substr(0,pos); } if(Dialog->FindLogic(LogicName) || CheckNameInInputed(INSTINCT_THINK_LOGIC,LogicName,Clause,false)){ //逻辑名重复 Clause->m_MemoryID = ERROR_8; return false; } Clause->m_Param = new eSTRING(LogicName); } break; case INSTINCT_RUN_TASK: case INSTINCT_DEBUG_TASK: case INSTINCT_STOP_TASK: case INSTINCT_PAUSE_TASK: case INSTINCT_STEP_TASK: { if( ParamList.size()!=0 ){ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; } } break; case INSTINCT_GOTO_TASK: { if( ParamList.size()!=1 ){ //Error = "the param more than one or lose param"; Clause->m_MemoryID = ERROR_3; return false; } tstring s = ParamList[0]; NumType type = IsNum(s); if(type != INT_NUM){ //Error = "The param must be a int num."; Clause->m_MemoryID = ERROR_6; return false; } int64 t = _ttoi64(s.c_str()); Clause->m_Param = new eINT(t); } break; case INSTINCT_SET_GLOBLELOGIC: break; case INSTINCT_CLOSE_DIALOG: break; case INSTINCT_LEARN_TOKEN: case INSTINCT_LEARN_PRONOUN: case INSTINCT_LEARN_ADJECTIVE: case INSTINCT_LEARN_NUMERAL: case INSTINCT_LEARN_VERB: case INSTINCT_LEARN_ADVERB: case INSTINCT_LEARN_ARTICLE: case INSTINCT_LEARN_PREPOSITION: case INSTINCT_LEARN_CONJUNCTION: case INSTINCT_LEARN_INTERJECTION: case INSTINCT_LEARN_NOUN: { //只能有一个参数 if(ParamList.size() != 1){ Clause->m_MemoryID = ERROR_3; return false; } tstring Word = ParamList[0]; Clause->m_Param = new eSTRING(Word); } break; case INSTINCT_LEARN_TEXT: { if(ParamList.size() == 1){ tstring Text = ParamList[0]; Clause->m_Param = new eSTRING(Text); }else if(ParamList.size() == 0){ tstring Text ; Clause->m_Param = new eSTRING(Text); }else{ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; } } break; case INSTINCT_LEARN_LOGIC: case INSTINCT_LEARN_OBJECT: case INSTINCT_LEARN_ACTION: { //只能有一个参数 if(ParamList.size() != 1){ Clause->m_MemoryID = ERROR_3; return false; } tstring Text = ParamList[0]; Text = TriToken(Text); //这里应该对text进行相应的检查 Clause->m_Param = new eSTRING(Text); } break; case INSTINCT_FIND_SET_PRICISION: { if( ParamList.size()!=1 ){ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; } tstring s = ParamList[0]; NumType type = IsNum(s); if(type != INT_NUM){ //Error = "The param must be a int num."; Clause->m_MemoryID = ERROR_6; return false; } int32 t = _ttoi(s.c_str()); Clause->m_Param = new eINT(t); } break; case INSTINCT_FIND_SET_STARTTIME: case INSTINCT_FIND_SET_ENDTIME: { // if( ParamList.size()!=0 ){ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; // } } break; case INSTINCT_FIND: case INSTINCT_FIND_LOGIC: case INSTINCT_FIND_OBJECT: { if( ParamList.size()!=1 ){ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; } tstring s = ParamList[0]; s=TriToken(s); Clause->m_Param = new eSTRING(s); } break; case INSTINCT_USE_ARM: { if( ParamList.size()!=0 ){ //Error = "param error" Clause->m_MemoryID = ERROR_20; return false; } } break; default: assert(0); return false; } return true; }