?? fio.cpp
字號:
////////////////////////////////////////////////////////////////////////
//+
// Module Name: fio.cpp
//
// Description: FIO specific routines
//
// Include Modules Referenced: fio.h
//
// Written by: John Tal
//
//
// Modification history:
//
// Date Engineer Mod # Modification Description
//
// 12-Feb-1992 Tal v 1.0-001 Initial conversion to C++
//-
////////////////////////////////////////////////////////////////////////
#include <fio.h>
////////////////////////////////////////////////////////////////////////
//+
// Function Name: GetFile
//
// Class: FIO_C
//
// Security: Public
//
// Description: Checks for existance of a file
//
// Parameters
// In: pcSeedPathName = File being looked for
//
// Return Codes: SHORT = FIO_OK = file exists
// = FIO_NO_FILE = file does not exist
//
// Written by: John Tal
//
//
// Modification History:
//
// Date Engineer Mod # Modification Description
//
// 12-Feb-1992 Tal v 1.0-001 Initial conversion to C++
//
//-
////////////////////////////////////////////////////////////////////////
SHORT FIO_C::GetFile(PCHAR pcSeedPathName)
{
C_DEF_MODULE("FIO_C::GetFile")
struct stat stStatMain;
/* check if file exists */
C_STATUS = stat(pcSeedPathName,&stStatMain);
if(C_STATUS)
C_SET_STATUS(FIO_NO_FILE)
else
C_SET_STATUS(FIO_OK)
C_RETURN
}
////////////////////////////////////////////////////////////////////////
//+
// Function Name: RemoveFile
//
// Class: FIO_C
//
// Security: Public
//
// Description: Remove a file, to be called by reader only
//
// Parameters
// In: pcSeedPathName = File to be removed
//
// Return Codes: SHORT = result from system unlink call
//
// Written by: John Tal
//
//
// Modification History:
//
// Date Engineer Mod # Modification Description
//
// 12-Feb-1992 Tal v 1.0-001 Initial conversion to C++
//
//-
////////////////////////////////////////////////////////////////////////
SHORT FIO_C::RemoveFile(PCHAR pcSeedPathName)
{
C_DEF_MODULE("FIO_C::RemoveFile")
C_STATUS = unlink(pcSeedPathName);
C_RETURN
}
////////////////////////////////////////////////////////////////////////
//+
// Function Name: IncSeedPathName
//
// Class: FIO_C
//
// Security: Public
//
// Description: Increment the extension of a filename
//
// Parameters
// In: pcSeedPathName = Filename to increment
//
// Return Codes: SHORT = C_OK = Got an item
// = C_NOTOK = Heap empty
//
// Written by: John Tal
//
//
// Modification History:
//
// Date Engineer Mod # Modification Description
//
// 12-Feb-1992 Tal v 1.0-001 Initial conversion to C++
//
//-
////////////////////////////////////////////////////////////////////////
SHORT FIO_C::IncSeedPathName(PCHAR pcSeedPathName)
{
C_DEF_MODULE("FIO_C::IncSeedPathName")
INT iPos;
CHAR szExtension[FIO_EXTENSION_LEN + 2];
INT iExtension;
CHAR szWorkStr[128];
iPos = FindChar(pcSeedPathName,FIO_PERIOD);
if(iPos == FIO_NO_CHAR)
C_LEAVE(iPos);
strcpy(szExtension,&pcSeedPathName[iPos + 1]);
iExtension = atoi(szExtension);
iExtension++;
if(iExtension > FIO_MAX_EXTENSION)
iExtension = 0;
sprintf(szExtension,"%d",iExtension);
while(strlen(szExtension) < FIO_EXTENSION_LEN)
{
strcpy(szWorkStr,"0");
strcat(szWorkStr,szExtension);
strcpy(szExtension,szWorkStr);
}
strcpy(&pcSeedPathName[iPos + 1],szExtension);
C_MODULE_EXIT:
C_RETURN
}
////////////////////////////////////////////////////////////////////////
//+
// Function Name: FindChar
//
// Class: FIO_C
//
// Security: Private
//
// Description: Looks for a character in a string [0] based
//
// Parameters
// In: pcString = string to check
// cChar = character to search for
//
// Return Codes: SHORT = FIO_NOCHAR = Charcter not found
// = !FIO_NO_CHAR = Offset of charcter in string
//
// Written by: John Tal
//
//
// Modification History:
//
// Date Engineer Mod # Modification Description
//
// 12-Feb-1992 Tal v 1.0-001 Initial conversion to C++
//
//-
////////////////////////////////////////////////////////////////////////
SHORT FIO_C::FindChar(PCHAR pcString, CHAR cChar)
{
C_DEF_MODULE("FIO_C::FindChar")
INT i;
INT iLen;
iLen = strlen(pcString);
for(i = 0; i < iLen; i++)
if(pcString[i] == cChar)
break;
if(i < iLen)
C_SET_STATUS(i)
else
C_SET_STATUS(FIO_NO_CHAR)
C_RETURN
}
#define TEST
#ifdef TEST
#include <cmemlib.h>
#include "mos.h"
char szReaderSeedPathName[] = "Testing.000";
char szWriterSeedPathName[] = "Testing.000";
//
// Reader Proc
//
SHORT
Proc1(MOS_P pclMos, PVOID pvWorkArea)
{
C_DEF_MODULE("Proc1")
FIO_C cFio;
C_STATUS = cFio.GetFile(szReaderSeedPathName);
if(!C_STATUS)
{
printf("Reader: Working on file %s\n",szReaderSeedPathName);
cFio.RemoveFile(szReaderSeedPathName);
cFio.IncSeedPathName(szReaderSeedPathName);
}
else
{
C_STATUS = pclMos -> Sleep(1);
}
pvWorkArea = pvWorkArea; // keep compiler quiet
C_RETURN
}
#define TEMP_FILE_NAME "Temp.Dat"
//
// Writer Proc
//
SHORT
Proc2(MOS_P pclMos,PVOID pvWorkArea)
{
C_DEF_MODULE("Proc2")
FIO_C cFio;
FILE *fp;
fp = fopen(TEMP_FILE_NAME,"w");
fclose(fp);
/* It is highly recommended that you write out the file as a temporary file
and rename it after it is closed. This will prevent the reader from
dealing with situations where the data has not been flushed out to
disk by the operating system (i.e. Unix).
*/
rename(TEMP_FILE_NAME,szWriterSeedPathName);
printf("Writer: Created file %s\n",szWriterSeedPathName);
cFio.IncSeedPathName(szWriterSeedPathName);
// C_STATUS = pclMos -> Sleep(1);
pvWorkArea = pvWorkArea; // keep compiler quiet
C_RETURN
}
main(VOID)
{
C_DEF_MODULE("Fio Test Main")
char szSeedPathName[128 + 1];
int iMode;
int iSts;
FILE * fp;
MOS_C clMos;
C_STATUS = clMos.ProcCreate(Proc1,"FIO_PROC_1",10,NULL);
C_STATUS = clMos.ProcCreate(Proc2,"FIO_PROC_2",10,NULL);
C_STATUS = clMos.Scheduler();
C_RETURN
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -