コード例 #1
0
bool ForceDirectories(const char *Path)
{
	char *pp, *sp, PathCopy[1024];
	if (strlen(Path) >= sizeof(PathCopy)) return false;
	strncpy(PathCopy, Path, sizeof(PathCopy));

	char Delimiter = '\\';

	bool Created = true;
	pp = PathCopy;
	while (Created && (sp = StrChar(pp, Delimiter)) != NULL)
	{
		if (sp != pp)
		{
			*sp = '\0';
			if (!DirectoryExists(PathCopy)) Created = CreateDirectory(PathCopy, NULL);
			*sp = Delimiter;
		}
		pp = sp + 1;
	}
	return Created;
}
コード例 #2
0
/*-------------------------------------------------------------------------*/
APIRET ReadText( INT check )
{
    APIRET           rc;
    INT              i = 0, len = 0;
    INT              x = maxXtext - 1;
    CHAR             last = '\n', *s, *string;
    INDEXTXT        *top, *start;

    FreeTxtIndex();

    string = malloc( MAX_BUFFER );

    if( string == NULL )
        return( ERROR_NOT_ENOUGH_MEMORY );

    if( mode == FILE_TYPE_PKT )
        FidoMsgGetStrSeek( PktFile, Current -> telltxt, SEEK_SET );

    if( mode == FILE_TYPE_MSG )
    {
        if(( rc = OpenFile( Current -> name )) != NO_ERROR )
            return( rc );
        if( fread( &msg, sizeof( msg ), 1, PktFile ) != 1 )
        {
            free( string );
            CloseFile();
            ShowError( "Error read file '%s'", ShowPath( Current -> name, 50 ));
            return( ERROR_READ_FAULT );
        }
        FidoMsgGetStrSeek( PktFile, 0, SEEK_CUR );
    }
        
    intl = origin = id = 0;
    MsgID.Zone = -1;
    
    while( last && FidoMsgGetStr( string, MAX_BUFFER - 1, PktFile, &last ) != NULL )
    {
        if( check )
            CheckString( string, i, Current );

        start = NULL;

        while( 1 )
        {
            len = strlen( string );
            s = &string[ len ];

            if( len > x )
            {
                if(( s = StrChar( string, x, ' ' )) == NULL )
                    if(( s = StrChar( string, x, ',' )) == NULL )
                        if(( s = StrChar( string, x, '.' )) == NULL )
                            if(( s = StrChar( string, x, ';' )) == NULL )
                                s = StrChar( string, x, ':' );
                if( s == NULL )
                {
                    len = x;
                    s = &string[len];
                }
                else
                {
                    len = s - string + 1;
                    s++;
                }
            }

            AddNextStruct( txtIndex, top );

            if( top == NULL )
            {
                free( string );
                return( ERROR_NOT_ENOUGH_MEMORY );
            }

            top -> str = malloc( len + 1 );
            memcpy( top -> str, string, len + 1 );
            top -> str[len] = 0;

            if( !start )
            {
                start = top;
                start -> color = GetLineColor( i, string );
            }
            else
                top -> color = start -> color;

            memcpy( string, s, strlen( s ) + 1 );

            txtcount++;

            if( string[0] == 0 )
                break;
        }
        i++;
        s = &start -> str[1];
    }

    free( string );
    
    if( check )
        CheckString( NULL, 0, Current );
    
    if( mode == FILE_TYPE_MSG )
        CloseFile();

    return( NO_ERROR );
}
コード例 #3
0
ファイル: dfnexpan.c プロジェクト: FDOS/freecom
char *dfnexpand(const char * const fnam, char * const path)
{	char *h, *p;				/* intermediate pointers */
	char *dr, *pa, *na, *ex;	/* filename components */
	char pathDr, *pathPa;		/* drive & path of 'path' */
	char *dynPath;

#ifdef SUPPORT_UNC_PATH
	DBG_ENTER("dfnuexpand", Suppl_dfn)
#else
	DBG_ENTER("dfnexpand", Suppl_dfn)
#endif

	assert(fnam);

	DBG_ARGUMENTS( ("fnam=\"%s\", path=\"%s\"", fnam, path) )

	chkHeap
	if((h = dfnsqueeze(fnam)) == 0) 
		DBG_RETURN_S( 0)

#ifdef SUPPORT_UNC_PATH
	if(isUNCpath(h)) {			/* UNC paths are always fully-qualified */
		/* check if the trailing '\\' is present to mark the root direc */
		DBG_RETURN_BS((*UNCpath(h) != '\\')? StrAppChr(h, '\\') : h)
	}
#endif

	chkHeap
	if(!*h || h[1] != ':' || h[2] != '\\') {
	/* the spec is not fully-qualified or completely empty */
		pathDr = 0;
		dynPath = 0;
		if((pathPa = path) != 0 && *pathPa) {
			if(pathPa[1] == ':') {	/* path[] has drive spec */
				pathDr = *path;
				if(!*(pathPa += 2)) {
					pathPa = 0;
					goto noPath;
				}
			}
			if(dfndelim(*pathPa) && !pathPa[1])
				++pathPa;		/* Trans "/" || "\\" --> "" */
noPath:;
		}
		chkHeap
		if(dfnsplit(h, &dr, &pa, &na, &ex)) {
			StrFree(h);
			if(dr) {				/* drive specified */
				if(pathDr && toFUpper(pathDr) != *dr)
					/* The specified path is for a different drive */
					pathPa = 0;
			}
			else {					/* drive spec missing */
				if((dr = StrChar(pathDr? pathDr: 'A' + getdisk())) == 0)
					goto errRet;
			}

			if(!pa || *pa != '\\' && *pa != NUL) {
			/* no path or a relative one */
				if(!pathPa) {				/* path has no path spec in it */
					if((dynPath = dfnpath(*dr)) == 0)
						goto errRet;
					pathPa = dynPath + 2;
				}

				if((p = dfnmerge(0, 0, pathPa, pa, 0)) == 0)
					goto errRet;
 				StrRepl(pa, p);
			}
			h = dfnmerge(0, dr, pa, na, ex);
		} else
			StrFree(h);

errRet:
		chkHeap
		free(dr);
		free(pa);
		free(na);
		free(ex);
		free(dynPath);
	}