Ejemplo n.º 1
0
static void FS_Push_Vertice(GLuint FontImage, float x, float y, float textx,
                            float texty, struct Vector4f Color, int z) {
    int ID = -1;
    for (int i = 0; i < FS_Texture_Count; i++) {
        if (FS_Font_Image[i] == FontImage && FS_Vertices_Count[i] < FONT_VERTICES_MAX) {
            ID = i;
            break;
        }
    }
    if (ID == -1) {
        if (FS_Texture_Count == TEXTURE_MAX)
            FS_Flush();
        FS_Font_Image[FS_Texture_Count] = FontImage;
        ID = FS_Texture_Count;
        FS_Vertices_Count[FS_Texture_Count] = 0;
        FS_Texture_Count++;
    }
    if (FS_Vertices_Count[ID] == (int)FONT_VERTICES_MAX)
    {
        FS_Flush();
    }
    FS_Vertices[ID][FS_Vertices_Count[ID]] = Vector5_Create(x, y, z, textx, texty);
    FS_Color[ID][FS_Vertices_Count[ID]] = Color;
    FS_Vertices_Count[ID]++;
}
Ejemplo n.º 2
0
/*
* SNAP_RecordDemoMetaDataMessage
*/
static void SNAP_RecordDemoMetaDataMessage( int demofile, msg_t *msg )
{
	int complevel;

	FS_Flush( demofile );

	complevel = FS_GetCompressionLevel( demofile );
	FS_SetCompressionLevel( demofile, 0 );

	DEMO_SAFEWRITE( demofile, msg, true );

	FS_SetCompressionLevel( demofile, complevel );

	FS_Flush( demofile );
}
Ejemplo n.º 3
0
/*
Write a message to a server-side demo file.
*/
void SVD_WriteDemoFile(const client_t *client, const msg_t *msg)
{
        int len;
        msg_t cmsg;
        byte cbuf[MAX_MSGLEN];
        fileHandle_t file = client->demo_file;

        if (*(int *)msg->data == -1) { // TODO: do we need this?
                Com_DPrintf("Ignored connectionless packet, not written to demo!\n");
                return;
        }

        // TODO: we only copy because we want to add svc_EOF; can we add it and then
        // "back off" from it, thus avoiding the copy?
        MSG_Copy(&cmsg, cbuf, sizeof(cbuf), (msg_t*) msg);
        MSG_WriteByte(&cmsg, svc_EOF); // XXX server code doesn't do this, SV_Netchan_Transmit adds it!

        // TODO: the headerbytes stuff done in the client seems unnecessary
        // here because we get the packet *before* the netchan has it's way
        // with it; just not sure that's really true :-/

        len = LittleLong(client->netchan.outgoingSequence);
        FS_Write(&len, 4, file);

        len = LittleLong(cmsg.cursize);
        FS_Write(&len, 4, file);

        FS_Write(cmsg.data, cmsg.cursize, file); // XXX don't use len!
        FS_Flush(file);
}
Ejemplo n.º 4
0
/* DESCRIPTION: COM_CopyFileChunk
// LOCATION: Doesn't appear here, but isn't hard to implement
// PATH: Some HPAK add/remove functions
//
// Two files.  It's like strcpy except for some reason we're given the
// size.  I guess that means don't zero out any pointers.  Since there's no
// return value and the FS catches exceptions, checking for errors doesn't
// seem worthwhile.
*/
void COM_CopyFileChunk(hl_file_t * file1, hl_file_t * file2, int size) {

   char buffer[1024];

   while(size > 1024) {

      FS_Read(buffer, 1, 1024, file2);
      FS_Write(buffer, 1, 1024, file1);
      size -= 1024;
   }
   //little bit to go

   FS_Read(buffer, 1, size, file2);
   FS_Write(buffer, 1, size, file1);

   FS_Flush(file2);
   FS_Flush(file1);
}
Ejemplo n.º 5
0
//*********************************************************************************
//  Function:		CETYPE FS_Rename (FSFILE* filePtr, const char * newName)
//---------------------------------------------------------------------------------
//  Summary:		Renames the file or directory identified by the filePtr
//  Input:
//    				filePtr -  	Pointer to the File Object structure identifying the
//								file to be renamed
//					newName	-	Character string providing new name
//  Return Values:
//    				CE_GOOD	-	File was deleted successfully
//								Other return codes may identify various error 
//								conditions as required.
//  Description:
//    				The FS_Rename(...) function will attempt to rename file or 
//					directory. First, it will search the directory where the entry 
//					is located for an object matching the new name - if such object 
//					found, the operation will fail; otherwise the object will be 
//					renamed.
//*********************************************************************************
CETYPE	FS_Rename (FSFILE* filePtr, const char * newName)
	{
 	//----------------------------------------------------------------
	// Validate conditions and parameters
 	//----------------------------------------------------------------
 	if (!SDFS_InitStatus)
 		return CE_NOT_INIT;		// FS is not initialized!
 	if (NULL == filePtr)
 		return CE_INVALID_ARGUMENT;		
 	if (NULL == newName)
 		return CE_INVALID_ARGUMENT;		
 	//----------------------------------------------------------------
    // Check if the file attributes allow write
    if ( (filePtr->dirFileEntry.DIR_Attr & ATTR_READONLY) == ATTR_READONLY )
        return CE_READONLY;
	//-----------------------------------------------------------------
	CETYPE 	RC			= CE_GOOD;
	char	fmtName[NAME_SIZE_8r3];
	FSFILE	Drtr;
	FSFILE	srchRes;
	DWORD	frstClsNum	= 0;
	//-----------------------------------------------------------------
	// Validate new name and convert it to 8.3 FAT format
	//-----------------------------------------------------------------
	if ( !SDFS_Format8dot3Name(newName, fmtName, FALSE) )
		return CE_INVALID_FILENAME;
	//-----------------------------------------------------------------
	// Prepare Directory File Object to perform search in the file's
	// Directory (Directory where the entry for this file is located)
	//-----------------------------------------------------------------
	// Obtain first cluster number of the file's directory
	frstClsNum = SDFS_DirGetFirstCluster(&filePtr->dirFileEntry);
	// Initialize File Object for file's directory
	SDFS_InitFSFILE(&Drtr, NULL, ATTR_DIRECTORY);
	// Set first cluster of the file's directory
	SDFS_DirSetFirstCluster(&Drtr.dirFileEntry, frstClsNum);
	// Set the current cluster of the file's directory
	Drtr.fileCrntCls = frstClsNum;
	//-----------------------------------------------------------------
	// Perform search for the new name in file's directory
	//-----------------------------------------------------------------
	RC = SDFS_DirFindNext(&Drtr, &srchRes, ATTR_NONE, ATTR_NONE,fmtName);
	if (CE_GOOD == RC)
		// Oops! object with this name already present
		return CE_FILENAME_EXISTS;
	if (CE_EOF != RC)	
		// Some unexpected error code - abort RENAME
		return RC;
	//-----------------------------------------------------------------
	// Name not found - rename the file
	//-----------------------------------------------------------------
	// Update the Name field in the Directory Entry
	memcpy(filePtr->dirFileEntry.DIR_Name, fmtName, NAME_SIZE_8r3);
	// Save updated entry to disk
	return FS_Flush(filePtr);
	}
Ejemplo n.º 6
0
void Log_Write( const char* fmt, ... ) {
	if ( !logfile.fp ) {
		return;
	}
	va_list ap;
	char buffer[ MAXPRINTMSG ];
	va_start( ap, fmt );
	Q_vsnprintf( buffer, sizeof ( buffer ), fmt, ap );
	va_end( ap );
	FS_Write( buffer, String::Length( buffer ), logfile.fp );
	FS_Flush( logfile.fp );
}
Ejemplo n.º 7
0
//*********************************************************************************
//  Function:		CETYPE	FS_Recover(FSFILE* filePtr)
//---------------------------------------------------------------------------------
//  Summary:		Recovers the length of a 0-length file identified by the filePtr
//					based upon the number of allocated clusters
//  Input:
//    				filePtr -  	Pointer to the File Object structure identifying the
//								file to be recovered
//  Return Values:
//    				CE_GOOD	-	File was recovered successfully
//								Other return codes may identify various error 
//								conditions as required.
//*********************************************************************************
CETYPE	FS_Recover(FSFILE* filePtr)
	{
 	//----------------------------------------------------------------
	// Validate conditions and parameters
 	//----------------------------------------------------------------
 	if (!SDFS_InitStatus)
 		return CE_NOT_INIT;		// FS is not initialized!
 	if (NULL == filePtr)
 		return CE_INVALID_ARGUMENT;		
 	//----------------------------------------------------------------
    // Check if this is a file and not a Directory
    if( FS_IsDirectory(filePtr) )
        return CE_DIRECTORY;
    // Check if the file is actually 0-length
    if( FS_GetSize(filePtr) > 0 )
        return CE_GOOD;
	//-----------------------------------------------------------------
	DWORD	ClsSize	= (DWORD)SDFS_VolumeInfo.SecPerClus 
						   * SDFS_VolumeInfo.sectorSize;
	DWORD	ClsNum	= SDFS_DirGetFirstCluster(&filePtr->dirFileEntry);
	//-----------------------------------------------------------------
	while (ClsNum < EOC_CLUSTER_FAT32)
		{
	    //-------------------------------------------------------
		// Process cluster chain
	    //-------------------------------------------------------
	    // The first 2 clusters in FAT32 are reserved...
	    if	( ClsNum < 2)  // Cluster Number can't be "0" and "1"
	    	return CE_RECOVERY_FAIL;
	    //-------------------------------------------------------
	    filePtr->dirFileEntry.DIR_FileSize += ClsSize;
	    //-------------------------------------------------------
	    // Load next cluster in the chain
	    //-------------------------------------------------------
	    ClsNum = SDFS_FATCacheRead(ClsNum);
		}
	//----------------------------------------------------------------- 
	// Flush updates to disk
	//----------------------------------------------------------------- 
	return FS_Flush(filePtr);
	}
Ejemplo n.º 8
0
/*
Stop a server-side demo.

This finishes out the file and clears the demo-related stuff
in client_t again.
*/
static void SVD_StopDemoFile(client_t *client)
{
        int marker = -1;
        fileHandle_t file = client->demo_file;

        Com_DPrintf("SVD_StopDemoFile\n");
        assert(client->demo_recording);

        // write the necessary trailer and close the demo file
        FS_Write(&marker, 4, file);
        FS_Write(&marker, 4, file);
        FS_Flush(file);
        FS_FCloseFile(file);

        // adjust client_t to reflect demo stopped
        client->demo_recording = qfalse;
        client->demo_file = -1;
        client->demo_waiting = qfalse;
        client->demo_backoff = 1;
        client->demo_deltas = 0;
}
Ejemplo n.º 9
0
//*********************************************************************************
//  Function:		CETYPE	FS_Delete (FSFILE* filePtr)
//---------------------------------------------------------------------------------
//  Summary:		Deletes the file identified by the filePtr
//  Input:
//    				filePtr -  	Pointer to the File Object structure identifying the
//								file to be deleted
//  Return Values:
//    				CE_GOOD	-	File was deleted successfully
//								Other return codes may identify various error 
//								conditions as required.
//*********************************************************************************
CETYPE	FS_Delete (FSFILE* filePtr)
	{
 	//----------------------------------------------------------------
	// Validate conditions and parameters
 	//----------------------------------------------------------------
 	if (!SDFS_InitStatus)
 		return CE_NOT_INIT;		// FS is not initialized!
 	if (NULL == filePtr)
 		return CE_INVALID_ARGUMENT;		
 	//----------------------------------------------------------------
    // Check if this is a file and not a Directory
    if( FS_IsDirectory(filePtr) )
        return CE_DELETE_DIR;
    // Check if the file attributes allow write
    if( FS_IsReadOnly(filePtr) )
        return CE_READONLY;
	//-----------------------------------------------------------------
	CETYPE 	RC		= CE_GOOD;
	DWORD	ClsNum	= SDFS_DirGetFirstCluster(&filePtr->dirFileEntry);
	//----------------------------------------------------------------- 
	// Free Cluster Chain and flush changes to disk
	//----------------------------------------------------------------- 
	if (CE_GOOD != (RC = SDFS_FATEraseClusterChain(ClsNum)))
		return RC;
	ClsNum = SDFS_FATCacheFlush();
	if (CLUSTER_FAIL_FAT32 == ClsNum)
		return CE_DISK_ERROR;
	//----------------------------------------------------------------- 
	// Mark Directory Entry as "deleted" and flush updates to disk
	//----------------------------------------------------------------- 
	filePtr->dirFileEntry.DIR_Name[0] = DIR_DEL;
	if (CE_GOOD != (RC = FS_Flush(filePtr)))
		return RC;
	//----------------------------------------------------------------- 
	 return  SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);
	}
Ejemplo n.º 10
0
void Renderer_Flush()
{
    DS_Flush();
    IS_Flush();
    FS_Flush();
}
Ejemplo n.º 11
0
/*
Start a server-side demo.

This does it all, create the file and adjust the demo-related
stuff in client_t.

This is mostly ripped from sv_client.c/SV_SendClientGameState
and cl_main.c/CL_Record_f.
*/
static void SVD_StartDemoFile(client_t *client, const char *path)
{
        int             i, len;
        entityState_t   *base, nullstate;
        msg_t           msg;
        byte            buffer[MAX_MSGLEN];
        fileHandle_t    file;

        Com_DPrintf("SVD_StartDemoFile\n");
        assert(!client->demo_recording);

        // create the demo file and write the necessary header
        file = FS_FOpenFileWrite(path);
        assert(file != 0);

        MSG_Init(&msg, buffer, sizeof(buffer));
        MSG_Bitstream(&msg); // XXX server code doesn't do this, client code does

        MSG_WriteLong(&msg, client->lastClientCommand); // TODO: or is it client->reliableSequence?

        MSG_WriteByte(&msg, svc_gamestate);
        MSG_WriteLong(&msg, client->reliableSequence);

        for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
                if (sv.configstrings[i][0]) {
                        MSG_WriteByte(&msg, svc_configstring);
                        MSG_WriteShort(&msg, i);
                        MSG_WriteBigString(&msg, sv.configstrings[i]);
                }
        }

        Com_Memset(&nullstate, 0, sizeof(nullstate));
        for (i = 0 ; i < MAX_GENTITIES; i++) {
                base = &sv.svEntities[i].baseline;
                if (!base->number) {
                        continue;
                }
                MSG_WriteByte(&msg, svc_baseline);
                MSG_WriteDeltaEntity(&msg, &nullstate, base, qtrue);
        }

        MSG_WriteByte(&msg, svc_EOF);

        MSG_WriteLong(&msg, client - svs.clients);
        MSG_WriteLong(&msg, sv.checksumFeed);

        MSG_WriteByte(&msg, svc_EOF); // XXX server code doesn't do this, SV_Netchan_Transmit adds it!

        len = LittleLong(client->netchan.outgoingSequence-1);
        FS_Write(&len, 4, file);

        len = LittleLong (msg.cursize);
        FS_Write(&len, 4, file);
        FS_Write(msg.data, msg.cursize, file);

        FS_Flush(file);

        // adjust client_t to reflect demo started
        client->demo_recording = qtrue;
        client->demo_file = file;
        client->demo_waiting = qtrue;
        client->demo_backoff = 1;
        client->demo_deltas = 0;
}
Ejemplo n.º 12
0
int main(void)
	{
	//*******************************************************************
	Init();
	TMRInit(2);		// Initialize Timer interface with Priority=2
	BLIInit();		// Initialize Signal interface
	//*******************************************************************
	//_T1IE 	= 0; 	// Temporarily disable Timer1 interrupt
	//*******************************************************************
	LogInit();			// Initialize Data Logger
	//*******************************************************************
	uint	i;
	char		RData[30];
	char		CData[30];

	for (i = 0; i < 30; i++)
		{
		RData[i] = CData[i] = 0;
		}

	char*		pFN		= "log1.txt";
	void*		pWData	= &"01 02 03 04 05 06 07 08 09";
	//-------------------------------------------------------------------
	
	CETYPE			RC;
	uint			ReadCnt;
	
	FSFILE			File;
	//*******************************************************************
	BLISignalON();
	//------------------------------
	// Create (Open) file for Writing and Reading 
	//------------------------------
	RC = FS_CreateFile(pFN, FS_CREATE_NEW, &File);
	while ( RC != CE_GOOD );
	//------------------------------
	// Write sample string to file
	//------------------------------
   	RC = FS_Write (&File, pWData, 26 );
	while (CE_GOOD != RC);
	//------------------------------
	// Check position in the file
	//------------------------------
   	i = FS_GetPosition (&File);
	while (i != 26);
	//------------------------------
	// Seek to start
	//------------------------------
   	FS_SeekStart(&File);
	//------------------------------
	// Reed from start
	//------------------------------
   	RC = FS_Read (&File, RData, 26, &ReadCnt);
	while (CE_GOOD != RC);
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//------------------------------

	//------------------------------
	// Open file for Reading 
	//------------------------------
	RC = FS_CreateFile(pFN, FS_READ_ONLY, &File);
	while ( RC != CE_GOOD );
	//------------------------------
	// Reed from start
	//------------------------------
   	RC = FS_Read (&File, CData, 26, &ReadCnt);
	while (CE_GOOD != RC);
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//------------------------------
	i = 1 + i;
	//*******************************************************************
	BLISignalOFF();
	//------------------------------
	while(1);
	return 0;
	}
Ejemplo n.º 13
0
/*
Start a server-side demo.

This does it all, create the file and adjust the demo-related
stuff in client_t.

This is mostly ripped from sv_client.c/SV_SendClientGameState
and cl_main.c/CL_Record_f.
*/
static void SVD_StartDemoFile(client_t *client, const char *path)
{
	int		i, len;
	entityState_t	*base, nullstate;
	msg_t		msg;
	byte		buffer[MAX_MSGLEN];
	fileHandle_t	file;
#ifdef USE_DEMO_FORMAT_42
	char		*s;
	int			v, size;
#endif

	Com_DPrintf("SVD_StartDemoFile\n");
	assert(!client->demo_recording);

	// create the demo file and write the necessary header
	file = FS_FOpenFileWrite(path);
	assert(file != 0);
	
	/* File_write_header_demo // ADD this fx */
	/* HOLBLIN  entete demo */ 
	#ifdef USE_DEMO_FORMAT_42
		//@Barbatos: get the mod version from the server
		s = Cvar_VariableString("g_modversion");
	
		size = strlen( s );
		len = LittleLong( size );
		FS_Write( &len, 4, file );
		FS_Write( s , size ,  file );
		
		v = LittleLong( PROTOCOL_VERSION );
		FS_Write ( &v, 4 , file );
		
		len = 0;
		len = LittleLong( len );
		FS_Write ( &len, 4 , file );
		FS_Write ( &len, 4 , file );
	#endif
	/* END HOLBLIN  entete demo */ 

	MSG_Init(&msg, buffer, sizeof(buffer));
	MSG_Bitstream(&msg); // XXX server code doesn't do this, client code does

	MSG_WriteLong(&msg, client->lastClientCommand); // TODO: or is it client->reliableSequence?

	MSG_WriteByte(&msg, svc_gamestate);
	MSG_WriteLong(&msg, client->reliableSequence);

	for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
		if (sv.configstrings[i][0]) {
			MSG_WriteByte(&msg, svc_configstring);
			MSG_WriteShort(&msg, i);
			MSG_WriteBigString(&msg, sv.configstrings[i]);
		}
	}

	Com_Memset(&nullstate, 0, sizeof(nullstate));
	for (i = 0 ; i < MAX_GENTITIES; i++) {
		base = &sv.svEntities[i].baseline;
		if (!base->number) {
			continue;
		}
		MSG_WriteByte(&msg, svc_baseline);
		MSG_WriteDeltaEntity(&msg, &nullstate, base, qtrue);
	}

	MSG_WriteByte(&msg, svc_EOF);

	MSG_WriteLong(&msg, client - svs.clients);
	MSG_WriteLong(&msg, sv.checksumFeed);

	MSG_WriteByte(&msg, svc_EOF); // XXX server code doesn't do this, SV_Netchan_Transmit adds it!

	len = LittleLong(client->netchan.outgoingSequence-1);
	FS_Write(&len, 4, file);

	len = LittleLong (msg.cursize);
	FS_Write(&len, 4, file);
	FS_Write(msg.data, msg.cursize, file);

	#ifdef USE_DEMO_FORMAT_42
		// add size of packet in the end for backward play /* holblin */
		FS_Write(&len, 4, file);
	#endif

	FS_Flush(file);

	// adjust client_t to reflect demo started
	client->demo_recording = qtrue;
	client->demo_file = file;
	client->demo_waiting = qtrue;
	client->demo_backoff = 1;
	client->demo_deltas = 0;
}
Ejemplo n.º 14
0
/*
=============
Com_Error

Both client and server can use this, and it will
do the apropriate things.
=============
*/
void Com_Error(error_type_t code, const char *fmt, ...)
{
    char            msg[MAXERRORMSG];
    va_list         argptr;
    size_t          len;

    // may not be entered recursively
    if (com_errorEntered) {
#ifdef _DEBUG
        if (com_debug_break && com_debug_break->integer) {
            Sys_DebugBreak();
        }
#endif
        Sys_Error("recursive error after: %s", com_errorMsg);
    }

    com_errorEntered = qtrue;

    va_start(argptr, fmt);
    len = Q_vscnprintf(msg, sizeof(msg), fmt, argptr);
    va_end(argptr);

    // save error msg
    // can't print into it directly since it may
    // overlap with one of the arguments!
    memcpy(com_errorMsg, msg, len + 1);

    // fix up drity message buffers
    MSG_Init();

    // abort any console redirects
    Com_AbortRedirect();

    // reset Com_Printf recursion level
    com_printEntered = 0;

    X86_POP_FPCW;

    if (code == ERR_DISCONNECT || code == ERR_RECONNECT) {
        Com_WPrintf("%s\n", com_errorMsg);
        SV_Shutdown(va("Server was killed: %s\n", com_errorMsg), code);
        CL_Disconnect(code);
        goto abort;
    }

#ifdef _DEBUG
    if (com_debug_break && com_debug_break->integer) {
        Sys_DebugBreak();
    }
#endif

    // make otherwise non-fatal errors fatal
    if (com_fatal_error && com_fatal_error->integer) {
        code = ERR_FATAL;
    }

    if (code == ERR_DROP) {
        Com_EPrintf("********************\n"
                    "ERROR: %s\n"
                    "********************\n", com_errorMsg);
        SV_Shutdown(va("Server crashed: %s\n", com_errorMsg), ERR_DROP);
        CL_Disconnect(ERR_DROP);
        goto abort;
    }

    if (com_logFile) {
        FS_FPrintf(com_logFile, "FATAL: %s\n", com_errorMsg);
    }

    SV_Shutdown(va("Server fatal crashed: %s\n", com_errorMsg), ERR_FATAL);
    CL_Shutdown();
    NET_Shutdown();
    logfile_close();
    FS_Shutdown();

    Sys_Error("%s", com_errorMsg);
    // doesn't get there

abort:
    if (com_logFile) {
        FS_Flush(com_logFile);
    }
    com_errorEntered = qfalse;
    longjmp(abortframe, -1);
}
Ejemplo n.º 15
0
int main(void)
	{
	//*******************************************************************
	Init();
	TMRInit(2);		// Initialize Timer interface with Priority=2
	BLIInit();		// Initialize Signal interface
	//*******************************************************************
	//_T1IE 	= 0; 	// Temporarily disable Timer1 interrupt
	//*******************************************************************
	LogInit();			// Initialize Data Logger
	//*******************************************************************
	uint	i;
	char		RData[30];
	char		CData[30];

	for (i = 0; i < 30; i++)
		{
		RData[i] = CData[i] = 0;
		}

	char*		pFN		= "log1.txt";
	void*		pWData	= &"01 02 03 04 05 06 07 08 09";
	//-------------------------------------------------------------------
	
	CETYPE			RC;
	uint			ReadCnt;
	
	FSFILE			File;
	SEARCH_STATE	Search;
	//*******************************************************************
	BLISignalON();
	//*******************************************************************
	
	// Search for every entry in the Root
	RC = FS_FindFirst(	"*", ATTR_NONE,  ATTR_NONE, &Search, &File);	
	while (CE_GOOD == RC)
		{
		RC = FS_FindNext(&Search, &File);
		}

	// Search only for files
	RC = FS_FindFirst(	"*", ATTR_NONE,  ATTR_DIRECTORY, &Search, &File);	
	while (CE_GOOD == RC)
		{
		RC = FS_FindNext(&Search, &File);
		}

	// Search only for directories
Deeper:
	RC = FS_FindFirst(	"*", ATTR_DIRECTORY,  ATTR_NONE, &Search, &File);	
	if (CE_GOOD == RC)
		{
		RC = FS_chDir(&File);
		if (CE_GOOD == RC)
			goto Deeper;
		}
		
Higher:
	RC = FS_GetCWD(&File);
	RC = CE_GOOD;
	RC = FS_chDirUp();
	if (CE_GOOD == RC)
		goto Higher;
		
	//*******************************************************************


	//------------------------------
	// Create (Open) file for Writing and Reading 
	//------------------------------
	RC = FS_CreateFile(pFN, FS_CREATE_NEW, &File);
	while ( RC != CE_GOOD );
	//------------------------------
	// Write sample string to file
	//------------------------------
   	RC = FS_Write (&File, pWData, 26 );
	while (CE_GOOD != RC);
	//------------------------------
	// Check position in the file
	//------------------------------
   	i = FS_GetPosition (&File);
	while (i != 26);
	//------------------------------
	// Seek to start
	//------------------------------
   	FS_SeekStart(&File);
	//------------------------------
	// Reed from start
	//------------------------------
   	RC = FS_Read (&File, RData, 26, &ReadCnt);
	while (CE_GOOD != RC);
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//------------------------------

	//------------------------------
	// Open file for Reading 
	//------------------------------
	RC = FS_CreateFile(pFN, FS_READ_ONLY, &File);
	while ( RC != CE_GOOD );
	//------------------------------
	// Reed from start
	//------------------------------
   	RC = FS_Read (&File, CData, 26, &ReadCnt);
	while (CE_GOOD != RC);
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//------------------------------
	i = 1 + i;

	//*******************************************************************
	BLISignalOFF();
	//------------------------------
	while(1);
	return 0;
	}
Ejemplo n.º 16
0
/*
* Com_Printf
* 
* Both client and server can use this, and it will output
* to the apropriate place.
*/
void Com_Printf( const char *format, ... )
{
	va_list	argptr;
	char msg[MAX_PRINTMSG];

	time_t timestamp;
	char timestamp_str[MAX_PRINTMSG];
	struct tm *timestampptr;
	timestamp = time( NULL );
	timestampptr = gmtime( &timestamp );
	strftime( timestamp_str, MAX_PRINTMSG, "%Y-%m-%dT%H:%M:%SZ ", timestampptr );

	va_start( argptr, format );
	Q_vsnprintfz( msg, sizeof( msg ), format, argptr );
	va_end( argptr );

	if( rd_target )
	{
		if( (int)( strlen( msg ) + strlen( rd_buffer ) ) > ( rd_buffersize - 1 ) )
		{
			rd_flush( rd_target, rd_buffer, rd_extra );
			*rd_buffer = 0;
		}
		strcat( rd_buffer, msg );
		return;
	}

	QMutex_Lock( com_print_mutex );

	Con_Print( msg );

	// also echo to debugging console
	Sys_ConsoleOutput( msg );

	// logconsole
	if( logconsole && logconsole->modified )
	{
		logconsole->modified = qfalse;

		if( log_file )
		{
			FS_FCloseFile( log_file );
			log_file = 0;
		}

		if( logconsole->string && logconsole->string[0] )
		{
			size_t name_size;
			char *name;

			name_size = strlen( logconsole->string ) + strlen( ".log" ) + 1;
			name = ( char* )Mem_TempMalloc( name_size );
			Q_strncpyz( name, logconsole->string, name_size );
			COM_DefaultExtension( name, ".log", name_size );

			if( FS_FOpenFile( name, &log_file, ( logconsole_append && logconsole_append->integer ? FS_APPEND : FS_WRITE ) ) == -1 )
			{
				log_file = 0;
				Com_Printf( "Couldn't open: %s\n", name );
			}

			Mem_TempFree( name );
		}
	}

	if( log_file )
	{
		if( logconsole_timestamp && logconsole_timestamp->integer )
			FS_Printf( log_file, "%s", timestamp_str );
		FS_Printf( log_file, "%s", msg );
		if( logconsole_flush && logconsole_flush->integer )
			FS_Flush( log_file ); // force it to save every time
	}

	QMutex_Unlock( com_print_mutex );
}
Ejemplo n.º 17
0
//*************************************************************************************
//  Function:		CETYPE FS_CreateFile (	const char * 	FileName, 
//											FILE_MODE 		mode,
//											FSFILE* 		filePtr )
//  Summary:		Creates/Opens a file with ascii name provided in FileName
//  Input:
//					FileName 	- The name of the file to open
//  		  		mode 		- File open mode (FILE_MODE enum)
//        			- FS_CREATE_NEW		- Create a new file or replace an existing file.
//        			- FS_OPEN_EXISTING	- Open existing file for read/write access or 
//										  creates a new file; file is positioned at the
//										  beginning.
//         			- FS_APPEND			- Open existing file for read/write access or 
//										  creates a new file; file is positioned just
//										  past the last byte.
//        			- FS_READ_ONLY		- Open existing file in read-only mode; file
//										  positioned at the beginning.
//					filePtr		- pointer to FSFILE data structure that will be confi-
//								  gured ro provide access to the file if function
//								  succeeds.
//  Return Values:
//    				CETYPE - Expected CE_GOOD, but may have other codes depending on
//							 various error conditions.
//  Description:
//    				This function will create and/or open specified file.
//    				The specified file name will be formatted to ensure that it's in 8.3
//					format. Next, the search for the specified file name will be
//					performed. If the name is found, the action will be taken based
//					upon the requested File Mode.  
//*************************************************************************************
CETYPE FS_CreateFile (	const char* FileName, FILE_MODE mode, FSFILE* filePtr )
	{
 	//----------------------------------------------------------------
	// Validate conditions and parameters
 	//----------------------------------------------------------------
 	if (!SDFS_InitStatus)
 		return CE_NOT_INIT;		// FS is not initialized!
 	if (NULL == FileName)
 		return CE_INVALID_ARGUMENT;		
 	if (NULL == filePtr)
 		return CE_INVALID_ARGUMENT;		
	//-----------------------------------------------------------------
	
	CETYPE 	RC			= CE_GOOD;
	char	fmtName[NAME_SIZE_8r3];
	
	//-----------------------------------------------------------------
	// Validate new name and convert it to 8.3 FAT format
	//-----------------------------------------------------------------
	if ( !SDFS_Format8dot3Name(FileName, fmtName, FALSE) )
		return CE_INVALID_FILENAME;

 	//================================================================
 	// Make sure that the name provided is unique...
 	//----------------------------------------------------------------
 	FS_SeekStart(&SDFS_CWD);		// Rewind Current Working Directory
 	RC = SDFS_DirFindNext(&SDFS_CWD, filePtr, ATTR_NONE,  ATTR_NONE, fmtName);
 	//----------------------------------------------------------------
 	if (CE_EOF == RC)
 		// There is no object with the same name
 		goto NotFound;
 	//----------------------------------------------------------------			
 	if (CE_GOOD != RC)
 		// Some other error (except for CE_EOF) had happened...
 		return RC;
 	//----------------------------------------------------------------			
 	if ( FS_IsDirectory(filePtr) )
 		// The object found is a Directory...
 		{
	 	SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
	 	return CE_FILENAME_EXISTS;
 		}
 	//----------------------------------------------------------------			


 	//================================================================
 	// The file with the specified name present on the disk...
 	//----------------------------------------------------------------
	switch(mode)
       	{
		case FS_CREATE_NEW:
            // File exists, we want to create a new one, so remove it first
            if ( CE_GOOD != (RC = FS_Delete(filePtr)) )
            	// Delete failed...
            	{
		 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
            	return RC;
            	}
            //-----------------------------------------
            // Nope, does not exist any more :)
            goto NotFound;

               	
		case FS_APPEND:
            // File exists, we want to position it at the end
            if ( CE_GOOD != (RC = FS_SeekEnd(filePtr)) )
            	// Seek failed...
            	{
		 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
            	return RC;
            	}
            //-----------------------------------------
            // Everything is fine!
            return CE_GOOD;
            

		case FS_READ_ONLY:
			// Set READONLY attribute on the FO data structure to prevent WRITEs
			filePtr->dirFileEntry.DIR_Attr |= ATTR_READONLY;
			// Fall-through to OPEN_EXISTING
		case FS_OPEN_EXISTING:
			FS_SeekStart(filePtr);
			return CE_GOOD;
			
			
		default:
	 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
           	return CE_INVALID_ARGUMENT;
       	}


 	//================================================================
 	// The file with the specified name does not exist on disk...
 	//----------------------------------------------------------------
 NotFound:
	switch(mode)
       	{
		case FS_CREATE_NEW:
		case FS_APPEND:
		case FS_OPEN_EXISTING:
			// For all of the cases above proceed to creating new file
			break;
			

		case FS_READ_ONLY:
			// Bad luck...
	 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
           	return CE_NOT_FOUND;
			
			
		default:
	 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
           	return CE_INVALID_ARGUMENT;
       	}


 	//================================================================
 	// Now it is time to create a new file
 	//----------------------------------------------------------------
 	// First, try to create Directory Entry
 	//----------------------------------------------------------------
 	if ( (RC = SDFS_DirFindEmpty(&SDFS_CWD, filePtr)) != CE_GOOD)
 		return RC;		// Could not create directory entry...
 	//----------------------------------------------------------------
 	// Second, allocate a cluster to the file
 	//----------------------------------------------------------------
 	if ( CE_GOOD != (RC = SDFS_ClusterAllocateNew(filePtr)) )
 		{
 		SDFS_InitFSFILE(filePtr, NULL, ATTR_NONE);	// Reset output FSFILE structure
	 	return RC;	
 		}
 	//----------------------------------------------------------------
 	// Third, set the name and Attributes of the new entry
 	//----------------------------------------------------------------
 	memcpy(filePtr->dirFileEntry.DIR_Name, fmtName, NAME_SIZE_8r3);
 	filePtr->dirFileEntry.DIR_Attr = ATTR_ARCHIVE;	
 	//----------------------------------------------------------------
 	// That's basically it - just need to save changes to disk
 	//----------------------------------------------------------------
 	return FS_Flush(filePtr);
	}
Ejemplo n.º 18
0
int main(void)
	{
	//*******************************************************************
	Init();
	TMRInit(2);		// Initialize Timer interface with Priority=2
	BLIInit();		// Initialize Signal interface
	//*******************************************************************
	//_T1IE 	= 0; 	// Temporarily disable Timer1 interrupt
	//*******************************************************************
	LogInit();	// Initialize Data Logger	
	//*******************************************************************
	//-------------------------------------------------------------------
	#define		MaxRec		60
	//-------------------------------------------------------------------
	struct
		{
		DWORD	TS;
		WORD	Index;
		char	filler[506];
		}	Data;
	//-------------------------------------------------------------------
	uint	i;
	for (i = 0; i < sizeof(Data.filler); i++)
		{
		Data.filler[i] = 0;
		}
	//-------------------------------------------------------------------
	DWORD	TimeStart;
	float	TimePoints[MaxRec];
//	WORD	TimeIndex[MaxRec];
	//-------------------------------------------------------------------
	char		pFN[15];

	
	WORD			RC;
	
	uint			ReadCnt;
	FSFILE			File;
	//*******************************************************************
	BLISignalON();
	//------------------------------
	// Create (Open) Log file for Writing and Reading 
	//------------------------------
	RC = LogNewFile(&File);
	while ( RC != LE_GOOD );
	//------------------------------
	// Retrieve and save for future new log file name 
	//------------------------------
	RC = FS_GetName(pFN, 15, &File);
	while ( RC != LE_GOOD );
	//------------------------------
	// Write sample data to file
	//------------------------------
	for (i=0; i < MaxRec; i++)
		{
		Data.Index 	= i;
		Data.TS		= TMRGetTS();
	   	RC = FS_WriteSector(&File, &Data);
		while (CE_GOOD != RC);
		}
	//------------------------------
	// Check position in the file
	//------------------------------
   	i = FS_GetPosition (&File);
	while (i != 512*MaxRec);
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//------------------------------

	//------------------------------
	// Open file for Reading 
	//------------------------------
	RC = FS_CreateFile(pFN, FS_READ_ONLY, &File);
	while ( RC != CE_GOOD );
	//------------------------------
	// Reed records
	//------------------------------
	for (i=0; i < MaxRec; i++)
		{
	   	RC = FS_Read (&File, &Data, sizeof(Data), &ReadCnt);
		while (CE_GOOD != RC);
		//--------------------------
//		TimeIndex[i] = Data.Index;
		//--------------------------
		if (0 == i)
			TimeStart = Data.TS;
		//--------------------------
		TimePoints[i] = (Data.TS - TimeStart) * TMRGetTSRate() * 1000.0;	// in msec
		//--------------------------
		TimeStart = Data.TS;
		}
	//------------------------------
	// Close the file - save changes
	//------------------------------
	RC = FS_Flush(&File);
   	while ( RC != CE_GOOD );
	//*******************************************************************
	BLISignalOFF();
	//------------------------------
	i = 1 + i;
	//------------------------------
	while(1);
	return 0;
	}
Ejemplo n.º 19
0
//*************************************************************************************
//  Function:		CETYPE FS_mkDir (char * Name, ATTR_TYPE Attr, FSFILE* newDir)
//-------------------------------------------------------------------------------------
//  Summary:		Creates directory with the specified name in the current working
//					directory.
//  Input:			
//					Name	- Name of the new directory
//					Attr	- Additional attributes of the new directory
//					newDir	- pointer to the File Object structure that on SUCCESS
//							  will be set to the newly created directory.
//  Return Values:
//					CETYPE enum member (expected CE_GOOD)
//					Other codes depending on encountered error conditions
//*************************************************************************************
CETYPE FS_mkDir (char * Name, ATTR_TYPE Attr, FSFILE* newDir)
	{
 	//----------------------------------------------------------------
	// Validate conditions and parameters
 	//----------------------------------------------------------------
 	if (!SDFS_InitStatus)
 		return CE_NOT_INIT;		// FS is not initialized!
 	if (NULL == Name)
 		return CE_INVALID_FILENAME;		
 	if (NULL == newDir)
 		return CE_INVALID_ARGUMENT;		
 	//----------------------------------------------------------------
 	char	fmtName[NAME_SIZE_8r3];
 	CETYPE	RC;
 	//----------------------------------------------------------------
 	// Verify/Format provided Directory name (for direct match)
 	//----------------------------------------------------------------
 	if ( !SDFS_Format8dot3Name (Name, fmtName, FALSE) )
 		return CE_INVALID_FILENAME;	// Invalid/missing name
 	//----------------------------------------------------------------
 	// Make sure that the name provided is unique...
 	//----------------------------------------------------------------
 	FS_SeekStart(&SDFS_CWD);		// Rewind Current Working Directory
 	RC = SDFS_DirFindNext(&SDFS_CWD, newDir, ATTR_NONE,  ATTR_NONE, fmtName);
 	//----------------------------------------------------------------
 	if (CE_GOOD == RC)
 		{
	 	if ( FS_IsDirectory(newDir) )
	 		// Directory with the same name is found...
	 		return CE_GOOD;
	 	else
	 		// There exists file with the same name...
	 		{
		 	SDFS_InitFSFILE(newDir, NULL, ATTR_NONE);	// Reset output FSFILE structure
		 	return CE_FILENAME_EXISTS;
	 		}
 		}
 	if (CE_EOF != RC)
 		return RC;		// Some other error happend on the way...
 	//----------------------------------------------------------------
 	// The name provided is unique; Try to create Directory Entry
 	//----------------------------------------------------------------
 	if ( (RC = SDFS_DirFindEmpty(&SDFS_CWD, newDir)) != CE_GOOD)
 		return RC;		// Could not create directory entry...
 	//----------------------------------------------------------------
 	// Success; Set the name and Attributes of the new entry
 	//----------------------------------------------------------------
 	memcpy(newDir->dirFileEntry.DIR_Name, fmtName, NAME_SIZE_8r3);
 	newDir->dirFileEntry.DIR_Attr = ATTR_DIRECTORY | ATTR_ARCHIVE;	
 	//----------------------------------------------------------------
 	// Allocate a cluster for the new Directory and create mandatory
 	// "." and ".." entries
 	//----------------------------------------------------------------
 	if ( (RC = SDFS_ClusterAllocateNew(newDir)) != CE_GOOD)
 		// Failure allocating cluster...
 		{
	 	SDFS_InitFSFILE(newDir, NULL, ATTR_NONE);	// Reset output FSFILE structure
	 	return RC;
 		}
 	//----------------------------------------------------------------
 	DIRENTRY	spcDir;
 	DWORD		dirCluster;
 	// Set template Directory record for "." and ".." entries
 	SDFS_DirResetEntry(	&spcDir, NULL, ATTR_DIRECTORY);
 	//----------------------------------------------------------------
 	// Create and store "." entry
 	//----------------------------------------------------------------
 	spcDir.DIR_Name[0] = '.';
 	dirCluster = SDFS_DirGetFirstCluster(&newDir->dirFileEntry);
 	SDFS_DirSetFirstCluster (&spcDir, dirCluster);
 	FS_Write(newDir, &spcDir, sizeof(DIRENTRY));
 	//----------------------------------------------------------------
 	// Create and store ".." entry
 	//----------------------------------------------------------------
 	spcDir.DIR_Name[1] = '.';
 	dirCluster = SDFS_DirGetFirstCluster(&SDFS_CWD.dirFileEntry);
 	if (dirCluster == SDFS_VolumeInfo.rootClsN)
 		// Parent is the Root directory of the volume
 		dirCluster = 0; // FAT32 rule for pointers to Root
 	SDFS_DirSetFirstCluster (&spcDir, dirCluster);
 	FS_Write(newDir, &spcDir, sizeof(DIRENTRY));
 	//----------------------------------------------------------------
 	return FS_Flush(newDir);
	}