static void growstackblock(int min) { char *p; int newlen; char *oldspace; int oldlen; struct stack_block *sp; struct stack_block *oldstackp; struct stackmark *xmark; if (min < stacknleft) min = stacknleft; if (min >= INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) error("Out of space"); min += stacknleft; min += ALIGN(sizeof(struct stack_block)); newlen = 512; while (newlen < min) newlen <<= 1; oldspace = stacknxt; oldlen = stacknleft; if (stackp != NULL && stacknxt == SPACE(stackp)) { INTOFF; oldstackp = stackp; stackp = oldstackp->prev; sp = ckrealloc((pointer)oldstackp, newlen); sp->prev = stackp; stackp = sp; stacknxt = SPACE(sp); stacknleft = newlen - (stacknxt - (char*)sp); sstrend = stacknxt + stacknleft; /* * Stack marks pointing to the start of the old block * must be relocated to point to the new block */ xmark = markp; while (xmark != NULL && xmark->stackp == oldstackp) { xmark->stackp = stackp; xmark->stacknxt = stacknxt; xmark->stacknleft = stacknleft; xmark = xmark->marknext; } INTON; } else { newlen -= ALIGN(sizeof(struct stack_block)); p = stalloc(newlen); if (oldlen != 0) memcpy(p, oldspace, oldlen); stunalloc(p); } }
/* Strip white space off a string ** ** On exit, ** Return value points to first non-white character, or to 0 if none. ** All trailing white space is overwritten with zero. */ PRIVATE char * strip(char * s) { #define SPACE(c) ((c==' ')||(c=='\t')||(c=='\n')) char * p=s; for(p=s;*p;p++); /* Find end of string */ for(p--;p>=s;p--) { if(SPACE(*p)) *p=0; /* Zap trailing blanks */ else break; } while(SPACE(*s))s++; /* Strip leading blanks */ return s; }
void block_free(byte *block, size_t size) { unsigned int space_nr = SPACE(block); unsigned int block_nr = BLOCK_NR(block); size_t blocks = BLOCKS(size); byte *block_map = SPACE_MAP(space_nr); int i; int ok = 1; for(i=0; i<blocks; ++i) block_map[block_nr+i] = TYPE_FREE; /* See if we can free the entire space */ for (i=0; i<BLOCKS_PER_SPACE; i++) { if (block_map[i] != TYPE_FREE) { ok = 0; break; } } unmap(block, GRAINROUND(page_size, size)); if (ok) { /* Free the entire space */ release_arena_space(space_nr); } }
void growstackblock(void) { char *p; int newlen; char *oldspace; int oldlen; struct stack_block *sp; struct stack_block *oldstackp; struct stackmark *xmark; newlen = (stacknleft == 0) ? MINSIZE : stacknleft * 2 + 100; newlen = ALIGN(newlen); oldspace = stacknxt; oldlen = stacknleft; if (stackp != NULL && stacknxt == SPACE(stackp)) { INTOFF; oldstackp = stackp; stackp = oldstackp->prev; sp = ckrealloc((pointer)oldstackp, newlen); sp->prev = stackp; stackp = sp; stacknxt = SPACE(sp); stacknleft = newlen - (stacknxt - (char*)sp); /* * Stack marks pointing to the start of the old block * must be relocated to point to the new block */ xmark = markp; while (xmark != NULL && xmark->stackp == oldstackp) { xmark->stackp = stackp; xmark->stacknxt = stacknxt; xmark->stacknleft = stacknleft; xmark = xmark->marknext; } INTON; } else { p = stalloc(newlen); if (oldlen != 0) memcpy(p, oldspace, oldlen); stunalloc(p); } }
static int reserve_arena_space(caddr_t *base) { int space; *base = mmap((void *)0, SPACE_SIZE, PROT_NONE, MAP_SHARED | MAP_AUTORESRV, zero_device, (off_t)0); if (*base == (caddr_t)-1 || ((unsigned long)*base) > ARENA_LIMIT) { /* Failed to reserve */ return 1; } space = SPACE(((word)(*base)) + (SPACE_SIZE) -1); if ((caddr_t)(SPACE_BASE(space)) != *base) { /* Oh dear, we've got an unaligned piece of space */ /* Unmap it, get double then junk the bits on the ends */ if (munmap(*base, SPACE_SIZE) == -1) { error("munmap(1)(0x%x, 0x%x) has returned an unexpected error code %d meaning %s", *base, SPACE_SIZE, errno, strerror(errno)); } *base = mmap((void *)0, 2*(SPACE_SIZE), PROT_NONE, MAP_SHARED | MAP_AUTORESRV, zero_device, (off_t)0); if (*base == (caddr_t)-1) { /* Failed to reserve */ return 1; } /* Now unmap the bits over at the start and end */ space = SPACE(((word)(*base)) + (SPACE_SIZE) -1); if ((caddr_t)(SPACE_BASE(space)) != *base) { /* unmap the leftover at the start */ if (munmap(*base, (unsigned long)(SPACE_BASE(space))-(unsigned long)(*base)) == -1) { error("munmap(2)(0x%x, 0x%x) has returned an unexpected error code %d meaning %s", *base, (unsigned long)(SPACE_BASE(space))-(unsigned long)(*base), errno, strerror(errno)); } } if (((unsigned long)(SPACE_BASE(space+1))) != ((unsigned long)(*base)) + 2 *(SPACE_SIZE)) { /* unmap the leftover at the end */ if (munmap((caddr_t)(SPACE_BASE(space+1)), (unsigned long)(*base)-((unsigned long)(SPACE_BASE(space-1)))) == -1) { error("munmap(3)(0x%x, 0x%x) has returned an unexpected error code %d meaning %s", SPACE_BASE(space+1), (unsigned long)(*base)-((unsigned long)(SPACE_BASE(space-1))), errno, strerror(errno)); } } } space_type[space] = TYPE_FREE; space_extent[space] = 0; SPACE_MAP(space) = NULL; return 0; }
void setstackmark(struct stackmark *mark) { mark->stackp = stackp; mark->stacknxt = stacknxt; mark->stacknleft = stacknleft; /* Ensure this block stays in place. */ if (stackp != NULL && stacknxt == SPACE(stackp)) stalloc(1); }
static void growstackblock(int min) { char *p; int newlen; char *oldspace; int oldlen; struct stack_block *sp; struct stack_block *oldstackp; if (min < stacknleft) min = stacknleft; if ((unsigned int)min >= INT_MAX / 2 - ALIGN(sizeof(struct stack_block))) error("Out of space"); min += stacknleft; min += ALIGN(sizeof(struct stack_block)); newlen = 512; while (newlen < min) newlen <<= 1; oldspace = stacknxt; oldlen = stacknleft; if (stackp != NULL && stacknxt == SPACE(stackp)) { INTOFF; oldstackp = stackp; stackp = oldstackp->prev; sp = ckrealloc((pointer)oldstackp, newlen); sp->prev = stackp; stackp = sp; stacknxt = SPACE(sp); stacknleft = newlen - (stacknxt - (char*)sp); sstrend = stacknxt + stacknleft; INTON; } else { newlen -= ALIGN(sizeof(struct stack_block)); p = stalloc(newlen); if (oldlen != 0) memcpy(p, oldspace, oldlen); stunalloc(p); } }
/* TODO */ void BfastFasta2BRGPrintProgramParameters(FILE* fp, struct arguments *args) { fprintf(fp, BREAK_LINE); fprintf(fp, "Printing Program Parameters:\n"); fprintf(fp, "programMode:\t\t\t\t%s\n", PROGRAMMODE(args->programMode)); fprintf(fp, "fastaFileName:\t\t\t\t%s\n", FILEREQUIRED(args->fastaFileName)); fprintf(fp, "space:\t\t\t\t\t%s\n", SPACE(args->space)); fprintf(fp, "timing:\t\t\t\t\t%s\n", INTUSING(args->timing)); fprintf(fp, BREAK_LINE); return; }
static void unmap(void *start, size_t length) { /* We simply rereserve this via mmap on reserve_device, * rather than unmapping */ int space = SPACE(start); off_t offset = (unsigned long)start - (unsigned long)(SPACE_BASE(space)); if (length > 0 && mmap(start, length, PROT_NONE, MAP_FIXED | MAP_SHARED, zero_device, offset) == (caddr_t)-1) { error("unmap has failed with an unexpected error code %d meaning %s\n", errno, strerror(errno)); }; arena_extent -= length; }
void space_resize(byte *space, size_t extent) { unsigned int space_no = SPACE(space); size_t current = space_extent[space_no]; extent = grain_round(extent); if(extent > current) map(space+current, extent-current); else if(current > extent) unmap(space+extent, current-extent); space_extent[space_no] = extent; }
byte *block_alloc(byte type, size_t size) { int s, b, found = 0, blocks = BLOCKS(size); byte *block_map; byte *space; if (arena_state != INITIALIZED) arena_init(); if (blocks > BLOCKS_PER_SPACE) error("Trying to allocate too many contiguous blocks."); for(s=0; s<SPACES_IN_ARENA; ++s) { if (space_type[s] == TYPE_BLOCKS) { block_map = SPACE_MAP(s); for (b=0; b<BLOCKS_PER_SPACE; b++) { if (block_map[b] == TYPE_FREE) { found ++; if(found >= blocks) { int start = b+1-found, k; for(k=start; k<=b; ++k) block_map[k] = type; map(BLOCK_BASE(s,start), GRAINROUND(page_size, size)); return(BLOCK_BASE(s,start)); } } else found = 0; } found = 0; } } /* None of the existing block spaces have room; let's make a new one */ space = space_alloc(TYPE_BLOCKS,0); /* allocate the new space */ s = SPACE(space); block_map = SPACE_MAP(s) = block_maps + s*BLOCKS_PER_SPACE; /* This is where the map is */ for(b=0; b< blocks; ++b) block_map[b] = type; for (b=blocks; b < BLOCKS_PER_SPACE; b++) block_map[b] = TYPE_FREE; /* ... and initialize it */ map(space, GRAINROUND(page_size, size)); return(space); }
void space_resize(byte *space, size_t extent) { unsigned int space_no = SPACE(space); size_t mapped = space_mapped[space_no]; extent = grain_round(extent); if(extent > mapped) { map(space+mapped, extent-mapped); space_mapped[space_no] = extent; } else if(extent == 0) { unmap(space, mapped); space_mapped[space_no] = 0; } space_extent[space_no] = extent; }
// put the rest of the page into the freelist void allocSpaceLeft(int index) { bufHeader_t* bufPtr; kma_size_t reqSpace; while(index >= 0) { reqSpace = SPACE(index); while((kflPtr->freespaceSize - reqSpace) >= 0) { bufPtr = (bufHeader_t*) kflPtr->freespacePtr; bufPtr->ptr = (void*)&kflPtr->p2fl[index]; kflPtr->freespaceSize -= reqSpace; kflPtr->freespacePtr += reqSpace; } index--; } }
/* TODO */ void BfastAlignPrintProgramParameters(FILE* fp, struct arguments *args) { if(0 <= VERBOSE) { fprintf(fp, BREAK_LINE); fprintf(fp, "Printing Program Parameters:\n"); fprintf(fp, "programMode:\t\t\t\t%s\n", PROGRAMMODE(args->programMode)); fprintf(fp, "fastaFileName:\t\t\t\t%s\n", FILEREQUIRED(args->fastaFileName)); fprintf(fp, "readsFileName:\t\t\t\t%s\n", FILESTDIN(args->readsFileName)); fprintf(fp, "compression:\t\t\t\t%s\n", COMPRESSION(args->compression)); fprintf(fp, "space:\t\t\t\t\t%s\n", SPACE(args->space)); fprintf(fp, "numThreads:\t\t\t\t%d\n", args->numThreads); fprintf(fp, "tmpDir:\t\t\t\t\t%s\n", args->tmpDir); fprintf(fp, "timing:\t\t\t\t\t%s\n", INTUSING(args->timing)); fprintf(fp, BREAK_LINE); } return; }
static void stnewblock(int nbytes) { struct stack_block *sp; int allocsize; if (nbytes < MINSIZE) nbytes = MINSIZE; allocsize = ALIGN(sizeof(struct stack_block)) + ALIGN(nbytes); INTOFF; sp = ckmalloc(allocsize); sp->prev = stackp; stacknxt = SPACE(sp); stacknleft = allocsize - (stacknxt - (char*)sp); stackp = sp; INTON; }
void kma_free(void* ptr, kma_size_t size) { // return size is larger than half page // simply free the page if(size > MAXSPACE / 2) { kpage_t* page = *((kpage_t**)((void*)ptr - sizeof(kpage_t*))); free_page(page); return; } // put the return buffer into the freelist int index = NDX(size + sizeof(bufHeader_t)); kma_size_t reqSpace = SPACE(index); bufHeader_t* bufPtr; bufPtr = (bufHeader_t*)(ptr - sizeof(bufHeader_t)); bufPtr->ptr = kflPtr->p2fl[index]; kflPtr->p2fl[index] = bufPtr; kflPtr->spaceUsed -= reqSpace; // if all buffers are returned, free all pages cleanupKFL(); }
void* kma_malloc(kma_size_t size) { // Check if the request is valid if(size > MAXSPACE) { printf("ERROR: too large request!\n"); return NULL; } // If no page is present in kernel // get a new page and initialize the header if(kflPtr == NULL) { if(initKFL(size)) return NULL; } // If the request size is larger than half page // simply return a whole page if(size > MAXSPACE / 2) { kpage_t* page; page = get_page(); *((kpage_t**)(page->ptr)) = page; return page->ptr + sizeof(kpage_t*); } // Roundup the size and calculate the index and size int index = NDX(size + sizeof(bufHeader_t)); kma_size_t reqSpace = SPACE(index); bufHeader_t* bufPtr; bool reqNewPage; // printf("size: %d\tindex: %d\t request space: %d\n", size, index, reqSpace); do { reqNewPage = FALSE; if(kflPtr->p2fl[index] == NULL) // No avalible buffer in freelist { if((reqSpace <= kflPtr->freespaceSize)) // cut a buffer from the current page { bufPtr = (bufHeader_t*) kflPtr->freespacePtr; kflPtr->freespaceSize -= reqSpace; kflPtr->freespacePtr += reqSpace; kflPtr->spaceUsed += reqSpace; return (void*)bufPtr + sizeof(bufHeader_t); } else // get a new page and initialize the header { allocSpaceLeft(index-1); initKFL(size); reqNewPage = TRUE; } } else // remove the buffer from the freelist and return it { bufPtr = kflPtr->p2fl[index]; kflPtr->p2fl[index] = (bufHeader_t*)bufPtr->ptr; kflPtr->spaceUsed += (int)reqSpace; return (void*)bufPtr + sizeof(bufHeader_t); } }while(reqNewPage); return NULL; }
void Instruction::print() const { #define BUFSZ 512 const size_t size = BUFSZ; char buf[BUFSZ]; int s, d; size_t pos = 0; PRINT("%s", colour[TXT_INSN]); if (join) PRINT("join "); if (predSrc >= 0) { const size_t pre = pos; if (getSrc(predSrc)->reg.file == FILE_PREDICATE) { if (cc == CC_NOT_P) PRINT("not"); } else { PRINT("%s", CondCodeStr[cc]); } if (pos > pre) SPACE(); pos += getSrc(predSrc)->print(&buf[pos], BUFSZ - pos); PRINT(" %s", colour[TXT_INSN]); } if (saturate) PRINT("sat "); if (asFlow()) { PRINT("%s", operationStr[op]); if (asFlow()->indirect) PRINT(" ind"); if (asFlow()->absolute) PRINT(" abs"); if (op == OP_CALL && asFlow()->builtin) { PRINT(" %sBUILTIN:%i", colour[TXT_BRA], asFlow()->target.builtin); } else if (op == OP_CALL && asFlow()->target.fn) { PRINT(" %s%s:%i", colour[TXT_BRA], asFlow()->target.fn->getName(), asFlow()->target.fn->getLabel()); } else if (asFlow()->target.bb) PRINT(" %sBB:%i", colour[TXT_BRA], asFlow()->target.bb->getId()); } else { PRINT("%s ", operationStr[op]); if (op == OP_LINTERP || op == OP_PINTERP) PRINT("%s ", interpStr[ipa]); switch (op) { case OP_SUREDP: case OP_ATOM: if (subOp < ARRAY_SIZE(atomSubOpStr)) PRINT("%s ", atomSubOpStr[subOp]); break; case OP_LOAD: case OP_STORE: if (subOp < ARRAY_SIZE(ldstSubOpStr)) PRINT("%s ", ldstSubOpStr[subOp]); break; case OP_SUBFM: if (subOp < ARRAY_SIZE(subfmOpStr)) PRINT("%s ", subfmOpStr[subOp]); break; case OP_SHFL: if (subOp < ARRAY_SIZE(shflOpStr)) PRINT("%s ", shflOpStr[subOp]); break; case OP_PIXLD: if (subOp < ARRAY_SIZE(pixldOpStr)) PRINT("%s ", pixldOpStr[subOp]); break; case OP_RCP: case OP_RSQ: if (subOp < ARRAY_SIZE(rcprsqOpStr)) PRINT("%s ", rcprsqOpStr[subOp]); break; case OP_EMIT: if (subOp < ARRAY_SIZE(emitOpStr)) PRINT("%s ", emitOpStr[subOp]); break; default: if (subOp) PRINT("(SUBOP:%u) ", subOp); break; } if (perPatch) PRINT("patch "); if (asTex()) PRINT("%s %s$r%u $s%u %s", asTex()->tex.target.getName(), colour[TXT_MEM], asTex()->tex.r, asTex()->tex.s, colour[TXT_INSN]); if (postFactor) PRINT("x2^%i ", postFactor); PRINT("%s%s", dnz ? "dnz " : (ftz ? "ftz " : ""), DataTypeStr[dType]); } if (rnd != ROUND_N) PRINT(" %s", RoundModeStr[rnd]); if (defExists(1)) PRINT(" {"); for (d = 0; defExists(d); ++d) { SPACE(); pos += getDef(d)->print(&buf[pos], size - pos); } if (d > 1) PRINT(" %s}", colour[TXT_INSN]); else if (!d && !asFlow()) PRINT(" %s#", colour[TXT_INSN]); if (asCmp()) PRINT(" %s%s", colour[TXT_INSN], CondCodeStr[asCmp()->setCond]); if (sType != dType) PRINT(" %s%s", colour[TXT_INSN], DataTypeStr[sType]); for (s = 0; srcExists(s); ++s) { if (s == predSrc || src(s).usedAsPtr) continue; const size_t pre = pos; SPACE(); pos += src(s).mod.print(&buf[pos], BUFSZ - pos); if (pos > pre + 1) SPACE(); if (src(s).isIndirect(0) || src(s).isIndirect(1)) pos += getSrc(s)->asSym()->print(&buf[pos], BUFSZ - pos, getIndirect(s, 0), getIndirect(s, 1)); else pos += getSrc(s)->print(&buf[pos], BUFSZ - pos, sType); } if (exit) PRINT("%s exit", colour[TXT_INSN]); PRINT("%s", colour[TXT_DEFAULT]); buf[MIN2(pos, BUFSZ - 1)] = 0; INFO("%s (%u)\n", buf, encSize); }
void arena_init(void) { int first_block_space = 0, i; switch (arena_state) { case UNINITIALIZED: { arena_state = INITIALIZING; page_size = getpagesize(); zero_device = open("/dev/zero", O_RDONLY); if(zero_device == -1) error_without_alloc("Arena initializing unable to open /dev/zero."); /* First mark all spaces reserved */ for (i = 0; i < NR_SPACES; i++) { space_type[i] = TYPE_RESERVED; space_extent[i] = (size_t)-1; SPACE_MAP(i) = NULL; } /* Now allocate the spaces we want */ for (i = 0; i < 2; i++) { int space; caddr_t base; if (reserve_arena_space(&base)) { error_without_alloc("Arena initializing unable to reserve memory\n"); } space = SPACE(((word)base) + (SPACE_SIZE) -1); if (first_block_space == 0) { /* Allocate first block space to what we've just got */ int i; first_block_space = space; for (i=0; i < BLOCKS_PER_SPACE; ++i) { first_block_space_map[i] = TYPE_FREE; } SPACE_MAP(first_block_space) = first_block_space_map; space_type[first_block_space] = TYPE_BLOCKS; space_extent[first_block_space] = (size_t)-2; } } arena_extent = 0; #ifdef COLLECT_STATS max_arena_extent = 0; #endif arena_state = INITIALIZED; /* The arena is now initialized, so we can call block_alloc */ block_maps = block_alloc(TYPE_RESERVED, (unsigned long)SPACES_IN_ARENA*BLOCKS_PER_SPACE); break; } case INITIALIZING: error_without_alloc("Allocation during arena startup."); case INITIALIZED: /* Could get to here if we alloc before arena_init gets called. */ break; default: error_without_alloc("Arena state inconsistent."); } }
void debugmsg(jia_msg_t *msg, int right) { SPACE(right); printf("********Print message********\n"); SPACE(right); switch (msg->op) { case DIFF: printf("msg.op = DIFF \n"); break; case DIFFGRANT: printf("msg.op = DIFFGRANT\n"); break; case GETP: printf("msg.op = GETP \n"); break; case GETPGRANT: printf("msg.op = GETPGRANT\n"); break; case ACQ: printf("msg.op = ACQ \n"); break; case ACQGRANT: printf("msg.op = ACQGRANT \n"); break; case INVLD: printf("msg.op = INVLD \n"); break; case BARR: printf("msg.op = BARR \n"); break; case BARRGRANT: printf("msg.op = BARRGRANT\n"); break; case REL: printf("msg.op = REL \n"); break; case WTNT: printf("msg.op = WTNT \n"); break; case STAT: printf("msg.op = STAT \n"); break; case STATGRANT: printf("msg.op = STATGRANT\n"); break; case JIAEXIT: printf("msg.op = JIAEXIT \n"); break; default: printf("msg.op = %d \n",msg->op); break; } SPACE(right); printf("msg.frompid = %d\n",msg->frompid); SPACE(right); printf("msg.topid = %d\n",msg->topid); SPACE(right); printf("msg.syn = %d\n",msg->syn); SPACE(right); printf("msg.seqno = %d\n",msg->seqno); SPACE(right); printf("msg.index = %d\n",msg->index); SPACE(right); printf("msg.size = %d\n",msg->size); SPACE(right); printf("msg.data = 0x%8lx\n",stol(msg->data)); SPACE(right); printf("msg.data = 0x%8lx\n",stol(msg->data+4)); SPACE(right); printf("msg.data = 0x%8lx\n",stol(msg->data+8)); }
char * dn_normalize( char *dn ) { char *d, *s; int state, gotesc; gotesc = 0; state = B4TYPE; for ( d = s = dn; *s; s++ ) { switch ( state ) { case B4TYPE: if ( ! SPACE( *s ) ) { state = INTYPE; *d++ = *s; } break; case INTYPE: if ( *s == '=' ) { state = B4VALUE; *d++ = *s; } else if ( SPACE( *s ) ) { state = B4EQUAL; } else { *d++ = *s; } break; case B4EQUAL: if ( *s == '=' ) { state = B4VALUE; *d++ = *s; } else if ( ! SPACE( *s ) ) { /* not a valid dn - but what can we do here? */ *d++ = *s; } break; case B4VALUE: if ( *s == '"' ) { state = INQUOTEDVALUE; *d++ = *s; } else if ( ! SPACE( *s ) ) { state = INVALUE; *d++ = *s; } break; case INVALUE: if ( !gotesc && SEPARATOR( *s ) ) { while ( SPACE( *(d - 1) ) ) d--; state = B4TYPE; if ( *s == '+' ) { *d++ = *s; } else { *d++ = ','; } } else if ( gotesc && !NEEDSESCAPE( *s ) && !SEPARATOR( *s ) ) { *--d = *s; d++; } else { *d++ = *s; } break; case INQUOTEDVALUE: if ( !gotesc && *s == '"' ) { state = B4SEPARATOR; *d++ = *s; } else if ( gotesc && !NEEDSESCAPE( *s ) ) { *--d = *s; d++; } else { *d++ = *s; } break; case B4SEPARATOR: if ( SEPARATOR( *s ) ) { state = B4TYPE; *d++ = *s; } break; default: fprintf (stderr, "dn_normalize - unknown state %d dn:%s \n", state, dn ); break; } if ( *s == '\\' ) { gotesc = 1; } else { gotesc = 0; } } *d = '\0'; return( dn ); }
void CSyncHttpConnection::StateChange(THttpEngineState aState) { iEngineStatus = aState; //CommonUtils::WriteLogL(_L("CSyncHttpConnection::StateChange iEngineStatus = "), iEngineStatus); switch (aState) { case EHttpError: case EHttpGetHeaderTimeOut: case EHttpGetBodyTimeOut: case EHttpFinished: if (iWait->IsStarted()) { iWait->AsyncStop(); } break; case EGetHeader: break; case ERedirect: { HBufC8* head = iConnection->GetResponeHeader(); TPtrC8 redirectUrl; if (head) { _LIT8(GOHREF, "Location:"); TInt redirectUrlIndex = head->FindC(GOHREF); if (redirectUrlIndex >= 0) { redirectUrl.Set(head->Right(head->Length() - redirectUrlIndex - GOHREF().Length())); _LIT8(SPACE, " "); redirectUrlIndex = redirectUrl.FindC(SPACE); while (redirectUrlIndex == 0) { redirectUrl.Set(redirectUrl.Right(redirectUrl.Length() - redirectUrlIndex - SPACE().Length())); redirectUrlIndex = redirectUrl.FindC(SPACE); } redirectUrlIndex = redirectUrl.FindC(_L8("\r\n")); if (redirectUrlIndex >= 0) { redirectUrl.Set(redirectUrl.Left(redirectUrlIndex)); } } } if (redirectUrl.Length() > 0) { TBuf<200> aUri; aUri.Copy(redirectUrl); //CommonUtils::WriteLogL(_L("CSyncHttpConnection::StateChange redirectUrl = "), aUri); iConnection->ResetVarible(); iConnection->Stop(); iConnection->GetRequestL(aUri, 0); iConnection->sendRequest(); } else { //CommonUtils::WriteLogL(_L("CSyncHttpConnection::StateChange ERedirect error"), _L("")); iEngineStatus = EHttpError; if (iWait->IsStarted()) { iWait->AsyncStop(); } } } break; default: if (iWait->IsStarted()) { iWait->AsyncStop(); } break; } }
/*! \param Func */ xbShort xbExpn::ProcessFunction( char * Func ) { /* 1 - pop function from stack 2 - verify function name and get no of parms needed 3 - verify no of parms >= remainder of stack 4 - pop parms off stack 5 - execute function 6 - push result back on stack */ char *buf = 0; xbExpNode *p1, *p2, *p3, *WorkNode, *FuncNode; xbShort ParmsNeeded,len; char ptype = 0; /* process type s=string, l=logical, d=double */ xbDouble DoubResult = 0; xbLong IntResult = 0; FuncNode = (xbExpNode *) Pop(); ParmsNeeded = GetFuncInfo( Func, 1 ); if( ParmsNeeded == -1 ) { return XB_INVALID_FUNCTION; } else { ParmsNeeded = 0; if( FuncNode->Sibling1 ) ParmsNeeded++; if( FuncNode->Sibling2 ) ParmsNeeded++; if( FuncNode->Sibling3 ) ParmsNeeded++; } if( ParmsNeeded > GetStackDepth()) return XB_INSUFFICIENT_PARMS; p1 = p2 = p3 = NULL; if( ParmsNeeded > 2 ) p3 = (xbExpNode *) Pop(); if( ParmsNeeded > 1 ) p2 = (xbExpNode *) Pop(); if( ParmsNeeded > 0 ) p1 = (xbExpNode *) Pop(); memset( WorkBuf, 0x00, WorkBufMaxLen+1); if( strncmp( Func, "ABS", 3 ) == 0 ) { ptype = 'd'; DoubResult = ABS( GetDoub( p1 )); } else if( strncmp( Func, "ASC", 3 ) == 0 ) { ptype = 'd'; DoubResult = ASC( p1->StringResult ); } else if( strncmp( Func, "AT", 2 ) == 0 ) { ptype = 'd'; DoubResult = AT( p1->StringResult, p2->StringResult ); } else if( strncmp( Func, "CDOW", 4 ) == 0 ) { ptype = 's'; buf = CDOW( p1->StringResult ); } else if( strncmp( Func, "CHR", 3 ) == 0 ) { ptype = 's'; buf = CHR( GetInt( p1 )); } else if( strncmp( Func, "CMONTH", 6 ) == 0 ) { ptype = 's'; buf = CMONTH( p1->StringResult ); } else if( strncmp( Func, "CTOD", 4 ) == 0 ) { ptype = 's'; buf = CTOD( p1->StringResult ); } else if( strncmp( Func, "DATE", 4 ) == 0 ) { ptype = 's'; buf = DATE(); } else if( strncmp( Func, "DAY", 3 ) == 0 ) { ptype = 'd'; DoubResult = DAY( p1->StringResult ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'C' ) { ptype = 's'; buf = DESCEND( p1->StringResult.c_str() ); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'N' ) { ptype = 'd'; DoubResult = DESCEND( GetDoub( p1 )); } else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'D' ) { xbDate d( p1->StringResult ); ptype = 'd'; DoubResult = DESCEND( d ); } else if( strncmp( Func, "DOW", 3 ) == 0 ) { ptype = 'd'; DoubResult = DOW( p1->StringResult ); } else if( strncmp( Func, "DTOC", 4 ) == 0 ) { ptype = 's'; buf = DTOC( p1->StringResult ); } else if( strncmp( Func, "DTOS", 4 ) == 0 ) { ptype = 's'; buf = DTOS( p1->StringResult ); } else if( strncmp( Func, "EXP", 3 ) == 0 ) { ptype = 'd'; DoubResult = EXP( GetDoub( p1 )); } else if( strncmp( Func, "IIF", 3 ) == 0 ){ ptype = 's'; buf = IIF( p1->IntResult, p2->StringResult, p3->StringResult ); } else if( strncmp( Func, "INT", 3 ) == 0 ) { ptype = 'd'; DoubResult = INT( GetDoub( p1 )); } else if( strncmp( Func, "ISALPHA", 7 ) == 0 ) { ptype = 'l'; IntResult = ISALPHA( p1->StringResult ); } else if( strncmp( Func, "ISLOWER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISLOWER( p1->StringResult ); } else if( strncmp( Func, "ISUPPER", 7 ) == 0 ) { ptype = 'l'; IntResult = ISUPPER( p1->StringResult ); } else if( strncmp( Func, "LEN", 3 ) == 0 ) { ptype = 'd'; DoubResult = LEN( p1->StringResult ); } else if( strncmp( Func, "LEFT", 4 ) == 0 ) { ptype = 's'; buf = LEFT( p1->StringResult, INT( p2->DoubResult )); } else if( strncmp( Func, "LTRIM", 5 ) == 0 ) { ptype = 's'; buf = LTRIM( p1->StringResult ); } else if( strncmp( Func, "LOG", 3 ) == 0 ) { ptype = 'd'; DoubResult = LOG( GetDoub( p1 )); } else if( strncmp( Func, "LOWER", 5 ) == 0 ) { ptype = 's'; buf = LOWER( p1->StringResult ); } else if( strncmp( Func, "MAX", 3 ) == 0 ) { ptype = 'd'; DoubResult = MAX( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MIN", 3 ) == 0 ) { ptype = 'd'; DoubResult = MIN( GetDoub( p1 ), GetDoub( p2 )); } else if( strncmp( Func, "MONTH", 5 ) == 0 ) { ptype = 'd'; DoubResult = MONTH( p1->StringResult ); } else if( strncmp( Func, "RECNO", 5 ) == 0 ) { ptype = 'd'; DoubResult = RECNO( FuncNode->dbf ); } else if( strncmp( Func, "REPLICATE", 9 ) == 0 ) { ptype = 's'; buf = REPLICATE( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RIGHT", 5 ) == 0 ) { ptype = 's'; buf = RIGHT( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "RTRIM", 5 ) == 0 ) { ptype = 's'; buf = RTRIM( p1->StringResult ); } else if( strncmp( Func, "SPACE", 5 ) == 0 ) { ptype = 's'; buf = SPACE( INT( GetDoub( p1 ))); } else if( strncmp( Func, "SQRT", 4 ) == 0 ) { ptype = 'd'; DoubResult = SQRT( GetDoub( p1 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 1 ) { ptype = 's'; buf = STRZERO( p1->StringResult ); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 2 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 3 ) { ptype = 's'; buf = STRZERO( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p3 ) { ptype = 's'; if(p1->ExpressionType == 'N') buf = STR( p1->DoubResult, GetInt( p2 ), GetInt( p3 )); else buf = STR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p2 ) { ptype = 's'; buf = STR( p1->StringResult, GetInt( p2 )); } else if( strncmp( Func, "STR", 3 ) == 0 && p1 ) { ptype = 's'; buf = STR( p1->StringResult ); } else if( strncmp( Func, "SUBSTR", 6 ) == 0 ) { ptype = 's'; buf = SUBSTR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); } else if( strncmp( Func, "TRIM", 4 ) == 0 ) { ptype = 's'; buf = TRIM( p1->StringResult ); } else if( strncmp( Func, "UPPER", 5 ) == 0 ) { ptype = 's'; buf = UPPER( p1->StringResult ); } else if( strncmp( Func, "VAL", 3 ) == 0 ) { ptype = 'd'; DoubResult = VAL( p1->StringResult ); } else if( strncmp( Func, "YEAR", 4 ) == 0 ) { ptype = 'd'; DoubResult = YEAR( p1->StringResult ); } if( p1 && !p1->InTree ) delete p1; if( p2 && !p2->InTree ) delete p2; if( p3 && !p3->InTree ) delete p3; if( !FuncNode->InTree ) delete FuncNode; if( buf ){ len = strlen( buf ); WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = len + 1; } else { len = 0; WorkNode = new xbExpNode; if( !WorkNode ) return XB_NO_MEMORY; WorkNode->ResultLen = 0; } switch( ptype ){ case 's': /* string or char result */ WorkNode->DataLen = len; WorkNode->ExpressionType = 'C'; WorkNode->Type = 's'; WorkNode->StringResult = buf; break; case 'd': /* numeric result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'N'; WorkNode->Type = 'd'; WorkNode->DoubResult = DoubResult; break; case 'l': /* logical result */ WorkNode->DataLen = 0; WorkNode->ExpressionType = 'L'; WorkNode->Type = 'l'; WorkNode->IntResult = IntResult; break; default: std::cout << "\nInternal error. " << ptype; break; } Push(WorkNode); return XB_NO_ERROR; }
void space_free(byte *space) { int space_no = SPACE(space); unmap(space, space_mapped[space_no]); release_arena_space(space_no); }
void print_version() { PRINT("Polygon-4 Tools Bootstrapper Version " << version()); SPACE(); }