simpleString getString(int & len,bool keep = true) { bool save = d_skipws; d_skipws = false; if(!d_word) { d_word = new char[1001]; } else if(strlen(d_word)<1000) { delete d_word; d_word = new char[10001]; }; char * t = d_word; char c; getCharacter(c); if(c!='\"') errorh(__LINE__); if(keep) { *t=c;++t;++len; }; peekCharacter(c); len = 0; while(c!='\"') { passCharacter(); *t = c;++t;++len; if(len>1000) errorh(__LINE__); peekCharacter(c); }; if(keep) { *t=c;++t;++len; }; passCharacter(); *t = '\0'; simpleString result(d_word); d_skipws = save; return result; };
char * grabBracketed(char front,char back) { bool save = d_skipws; d_skipws = false; char c; getCharacter(c); if(c!=front) { GBStream << "Got:" << c << " and not " << front << '\n'; errorh(__LINE__); }; vector<char> vec; int nest = 1; while(nest>0) { getCharacter(c); if(c==front) { ++nest; } else if(c==back) { --nest; }; if(nest!=0) vec.push_back(c); if(nest<0) errorh(__LINE__); }; if(c!=back) { GBStream << "Got:" << c << " and not " << front << '\n'; errorh(__LINE__); }; int sz = vec.size(); char * result = new char[sz+1]; copy(vec.begin(),vec.end(),result); result[sz] = '\0'; d_skipws = save; return result; };
simpleString getAlphaNumWord(int & len) { len = 0; if(!d_word) { d_word = new char[1001]; } else if(strlen(d_word)<1000) { delete d_word; d_word = new char[1001]; }; char c; char * t = d_word; peekCharacter(c); if(('a'<=c && c <= 'z') || ('A'<=c && c <= 'Z')) { while(('a'<=c && c <= 'z') || ('A'<=c && c <= 'Z') || ('0'<=c && c <= '9')) { passCharacter(); *t = c; ++t;++len; if(len>1000) errorh(__LINE__); if(eof()) break; peekCharacter(c); }; }; *t = '\0'; simpleString result(d_word); return result; };
inline void subMonomial::start(int newstart) { #ifdef CAREFUL if(newstart<=0) { error1(newstart); } else if (newstart + _length - 1 > _mono.numberOfFactors()) { error2(newstart); } else #endif { if(newstart>_start) { int diff = newstart - _start; if(diff==0) { /* do nothing */ } else if(diff==1) { ++start_iterator; } else { if(diff<0) errorh(__LINE__); for(int jjjj=1;jjjj<=diff;++jjjj,++start_iterator) {}; #if 0 ncgbadvance(start_iterator,diff); // just diff, not diff-1 #endif } _start = newstart; } else { _start = newstart; start_iterator = _mono.begin(); for(int jjjj=2;jjjj<=newstart;++jjjj,++start_iterator) {}; #if 0 ncgbadvance(start_iterator,newstart-1); #endif } } };
bool operator()(const VariableSet & m,const VariableSet & n) const { bool result = false; int msz = m.size(); int nsz = n.size(); if(msz!=nsz) { result = msz< nsz; } else if(msz>0) { result = false; // perhaps they are equal Variable v1,v2; bool b1 = m.firstVariable(v1); bool b2 = n.firstVariable(v2); if(v1==v2) { while(b1&&b2) { b1 = m.nextVariable(v1); b2 = n.nextVariable(v2); if(b1) { if(v1!=v2) { result = operator()(v1,v2); }; } else break; }; } else { result = operator()(v1,v2); }; if(b1!=b2) errorh(__LINE__); }; return result; };
const Term & tip() const { if(d_terms.empty()) { tryToFillList(); if(d_terms.empty()) errorh(__LINE__); }; return d_terms.front(); };
int grabInteger() { int result = 0; int sign = 1; char c; peekCharacter(c); if(c=='-') { passCharacter(); sign = -1; peekCharacter(c); }; if('0'<=c&&c<='9') { while('0'<=c && c<='9') { passCharacter(); result *=10; result += (c-'0'); if(eof()) break; peekCharacter(c); }; } else { GBStream << "Error: no integer found\n."; errorh(__LINE__); }; result *= sign; return result; };
inline void Polynomial::setToZero() { if(_numberOfTerms>0) { _terms.clear(); _numberOfTerms = 0; _totalDegree = 0; } else if(_numberOfTerms<0) errorh(__LINE__); };
void peekCharacter(char & c) { if(!d_useUnget) { if(eof()) errorh(__LINE__); vGet(d_unget); d_useUnget = true; }; c = d_unget; //GBStream << "peeking " << d_unget << '\n'; };
void passString() { char c; getCharacter(c); if(c!='\"') errorh(__LINE__); peekCharacter(c); while(c!='\"') { passCharacter(); peekCharacter(c); }; passCharacter(); };
static void stream_close(struct stream *strm, int err) { stream_error_h *errorh = strm->errorh; strm->terminated = true; strm->errorh = NULL; if (errorh) { errorh(strm, err, strm->errorh_arg); } }
lispval Nbreak() { register lispval hold; register FILE *port; port = okport(Vpoport->a.clb,stdout); fprintf(port,"Breaking:"); if ((hold = lbot->val) != nil && ((hold = hold->d.car) != nil)) { printr(hold,port); } putc('\n',port); dmpport(port); return(errorh(Verbrk,"",nil,TRUE,0)); }
int getNumber() { int result = 0; int sign = 1; char c; peekCharacter(c); if(c=='-') { sign = -1; passCharacter(); peekCharacter(c); if(c=='+') { passCharacter(); peekCharacter(c); } else if(c=='-') { sign = 1; passCharacter(); peekCharacter(c); }; } else if(c=='+') { passCharacter(); peekCharacter(c); if(c=='+') { passCharacter(); peekCharacter(c); } else if(c=='-') { sign = -1; passCharacter(); peekCharacter(c); }; }; if('0'<=c&&c<='9') { while('0'<=c && c<='9') { passCharacter(); result *=10; result += (c-'0'); if(eof()) break; peekCharacter(c); }; } else { GBStream << "Error: no integer found"; GBStream << "Last character peeked:" << c << '\n'; errorh(__LINE__); }; result *= sign; return result; };
simpleString getUntilCharacterButNot(const char * avoids,int & len) { len = 0; if(!d_word) { d_word = new char[1001]; } else if(strlen(d_word)<1000) { delete d_word; d_word = new char[10001]; }; char * t = d_word; peekCharacter(*t); while(check(*t,avoids)) { passCharacter(); ++t;++len; if(len>1000) errorh(__LINE__); peekCharacter(*t); }; *t = '\0'; simpleString result(d_word); return result; };
simpleString getUntilCharacterButNot(char avoid) { int len = 0; if(!d_word) { d_word = new char[1001]; } else if(strlen(d_word)<1000) { delete d_word; d_word = new char[1001]; }; char * t = d_word; peekCharacter(*t); cout << "char:" << *t << endl; while(*t!=avoid) { cout << "char:" << *t << endl; passCharacter(); ++t;++len; if(len>1000) errorh(__LINE__); peekCharacter(*t,"\n\t "); }; *t = '\0'; simpleString result(d_word); return result; };
GraphVertex() { errorh(__LINE__);};
inline const Match & MatcherMonomial::matchIs() { if(_theMatch==0) errorh(__LINE__); return * _theMatch; };
/** * Connect function, Windows Sockets * TODO: move to separate class/file * and maybe switch to HTTP/1.1 */ void connectFunction(HWND hWnd) { //SOCKET_READ_BUFFER_SIZE is 1048576 (1MB) struct sockaddr_in dest_addr, my_addr; struct hostent *hostInfo; char* hWndTxbAddressTxt = (char*)malloc(sizeof(char)*100); char* hWndTxbPortTxt = (char*)malloc(sizeof(char)*6); char* tmpCharPtr = (char*)malloc(sizeof(char)*SOCKET_READ_BUFFER_SIZE); SOCKET sock = socket(AF_INET, SOCK_STREAM, 0); memset(hWndTxbAddressTxt, '\0', 100); memset(hWndTxbPortTxt, '\0', 6); memset(tmpCharPtr, '\0', SOCKET_READ_BUFFER_SIZE); SendMessage(GetDlgItem(hWnd, ID_EDIT_ADDRESS), WM_GETTEXT, 100, (LPARAM) hWndTxbAddressTxt); //fun part! SOCKETS & ADDRESSES! //TODO: make it check the address vadility first! hostInfo = gethostbyname(hWndTxbAddressTxt); //TODO: change to prioritise the 171.x.x.x net my_addr.sin_addr.s_addr = INADDR_ANY; my_addr.sin_family = AF_INET; my_addr.sin_port = htons(0); memset(&(my_addr.sin_zero), '\0', sizeof(my_addr.sin_zero)); dest_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)hostInfo->h_addr_list[0]))); dest_addr.sin_family = AF_INET; //read port number SendMessage(GetDlgItem(hWnd, ID_EDIT_PORT), WM_GETTEXT, 6, (LPARAM) hWndTxbPortTxt); //set port number dest_addr.sin_port = htons(atoi(hWndTxbPortTxt)); memset(&(dest_addr.sin_zero), '\0', sizeof(dest_addr.sin_zero)); sprintf(tmpCharPtr, "Connecting to %s on port %s", hWndTxbAddressTxt, hWndTxbPortTxt); SendMessage(GetDlgItem(hWnd, ID_EDIT_INFO), WM_SETTEXT, 0, (LPARAM) tmpCharPtr); //lets try this shit now! if (connect(sock, (struct sockaddr *) &dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) { sprintf(tmpCharPtr, "Ragnarok sized error!\r\nFailed to connect to %s on port %s.\r\n%s.", hWndTxbAddressTxt, hWndTxbPortTxt, errorh()); SendMessage(GetDlgItem(hWnd, ID_EDIT_INFO), WM_SETTEXT, 0, (LPARAM) tmpCharPtr); free(hWndTxbAddressTxt); free(hWndTxbPortTxt); free(tmpCharPtr); return; } else { sprintf(tmpCharPtr, "Connected to %s on port %s", hWndTxbAddressTxt, hWndTxbPortTxt); SendMessage(GetDlgItem(hWnd, ID_EDIT_INFO), WM_SETTEXT, 0, (LPARAM) tmpCharPtr); } memset(tmpCharPtr, '\0', SOCKET_READ_BUFFER_SIZE); char* requestString = (char*)malloc(sizeof(char)*200); memset(requestString, '\0', 200); LRESULT selectedFunction = SendMessage(GetDlgItem(hWnd, ID_CBFUNCTIONS), CB_GETCURSEL, 0, 0); //set hostname to vapix object too //TODO: this should be done elswhere alot earlier vapix->setHostname(hWndTxbAddressTxt); vapix->setPort(selectedFunction, atoi(hWndTxbPortTxt)); // TODO: requestString = make it take the EditBox string and remove the http://address[:port] requestString = vapix->getFunctionCode(selectedFunction); sprintf(tmpCharPtr, "GET /%s HTTP/1.0\r\nHost: %s\r\nContent-type: charset=ISO-8859-1\r\rConnection: Close\r\n\r\n", requestString, hWndTxbAddressTxt); send(sock, tmpCharPtr, (int)strlen(tmpCharPtr), 0); //clear buffer for receiving memset(tmpCharPtr, '\0', SOCKET_READ_BUFFER_SIZE); //cool! now lets see what we got recv(sock, tmpCharPtr, SOCKET_READ_BUFFER_SIZE, 0); //tmpCharPtr = makeStringWinCompatible(tmpCharPtr); //fill the edit box with the results SendMessage(GetDlgItem(hWnd, ID_EDIT_INFO), WM_SETTEXT, 0, (LPARAM)tmpCharPtr); //that's it folks if (sock != NULL) { shutdown(sock, 0); closesocket(sock); } free(hWndTxbAddressTxt); free(hWndTxbPortTxt); free(tmpCharPtr); free(requestString); }
void unGetCharacter(char c) { if(d_useUnget) errorh(__LINE__); if(d_unget!=c) errorh(__LINE__); d_useUnget = true; };
void passCharacter() { if(!d_useUnget) errorh(__LINE__); d_useUnget = false; //GBStream << "passing " << d_unget << '\n'; };
int number() const { if(!d_valid) errorh(__LINE__); return d_num;}
void spolynomial(Polynomial & x) const { if(d_computed) errorh(__LINE__); prspolynomial(x); };
void shouldBeEnd() { if(d_count!=0) errorh(__LINE__); if(!eoi()) errorh(__LINE__); if(d_should_extra) vShouldBeEnd(); };
bool valid() const { if(!d_valid) errorh(__LINE__); return d_data().d_valid;}
void operator=(const ByAdmissible &) const { errorh(__LINE__);};
void setNotEndOfInput() { if(!d_eoi) { errorh(__LINE__); }; d_eoi = false; };