void refactorString(struct bucketString *pStr) { struct bucket *pResult; struct bucket *pBkt; int i, j; /* Exit if string is empty, or only one bucket exists */ if (pStr == NULL) return; if (pStr->pBkt == NULL) { pStr->pLast = NULL; return; } if (pStr->pBkt->pNext == NULL) { if (isBucketNonEmpty(pStr->pBkt)==0) { /* Dump bucket */ clearString(pStr); return; } else { /* Already have only one valid bucket */ pStr->pLast = pStr->pBkt; return; } } /* Attempt to create new bucket */ pResult = newBucket(getStringLen(pStr)); if (pResult == NULL) { /* Failed to create bucket. Clear string (probably empty) */ clearString(pStr); return; } /* Copy over data from existing buckets */ i = 0; for (pBkt = pStr->pBkt; pBkt != NULL; pBkt = pBkt->pNext) { /* Skip empty buckets */ if (isBucketNonEmpty(pBkt) == 0) continue; /* Copy buffers. i accumulates continuously */ for (j = 0; j < pBkt->size; i++, j++) { pResult->pBuf[i] = pBkt->pBuf[j]; } } /* Remove old buckets and reassign to new bucket */ clearString(pStr); pStr->pBkt = pResult; pStr->pLast = pResult; }
void freeString(struct bucketString **ppStr) { if (ppStr == NULL) return; if (*ppStr == NULL) return; clearString(*ppStr); free(*ppStr); *ppStr = NULL; }
void DotWriter::doIO() { string edgeDeclerationPart = edgesToDot(); string nodeDeclerationPart = nodesToDot(); // open a filestream fstream fileStream(_fileName.c_str(), ios::out); string resultString = "digraph " + clearString(_graphPointer->getName()) + "{"; resultString += nodeDeclerationPart; resultString += edgeDeclerationPart; resultString += "\n}"; fileStream << resultString; fileStream.close(); }
// Devuelve un string con los argumentos separados por espacio char* getSpaceSeparatedString( char* script ){ // Creo e inicializo lo q sera el nuevo string char* result = malloc(1*sizeof(char)); clearString(result, 1); char* resultAux; // variable auxiliar int i = 0; for( i=0; i<strlen(script); i++){ char* subs; if( isNumericFormat(script[i]) == 0 ){ // si no es formato numerico -> un espacio antes y otro despues subs = malloc( 4 * sizeof(char) ); subs[0] = ' '; subs[1] = script[i]; subs[2] = ' '; subs[3] = '\0'; } else { subs = malloc( 2 * sizeof(char) ); subs[0] = script[i]; subs[1] = '\0'; } // genero la nueva cadena, para concatenar int l = strlen(result) + strlen(subs); resultAux = malloc( (l+1)*sizeof(char) ); clearString(resultAux, l+1); // concateno el result actual con el substring strcat(resultAux, result); strcat(resultAux, subs); free(result); // libero el viejo result free(subs); // libero el substring result = resultAux; //cambio la referencia } return result; }
//Parses the parameters out of the input buffer into the par variable //Copies the characters between : and ( if found. void getPar(unsigned char* buff, char* par){ int i = 0; // WHY DID I FORGET TO INITIALIZE IT TO 0?????? int found = 0; clearString(par); while(buff[i] != 0) { if(buff[i] == '(') found = ++i; if(found){ if(buff[i] == ')') break; par[i-found] = buff[i]; } i++; } return; }
//Parses the command out of the input buffer into the cmd variable //Copies the characters between : and ( if found. void getCmd(unsigned char* buff, char* cmd){ int i=0; // WHY DID I FORGET TO INITIALIZE IT TO 0?????? int found = 0; clearString(cmd); while(buff[i] != 0) { if(buff[i] == ':') found = ++i; if(found){ if(buff[i] == '(') break; cmd[i-found] = buff[i]; } i++; } return; }
//Initialize void init(){ //Clear buffer unsigned char inBuff[BUFFER_MAX]; int fd = openSerial(); int receivedBytes; while( (receivedBytes = read(fd,inBuff,BUFFER_MAX)) ){ if(receivedBytes && DEBUG) printf("Emptied buffer of %d bytes\n",receivedBytes); } clearString((char*)inBuff); usleep(100000); //Send wake up command to Arduino char buffHost[8] = ":wakeup:"; int sentBytes = write(fd,buffHost,sizeof(buffHost)); if(DEBUG) printf("%d bytes sent\n",sentBytes); usleep(100000); close(fd); }
Intervall parse(string input){ Intervall result = Intervall(NAN); //string term((inputIntervall->text()).toStdString()); string term=clearString(input);//Leerzeichen in term löschen if(term!=""){ if(validChars(term)==false){//Überprüfung, ob term ungültige Zeichen enthält errorWindow("Nonvalid character!"); return Intervall(NAN); }else if(brackets(term)==false){//Überprüfung, ob die Anzahl von "(" mit ")" in term übereinstimmt errorWindow("Can't match delimiters!"); return Intervall(NAN); }else if(intervalBrackets(term)==false){//Überprüfung, ob die Anzahl von "[" mit "]" in term übereinstimmt errorWindow("Can't match interval delimiters!"); return Intervall(NAN); }else { result=parseTermOfIntervals(term);//term parsen -> result } } return result; }
//Parse the parameters into the PARAMETERS array //Parameters must be divided by commas int parseParameters(char* par){ int i = 0; int number = 0; int pos = 0; int p; //Clear all parameters for(p=0;p<PARS;p++){ clearString(PARAMETERS[p]); } //Extract parameters into the PARAMETERS array while(par[i]!=0){ if(par[i] == ','){ number++; pos = i+1; // add one to ignore the ',' }else{ PARAMETERS[number][i-pos]=par[i]; } i++; } return number+1; // Number of parameters found }
QString InputMask::maskString( uint pos, const QString &str, bool clear ) const { if ( pos >= ( uint ) m_maxLength ) return QString::fromLatin1( "" ); QString fill; fill = clear ? clearString( 0, m_maxLength ) : m_text; uint strIndex = 0; QString s = QString::fromLatin1( "" ); int i = pos; while ( i < m_maxLength ) { if ( strIndex < str.length() ) { if ( m_maskData[ i ].separator ) { s += m_maskData[ i ].maskChar; if ( str[ ( int ) strIndex ] == m_maskData[ i ].maskChar ) strIndex++; ++i; } else { if ( isValidInput( str[ ( int ) strIndex ], m_maskData[ i ].maskChar ) ) { switch ( m_maskData[ i ].caseMode ) { case MaskInputData::Upper: s += str[ ( int ) strIndex ].upper(); break; case MaskInputData::Lower: s += str[ ( int ) strIndex ].lower(); break; default: s += str[ ( int ) strIndex ]; } ++i; } else { // search for separator first int n = findInMask( i, TRUE, TRUE, str[ ( int ) strIndex ] ); if ( n != -1 ) { if ( str.length() != 1 || i == 0 || ( i > 0 && ( !m_maskData[ i - 1 ].separator || m_maskData[ i - 1 ].maskChar != str[ ( int ) strIndex ] ) ) ) { s += fill.mid( i, n - i + 1 ); i = n + 1; // update i to find + 1 } } else { // search for valid m_blank if not n = findInMask( i, TRUE, FALSE, str[ ( int ) strIndex ] ); if ( n != -1 ) { s += fill.mid( i, n - i ); switch ( m_maskData[ n ].caseMode ) { case MaskInputData::Upper: s += str[ ( int ) strIndex ].upper(); break; case MaskInputData::Lower: s += str[ ( int ) strIndex ].lower(); break; default: s += str[ ( int ) strIndex ]; } i = n + 1; // updates i to find + 1 } } } strIndex++; } } else break; } return s; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { settingsOpen = false; onSave = 0; QDir home(QDir::homePath()+"/parserYandex/"); QDir homeSaved(QDir::homePath()+"/parserYandex/saved/"); if (!home.exists()) home.mkpath(QDir::homePath()+"/parserYandex/"); if (!homeSaved.exists()) home.mkpath(QDir::homePath()+"/parserYandex/saved"); path = QDir::homePath()+"/parserYandex/saved/"; ui->setupUi(this); ui->settingsButton->setIcon(QIcon(":/icons/settings.png")); ui->settingsButton->setFixedSize(24,24); ui->settingsButton->setStyleSheet( "QPushButton {" "image: url(:/icons/settings.png); " "border: none;" "}" "QPushButton:hover {" "image: url(:/icons/settings_pressed.png);" "}" "QPushButton:pressed {" "image: url(:/icons/settings_pressed.png);" "}" "QPushButton:focus {" "border: none;" "}" ); ui->enterButton->setIcon(QIcon(":/icons/clear.png")); ui->enterButton->setFixedSize(20,20); ui->enterButton->setStyleSheet( "QPushButton {" "image: url(:/icons/clear.png); " "border: none;" "}" "QPushButton:hover {" "image: url(:/icons/clear_pressed.png);" "}" "QPushButton:pressed {" "image: url(:/icons/clear.png);" "}" "QPushButton:focus {" "border: none;" "}" ); this->resize(QSize(630,166)); ui->yandexBox->setChecked(true); ui->progressBar->hide(); ui->autoCompletion->hide(); ui->autoCompletion->setResizeMode(QListView::Adjust); ui->settings->hide(); ui->settings_arrow->hide(); ui->resultTable->hide(); ui->label->setText(QString("История пуста. Начни менять историю прямо сейчас.")); ui->newWindow->setShortcut(Qt::Key_Control+Qt::Key_N); ui->newWindow->setEnabled(true); ui->exit->setShortcuts(QKeySequence::Quit); manager = new QNetworkAccessManager(this); connect(ui->exit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); connect(ui->newWindow, SIGNAL(triggered()), this, SLOT(newWindow())); connect(ui->searchString, SIGNAL(returnPressed()), this, SLOT(sendString())); connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); connect(ui->enterButton, SIGNAL(clicked()), this, SLOT(clearString())); connect(ui->about, SIGNAL(triggered()), this, SLOT(showAuthor())); connect(ui->help, SIGNAL(triggered()), this, SLOT(showHowToUse())); connect(ui->searchString, SIGNAL(textEdited(QString)), this, SLOT(getAutoComplition(QString))); initTest(); }
int main(void) { SYSTEMConfigPerformance(10000000); enableInterrupts(); initTimerDebounce(); initTimerDelay(); initLCD(); initKeypad(); int runQATests = NTEST; //test keypad software functions if TEST, don't if NTEST if(runQATests == TEST) { test_clearString(); delayUs(2000000); clearLCD(); test_checkPass(); delayUs(2000000); clearLCD(); test_updatePass(); return -1; } char key = NULL; char passStringa[5] = ""; char passStringb[5] = ""; char passStringc[5] = ""; char passStringd[5] = ""; int PassCount = 0; int correct = NOTMATCH; char tempPass[5] = ""; char guessString[5] = ""; moveCursorLCD(0,0); while(1) { switch(state) { case enter: if(mode != ENTER || prevState != enter) { clearLCD(); printStringLCD("Enter"); moveCursorLCD(1,0); mode = ENTER; } prevState = enter; break; case debounce: break; case update: if(row != -1) { key = scanKeypad(row); } else { break; } if(key != -1) { printCharLCD(key); if(mode == ENTER) { guessString[keyPresses] = key;//append key to guessString state = enter; } else if(mode == SET) { tempPass[keyPresses] = key;//append key to passString state = set_mode; } keyPresses = keyPresses + 1; if(mode == ENTER) { correct = NOTMATCH; correct = checkPass(guessString, passStringa, passStringb, passStringc, passStringd); if(keyPresses == 4 && (correct == NOTMATCH)) { state = bad; } else if(key == '#') { state = bad; } else if((keyPresses > 1) && (keyPresses < 4) && (key == '*') && (strcmp(guessString, "**")!=0)) { state = bad; } else if((keyPresses==2)&&(strcmp(guessString,"**")==0)) { state = set_mode; } else if((keyPresses==2) && (key!='*')&&(guessString[0]=='*')) { state = bad; } else if((keyPresses==4)&&(correct == 0)) { state = good; } } else if((keyPresses<4)&&(mode==SET)&&(key!='#')&&(key!='*')) { state = set_mode; } else if(((key=='#')||(key=='*'))&&(mode==SET)) { state = invalid; } else if((mode==SET)&&(keyPresses==4)&&(key!='#')&&(key!='*')) { state = valid; } else if(keyPresses < 4 && mode == ENTER && key != '#') state = enter; } else { printCharLCD(' '); moveCursorLCD(1, keyPresses); if(mode == ENTER) state = enter; else if(mode == SET) state = set_mode; } key = NULL; break; case set_mode: if(mode != SET || prevState != set_mode) { clearLCD(); printStringLCD("Set Mode"); moveCursorLCD(1,0); keyPresses = 0; strcpy(guessString, ""); clearString(guessString); mode = SET; } prevState = set_mode; break; case good: clearLCD(); printStringLCD("Good"); keyPresses = 0; clearString(guessString); state = enter; prevState = good; delayUs(2000000); break; case bad: clearLCD(); printStringLCD("Bad"); keyPresses = 0; clearString(guessString); state = enter; prevState = bad; delayUs(2000000); break; case valid: clearLCD(); if(PassCount == 3) { PassCount = 0; } else PassCount = PassCount + 1; updatePass(tempPass, passStringa, passStringb, passStringc, passStringd, PassCount); printStringLCD("Valid"); keyPresses = 0; clearString(tempPass); mode = ENTER; state = enter; prevState = valid; delayUs(2000000); break; case invalid: clearLCD(); printStringLCD("Invalid"); keyPresses = 0; clearString(tempPass); mode = ENTER; state = enter; prevState = invalid; delayUs(2000000); break; } } return 0; }
int main(int argc, char *argv[]){ char line[1024] = "string"; char line2[1024] = "string"; int n = 0; /* number of calls to 'command' */ int i = 0; pid_t pid = 0; /* install SIGCHLD handler */ signal(SIGCHLD, sigchld_handler); //signal(SIGCHLD, SIG_IGN); // prehaps use this? signal(SIGINT, SIG_IGN); // ignore CTRL - C printf("Press t to test or any other key to continue...\n"); printf("$ "); if(!fgets(line, 1024, stdin)){ printf("\n"); exit(0); } while(1) { if(line[0] == 't'&& line[1] == '\n'){ //strcpy(line ,"kate & ls | grep l\n"); //check mixed commands //check_all_errorcheck(); //printf("\n"); //check_parse(); //check_run(); //printf("\n"); printf("No tests chosen in source file\n"); break; } else { clearString(line); clearString(line2); fflush(stdin); fflush(stdout); printf("$ "); if(!fgets(line, 1024, stdin)){ printf("\n"); break; } strcpy(line2, line); int c = chck_general_error(line2); if(c == -1){ perror("invalid input"); writeToLogFile(line, "invalid input", EIO); printf("\n"); continue; } } if(strcmp(EXITN,line) == 0){ break; } strcpy ( lineBCKP, line); int input = 0; int first = 1; int trailingAmp = 0; int status = 0; int delimitFlag = 0; char* cmd = line; char* next = strpbrk(cmd, DELIMITERS); /* Find first '|' or '&' */ while (next != NULL) { /* 'next' points to '|' or '&' */ if(*next == '|') delimitFlag = PIPE_NUM; if(*next == '&'){ delimitFlag = AMPERSAND_NUM; if(*(next + 1) == '\n'){ trailingAmp = 1; //printf("trailing amp\n"); } } *next = '\0'; input = run(cmd, input, first, 0, &n, delimitFlag); cmd = next + 1; next = strpbrk(cmd, DELIMITERS); /* Find next '|' or '&' */ first = 0; } if(!trailingAmp) input = run(cmd, input, first, 1, &n, NO_BLOCK_ENDING); //cleanup(n); n = 0; } }
//Send email with attachment photo taken from Webcam void *emailPhotoFunc(void *arg){ struct commandStructure *command = (commandStructure *) arg; char cmd[PARS_SIZE]; //char message[PARS_SIZE]; char emailAddress[PARS_SIZE]; char emailSubject[PARS_SIZE]; char emailMessage[PARS_SIZE]; char streamerCommand[100]; time_t now = time(NULL); int status; //Copy command info locally strcpy(cmd,(const char*) command->cmd); strcpy(emailAddress,(const char*) command->par[0]); strcpy(emailSubject,(const char*) command->par[1]); strcpy(emailMessage,(const char*) command->par[2]); if(DEBUG){ printf("============================\nIn emailPhoto thread:\n"); printf("cmd: %s\n",cmd); printf("email: %s\n",emailAddress); printf("subject: %s\n",emailSubject); printf("message: %s\n",emailMessage); printf("time: %s",ctime(&now)); } //Create streamer command to take a photo from webcam strcpy(streamerCommand, "streamer -q -w 0 -t 5 -j 85 -c /dev/video1 -s 640x480 -o ~/capture00.jpeg"); status = system(streamerCommand); if(status == -1){ printf("==Error: Could not take picture from webcam. Command %s\n",streamerCommand); pthread_exit(NULL); }else{ printf("==Picture taken successfully!\n"); } //Email command char* email[stringSize(emailAddress)+5]; char* subject[stringSize(emailSubject)+10]; clearString((char*)email); appendString((char*)email,"To: "); appendString((char*)email,emailAddress); appendString((char*)email,"\n"); clearString((char*)subject); appendString((char*)subject,"Subject: "); appendString((char*)subject,emailSubject); appendString((char*)subject,"\n"); //1. Open email file FILE* fp; fp = fopen("/home/udooer/mail.txt","w+"); //2. Write To, From, Subject and Contents fputs((char*)email,fp); fputs("From: [email protected]\n",fp); fputs((char*)subject,fp); fputs("\n",fp); fprintf(fp,"%s\n",emailMessage); fprintf(fp,"%s\n",ctime(&now)); fputs("\n",fp); fputs("Message sent by Udoo Neo.\n",fp); fputs("=========================\n",fp); fputs("\n",fp); //3. Close file fclose(fp); char mpackCommand[100]; strcpy(mpackCommand,"mpack -s \""); strcat(mpackCommand,(const char*) emailSubject); strcat(mpackCommand, "\" -d ~/mail.txt ~/capture04.jpeg "); strcat(mpackCommand, emailAddress); if(DEBUG) printf("Command to execute: %s\n",mpackCommand); status = system(mpackCommand); if(status == -1){ printf("==Error: could not send email\n"); }else{ //printf(" ============================\nIn emailPhoto thread:\n"); printf("==Email sent successfully! on %s",ctime(&now)); //printf(" ============================\n"); } //printf("%s\n",ctime(&now)); pthread_exit(NULL); }
//Email function to be called in a "detached" thread void *emailFunc(void *arg){ struct commandStructure *command = (commandStructure *) arg; char cmd[PARS_SIZE]; char emailAddress[PARS_SIZE]; char emailSubject[PARS_SIZE]; char emailMessage[PARS_SIZE]; time_t now = time(NULL); if(DEBUG){ printf("============================\nIn email thread:\n"); printf("cmd: %s\n",cmd); printf("email: %s\n",emailAddress); printf("subject: %s\n",emailSubject); printf("message: %s\n",emailMessage); printf("time: %s",ctime(&now)); } //Copy command info locally strcpy(cmd,(const char*) command->cmd); strcpy(emailAddress,(const char*) command->par[0]); strcpy(emailSubject,(const char*) command->par[1]); strcpy(emailMessage,(const char*) command->par[2]); int status; char* email[stringSize(emailAddress)+5]; char* subject[stringSize(emailSubject)+10]; clearString((char*)email); appendString((char*)email,"To: "); appendString((char*)email,emailAddress); appendString((char*)email,"\n"); clearString((char*)subject); appendString((char*)subject,"Subject: "); appendString((char*)subject,emailSubject); appendString((char*)subject,"\n"); //1. Open email file FILE* fp; fp = fopen("/home/udooer/mail.txt","w+"); //2. Write To, From, Subject and Contents fputs((char*)email,fp); fputs("From: [email protected]\n",fp); fputs((char*)subject,fp); fputs("\n",fp); fprintf(fp,"%s\n",emailMessage); fprintf(fp,"%s\n",ctime(&now)); fputs("\n",fp); fputs("Message sent by Udoo Neo.\n",fp); fputs("=========================\n",fp); fputs("\n",fp); //3. Close file fclose(fp); status = system("cat ~/mail.txt"); if(status == -1) printf("Error: could not execute command\n"); //4. send email char ssmtpCommand[40]; strcpy(ssmtpCommand, "ssmtp "); appendString((char*) ssmtpCommand, emailAddress); strcat(ssmtpCommand, " < ~/mail.txt"); printf("Command to execute: %s\n",ssmtpCommand); status = system(ssmtpCommand); if(status == -1){ printf("Error: could not send email\n"); }else{ printf("Email sent successfully! on %s\n",ctime(&now)); } pthread_exit(NULL); }
void ovenGraphScreen::drawGraph (void) { oven.calculateReflowVars (); uint16_t width = _WIDTH; uint16_t height = _HEIGHT; uint16_t x = _LEFT; uint16_t left = x; x2 = left + width; uint16_t y = _TOP; uint16_t top = y; uint16_t bottom = top + height; char st[10] = { 0 }; float currentTemp = oven.reflowVars.startTemp; fullScaleTemp = oven.reflowVars.peakTemp + 15.0f - currentTemp; //draw graph background myBui.myLCD.setColor (VGA_SILVER); myBui.myLCD.fillRect (left, top, x2, bottom); //print 0 time myBui.myLCD.setColor (VGA_WHITE); myBui.myLCD.setBackColor (VGA_BLACK); myBui.myLCD.print ("0", left + 1, bottom + 2); //print full time fullScaleTime = oven.reflowVars.totalTime; uint8_t stLen = stringUtils.itos(fullScaleTime, st); myBui.printRight (st, x2 - 1, bottom + 2, stLen); //print current temp myBui.myLCD.setColor (VGA_RED); clearString (st, 10); stLen = stringUtils.ftos(oven.temp, st, 2); myBui.myLCD.print (st, left - 2, bottom - (stLen * myBui.myLCD.getFontXsize ()), 90); /******************************************************************************/ //determine x (time) coordinate for preheat uint16_t time = oven.reflowVars.preheatTime; float percent = (float)time / (float)fullScaleTime; x = (uint16_t)((float)width * percent) + left; //print x (time) coordinate for preheat myBui.myLCD.setColor (VGA_WHITE); clearString (st, 10); stLen = stringUtils.itos(time, st); myBui.printCenter (st, x, bottom + 2, stLen); //determine y (temp) coordinate for preheat float temp = oven.reflowVars.soakTemp; percent = (temp - currentTemp) / fullScaleTemp; y = (height - (uint16_t)((float)height * percent)) + top; //print y (temp) coordinate for preheat myBui.myLCD.setColor (VGA_RED); clearString (st, 10); stLen = stringUtils.itos(temp, st); myBui.myLCD.print (st, left - 2, y, 90); //draw lines for preheat myBui.myLCD.setColor (VGA_GRAY); myBui.myLCD.drawLine (left, y, x, y); // temp line myBui.myLCD.drawLine (x, y, x, bottom); // time line myBui.myLCD.setColor (VGA_LIME); drawThickLine (left + 1, bottom - 1, x, y); // setpoint slop x2 = x; y2 = y; /******************************************************************************/ //determine x (time) coordinate for soak time = oven.reflowVars.preheatTime + oven.reflowVars.soakTime; percent = (float)time / (float)fullScaleTime; x = (uint16_t)((float)width * percent) + left; //print x (time) coordinate for soak myBui.myLCD.setColor (VGA_WHITE); clearString (st, 10); stLen = stringUtils.itos(time, st); myBui.printCenter (st, x, bottom + 2, stLen); //print y (temp) coordinate for preheat temp = oven.reflowVars.soakTemp + oven.reflowVars.soakTempIncrease; percent = (temp - currentTemp) / fullScaleTemp; y = (height - (uint16_t)((float)height * percent)) + top; //print y (temp) coordinate for preheat myBui.myLCD.setColor (VGA_RED); clearString (st, 10); stLen = stringUtils.itos(temp, st); myBui.myLCD.print (st, left - 2, y - (stLen * myBui.myLCD.getFontXsize ()), 90); //draw lines for soak myBui.myLCD.setColor (VGA_GRAY); myBui.myLCD.drawLine (left, y, x, y); // temp line myBui.myLCD.drawLine (x, y, x, bottom); // time line myBui.myLCD.setColor (VGA_LIME); drawThickLine (x2, y2, x, y); // setpoint slop x2 = x; y2 = y; /******************************************************************************/ //determine x (time) coordinate for ramp time = oven.reflowVars.preheatTime + oven.reflowVars.soakTime + oven.reflowVars.rampTime; percent = (float)time / (float)fullScaleTime; x = (uint16_t)((float)width * percent) + left; //print x (time) coordinate for ramp myBui.myLCD.setColor (VGA_WHITE); clearString (st, 10); stLen = stringUtils.itos(time, st); myBui.printCenter (st, x, bottom + 2, stLen); //determine y (temp) coordinate for ramp temp = oven.reflowVars.peakTemp; percent = (temp - currentTemp) / fullScaleTemp; y = (height - (uint16_t)((float)height * percent)) + top; //print y (temp) coordinate for ramp myBui.myLCD.setColor (VGA_RED); clearString (st, 10); stLen = stringUtils.itos(temp, st); myBui.myLCD.print (st, left - 2, y - 5, 90); //draw lines for ramp myBui.myLCD.setColor (VGA_GRAY); myBui.myLCD.drawLine (left, y, x, y); // temp line myBui.myLCD.drawLine (x, y, x, bottom); // time line myBui.myLCD.setColor (VGA_LIME); drawThickLine (x2, y2, x, y); // setpoint slop x2 = x; y2 = y; /******************************************************************************/ //determine x (time) coordinate for peak time = oven.reflowVars.preheatTime + oven.reflowVars.soakTime + oven.reflowVars.rampTime + oven.reflowVars.peakTime; percent = (float)time / (float)fullScaleTime; x = (uint16_t)((float)width * percent) + left; //print x (time) coordinate for ramp myBui.myLCD.setColor (VGA_WHITE); clearString (st, 10); stLen = stringUtils.itos(time, st); myBui.printCenter (st, x, bottom + 2, stLen); //draw lines for peak myBui.myLCD.setColor (VGA_GRAY); myBui.myLCD.drawLine (x, y, x, bottom); // time line myBui.myLCD.setColor (VGA_LIME); drawThickLine (x2, y2, x, y); // setpoint slop x2 = x; /******************************************************************************/ //determine x (time) coordinate for peak x = left + width - 1; y = top + height - 1; drawThickLine (x2, y2, x, y); // setpoint slop }
static int parseStmt(ej_t *ep, int state, int flags) { ejfunc_t func; ejfunc_t *saveFunc; ejinput_t condScript, endScript, bodyScript, incrScript; char_t *value, *identifier; int done, expectSemi, thenFlags, elseFlags, tid, cond, forFlags; int ejVarType; a_assert(ep); /* * Set these to NULL, else we try to free them if an error occurs. */ endScript.putBackToken = NULL; bodyScript.putBackToken = NULL; incrScript.putBackToken = NULL; condScript.putBackToken = NULL; expectSemi = 0; saveFunc = NULL; for (done = 0; !done; ) { tid = ejLexGetToken(ep, state); switch (tid) { default: ejLexPutbackToken(ep, TOK_EXPR, ep->token); done++; break; case TOK_ERR: state = STATE_ERR; done++; break; case TOK_EOF: state = STATE_EOF; done++; break; case TOK_NEWLINE: break; case TOK_SEMI: /* * This case is when we discover no statement and just a lone ';' */ if (state != STATE_STMT) { ejLexPutbackToken(ep, tid, ep->token); } done++; break; case TOK_ID: /* * This could either be a reference to a variable or an assignment */ identifier = NULL; setString(B_L, &identifier, ep->token); /* * Peek ahead to see if this is an assignment */ tid = ejLexGetToken(ep, state); if (tid == TOK_ASSIGNMENT) { if (parse(ep, STATE_RELEXP, flags) != STATE_RELEXP_DONE) { clearString(&identifier); goto error; } if (flags & FLAGS_EXE) { if ( state == STATE_DEC ) { ejSetLocalVar(ep->eid, identifier, ep->result); } else { ejVarType = ejGetVar(ep->eid, identifier, &value); if (ejVarType > 0) { ejSetLocalVar(ep->eid, identifier, ep->result); } else { ejSetGlobalVar(ep->eid, identifier, ep->result); } } } } else if (tid == TOK_INC_DEC ) { value = NULL; if (flags & FLAGS_EXE) { ejVarType = ejGetVar(ep->eid, identifier, &value); if (ejVarType < 0) { ejError(ep, T("Undefined variable %s\n"), identifier); goto error; } setString(B_L, &ep->result, value); if (evalExpr(ep, value, (int) *ep->token, T("1")) < 0) { state = STATE_ERR; break; } if (ejVarType > 0) { ejSetLocalVar(ep->eid, identifier, ep->result); } else { ejSetGlobalVar(ep->eid, identifier, ep->result); } } } else { /* * If we are processing a declaration, allow undefined vars */ value = NULL; if (state == STATE_DEC) { if (ejGetVar(ep->eid, identifier, &value) > 0) { ejError(ep, T("Variable already declared"), identifier); clearString(&identifier); goto error; } ejSetLocalVar(ep->eid, identifier, NULL); } else { if ( flags & FLAGS_EXE ) { if (ejGetVar(ep->eid, identifier, &value) < 0) { ejError(ep, T("Undefined variable %s\n"), identifier); clearString(&identifier); goto error; } } } setString(B_L, &ep->result, value); ejLexPutbackToken(ep, tid, ep->token); } clearString(&identifier); if (state == STATE_STMT) { expectSemi++; } done++; break; case TOK_LITERAL: /* * Set the result to the literal (number or string constant) */ setString(B_L, &ep->result, ep->token); if (state == STATE_STMT) { expectSemi++; } done++; break; case TOK_FUNCTION: /* * We must save any current ep->func value for the current stack frame */ if (ep->func) { saveFunc = ep->func; } memset(&func, 0, sizeof(ejfunc_t)); setString(B_L, &func.fname, ep->token); ep->func = &func; setString(B_L, &ep->result, T("")); if (ejLexGetToken(ep, state) != TOK_LPAREN) { freeFunc(&func); goto error; } if (parse(ep, STATE_ARG_LIST, flags) != STATE_ARG_LIST_DONE) { freeFunc(&func); ep->func = saveFunc; goto error; } /* * Evaluate the function if required */ if (flags & FLAGS_EXE && evalFunction(ep) < 0) { freeFunc(&func); ep->func = saveFunc; goto error; } freeFunc(&func); ep->func = saveFunc; if (ejLexGetToken(ep, state) != TOK_RPAREN) { goto error; } if (state == STATE_STMT) { expectSemi++; } done++; break; case TOK_IF: if (state != STATE_STMT) { goto error; } if (ejLexGetToken(ep, state) != TOK_LPAREN) { goto error; } /* * Evaluate the entire condition list "(condition)" */ if (parse(ep, STATE_COND, flags) != STATE_COND_DONE) { goto error; } if (ejLexGetToken(ep, state) != TOK_RPAREN) { goto error; } /* * This is the "then" case. We need to always parse both cases and * execute only the relevant case. */ if (*ep->result == '1') { thenFlags = flags; elseFlags = flags & ~FLAGS_EXE; } else { thenFlags = flags & ~FLAGS_EXE; elseFlags = flags; } /* * Process the "then" case. Allow for RETURN statement */ switch (parse(ep, STATE_STMT, thenFlags)) { case STATE_RET: return STATE_RET; case STATE_STMT_DONE: break; default: goto error; } /* * check to see if there is an "else" case */ ejRemoveNewlines(ep, state); tid = ejLexGetToken(ep, state); if (tid != TOK_ELSE) { ejLexPutbackToken(ep, tid, ep->token); done++; break; } /* * Process the "else" case. Allow for return. */ switch (parse(ep, STATE_STMT, elseFlags)) { case STATE_RET: return STATE_RET; case STATE_STMT_DONE: break; default: goto error; } done++; break; case TOK_FOR: /* * Format for the expression is: * * for (initial; condition; incr) { * body; * } */ if (state != STATE_STMT) { goto error; } if (ejLexGetToken(ep, state) != TOK_LPAREN) { goto error; } /* * Evaluate the for loop initialization statement */ if (parse(ep, STATE_EXPR, flags) != STATE_EXPR_DONE) { goto error; } if (ejLexGetToken(ep, state) != TOK_SEMI) { goto error; } /* * The first time through, we save the current input context just * to each step: prior to the conditional, the loop increment and the * loop body. */ ejLexSaveInputState(ep, &condScript); if (parse(ep, STATE_COND, flags) != STATE_COND_DONE) { goto error; } cond = (*ep->result != '0'); if (ejLexGetToken(ep, state) != TOK_SEMI) { goto error; } /* * Don't execute the loop increment statement or the body first time */ forFlags = flags & ~FLAGS_EXE; ejLexSaveInputState(ep, &incrScript); if (parse(ep, STATE_EXPR, forFlags) != STATE_EXPR_DONE) { goto error; } if (ejLexGetToken(ep, state) != TOK_RPAREN) { goto error; } /* * Parse the body and remember the end of the body script */ ejLexSaveInputState(ep, &bodyScript); if (parse(ep, STATE_STMT, forFlags) != STATE_STMT_DONE) { goto error; } ejLexSaveInputState(ep, &endScript); /* * Now actually do the for loop. Note loop has been rotated */ while (cond && (flags & FLAGS_EXE) ) { /* * Evaluate the body */ ejLexRestoreInputState(ep, &bodyScript); switch (parse(ep, STATE_STMT, flags)) { case STATE_RET: return STATE_RET; case STATE_STMT_DONE: break; default: goto error; } /* * Evaluate the increment script */ ejLexRestoreInputState(ep, &incrScript); if (parse(ep, STATE_EXPR, flags) != STATE_EXPR_DONE) { goto error; } /* * Evaluate the condition */ ejLexRestoreInputState(ep, &condScript); if (parse(ep, STATE_COND, flags) != STATE_COND_DONE) { goto error; } cond = (*ep->result != '0'); } ejLexRestoreInputState(ep, &endScript); done++; break; case TOK_VAR: if (parse(ep, STATE_DEC_LIST, flags) != STATE_DEC_LIST_DONE) { goto error; } done++; break; case TOK_COMMA: ejLexPutbackToken(ep, TOK_EXPR, ep->token); done++; break; case TOK_LPAREN: if (state == STATE_EXPR) { if (parse(ep, STATE_RELEXP, flags) != STATE_RELEXP_DONE) { goto error; } if (ejLexGetToken(ep, state) != TOK_RPAREN) { goto error; } return STATE_EXPR_DONE; } done++; break; case TOK_RPAREN: ejLexPutbackToken(ep, tid, ep->token); return STATE_EXPR_DONE; case TOK_LBRACE: /* * This handles any code in braces except "if () {} else {}" */ if (state != STATE_STMT) { goto error; } /* * Parse will return STATE_STMT_BLOCK_DONE when the RBRACE is seen */ do { state = parse(ep, STATE_STMT, flags); } while (state == STATE_STMT_DONE); /* * Allow return statement. */ if (state == STATE_RET) { return state; } if (ejLexGetToken(ep, state) != TOK_RBRACE) { goto error; } return STATE_STMT_DONE; case TOK_RBRACE: if (state == STATE_STMT) { ejLexPutbackToken(ep, tid, ep->token); return STATE_STMT_BLOCK_DONE; } goto error; case TOK_RETURN: if (parse(ep, STATE_RELEXP, flags) != STATE_RELEXP_DONE) { goto error; } if (flags & FLAGS_EXE) { while ( ejLexGetToken(ep, state) != TOK_EOF ); done++; return STATE_RET; } break; } } if (expectSemi) { tid = ejLexGetToken(ep, state); if (tid != TOK_SEMI && tid != TOK_NEWLINE) { goto error; } /* * Skip newline after semi-colon */ ejRemoveNewlines(ep, state); } /* * Free resources and return the correct status */ doneParse: if (tid == TOK_FOR) { ejLexFreeInputState(ep, &condScript); ejLexFreeInputState(ep, &incrScript); ejLexFreeInputState(ep, &endScript); ejLexFreeInputState(ep, &bodyScript); } if (state == STATE_STMT) { return STATE_STMT_DONE; } else if (state == STATE_DEC) { return STATE_DEC_DONE; } else if (state == STATE_EXPR) { return STATE_EXPR_DONE; } else if (state == STATE_EOF) { return state; } else { return STATE_ERR; } /* * Common error exit */ error: state = STATE_ERR; goto doneParse; }
int Funktion::parseFunction(string func){ string::iterator it; func = clearString(func); func = multiplicationSign(func); if(func=="") return 0; if(brackets(func)==false){ return 1; } if(Funktion::validChars(func)==false){ return 2; } int brackets = 0; for(int i=0;i<2;i++){ for(it=func.end();it>=func.begin();it--){ if(*it=='(') brackets--; if(*it==')') brackets++; if(*it==binaryFunction[i].at(0) && brackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+'){ Funktion a; Funktion b; if(it==func.begin()){ string funca(it+1,func.end()); int retVal = a.parseFunction(funca); if(retVal==0){ function->insert(function,i,""); function->insertTree(function->right,a.getFunction()); } return retVal; } else if(it==func.end()){ return 3; } else{ string funca(func.begin(),it); string funcb(it+1,func.end()); int retVal1 = a.parseFunction(funca); int retVal2 = b.parseFunction(funcb); if(retVal1==0 && retVal2==0){ function->insert(function,i,""); function->insertTree(function->left,a.getFunction()); function->insertTree(function->right,b.getFunction()); return 0; } if(retVal1==0) return retVal2; if(retVal2==0) return retVal1; return -1; } } } } for(int i=2;i<sizeof(binaryFunction)/sizeof(binaryFunction[0]);i++){ for(it=func.end();it>=func.begin();it--){ if(*it=='(') brackets--; if(*it==')') brackets++; if(*it==binaryFunction[i].at(0) && brackets==0){ Funktion a; Funktion b; if(it==func.begin()){ return 3; } else if(it==func.end()){ return 3; } else{ string funca(func.begin(),it); string funcb(it+1,func.end()); int retVal1 = a.parseFunction(funca); int retVal2 = b.parseFunction(funcb); if(retVal1==0 && retVal2==0){ function->insert(function,i,""); function->insertTree(function->left,a.getFunction()); function->insertTree(function->right,b.getFunction()); return 0; } if(retVal1==0) return retVal2; if(retVal2==0) return retVal1; return -1; } } } } it = func.begin(); for(int i=0;i<sizeof(unaryFunction)/sizeof(unaryFunction[0]);i++){ if(string(it,it+unaryFunction[i].length())==unaryFunction[i] && brackets==0){ Funktion a; string funca(func,unaryFunction[i].length()); int retVal = a.parseFunction(funca); if(retVal==0){ function->insert(function,i+sizeof(binaryFunction)/sizeof(binaryFunction[0]),""); function->insertTree(function->left,a.getFunction()); } return retVal; } } if(*it=='('){ Funktion a; string funca(func.begin()+1,func.end()-1); int retVal = a.parseFunction(funca); if(retVal==0) function->insertTree(function,a.getFunction()); return retVal; } if(*it=='x'){ function->insert(function,-4,"x"); return 0; } function->insert(function,-3,func); return 0; }