FskErr FskFSFileRename(const char *fullPath, const char *newName) { int err; char *p, newPath[PATH_MAX]; FskFileInfo itemInfo; err = sCheckFullPath(fullPath, kFskPathIsFile); BAIL_IF_ERR(err); err = FskFSFileGetFileInfo(fullPath, &itemInfo); BAIL_IF_ERR(err); if (itemInfo.filetype == kFskDirectoryItemIsDirectory) BAIL(kFskErrIsDirectory); p = FskStrRChr((char *)newName, '/'); if (p) BAIL(kFskErrOperationFailed); // newName contains path elements FskStrCopy(newPath, fullPath); p = FskStrRChr(newPath, '/'); if (p) *++p = '\0'; FskStrCat(newPath, newName); err = rename(fullPath, newPath); if (err == -1) BAIL(errnoToFskErr(errno)); err = kFskErrNone; bail: return err; }
static void pam5_basepair_handle_match(struct patternMatch *match) { struct atom *aAh = match->p->atoms[match->atomIndices[0]]; struct atom *aGv = match->p->atoms[match->atomIndices[1]]; struct atom *aS1 = match->p->atoms[match->atomIndices[2]]; struct atom *aS2 = match->p->atoms[match->atomIndices[3]]; struct atom *vA; struct bond *bond; pam5_requires_gromacs(match->p); BAIL(); init_stack_match(); BAIL(); // S1 // | // Gv----Ah // | // S2 if (aAh->isGrounded) { vA = makeVirtualAtom(vAh5_type, sp3, 3, 1, aGv, aS1, aS2, NULL, axis_pq, axis_pq, 0.0); bond = makeBond(match->p, vA, aAh, '1'); queueAtom(match->p, vA); trace_makeVirtualAtom(match, vA); queueBond(match->p, bond); trace_makeBond(match, bond); } //printMatch(match); }
void evaluateGradient(struct configuration *p) { struct functionDefinition *fd; int i; double gradientCoordinate; NULLPTR(p); fd = p->functionDefinition; NULLPTR(fd); if (p->gradient == NULL) { p->gradient = (double *)allocate(sizeof(double) * fd->dimension); if (fd->dfunc == NULL) { evaluateGradientFromPotential(p); BAIL(); } else { (*fd->dfunc)(p); BAIL(); } fd->gradientEvaluationCount++; p->parameter = 0.0; p->maximumCoordinateInGradient = 0.0; for (i=fd->dimension-1; i>=0; i--) { CHECKNAN(p->gradient[i]); gradientCoordinate = fabs(p->gradient[i]); if (p->maximumCoordinateInGradient < gradientCoordinate) { p->maximumCoordinateInGradient = gradientCoordinate; } } } }
int alloc_monitoring_datas() { int error = 0; if (world.config == NULL) { goto cleanup; } qsort(world.stored_data, MAX_ACTIVE_ADDRS, sizeof(monitoring_data*), sub_storeptrs); int data_pos = 0; for(int i = 0; i < world.num_active_addrs; i++) { uint8_t addr = world.active_addrs[i]; while(world.stored_data[data_pos] != NULL && world.stored_data[data_pos]->addr != addr) { data_pos++; } if (world.stored_data[data_pos] == NULL) { log("Detected PSU at address 0x%02x\n", addr); //syslog(LOG_INFO, "Detected PSU at address 0x%02x", addr); world.stored_data[data_pos] = alloc_monitoring_data(addr); if (world.stored_data[data_pos] == NULL) { BAIL("allocation failed\n"); } //reset search pos after alloc (post-sorted addrs may already be alloc'd, need to check again) data_pos = 0; continue; } if (world.stored_data[data_pos]->addr == addr) { continue; } BAIL("shouldn't get here!\n"); } cleanup: return error; }
// Sets the phosphate-sugar bond type differently based on the bond // direction. This allows the phosphate to be closer to one sugar // than the other, based on the strand direction. static void pam5_phosphate_sugar_match(struct patternMatch *match) { struct part *p = match->p; struct atom *aPl = p->atoms[match->atomIndices[0]]; struct atom *aSs = p->atoms[match->atomIndices[1]]; struct bond *b = getBond(p, aPl, aSs); BAIL(); struct stretch *s = getStretch(p, aPl, aSs); BAIL(); int reverse; pam5_requires_gromacs(match->p); BAIL(); init_stack_match(); BAIL(); switch (b->direction) { case 'F': reverse = (b->a1 == aSs); break; case 'R': reverse = (b->a1 == aPl); break; default: ERROR2("pam5_phosphate_sugar_match: bond between ids %d and %d has no direction", aPl->atomID, aSs->atomID); p->parseError(p->stream); return; } s->stretchType = reverse ? stretch_5_Ss_Pl_3 : stretch_5_Pl_Ss_3 ; trace_setStretchType(match, s); //printMatch(match); }
// --------------------------------------------------------------------- FskErr FskFSFileOpen(const char *fullPath, UInt32 permissions, FskFSFile *frefOut) { FskErr err; FskFSFile fref; FskFileInfo itemInfo; if (frefOut) *frefOut = NULL; err = sCheckFullPath(fullPath, kFskPathIsFile); BAIL_IF_ERR(err); err = FskFSFileGetFileInfo(fullPath, &itemInfo); BAIL_IF_ERR(err); if (itemInfo.filetype == kFskDirectoryItemIsDirectory) BAIL(kFskErrIsDirectory); err = FskMemPtrNewClear(sizeof(FskFSFileRecord), (FskMemPtr*)(void*)&fref); BAIL_IF_NONZERO(err, err, kFskErrMemFull); fref->thePermissions = permissions; fref->theFile = FOPEN(fullPath, sPermsToPermStr(permissions)); if (!fref->theFile) { FskMemPtrDispose(fref); BAIL(errnoToFskErr(errno)); } *frefOut = fref; bail: return err; }
int dircopy(char *base, char *src[], int nsrc) { char *dest = NULL; int baselen = strlen(base) + 1; /* +1 for '/' */ int i, destlen = 0, ret = 0; #define BAIL() do{ ret = 1; goto bail; } while(0) for(i = 0; i < nsrc; i++){ int newlen = baselen + strlen(src[i]) + 1; if(destlen < newlen){ char *tmp = realloc(dest, newlen); if(!tmp){ perrorf("realloc()"); BAIL(); } dest = tmp; } if(*src[i] != '/') sprintf(dest, "%s/%s", base, src[i]); else strcpy(dest, src[i]); if(copy(dest, src[i])) BAIL(); } bail: free(dest); return ret; }
/* Append string to a named global attribute. Create the attribute if * it doesn't exist. */ static int nccf_append_att(int ncid, const char *name, const char *string) { char *att_str = NULL; size_t len, new_len; int ret; /* Find out if there is an attribute of this name. */ ret = nc_inq_attlen(ncid, NC_GLOBAL, name, &len); if (ret == NC_ENOTATT) { /* Create the attribute. I will null-terminate this * attribute. */ if ((ret = nc_put_att_text(ncid, NC_GLOBAL, name, strlen(string) + 1, string))) return ret; } else if (ret == NC_NOERR) { /* The attribute already exists. Get memory to hold the existing * att plus our version string. Add one for the space, and one * for a terminating null. */ new_len = len + strlen(string) + 1; if (!(att_str = malloc(new_len + 1))) return CF_ENOMEM; /* Get the existing attribute value. */ if ((ret = nc_get_att_text(ncid, NC_GLOBAL, name, att_str))) BAIL(CF_ENETCDF); /* If it's already in the string, our work is done.*/ if (strstr(att_str, string)) { free(att_str); return CF_NOERR; } /* Append our string to the existing att. */ att_str[len] = 0; strcat(att_str, " "); strcat(att_str, string); /* Delete the existing attribute, so we can rewrite it. */ if ((ret = nc_del_att(ncid, NC_GLOBAL, name))) BAIL(ret); /* Rewrite the attribute with our string appended. */ if ((ret = nc_put_att_text(ncid, NC_GLOBAL, name, strlen(att_str) + 1, att_str))) BAIL(ret); } exit: if (att_str) free(att_str); return ret; }
static void pam5_stack_match(struct patternMatch *match) { struct atom *aGv1 = match->p->atoms[match->atomIndices[0]]; struct atom *aGv2 = match->p->atoms[match->atomIndices[1]]; struct atom *aS1a = match->p->atoms[match->atomIndices[2]]; struct atom *aS1b = match->p->atoms[match->atomIndices[3]]; struct atom *aS2a = match->p->atoms[match->atomIndices[4]]; struct atom *aS2b = match->p->atoms[match->atomIndices[5]]; struct atom *vA; struct atom *vB; struct bond *bond; int i; pam5_requires_gromacs(match->p); BAIL(); init_stack_match(); BAIL(); // S1a S2b // | | // Gv1----Gv2 // | | // S1b S2a if (!isExpectedTwist(match->p, aGv1, aGv2, aS1a, aS1b)) { aS1a = match->p->atoms[match->atomIndices[3]]; aS1b = match->p->atoms[match->atomIndices[2]]; } if (!isExpectedTwist(match->p, aGv2, aGv1, aS2a, aS2b)) { aS2a = match->p->atoms[match->atomIndices[5]]; aS2b = match->p->atoms[match->atomIndices[4]]; } // Atoms are now in canonical orientations. The twist is such that // the S1a-S2a distance is greater than the S1b-S2b distance in // BDNA. for (i=0; i<8 && i < numStruts; i++) { vA = makeVirtualAtom(vDa_type[i], sp3, 3, 1, aGv1, aS1a, aS1b, NULL, vDax_p[i], vDax_q[i], 0.0); vB = makeVirtualAtom(vDb_type[i], sp3, 3, 1, aGv2, aS2a, aS2b, NULL, vDbx_p[i], vDbx_q[i], 0.0); bond = makeBond(match->p, vA, vB, '1'); queueAtom(match->p, vA); trace_makeVirtualAtom(match, vA); queueAtom(match->p, vB); trace_makeVirtualAtom(match, vB); queueBond(match->p, bond); trace_makeBond(match, bond); } //printMatch(match); }
static int fsync_dir(const char *name) { char *file = (char*) malloc(sizeof(char)*(strlen(name)+1)); strcpy(file, name); trim_rightmost_path_component(file); FP(stderr, " fsync-ing '%s'\n", file); int fd; if (-1 == (fd = open(file, O_RDONLY))) BAIL("open failed"); if (-1 == fsync(fd)) BAIL("fsync failed"); if (-1 == close(fd)) BAIL("close failed"); free(file); return 0; }
/* fplay_read_header * * Read the header out of a file, and determine if it is WAV or ILDA. */ int fplay_read_header(void) { char buf[8]; int ret = fplay_read(buf, 8); if (ret == 0) return 0; else if (ret != 8) BAIL("short read"); if (!memcmp(buf, "RIFF", 4)) { uint32_t wav_file_size = *(uint32_t *)(buf + 4); fplay_read_check(buf, 8); if (memcmp(buf, "WAVEfmt ", 8)) BAIL("RIFF file not WAV"); return wav_read_file_header(wav_file_size); } /* If it's not WAV, it had better be ILDA */ if (memcmp(buf, "ILDA\0\0\0", 7)) BAIL("file is not WAV or ILDA"); fplay_state = buf[7]; /* Read the rest of the header of this particular frame. */ switch (fplay_state) { case STATE_ILDA_0: case STATE_ILDA_1: case STATE_ILDA_4: case STATE_ILDA_5: /* 2D, 3D, and formats 4 and 5 */ ret = ilda_read_frame_header(); if (ret < 0) return ret; if (fplay_points_left < 0) BAIL("negative points in frame"); /* Zero-length means end of file */ if (fplay_points_left == 0) return 0; /* Save off the beginning of this frame, in case we * need to repeat it. */ fplay_frame_start.fptr = fplay_file.fptr; fplay_frame_start.curr_clust = fplay_file.curr_clust; fplay_frame_start.dsect = fplay_file.dsect; ilda_frame_pointcount = fplay_points_left; break; default: BAILV("ilda: bad format %d", fplay_state); } return 1; }
FskErr FskFSFileMap(const char *fullPath, unsigned char **data, FskInt64 *dataSize, FskFSFileMapping *mapOut) { FskErr err = kFskErrNone; FskFSFileMapping map = NULL; FskInt64 size; int fp; struct stat statbuf; err = sCheckFullPath(fullPath, kFskPathIsFile); if (err) return err; err = FskMemPtrNewClear(sizeof(FskFSFileMappingRecord), (FskMemPtr*)(void*)&map); BAIL_IF_ERR(err); map->file = -1; fp = open(fullPath, O_RDONLY); if (fp < 0) BAIL(errnoToFskErr(errno)); map->file = fp; fstat(map->file, &statbuf); size = statbuf.st_size; if (size > 0xffffffff) BAIL(kFskErrOperationFailed); map->length = size; map->address = mmap(NULL, map->length, PROT_READ, MAP_SHARED, map->file, 0); if (MAP_FAILED == map->address) { map->address = NULL; BAIL(kFskErrOperationFailed); } *data = (unsigned char *)map->address; *dataSize = size; bail: if (kFskErrNone != err) { FskFSFileDisposeMap(map); map = NULL; } *mapOut = map; return err; }
FskErr FskSemaphoreNew_(FskSemaphore *sem, UInt32 value, FSK_SYNCHRONIZATION_DEBUG_ARGS) #endif { FskErr err; err = FskMemPtrNewClear(sizeof(FskSemaphoreRecord), (FskMemPtr *)sem); BAIL_IF_ERR(err); if (((*sem)->hSem = CreateSemaphore(NULL, value, 0x7fffffff, NULL)) == NULL) { BAIL(kFskErrOperationFailed); } FskInstrumentedItemNew(*sem, NULL, &gFskSemaphoreTypeInstrumentation); #if SUPPORT_INSTRUMENTATION && SUPPORT_SYNCHRONIZATION_DEBUG if (FskInstrumentedItemHasListeners(*sem)) { FskSynchronizationInstrMsgRecord msg; msg.file = file; msg.line = line; msg.function = function; FskInstrumentedItemSendMessage(*sem, kFskSynchronizationInstrMsgSemaphoreNew, &msg); } #endif bail: if ((err != kFskErrNone) && (*sem != NULL)) { FskMemPtrDispose(*sem); *sem = NULL; } return err; }
FskErr FskMutexNew_uninstrumented(FskMutex *mutex, const char *name) { FskErr err; pthread_mutexattr_t attr; err = FskMemPtrNewClear(sizeof(FskMutexRecord), (FskMemPtr *)mutex); BAIL_IF_ERR(err); if ((pthread_mutexattr_init(&attr) != 0) || (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) || (pthread_mutex_init(&(*mutex)->mutex, &attr) != 0)) { BAIL(kFskErrOperationFailed); } #if SUPPORT_INSTRUMENTATION (*mutex)->name = FskStrDoCopy_Untracked(name); #endif bail: pthread_mutexattr_destroy(&attr); if ((err != kFskErrNone) && (*mutex != NULL)) { #if SUPPORT_INSTRUMENTATION FskMemPtrDispose((FskMemPtr)(*mutex)->name); #endif FskMemPtrDispose(*mutex); *mutex = NULL; } return err; }
// // convert unicode string to auth type // HRESULT Wstr2AuthType ( IN LPCWSTR pszSrc, OUT PIHV_AUTH_TYPE pAuthType ) { HRESULT hr = S_OK; DWORD dwIndex = 0; if ( (!pAuthType) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } for ( dwIndex = 0; dwIndex < MAX_AUTH_TYPES; dwIndex++ ) { if ( 0 == wcscmp( gppszIhvAuthTypes[dwIndex], pszSrc ) ) { (*pAuthType) = (IHV_AUTH_TYPE) dwIndex; BAIL( ); } } // String not found. hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); error: return hr; }
void evaluateGradientFromPotential(struct configuration *p) { struct functionDefinition *fd; struct configuration *pPlusDelta = NULL; struct configuration *pMinusDelta = NULL; int i; int j; NULLPTR(p); fd = p->functionDefinition; NULLPTR(fd); if (fd->gradient_delta == 0.0) { fd->gradient_delta = 1e-8; } for (i=0; i<fd->dimension; i++) { pPlusDelta = makeConfiguration(fd); for (j=0; j<fd->dimension; j++) { pPlusDelta->coordinate[j] = p->coordinate[j]; } pPlusDelta->coordinate[i] += fd->gradient_delta / 2.0; pMinusDelta = makeConfiguration(fd); for (j=0; j<fd->dimension; j++) { pMinusDelta->coordinate[j] = p->coordinate[j]; } pMinusDelta->coordinate[i] -= fd->gradient_delta / 2.0; p->gradient[i] = (evaluate(pMinusDelta) - evaluate(pPlusDelta)) / fd->gradient_delta; BAIL(); SetConfiguration(&pPlusDelta, NULL); SetConfiguration(&pMinusDelta, NULL); } }
static void pam5_basepair_match(struct patternMatch *match) { struct atom *aS1 = match->p->atoms[match->atomIndices[1]]; struct atom *aS2 = match->p->atoms[match->atomIndices[2]]; struct bond *bond; pam5_requires_gromacs(match->p); BAIL(); init_stack_match(); BAIL(); bond = makeBond(match->p, aS1, aS2, '1'); queueBond(match->p, bond); trace_makeBond(match, bond); //printMatch(match); }
static FskErr FskGPIONew(FskGPIO *gpioOut, int pin, char *pinName, GPIOdirection direction) { FskErr err = kFskErrNone; FskGPIO gpio = NULL; err = FskMemPtrNewClear(sizeof(FskGPIORecord), (FskMemPtr *)&gpio); BAIL_IF_ERR(err); gpio->pinNum = pin; gpio->realPin = FskHardwarePinsMux(pin, kFskHardwarePinGPIO); gpio->thread = FskThreadGetCurrent(); if (gpio->realPin < 0) BAIL(kFskErrInvalidParameter); err = FskGPIOPlatformInit(gpio); BAIL_IF_ERR(err); if (undefined != direction) { err = FskGPIOPlatformSetDirection(gpio, direction); BAIL_IF_ERR(err); } bail: if (err && gpio) { FskGPIOPlatformDispose(gpio); FskMemPtrDisposeAt(&gpio); } *gpioOut = gpio; return err; }
FskErr FskPinI2CNew(FskPinI2C *pin, SInt32 sda, SInt32 sclk, SInt32 bus) { FskErr err; FskPinI2CDispatch dispatch = NULL; UInt32 i = 0; while (true) { SInt32 remappedBus = kFskPinI2CNoBus; FskPinI2CDispatch aDispatch = FskExtensionGetByIndex(kFskExtensionPinI2C, i++); if (NULL == aDispatch) BAIL(kFskErrExtensionNotFound); if ((aDispatch->doCanHandle)(sda, sclk, bus, &remappedBus)) { dispatch = aDispatch; break; } if (kFskPinI2CNoBus != remappedBus) bus = remappedBus; } err = (dispatch->doNew)(pin, sda, sclk, bus); BAIL_IF_ERR(err); (*pin)->dispatch = dispatch; bail: return err; }
FskErr FskPinAnalogNew(FskPinAnalog *pin, SInt32 number, const char *name) { FskErr err; FskPinAnalogDispatch dispatch = NULL; UInt32 i = 0; while (true) { FskPinAnalogDispatch aDispatch = FskExtensionGetByIndex(kFskExtensionPinAnalog, i++); if (NULL == aDispatch) BAIL(kFskErrExtensionNotFound); if ((aDispatch->doCanHandle)(number, name, &number)) { dispatch = aDispatch; break; } } err = (dispatch->doNew)(pin, number, name); BAIL_IF_ERR(err); (*pin)->dispatch = dispatch; bail: return err; }
// // convert unicode string to cipher type // HRESULT Wstr2CipherType ( _In_ LPCWSTR pszSrc, _Out_ PIHV_CIPHER_TYPE pCipherType ) { HRESULT hr = S_OK; DWORD dwIndex = 0; if ( (!pCipherType) || (!pszSrc) ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } for ( dwIndex = 0; dwIndex < MAX_CIPHER_TYPES; dwIndex++ ) { if ( 0 == wcscmp( gppszIhvCipherTypes[dwIndex], pszSrc ) ) { (*pCipherType) = (IHV_CIPHER_TYPE) dwIndex; BAIL( ); } } // String not found. hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); error: return hr; }
// Convert unicode string to BSTR. NULL safe. HRESULT Wstr2Bstr ( _In_ LPCWSTR pszSrc, _Outptr_ BSTR* pbstrDest ) { HRESULT hr = S_OK; if ( !pbstrDest ) { hr = E_INVALIDARG; BAIL_ON_FAILURE( hr ); } (*pbstrDest) = NULL; if ( !pszSrc ) { BAIL( ); } (*pbstrDest) = SysAllocString( pszSrc ); if ( !(*pbstrDest) ) { hr = E_OUTOFMEMORY; BAIL_ON_FAILURE( hr ); } error: return hr; }
int nccf_inq_convention(int ncid, int *cf_convention) { size_t len, new_len; char *existing_att = NULL; int ret = CF_NOERR; /* Find out if there is a conventions attribute. */ ret = nc_inq_attlen(ncid, NC_GLOBAL, CF_CONVENTIONS, &len); if (ret == NC_NOERR) { /* Get memory to hold the existing att plus our version * string. */ new_len = len + strlen(CF_CONVENTION_STRING) + 1; if (!(existing_att = malloc(new_len))) return CF_ENOMEM; /* Get the existing att. */ if ((ret = nc_get_att_text(ncid, NC_GLOBAL, CF_CONVENTIONS, existing_att))) BAIL(CF_ENETCDF); /* If it's already in the string, our work is done.*/ if (strstr(existing_att, CF_CONVENTION_STRING)) { if (cf_convention) *cf_convention = 1; ret = CF_NOERR; } } else if (ret == NC_ENOTATT) { /* No conventions att means no cf conventions. ;-( But this is * not an error. */ if (cf_convention) *cf_convention = 0; ret = NC_NOERR; } else BAIL(CF_ENETCDF); exit: if (existing_att) free(existing_att); return ret; }
int cmd_flamewall(string str) { object tp=this_player(); object env=environment(tp); object fw; int py, md, intel; if (!spell()) return 0; if (tp->query_disable()) return 1; if (env->query_property("no attack") || env->query_property("no magic")) BAIL("You cannot cast that here.\n"); if (present("flamewallobj",env)) BAIL("There is already a flamewall here!\n"); py= tp->query_skill("pyromancy"); md= tp->query_skill("magic defense"); intel= tp->query_stats("intelligence"); if (tp->query_mp() < (py+md+intel)*2/5) BAIL("You are too low on magic.\n"); tp->add_mp(-(py+md+intel)*2/5+random(50)); message("info","%^BOLD%^You wave your hand in a circle and " "a %^RED%^ring of flame%^RESET%^%^BOLD%^ shoots up around you!",tp); message("info","%^BOLD%^"+tp->query_cap_name()+" waves "+ tp->query_possessive()+" hand around and a %^RED%^ring of flame" "%^RESET%^%^BOLD%^ shoots up around "+tp->query_objective()+"!", env, tp); tp->add_skill_points("pyromancy",md/20); tp->add_skill_points("magic defense",py/30); fw=new(PLACE"flamewallobj"); fw->set_owner(tp); fw->set_strength(py/3+md/4+intel*3/2); fw->set_time(py/30+md/25+3+random(3)); fw->move(env); fw->heart_beat(); return 1; }
static int fsync_paranoid(const char *name) { char rp[1+PATH_MAX], *file = (char *) malloc(sizeof(char)*(strlen(name)+1)); strcpy(file, name); FP(stderr, "fsync to root '%s'\n", file); if (NULL == realpath(file, rp)) BAIL("realpath failed"); FP(stderr, " realpath '%s'\n", rp); do { int fd; FP(stderr, " fsync-ing '%s'\n", rp); if (-1 == (fd = open(rp, O_RDONLY))) BAIL("open failed"); if (-1 == fsync(fd)) BAIL("fsync failed"); if (-1 == close(fd)) BAIL("close failed"); trim_rightmost_path_component(rp); } while (*rp); FP(stderr, " done\n"); free(file); return 0; }
// base function to obtain text from // node described by XPATH. HRESULT CIhvProfileBase::GetTextFromNode ( IN LPCWSTR pszQuery, OUT BSTR* pbstrText ) { HRESULT hr = S_OK; BSTR bstrQuery = NULL; IXMLDOMNode* pQueryNode = NULL; ASSERT( pszQuery ); ASSERT( pbstrText ); // if node is NULL, return empty string. if ( !m_pRootNode ) { hr = Wstr2Bstr ( L"", pbstrText ); BAIL( ); } hr = Wstr2Bstr ( pszQuery, &bstrQuery ); BAIL_ON_FAILURE( hr ); hr = m_pRootNode->selectSingleNode( bstrQuery, &pQueryNode ); BAIL_ON_FAILURE( hr ); if (!pQueryNode) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } hr = pQueryNode->get_text( pbstrText ); BAIL_ON_FAILURE( hr ); if ( !(*pbstrText) ) { hr = E_UNEXPECTED; BAIL_ON_FAILURE( hr ); } error: RELEASE_INTERFACE( pQueryNode ); SYS_FREE_STRING( bstrQuery ); return hr; }
void ring_add(Node *node) { num_nodes++; if ((nodes = realloc(nodes, sizeof(void*) * num_nodes)) == NULL) { BAIL("Failed to realloc rings array"); } nodes[num_nodes] = node; }
FskErr KprDBStatementNew(KprDBStatement* it, KprDB db, const char* text, char* bindFormat, char* rowFormat) { FskErr err = kFskErrNone; KprDBStatement self = NULL; SInt32 count, size, i; bailIfError(KprMemPtrNewClear(sizeof(KprDBStatementRecord), it)); self = *it; FskInstrumentedItemNew(self, NULL, &KprDBStatementInstrumentation); bailIfError(sqlite3_prepare_v2(db->data, text, FskStrLen(text), &self->data, NULL)); count = sqlite3_bind_parameter_count(self->data); if (count && !bindFormat) BAIL(kFskErrInvalidParameter); if (!count && bindFormat) BAIL(kFskErrInvalidParameter); if (count) { if ((SInt32)FskStrLen(bindFormat) != count) BAIL(kFskErrInvalidParameter); self->bindFormat = FskStrDoCopy(bindFormat); bailIfNULL(self->bindFormat); } count = sqlite3_column_count(self->data); if (count && !rowFormat) BAIL(kFskErrInvalidParameter); if (!count && rowFormat) BAIL(kFskErrInvalidParameter); if (count) { if ((SInt32)FskStrLen(rowFormat) != count) BAIL(kFskErrInvalidParameter); self->rowFormat = FskStrDoCopy(rowFormat); bailIfNULL(self->rowFormat); bailIfError(KprMemPtrNewClear(count * sizeof(char*), &self->keys)); for (size = 0, i = 0; rowFormat[i]; i++) { self->keys[i] = sqlite3_column_name(self->data, i); switch (rowFormat[i]) { case 'b': size += sizeof(void*) + sizeof(UInt32); break; case 'd': size += sizeof(double); break; case 'i': size += sizeof(SInt32); break; case 'I': size += sizeof(FskInt64); break; case 'r': size += sizeof(SInt32); break; case 't': size += sizeof(char*); break; default: BAIL(kFskErrInvalidParameter); break; } } bailIfError(KprMemPtrNewClear(size, &self->values)); } bail: if (err) KprDBStatementDispose(self); return err; }
// Creates the Gv-Pl interaction, which replaces the Gv-Ss-Pl bend // term. Only do this on the 5' side. static void pam5_groove_phosphate_match(struct patternMatch *match) { struct part *p = match->p; struct atom *aGv = p->atoms[match->atomIndices[0]]; struct atom *aSs = p->atoms[match->atomIndices[1]]; struct atom *aPl = p->atoms[match->atomIndices[2]]; struct bond *b = getBond(p, aPl, aSs); BAIL(); struct bond *bond; struct bend *bend; int reverse; char order; pam5_requires_gromacs(p); BAIL(); switch (b->direction) { case 'F': reverse = (b->a1 == aSs); break; case 'R': reverse = (b->a1 == aPl); break; default: ERROR2("pam5_phosphate_sugar_match: bond between ids %d and %d has no direction", aPl->atomID, aSs->atomID); p->parseError(p->stream); return; } if (reverse) { order = '2'; } else { order = '1'; bend = getBend(p, aGv, aSs, aPl); bend->bendType = bend_Gv_Ss_Pl_5; } bond = makeBond(p, aPl, aGv, order); queueBond(p, bond); trace_makeBond(match, bond); //printMatch(match); }
int main() { int ncid, temp_varid, dimids[NUMDIMS]; float temp[LAT_LEN][LON_LEN], *fp; char classic_file[] = "classic.nc", offset64_file[] = "offset.nc"; char *file = classic_file; int i, res; /* Create a bunch of phoney data so we have something to write in the example file. */ for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++) *fp++ = 10. + i/10.; /* Now create the file in both formats with the same code. */ for (i=0; i<2; i++) { if (i==1) /* 64-bit offset format file */ { file = offset64_file; if ((res = nc_set_default_format(NC_FORMAT_64BIT, NULL))) BAIL(res); } /* Create the netCDF file. */ if ((res = nc_create(file, NC_CLOBBER, &ncid))) BAIL(res); /* Define dimensions. */ if ((res = nc_def_dim(ncid, "latitude", LAT_LEN, dimids))) BAIL(res); if ((res = nc_def_dim(ncid, "longitude", LON_LEN, &dimids[1]))) BAIL(res); /* Define the variable. */ if ((res = nc_def_var(ncid, "sfc_temp", NC_FLOAT, NUMDIMS, dimids, &temp_varid))) BAIL(res); /* We're finished defining metadata. */ if ((res = nc_enddef(ncid))) BAIL(res); if ((res = nc_put_var_float(ncid, temp_varid, (float *)temp))) BAIL(res); /* We're done! */ if ((res = nc_close(ncid))) BAIL(res); } return 0; }