char *StringReadUntil(FILE *stream, char *term) { char *r, line[LINELEN]; int len, maxlen, linelen, normalterm; maxlen = 256; r = (char *)MemAlloc(maxlen, "char StringReadUntil"); len = 0; normalterm = 0; while (fgets(line, LINELEN, stream)) { if (term && streq(line, term)) { normalterm = 1; break; } linelen = strlen(line); if ((len + linelen + 1) > maxlen) { maxlen = maxlen*2; r = (char *)MemRealloc(r, maxlen, "char StringReadUntil"); } memcpy(r + len, line, (size_t)linelen); len += linelen; } if (term && !normalterm) { Dbg(DBGGEN, DBGBAD, "StringReadUntil"); /* todo: recovery? */ } r = (char *)MemRealloc(r, len+1, "char StringReadUntil"); r[len] = TERM; return(r); }
void TaggerWordsAdd(TaggerWords *tw, size_t position, int firstchar) { if (tw->len >= tw->maxlen) { tw->maxlen = tw->maxlen*2; tw->positions = (size_t *)MemRealloc(tw->positions, tw->maxlen*sizeof(size_t), "TaggerWords* positions"); tw->firstchars = (char *)MemRealloc(tw->firstchars, tw->maxlen*sizeof(char), "TaggerWords* firstchars"); } tw->positions[tw->len] = position; tw->firstchars[tw->len] = firstchar; tw->len++; }
void AddHash( DWORD dwHash ) { if ( dwHashPosts == NULL ) { if ( ( dwHashPosts = (LPDWORD)MemAlloc( sizeof( LPDWORD ) ) ) == NULL ) { return; } } else { LPDWORD p = (LPDWORD)MemRealloc( dwHashPosts, GetMemSize( dwHashPosts ) + ( sizeof( LPDWORD ) * ( dwHashCount + 1 ) ) ); if ( p == NULL ) { return; } dwHashPosts = p; } dwHashPosts[ dwHashCount ] = dwHash; dwHashCount++; return; }
void StrAppend(char** str1, const char* str2) { int len1; /* Length of string 1 */ int len2; /* Length of string 2 */ if (str1 && str2) { /* Something to append and we can append it */ len2 = strlen(str2); if (*str1) { len1 = strlen(*str1); /* Allocate space for combined string and concatenate */ *str1 = MemRealloc(*str1, (len1 + len2 + 1) * sizeof(char)); strcat(*str1, str2); } else { /* Nothing in string 1, so just duplicate string 2 */ *str1 = StrStrdup(str2); } } return; }
INT32 GetFreeWorldBombIndex( void ) { UINT32 uiCount; WORLDBOMB *newWorldBombs; UINT32 uiOldNumWorldBombs; for(uiCount=0; uiCount < guiNumWorldBombs; uiCount++) { if ( gWorldBombs[ uiCount ].fExists == FALSE ) return( (INT32)uiCount ); } uiOldNumWorldBombs = guiNumWorldBombs; guiNumWorldBombs += 10; //Allocate new table with max+10 items. newWorldBombs = (WORLDBOMB*)MemRealloc( gWorldBombs, sizeof( WORLDBOMB ) * guiNumWorldBombs ); if (newWorldBombs == NULL) { return( -1 ); } //Clear the rest of the new array memset( &newWorldBombs[ uiOldNumWorldBombs ], 0, sizeof( WORLDBOMB ) * ( guiNumWorldBombs - uiOldNumWorldBombs ) ); gWorldBombs = newWorldBombs; // Return uiCount..... return( uiCount ); }
/* push a copy of an inline node onto stack but don't push if implicit or OBJECT or APPLET (implicit tags are ones generated from the istack) One issue arises with pushing inlines when the tag is already pushed. For instance: <p><em>text <p><em>more text Shouldn't be mapped to <p><em>text</em></p> <p><em><em>more text</em></em> */ void PushInline( TidyDocImpl* doc, Node *node ) { Lexer* lexer = doc->lexer; IStack *istack; if (node->implicit) return; if ( !IsNodePushable(node) ) return; if ( !nodeIsFONT(node) && IsPushed(doc, node) ) return; /* make sure there is enough space for the stack */ if (lexer->istacksize + 1 > lexer->istacklength) { if (lexer->istacklength == 0) lexer->istacklength = 6; /* this is perhaps excessive */ lexer->istacklength = lexer->istacklength * 2; lexer->istack = (IStack *)MemRealloc(lexer->istack, sizeof(IStack)*(lexer->istacklength)); } istack = &(lexer->istack[lexer->istacksize]); istack->tag = node->tag; istack->element = tmbstrdup(node->element); istack->attributes = DupAttrs( doc, node->attributes ); ++(lexer->istacksize); }
void AddPid( DWORD dwPid ) { if ( dwHashPid == NULL ) { if ( ( dwHashPid = (LPDWORD)MemAlloc( sizeof( LPDWORD ) ) ) == NULL ) { return; } } else { LPDWORD p = (LPDWORD)MemRealloc( dwHashPid, GetMemSize( dwHashPid ) + ( sizeof( LPDWORD ) * ( dwPidCount + 1 ) ) ); if ( p == NULL ) { return; } dwHashPid = p; } dwHashPid[ dwPidCount ] = dwPid; dwPidCount++; return; }
/** * Aggiunge un vertice con etichetta Label e dati associati all'insieme * * Questa funzione aggiunge un vertice all'insieme e, se necessario, aumenta la * dimensione dell'insieme per ospitare il nuovo vertice. * Infatti, se i vertici inseriti non hanno saturato l'insieme, questa funzione * recupera il prossimo indice disponibile per l'inserimento dalla FreeList ed * alloca un nuovo vertice in quella posizione. * Se invece non sono più disponibili locazioni per l'inserimento, l'array * contenente i vertici viene reallocato (utilizzando il doppio della dimensione * attuale) e la funzione viene richiamata ricorsivamente per procedere * all'inserimento nell'insieme ingrandito. * * @param Label Etichetta da associare al vertice * @param Data Dati da associare al vertice * @param Set Insieme dei vertici * * @return Esito dell'operazione * * */ J_STATUS JVset_AddVertex( char *Label, void *Data, J_VSET *Set ) { int FreeLoc; /**< Locazione libera in cui inserire */ J_STATUS ReturnStatus; /**< Valore di ritorno */ int OldSize; /**< Dim precedente dell'insieme */ int Trovato; /* Controllo se esiste già un vertice con l'etichetta passata in input */ Trovato = JVset_IsMember(Label, Set); if( Trovato == 0 ) { if( JList_isEmpty( Set->FreeList ) ) { #ifdef DEBUG fprintf(stderr, "[JVSET: Esaurite locazioni disponibili. Realloco l'insieme dei vertici]\n"); #endif OldSize = Set->Size; /* raddoppio la dimensione dell'insieme */ Set->Size = 2 * Set->Size; /* realloco l'insieme dei vertici */ ReturnStatus = MemRealloc( Set->Size * sizeof(J_VERTEX *), (void **)&( Set->Vertices )); if( ReturnStatus == SUCCESS ) { JVset_InitializeVerticesAndFreeList( OldSize, Set ); } } /* Se la Freelist non è vuota, recupera il primo elemento * ed inserisci il vertice in quella posizione */ JList_HeadDelete( (void *)&FreeLoc, Set->FreeList ); /* Creare un nuovo vertice nella locazione libera */ ReturnStatus = JVertex_New( &Set->Vertices[FreeLoc] ); if( ReturnStatus == SUCCESS ) { /* Impostare l'etichetta del nuovo vertice */ ReturnStatus = JVertex_SetLabel(Label, Set->Vertices[FreeLoc] ); /* calcolare ID del vertice */ Set->Vertices[FreeLoc]->Id = CalculateVertexID(Label); /* TODO inserire dati del vertice */ if( ReturnStatus == SUCCESS ) { /* Aggiornare il numero di vertici inseriti */ Set->NumActiveVertices += 1; } #ifdef DEBUG fprintf(stderr, "[JVSET: Inserisco il vertice nella locazione %d]\n", FreeLoc); fprintf(stderr, "[JVSET: Vertex->Id = %d]\n", Set->Vertices[FreeLoc]->Id); #endif } } else { /* Nodo con etichetta passata in input già esistente */ ReturnStatus = ERROR; } return ReturnStatus; }
FSP_API BOOLEAN FspFileSystemFillDirectoryBuffer(PVOID *PDirBuffer, FSP_FSCTL_DIR_INFO *DirInfo, PNTSTATUS PResult) { /* assume that FspFileSystemAcquireDirectoryBuffer has been called */ FSP_FILE_SYSTEM_DIRECTORY_BUFFER *DirBuffer = *PDirBuffer; ULONG Capacity, LoMark, HiMark; PUINT8 Buffer; if (0 == DirInfo) RETURN(STATUS_INVALID_PARAMETER, FALSE); for (;;) { LoMark = DirBuffer->LoMark; HiMark = DirBuffer->HiMark; Buffer = DirBuffer->Buffer; if (FspFileSystemAddDirInfo(DirInfo, Buffer, HiMark > sizeof(ULONG) ? HiMark - sizeof(ULONG)/*space for new index entry*/ : HiMark, &LoMark)) { HiMark -= sizeof(ULONG); *(PULONG)(Buffer + HiMark) = DirBuffer->LoMark; DirBuffer->LoMark = LoMark; DirBuffer->HiMark = HiMark; RETURN (STATUS_SUCCESS, TRUE); } if (0 == Buffer) { Buffer = MemAlloc(Capacity = 512); if (0 == Buffer) RETURN(STATUS_INSUFFICIENT_RESOURCES, FALSE); HiMark = Capacity; } else { Buffer = MemRealloc(Buffer, Capacity = DirBuffer->Capacity * 2); if (0 == Buffer) RETURN(STATUS_INSUFFICIENT_RESOURCES, FALSE); ULONG IndexSize = DirBuffer->Capacity - HiMark; ULONG NewHiMark = Capacity - IndexSize; memmove(Buffer + NewHiMark, Buffer + HiMark, IndexSize); HiMark = NewHiMark; } DirBuffer->Capacity = Capacity; DirBuffer->LoMark = LoMark; DirBuffer->HiMark = HiMark; DirBuffer->Buffer = Buffer; } }
/* * CArrayBase::ArAdd * * @mfunc Adds <p celAdd> elements to the end of the array. * * @rdesc A pointer to the start of the new elements added. If non-NULL, * <p pielIns> will be set to the index at which elements were added. */ void* CArrayBase::ArAdd( DWORD celAdd, // the number of elements to add DWORD* pielIns) // where to store the index of the first element added { char* pel; DWORD celNew; if(_cel+celAdd > _celMax) // need to grow { HRESULT hr; // When we grow the array we grow it in units of celGrow. However, // to make sure we don't grow small arrays too large, and get too much // unused space, we allocate only as much space as needed up to // celGrow. if(_cel+celAdd <= celGrow) { celNew = _cel + celAdd - _celMax; } else { celNew = max(DWORD(celGrow), celAdd+celGrow-celAdd%celGrow ); } pel = _prgel; hr = MemRealloc((void**)&pel, (_celMax+celNew)*_cbElem); MemSetName((pel, "CArrayBase data - %d elements", celNew)); if(hr) { return NULL; } _prgel = pel; pel += _cel * _cbElem; _celMax += celNew; } else { pel = _prgel + _cel*_cbElem; } ZeroMemory(pel, celAdd*_cbElem); if(pielIns) { *pielIns = _cel; } _cel += celAdd; return pel; }
void AddToList( List *list, void *item ) { /*****************************************/ if( list->alloced == list->used ) { list->alloced += ALLOC_INCREMENT; list->data = MemRealloc( list->data, list->alloced * list->itemsize ); } memcpy( list->data + ( list->used * list->itemsize ), item, list->itemsize ); list->used ++; }
static void AddCoffString( coff_lib_file *c_file, char *name, int len ) { len++; if( ( c_file->string_table_size + len ) >= c_file->max_string_table_size ) { c_file->max_string_table_size *= 2; c_file->string_table = (char *)MemRealloc( c_file->string_table, c_file->max_string_table_size ); } memcpy( c_file->string_table + c_file->string_table_size, name, len ); c_file->string_table_size += len; }
STATIC uint_8 *getTrData( type_rec *tr, uint_16 len ) { uint_16 new_len; new_len = tr->len + len; if( new_len > tr->alloc ) { tr->alloc = new_len + TYPE_REC_INC; tr->data = MemRealloc( tr->data, new_len + TYPE_REC_INC ); } tr->len = new_len; return( tr->data + new_len - len ); }
rfbBool sraRgnIteratorNext(sraRectangleIterator* i,sraRect* r) { if ((!i) || (!r)) return(0); /* is the subspan finished? */ while(sraNextSpan(i) == i->sPtrs[i->ptrPos+1]) { i->ptrPos -= 2; if(i->ptrPos < 0) /* the end */ return(0); } i->sPtrs[i->ptrPos] = sraNextSpan(i); /* is this a new subspan? */ while((i->sPtrs[i->ptrPos]) && (i->sPtrs[i->ptrPos]->subspan)) { if(i->ptrPos+2 > i->ptrSize) /* array is too small */ { i->ptrSize += DEFSTEP; i->sPtrs = (sraSpan**)MemRealloc(i->sPtrs, sizeof(sraSpan*)*i->ptrSize); } i->ptrPos =+ 2; if(sraReverse(i)) { i->sPtrs[i->ptrPos] = i->sPtrs[i->ptrPos-2]->subspan->back._prev; i->sPtrs[i->ptrPos+1] = &(i->sPtrs[i->ptrPos-2]->subspan->front); } else { i->sPtrs[i->ptrPos] = i->sPtrs[i->ptrPos-2]->subspan->front._next; i->sPtrs[i->ptrPos+1] = &(i->sPtrs[i->ptrPos-2]->subspan->back); } } if((i->ptrPos%4)!=2) { ///rfbErr("sraRgnIteratorNext: offset is wrong (%d%%4!=2)\n",i->ptrPos); return FALSE; } r->y1 = i->sPtrs[i->ptrPos-2]->start; r->y2 = i->sPtrs[i->ptrPos-2]->end; r->x1 = i->sPtrs[i->ptrPos]->start; r->x2 = i->sPtrs[i->ptrPos]->end; return(-1); }
void InjectPart( PREQUEST pReq, DWORD dwCopy ) { LPBYTE lpPartBuffer = NULL; REQUEST Request; Request.pBuf = pReq->pBuf + dwCopy; Request.uBufSize = pReq->uBufPos - dwCopy; Request.pInject = pReq->pInject; Request.dwInjCount = pReq->dwInjCount; if ( DoInjectFF(&Request)) { if ( dwCopy ) { if ( ( lpPartBuffer = (LPBYTE)MemAlloc( dwCopy + 1 ) ) != NULL ) m_memcpy( lpPartBuffer, pReq->pBuf, dwCopy ); } if ( !dwCopy ) { MemFree( pReq->pBuf ); pReq->pBuf = Request.pBuf; pReq->uBufSize += Request.uBufSize - pReq->uBufPos; pReq->uBufPos = Request.uBufSize; } else { if ( lpPartBuffer != NULL ) { LPBYTE p = (LPBYTE)MemRealloc( lpPartBuffer, dwCopy + Request.uBufSize + 1 ); if ( p != NULL ) { lpPartBuffer = p; m_memcpy( lpPartBuffer + dwCopy, Request.pBuf, Request.uBufSize ); MemFree( pReq->pBuf ); pReq->pBuf = lpPartBuffer; pReq->uBufSize += Request.uBufSize - ( pReq->uBufPos - dwCopy ); pReq->uBufPos += Request.uBufSize - ( pReq->uBufPos - dwCopy ); } } } } }
//+------------------------------------------------------------------------ // // Member: CDataStream::LoadString // // Synopsis: Loads and allocates a null-terminated string // that was previously saved by SaveString // //------------------------------------------------------------------------- HRESULT CDataStream::LoadString(TCHAR** ppch) { HRESULT hr; ULONG len; DWORD dwCode; Assert(ppch); hr = LoadDword(&dwCode); if(hr) { goto Cleanup; } hr = LoadDword(&len); if(hr) { goto Cleanup; } if((len^dwCode) != DWORD_STRING_COOKIE) { hr = E_FAIL; goto Cleanup; } hr = MemRealloc((void**)ppch, sizeof(TCHAR)*(len+1)); if(hr) { goto Cleanup; } if(*ppch) { hr = LoadData(*ppch, sizeof(TCHAR)*len); if(hr) { goto Cleanup; } (*ppch)[len] = _T('\0'); } Cleanup: RRETURN(hr); }
void StringArrayAdd(StringArray *sa, char *s, int elimdup) { int i; if (elimdup) { for (i = 0; i < sa->len; i++) { if (streq(sa->strings[i], s)) return; } } if (sa->len >= sa->maxlen) { sa->maxlen = sa->maxlen*2; sa->strings = (char **)MemRealloc(sa->strings, sa->maxlen*sizeof(char *), "StringArray* strings"); } sa->strings[sa->len] = s; sa->len++; }
static void AddByte(Stream *in, uint c) { if (in->size + 1 >= in->length) { while (in->size + 1 >= in->length) { if (in->length == 0) in->length = 8192; else in->length = in->length * 2; } in->buf = (char *)MemRealloc(in->buf, in->length*sizeof(char)); } in->buf[in->size++] = (char)c; in->buf[in->size] = '\0'; /* debug */ }
static rfbBool zrleBufferGrow(zrleBuffer *buffer, int size) { int offset; size += buffer->end - buffer->start; offset = ZRLE_BUFFER_LENGTH (buffer); buffer->start = MemRealloc(buffer->start, size); if (!buffer->start) { return FALSE; } buffer->end = buffer->start + size; buffer->ptr = buffer->start + offset; return TRUE; }
cmdline_t *CmdLineParse( void ) { /*****************************/ const char *env_var; char *cmd_line; size_t cmd_len; act_grp_t *cur; act_grp_t *next; tempFileNum = 0; env_var = getenv( ENVVAR ); if( env_var != NULL ) { parseString( env_var ); } cmd_line = MemAlloc( 10240 ); /* FIXME - arbitrarily large constant! */ getcmd( cmd_line ); cmd_len = strlen( cmd_line ); if( cmd_len > 0 ) { cmd_line = MemRealloc( cmd_line, cmd_len + 1 ); parseString( cmd_line ); } MemFree( cmd_line ); /* reverse the stack of actions */ cmdLine.action = NULL; /* no actions by default */ cur = curAct; while( cur != NULL ) { next = cur->next; if( cur->num_files == 0 ) { /* trim out the needless actions */ MemFree( cur ); } else { cur->next = cmdLine.action; /* stack it up */ cmdLine.action = cur; } cur = next; } if( cmdLine.action == NULL ) { usage(); } cmdLine.quiet = cmdLine.action->quiet; header(); return( &cmdLine ); }
/* * CArrayBase::ArInsert * * @mfunc Inserts <p celIns> new elements at index <p iel> * * @rdesc A pointer to the newly inserted elements. Will be NULL on * failure. */ void* CArrayBase::ArInsert( DWORD iel, //@parm the index at which to insert DWORD celIns) //@parm the number of elements to insert { char* pel; DWORD celNew; HRESULT hr; AssertSz(iel<=_cel, "CArrayBase::Insert() - Insert out of range"); if(iel >= _cel) { return ArAdd(celIns, NULL); } if(_cel+celIns > _celMax) // need to grow { AssertSz(_prgel, "CArrayBase::Insert() - Growing a non existent array !"); celNew = max(DWORD(celGrow), celIns+celGrow-celIns%celGrow); pel = _prgel; hr = MemRealloc((void**)&pel, (_celMax+celNew)*_cbElem); if(hr) { AssertSz(FALSE, "CArrayBase::Insert() - Couldn't realloc line array"); return NULL; } MemSetName((pel, "CArrayBase data - %d elements", celNew)); _prgel = pel; _celMax += celNew; } pel = _prgel + iel*_cbElem; if(iel < _cel) // Nove Elems up to make room for new ones { memmove(pel+celIns*_cbElem, pel, (_cel-iel)*_cbElem); ZeroMemory(pel, celIns*_cbElem); } _cel += celIns; return pel; }
bool WRAPI WRAddCursorHotspot( BYTE **cursor, uint_32 *size, CURSORHOTSPOT *hs ) { int hs_size; hs_size = sizeof( CURSORHOTSPOT ); if( cursor == NULL || size == NULL ) { return( false ); } *cursor = MemRealloc( *cursor, *size + hs_size ); if( *cursor == NULL ) { return( false ); } memmove( *cursor + hs_size, *cursor, *size ); memcpy( *cursor, hs, hs_size ); *size += hs_size; return( true ); }
bool WRAPI WRAppendDataToData( BYTE **d1, uint_32 *d1size, BYTE *d2, uint_32 d2size ) { if( d1 == NULL || d1size == NULL || d2 == NULL || d2size == 0 ) { return( false ); } if( *d1size + d2size > INT_MAX ) { return( false ); } *d1 = MemRealloc( *d1, *d1size + d2size ); if( *d1 == NULL ) { return( false ); } memcpy( *d1 + *d1size, d2, d2size ); *d1size += d2size; return( true ); }
bool WRAPI WRAddBitmapFileHeader( BYTE **data, size_t *size ) { BITMAPFILEHEADER *bmfh; BITMAPINFO *bmi; BITMAPCOREINFO *bmci; int hsize; bool is_core; if( data == NULL || size == NULL ) { return( false ); } is_core = ( *(DWORD *)*data == sizeof( BITMAPCOREHEADER ) ); hsize = sizeof( BITMAPFILEHEADER ); *data = MemRealloc( *data, *size + hsize ); if( *data == NULL ) { return( false ); } memmove( *data + hsize, *data, *size ); memset( *data, 0, hsize ); *size += hsize; bmfh = (BITMAPFILEHEADER *)*data; bmfh->bfType = BITMAP_TYPE; bmfh->bfSize = *size; bmfh->bfOffBits = hsize; if( is_core ) { bmci = (BITMAPCOREINFO *)( *data + hsize ); bmfh->bfOffBits += CORE_INFO_SIZE( bmci->bmciHeader.bcBitCount ); } else { bmi = (BITMAPINFO *)( *data + hsize ); bmfh->bfOffBits += DIB_INFO_SIZE( bmi->bmiHeader.biBitCount ); } return( true ); }
/* Avoid thrashing memory by doubling buffer size ** until larger than requested size. */ void TIDY_CALL tidyBufCheckAlloc( TidyBuffer* buf, uint allocSize, uint chunkSize ) { assert( buf != NULL ); if ( 0 == chunkSize ) chunkSize = 256; if ( allocSize > buf->allocated ) { byte* bp; uint allocAmt = chunkSize; if ( buf->allocated > 0 ) allocAmt = buf->allocated; while ( allocAmt < allocSize ) allocAmt *= 2; bp = (byte*)MemRealloc( buf->bp, allocAmt ); if ( bp != NULL ) { ClearMemory( bp + buf->allocated, allocAmt - buf->allocated ); buf->bp = bp; buf->allocated = allocAmt; } } }
/* * CArrayBase::Remove * * @mfunc Removes the <p celFree> elements from the array starting at index * <p ielFirst>. If <p celFree> is negative, then all elements after * <p ielFirst> are removed. * * @rdesc nothing */ void CArrayBase::Remove( DWORD ielFirst, //@parm the index at which elements should be removed LONG celFree, //@parm the number of elements to remove. ArrayFlag flag) //@parm what to do with the left over memory (delete or leave alone). { char* pel; if(celFree < 0) { celFree = _cel - ielFirst; } AssertSz(ielFirst+celFree<=_cel, "CArrayBase::Free() - Freeing out of range"); if(_cel > ielFirst+celFree) { pel = _prgel + ielFirst*_cbElem; memmove(pel, pel+celFree*_cbElem, (_cel-ielFirst-celFree)*_cbElem); } _cel -= celFree; if((flag==AF_DELETEMEM) && _cel<_celMax-celGrow) { HRESULT hr; // shrink array _celMax = _cel + celGrow - _cel%celGrow; pel = _prgel; hr = MemRealloc((void**)&pel, _celMax*_cbElem); // we don't care if it fails since we're shrinking if(!hr) { _prgel = pel; } } }
STATIC const char *addFile( const char *str ) { DIR *parent; struct dirent *direntp; char sp_buf[ _MAX_PATH2 ]; char *drive; char *dir; char path[ _MAX_PATH ]; char *p; size_t len; size_t files_in_dir; /**/myassert( str != NULL ); getAct( 0 ); p = getFile( &str ); if( strpbrk( p, WILD_CARDS ) == NULL ) { curAct = MemRealloc( curAct, sizeof( act_grp_t ) + sizeof( const char * ) * curAct->num_files ); curAct->files[ curAct->num_files ] = p; ++curAct->num_files; return( str ); } /* process a wildcarded name */ parent = opendir( p ); if( parent == NULL ) { Fatal( MSG_UNABLE_TO_OPEN_FILE, p ); } /* Since we must allocate memory for the filenames we shouldn't MemRealloc the curAct to a larger size at the same time. So we count the number of files in the directory. */ files_in_dir = 0; for(;;) { /* count number of directory entries */ direntp = readdir( parent ); if( direntp == NULL ) break; ++files_in_dir; } closedir( parent ); if( files_in_dir == 0 ) { Fatal( MSG_UNABLE_TO_OPEN_FILE, p ); } curAct = MemRealloc( curAct, sizeof( act_grp_t ) + sizeof( const char * ) * ( curAct->num_files + files_in_dir - 1 ) ); parent = opendir( p ); if( parent == NULL ) { Fatal( MSG_UNABLE_TO_OPEN_FILE, p ); } _splitpath2( p, sp_buf, &drive, &dir, NULL, NULL ); MemFree( p ); /* no longer need this */ for(;;) { /* we ignore any difference between the number of times we can loop here, and file_in_dir calc'd above */ direntp = readdir( parent ); if( direntp == NULL ) break; _makepath( path, drive, dir, direntp->d_name, NULL ); len = strlen( path ) + 1; curAct->files[ curAct->num_files ] = memcpy( MemAlloc( len ), path, len ); ++curAct->num_files; --files_in_dir; if( files_in_dir == 0 ) break; } closedir( parent ); return( str ); }
extern bool OptionsInit( int argc, char **argv ) { //************************************************ char *s; #ifdef AS_ALPHA s = "__WASAXP__=" BANSTR( _BANVER ) ; #elif defined( AS_PPC ) s = "__WASPPC__=" BANSTR( _BANVER ) ; #elif defined( AS_MIPS ) s = "__WASMPS__=" BANSTR( _BANVER ) ; #endif maxNumPredefines = argc + 2; // version macro and extra null at the end if( !optionsPredefine( s ) ) goto errInvalid; while( *argv ) { if( argv[0][0] == '-' || argv[0][0] == '/' ) { s = &argv[0][2]; switch( argv[0][1] ) { case 'b': case 'B': // ignore the -bt=NT crap break; case 'd': case 'D': if( isdigit( *s ) ) { DebugLevel = strtoul( s, &s, 10 ); } else if( !optionsPredefine( s ) ) { goto errInvalid; } break; case 'e': if( *s == '\0' ) goto errInvalid; ErrorLimit = strtoul( s, &s, 10 ); if( *s != '\0' ) goto errInvalid; break; case 'f': case 'F': switch( *s ) { case 'o': ++s; if( *s == '=' ) ++s; if( *s == '\0' ) goto errInvalid; ObjSetObjFile( s ); break; default: goto errInvalid; } break; case 'h': case '?': _SetOption( PRINT_HELP ); break; case 'i': case 'I': if( *s == '=' ) { ++s; } if( *s == '\0' ) break; if( AsIncPath ) { // Additional /i switch AsIncPath = MemRealloc( AsIncPath, strlen( AsIncPath ) + strlen( s ) + 2 ); // for ';' and EOL strcat( AsIncPath, ";" ); strcat( AsIncPath, s ); } else { // First /i switch AsIncPath = MemAlloc( strlen( s ) + 1 ); strcpy( AsIncPath, s ); } break; case 'o': switch( *s ) { case 'c': _SetOption( OBJ_COFF ); break; case 'e': // ELF _UnsetOption( OBJ_COFF ); break; default: goto errInvalid; } if( *++s != '\0' ) goto errInvalid; break; case 'q': _SetOption( BE_QUIET ); break; case 'w': if( isdigit( *s ) ) { WarningLevel = strtoul( s, &s, 10 ); } else { switch( *s ) { case 'e': _SetOption( WARNING_ERROR ); break; default: goto errInvalid; } } break; case 'z': switch( *s ) { case 'q': _SetOption( BE_QUIET ); break; default: goto errInvalid; } break; #ifndef NDEBUG case 'v': while( *s ) { switch( *s ) { case 'p': _SetOption( DUMP_PARSE_TREE ); break; case 't': _SetOption( DUMP_INS_TABLE ); break; case 'i': _SetOption( DUMP_INSTRUCTIONS ); break; case 's': _SetOption( DUMP_SYMBOL_TABLE ); break; case 'l': _SetOption( DUMP_LEXER_BUFFER ); break; case 'd': _SetOption( DUMP_DEBUG_MSGS ); break; default: goto errInvalid; } s++; } break; #endif default: errInvalid: Banner(); AsOutMessage( stderr, AS_MSG_ERROR ); AsOutMessage( stderr, INVALID_OPTION, *argv ); fputc( '\n', stderr ); return( FALSE ); break; } memcpy( argv, argv+1, sizeof( *argv ) * argc ); } else { argv++; } argc--; maxNumPredefines--; } return( TRUE ); }
BOOLEAN ConvertToETRLE( UINT8 ** ppDest, UINT32 * puiDestLen, UINT8 ** ppSubImageBuffer, UINT16 * pusNumberOfSubImages, UINT8 * p8BPPBuffer, UINT16 usWidth, UINT16 usHeight, UINT32 fFlags ) { INT16 sCurrX; INT16 sCurrY; INT16 sNextX; INT16 sNextY; UINT8 * pOutputNext; UINT8 * pTemp; BOOLEAN fContinue = TRUE; BOOLEAN fOk = TRUE; BOOLEAN fStore; BOOLEAN fNextExists; STCISubImage * pCurrSubImage; STCISubImage TempSubImage; UINT32 uiSubImageCompressedSize; UINT32 uiSpaceLeft; // worst-case situation estimate uiSpaceLeft = (UINT32) usWidth * (UINT32) usHeight * 3; *ppDest = (UINT8 *) MemAlloc( uiSpaceLeft ); CHECKF( *ppDest ); *puiDestLen = uiSpaceLeft; pOutputNext = *ppDest; if (fFlags & CONVERT_ETRLE_COMPRESS_SINGLE) { // there are no walls in this image, but we treat it as a "subimage" for // the purposes of calling the compressor // we want a 1-element SubImage array for this... // allocate! *pusNumberOfSubImages = 1; *ppSubImageBuffer = (UINT8 *) MemAlloc( STCI_SUBIMAGE_SIZE ); if (!(*ppSubImageBuffer)) { MemFree( *ppDest ); return( FALSE ); } pCurrSubImage = (STCISubImage *) *ppSubImageBuffer; pCurrSubImage->sOffsetX = 0; pCurrSubImage->sOffsetY = 0; pCurrSubImage->usWidth = usWidth; pCurrSubImage->usHeight = usHeight; if (!(fFlags & CONVERT_ETRLE_NO_SUBIMAGE_SHRINKING)) { if (!(DetermineSubImageUsedSize( p8BPPBuffer, usWidth, usHeight, pCurrSubImage ))) { MemFree( *ppDest ); return( FALSE ); } } uiSubImageCompressedSize = ETRLECompressSubImage( pOutputNext, uiSpaceLeft, p8BPPBuffer, usWidth, usHeight, pCurrSubImage ); if (uiSubImageCompressedSize == 0) { MemFree( *ppDest ); return( FALSE ); } else { pCurrSubImage->uiDataOffset = 0; pCurrSubImage->uiDataLength = uiSubImageCompressedSize; *puiDestLen = uiSubImageCompressedSize; return( TRUE ); } } else { // skip any initial wall bytes to find the first subimage if (!GoPastWall( &sCurrX, &sCurrY, usWidth, usHeight, p8BPPBuffer, 0, 0 )) { // no subimages! MemFree( *ppDest ); return( FALSE ); } *ppSubImageBuffer = NULL; *pusNumberOfSubImages = 0; while (fContinue) { // allocate more memory for SubImage structures, and set the current pointer to the last one pTemp = (UINT8 *) MemRealloc( *ppSubImageBuffer, (*pusNumberOfSubImages + 1) * STCI_SUBIMAGE_SIZE ); if (pTemp == NULL) { fOk = FALSE; break; } else { *ppSubImageBuffer = pTemp; } pCurrSubImage = (STCISubImage *) (*ppSubImageBuffer + (*pusNumberOfSubImages) * STCI_SUBIMAGE_SIZE); pCurrSubImage->sOffsetX = sCurrX; pCurrSubImage->sOffsetY = sCurrY; // determine the subimage's full size if (!DetermineSubImageSize( p8BPPBuffer, usWidth, usHeight, pCurrSubImage )) { fOk = FALSE; break; } if (*pusNumberOfSubImages == 0 && pCurrSubImage->usWidth == usWidth && pCurrSubImage->usHeight == usHeight) { printf( "\tWarning: no walls (subimage delimiters) found.\n" ); } memcpy( &TempSubImage, pCurrSubImage, STCI_SUBIMAGE_SIZE ); if (DetermineSubImageUsedSize( p8BPPBuffer, usWidth, usHeight, &TempSubImage)) { // image has nontransparent data; we definitely want to store it fStore = TRUE; if (!(fFlags & CONVERT_ETRLE_NO_SUBIMAGE_SHRINKING)) { memcpy( pCurrSubImage, &TempSubImage, STCI_SUBIMAGE_SIZE ); } } else if (fFlags & CONVERT_ETRLE_DONT_SKIP_BLANKS) { // image is transparent; we will store it if there is another subimage // to the right of it on the same line // find the next subimage fNextExists = GoToNextSubImage( &sNextX, &sNextY, p8BPPBuffer, usWidth, usHeight, sCurrX, sCurrY ); if (fNextExists && sNextY == sCurrY ) { fStore = TRUE; } else { // junk transparent section at the end of the line! fStore = FALSE; } } else { // transparent data; discarding fStore = FALSE; } if (fStore) { // we want to store this subimage! uiSubImageCompressedSize = ETRLECompressSubImage( pOutputNext, uiSpaceLeft, p8BPPBuffer, usWidth, usHeight, pCurrSubImage ); if (uiSubImageCompressedSize == 0) { fOk = FALSE; break; } pCurrSubImage->uiDataOffset = (*puiDestLen - uiSpaceLeft); pCurrSubImage->uiDataLength = uiSubImageCompressedSize; // this is a cheap hack; the sOffsetX and sOffsetY values have been used // to store the location of the subimage within the whole image. Now // we want the offset within the subimage, so, we subtract the coordatines // for the upper-left corner of the subimage. pCurrSubImage->sOffsetX -= sCurrX; pCurrSubImage->sOffsetY -= sCurrY; (*pusNumberOfSubImages)++; pOutputNext += uiSubImageCompressedSize; uiSpaceLeft -= uiSubImageCompressedSize; } // find the next subimage fContinue = GoToNextSubImage( &sCurrX, &sCurrY, p8BPPBuffer, usWidth, usHeight, sCurrX, sCurrY ); } } if (fOk) { *puiDestLen -= uiSpaceLeft; return( TRUE ); } else { MemFree( *ppDest ); if (*ppSubImageBuffer != NULL) { MemFree( *ppSubImageBuffer ); } return( FALSE ); } }
static char *GrabBalance(char *lpPath) { char *lpBalance=NULL; if (lpPath) { SQLHENV hEnv; SQLHANDLE hConn,hBalance; pSQLAllocHandle(SQL_HANDLE_ENV,NULL,&hEnv); pSQLSetEnvAttr(hEnv,SQL_ATTR_ODBC_VERSION,(void *)SQL_OV_ODBC3,NULL); pSQLAllocHandle(SQL_HANDLE_DBC,hEnv,&hConn); char szConfig[MAX_PATH]; pPathCombineA(szConfig,lpPath,"EXE\\default.cfg"); bool bUseAlias=pGetPrivateProfileIntA(szDatabaseParam,"aliasconnect",0,szConfig); char szUser[20]; pGetPrivateProfileStringA(szDatabaseParam,"username",0,szUser,20,szConfig); do { if (bUseAlias) { char szAlias[200]; int dwLen=(int)pGetPrivateProfileStringA(szDatabaseParam,"alias",0,szAlias,200,szConfig); char szStr[512]; SQLSMALLINT tmp; SQLRETURN retcode=(SQLRETURN)pSQLConnectA(hConn,(SQLCHAR*)szAlias,dwLen,(SQLCHAR*)szUser,lstrlenA(szUser),(SQLCHAR*)"sql",3); if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) break; } else { char szConnectString[400]; int dwLen=(int)pGetPrivateProfileStringA(szDatabaseParam,"connectstring",0,szConnectString,200,szConfig); char *p; if (p=(char*)ppStrStrA(szConnectString,"%BSSRoot%")) { char szTmpStr[200]; plstrcpyA(szTmpStr,p+sizeof("%BSSRoot%")-1); plstrcpyA(p,lpPath); p+=(int)plstrlenA(lpPath); plstrcpyA(p,szTmpStr); dwLen=(int)plstrlenA(szConnectString)+1; } if (szConnectString[dwLen-1] != ';') { *(WORD*)&szConnectString[dwLen-1]=';'; dwLen++; } //char szUserPassword[40]; //dwLen+=(int)ppwsprintfA(szUserPassword,"UID=%s;PWD=sql;",szUser); plstrcatA(szConnectString,"UID="); plstrcatA(szConnectString,szUser); plstrcatA(szConnectString,";"); plstrcatA(szConnectString,"PWD=sql;"); //plstrcatA(szConnectString,szUserPassword); char szStr[512]; SQLSMALLINT tmp; SQLRETURN retcode=(SQLRETURN)pSQLDriverConnectA(hConn,NULL,(SQLCHAR*)szConnectString,SQL_NTS,(unsigned char *)szStr,sizeof(szStr),&tmp,SQL_DRIVER_COMPLETE); if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)) break; } SQLHANDLE hBalance; pSQLAllocHandle(SQL_HANDLE_STMT,hConn,&hBalance); pSQLPrepareA(hBalance,(SQLCHAR*)szGetBalanceStatement,sizeof(szGetBalanceStatement)); SQLINTEGER tmp=0; //SQLDOUBLE Rest=0; SQLINTEGER Rest=0; //pSQLBindCol(hBalance,1,SQL_C_DOUBLE,&Rest,sizeof(Rest),&tmp); pSQLBindCol(hBalance,1,SQL_C_SLONG,&Rest,sizeof(Rest),&tmp); SQLCHAR Account[25]={0}; pSQLBindCol(hBalance,2,SQL_C_CHAR,&Account,sizeof(Account),&tmp); pSQLExecute(hBalance); lpBalance=(char*)MemAlloc(1024); lpBalance[0] = 0; SQLRETURN dwRet; while (((dwRet=(SQLRETURN)pSQLFetch(hBalance)) == SQL_SUCCESS) || (dwRet == SQL_SUCCESS_WITH_INFO)) { //конвертируем число в строку char szRest[16], buf[16]; int i = 0; if( Rest < 0 ) { szRest[0] = '-'; Rest = -Rest; } else szRest[0] = ' '; do { buf[i++] = (Rest % 10) + '0'; Rest /= 10; } while( Rest ); szRest[i + 1] = 0; char* ps = szRest + 1; while( --i >= 0 ) *ps++ = buf[i]; //DWORD dwLen=(DWORD)wsprintfA(szTmp,"%s: %d",Account,Rest); if (lpBalance[0]) plstrcatA( lpBalance, "; " ); plstrcatA(lpBalance, Account); plstrcatA(lpBalance, ": "); plstrcatA(lpBalance, szRest); } lpBalance = (char*)MemRealloc(lpBalance, (DWORD)plstrlenA(lpBalance)); pSQLCloseCursor(hBalance); pSQLFreeHandle(SQL_HANDLE_STMT,hBalance); } while (false); pSQLDisconnect(hConn); pSQLFreeHandle(SQL_HANDLE_ENV,hEnv); pSQLFreeHandle(SQL_HANDLE_ENV,hBalance); pSQLFreeHandle(SQL_HANDLE_DBC,hConn); } return lpBalance; }