/**************************************************************************************** * Purpose: This function will accept two strings (plaintext and the key) and check if they * have valid characters and that the key is at least as long as the plaintext * * Entry: This function receives two strings * * Exit: The function does not return a value *****************************************************************************************/ void errorCheck(char ptext[256],char ktext[256]) { FILE *fp; char plaintext[256]; char key[256]; int i; //Check if the shortkey is shorter than the plaintext fp = fopen(ptext,"r"); if (fp == NULL) { printf("Error opening the file \n"); exit(1); } //Read the contends of the file fgets(plaintext, 256, fp); fclose(fp); fp = fopen(ktext,"r"); if (fp == NULL) { printf("Error opening the file \n"); exit(1); } //Read the contends of the file and convert to cipher text fgets(key, 256, fp); fclose(fp); if (strlen(key) < strlen (plaintext)) { char badKey[256]; sprintf(badKey,"Error key '%s' is too short \n",ktext); printf("%s\n",badKey); exit(1); } //Strip off the new line char *pos; if ((pos=strchr(plaintext, '\n')) != NULL) //String contains a new line { *pos = '\0'; } //Check for bad characters for (i = 0; i < strlen(plaintext); i++) { int check = checkText(plaintext[i]); if (check == 1) { char badKey[256] = "The text file contains bad characters \n"; perror(badKey); exit(1); } } }
WndCustomData::WndCustomData( const QString & i_name, const QString & i_text): Wnd( i_name), m_text( i_text) { QVBoxLayout * qVLayout = new QVBoxLayout( this); m_qText = new QPlainTextEdit( this); qVLayout->addWidget( m_qText); m_qText->setLineWrapMode( QPlainTextEdit::NoWrap); m_qText->setPlainText( m_text); QHBoxLayout * qHLayout = new QHBoxLayout(); qVLayout->addLayout( qHLayout); QPushButton * qBCancel = new QPushButton("Cancel", this); qHLayout->addWidget( qBCancel); connect( qBCancel, SIGNAL( clicked()), this, SLOT( close())); QPushButton * qBCheck = new QPushButton("Check", this); qHLayout->addWidget( qBCheck); connect( qBCheck, SIGNAL( clicked()), this, SLOT( checkText())); QPushButton * qBSet = new QPushButton("Set", this); qHLayout->addWidget( qBSet); connect( qBSet, SIGNAL( clicked()), this, SLOT( setText())); m_qLine = new QLineEdit( this); qVLayout->addWidget( m_qLine); m_qLine->setReadOnly( true); }
afs_int32 writeText(struct ubik_trans *ut, int fid, int textType) { struct textBlock *tbPtr; afs_int32 textSize, writeSize; dbadr dbAddr; struct block block; afs_int32 code = 0; /* check lock is free */ code = checkLock(textType); if (code) ERROR(code); /* ensure that this block has the correct type */ code = checkText(ut, textType); if (code) { LogError(0, "writeText: text type %d damaged\n", textType); ERROR(code); } tbPtr = &db.h.textBlock[textType]; textSize = ntohl(tbPtr->size); dbAddr = ntohl(tbPtr->textAddr); if (!dbAddr) goto error_exit; /* Don't save anything if no blocks */ writeTextHeader(fid, textType); while (dbAddr) { code = cdbread(ut, text_BLOCK, dbAddr, (char *)&block, sizeof(block)); if (code) ERROR(code); writeSize = MIN(textSize, BLOCK_DATA_SIZE); if (!writeSize) break; if (canWrite(fid) <= 0) ERROR(BUDB_DUMPFAILED); if (write(fid, &block.a[0], writeSize) != writeSize) ERROR(BUDB_IO); haveWritten(writeSize); textSize -= writeSize; dbAddr = ntohl(block.h.next); } error_exit: return (code); }
void WndCustomData::setText() { checkText(); if( false == m_valid ) return; if( m_text == m_newText ) { m_qLine->setText("Text was not changed."); return; } emit textEdited( m_newText); close(); }
mainView::mainView(QWidget *parent) : QWidget(parent), ui(new Ui::mainView) { ui->setupUi(this); ui->lineEdit->setEmptyMessage("Type 'mibit' to see what happens"); tip1 = new MibitTip(this, ui->lineEdit, "tip.svg",QPixmap("important.png") ); tip3 = new MibitTip(this, ui->btnTest3, "tip.svg", QPixmap("important.png"), tpAbove ); dialog1 = new MibitDialog(this,"Nothing","dialog-theme.opaque.svg",QPixmap("face-smile.png"), atSlideDown ); dialog1->setSize(300,150); floatPanel = new MibitFloatPanel(this,"rotated_panel.svg", Bottom); floatPanel->setSize(350,200); floatPanel->addWidget(ui->toFloat); QTimer::singleShot(3000,floatPanel,SLOT(showPanel())); notifier = new MibitNotifier(this,"notifier.svg",QPixmap("information.png"));//onTop = true connect(ui->btnClosePanel, SIGNAL(clicked()), floatPanel, SLOT(hideOnUserRequest())); connect(ui->btnQuit, SIGNAL(clicked()),qApp, SLOT(quit())); ui->slider->setRange(0,100); connect(ui->slider, SIGNAL(valueChanged(int)), ui->progressBar, SLOT(setValue(int))); connect(ui->btnTest1, SIGNAL(clicked()), SLOT(showTip1())); connect(ui->btnTest3, SIGNAL(clicked()), SLOT(showTip3())); connect(ui->btnDialog1, SIGNAL(clicked()), SLOT(showDialog1())); connect(ui->btnDialog2, SIGNAL(clicked()), SLOT(showDialog2())); connect(ui->btnDialog3, SIGNAL(clicked()), SLOT(showDialog3())); connect(ui->btnDialog4, SIGNAL(clicked()), SLOT(showDialog4())); connect(ui->btnNotify, SIGNAL(clicked()), this, SLOT(showNotify()) ); connect(ui->btnNotify2, SIGNAL(clicked()), this, SLOT(showNotify2()) ); connect(ui->lineEdit,SIGNAL(textEdited(QString)), this, SLOT(checkText(QString))); QTimer::singleShot(700,this,SLOT(showDialog1())); QTimer::singleShot(0,this,SLOT(centerWindow())); }