Exemplo n.º 1
0
/*
 * selectTag - select a tag from a list of possible tags
 */
static vi_rc selectTag( FILE *f, char *str, char *buff, char *fname )
{
    int         tagcnt;
    char        **taglist;
    int         i;
    int         whichtag;
    char        tag[MAX_STR];

    tagcnt = 0;
    taglist = NULL;

    for( ;; ) {
        RemoveLeadingSpaces( buff );
        taglist = MemReAlloc( taglist, sizeof( char * ) * (tagcnt + 1) );
        AddString( &taglist[tagcnt], buff );
        i = 0;
        while( !isspace( taglist[tagcnt][i] ) ) {
            i++;
        }
        taglist[tagcnt][i] = 0;
        tagcnt++;
        if( fgets( buff, MAX_STR, f ) == NULL )  {
            break;
        }
        if( NextWord1( buff, tag ) <= 0 ) {
            continue;
        }
        if( EditFlags.IgnoreTagCase ) {
            i = stricmp( str, tag );
        } else {
            i = strcmp( str, tag );
        }
        if( i ) {
            break;
        }
    }
    fclose( f );
    if( EditFlags.TagPrompt && EditFlags.WindowsStarted && tagcnt > 1 ) {
        whichtag = PickATag( tagcnt, taglist, str );
        if( whichtag < 0 ) {
            return( DO_NOT_CLEAR_MESSAGE_WINDOW );
        }
    } else {
        whichtag = 0;
    }
    taglist[whichtag][strlen( taglist[whichtag] )] = ' ';
    strcpy( buff, taglist[whichtag] );
    MemFreeList( tagcnt, taglist );

    if( NextWord1( buff, fname ) <= 0 ) {
        return( ERR_INVALID_TAG_FOUND );
    }
    buff[strlen( buff ) - 1] = 0;
    RemoveLeadingSpaces( buff );
    if( buff[0] == 0 ) {
        return( ERR_INVALID_TAG_FOUND );
    }
    return( ERR_NO_ERR );

} /* selectTag */
Exemplo n.º 2
0
/*
 * readDIBInfo - read BITMAPINFO structure from a bitmap file
 *
 * NOTE: Assume fp is positioned at the start of the bitmap information.
 *       We first read in the BITMAPINFOHEADER to get information about the
 *       number of quads needed, then we reposition ourselves and read in
 *       the entire BITMAPINFOHEADER structure.
 */
static BITMAPINFO *readDIBInfo( FILE *fp )
{
    BITMAPINFO          *bm;
    BITMAPINFOHEADER    *header;
    long                bitmap_size;

    header = MemAlloc( sizeof( BITMAPINFOHEADER ) );
    if( header == NULL ) {
        return( NULL );
    }
    fseek( fp, START_OF_HEADER, SEEK_SET );
    fread( header, sizeof( BITMAPINFOHEADER ), 1, fp );
    if( header->biBitCount < 9 ) {
        /* Bitmap has palette, read it */
        fseek( fp, START_OF_HEADER, SEEK_SET );
        bitmap_size = DIB_INFO_SIZE( header->biBitCount );
        bm = MemReAlloc( header, bitmap_size );
        if( bm == NULL ) {
            return( NULL );
        }
        fread( bm, bitmap_size, 1, fp );
    }
    else {
        return( (BITMAPINFO*) header );
    }

    return( bm );

} /* readDIBInfo */
Exemplo n.º 3
0
/********************************************************************
 ProcFindAllIdsFromExeName() - returns an array of process ids that are running specified executable.

*******************************************************************/
extern "C" HRESULT DAPI ProcFindAllIdsFromExeName(
    __in_z LPCWSTR wzExeName,
    __out DWORD** ppdwProcessIds,
    __out DWORD* pcProcessIds
    )
{
    HRESULT hr = S_OK;
    DWORD er = ERROR_SUCCESS;
    HANDLE hSnap = INVALID_HANDLE_VALUE;
    BOOL fContinue = FALSE;
    PROCESSENTRY32W peData = { sizeof(peData) };
    
    hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (INVALID_HANDLE_VALUE == hSnap)
    {
        ExitWithLastError(hr, "Failed to create snapshot of processes on system");
    }

    fContinue = ::Process32FirstW(hSnap, &peData);

    while (fContinue)
    {
        if (0 == lstrcmpiW((LPCWSTR)&(peData.szExeFile), wzExeName))
        {
            if (!*ppdwProcessIds)
            {
                *ppdwProcessIds = static_cast<DWORD*>(MemAlloc(sizeof(DWORD), TRUE));
                ExitOnNull(ppdwProcessIds, hr, E_OUTOFMEMORY, "Failed to allocate array for returned process IDs.");
            }
            else
            {
                DWORD* pdwReAllocReturnedPids = NULL;
                pdwReAllocReturnedPids = static_cast<DWORD*>(MemReAlloc(*ppdwProcessIds, sizeof(DWORD) * ((*pcProcessIds) + 1), TRUE));
                ExitOnNull(pdwReAllocReturnedPids, hr, E_OUTOFMEMORY, "Failed to re-allocate array for returned process IDs.");

                *ppdwProcessIds = pdwReAllocReturnedPids;
            }
            
            (*ppdwProcessIds)[*pcProcessIds] = peData.th32ProcessID;
            ++(*pcProcessIds);
        }

        fContinue = ::Process32NextW(hSnap, &peData);
    }

    er = ::GetLastError();
    if (ERROR_NO_MORE_FILES == er)
    {
        hr = S_OK;
    }
    else
    {
        hr = HRESULT_FROM_WIN32(er);
    }

LExit:
    ReleaseFile(hSnap);

    return hr;
}
Exemplo n.º 4
0
/********************************************************************
StrAnsiAlloc - allocates or reuses dynamic ANSI string memory

NOTE: caller is responsible for freeing ppsz even if function fails
********************************************************************/
extern "C" HRESULT DAPI StrAnsiAlloc(
	__inout LPSTR* ppsz,
	__in DWORD_PTR cch
	)
{
	Assert(ppsz && cch);
	HRESULT hr = S_OK;
	LPSTR psz = NULL;

	if (cch >= MAXDWORD / sizeof(WCHAR))
	{
		ExitOnFailure1(hr = E_OUTOFMEMORY, "Not enough memory to allocate string of size: %d", cch);
	}

	if (*ppsz)
		psz = static_cast<LPSTR>(MemReAlloc(*ppsz, sizeof(CHAR) * cch, FALSE));
	else
		psz = static_cast<LPSTR>(MemAlloc(sizeof(CHAR) * cch, TRUE));

	ExitOnNull1(psz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %d", cch);

	*ppsz = psz;
LExit:
	return hr;
}
Exemplo n.º 5
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
void CBZDoc::InsertData(DWORD dwPtr, DWORD dwSize, BOOL bIns)
{
    int nGlow = dwSize - (m_dwTotal - dwPtr);
    if(!m_pData) {
        m_pData = (LPBYTE)MemAlloc(dwSize);
        m_dwTotal = dwSize;
    } else if(bIns || dwPtr == m_dwTotal) {
        m_pData = (LPBYTE)MemReAlloc(m_pData, m_dwTotal+dwSize);
        memmove(m_pData+dwPtr+dwSize, m_pData+dwPtr, m_dwTotal - dwPtr);
        m_dwTotal += dwSize;
    } else if(nGlow > 0) {
        m_pData = (LPBYTE)MemReAlloc(m_pData, m_dwTotal+nGlow);
        m_dwTotal += nGlow;
    }
    ASSERT(m_pData != NULL);
}
Exemplo n.º 6
0
static void destroyBlock( int i, char *start )
{
    char    new_ss[MAX_STR];

    if( EditVars.NumStatusSections == 1 ) {
        // unfortunately wstatus.c can't handle this right now
        // (it would be nice)
        MyBeep();
        return;
    }

    if( i != EditVars.NumStatusSections ) {
        memmove( EditVars.StatusSections + i, EditVars.StatusSections + i + 1, (EditVars.NumStatusSections - 1 - i) * sizeof( section_size ) );
    }
    EditVars.NumStatusSections--;
    EditVars.StatusSections = MemReAlloc( EditVars.StatusSections, EditVars.NumStatusSections * sizeof( section_size ) );

    strncpy( new_ss, EditVars.StatusString, start - EditVars.StatusString );
    new_ss[start - EditVars.StatusString] = '\0';
    while( start[0] && !(start[0] == '$' && start[1] == '[') ) {
        start++;
    }
    if( start[0] == '$' ) {
        start += 2;
        strcat( new_ss, start );
    }
    ReplaceString( &EditVars.StatusString, new_ss );

    totalRedraw();
}
Exemplo n.º 7
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
DWORD CBZDoc::DoUndo()
{
    DWORD dwSize = *((DWORD*)(m_pUndo+m_dwUndo-4));
    m_dwUndo -= dwSize;
    dwSize -= 9;
    LPBYTE p = m_pUndo + m_dwUndo;
    DWORD dwPtr = *((DWORD*&)p)++;
    UndoMode mode = (UndoMode)*p++;
#ifdef FILE_MAPPING
    QueryMapView(m_pData, dwPtr);
#endif //FILE_MAPPING
    if(mode == UNDO_DEL) {
        DeleteData(dwPtr, *((DWORD*)p));
    } else {
        InsertData(dwPtr, dwSize, mode == UNDO_INS);
        memcpy(m_pData+dwPtr, p, dwSize);
    }
    if(m_dwUndo)
        m_pUndo = (LPBYTE)MemReAlloc(m_pUndo, m_dwUndo);
    else {				// ### 1.54
        MemFree(m_pUndo);
        m_pUndo = NULL;
        if(m_dwUndoSaved)
            m_dwUndoSaved = UINT_MAX;
    }
    // if(!m_pUndo)
    TouchDoc();
    return dwPtr;
}
Exemplo n.º 8
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
void CBZDoc::StoreUndo(DWORD dwPtr, DWORD dwSize, UndoMode mode)
{
    if(mode == UNDO_OVR && dwPtr+dwSize >= m_dwTotal)
        dwSize = m_dwTotal - dwPtr;
    if(dwSize == 0) return;
#ifdef FILE_MAPPING
    QueryMapView(m_pData, dwPtr);
#endif //FILE_MAPPING
    DWORD dwBlock = dwSize + 9;
    if(mode == UNDO_DEL)
        dwBlock = 4 + 9;
    if(!m_pUndo) {
        m_pUndo = (LPBYTE)MemAlloc(dwBlock);
        m_dwUndo = m_dwUndoSaved = 0;
    } else
        m_pUndo = (LPBYTE)MemReAlloc(m_pUndo, m_dwUndo+dwBlock);
    ASSERT(m_pUndo != NULL);
    LPBYTE p = m_pUndo + m_dwUndo;
    *((DWORD*&)p)++ = dwPtr;
    *p++ = mode;
    if(mode == UNDO_DEL) {
        *((DWORD*&)p)++ = dwSize;
    } else {
        memcpy(p, m_pData+dwPtr, dwSize);
        p+=dwSize;
    }
    *((DWORD*&)p)++ = dwBlock;
    m_dwUndo += dwBlock;
    ASSERT(p == m_pUndo+m_dwUndo);
    TouchDoc();
}
Exemplo n.º 9
0
/*
 * FindHistInit - initial find history structure
 */
void FindHistInit( int max )
{
    EditVars.FindHist.max = max;
    EditVars.FindHist.curr = 0;
    EditVars.FindHist.data = MemReAlloc( EditVars.FindHist.data, (EditVars.FindHist.max + 1) * sizeof( char * ) );

} /* FindHistInit */
Exemplo n.º 10
0
void DCResize( info *info )
{
    int     nlines, extra;
    dc      dc;

    if( info == NULL ) {
        // Windows is sending WM_SIZE before we've set CurrentInfo -
        // hang on & cache will be initialized in DCCreate in a moment
        return;
    }
    nlines = WindowAuxInfo( info->CurrentWindow, WIND_INFO_TEXT_LINES );
    dc = info->dc;
    dc += info->dc_size - 1;
    for( extra = nlines - info->dc_size; extra < 0; ++extra ) {
        deinitDCLine( dc );
        dc--;
    }
    if( nlines == 0 ) {
        // no room to display anything - trash the cache
        if( info->dc ) {
            MemFree( info->dc );
        }
        info->dc = NULL;
    } else {
        info->dc = dc = MemReAlloc( info->dc, nlines * sizeof( dc_line ) );
        dc += info->dc_size;
        for( ; extra > 0; --extra ) {
            initDCLine( dc );
            dc++;
        }
    }
    info->dc_size = nlines;
}
Exemplo n.º 11
0
/*
 * LastFilesHistInit - initial find history structure
 */
void LastFilesHistInit( int max )
{
    EditVars.LastFilesHist.max = max;
    EditVars.LastFilesHist.curr = 0;
    EditVars.LastFilesHist.data = MemReAlloc( EditVars.LastFilesHist.data,
        (EditVars.LastFilesHist.max + 1) * sizeof( char * ) );

} /* LastFilesHistInit */
Exemplo n.º 12
0
/*
 * EMSInit - init for EMS memory usage
 */
void EMSInit( void )
{
    void                *vect;
    char                *check;
    unsigned            i;
    unsigned short      seg;
    unsigned char       handle;
    ems_addr            h;

    EMSCtrl.inuse = FALSE;
    if( !EditFlags.ExtendedMemory ) {
        return;
    }

    EMSCtrl.exhausted = FALSE;
    vect = DosGetVect( EMS_INTERRUPT );
    check = MK_FP( FP_SEG( vect ), EMS_INTERRUPT_OFFSET );
    for( i = 0; i <= 7; i++ ) {
        if( check[i] != emsStr[i] ) {
            return;
        }
    }
    if( _EMSStatus() != 0 ) {
        return;
    }
    if( _EMSGetPageFrame( &seg ) != 0 ) {
        return;
    }
    EMSCtrl.seg = seg;

    if( _EMSAllocateMemory( EMS_MAX_LOGICAL_PAGES, &handle ) != 0 ) {
        return;
    }
    EMSCtrl.handles[EMSCtrl.allocated] = handle;
    EMSCtrl.logical = 0;
    EMSCtrl.max_logical = EMS_MAX_LOGICAL_PAGES;
    EMSCtrl.offset = 0;
    EMSCtrl.allocated = 1;
    for( i = 0; i < EMS_MAX_PHYSICAL_PAGES; i++ ) {
        EMSCtrl.physical[i].used = FALSE;
    }

    emsPtrs = MemAlloc( sizeof( long ) * MaxEMSBlocks );

    for( i = 0; i < MaxEMSBlocks; i++ ) {
        emsPtrs[i] = eMSAlloc( MAX_IO_BUFFER );
        if( emsPtrs[i] == NULL ) {
            break;
        }
        h.external = emsPtrs[i];
        TotalEMSBlocks++;
    }
    emsPtrs = MemReAlloc( emsPtrs, TotalEMSBlocks * sizeof( long ) );

    EMSCtrl.inuse = TRUE;


} /* EMSInit */
Exemplo n.º 13
0
/*
 * DIPCliRealloc
 */
void *DIGCLIENT DIGCliRealloc( void *ptr, unsigned size ) {

    void        *ret;

    DEBUGOUT( "realloc BEGIN" );
    ret = MemReAlloc( ptr, size );
    DEBUGOUT( "realloc END" );
    return( ret );
}
Exemplo n.º 14
0
BOOL AllocNewBuf( void ) {

    MemBlocks = MemReAlloc( MemBlocks, ( MemBlocksCnt + 1 ) * sizeof( void * ) );
    if( MemBlocks == NULL ) return( FALSE );
    MemBlocks[ MemBlocksCnt ] = MemAlloc( MEM_BLOCK_SIZE );
    if( MemBlocks[ MemBlocksCnt ] == NULL ) return( FALSE );
    BufEnd = MemBlocks[ MemBlocksCnt ];
    BytesLeft = MEM_BLOCK_SIZE;
    return( TRUE );
}
Exemplo n.º 15
0
/*
 * shrinkUndoStack - reduce size of undo stack by one
 */
static void shrinkUndoStack( undo_stack *stack )
{
    stack->current--;
    if( stack->current < 0 ) {
        MemFreePtr( (void **)&stack->stack );
    } else {
        stack->stack = MemReAlloc( stack->stack, (stack->current + 1) * sizeof( undo * ) );
    }

} /* shrinkUndoStack */
Exemplo n.º 16
0
Arquivo: BZDoc.cpp Projeto: tnzk/bz
void CBZDoc::DeleteData(DWORD dwPtr, DWORD dwSize)
{
    if(dwPtr == m_dwTotal) return;
    memmove(m_pData+dwPtr, m_pData+dwPtr+dwSize, m_dwTotal-dwPtr-dwSize);
    m_dwTotal -= dwSize;
#ifdef FILE_MAPPING
    if(!IsFileMapping())
#endif //FILE_MAPPING
        m_pData = (LPBYTE)MemReAlloc(m_pData, m_dwTotal);
    TouchDoc();
}
Exemplo n.º 17
0
static void buildDefaults( void )
{
    section_size    def_sections[] = DEFAULT_STATUSSECTIONS;

    ReplaceString( &EditVars.StatusString, DEFAULT_STATUSSTRING );

    EditVars.NumStatusSections = NARRAY( def_sections );
    EditVars.StatusSections = MemReAlloc( EditVars.StatusSections, sizeof( def_sections ) );
    memcpy( EditVars.StatusSections, def_sections, sizeof( def_sections ) );

    totalRedraw();
}
Exemplo n.º 18
0
/*
 * AddToHeapList - add a new item to the heap list
 */
static BOOL AddToHeapList( heap_list *hl )
{
    void        *ptr;
    ptr = MemReAlloc( HeapList,
                    sizeof( heap_list * ) * (HeapListSize + 1) );
    if( ptr == NULL ) {
        return( FALSE );
    } else {
        HeapList = ptr;
    }
    HeapList[ HeapListSize ] = MemAlloc( sizeof( heap_list ) );
    if( HeapList[ HeapListSize ] == NULL ) return( FALSE );
    *HeapList[ HeapListSize ] = *hl;
    HeapListSize++;
    return( TRUE );
} /* AddToHeapList */
Exemplo n.º 19
0
/*
 * getNextPos - get a pointer to the next available pointer position
 *              in the element list for a tracking window
 */
static void *getNextPos( DDETrackInfo *listinfo )
{
    WORD                i;
    void                **data;

    data = listinfo->data;
    for( i = 0; i < listinfo->cnt; i++ ) {
        if( data[i] == NULL ) {
            return( data + i );
        }
    }
    listinfo->cnt++;
    listinfo->data = MemReAlloc( listinfo->data,
                                 listinfo->cnt * sizeof( void * ) );
    return( (void **)listinfo->data + listinfo->cnt - 1 );

} /* getNextPos */
Exemplo n.º 20
0
static void splitBlock( int i, char *start )
{
    char    new_ss[MAX_STR];
    int     diff;
    RECT    rect;

    if( EditVars.NumStatusSections == MAX_SECTIONS ) {
        MyBeep();
        return;
    }

    if( i == EditVars.NumStatusSections ) {
        GetWindowRect( status_window_id, &rect );
        diff = rect.right - EditVars.StatusSections[i - 1];
    } else if( i == 0 ) {
        diff = EditVars.StatusSections[1];
    } else {
        diff = EditVars.StatusSections[i] - EditVars.StatusSections[i - 1];
    }

    if( diff < BOUNDARY_WIDTH * 4 ) {
        MyBeep();
        return;
    }
    EditVars.NumStatusSections++;
    EditVars.StatusSections = MemReAlloc( EditVars.StatusSections, EditVars.NumStatusSections * sizeof( section_size ) );
    memmove( EditVars.StatusSections + i + 1, EditVars.StatusSections + i, (EditVars.NumStatusSections - 1 - i) * sizeof( section_size ) );
    if( i > 0 ) {
        EditVars.StatusSections[i] = EditVars.StatusSections[i - 1] + (diff / 2);
    } else {
        EditVars.StatusSections[i] /= 2;
    }

    while( start[0] && !(start[0] == '$' && start[1] == '[') ) {
        start++;
    }
    strncpy( new_ss, EditVars.StatusString, start - EditVars.StatusString );
    new_ss[start - EditVars.StatusString] = '\0';
    strcat( new_ss, "$[ " );
    strcat( new_ss, start );
    ReplaceString( &EditVars.StatusString, new_ss );

    totalRedraw();
}
Exemplo n.º 21
0
/*
 * addDontAttatch
 */
static void addDontAttatch( DWORD pid ) {

    DWORD               i;

    for( i=0; i < noGetUsedSize; i++ ) {
        if( noGetList[i] > pid ) break;
        if( noGetList[i] == pid ) return;
    }
    noGetUsedSize ++;
    if( noGetUsedSize >= noGetAllocSize ) {
        noGetAllocSize += NO_ATTATCH_ALLOC_INCREMENT;
        noGetList = MemReAlloc( noGetList, noGetAllocSize * sizeof( DWORD ) );
    }
    if( i < noGetUsedSize - 1 ) {
        memmove( noGetList + i + 1, noGetList + i,
                    ( noGetUsedSize - i - 1 ) * sizeof( DWORD ) );
    }
    noGetList[ i ] = pid;
}
Exemplo n.º 22
0
/*
 * readCoreInfo - read BITMAPCOREINFO structure from a bitmap file
 */
static BITMAPCOREINFO *readCoreInfo( FILE *fp )
{
    BITMAPCOREINFO      *bm_core;
    BITMAPCOREHEADER    *header;
    long                bitmap_size;

    header = MemAlloc( sizeof( BITMAPCOREHEADER ) );
    if( header == NULL ) {
        return( NULL );
    }
    fseek( fp, START_OF_HEADER, SEEK_SET );
    fread( header, sizeof( BITMAPCOREHEADER ), 1, fp );
    fseek( fp, START_OF_HEADER, SEEK_SET );
    bitmap_size = CORE_INFO_SIZE( header->bcBitCount );
    bm_core = MemReAlloc( header, bitmap_size );
    if( bm_core == NULL ) {
        return( NULL );
    }
    fread( bm_core, bitmap_size, 1, fp );
    return( bm_core );

} /* readCoreInfo */
Exemplo n.º 23
0
/********************************************************************
StrAllocStringAnsi - allocates or reuses dynamic string memory and copies in an existing ANSI string

NOTE: caller is responsible for freeing ppwz even if function fails
NOTE: cchSource must equal the length of wzSource (not including the NULL terminator)
NOTE: if cchSource == 0, length of wzSource is used instead
********************************************************************/
extern "C" HRESULT DAPI StrAllocStringAnsi(
	__inout LPWSTR* ppwz,
	__in LPCSTR szSource,
	__in DWORD_PTR cchSource,
	__in UINT uiCodepage
	)
{
	Assert(ppwz && szSource);

	HRESULT hr = S_OK;
	LPWSTR pwz = NULL;
	DWORD_PTR cch = 0;
	DWORD_PTR cchDest = cchSource;  // at least enough

	if (*ppwz)
	{
		cch = MemSize(*ppwz);  // get the count in bytes so we can check if it failed (returns -1)
		if (-1 == cch)
		{
			ExitOnFailure(hr = E_INVALIDARG, "failed to get size of destination string");
		}
		cch /= sizeof(WCHAR);  //convert the count in bytes to count in characters
	}

	if (0 == cchSource)
	{
		cchDest = ::MultiByteToWideChar(uiCodepage, 0, szSource, -1, NULL, 0);
		if (0 == cchDest)
		{
			ExitWithLastError1(hr, "failed to get required size for conversion to unicode: %s", szSource);
		}

		--cchDest; //subtract one because MultiByteToWideChar includes space for the NULL terminator that we track below
	}
	else if (L'\0' == szSource[cchSource]) // if the source already had a null terminator, don't count that in the character count because we track it below
	{
		cchDest = cchSource - 1;
	}

	if (cch < cchDest + 1)
	{
		cch = cchDest + 1;
		if (cch >= MAXDWORD / sizeof(WCHAR))
		{
			ExitOnFailure1(hr = E_OUTOFMEMORY, "Not enough memory to allocate string of size: %d", cch);
		}

		if (*ppwz)
		{
			pwz = static_cast<LPWSTR>(MemReAlloc(*ppwz, sizeof(WCHAR) * cch, TRUE));
		}
		else
		{
			pwz = static_cast<LPWSTR>(MemAlloc(sizeof(WCHAR) * cch, TRUE));
		}

		ExitOnNull1(pwz, hr, E_OUTOFMEMORY, "failed to allocate string, len: %d", cch);

		*ppwz = pwz;
	}

	if (0 == ::MultiByteToWideChar(uiCodepage, 0, szSource, 0 == cchSource ? -1 : (int)cchSource, *ppwz, (int)cch))
	{
		ExitWithLastError1(hr, "failed to convert to unicode: %s", szSource);
	}
	(*ppwz)[cchDest] = L'\0';

LExit:
	return hr;
}
Exemplo n.º 24
0
/*
 * InsertLinesAtCursor - insert a set of lines at current pos. in file
 */
vi_rc InsertLinesAtCursor( fcb_list *fcblist, undo_stack *us )
{
    fcb         *cfcb;
    linenum     e;
    int         lastLineLen;
    char        *source;
    line        *tLine;
    vi_rc       rc;

    rc = ModificationTest();
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    /*
     * find the number of lines inserted
     */
    e = 0;
    for( cfcb = fcblist->head; cfcb != NULL; cfcb = cfcb->next ) {
        e += (cfcb->end_line - cfcb->start_line + 1);
    }

    // add chars from right of cursor to end of last line of buffer
    source = CurrentLine->data + CurrentPos.column - 1;
    lastLineLen = fcblist->tail->lines.tail->len;
    fcblist->tail->lines.tail->len += CurrentLine->len - CurrentPos.column + 1;

    fcblist->tail->byte_cnt += CurrentLine->len - CurrentPos.column + 1;

    tLine = fcblist->tail->lines.tail->prev;
    fcblist->tail->lines.tail = MemReAlloc( fcblist->tail->lines.tail,
                    sizeof( line ) + fcblist->tail->lines.tail->len + 1 );
    if( tLine ) {
        tLine->next = fcblist->tail->lines.tail;
    }
    strcpy( fcblist->tail->lines.tail->data + lastLineLen, source );

    StartUndoGroup( us );

    // create new current line in work line
    CurrentLineReplaceUndoStart();
    GetCurrentLine();
    WorkLine->len = CurrentPos.column + fcblist->head->lines.head->len - 1;
    strcpy( WorkLine->data + CurrentPos.column - 1, fcblist->head->lines.head->data );

    // replace current line
    ReplaceCurrentLine();
    CurrentLineReplaceUndoEnd( true );

    // remove first line of buffer
    FetchFcb( fcblist->head );
    fcblist->head->non_swappable = true;
    fcblist->head->start_line++;
    fcblist->head->byte_cnt -= fcblist->head->lines.head->len + 1;
    tLine = fcblist->head->lines.head;
    fcblist->head->lines.head = fcblist->head->lines.head->next;
    fcblist->head->lines.head->prev = NULL;
    MemFree( tLine );
    fcblist->head->non_swappable = false;

    // add rest of lines of buffer & done
    if( fcblist->head->lines.head) {
        InsertLines( CurrentPos.line, fcblist, us );
    }
    EndUndoGroup( us );

    // if are indeed linebased, move cursor as well
    if( !EditFlags.LineBased ) {
        GoToLineNoRelCurs( CurrentPos.line + e - 1 );
        GoToColumnOnCurrentLine( lastLineLen + 1 );
    }

    return( ERR_NO_ERR );

} /* InsertLinesAtCursor */
Exemplo n.º 25
0
/********************************************************************
RmuAddProcessById - Adds the process ID to the Restart Manager sesion.

You should call this multiple times as necessary before calling
RmuRegisterResources.

********************************************************************/
extern "C" HRESULT DAPI RmuAddProcessById(
    __in PRMU_SESSION pSession,
    __in DWORD dwProcessId
    )
{
    HRESULT hr = S_OK;
    HANDLE hProcess = NULL;
    FILETIME CreationTime = {};
    FILETIME ExitTime = {};
    FILETIME KernelTime = {};
    FILETIME UserTime = {};
    BOOL fLocked = FALSE;

    HANDLE hToken = NULL;
    TOKEN_PRIVILEGES priv = { 0 };
    TOKEN_PRIVILEGES* pPrevPriv = NULL;
    DWORD cbPrevPriv = 0;
    DWORD er = ERROR_SUCCESS;
    BOOL fAdjustedPrivileges = FALSE;
    BOOL fElevated = FALSE;
    ProcElevated(::GetCurrentProcess(), &fElevated);

    // Must be elevated to adjust process privileges
    if (fElevated) {
        // Adding SeDebugPrivilege in the event that the process targeted by ::OpenProcess() is in a another user context.
        if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
        {
            ExitWithLastError(hr, "Failed to get process token.");
        }

        priv.PrivilegeCount = 1;
        priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        if (!::LookupPrivilegeValueW(NULL, L"SeDebugPrivilege", &priv.Privileges[0].Luid))
        {
            ExitWithLastError(hr, "Failed to get debug privilege LUID.");
        }

        cbPrevPriv = sizeof(TOKEN_PRIVILEGES);
        pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(MemAlloc(cbPrevPriv, TRUE));
        ExitOnNull(pPrevPriv, hr, E_OUTOFMEMORY, "Failed to allocate memory for empty previous privileges.");

        if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv))
        {
            LPVOID pv = MemReAlloc(pPrevPriv, cbPrevPriv, TRUE);
            ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for previous privileges.");
            pPrevPriv = static_cast<TOKEN_PRIVILEGES*>(pv);

            if (!::AdjustTokenPrivileges(hToken, FALSE, &priv, cbPrevPriv, pPrevPriv, &cbPrevPriv))
            {
                ExitWithLastError(hr, "Failed to get debug privilege LUID.");
            }
        }

        fAdjustedPrivileges = TRUE;
    }

    hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
    if (hProcess)
    {
        if (!::GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime))
        {
            ExitWithLastError(hr, "Failed to get the process times for process ID %d.", dwProcessId);
        }

        ::EnterCriticalSection(&pSession->cs);
        fLocked = TRUE;
        hr = RmuApplicationArrayAlloc(&pSession->rgApplications, &pSession->cApplications, dwProcessId, CreationTime);
        ExitOnFailure(hr, "Failed to add the application to the array.");
    }
    else
    {
        er = ::GetLastError();
        if (ERROR_ACCESS_DENIED == er)
        {
            // OpenProcess will fail when not elevated and the target process is in another user context. Let the caller log and continue.
            hr = E_NOTFOUND;
        }
        else
        {
            ExitOnWin32Error(er, hr, "Failed to open the process ID %d.", dwProcessId);
        }
    }

LExit:
    if (hProcess)
    {
        ::CloseHandle(hProcess);
    }

    if (fAdjustedPrivileges)
    {
        ::AdjustTokenPrivileges(hToken, FALSE, pPrevPriv, 0, NULL, NULL);
    }

    ReleaseMem(pPrevPriv);
    ReleaseHandle(hToken);

    if (fLocked)
    {
        ::LeaveCriticalSection(&pSession->cs);
    }

    return hr;
}
Exemplo n.º 26
0
EESTATUS
GetExpr (
    uint radix,
    PEEHSTR phStr,
    ulong  *pEnd
    )
{
    EESTATUS    retval = EENOMEMORY;
    char *pStr;
    char *pExprStr;
    HDEP        hExprStr;
    int         len;
    ulong       strIndex;
    UINT nLen;

    Unreferenced( radix );

    //M00KLUDGE - this routine will eventuall have to walk the bound tree
    //            and format the expression because of ambiguous expressions

    // use the saved original string if there is one
    // (in case the expression has been modified)

    if (pExState->hExStrSav) {
        hExprStr = pExState->hExStrSav;
        len = pExState->ExLenSav;
        strIndex = pExState->strIndexSav;
    } else {
        hExprStr = pExState->hExStr;
        len = pExState->ExLen;
        strIndex = pExState->strIndex;
    }

    pExprStr = (char *) MemLock (hExprStr);

    nLen = len+1;
    if (((*phStr = MemAllocate (nLen)) != 0)) {
        // the expression has been bound and memory allocated
        char        tempBuf[TYPESTRMAX];
        UINT        nb;
        UINT        nIndex = 0;
        BOOL        fHSYM;
        char *psz;
        ulong       nAdj = 0;

        pStr = (char *) MemLock (*phStr);
        for (psz = pExprStr; (psz < pExprStr + len) && *psz; psz = _tcsinc (psz)) {
            fHSYM = FALSE;
            if (*psz == HSYM_MARKER) {
                HSYM hSym = GetHSYMFromHSYMCode(psz + 1);
                psz += HSYM_CODE_LEN;  // skip embedded HSYM code
                fHSYM = TRUE;
                DASSERT (hSym);
                if (GetNameFromHSYM(tempBuf, hSym) == FALSE) {
                    pExState->err_num = ERR_INTERNAL;
                    MemUnLock(*phStr);
                    MemUnLock(hExprStr);
                    return EEGENERAL;
                }
                nb = _tcslen(tempBuf);
                // compute adjustment for strIndex:
                // if an HSYM is to the left of strIndex,
                // strIndex needs to be adjusted
                if (psz <= pExprStr + strIndex)
                    nAdj += (nb - sizeof (char) - HSYM_CODE_LEN);
            } else {
                nb = 1;
            }

            // check if there is space in the buffer and
            // copy nb characters to the destination string

            if (nIndex + nb > nLen-1) {
                // there is not enough space, grow buffer
                MemUnLock(*phStr);
                nLen += NAMESTRMAX;
                if ((*phStr = MemReAlloc(*phStr, nLen)) == 0){
                    MemUnLock(hExprStr);
                    return EENOMEMORY;
                }
                pStr = (char *) MemLock (*phStr);
            }
            if (fHSYM) {
                // copy name from tembBuf
                memcpy(pStr+nIndex, tempBuf, nb);
                nIndex += nb;
            } else {
                // copy a single character from pExprStr
                _tccpy (pStr + nIndex, psz);
                nIndex += _tclen (psz);
            }
        }
        pStr[nIndex++] = 0;
        MemUnLock (*phStr);

        // Reallocate the buffer in case it is too large
        DASSERT (nIndex <= nLen);
        if (nIndex < nLen &&
            (*phStr = MemReAlloc(*phStr, nIndex)) == 0){
            MemUnLock(hExprStr);
            return EENOMEMORY;
        }
        retval = EENOERROR;
        *pEnd = strIndex + nAdj;
    }
    MemUnLock (hExprStr);

    return retval;
}
Exemplo n.º 27
0
/*
 * DIGCliRealloc
 */
void *DIGCLIENT DIGCliRealloc( void *ptr, size_t size ) {
    return( MemReAlloc( ptr, size ) );
}
Exemplo n.º 28
0
void mainCRTStartup()
{
	const UINT cchSubDir = (sizeof(SUBFOLDER) / sizeof(TCHAR)) - 1;
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	UINT ec, cch, cchParams;
	TCHAR *p = GetCommandLine(), *cmd = 0;

	if (*p == _T('\"'))
		do ++p; while(*p && *p != _T('\"'));
	else
		while(*p && *p > _T(' ')) ++p;

	/* Skip end quote and whitespace */
	do if (!*p) break; else ++p; while(*p <= ' ');

	ec = ERROR_OUTOFMEMORY;
	cchParams = lstrlen(p), cch = MAX_PATH;
	for (;;)
	{
		TCHAR *mem;
		UINT cchTot = 1 + cch + 1 + cchSubDir + 2 + cchParams + 1, cchSelf;
		mem = (TCHAR*) MemReAlloc(cmd, cchTot * sizeof(TCHAR));
		if (!mem) goto app_die;
		cmd = mem;
		cchSelf = GetModuleFileName(NULL, cmd + 1, cch);
		if (!cchSelf) goto app_diegle;
		if (cchSelf < cch)
		{
			/* Insert subfolder before the filename */
			TCHAR *src = cmd + cchSelf + 1, *dst = src + cchSubDir + 1;
			for(; src > cmd; --src, --dst)
			{
				*dst = *src;
				if (_T('\\') == *src || _T('/')  == *src) break;
			}
			*++src = _T('\0');
			lstrcat(src, SUBFOLDER);
			src[cchSubDir] = _T('\\');

			/* Quote path and append parameters */
			cmd[0] = _T('\"');
			lstrcat(cmd, _T("\" "));
			lstrcat(cmd, p);
			break;
		}
		cch *= 2;
	}

	MemZero(&si, sizeof(si));
	si.cb = sizeof(si);

	if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
	{
		DWORD forkec;
		WaitForSingleObject(pi.hProcess, INFINITE);
		GetExitCodeProcess(pi.hProcess, &forkec);
		ec = forkec;
		CANLEAK(CloseHandle(pi.hProcess));
		CANLEAK(CloseHandle(pi.hThread));
		goto app_end;
	}

app_diegle:
	ec = GetLastError();
app_die:
	SIOFmtPut("Unable to start child process, error %#x\n", ec);
app_end:
	CANLEAK(MemFree(cmd));
	ExitProcess(ec);
}
Exemplo n.º 29
0
/*
 * processSetToken - set value for set token
 */
static vi_rc processSetToken( int j, char *value, int *winflag, bool isnonbool )
{
    char        fn[MAX_STR], str[MAX_STR];
#ifndef VICOMP
    char        tmp[3];
    char        settokstr[TOK_MAX_LEN + 1];
    char        save[MAX_STR];
    vi_rc       rc = ERR_NO_ERR;
    int         i, clr, k;
    bool        newset;
    bool        set1, toggle, *ptr;
    jmp_buf     jmpaddr;
    cursor_type ct;
    char        *name;
    command_rtn fptr;
    event_bits  eb;
    bool        redisplay = FALSE;
#endif
    bool        bvalue;

#ifdef VICOMP
    winflag = winflag;
    isnonbool = isnonbool;
#endif
    /*
     * set up value for boolean set commands
     */
    if( j < 0 ) {
        j *= -1;
        bvalue = FALSE;
    } else {
        bvalue = TRUE;
    }
#ifndef VICOMP
    if( !(*winflag) ) {
        toggle = TRUE;
        set1 = isnonbool;
    } else {
        toggle = FALSE;
#endif
        if( j >= SET1_T_ ) {
#ifndef VICOMP
            if( EditFlags.CompileScript ) {
#endif
                if( !bvalue ) {
                    j *= -1;
                }
                itoa( j, str, 10 );
                StrMerge( 2, WorkLine->data, str, SingleBlank );
                return( ERR_NO_ERR );
#ifndef VICOMP
            }
            set1 = FALSE;
            j -= SET1_T_;
        } else {
            set1 = TRUE;
#endif
        }
#ifndef VICOMP
    }
    *winflag = FALSE;

    /*
     * process boolean settings
     */
    if( !set1 ) {
        if( j >= SET2_T_ ) {
            return( ERR_INVALID_SET_COMMAND );
        }
        ptr = &(((bool *)&EditFlags)[j]);
        newset = bvalue;
        if( toggle ) {
            newset = !(*ptr);
        }
        switch( j ) {
        case SET2_T_MODELESS:
            if( (newset && !EditFlags.Modeless) ||
                (!newset && EditFlags.Modeless) ) {
                for( k = 0; k < MAX_EVENTS; k++ ) {
                    fptr = EventList[k].rtn;
                    eb = EventList[k].b;
                    EventList[k].rtn = EventList[k].alt_rtn;
                    EventList[k].alt_rtn = fptr;
                    EventList[k].b = EventList[k].alt_b;
                    EventList[k].alt_b = eb;
                }
                if( !EditFlags.Modeless ) {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_INSERT );
                    }
                    EditFlags.WasOverstrike = FALSE;
                    NewCursor( CurrentWindow, EditVars.InsertCursorType );
                } else {
                    if( MenuWindow != NO_WINDOW ) {
                        UpdateCurrentStatus( CSTATUS_COMMAND );
                    }
                    NewCursor( CurrentWindow, EditVars.NormalCursorType );
                    // nomodeless must be line based or it dies!
                    EditFlags.LineBased = TRUE;
                }
                /* re-position cursor in window
                */
                SetWindowCursor();
            }
            EditFlags.Modeless = newset;
            break;
        case SET2_T_UNDO:
            if( EditFlags.Undo && !newset ) {
                FreeAllUndos();
            }
            EditFlags.Undo = newset;
            break;
        case SET2_T_STATUSINFO:
            EditFlags.StatusInfo = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            rc = NewStatusWindow();
            break;
        case SET2_T_WINDOWGADGETS:
            EditFlags.WindowGadgets = newset;
            ResetAllWindows();
            *winflag = TRUE;
            redisplay = TRUE;
            break;
        case SET2_T_REALTABS:
            EditFlags.RealTabs = newset;
            redisplay = TRUE;
            break;
        case SET2_T_CLOCK:
            EditFlags.Clock = newset;
            redisplay = TRUE;
            break;
        case SET2_T_TOOLBAR:
            EditFlags.Toolbar = newset;
#ifdef __WIN__
            ResizeRoot();
#endif
            break;
        case SET2_T_COLORBAR:
            EditFlags.Colorbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Colorbar = FALSE;
            } else {
                RefreshColorbar();
            }
#endif
            break;
        case SET2_T_SSBAR:
            EditFlags.SSbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.SSbar = FALSE;
            } else {
                RefreshSSbar();
            }
#endif
            break;
        case SET2_T_FONTBAR:
            EditFlags.Fontbar = newset;
#ifdef __WIN__
            if( Root == NULL ) {
                EditFlags.Fontbar = FALSE;
            } else {
                RefreshFontbar();
            }
#endif
            break;
        case SET2_T_MARKLONGLINES:
            EditFlags.MarkLongLines = newset;
            break;
        case SET2_T_MENUS:
            EditFlags.Menus = newset;
            InitMenu();
            break;
        case SET2_T_LINENUMBERS:
            if( toggle ) {
                newset = !EditFlags.LineNumbers;
            }
            if( newset != EditFlags.LineNumbers ) {
                EditFlags.LineNumbers = newset;
                rc = LineNumbersSetup();
                *winflag = TRUE;
            }
            break;
        case SET2_T_CURRENTSTATUS:
            EditFlags.CurrentStatus = newset;
            InitMenu();
            break;
        case SET2_T_DISPLAYSECONDS:
            EditFlags.DisplaySeconds = newset;
            redisplay = TRUE;
            break;
        case SET2_T_PPKEYWORDONLY:
            EditFlags.PPKeywordOnly = newset;
            redisplay = TRUE;
            break;
        case SET2_T_LASTEOL:
#ifndef __WIN__
            *ptr = TRUE;
            toggle = FALSE;
            break;
#endif
        default:
            *ptr = newset;
            break;
        }
        if( msgFlag ) {
            if( !newset ) {
                tmp[0] = 'n';
                tmp[1] = 'o';
                tmp[2] = 0;
            } else {
                tmp[0] = 0;
            }
            MySprintf( fn, "%s%s set", tmp, GetTokenStringCVT( SetTokens2, j, settokstr, TRUE ) );
        }
        if( toggle ) {
            strcpy( save, BoolStr[(int) newset] );
            (*winflag) += 1;
        }

    /*
     * process value settings
     */
    } else {
        if( toggle ) {
            rc = GetNewValueDialog( value );
            if( rc != ERR_NO_ERR ) {
                return( rc );
            }
            strcpy( save, value );
        }
#endif /* VICOMP */
        RemoveLeadingSpaces( value );
        if( value[0] == '"' ) {
            NextWord( value, fn, "\"" );
            EliminateFirstN( value, 1 );
        } else {
            NextWord1( value, fn );
        }
#ifndef VICOMP
        if( EditFlags.CompileScript ) {
#endif
            itoa( j, str, 10 );
            strcat( WorkLine->data, str );
            if( fn[0] == '\0' )
                return( ERR_NO_ERR );
            switch( j ) {
            case SET1_T_STATUSSTRING:
            case SET1_T_FILEENDSTRING:
            case SET1_T_HISTORYFILE:
            case SET1_T_TMPDIR:
            case SET1_T_TAGFILENAME:
                StrMerge( 4, WorkLine->data, SingleBlank, SingleQuote, fn, SingleQuote );
                break;
            case SET1_T_COMMANDCURSORTYPE:
            case SET1_T_OVERSTRIKECURSORTYPE:
            case SET1_T_INSERTCURSORTYPE:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            case SET1_T_TILECOLOR:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                if( NextWord1( value, fn ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( NextWord1( value, str ) <= 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StrMerge( 4, WorkLine->data, fn, SingleBlank, str, SingleBlank );
                break;
            case SET1_T_STATUSSECTIONS:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                while( NextWord1( value, fn ) > 0 ) {
#ifdef VICOMP
                    int k;
#endif
                    k = atoi( fn );
                    if( k <= 0 ) {
                        break;
                    }
                    StrMerge( 2, WorkLine->data, SingleBlank, fn );
                }
                break;
            default:
                StrMerge( 2, WorkLine->data, SingleBlank, fn );
                break;
            }
            return( ERR_NO_ERR );
#ifndef VICOMP
        }
        switch( j ) {
        case SET1_T_STATUSSECTIONS:
            if( EditVars.StatusSections != NULL ) {
                MemFree( EditVars.StatusSections );
                EditVars.StatusSections = NULL;
                EditVars.NumStatusSections = 0;
            }
            for( ;; ) {
                k = atoi( fn );
                if( k <= 0 ) {
                    break;
                }
                EditVars.StatusSections = MemReAlloc( EditVars.StatusSections,
                                    sizeof( short ) * (EditVars.NumStatusSections + 1) );
                EditVars.StatusSections[EditVars.NumStatusSections] = k;
                EditVars.NumStatusSections++;
                if( NextWord1( value, fn ) <= 0 ) {
                    break;
                }
            }
            if( EditVars.StatusSections == NULL ) {
                MySprintf( fn, "statussections turned off" );
            } else {
                MySprintf( fn, "statussections set" );
            }
            break;
        case SET1_T_FILEENDSTRING:
            AddString2( &EditVars.FileEndString, fn );
            ResetAllWindows();
            redisplay = TRUE;
            break;
        case SET1_T_STATUSSTRING:
            AddString2( &EditVars.StatusString, fn );
            if( StatusWindow != NO_WINDOW ) {
                ClearWindow( StatusWindow );
                UpdateStatusWindow();
            }
            if( msgFlag ) {
                MySprintf( fn, "statusstring set to %s", EditVars.StatusString );
            }
            break;
        case SET1_T_GREPDEFAULT:
            AddString2( &EditVars.GrepDefault, fn );
            break;
        case SET1_T_TILECOLOR:
            if( EditVars.TileColors == NULL ) {
                EditVars.TileColors = (type_style *) MemAlloc( sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( i = 0; i <= EditVars.MaxTileColors; ++i ) {
                    EditVars.TileColors[i].foreground = -1;
                    EditVars.TileColors[i].background = -1;
                    EditVars.TileColors[i].font = -1;
                }
            }
            clr = atoi( fn );
            if( clr > EditVars.MaxTileColors ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].foreground = atoi( fn );
            if( NextWord1( value, fn ) <= 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            EditVars.TileColors[clr].background = atoi( fn );
            EditVars.TileColors[clr].font = FONT_DEFAULT;
            if( msgFlag ) {
                MySprintf( fn, "tilecolor %d set", clr );
            }
            break;
        case SET1_T_GADGETSTRING:
            SetGadgetString( fn );
            if( msgFlag ) {
                MySprintf( fn, "gadget string set to %s", EditVars.GadgetString );
            }
            ResetAllWindows();
            break;
        case SET1_T_SHELLPROMPT:
            AddString2( &EditVars.SpawnPrompt, fn );
            if( msgFlag ) {
                MySprintf( fn, "prompt string set to %s", EditVars.SpawnPrompt );
            }
            break;
        case SET1_T_FIGNORE:
            if( fn[0] == 0 ) {
                MemFreePtr( (void **)&EditVars.FIgnore );
                EditVars.CurrFIgnore = 0;
                if( msgFlag ) {
                    MySprintf( fn, "fignore reset" );
                }
            } else {
                EditVars.FIgnore = MemReAlloc( EditVars.FIgnore, EXTENSION_LENGTH * (EditVars.CurrFIgnore + 1) );
                str[0] = '.';
                str[1] = 0;
                strcat( str, fn );
                str[EXTENSION_LENGTH - 1] = 0;
                strcpy( &EditVars.FIgnore[EXTENSION_LENGTH * EditVars.CurrFIgnore], str );
                EditVars.CurrFIgnore++;
                if( msgFlag ) {
                    MySprintf( fn, "%s added to fignore", str );
                }
            }
            break;
        case SET1_T_HISTORYFILE:
            AddString2( &EditVars.HistoryFile, fn );
            if( msgFlag ) {
                MySprintf( fn, "history file set to %s", EditVars.HistoryFile );
            }
            break;

        case SET1_T_TAGFILENAME:
            AddString2( &EditVars.TagFileName, fn );
            if( msgFlag ) {
                MySprintf( fn, "tag file name set to %s", EditVars.TagFileName );
            }
            break;

        case SET1_T_FILENAME:
            if( CurrentFile != NULL ) {
                AddString2( &(CurrentFile->name), fn );
                SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE );
                if( msgFlag ) {
                    MySprintf( fn, "filename set to %s", CurrentFile->name );
                }
                FileSPVAR();
            }
            break;
        case SET1_T_TMPDIR:
            AddString2( &EditVars.TmpDir, fn );
            VerifyTmpDir();
            if( msgFlag ) {
                MySprintf( fn, "tmpdir set to %s", EditVars.TmpDir );
            }
            break;
        case SET1_T_WORD:
            AddString2( &EditVars.WordDefn, fn );
            InitWordSearch( EditVars.WordDefn );
            if( msgFlag ) {
                MySprintf( fn, "word set to %s", EditVars.WordDefn );
            }
            break;
        case SET1_T_WORDALT:
            AddString2( &EditVars.WordAltDefn, fn );
            if( msgFlag ) {
                MySprintf( fn, "wordalt set to %s", EditVars.WordAltDefn );
            }
            break;
        case SET1_T_MAGICSTRING:
            AddString2( &EditVars.Majick, fn );
            if( msgFlag ) {
                MySprintf( fn, "magicstring set to %s", EditVars.Majick );
            }
            break;
        case SET1_T_COMMANDCURSORTYPE:
        case SET1_T_OVERSTRIKECURSORTYPE:
        case SET1_T_INSERTCURSORTYPE:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            ct.height = GetConstExpr();
            if( NextWord1( value, fn ) <= 0 ) {
                ct.width = 100;
            } else {
                i = setjmp( jmpaddr );
                if( i != 0 ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                StartExprParse( fn, jmpaddr );
                ct.width = GetConstExpr();
            }
            if( j == SET1_T_COMMANDCURSORTYPE ) {
                EditVars.NormalCursorType = ct;
                name = "command";
            } else if( j == SET1_T_OVERSTRIKECURSORTYPE ) {
                EditVars.OverstrikeCursorType = ct;
                name = "overstrike";
            } else {
                EditVars.InsertCursorType = ct;
                name = "insert";
            }
            if( msgFlag ) {
                MySprintf( fn, "%s cursor type set to %d,%d", name,
                                ct.height, ct.width );
            }
            break;
        default:
            i = setjmp( jmpaddr );
            if( i != 0 ) {
                return( ERR_INVALID_SET_COMMAND );
            }
            StartExprParse( fn, jmpaddr );
            i = GetConstExpr();
            if( i < 0 ) {
                i = 0;
            }
            switch( j ) {
            case SET1_T_WRAPMARGIN:
                EditVars.WrapMargin = i;
                break;
            case SET1_T_CURSORBLINKRATE:
                SetCursorBlinkRate( i );
                break;
            case SET1_T_MAXPUSH:
                EditVars.MaxPush = i;
                if( EditVars.MaxPush < 1 ) {
                    EditVars.MaxPush = 1;
                }
                InitFileStack();
                break;
            case SET1_T_RADIX:
                EditVars.Radix = i;
                break;
            case SET1_T_AUTOSAVEINTERVAL:
                EditVars.AutoSaveInterval = i;
                SetNextAutoSaveTime();
                break;
            case SET1_T_LANGUAGE:
                if( i < LANG_NONE || i >= LANG_MAX ) {
                    return( ERR_INVALID_SET_COMMAND );
                }
                if( CurrentInfo != NULL ) {
                    LangFini( CurrentInfo->fsi.Language );
                    LangInit( i );
                    redisplay = TRUE;
                }
                break;
            case SET1_T_MOVECOLOR:
                EditVars.MoveColor = i;
                break;
            case SET1_T_RESIZECOLOR:
                EditVars.ResizeColor = i;
                break;
            case SET1_T_MOUSEDCLICKSPEED:
                EditVars.MouseDoubleClickSpeed = i;
                break;
            case SET1_T_MOUSESPEED:
                SetMouseSpeed( i );
                break;
            case SET1_T_MOUSEREPEATDELAY:
                EditVars.MouseRepeatDelay = i;
                break;
            case SET1_T_CURRENTSTATUSCOLUMN:
                EditVars.CurrentStatusColumn = i;
                InitMenu();
                break;
            case SET1_T_ENDOFLINECHAR:
                EditVars.EndOfLineChar = i;
                break;
            case SET1_T_EXITATTR:
                EditVars.ExitAttr = (char) i;
                break;
            case SET1_T_INACTIVEWINDOWCOLOR:
                EditVars.InactiveWindowColor = i;
                break;
            case SET1_T_TABAMOUNT:
                EditVars.TabAmount = i;
                break;
            case SET1_T_SHIFTWIDTH:
                EditVars.ShiftWidth = i;
                break;
            case SET1_T_PAGELINESEXPOSED:
                EditVars.PageLinesExposed = i;
                break;
            case SET1_T_HARDTAB:
                EditVars.HardTab = i;
                redisplay = TRUE;
                break;
            case SET1_T_STACKK:
                if( EditFlags.Starting ) {
                    EditVars.StackK = i;
                }
                break;
            case SET1_T_LINENUMWINWIDTH:
                EditVars.LineNumWinWidth = i;
                break;
            case SET1_T_MAXWINDOWTILEX:
                EditVars.MaxWindowTileX = i;
                break;
            case SET1_T_MAXWINDOWTILEY:
                EditVars.MaxWindowTileY = i;
                break;
            case SET1_T_MAXSWAPK:
                SwapBlockInit( i );
                break;
            case SET1_T_MAXEMSK:
#ifndef NOEMS
                EMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXXMSK:
#ifndef NOXMS
                XMSBlockInit( i );
#endif
                break;
            case SET1_T_MAXFILTERHISTORY:
                FilterHistInit( i );
                break;
            case SET1_T_MAXCLHISTORY:
                CLHistInit( i );
                break;
            case SET1_T_MAXFINDHISTORY:
                FindHistInit( i );
                break;
            case SET1_T_MAXLASTFILESHISTORY:
                LastFilesHistInit( i );
                break;
            case SET1_T_MAXTILECOLORS:
                k = (EditVars.TileColors == NULL) ? 0 : EditVars.MaxTileColors + 1;
                EditVars.MaxTileColors = i;
                EditVars.TileColors = MemReAlloc( EditVars.TileColors, sizeof( type_style ) * ( EditVars.MaxTileColors + 1 ) );
                for( ; k <= EditVars.MaxTileColors; ++k ) {
                    EditVars.TileColors[k].foreground = -1;
                    EditVars.TileColors[k].background = -1;
                    EditVars.TileColors[k].font = -1;
                }
                break;
            case SET1_T_CLOCKX:
                EditVars.ClockX = i;
                GetClockStart();
                break;
            case SET1_T_CLOCKY:
                EditVars.ClockY = i;
                GetClockStart();
                break;
            case SET1_T_SPINX:
                EditVars.SpinX = i;
                GetSpinStart();
                break;
            case SET1_T_SPINY:
                EditVars.SpinY = i;
                GetSpinStart();
                break;
            case SET1_T_MAXLINELEN:
                /* file save fails if 1 line is > MAX_IO_BUFFER */
                i = __min( i, MAX_IO_BUFFER );
                EditVars.MaxLine = i;
                StaticStart();
                WorkLine = MemReAlloc( WorkLine, sizeof( line ) + EditVars.MaxLine + 2 );
                break;
            case SET1_T_TOOLBARBUTTONHEIGHT:
                EditVars.ToolBarButtonHeight = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARBUTTONWIDTH:
                EditVars.ToolBarButtonWidth = i;
#ifdef __WIN__
                ResizeRoot();
#endif
                break;
            case SET1_T_TOOLBARCOLOR:
                EditVars.ToolBarColor = i;
#ifdef __WIN__
                if( GetToolbarWindow() != NULL ) {
                    InvalidateRect( GetToolbarWindow(), NULL, TRUE );
                    UpdateWindow( GetToolbarWindow() );
                }
#endif
                break;
            default:
                return( ERR_INVALID_SET_COMMAND );
            }

            if( msgFlag ) {
                MySprintf( fn, "%s set to %d", GetTokenStringCVT( SetTokens1, j, settokstr, TRUE ), i );
            }
            break;
        }
    }

    if( msgFlag && rc == ERR_NO_ERR && !EditFlags.Quiet ) {
        setMessage( fn, redisplay );
        rc = DO_NOT_CLEAR_MESSAGE_WINDOW;
    }
    if( rc == ERR_NO_ERR && toggle ) {
        strcpy( value, save );
    }
    return( rc );
#endif /* VICOMP */

} /* processSetToken */
Exemplo n.º 30
0
static  int  ParseArgs( int argc, char **argv )
/*********************************************/
{
    char        *p;
    int         wcc_option;
    int         c;
    int         i;
    list        *new_item;

    initialize_Flags();
    DebugFlag          = 1;
    StackSize = NULL;
    Conventions[0]     = 'r';
    Conventions[1]     = '\0';
    preprocess_only    = 0;
    cpp_want_lines     = 1; /* NB: wcc and wcl default to 0 here */
    cpp_keep_comments  = 0;
    cpp_encrypt_names  = 0;
    cpp_linewrap       = NULL;
    O_Name             = NULL;

    AltOptChar = '-'; /* Suppress '/' as option herald */
    while( (c = GetOpt( &argc, argv,
#if 0
                        "b:Cc::D:Ef:g::"
                        "HI:i::k:L:l:M::m:"
                        "O::o:P::QSs::U:vW::wx:yz::",
#else
                        "b:CcD:Ef:g::"
                        "HI:i::k:L:l:M::m:"
                        "O::o:P::QSs::U:vW::wx::yz::",
#endif
                        EnglishHelp )) != -1 ) {

        char    *Word = "";
        int     found_mapping = FALSE;

        for( i = 0; i < sizeof( mappings ) / sizeof( mappings[0] ); i++ ) {
            option_mapping  *m    = mappings + i;
            char            *tail = strchr( m->LongName, ':' );

            if( c != m->LongName[0] )
                continue;
            if( OptArg == NULL ) {
                if( m->LongName[1] == '\0' ) {
                    strcat( CC_Opts, " -" );
                    strcat( CC_Opts, m->WatcomName );
                    found_mapping = TRUE;
                    break;
                }
                /* non-existant argument can't match other cases */
                continue;
            }
            if( tail != NULL ) {
                if( !strncmp( OptArg, m->LongName + 1,
                              tail - m->LongName - 1 ) ) {
                    strcat( CC_Opts, " -" );
                    strcat( CC_Opts, m->WatcomName );
                    strcat( CC_Opts, OptArg + ( tail - m->LongName - 1) );
                    found_mapping = TRUE;
                    break;
                }
            } else if( !strcmp( OptArg, m->LongName + 1 ) ) {
                strcat( CC_Opts, " -" );
                strcat( CC_Opts, m->WatcomName );
                found_mapping = TRUE;
                break;
            }
        }
        if( found_mapping )
            continue;

        if( OptArg != NULL ) {
            Word = MemAlloc( strlen( OptArg ) + 6 );
            strcpy( Word, OptArg );
        }

        wcc_option = 1;

        switch( c ) {
        case 'f':
            if( !strcmp( Word, "syntax-only" ) ) {
                c = 'z';
                strcpy( Word, "s" );
                Flags.no_link = 1;
                break;
            }
            if( !strncmp( Word, "cpp-wrap=", 9 ) ) {
                MemFree( cpp_linewrap );
                Word[7] = 'w';
                cpp_linewrap = MemStrDup( Word + 7 );
                wcc_option = 0;
                break;
            }
            if( !strcmp( Word, "mangle-cpp" ) ) {
                cpp_encrypt_names = 1;
                wcc_option = 0;
                break;
            }
            switch( Word[0] ) {
            case 'd':           /* name of linker directive file */
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    MakeName( Word, ".lnk" );    /* add extension */
                    MemFree( Link_Name );
                    Link_Name = strfdup( Word + 2 );
                } else {
                    MemFree( Link_Name );
                    Link_Name = MemStrDup( TEMPFILE );
                }
                wcc_option = 0;
                break;
            case 'm':           /* name of map file */
                Flags.map_wanted = TRUE;
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    MemFree( Map_Name );
                    Map_Name = strfdup( Word + 2 );
                }
                wcc_option = 0;
                break;
            case 'o':           /* name of object file */
                /* parse off argument, so we get right filename
                   in linker command file */
                p = &Word[1];
                if( Word[1] == '='  ||  Word[1] == '#' ) {
                    ++p;
                }
                MemFree( Obj_Name );
                Obj_Name = strfdup( p );        /* 08-mar-90 */
                break;
            case 'r':           /* name of error report file */
                Flags.want_errfile = TRUE;
                break;
            }
            /* avoid passing on unknown options */
            wcc_option = 0;
            break;

        case 'k':               /* stack size option */
            if( Word[0] != '\0' ) {
                MemFree( StackSize );
                StackSize = MemStrDup( Word );
            }
            wcc_option = 0;
            break;

        /* compiler options that affect the linker */
        case 'c':           /* compile only */
            Flags.no_link = TRUE;
            wcc_option = 0;
            break;
        case 'x':           /* change source language */
            if( strcmp( Word, "c" ) == 0 ) {
                Flags.force_c = TRUE;
            } else if( strcmp( Word, "c++" ) == 0 ) {
                Flags.force_c_plus = TRUE;
            } else {
                Flags.no_link = TRUE;
            }
            wcc_option = 0;
            break;

        case 'm':
            if( ( !strncmp( "cmodel=", Word, 7 ) )
                && ( Word[8] == '\0' ) ) {
                if( Word[7] == 't' ) {      /* tiny model */
                    Word[0] = 's';              /* change to small */
                    Flags.tiny_model = TRUE;
                } else {
                    Word[0] = Word[7];
                }
                Word[1] = '\0';
                break;
            }
            if( !strncmp( "regparm=", Word, 8 ) ) {
                if( !strcmp( Word + 8, "0" ) ) {
                    Conventions[0] =  's';
                } else {
                    Conventions[0] = 'r';
                }
                wcc_option = 0;
                break;
            }
            if( !strncmp( "tune=i", Word, 6 ) ) {
                switch( Word[6] ) {
                case '0':
                case '1':
                case '2':
                    CPU_Class = Word[6];
                    Conventions[0] = '\0';
                    break;
                case '3':
                case '4':
                case '5':
                case '6':
                    CPU_Class = Word[6];
                    break;
                default:
                    /* Unknown CPU type --- disable generation of this
                     * option */
                    CPU_Class = '\0';
                }
                wcc_option = 0;
                break;
            }
            wcc_option = 0;     /* dont' pass on unknown options */
            break;

        case 'z':                   /* 12-jan-89 */
            switch( tolower( Word[0] ) ) {
            case 's':
                Flags.no_link = TRUE;
                break;
            case 'q':
                Flags.be_quiet = TRUE;
                break;
            case 'w':
                Flags.windows = TRUE;
            }
            break;
        case 'E':
            preprocess_only = 1;
            wcc_option = 0;
            break;
        case 'P':
            cpp_want_lines = 0;
            wcc_option = 0;
            break;
        case 'C':
            cpp_keep_comments = 1;
            wcc_option = 0;
            break;
        case 'o':
            MemFree( O_Name );
            O_Name = strfdup( OptArg );
            wcc_option = 0;
            break;
        case 'g':
            if( OptArg == NULL ) {
                Word = "2";
            } else if( !isdigit( OptArg[0] ) ) {
                c = 'h';
                if( strcmp( Word, "w" ) == 0 ) {
                    DebugFlag = 3;
                } else if( strcmp( Word, "c" ) == 0 ) { /* 02-mar-91 */
                    Flags.do_cvpack = 1;
                    DebugFlag = 4;
                } else if( strcmp( Word, "d" ) == 0 ) {
                    DebugFlag = 5;
                }
                break;
            }
            c = 'd';
        parse_d:
            if( DebugFlag == 0 ) {  /* not set by -h yet */
                if( strcmp( Word, "1" ) == 0 ) {
                    DebugFlag = 1;
                } else if( strcmp( Word, "1+" ) == 0 ) { /* 02-mar-91 */
                    DebugFlag = 2;
                } else if( strcmp( Word, "2" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "2i" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "2s" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3i" ) == 0 ) {
                    DebugFlag = 2;
                } else if( strcmp( Word, "3s" ) == 0 ) {
                    DebugFlag = 2;
                }
            }
            break;
        case 'S':
            Flags.do_disas = TRUE;
            Flags.no_link = TRUE;
            if( DebugFlag == 0 ) {
                c = 'd';
                Word = "1";
                goto parse_d;
            }
            wcc_option = 0;
            break;
        case 's':
            if( OptArg != NULL ) {
                /* leave -shared to mapping table */
                wcc_option = 0;
                break;
            }
            Flags.strip_all = 1;
            DebugFlag = 0;
            wcc_option = 0;
            break;
        case 'v':
            Flags.be_quiet = 0;
            wcc_option = 0;
            break;
        case 'W':
            if( OptArg != NULL && strncmp( OptArg, "l,", 2 ) == 0 ) {
                AddDirective( OptArg + 2 );
                wcc_option = 0;
            }
            /* other cases handled by table */
            break;
        case 'I':
            xlate_fname( Word );
            break;
        case 'b':
            Flags.link_for_sys = TRUE;
            MemFree( SystemName );
            SystemName = MemStrDup( Word );
            /* if Word found in specs.owc, add options from there: */
            if( ConsultSpecsFile( Word ) ) {
                /* all set */
                wcc_option = 0;
            } else {
                /* not found --- default to bt=<system> */
                strcpy( Word, "t=" );
                strcat( Word, SystemName );
            }
            break;
        case 'l':
            new_item = MemAlloc( sizeof( list ) );
            new_item->next = NULL;
            p = MemAlloc( strlen( OptArg ) + 2 + 1 );
            strcpy( p, OptArg );
            strcat( p, ".a" );
            new_item->item = strfdup( p );
            MemFree( p );
            ListAppend( &Libs_List, new_item );
            wcc_option = 0;
            break;
        case 'L':
            xlate_fname( Word );
            fputs( "libpath ", Fp );
            Fputnl( Word, Fp );
            wcc_option = 0;
            break;
        case 'i':       /* -include <file> --> -fi=<file> */
            if( OptArg == NULL ) {
                wcc_option = 0;
                break;
            }
            if( !strcmp( OptArg, "nclude" ) ) {
                c = 'f';
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -include missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "i=" );
                strfcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
                break;
            }
            /* avoid passing un unknown options */
            wcc_option = 0;
            break;

        case 'M':               /* autodepend information for Unix makes */
            if( OptArg == NULL ) {
                wcc_option = 0;
                break;
            }
            c = 'a';
            if( !strcmp( OptArg, "D" ) ||
                !strcmp( OptArg, "MD" ) ) {
                /* NB: only -MMD really matches OW's behaviour, but
                 * for now, let's accept -MD to mean the same */
                /* translate to -adt=.o */
                strcpy( Word, "dt=.o" );
            } else if( !strcmp( OptArg, "F" ) ) {
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -MF missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "d=" );
                strfcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
            } else if( !strcmp( OptArg, "T") ) {
                Word = MemReAlloc( Word, strlen( argv[OptInd] ) + 6 );
                if( OptInd >= argc - 1 ) {
                    MemFree( cpp_linewrap );
                    PrintMsg( "Argument of -M%s missing\n", OptArg );
                    return( 1 );
                }
                strcpy( Word, "dt=" );
                strcat( Word, argv[OptInd] );
                argv[OptInd++][0] = '\0';
            } else {
                /* avoid passing on incompatible options */
                wcc_option = 0;
            }
            break;
        }

        /* don't add linker-specific options */
        /* to compiler command line:     */
        if( wcc_option ) {
            addccopt( c, Word );
        }
        if( OptArg != NULL ) {
            MemFree( Word );
            Word = NULL;
        }
    }

    if( preprocess_only ) {
        Flags.no_link = TRUE;
        if( O_Name == NULL ) {
            MemFree( Obj_Name );           /* preprocess to stdout by default */
            Obj_Name = NULL;
        }
        strcat( CC_Opts, " -p" );
        if( cpp_encrypt_names )
            strcat( CC_Opts, "e" );
        if( cpp_want_lines )
            strcat( CC_Opts, "l" );
        if( cpp_keep_comments )
            strcat( CC_Opts, "c" );
        if( cpp_linewrap != NULL ) {
            strcat( CC_Opts, cpp_linewrap );
        }
    }
    if( CPU_Class )
        addccopt( CPU_Class, Conventions );
    if( Flags.be_quiet )
        addccopt( 'z', "q" );
    if( O_Name != NULL ) {
        if( Flags.no_link && !Flags.do_disas ) {
            MemFree( Obj_Name );
            Obj_Name = O_Name;
        } else {
            strcpy( Exe_Name, O_Name );
            Flags.keep_exename = 1;
            MemFree( O_Name );
        }
        O_Name = NULL;
    }
    if( Obj_Name != NULL ) {
        strcat( CC_Opts, " -fo=" );
        strcat( CC_Opts, Obj_Name );
    }
    if( !Flags.want_errfile ) {
        strcat( CC_Opts, " -fr" );
    }
    for( i = 1; i < argc ; i++ ) {
        Word = argv[i];
        if( Word == NULL || Word[0] == '\0' )
            /* HBB 20060217: argument was used up */
            continue;
        new_item = MemAlloc( sizeof( list ) );
        new_item->next = NULL;
        new_item->item = strfdup( Word );
        if( FileExtension( Word, ".lib" ) || FileExtension( Word, ".a" ) ) {
            ListAppend( &Libs_List, new_item );
        } else {
            ListAppend( &Files_List, new_item );
        }
    }
    MemFree( cpp_linewrap );
    return( 0 );
}