static void copy_template(char *confbase) { char *tmpname = NULL, *conffile; int ret, len; /* look for a template configuration file */ tmpname = malloc(strlen(confbase) + 4); FAILIF(!tmpname, "Allocation failed"); sprintf(tmpname, "%s.ex", confbase); conffile = codaconf_file(tmpname); free(tmpname); FAILIF(!conffile, "Configuration file template '%s.ex' not found\n", confbase); /* strip the '.ex' */ len = strlen(conffile); tmpname = malloc(len + 1); FAILIF(!tmpname, "Allocation failed"); strcpy(tmpname, conffile); tmpname[len - 3] = '\0'; /* copy the template configuration file */ ret = copyfile_byname(conffile, tmpname); FAILIF(ret, "Failed to copy template file to '%s'\n", tmpname); free(tmpname); }
void fill_image_data(GDALImage *image) { GDALResult result; // Open GDAL File image->dataset = GDALOpen(image->filepath, GA_ReadOnly); FAILIF(image->dataset, NULL, "Unable to open file."); // Get file information image->driver = GDALGetDatasetDriver(image->dataset); image->original_width = GDALGetRasterXSize(image->dataset); image->original_height = GDALGetRasterYSize(image->dataset); image->band_count = limit_band_count(GDALGetRasterCount(image->dataset)); // Open first band to get block information image->current_band = GDALGetRasterBand(image->dataset, 1); result = GDALGetGeoTransform(image->dataset, image->geo_transform); FAILIF(result, CE_Failure, "Failed to get GeoTransform data"); GDALGetBlockSize(image->current_band, &image->block_size.x, &image->block_size.y); image->output_size.x = image->block_size.x/image->scale; image->output_size.y = image->block_size.y/image->scale; image->num_blocks.x = image->original_width/image->block_size.x; image->num_blocks.y = image->original_height/image->block_size.y; DEFAULT(image->num_blocks.x, 0, 1); DEFAULT(image->num_blocks.y, 0, 1); DEFAULT(image->output_size.x, 0, 1); DEFAULT(image->output_size.y, 0, 1); }
bool readParamsFile(char *paramsFile) { FILE *pFile = fopen(paramsFile, "rt"); if (pFile == NULL) { fprintf(stderr, "Warning: could not open %s, will try to compute parameters " "and write them to that file\n", paramsFile); return true; } else { fscanf(pFile, "%ld\n", &nRadii); fprintf(stderr, "Using the following R-NN DS parameters (from %s):\n", paramsFile); fprintf(stderr, "N radii = %ld, nPoints = %ld\n", nRadii, nPoints); FAILIF(NULL == (nnStructs = (PRNearNeighborStructT*)MALLOC(nRadii * sizeof(PRNearNeighborStructT)))); FAILIF(NULL == (algParameters = (RNNParametersT*)MALLOC(nRadii * sizeof(RNNParametersT)))); for(IntT i = 0; i < nRadii; i++){ algParameters[i] = readRNNParameters(pFile); printRNNParameters(stderr, algParameters[i]); nnStructs[i] = initLSH_WithDataSet(algParameters[i], nPoints, dataSetPoints); } pointsDimension = algParameters[0].dimension; if (listOfRadii != NULL) FREE(listOfRadii); FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT)))); for(IntT i = 0; i < nRadii; i++){ listOfRadii[i] = algParameters[i].parameterR; } return false; } }
// Creates the LSH hash functions for the R-near neighbor structure // <nnStruct>. The functions fills in the corresponding field of // <nnStruct>. void initHashFunctions(PRNearNeighborStructT nnStruct){ ASSERT(nnStruct != NULL); LSHFunctionT **lshFunctions; // allocate memory for the functions FAILIF(NULL == (lshFunctions = (LSHFunctionT**)MALLOC(nnStruct->nHFTuples * sizeof(LSHFunctionT*)))); for(IntT i = 0; i < nnStruct->nHFTuples; i++){ FAILIF(NULL == (lshFunctions[i] = (LSHFunctionT*)MALLOC(nnStruct->hfTuplesLength * sizeof(LSHFunctionT)))); for(IntT j = 0; j < nnStruct->hfTuplesLength; j++){ FAILIF(NULL == (lshFunctions[i][j].a = (RealT*)MALLOC(nnStruct->dimension * sizeof(RealT)))); } } // initialize the LSH functions for(IntT i = 0; i < nnStruct->nHFTuples; i++){ for(IntT j = 0; j < nnStruct->hfTuplesLength; j++){ // vector a for(IntT d = 0; d < nnStruct->dimension; d++){ #ifdef USE_L1_DISTANCE lshFunctions[i][j].a[d] = genCauchyRandom(); #else lshFunctions[i][j].a[d] = genGaussianRandom(); #endif } // b lshFunctions[i][j].b = genUniformRandom(0, nnStruct->parameterW); } } nnStruct->lshFunctions = lshFunctions; }
/* apriori() calls this function when it determine the size of a library in memory. pm_report_library_size_in_memory() makes sure that the library fits in the slot provided by the prelink map. */ void pm_report_library_size_in_memory(const char *name, off_t fsize) { char *x; mapentry *me; int n; x = strrchr(name,'/'); if(x) name = x+1; for(me = maplist; me; me = me->next){ for (n = 0; n < me->num_names; n++) { if(!strcmp(name, me->names[n])) { off_t slot = me->next ? me->next->base : PRELINK_MAX; slot -= me->base; FAILIF(fsize > slot, "prelink map error: library %s@0x%08x is too big " "at %lld bytes, it runs %lld bytes into " "library %s@0x%08x!\n", me->names[0], me->base, fsize, fsize - slot, me->next->names[0], me->next->base); return; } } } FAILIF(1, "library '%s' not in prelink map\n", name); }
int main(int argc, char **argv) { char *conffile; const char *p, *val; int i, len; FAILIF(argc < 2, "Usage: %s <conffile> [<variable> [<value>]]\n", argv[0]); conffile = codaconf_file(argv[1]); if (argc < 3) { if (!conffile) { fprintf(stdout, "/dev/null\n"); exit(EXIT_FAILURE); } fprintf(stdout, "%s\n", conffile); exit(EXIT_SUCCESS); } /* Hmm, should we really copy the template file on lookups as well. On one * hand it makes a 'readonly' operation 'write' data. On the other hand * there would otherwise be no other way to use the default template * without modifications */ if (!conffile) { copy_template(argv[1]); conffile = codaconf_file(argv[1]); FAILIF(!conffile, "Failed to copy template file to '%s'\n", argv[1]); } codaconf_init_one(conffile); val = codaconf_lookup(argv[2], NULL); if (argc < 4) { FAILIF(!val, "Variable '%s' not found in '%s'\n", argv[2], conffile); fprintf(stdout, "%s\n", val); exit(EXIT_SUCCESS); } /* argc >= 4 */ /* check if this value was already set */ if (val) { p = val; for (i = 3; i <= argc; i++) { len = strlen(argv[i]); if (strncmp(argv[i], p, len) != 0) break; p = p + len; if (*p != ' ') break; p++; } if (i == argc - 1 && *p == '\0') exit(EXIT_SUCCESS); } do_rewrite(conffile, argc, argv); exit(EXIT_SUCCESS); }
inline PPointT readPoint2(char *line, char *comment){ PPointT p; RealT sqrLength = 0; FAILIF(NULL == (p = (PPointT)MALLOC(sizeof(PointT)))); FAILIF(NULL == (p->coordinates = (RealT*)MALLOC(pointsDimension * sizeof(RealT)))); IntT d; char *t; if (comment != NULL) { int a, b; regmatch_t pmatch[2]; if (regexec(&preg[ENUM_PPROP_FILE], comment, 2, pmatch, 0) == 0 && (a = pmatch[1].rm_so) != -1) { b = pmatch[1].rm_eo; FAILIF(NULL == (p->filename = (char*)MALLOC(b-a+1))); memmove(p->filename, comment + a, b-a); p->filename[b-a] = '\0'; } for (int i = 1; i < ENUM_PPROP_LAST_NOT_USED; i++) { if (regexec(&preg[i], comment, 2, pmatch, 0) == 0 && (a = pmatch[1].rm_so) != -1) { b = pmatch[1].rm_eo; char t = comment[b]; comment[b] = '\0'; p->prop[i-1] = atoi(comment + a); comment[b] = t; if ( i==ENUM_PPROP_OIDs ) { // memeory bottleneck now // int c = pmatch[0].rm_so, d = pmatch[0].rm_eo; // FAILIF(NULL == (p->oids = (char*)MALLOC(d-c+1))); // memmove(p->oids, comment + c, d-c); // p->oids[d-c] = '\0'; p->oids = NULL; } } else { p->prop[i-1] = 0; if ( i==ENUM_PPROP_OIDs ) p->oids = NULL; } } p->prop[ENUM_PPROP_OFFSET-1] = p->prop[ENUM_PPROP_OFFSET-1] - p->prop[ENUM_PPROP_LINE-1] +1; // the line range. } for (d = 0, t = line; *t != '\0' && d < pointsDimension; d++) { while ( !isdigit(*t) && *t != '\0' && *t != '.') t++; p->coordinates[d] = strtof(t, &t); // TOFIX: certain versions of gcc have bugs for strtof. sqrLength += SQR(p->coordinates[d]); } p->index = -1; p->sqrLength = sqrLength; return p; }
// Initializes the fields of a R-near neighbors data structure except // the hash tables for storing the buckets. PRNearNeighborStructT initializePRNearNeighborFields(RNNParametersT algParameters, Int32T nPointsEstimate){ PRNearNeighborStructT nnStruct; FAILIF(NULL == (nnStruct = (PRNearNeighborStructT)MALLOC(sizeof(RNearNeighborStructT)))); nnStruct->parameterR = algParameters.parameterR; nnStruct->parameterR2 = algParameters.parameterR2; nnStruct->useUfunctions = algParameters.useUfunctions; nnStruct->parameterK = algParameters.parameterK; if (!algParameters.useUfunctions) { // Use normal <g> functions. nnStruct->parameterL = algParameters.parameterL; nnStruct->nHFTuples = algParameters.parameterL; nnStruct->hfTuplesLength = algParameters.parameterK; }else{ // Use <u> hash functions; a <g> function is a pair of 2 <u> functions. nnStruct->parameterL = algParameters.parameterL; nnStruct->nHFTuples = algParameters.parameterM; nnStruct->hfTuplesLength = algParameters.parameterK / 2; } nnStruct->parameterT = algParameters.parameterT; nnStruct->dimension = algParameters.dimension; nnStruct->parameterW = algParameters.parameterW; nnStruct->nPoints = 0; nnStruct->pointsArraySize = nPointsEstimate; FAILIF(NULL == (nnStruct->points = (PPointT*)MALLOC(nnStruct->pointsArraySize * sizeof(PPointT)))); // create the hash functions initHashFunctions(nnStruct); // init fields that are used only in operations ("temporary" variables for operations). // init the vector <pointULSHVectors> and the vector // <precomputedHashesOfULSHs> FAILIF(NULL == (nnStruct->pointULSHVectors = (Uns32T**)MALLOC(nnStruct->nHFTuples * sizeof(Uns32T*)))); for(IntT i = 0; i < nnStruct->nHFTuples; i++){ FAILIF(NULL == (nnStruct->pointULSHVectors[i] = (Uns32T*)MALLOC(nnStruct->hfTuplesLength * sizeof(Uns32T)))); } FAILIF(NULL == (nnStruct->precomputedHashesOfULSHs = (Uns32T**)MALLOC(nnStruct->nHFTuples * sizeof(Uns32T*)))); for(IntT i = 0; i < nnStruct->nHFTuples; i++){ FAILIF(NULL == (nnStruct->precomputedHashesOfULSHs[i] = (Uns32T*)MALLOC(N_PRECOMPUTED_HASHES_NEEDED * sizeof(Uns32T)))); } // init the vector <reducedPoint> FAILIF(NULL == (nnStruct->reducedPoint = (RealT*)MALLOC(nnStruct->dimension * sizeof(RealT)))); // init the vector <nearPoints> nnStruct->sizeMarkedPoints = nPointsEstimate; FAILIF(NULL == (nnStruct->markedPoints = (BooleanT*)MALLOC(nnStruct->sizeMarkedPoints * sizeof(BooleanT)))); for(IntT i = 0; i < nnStruct->sizeMarkedPoints; i++){ nnStruct->markedPoints[i] = FALSE; } // init the vector <nearPointsIndeces> FAILIF(NULL == (nnStruct->markedPointsIndeces = (Int32T*)MALLOC(nnStruct->sizeMarkedPoints * sizeof(Int32T)))); nnStruct->reportingResult = TRUE; return nnStruct; }
int main(int argc, char **argv) { argc--, argv++; if (!argc) return 0; /* Check to see whether the ELF library is current. */ FAILIF (elf_version(EV_CURRENT) == EV_NONE, "libelf is out of date!\n"); const char *filename; for (; argc; argc--) { filename = *argv++; Elf *elf; GElf_Ehdr elf_hdr; int fd; int prelinked; long prelink_addr = 0; INFO("Processing file [%s]\n", filename); fd = open(filename, O_RDONLY); FAILIF(fd < 0, "open(%d): %s (%d).\n", filename, strerror(errno), errno); elf = elf_begin(fd, ELF_C_READ_MMAP_PRIVATE, NULL); FAILIF_LIBELF(elf == NULL, elf_begin); FAILIF_LIBELF(0 == gelf_getehdr(elf, &elf_hdr), gelf_getehdr); #ifdef SUPPORT_ANDROID_PRELINK_TAGS prelinked = check_prelinked(filename, elf_hdr.e_ident[EI_DATA] == ELFDATA2LSB, &prelink_addr); #else #error 'SUPPORT_ANDROID_PRELINK_TAGS is not defined!' #endif if (prelinked) PRINT("%s: 0x%08x\n", filename, prelink_addr); else PRINT("%s: not prelinked\n", filename); FAILIF_LIBELF(elf_end(elf), elf_end); close(fd); } return 0; }
// Reads in the data set points from <filename> in the array // <dataSetPoints>. Each point get a unique number in the field // <index> to be easily indentifiable. void readDataSetFromFile(char *filename){ FILE *f = fopen(filename, "rt"); FAILIF(f == NULL); //fscanf(f, "%d %d ", &nPoints, &pointsDimension); //FSCANF_DOUBLE(f, &thresholdR); //FSCANF_DOUBLE(f, &successProbability); //fscanf(f, "\n"); FAILIF(NULL == (dataSetPoints = (PPointT*)MALLOC(nPoints * sizeof(PPointT)))); for(IntT i = 0; i < nPoints; i++){ dataSetPoints[i] = readPoint(f); dataSetPoints[i]->index = i; } }
inline PPointT readPoint(FILE *fileHandle){ PPointT p; RealT sqrLength = 0; FAILIF(NULL == (p = (PPointT)MALLOC(sizeof(PointT)))); FAILIF(NULL == (p->coordinates = (RealT*)MALLOC(pointsDimension * sizeof(RealT)))); for(IntT d = 0; d < pointsDimension; d++){ FSCANF_REAL(fileHandle, &(p->coordinates[d])); sqrLength += SQR(p->coordinates[d]); } fscanf(fileHandle, "%[^\n]", sBuffer); p->index = -1; p->sqrLength = sqrLength; return p; }
fresult YNDialogForm::CreateMenu( IMenu** o_mnu ) { fresult fres; MenuFactory* mf = _Factories->GetMenuFactory(); //ready factory mf->CurrentInterlaced = true; mf->CurrentTextFormatHandle = TF_MENU; mf->CurrentEvenTextFormatHandle = TF_MENUEVEN; mf->ClearSettings(); //Set up menu MenuItemSettings* mis; //ItemOriginZ mis = &mf->Settings[ItemOriginZ]; mis->ImgHandle = small_arrow_right_red; mis->OverrideTextFormat = TF_MENU_RED; mis->Text = " "; fres = _FormManager->GetCloseFormHandler(&mis->Handler, fsrOK); mis->Empty = FALSE; //ItemOriginE mis = &mf->Settings[ItemOriginE]; mis->ImgHandle = small_arrow_bottom; mis->Text = "назад"; fres = _FormManager->GetCloseFormHandler(&mis->Handler, fsrCancel); ENSURESUCCESS(fres); mis->Empty = FALSE; //create mnu IMenu* mnu = NULL; fres = mf->GetMenu(ABCXYZLER, &mnu); ENSURESUCCESS(fres); //Clean up mf->ClearSettings(); mf->DefaultInterlaced=mf->CurrentInterlaced; mf->DefaultTextFormatHandle=mf->CurrentTextFormatHandle; mf->DefaultEvenTextFormatHandle=mf->CurrentEvenTextFormatHandle; //Get menu Items _miYes = (MenuItem*)mnu->GetItem(0); FAILIF(_miYes==NULL); _miCancel =(MenuItem*)mnu->GetItem(1); FAILIF(_miCancel==NULL); *o_mnu = mnu; return SUCCESS; }
void InitComm() { MAKE_Q(toRover, RoverCmd, 4); #if ETHER_EMU==1 #else FAILIF(vtI2CInit(&vtI2C0,0,mainI2CMONITOR_TASK_PRIORITY,I2C_Stack) != vtI2CInitSuccess); #endif }
/** * Helper for test_structure_sizes() * * Prints out the size of the struct */ static void check_structure_size(const char *what, int sz) { printf("%s size is %d bytes\n", what, sz); errno=EINVAL; FAILIF(sz % NDN_BT_SIZE_UNITS != 0); }
// Adds a new point to the LSH data structure, that is for each // i=0..parameterL-1, the point is added to the bucket defined by // function g_i=lshFunctions[i]. void addNewPointToPRNearNeighborStruct(PRNearNeighborStructT nnStruct, PPointT point){ ASSERT(nnStruct != NULL); ASSERT(point != NULL); ASSERT(nnStruct->reducedPoint != NULL); ASSERT(!nnStruct->useUfunctions || nnStruct->pointULSHVectors != NULL); ASSERT(nnStruct->hashedBuckets[0]->typeHT == HT_LINKED_LIST || nnStruct->hashedBuckets[0]->typeHT == HT_STATISTICS); nnStruct->points[nnStruct->nPoints] = point; nnStruct->nPoints++; preparePointAdding(nnStruct, nnStruct->hashedBuckets[0], point); // Initialize the counters for defining the pair of <u> functions used for <g> functions. IntT firstUComp = 0; IntT secondUComp = 1; TIMEV_START(timeBucketIntoUH); for(IntT i = 0; i < nnStruct->parameterL; i++){ if (!nnStruct->useUfunctions) { // Use usual <g> functions (truly independent; <g>s are precisly // <u>s). addBucketEntry(nnStruct->hashedBuckets[i], 1, nnStruct->precomputedHashesOfULSHs[i], NULL, nnStruct->nPoints - 1); } else { // Use <u> functions (<g>s are pairs of <u> functions). addBucketEntry(nnStruct->hashedBuckets[i], 2, nnStruct->precomputedHashesOfULSHs[firstUComp], nnStruct->precomputedHashesOfULSHs[secondUComp], nnStruct->nPoints - 1); // compute what is the next pair of <u> functions. secondUComp++; if (secondUComp == nnStruct->nHFTuples) { firstUComp++; secondUComp = firstUComp + 1; } } //batchAddRequest(nnStruct, i, firstUComp, secondUComp, point); } TIMEV_END(timeBucketIntoUH); // Check whether the vectors <nearPoints> & <nearPointsIndeces> is still big enough. if (nnStruct->nPoints > nnStruct->sizeMarkedPoints) { nnStruct->sizeMarkedPoints = 2 * nnStruct->nPoints; FAILIF(NULL == (nnStruct->markedPoints = (BooleanT*)REALLOC(nnStruct->markedPoints, nnStruct->sizeMarkedPoints * sizeof(BooleanT)))); for(IntT i = 0; i < nnStruct->sizeMarkedPoints; i++){ nnStruct->markedPoints[i] = FALSE; } FAILIF(NULL == (nnStruct->markedPointsIndeces = (Int32T*)REALLOC(nnStruct->markedPointsIndeces, nnStruct->sizeMarkedPoints * sizeof(Int32T)))); } }
// Creates the LSH hash functions for the R-near neighbor structure // <nnStruct>. The functions fills in the corresponding field of // <nnStruct>. void initHashFunctions(PRNearNeighborStructT nnStruct) { /*按照 nHFTuples个 组,hfTuplesLength个最终的维度 产生高斯分布的随机值: a向量和 b,付给 nnStruct->lshFunctions【】【】 用于第一步的点积降维 */ //按照gi hi 两层函数族的格式,初始化nnStruct->lshFunctions所指向的二维指针 //nHFTuples组hash函数g,每个组有hfTuplesLength个hi,每个hi就是一个向量a和一个b //按照a。v+b 的格式,初始化结构体中的随机向量和空间 //nnStruct结构体中,初始化nnStruct->lshFunctions 所指向的二维随机矩阵 ASSERT(nnStruct != NULL);//编程技巧: asssert来判断条件执行: __line__ --file__显示位置 LSHFunctionT **lshFunctions;//LSHFunctionT结构体就两个元素:一个指针+一个double // allocate memory for the functions FAILIF(NULL == (lshFunctions = (LSHFunctionT**)MALLOC(nnStruct->nHFTuples * sizeof(LSHFunctionT*)))); for(IntT i = 0; i < nnStruct->nHFTuples; i++) { FAILIF(NULL == (lshFunctions[i] = (LSHFunctionT*)MALLOC(nnStruct->hfTuplesLength * sizeof(LSHFunctionT)))); for(IntT j = 0; j < nnStruct->hfTuplesLength; j++) { FAILIF(NULL == (lshFunctions[i][j].a = (RealT*)MALLOC(nnStruct->dimension * sizeof(RealT)))); } } // initialize the LSH functions //这里开始构造算法中的一组“位置敏感”的Hash函数。 for(IntT i = 0; i < nnStruct->nHFTuples; i++) { for(IntT j = 0; j < nnStruct->hfTuplesLength; j++) { // vector a for(IntT d = 0; d < nnStruct->dimension; d++) { #ifdef USE_L1_DISTANCE lshFunctions[i][j].a[d] = genCauchyRandom();//L1距离有柯西分布 #else lshFunctions[i][j].a[d] = genGaussianRandom(); //L2使用高斯分布 公式中a就是一组d维的正态分布随机数 #endif } // b lshFunctions[i][j].b = genUniformRandom(0, nnStruct->parameterW); } } nnStruct->lshFunctions = lshFunctions; }
// Creates a new vector of size <size> and copies the vector <from> to // the new vector. IntT *copyOfVector(IntT size, IntT *from){ IntT *newVector; FAILIF(NULL == (newVector = (IntT*)MALLOC(size * sizeof(IntT)))); for(IntT i = 0; i < size; i++){ newVector[i] = from[i]; } return newVector; }
fresult ItemsListFormBase::DoLayout() { fresult fres; ubyte_t controlsCount = 5; Size caSz = _App->GetClientAreaSize(); Position caPos = _App->GetClientAreaPos(); fres = _Factories->GetPanelFactory()->GetPanel(caSz, caPos, controlsCount, CL_TRANSPARENT, &_FormPanel); ENSURESUCCESS(fres); //get stipes Panel* stripes = NULL; fres = GetStripesPanel(frmStripeOneTopOneBot, &stripes); ENSURESUCCESS(fres); if (stripes!=NULL) { fres = _FormPanel->AppendControl(stripes); ENSURESUCCESS(fres); } //get message title TextFieldFactory* tff = _Factories->GetTextFieldFactory(); FAILIF(tff==NULL); Position posTitle; posTitle.Left = 0; posTitle.Top = caPos.Top+4; tff->CurrentTextFormatHandle = TF_GRAYTEXT; fres = tff->GetTextBox(posTitle, 26, &_txtItemHeader); ENSURESUCCESS(fres); fres = _FormPanel->AppendControl(_txtItemHeader); ENSURESUCCESS(fres); tff->CurrentTextFormatHandle = TF_NORMAL_EVEN; Position posContent; Size szContent; //- for scroll menu fres = GetContentDimensions(&posContent, &szContent); ENSURESUCCESS(fres); szContent.Width = szContent.Width - 13; fres = tff->GetTextBox(posContent, szContent, &_txtItemContent); ENSURESUCCESS(fres); fres = _FormPanel->AppendControl(_txtItemContent); ENSURESUCCESS(fres); tff->ResetDefaults(); //get menu fres = CreateMenu(&_Menu); ENSURESUCCESS(fres); return SUCCESS; }
fresult YNDialogForm::DoLayout() { fresult fres; ubyte_t controlsCount = 3; Size caSz = _App->GetClientAreaSize(); Position caPos = _App->GetClientAreaPos(); fres = _Factories->GetPanelFactory()->GetPanel(caSz, caPos, controlsCount, CL_TRANSPARENT, &_FormPanel); ENSURESUCCESS(fres); //get stipes Panel* stripes = NULL; fres = GetStripesPanel(frmStripeMessageYNDialog, &stripes); ENSURESUCCESS(fres); if (stripes!=NULL) { fres = _FormPanel->AppendControl(stripes); ENSURESUCCESS(fres); } //get message title TextFieldFactory* tff = _Factories->GetTextFieldFactory(); FAILIF(tff==NULL); Position posTitle; posTitle.Left = 0; posTitle.Top = caPos.Top+4; tff->CurrentTextFormatHandle = TF_NORMAL; fres = tff->GetTextBox(posTitle, 26, &_txtHeader); ENSURESUCCESS(fres); fres = _FormPanel->AppendControl(_txtHeader); ENSURESUCCESS(fres); tff->CurrentTextFormatHandle = TF_NORMAL_EVEN; Position posContent; posContent.Left = 2; posContent.Top = posTitle.Top+16; Size txSize; txSize.Width = 26; txSize.Height =7; fres = tff->GetTextBox(posContent, txSize, 1, &_txtContent); ENSURESUCCESS(fres); fres = _FormPanel->AppendControl(_txtContent); ENSURESUCCESS(fres); tff->ResetDefaults(); //get menu fres = CreateMenu(&_Menu); ENSURESUCCESS(fres); return SUCCESS; }
/** * Test that the lockfile works. */ int test_btree_lockfile(void) { int res; struct ndn_btree_io *io = NULL; struct ndn_btree_io *io2 = NULL; io = ndn_btree_io_from_directory(getenv("TEST_DIRECTORY"), NULL); CHKPTR(io); /* Make sure the locking works */ errno = 0; io2 = ndn_btree_io_from_directory(getenv("TEST_DIRECTORY"), NULL); FAILIF(io2 != NULL || errno == 0); errno=EINVAL; res = io->btdestroy(&io); CHKSYS(res); FAILIF(io != NULL); return(res); }
// The second heuristic for detecting bugs. // return true when there are inconsistent changes. bool inconsistentIDchanges(char *v1, char *v2) { regex_t id; regmatch_t pmatch[1]; char *id1, *id2; int nChanged=0, nUnchanged=0; if ( v1==v2 ) return false; else if ( v1==NULL || v2==NULL ) return true; FAILIF(0 != regcomp(&id, "([^,}[:blank:]]+)", REG_EXTENDED)); int a, b, c, d; while ( regexec(&id, v1, 1, pmatch, 0) == 0 && (a=pmatch[0].rm_so) != -1 ) { char t1 = v1[(b=pmatch[0].rm_eo)]; v1[b] = '\0'; if ( regexec(&id, v2, 1, pmatch, 0) == 0 && (c=pmatch[0].rm_so) != -1 ) { char t2 = v2[(d=pmatch[0].rm_eo)]; v2[d] = '\0'; if ( strcmp(v1, v2)==0 ) nUnchanged++; else nChanged++; v2[d] = t2; v1[b] = t1; v2 += d; v1 += b; } else { nChanged++; v1[b] = t1; v1 += b; break; } } while ( regexec(&id, v1, 1, pmatch, 0) == 0 && (a=pmatch[0].rm_so) != -1 ) { nChanged++; v1 += pmatch[0].rm_eo; } while ( regexec(&id, v2, 1, pmatch, 0) == 0 && (c=pmatch[0].rm_so) != -1 ) { nChanged++; v2 += pmatch[0].rm_eo; } // need quantified condition here. return false; }
void setup_prelink_info(const char *fname, int elf_little, long base) { FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %d!\n", sizeof(prelink_info_t)); int fd = open(fname, O_WRONLY); FAILIF(fd < 0, "open(%s, O_WRONLY): %s (%d)\n" , fname, strerror(errno), errno); prelink_info_t info; off_t sz = lseek(fd, 0, SEEK_END); FAILIF(sz == (off_t)-1, "lseek(%d, 0, SEEK_END): %s (%d)!\n", fd, strerror(errno), errno); if (!(elf_little ^ is_host_little())) { /* Same endianness */ INFO("Host and ELF file [%s] have same endianness.\n", fname); info.mmap_addr = base; } else { /* Different endianness */ INFO("Host and ELF file [%s] have different endianness.\n", fname); info.mmap_addr = switch_endianness(base); } strncpy(info.tag, "PRE ", 4); int num_written = write(fd, &info, sizeof(info)); FAILIF(num_written < 0, "write(%d, &info, sizeof(info)): %s (%d)\n", fd, strerror(errno), errno); FAILIF(sizeof(info) != num_written, "Could not write %d bytes (wrote only %d bytes) as expected!\n", sizeof(info), num_written); FAILIF(close(fd) < 0, "close(%d): %s (%d)!\n", fd, strerror(errno), errno); }
int check_prelinked(const char *fname, int elf_little, long *prelink_addr) { FAILIF(sizeof(prelink_info_t) != 8, "Unexpected sizeof(prelink_info_t) == %d!\n", sizeof(prelink_info_t)); int fd = open(fname, O_RDONLY); FAILIF(fd < 0, "open(%s, O_RDONLY): %s (%d)!\n", fname, strerror(errno), errno); off_t end = lseek(fd, 0, SEEK_END); int nr = sizeof(prelink_info_t); off_t sz = lseek(fd, -nr, SEEK_CUR); ASSERT((long)(end - sz) == (long)nr); FAILIF(sz == (off_t)-1, "lseek(%d, 0, SEEK_END): %s (%d)!\n", fd, strerror(errno), errno); prelink_info_t info; int num_read = read(fd, &info, nr); FAILIF(num_read < 0, "read(%d, &info, sizeof(prelink_info_t)): %s (%d)!\n", fd, strerror(errno), errno); FAILIF(num_read != sizeof(info), "read(%d, &info, sizeof(prelink_info_t)): did not read %d bytes as " "expected (read %d)!\n", fd, sizeof(info), num_read); int prelinked = 0; if (!strncmp(info.tag, "PRE ", 4)) { set_prelink(prelink_addr, elf_little, &info); prelinked = 1; } FAILIF(close(fd) < 0, "close(%d): %s (%d)!\n", fd, strerror(errno), errno); return prelinked; }
fresult NewWoundForm::DoLayout() { fresult fres; ubyte_t controlsCount =2; Position pos; pos.Top = 0; pos.Left = 0; Size sz; sz = _App->GetDisplaySize(); fres = _Factories->GetPanelFactory()->GetPanel(sz, pos, controlsCount, CL_CONTROL_BACKGROUND, &_FormPanel); ENSURESUCCESS(fres); //get header fres = CreateHeader(INVALID_HANDLE, "Укажи место ранения", NULL); ENSURESUCCESS(fres); _txtHeaderSubTitle->SetVisible(FALSE); _pbxHeaderIcon->SetVisible(FALSE); Size szHeaderSize; szHeaderSize.Width = sz.Width; szHeaderSize.Height = 14; fres = _pnlPanelHeader->SetSize(szHeaderSize); ENSURESUCCESS(fres); TextFieldFactory* tff = _Factories->GetTextFieldFactory(); sz.Width = 78; sz.Height =80; pos.Top = 16; pos.Left = 42; tff->CurrentWrap = TRUE; fres = tff->GetTextBox(pos, sz, &_txtWoundText); ENSURESUCCESS(fres); fres = _FormPanel->AppendControl(_txtWoundText); ENSURESUCCESS(fres); tff->CurrentWrap = tff->DefaultWrap; _Menus = AllocMenus(1); FAILIF(_Menus==NULL); IMenu* mnu = NULL; fres = CreateMenu(&mnu); ENSURESUCCESS(fres); if (mnu!=NULL) { _Menus[0] = mnu; } return SUCCESS; }
fresult MedChooseTorsoWoundForm::OnMenu( IMenuItem* mi, bool_t* handled ) { fresult fres; _currentTarget = mwtUnknownTarget; char* hitTargetName; //search menu handler char* miName = mi->GetName(); MenuFactory* mf = _Factories->GetMenuFactory(); FAILIF(mf==NULL); MenuItemSettings* mis = mf->Settings; bool_t found = FALSE; for(ubyte_t i=0; i<MenuItemOriginsLast;i++) { if (StringEquals(miName, mis[i].Name) == TRUE) { switch (i) { case ItemOriginB: _currentTarget = mwtUpTorso; hitTargetName = "Травма верх корпуса"; found = TRUE; break; case ItemOriginY: _currentTarget = mwtUpTorso; hitTargetName = "Травма низа корпуса"; found = TRUE; break; default: found = FALSE; } break; } } if (found != TRUE) { return GENERAL_ERROR; } char* woundDescription = NULL; woundDescription = _App->Logic->MedLogic->GetWoundTargetText(_currentTarget); fres = _App->ShowYNDialogEx(NEW_WOUND_DIALOG_NAME, _TitleText, "добавить\nпроблему", hitTargetName, woundDescription, "добавить проблему"); ENSURESUCCESS(fres); *handled = TRUE; return SUCCESS; }
fresult FormBase::BaseInit( Repositories* reps, Factories* facts, char* name, FormManager* frmmngr, ApplicationBase* app ) { FAILIF(reps==NULL); FAILIF(facts==NULL); FAILIF(name==NULL); FAILIF(frmmngr==NULL); FAILIF(app==NULL); _Repositories = reps; _Factories = facts; _FormManager = frmmngr; _Name = name; _AppBase = app; _FormPanel = NULL; _Menu = &_mnuInstance; _IsDialog = FALSE; _AutoDispatchMenuHandler = &(_autoDispatchMenuHandlerInstance); _AutoDispatchMenuHandler->Init(this, &FormBase::DefaultMenuHandler); return SUCCESS; }
bool_t xdr_send_auth(xdr_s_type *xdr, const opaque_auth *auth) { #define FAILIF(x) do { if (x) return FALSE; } while(0) switch (sizeof(auth->oa_flavor)) { case 1: FAILIF(!XDR_SEND_INT8(xdr, (int8_t *)&auth->oa_flavor)); break; case 2: FAILIF(!XDR_SEND_INT16(xdr, (int16_t *)&auth->oa_flavor)); break; case 4: FAILIF(!XDR_SEND_INT32(xdr, (int32_t *)&auth->oa_flavor)); break; default: return FALSE; } return (XDR_SEND_UINT(xdr, (uint32_t *)&auth->oa_length) && (auth->oa_length == 0 || XDR_SEND_BYTES(xdr, (uint8_t *)auth->oa_base, auth->oa_length))); }
fresult Honor2Logic::Init( Honor2App* app ) { _medInit(); _App = app; _mainForm = (Honor2MainForm*)_App->GetFormManager()->GetForm(_App->Forms->Honor2MainFormName); FAILIF(_mainForm==NULL); _logForm = (LogForm*)_App->GetFormManager()->GetForm(_App->Forms->LogFormName); FAILIF(_logForm==NULL); //init lustra _lastKnownDiscoveryTime = ArmletApi::GetUpTime(); _lastKnownRoomId = UNKNOWN_ID; _lastKnownLustraId = UNKNOWN_ID; _lastKnownLustraIdIsOut = true; //Launch lustra query Timer ArmletApi::RequestTimer(_QueryLustraTimerCallback, LUSTRA_POLL_TIME); //launch medicine ArmletApi::RequestTimer(_MedicineTimerTickCallback, BREATH_TICK_TIME); //update strings in case of armlet restart char* medstatus; char* diagnostics; char* medEvents; _medUpdateStrings(&medstatus, &diagnostics, &medEvents); fresult fres = SetMedStatus(medstatus, diagnostics, medEvents); if (fres!=SUCCESS) { ReportError("Cant't set status!"); } return SUCCESS; }
static inline void run_checks(const void *l, const void *r) { range_t *left = (range_t *)l, *right = (range_t *)r; if (CONTAINS(left, right)) { if (left->err_fn) left->err_fn(ERROR_CONTAINS, left, right); FAILIF(1, "Range sorting error: [%lld, %lld) contains [%lld, %lld)!\n", left->start, left->start + left->length, right->start, right->start + right->length); } if (CONTAINS(right, left)) { if (right->err_fn) right->err_fn(ERROR_CONTAINS, left, right); FAILIF(1, "Range sorting error: [%lld, %lld) contains [%lld, %lld)!\n", right->start, right->start + right->length, left->start, left->start + left->length); } if (INTERSECT(left, right)) { if (left->err_fn) left->err_fn(ERROR_OVERLAPS, left, right); FAILIF(1, "Range sorting error: [%lld, %lld)and [%lld, %lld) intersect!\n", left->start, left->start + left->length, right->start, right->start + right->length); } }
// Constructs a new empty R-near-neighbor data structure. PRNearNeighborStructT initLSH(RNNParametersT algParameters, Int32T nPointsEstimate){ ASSERT(algParameters.typeHT == HT_LINKED_LIST || algParameters.typeHT == HT_STATISTICS); PRNearNeighborStructT nnStruct = initializePRNearNeighborFields(algParameters, nPointsEstimate); // initialize second level hashing (bucket hashing) FAILIF(NULL == (nnStruct->hashedBuckets = (PUHashStructureT*)MALLOC(nnStruct->parameterL * sizeof(PUHashStructureT)))); Uns32T *mainHashA = NULL, *controlHash1 = NULL; BooleanT uhashesComputedAlready = FALSE; for(IntT i = 0; i < nnStruct->parameterL; i++){ nnStruct->hashedBuckets[i] = newUHashStructure(algParameters.typeHT, nPointsEstimate, nnStruct->parameterK, uhashesComputedAlready, mainHashA, controlHash1, NULL); uhashesComputedAlready = TRUE; } return nnStruct; }