Esempio n. 1
0
File: lab6.cpp Progetto: ZOO-OO/IU9
	Program(std::vector<Shader> shaders) :
			object_(0) {
		if (shaders.size() == 0)
			errorHandle("No shaders for program");

		object_ = glCreateProgram();
		if (object_ == 0)
			errorHandle("glCreateProgram fail");

		for (std::size_t i = 0; i < shaders.size(); i++)
			glAttachShader(object_, shaders[i].object());
		glLinkProgram(object_);
		for (std::size_t i = 0; i < shaders.size(); i++)
			glDetachShader(object_, shaders[i].object());

		GLint status;
		glGetProgramiv(object_, GL_LINK_STATUS, &status);

		if (status == GL_FALSE) {
			std::string msg("Program linking failed ");
			GLint logLen;
			glGetProgramiv(object_, GL_INFO_LOG_LENGTH, &logLen);
			auto logStr = new char[logLen + 1];
			glGetProgramInfoLog(object_, logLen, NULL, logStr);
			msg += logStr;
			delete logStr;
			glDeleteShader(object_);
			object_ = 0;
			errorHandle(msg);
		}
	}
Esempio n. 2
0
void testAppend(){
	
	OsFile id;/* I don't like the implementation since OSFile need to create by myself*/
	int Readonly;

	int i,nPages;
	double time;
	
	char * buf=sqlite3Malloc(config.pagesize);
	rc = sqlite3OsOpenReadWrite( config.datfile, &id, &Readonly);
	errorHandle(rc, "can't open the file");

	for(nPages=1; nPages<=config.pagenum; nPages++){
		
		printf("append %d pages!\n",nPages);
		
		
		start_timer();
		for(i=0;i<nPages;i++){
			sqlite3Randomness(config.pagesize, buf);
			rc = sqlite3OsWrite(&id, buf, config.pagesize);
			errorHandle(rc, "write error");
		}
		time = get_timer();
		pr_times(config.recordfile, time);
				

	}
	rc= sqlite3OsClose(&id);
	errorHandle(rc, "can't close the file");

    //TODO can't find the defintion, do it later
    //sqlite3Free((void *)buf);
}
Esempio n. 3
0
File: lab6.cpp Progetto: ZOO-OO/IU9
	Shader(const std::string &shaderCode, GLenum type) :
			object_(0) {
		object_ = glCreateShader(type);

		if (object_ == 0)
			errorHandle("glCreateShader fail");

		auto code = shaderCode.c_str();
		glShaderSource(object_, 1, &code, NULL);

		glCompileShader(object_);
		GLint status;
		glGetShaderiv(object_, GL_COMPILE_STATUS, &status);

		if (status == GL_FALSE) {
			std::string msg("Shader compile failure:\n");
			GLint logLen;
			glGetShaderiv(object_, GL_INFO_LOG_LENGTH, &logLen);
			auto logStr = new char[logLen + 1];
			glGetShaderInfoLog(object_, logLen, NULL, logStr);
			msg += logStr;
			delete logStr;
			glDeleteShader(object_);
			object_ = 0;
			errorHandle(msg);
		}
	}
void MainWindow::on_addCompDone_clicked()
{
    Controller cont;
    bool check = true;
    QMessageBox warning;
    QVector<Computers> list;
    QString name;
    QString created = "No";
    QString creationYear = "Never";
    QString type;
    QString description;


    if(ui->inCompName->text() == ""){
        check = false;
        errorHandle(0);
    }
    else if(ui->inCompYear->text() == ""){
        check = false;
        errorHandle(4);
    }
    else if(ui->inCompType->text() == ""){
        check = false;
        errorHandle(3);
    }
    else if(ui->inCompDesc->toPlainText() == ""){
        check = false;
        errorHandle(1);
    }
    if(check){
        name = ui->inCompName->text();
        if(ui->inCompCreated->isChecked()){
            created = "Yes";
            creationYear = ui->inCompYear->text();
        }
        type = ui->inCompType->text();
        description = ui->inCompDesc->toPlainText();
        cont.add(name, created, creationYear, type, description, false);
        list = cont.getComputers("");
        displayAllComputers(list);
        ui->inCompDesc->clear();
        ui->inCompName->clear();
        ui->inCompType->clear();
        ui->inCompYear->setValue(0);
        ui->inCompCreated->setChecked(false);
    }

    return;
}
// Let the user change the thread message if desired
void promptForNewMessage(char* msg)
{
    printf("Would you like to change the thread message? (y/N) ");
    fgets(msg, MSG_SIZE, stdin);
    
    switch(*msg)
    {
        case 'y':
        case 'Y':
            // get new number of threads
            printf("Please enter a new message:\n    ");
            if(fgets(msg, MSG_SIZE, stdin) == NULL)
                errorHandle("No new message was entered.\n");
            
            // remove extra newline
            char* last = strrchr(msg, '\n');
            *last = '\0';
            return;
        default:
            break;
    }

    // default return value
    strcpy(msg, "Hello from this thread.");
}
void MainWindow::on_addSciDone_clicked()
{
    Controller cont;
    bool check = true;
    QMessageBox box;
    QVector<Scientist> list;
    QString name;
    QString gender = "Male";
    QString birth;
    QString death = "Alive";
    QString desc;

    if(ui->inSciName->text() == ""){
        errorHandle(0);
        check = false;
    }
    else if(ui->inSciBirth->date() > ui->inSciDeath->date() && !ui->inSciAlive->isChecked()){
        errorHandle(2);
        check = false;
    }
    else if(ui->inSciDesc->toPlainText() == ""){
        errorHandle(1);
        check = false;
    }
    if(check){
        name = ui->inSciName->text();
        if(ui->inSciFemale->isChecked()){
            gender = "Female";
        }
        birth = ui->inSciBirth->date().toString("yyyy-MM-dd");
        if(!ui->inSciAlive->isChecked()){
            death = ui->inSciDeath->date().toString("yyyy-MM-dd");
        }
        desc = ui->inSciDesc->toPlainText();

        cont.add(name, gender, birth, death, desc, true);
        list = cont.getScientists("");
        displayAllScientists(list);
        ui->inSciName->clear();
        ui->inSciAlive->setChecked(true);
        ui->inSciDesc->clear();

    }

    return;
}
Esempio n. 7
0
int main(int argc,char* argv[]){
	FILE* fm;
	if(1==argc){
		if((fm=fopen(FMAKEFILE,"r"))==NULL)
			errorHandle(NO_FMAKEFILE);
	}else if((fm=fopen(argv[1],"r"))==NULL){
		errorHandle(OPEN_FAILED);
	}

	parse(fm);

	build();

	fclose(fm);
	releaseParseResource();
	releaseBuildResource();
	return 0;
}
Esempio n. 8
0
File: lab6.cpp Progetto: ZOO-OO/IU9
	static Shader shaderFromFile(const std::string &file, GLenum type) {
		std::ifstream f;
		f.open(file.c_str(), std::ios::in | std::ios::binary);
		if (!f.is_open())
			errorHandle(std::string("Failed to open ") + file);
		std::stringstream buf;
		buf << f.rdbuf();
		return Shader(buf.str(), type);
	}
Esempio n. 9
0
File: lab6.cpp Progetto: ZOO-OO/IU9
	void load(std::string name) {
		unsigned char header[54];
		unsigned int dataPos;
		unsigned int imageSize;
		unsigned char *data;

		FILE *file = fopen(name.c_str(), "rb");
		if (!file) {
			errorHandle("No such file " + name);
			return;
		}
		if (fread(header, 1, 54, file) != 54) {
			errorHandle("File too short " + name);
			return;
		}
		if (header[0] != 'B' || header[1] != 'M') {
			errorHandle("Not bmp2 " + name);
			return;
		}
		if (*(int*) &(header[0x1E]) != 0) {
			errorHandle("Not bmp3 " + name);
			return;
		}
		if (*(int*) &(header[0x1C]) != 24) {
			errorHandle("Not bmp4 " + name);
			return;
		}

		dataPos = *(int*) &(header[0x0A]);
		imageSize = *(int*) &(header[0x22]);
		width_ = *(int*) &(header[0x12]);
		height_ = *(int*) &(header[0x16]);

		if (imageSize == 0)
			imageSize = width_ * height_ * 3;
		if (dataPos == 0)
			dataPos = 54;

		data = new unsigned char[imageSize];
		fread(data, 1, imageSize, file);
		fclose(file);
		data_ = data;
	}
void MainWindow::on_listOfSci_cellChanged(int row, int column)
{
    Controller cont;
    if(canEdit){
        bool check = true;
        bool alive = false;
        QString death = ui->listOfSci->item(row,4)->text();
        QDate currB = QDate::fromString(ui->listOfSci->item(row, 3)->text(), "yyyy-MM-dd");
        QDate currD = QDate::fromString(death, "yyyy-MM-dd");
        if(death == "Alive"){
            alive = true;
        }
        if(column == 1 && ui->listOfSci->item(row, column)->text() == ""){
            errorHandle(0);
            check = false;
        }
        else if(column == 4 && !currD.isValid() && death != "Alive"){
            errorHandle(6);
            check = false;
        }
        else if(((column == 3 && (currB > currD)) || (column == 4 && (currB > currD))) && (currB.isValid() && currD.isValid()) && !alive){
            errorHandle(2);
            check = false;
        }
        else if(((!currB.isValid() || !currD.isValid()) && !alive) || (death != "Alive" && !currD.isValid()) || (!currB.isValid() && alive)){
            errorHandle(5);
            check = false;
        }
        else if(column == 5 && ui->listOfSci->item(row, column)->text() == ""){
            errorHandle(1);
            check = false;
        }
        if(check){
            QString id = ui->listOfSci->item(row, 0)->text();
            QString newThing = ui->listOfSci->item(row, column)->text();
            cont.edit(id, newThing, column, true);
        }
    }

    return;
}
Esempio n. 11
0
void MWiFi::errorRoutine()
{
      if (errorHandle!=NULL){errorHandle(ERRORTYPE);return;}
      if (ERRLOG) 
      {
        char pbuff[20];
        if (ERRORTYPE>72) snprintf(pbuff,20,"WFWrn: %2d ",ERRORTYPE);
        else snprintf(pbuff,20,"WFErr: %2d ",ERRORTYPE);
        Serial.println(pbuff);
      }
      if (ERRORTYPE<73){wdt_enable(WDTO_15MS);delay(20);}
}
Esempio n. 12
0
static void splitLineAndStoreTokens(char* line){
	line[strlen(line)-1]='\0';
	char keyWord=line[0];
	if('E'==keyWord){
		if(ENAME==NULL){
			int pointerMoveStep=1;
			while(isspace(line[++pointerMoveStep]));
			ENAME=(char*)malloc(strlen(line));
			strcpy(ENAME,line+pointerMoveStep*sizeof(char));
			return;
		}else
			errorHandle(REDEFINE_ENAME);
	}else if('F'==keyWord){
		if(FLAGS==NULL){
			FLAGS=(char*)malloc(strlen(line));
			strcpy(FLAGS,line+1*sizeof(char));
		}else{
			FLAGS=(char*)realloc(FLAGS,strlen(line)+strlen(FLAGS));
			strcat(FLAGS,line+1*sizeof(char));
		}
		return;
	}else if('L'==keyWord){
		if(LIBS==NULL){
			LIBS=(char*)malloc(strlen(line));
			strcpy(LIBS,line+1*sizeof(char));
		}else{
			LIBS=(char*)realloc(LIBS,strlen(line)+strlen(LIBS));
			strcat(LIBS,line+1*sizeof(char));
		}
		return;
	}else if('C'==keyWord||'H'==keyWord){
		char tempFileName[NAME_MAX];
		int pointerMoveStep=1;
		while(isspace(line[++pointerMoveStep]));
		int i,j;
		for(i=pointerMoveStep,j=0;line[i]!='\0';){
			tempFileName[j++]=line[i++];
			if(isspace(line[i])||line[i]=='\0'){
				tempFileName[j]='\0';
				if('C'==keyWord)
					addToCOList(tempFileName);
				else
					addToHList(tempFileName);
                
				j=0;
				while(isspace(line[++i]));
			}
		}
		return;
	}
    
}
// Create all threads and catch errors
void createThreads(ThreadData* td, int numberOfThreads)
{
    char tMsg[MSG_SIZE];

    promptForNewMessage(tMsg);
    
    for(int8 i = 0; i < numberOfThreads; ++i)
    {
        td[i].id = i+1;
        strcpy(td[i].message, tMsg);
        if(pthread_create(&td[i].tid, NULL, threadFunction, &td[i]))
            errorHandle("Error creating thread");
    }
}
Esempio n. 14
0
void parse(FILE* fm){
	int lineCount=0;
	char line[MAXLINE];
	while(fgets(line,MAXLINE,fm)){
		lineCount++;
        
		if(isEmpty(line))
			continue;
        
		checkFormat(line,lineCount);
        
		splitLineAndStoreTokens(line);
	}
	if(NULL==ENAME)
		errorHandle(NO_ELINE);
	showParseResult();
}
Esempio n. 15
0
void TcpConnection::readHandle()
{
//	socketAct::read(channelPtr_->fd(), (void *)inputBuffer, MAXSIZE); // just to test
	loop_->assertInLoopThread();
	ssize_t n = inputBuffer.readFd(channelPtr_->fd());
	if(n > 0)
	{
		messageCb_(shared_from_this(), &inputBuffer);
	}
	else if(n == 0)
	{
		printf("read size is   %s  %s\n", __FUNCTION__, __FILE__);
		closeHanle();
	}
	else
	{
		printf("read error is   %s  %s\n", __FUNCTION__, __FILE__);
		errorHandle();
	}
}
Esempio n. 16
0
 T& get(const std::string& path = "default")
 {
     //if we have a valid path check current resources and return if found
     if (!path.empty())
     {
         auto r = m_resources.find(path);
         if (r != m_resources.end())
         {
             return *r->second;
         }
     }
     //else attempt to load from file
     std::unique_ptr<T> r = std::unique_ptr<T>(new T());
     if (path.empty() || !r->loadFromFile(path))
     {
         m_resources[path] = errorHandle(); //error handle should return message endl
     }
     else
     {
         m_resources[path] = std::move(r);
     }
     //TODO - we could check for map size here and flush if over certain size
     return *m_resources[path];
 }
Esempio n. 17
0
        /*!
        \brief Attempts to load a resource from disk at the given path

        If the resource is not found or fails to load the resource manager
        supplies a fallback resource, as defined by the concrete implementation
        of the resource manager.
        \see errorHandle
        */
        T& get(const std::string& path = "default")
        {
            //if we have a valid path check current resources and return if found
            if (!path.empty())
            {
                auto r = m_resources.find(path);
                if (r != m_resources.end())
                {
                    return *r->second;
                }
            }
            //else attempt to load from file
            std::unique_ptr<T> r = std::make_unique<T>();
            if (path.empty() || !r->loadFromFile(path))
            {
                m_resources[path] = errorHandle();
            }
            else
            {
                m_resources[path] = std::move(r);
            }

            return *m_resources[path];
        }
// Collect finished threads and catch errors
void joinThreads(ThreadData* td, int numberOfThreads)
{
    for(int8 j = 0; j < numberOfThreads; ++j)
        if(pthread_join(td[j].tid, NULL))
            errorHandle("Error joining thread");
}
void MainWindow::on_listOfComps_cellChanged(int row, int column)
{
    Controller cont;
    if(canEdit){
        QRegExp isDigit("^[0-9]+$");
        bool check = true;
        bool popupCheck = true;
        QString createdS = ui->listOfComps->item(row, 2)->text();
        QString newThing = ui->listOfComps->item(row, column)->text();
        if(column == 1 && ui->listOfComps->item(row, column)->text() == ""){
            errorHandle(0);
            check = false;
        }
        else if(column == 3 && !isDigit.exactMatch(newThing) && newThing != "Never"){
            errorHandle(4);
            check = false;
        }
        else if(column == 4 && ui->listOfComps->item(row, column)->text() == ""){
            errorHandle(3);
            check = false;
        }
        else if(column == 5 && ui->listOfComps->item(row, column)->text() == ""){
            errorHandle(1);
            check = false;
        }
        if(check){

            QString id = ui->listOfComps->item(row, 0)->text();

            if(column == 2 && createdS == "No"){
                ui->listOfComps->item(row, 3)->setText("Never");
                cont.edit(id, "Never", 3, false);
            }
            else if(column == 2 && createdS == "Yes"){
                QString newnum;
                if(!isDigit.exactMatch(ui->listOfComps->item(row,3)->text()))
                    newnum = getNumDialog();
                    if(newnum != ""){
                        ui->listOfComps->item(row, 3)->setText(newnum);
                        cont.edit(id, newnum, 3, false);
                    }
                    else{
                        popupCheck = false;
                        ui->listOfComps->item(row, column)->setText("No");
                        cont.edit(id, "No", 2, false);
                    }
            }
            else if(column == 3 && isDigit.exactMatch(newThing)){
                ui->listOfComps->item(row, 2)->setText("Yes");
                cont.edit(id, "Yes", column, false);
            }
            else if(column == 3 && newThing == "Never"){
                ui->listOfComps->item(row, 2)->setText("No");
                cont.edit(id, "No", 2, false);
            }
            if(popupCheck){
                cont.edit(id, newThing, column, false);
            }
        }
    }

    return;
}
Esempio n. 20
0
int main(int argc, char* argv[])
{
    char first_name[MAX_NAME_LEN], last_name[MAX_NAME_LEN];
    char credit_str[MAX_NAME_LEN], amount_int_str[STR_LEN], temp[STR_LEN];
    unsigned int month, year, secure_code, zip;
    unsigned int amount_int, amount_frac;
    unsigned int ret;
    char local_name[MAX_NAME_LEN+1], domain_name[MAX_DOMAIN_LEN+1];

    if (argc != 1 )
    {
        printf("Usage: sainting\n");
        return -1;
    }


    //input first name
    do
    {
        memset(first_name, 0, MAX_NAME_LEN);
        printf("Please input your first name [continue letters, space is not supported, no more than 63], press ENTER when done:\n");
        ret = getCString(first_name, MAX_NAME_LEN);
        if (ret)
        {
            errorHandle(ret);
            //return -2;
        }
    }while(ret);
    //transfer string format
    transString(first_name); 

    //input last name
    do
    {
        memset(last_name, 0, MAX_NAME_LEN);
        printf("Please input your last name [continue letters, space is not supported, no more than 63], press ENTER when done:\n");
        ret = getCString(last_name, MAX_NAME_LEN);
        if (ret)
        {
            errorHandle(ret);
            //return -3;
        }
    }while(ret); 
    //transfer string format
    transString(last_name);

    //input credit card number
    do
    {
        memset(credit_str, 0, MAX_NAME_LEN);
        printf("Please input creadit card number (16 digits), press ENTER when done:\n");    
        ret = getNString(credit_str, CREDIT_CARD_LEN+1);
        if (ret)
        {
            errorHandle(ret);
            //return -4;
        }
    }while(ret);
 

    //input month
    do
    {
        month = 0;
        memset(temp, 0, STR_LEN);
        printf("Please input expiration month xx (2 digits 01~12), press ENTER when done:\n");
        ret = getNString(temp, MONTH_LEN+1);
        if (!ret)
        {
            month = atoi(temp);
            if ( (month>=1) && (month<=12) )
            {
                //do nothing
            }   
            else
            {
                ret = ERR_OUT_OF_RANGE;
            }
        }
        if (ret)
        {
            errorHandle(ret);
            //return -5;
        }
    }while(ret);


    //input year
    do
    {
        year = 0;
        memset(temp, 0, STR_LEN);
        printf("Please input expiration year xxxx (4 digits, 1985~2011), press ENTER when done:\n");
        ret = getNString(temp, YEAR_LEN+1);
        if (!ret)
        {
            year = atoi(temp);
            if ( (year>=1985) && (year<=2011) )
            {
                //do nothing
            }
            else
            {
                ret = ERR_OUT_OF_RANGE;
            }
        }
        if (ret)
        {
            errorHandle(ret);
            //return -6;
        }
    }while(ret);


    //input security code
    secure_code = 0;
    do
    {
        memset(temp, 0, STR_LEN);
        printf("Please input security code xxx (3 digits), press ENTER when done:\n");
        ret = getNString(temp, SECURE_CODE_LEN+1);
        if (ret)
        {
            errorHandle(ret);
            //return -7;
        }
    }while(ret);
    secure_code = atoi(temp);



    //input zip code
    zip = 0;
    do
    {
        memset(temp, 0, STR_LEN);
        printf("Please input zip code xxxxx (5 digits), press ENTER when done:\n");
        ret = getNString(temp, ZIP_LEN+1);
        if (ret)
        {
            errorHandle(ret);
            //return -8;
        }
    }while(ret);
    zip = atoi(temp);


    //input purchase amount
    do
    {
        amount_int = 0;
        amount_frac = 0;
        printf("Please input purchase amount A.B (A <= 9 digits, B <= 2 digits), press ENTER when done:\n");
        ret = getDollarNum(&amount_int, 9, &amount_frac, 2); 
        if (ret)
        {
            errorHandle(ret);
            //return -9;
        }
    }while(ret);

    memset(amount_int_str, 0, STR_LEN);
    transNum(amount_int_str, amount_int);

    //input email address
    do
    {
        memset(local_name, 0, MAX_NAME_LEN+1);
        memset(domain_name, 0, MAX_DOMAIN_LEN+1);
        printf("Please input email address A@B (A's len <= 64, B's len <= 253. '[]' is not support in domain name), press ENTER when done:\n");
        ret = getEmailLname(local_name, MAX_NAME_LEN+1);
        if (ret)
        {
            errorHandle(ret);
            //return -10;
        }
        else
        {
            ret = getEmailDname(domain_name, MAX_DOMAIN_LEN+1);
            if (ret)
            {
                errorHandle(ret);
                //return -11;
            }
        }
    }while(ret);

    // print result
    printf("\nSummary\n");
    printf("=================================================\n");
    printf("Name                       <%s %s>\n", first_name, last_name);
    printf("Credit card number         %c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c\n",
            credit_str[0], credit_str[1], credit_str[2], credit_str[3],
            credit_str[4], credit_str[5], credit_str[6], credit_str[7],
            credit_str[8], credit_str[9], credit_str[10], credit_str[11],
            credit_str[12], credit_str[13], credit_str[14], credit_str[15]);
    printf("Expiration month and year  <%s %d>\n", monthStr[month-1], year);
    printf("Security code              %d\n", secure_code);
    printf("Zip code                   %d\n", zip);
    printf("Purchase amount            %s.%02d\n", amount_int_str, amount_frac);
    printf("Email address              <%s@%s>\n", local_name, domain_name);
    printf("\n");
    return 0;
}
Esempio n. 21
0
Mento::Mento(QObject *parent) :
    QObject(parent)
{
    if(CocoaInitialize::DefaultApp()->checkRunning())
    {
        initsuccess=false;
        QMessageBox::warning(0,"Warning","Cocoa Mento 正在运行当中!",QMessageBox::Ok,QMessageBox::Ok);
        return;
    }
    else initsuccess=true;

    log=new QTextBrowser();
    log->setWindowModality(Qt::WindowModal);
    log->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint);
    log->setGeometry(200,200,400,500);
    log->setWindowTitle(tr("认证日志"));

    gt=new Guite();

    main=new Menu("Cocoa Mento");
    sub=new Menu("Settings");

    status=new MenuItem("[状态:正常] 未连接");
    connectHandle=new MenuItem("开始认证");
    settings=new MenuItem("偏好设置");
    about=new MenuItem("关于CocoaMento");
    aboutQt=new MenuItem("关于Qt");
    help=new MenuItem("使用说明");
    exit=new MenuItem("退出");
    resetsettings=new MenuItem("重置偏好设置");
    logs=new MenuItem("显示日志");

    cv=new ConfigView();
    cvcontainer=new MenuViewItem("Settings",cv);

    cv->setPalette(Qt::white);
    cv->show();

    settings->setSubMenu(sub);

    main->addMenuItem(status);
    main->addMenuSeparator();
    main->addMenuItem(connectHandle);
    main->addMenuItem(settings);
    main->addMenuItem(resetsettings);
    main->addMenuItem(logs);
    main->addMenuSeparator();
    main->addMenuItem(help);
    main->addMenuItem(about);
    main->addMenuItem(aboutQt);
    main->addMenuSeparator();
    main->addMenuItem(exit);

    sub->addMenuItem(cvcontainer);

    icon=new StatusIcon();
    icon->setMenu(main);
    icon->showIcon();

    mainthread=new MentoThread(cv->Config());

    connect((QObject*)exit->port,SIGNAL(trigger()),this,SLOT(quitApp()));
    connect((QObject*)resetsettings->port,SIGNAL(trigger()),cv,SLOT(resetConfig()));
    connect((QObject*)connectHandle->port,SIGNAL(trigger()),this,SLOT(toggleConnect()));
    connect((QObject*)logs->port,SIGNAL(trigger()),log,SLOT(show()));
    connect((QObject*)about->port,SIGNAL(trigger()),gt,SLOT(showAbout()));
    connect((QObject*)aboutQt->port,SIGNAL(trigger()),this,SLOT(showAboutQt()));
    connect((QObject*)help->port,SIGNAL(trigger()),gt,SLOT(showHelp()));


    connect(mainthread,SIGNAL(output(QString)),this,SLOT(outputHandle(QString)));
    connect(mainthread,SIGNAL(exitSuccess()),this,SLOT(exitHandle()));
    connect(mainthread,SIGNAL(statusChanged(QString,int)),this,SLOT(statusHandle(QString,int)));
    connect(mainthread,SIGNAL(error(QString)),this,SLOT(errorHandle(QString)));
    connect(mainthread,SIGNAL(authError()),this,SLOT(authMento()));
    connect(mainthread,SIGNAL(noConfig()),this,SLOT(noconfigHandle()));
    connect(mainthread,SIGNAL(notify(QString)),this,SLOT(notifyHandle(QString)));

    if(cv->autoConnect()) toggleConnect();
}
Esempio n. 22
0
static void checkFormat(const char* line,int lineCount){
	if(line[0]!='E'&&line[0]!='C'&&line[0]!='H'&&line[0]!='F'&&line[0]!='L')
		errorHandle(UNKNOW_KEYWORD,lineCount,(int)line[0]);
	if(!isspace(line[1]))
		errorHandle(BAD_FORMAT,lineCount);
}
Esempio n. 23
0
File: main.c Progetto: bisan11/hw03
int main(int argc, char* argv[])
{

int parameter=checkparametr (argc,argv);
if (parameter!=0){
    return -2;}

PTGALLERY *ptgallery=malloc(sizeof(PTGALLERY));
if(!ptgallery){
    errorHandle(ERROR_NO_MEMORY);
    return 0;
}
struct node * actualPic=NULL;
initGallery(ptgallery);

char c;
char bond[5000];
struct node *newpic;

while (1){
    printf(">");
    fgets(bond,5000,stdin);

    if (strlen(bond)>2){
        errorHandle(ERROR_WRONG_CMD);

    }
    else {
        c=bond[0];
        int b=0;
    switch (c){
    case 'n':;

    newpic=malloc(sizeof(struct node));
    if(!newpic){
        errorHandle(ERROR_NO_MEMORY);
        break;
    }
    newpic->next=NULL;
    newpic->prev=NULL;
        b=newpicture(actualPic,newpic,ptgallery);
        if(!b){
            actualPic = newpic;

            printgal(ptgallery, actualPic);
        }else{
            printgal(ptgallery, actualPic);

            free(newpic);
        }

        break;
    case 'd':
        if((ptgallery->first == NULL)||(ptgallery->last == NULL)){
            break;
        } else if((ptgallery->first == ptgallery->last)){
            ptgallery->first = NULL;
            ptgallery->last = NULL;
            free(actualPic->value);
            free(actualPic);
            actualPic=NULL;
            break;
        } else {
            if(!(actualPic->prev)){
                ptgallery->first = actualPic->next;
                actualPic = actualPic->next;
                freepic(ptgallery->first->prev);
                ptgallery->first->prev = NULL;
            } else if(actualPic->next == NULL){
                ptgallery->last=actualPic->prev;
                actualPic = actualPic->prev;
                freepic(ptgallery->last->next);
                ptgallery->last->next=NULL;
            } else {
                struct node *needed=actualPic;
                actualPic->prev->next=actualPic->next;
                actualPic->next->prev=actualPic->prev;

                actualPic = actualPic->next;
                free (needed);
            }
        }
        printgal(ptgallery,actualPic);
        break;
    case 'r':
        if(ptgallery->first==actualPic){
            actualPic=ptgallery->last;
        } else {
            actualPic=actualPic->prev;
        }
        printgal(ptgallery, actualPic);
        break;
    case 'l':
        if(ptgallery->last==actualPic){
            actualPic=ptgallery->first;
        } else {
            actualPic=actualPic->next;
        }
        printgal(ptgallery, actualPic);
        break;
    case 's':
        printf ("size: %i\n",howmanypictures(ptgallery));
        break;
    case 'q':
        actualPic = ptgallery->first;
       while(actualPic!=NULL){
           if(actualPic->next !=NULL){
           actualPic = actualPic->next;
           freepic(actualPic->prev);
           } else {
               freepic(actualPic);
           break;
           }

       }
        free(ptgallery);

        return 0;
    case '\n':
        break;
    default:
        errorHandle(ERROR_WRONG_CMD);
        break;
    }}}
return 0;
}