void CKongQi::on_pushButton_clicked() { if (tablerow1<0|| tablerow2<0) { return; } QSqlQuery m_query(m_control->m_sql); m_query.prepare("insert into KongQiTable(name,shortaddr,longaddr,dir,cname,cshortaddr,clongaddr,cdir,cfunction,truefunction) values(:name,:shortaddr,:longaddr,:dir,:cname,:cshortaddr,:clongaddr,:cdir,:cfunction,:truefunction)"); m_query.bindValue(":name", trUtf8("空气质量")); QTableWidgetItem *item = ui->tableWidget->item(tablerow1, 1); m_query.bindValue(":shortaddr", item->text()); item = ui->tableWidget->item(tablerow1, 0); m_query.bindValue(":longaddr", item->text()); m_query.bindValue(":dir",m_control->RetDirByMacAddr(item->text())); item = ui->tableWidget_2->item(tablerow2, 0); m_query.bindValue(":cname", item->text()); item = ui->tableWidget_2->item(tablerow2, 1); m_query.bindValue(":cshortaddr", item->text()); item = ui->tableWidget_2->item(tablerow2, 2); m_query.bindValue(":clongaddr", item->text()); item = ui->tableWidget_2->item(tablerow2, 3); m_query.bindValue(":cdir", item->text()); item = ui->tableWidget_2->item(tablerow2, 4); m_query.bindValue(":cfunction", item->text()); m_query.bindValue(":truefunction", ui->comboBox->currentText()); bool ok=m_query.exec(); if(ok==false) { return; } readtable(); }
void readModelFiles(int l) { char fname[100]; char ext[5][10]={"vars","func","prtcls","lgrng","extlib"}; int i; for(i=0;i<5;i++) cleartab(modelTab+i); lastModel=0; for(i=0;i<5;i++) { sprintf(fname,"./models/%s%d.mdl",ext[i],l); readtable(modelTab+i,fname); } }
int main(int argc, char **argv){ long i; int j; int swap; int rndpos; double threshold1, threshold2, threshold3; double sd1, sd2, sd3; if(argc < 2){ fprintf(stderr, "Not enough parameter\n"); return(2); } readtable(argv[1]); initrnd(); copy2vec(); sd(&threshold1, &threshold2, &threshold3); printf("cycle\tdiff1\tdiff2\tdiff3\tviolate\n"); for(i = 0; i < SIMNUM; i++){ sd(&sd1, &sd2, &sd3); if(sd1 <= threshold1 && sd2 <= threshold2 && sd3 <= threshold3){ printf("%ld\t%f\t%f\t%f\t1\n", i, sd1, sd2, sd3); } else{ printf("%ld\t%f\t%f\t%f\t0\n", i, sd1, sd2, sd3); } /* Knuth shuffle in three groups */ for(j = 0; j < count; j++){ rndpos = getint(j, count - 1); swap = shuffled[j]; shuffled[j] = shuffled[rndpos]; shuffled[rndpos] = swap; rndpos = getint(count, count * 2 - 1); swap = shuffled[count + j]; shuffled[count + j] = shuffled[rndpos]; shuffled[rndpos] = swap; rndpos = getint(count * 2, count * 3 - 1); swap = shuffled[count * 2 + j]; shuffled[count * 2 + j] = shuffled[rndpos]; shuffled[rndpos] = swap; } } free(vector); free(shuffled); return(EXIT_SUCCESS); }
void CKey::on_pushButton_2_clicked() { if(tablerow3<0) { return; } QSqlQuery m_query(m_control->m_sql); m_query.prepare("delete FROM KeyTable where keyval=?"); m_query.bindValue(0,ui->tableWidget_3->item(tablerow3,3)->text());//ui->tableWidget_3->currentRow() bool ok=m_query.exec(); if(ok==false) { return; } int i=ui->tableWidget_3->rowCount(); if(i==1) { ui->tableWidget_3->removeRow(0); } readtable(); tablerow3=-1; }
static int hts_parse_java(t_hts_callbackarg * carg, httrackp * opt, htsmoduleStruct * str) { /* The wrapper_name memebr has changed: not for us anymore */ if (str->wrapper_name == NULL || strcmp(str->wrapper_name, libName) != 0) { /* Call parent functions if multiple callbacks are chained. */ if (CALLBACKARG_PREV_FUN(carg, parse) != NULL) { return CALLBACKARG_PREV_FUN(carg, parse) (CALLBACKARG_PREV_CARG(carg), opt, str); } strcpy(str->err_msg, "unexpected error: bad wrapper_name and no previous wrapper"); return 0; /* Unexpected error */ } else { if (detect_mime(str)) { /* (Legacy code) */ char catbuff[CATBUFF_SIZE]; FILE *fpout; JAVA_HEADER header; RESP_STRUCT *tab; const char *file = str->filename; str->relativeToHtmlLink = 1; #if JAVADEBUG printf("fopen\n"); #endif if ((fpout = FOPEN(fconv(catbuff, sizeof(catbuff), file), "r+b")) == NULL) { //fprintf(stderr, "Cannot open input file.\n"); sprintf(str->err_msg, "Unable to open file %s", file); return 0; // une erreur.. } #if JAVADEBUG printf("fread\n"); #endif //if (fread(&header,1,sizeof(JAVA_HEADER),fpout) != sizeof(JAVA_HEADER)) { // pas complet.. if (fread(&header, 1, 10, fpout) != 10) { // pas complet.. fclose(fpout); sprintf(str->err_msg, "File header too small (file len = " LLintP ")", (LLint) fsize(file)); return 0; } #if JAVADEBUG printf("header\n"); #endif // tester en tête if (reverse_endian()) { header.magic = hts_swap32(header.magic); header.count = hts_swap16(header.count); } if (header.magic != 0xCAFEBABE) { sprintf(str->err_msg, "non java file"); if (fpout) { fclose(fpout); fpout = NULL; } return 0; } tab = (RESP_STRUCT *) calloc(header.count, sizeof(RESP_STRUCT)); if (!tab) { sprintf(str->err_msg, "Unable to alloc %d bytes", (int) sizeof(RESP_STRUCT)); if (fpout) { fclose(fpout); fpout = NULL; } return 0; // erreur.. } #if JAVADEBUG printf("calchead\n"); #endif { int i; for(i = 1; i < header.count; i++) { int err = 0; // ++ tab[i] = readtable(str, fpout, tab[i], &err); if (!err) { if ((tab[i].type == HTS_LONG) || (tab[i].type == HTS_DOUBLE)) i++; //2 element si double ou float } else { // ++ une erreur est survenue! if (strnotempty(str->err_msg) == 0) strcpy(str->err_msg, "Internal readtable error"); free(tab); if (fpout) { fclose(fpout); fpout = NULL; } return 0; } } } #if JAVADEBUG printf("addfiles\n"); #endif { //unsigned int acess; unsigned int Class; unsigned int SClass; int i; //acess = readshort(fpout); Class = readshort(fpout); SClass = readshort(fpout); for(i = 1; i < header.count; i++) { if (tab[i].type == HTS_CLASS) { if ((tab[i].index1 < header.count) && (tab[i].index1 >= 0)) { if ((tab[i].index1 != SClass) && (tab[i].index1 != Class) && (tab[tab[i].index1].name[0] != '[')) { if (!strstr(tab[tab[i].index1].name, "java/")) { char BIGSTK tempo[1024]; tempo[0] = '\0'; sprintf(tempo, "%s.class", tab[tab[i].index1].name); #if JAVADEBUG printf("add %s\n", tempo); #endif if (tab[tab[i].index1].file_position >= 0) str->addLink(str, tempo); /* tab[tab[i].index1].file_position */ } } } else { i = header.count; // exit } } } } #if JAVADEBUG printf("end\n"); #endif free(tab); if (fpout) { fclose(fpout); fpout = NULL; } return 1; } else { strcpy(str->err_msg, "bad MIME type"); } } return 0; /* Error */ }
CKey::CKey(QWidget *parent) : QWidget(parent), ui(new Ui::CKey) { ui->setupUi(this); this->setWindowFlags(Qt::FramelessWindowHint); m_control->whichdialog=9; m_text=ui->textEdit; QStringList header; header.append(trUtf8("MAC地址")); header.append(trUtf8("短地址")); ui->tableWidget->setColumnCount(2); ui->tableWidget->setColumnWidth(0, 236); ui->tableWidget->setColumnWidth(1, 136); ui->tableWidget->setHorizontalHeaderLabels(header); ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); ui->tableWidget->verticalHeader()->setVisible(false); ui->tableWidget->horizontalHeader()->setVisible(false); header.clear(); header.append(trUtf8("节点名称")); header.append(trUtf8("短地址")); header.append(trUtf8("MAC地址")); header.append(trUtf8("节点位置")); header.append(trUtf8("功能")); ui->tableWidget_2->setColumnCount(5); ui->tableWidget_2->setColumnWidth(0, 120); ui->tableWidget_2->setColumnWidth(1, 128); ui->tableWidget_2->setColumnWidth(2, 128); ui->tableWidget_2->setColumnWidth(3, 128); ui->tableWidget_2->setColumnWidth(4, 128); ui->tableWidget_2->setHorizontalHeaderLabels(header); ui->tableWidget_2->setSelectionMode(QAbstractItemView::SingleSelection); // ui->tableWidget_2->verticalHeader()->setVisible(false); ui->tableWidget_2->horizontalHeader()->setVisible(false); SelectGuanXianAddr(); header.clear(); header.append(trUtf8("主控名称")); header.append(trUtf8("主控短地址")); header.append(trUtf8("主控MAC地址")); header.append(trUtf8("主控位置")); header.append(trUtf8("主控界值")); header.append(trUtf8("被控名称")); header.append(trUtf8("被控短地址")); header.append(trUtf8("被控MAC地址")); header.append(trUtf8("被控位置")); header.append(trUtf8("功能")); header.append(trUtf8("实际功能")); ui->tableWidget_3->setColumnCount(11); ui->tableWidget_3->setColumnWidth(0, 100); ui->tableWidget_3->setColumnWidth(1, 100); ui->tableWidget_3->setColumnWidth(2, 268); ui->tableWidget_3->setColumnWidth(3, 100); ui->tableWidget_3->setColumnWidth(4, 110); ui->tableWidget_3->setColumnWidth(5, 100); ui->tableWidget_3->setColumnWidth(6, 148); ui->tableWidget_3->setColumnWidth(7, 248); ui->tableWidget_3->setColumnWidth(8, 118); ui->tableWidget_3->setColumnWidth(9, 108); ui->tableWidget_3->setColumnWidth(10, 108); ui->tableWidget_3->setHorizontalHeaderLabels(header); ui->tableWidget_3->setSelectionMode(QAbstractItemView::SingleSelection); ui->tableWidget_3->verticalHeader()->setVisible(false); ui->tableWidget_3->horizontalHeader()->setVisible(false); SelectGuanXianControl(); readtable(); ui->comboBox->insertItem(0,QIcon(":/images/1.png"),trUtf8("开")); ui->comboBox->insertItem(1,QIcon(":/images/2.png"),trUtf8("关")); ui->comboBox->setCurrentIndex(0); tablerow1=-1; tablerow2=-1; tablerow3=-1; }
int main(int argc, char *argv[]){ double r; int i; int *lut_c; int *lut_f; polynom *erg; /* getopt */ int c; opterr = 0; while((c=getopt(argc, argv, "r:m:s:")) != -1) { switch(c) { case 'r': R0=atof(optarg); break; case 'm': AD_MAX=atoi(optarg); break; case 's': AD_STEP=atoi(optarg); break; case '?': if (optopt == 'r' || optopt == 'm' || optopt == 's'){ fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else if (isprint (optopt)) { fprintf(stderr, "Unknown option '-%c'.\n", optopt); } else { fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); } /* fall through */ default: usage(argv[0]); return 1; } } if(optind != argc-1 || R0 <=0 || AD_MAX <=0 || AD_STEP <= 0){ usage(argv[0]); return 1; } printf("Using: R0 = %lf, AD_MAX = %d, AD_STEP = %d\n", R0, AD_MAX, AD_STEP); readtable(argv[optind]); orthonormal(basis); erg = approx(); testresult(erg); for(i=0; i<4; i++){ a[i] = (*erg)[i]; } lut_c = malloc(sizeof(int) * LUT_SIZE); lut_f = malloc(sizeof(int) * LUT_SIZE); lut_c[0]=0; lut_f[0]=0; for(i=1; i<LUT_SIZE; i++){ r = rtot(ad_to_r(i*AD_STEP)); lut_c[i] = (int)round(r * 10.0); lut_f[i] = (int)round(C_TO_F(r) * 10.0); } printf("//Celsius\n"); printf("const int ad_lookup[] = { 0"); for(i=1; i<LUT_SIZE; i++){ printf(", %d", lut_c[i]); } printf(" };\n"); printf("//Fahrenheit\n"); printf("const int ad_lookup[] = { 0"); for(i=1; i<LUT_SIZE; i++){ printf(", %d", lut_f[i]); } printf(" };\n"); }
static int elfreadsyms (int fd, Elf32_Ehdr *eh, Elf32_Shdr *shtab, int flags) { Elf32_Shdr *sh, *strh, *shstrh, *ksh; Elf32_Sym *symtab; Elf32_Ehdr *keh; char *shstrtab, *strtab, *symend; int nsym, offs, size, i; int *symptr; /* Fix up twirl */ if (bootseg++ > 0) { fprintf (stderr, "\b + "); } /* * If we are loading symbols to support kernel DDB symbol handling * make room for an ELF header at _end and after that a section * header. DDB then finds the symbols using the data put here. */ if(flags & KFLAG) { tablebase = roundup(tablebase, sizeof(long)); symptr = (int *)tablebase; tablebase += sizeof(int *) * 2; keh = (Elf32_Ehdr *)tablebase; tablebase += sizeof(Elf32_Ehdr); tablebase = roundup(tablebase, sizeof(long)); ksh = (Elf32_Shdr *)tablebase; tablebase += roundup((sizeof(Elf32_Shdr) * eh->e_shnum), sizeof(long)); memcpy(ksh, shtab, roundup((sizeof(Elf32_Shdr) * eh->e_shnum), sizeof(long))); sh = ksh; } else { sh = shtab; } shstrh = &sh[eh->e_shstrndx]; for (i = 0; i < eh->e_shnum; sh++, i++) { if (sh->sh_type == SHT_SYMTAB) { break; } } if (i >= eh->e_shnum) { return (0); } if(flags & KFLAG) { strh = &ksh[sh->sh_link]; nsym = sh->sh_size / sh->sh_entsize; offs = sh->sh_offset; size = sh->sh_size; fprintf (stderr, "%d syms ", nsym); } else { strh = &shtab[sh->sh_link]; nsym = (sh->sh_size / sh->sh_entsize) - sh->sh_info; offs = sh->sh_offset + (sh->sh_info * sh->sh_entsize); size = nsym * sh->sh_entsize; fprintf (stderr, "%d syms ", nsym); } /* * Allocate tables in correct order so the kernel grooks it. * Then we read them in the order they are in the ELF file. */ shstrtab = gettable(shstrh->sh_size, "shstrtab", flags); strtab = gettable(strh->sh_size, "strtab", flags); symtab = gettable(size, "symtab", flags); symend = (char *)symtab + size; do { if(shstrh->sh_offset < offs && shstrh->sh_offset < strh->sh_offset) { #if 0 /* * We would like to read the shstrtab from the file but since this * table is located in front of the shtab it is already gone. We can't * position backwards outside the current segment when using tftp. * Instead we create the names we need in the string table because * it can be reconstructed from the info we now have access to. */ if (!readtable (shstrh->sh_offset, (void *)shstrtab, shstrh->sh_size, "shstring", flags)) { return(0); } #else memset(shstrtab, 0, shstrh->sh_size); strcpy(shstrtab + shstrh->sh_name, ".shstrtab"); strcpy(shstrtab + strh->sh_name, ".strtab"); strcpy(shstrtab + sh->sh_name, ".symtab"); #endif shstrh->sh_offset = 0x7fffffff; } if (offs < strh->sh_offset && offs < shstrh->sh_offset) { if (!(readtable(fd, offs, (void *)symtab, size, "sym", flags))) { return (0); } offs = 0x7fffffff; } if (strh->sh_offset < offs && strh->sh_offset < shstrh->sh_offset) { if (!(readtable (fd, strh->sh_offset, (void *)strtab, strh->sh_size, "string", flags))) { return (0); } strh->sh_offset = 0x7fffffff; } if (offs == 0x7fffffff && strh->sh_offset == 0x7fffffff && shstrh->sh_offset == 0x7fffffff) { break; } } while(1); if(flags & KFLAG) { /* * Update the kernel headers with the current info. */ shstrh->sh_offset = (Elf32_Off)shstrtab - (Elf32_Off)keh; strh->sh_offset = (Elf32_Off)strtab - (Elf32_Off)keh; sh->sh_offset = (Elf32_Off)symtab - (Elf32_Off)keh; memcpy(keh, eh, sizeof(Elf32_Ehdr)); keh->e_phoff = 0; keh->e_shoff = sizeof(Elf32_Ehdr); keh->e_phentsize = 0; keh->e_phnum = 0; printf("\nKernel debugger symbols ELF hdr @ %p", keh); symptr[0] = (int)keh; symptr[1] = roundup((int)symend, sizeof(int)); } else { /* * Add all global sybols to PMONs internal symbol table. */ for (i = 0; i < nsym; i++, symtab++) { int type; dotik (4000, 0); if (symtab->st_shndx == SHN_UNDEF || symtab->st_shndx == SHN_COMMON) { continue; } type = ELF_ST_TYPE (symtab->st_info); if (type == STT_SECTION || type == STT_FILE) { continue; } /* only use globals and functions */ if (ELF_ST_BIND(symtab->st_info) == STB_GLOBAL || type == STT_FUNC){ if (symtab->st_name >= strh->sh_size) { fprintf (stderr, "\ncorrupt string pointer"); return (0); } } if (!newsym (strtab + symtab->st_name, symtab->st_value)) { fprintf (stderr, "\nonly room for %d symbols", i); return (0); } } } return (1); }
int main(int argv, char**argc) { char fname[200]; int i,nLn,L; FILE*f; int nVar=0,nFunc=0,first; char path[200]; if(argv!=3) { printf("Arguments expected: 1)path to model files; 2) model number.\n"); return 1;} sscanf(argc[1],"%s",path); if(sscanf(argc[2],"%d",&L)!=1) { printf("Second argument should be a number\n"); return 1;} { char ext[3][8]={"vars","func","prtcls"}; for(i=0;i<3;i++) { cleartab(modelTab+i); sprintf(fname,"%s/%s%d.mdl",path,ext[i],L); if(readtable(modelTab+i,fname)) {printf("Problem in reading of Table %s\n", fname); return 2; } } if(read2VarsParticles()) {printf("Error in model\n"); return 3;} } f=fopen("VandP.c","w"); fprintf(f,"#include <stdio.h>\n"); fprintf(f,"#include <math.h>\n"); fprintf(f,"#include \"V_and_P.h\"\n"); fprintf(f,"extern int FError;\n"); for(nLn=0,i=0;i<nparticles;i++) if(!strchr("*fcCtT",prtclbase[i].hlp)&&i+1<=prtclbase[i].anti)nLn++; fprintf(f,"int nModelParticles=%d;\n",nLn); fprintf(f,"ModelPrtclsStr ModelPrtcls[%d]=\n{\n",nLn); for(nLn=0,i=0;i<nparticles;i++) if(!strchr("*fcCtT",prtclbase[i].hlp)) { int anti=prtclbase[i].anti; if(i+1>anti) continue; if(nLn)fprintf(f,","); else fprintf(f," "); nLn++; fprintf(f," {\"%s\",",prtclbase[i].name); if(i+1==anti) fprintf(f,"\"%s\", ",prtclbase[i].name); else fprintf(f,"\"%s\", ",prtclbase[anti-1].name); fprintf(f,"%ld, \"%s\",\"%s\",%d,%d}\n", prtclbase[i].N, prtclbase[i].massidnt, prtclbase[i].imassidnt, prtclbase[i].spin, prtclbase[i].cdim); } fprintf(f,"};\n"); if (vararr) free(vararr); vararr = (singlevardescription*)m_alloc((nCommonVars+1) * sizeof(singlevardescription)); for(i=0;i<=nCommonVars;i++) { if(i==0 || strcmp(modelvars[i].varname,"i")==0) { sprintf(vararr[i].alias,"XXX"); vararr[i].tmpvalue=0; vararr[i].num=0; vararr[i].used = 0; }else { sprintf(vararr[i].alias,"V[%d]",nVar+nFunc); vararr[i].tmpvalue=modelvars[i].varvalue; vararr[i].num=nVar+nFunc; vararr[i].used = 1; if(modelvars[i].func) nFunc++; else nVar++; } } fprintf(f,"int nModelVars=%d;\n",nVar); fprintf(f,"int nModelFunc=%d;\n",nFunc); fprintf(f,"char*varNames[%d]={\n ", nVar+nFunc); for(first=1,i=0;i<=nCommonVars;i++) if(vararr[i].used) { if(first) first=0;else fprintf(f,","); fprintf(f,"\"%s\"\n",modelvars[i].varname); } fprintf(f,"};\n"); fprintf(f,"double varValues[%d]={\n ", nVar+nFunc); for(first=1,i=0;i<=nCommonVars;i++) if(vararr[i].used) { if(first) first=0;else fprintf(f,","); fprintf(f,"%E\n",modelvars[i].varvalue); } fprintf(f,"};\n"); /*static void writesubroutineinit(void) */ fprintf(f,"#include\"extern.h\"\n"); ext_h=fopen("extern.h","w"); fprintf(f,"int calcMainFunc(void)\n{\n"); fprintf(f," double *V=varValues;\n"); fprintf(f," FError=0;\n"); for(i=1;i<=nCommonVars;i++) { if (vararr[i].used && modelvars[i].func) { checkNaN=0; { char * ss=(char *)readExpression(modelvars[i].func,rd_c,act_c,free); fprintf(f," %s=%s;\n",vararr[i].alias,ss+3); free(ss); } if(checkNaN) fprintf(f," if(!finite(%s) || FError) return %d;\n",vararr[i].alias,vararr[i].num); } } fprintf(f,"return 0;\n}\n"); fclose(ext_h); fclose(f); return 0; }