bfileattributes.cpp

これは、ファイル属性の使用例です。

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include "btrieveCpp.h"
static char *btrieveFileName = (char *)"squaresAndSquareRoots.btr";
createFile(BtrieveClient *btrieveClient)
{
BtrieveFileAttributes btrieveFileAttributes;
// If SetBalancedIndexes() fails.
if ((status = btrieveFileAttributes.SetBalancedIndexes(true)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFileAttributes::SetBalancedIndexes():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetFileVersion() fails.
{
printf("Error: BtrieveFileAttributes::SetFileVersion():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetFixedRecordLength() fails.
if ((status = btrieveFileAttributes.SetFixedRecordLength(4)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFileAttributes::SetFixedRecordLength():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetFreeSpaceThreshold() fails.
{
printf("Error: BtrieveFileAttributes::SetFreeSpaceThreshold():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetPageSize() fails.
if ((status = btrieveFileAttributes.SetPageSize(Btrieve::PAGE_SIZE_16384, true)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFileAttributes::SetPageSize():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetPreallocatedPageCount() fails.
if ((status = btrieveFileAttributes.SetPreallocatedPageCount(64 * 1024 - 1)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFileAttributes::SetPreallocatedPageCount():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetRecordCompressionMode() fails.
{
printf("Error: BtrieveFileAttributes::SetRecordCompressionMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetReservedDuplicatePointerCount() fails.
if ((status = btrieveFileAttributes.SetReservedDuplicatePointerCount(119)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFileAttributes::SetReservedDuplicatePointerCount():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetSystemDataMode() fails.
{
printf("Error: BtrieveFileAttributes::SetSystemDataMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If SetVariableLengthRecordsMode() fails.
{
printf("Error: BtrieveFileAttributes::SetVariableLengthRecordsMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If FileCreate() fails.
if ((status = btrieveClient->FileCreate(&btrieveFileAttributes, btrieveFileName, Btrieve::CREATE_MODE_OVERWRITE)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveClient::FileCreate():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
leave:
return status;
}
openFile(BtrieveClient *btrieveClient, BtrieveFile *btrieveFile)
{
// If FileOpen() fails.
if ((status = btrieveClient->FileOpen(btrieveFile, btrieveFileName, NULL, Btrieve::OPEN_MODE_NORMAL)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveClient::FileOpen():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
leave:
return status;
}
printFileInformation(BtrieveFile *btrieveFile)
{
Btrieve::FileVersion btrieveFileVersion;
Btrieve::FreeSpaceThreshold btrieveFreeSpaceThreshold;
Btrieve::PageSize btrievePageSize;
Btrieve::RecordCompressionMode btrieveRecordCompressionMode;
Btrieve::SystemDataMode btrieveSystemDataMode;
Btrieve::VariableLengthRecordsMode btrieveVariableLengthRecordsMode;
BtrieveFileInformation btrieveFileInformation;
int i;
// If GetInformation() fails.
if ((status = btrieveFile->GetInformation(&btrieveFileInformation)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveFile::GetInformation():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
// If GetBalancedIndexes() fails.
if ((i = btrieveFileInformation.GetBalancedIndexes()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetBalancedIndexes():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("BalancedIndexes = %s\n", i > 0 ? "Yes" : "No");
// If GetFileVersion() fails.
if ((btrieveFileVersion = btrieveFileInformation.GetFileVersion()) == Btrieve::FILE_VERSION_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetFileVersion():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("FileVersion = %s\n", Btrieve::FileVersionToString(btrieveFileVersion));
// If GetFreeSpaceThreshold() fails.
if ((btrieveFreeSpaceThreshold = btrieveFileInformation.GetFreeSpaceThreshold()) == Btrieve::FREE_SPACE_THRESHOLD_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetFreeSpaceThreshold():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("FreeSpaceThreshold = %s\n", Btrieve::FreeSpaceThresholdToString(btrieveFreeSpaceThreshold));
// If GetFixedRecordLength() fails.
if ((i = btrieveFileInformation.GetFixedRecordLength()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetFixedRecordLength():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("FixedRecordLength = %d\n", i);
// If GetPageCompression() fails.
if ((i = btrieveFileInformation.GetPageCompression()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetPageCompression():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("PageCompression = %s\n", i > 0 ? "Yes" : "No");
// If GetPagePreallocation() fails.
if ((i = btrieveFileInformation.GetPagePreallocation()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetPagePreallocation():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("PagePreallocation = %s\n", i > 0 ? "Yes" : "No");
// If GetPageSize() fails.
if ((btrievePageSize = btrieveFileInformation.GetPageSize()) == Btrieve::PAGE_SIZE_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetPageSize():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("PageSize = %s\n", Btrieve::PageSizeToString(btrievePageSize));
// If GetRecordCompressionMode() fails.
if ((btrieveRecordCompressionMode = btrieveFileInformation.GetRecordCompressionMode()) == Btrieve::RECORD_COMPRESSION_MODE_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetRecordCompressionMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("RecordCompressionMode = %s\n", Btrieve::RecordCompressionModeToString(btrieveRecordCompressionMode));
// If GetSystemDataMode() fails.
if ((btrieveSystemDataMode = btrieveFileInformation.GetSystemDataMode()) == Btrieve::SYSTEM_DATA_MODE_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetSystemDataMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("SystemDataMode = %s\n", Btrieve::SystemDataModeToString(btrieveSystemDataMode));
// If GetUnusedDuplicatePointerCount() fails.
if ((i = btrieveFileInformation.GetUnusedDuplicatePointerCount()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetUnusedDuplicatePointerCount():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("UnusedDuplicatePointerCount = %d\n", i);
// If GetUnusedPageCount() fails.
if ((i = btrieveFileInformation.GetUnusedPageCount()) < 0)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetUnusedPageCount():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("UnusedPageCount = %d\n", i);
// If GetVariableLengthRecordsMode() fails.
if ((btrieveVariableLengthRecordsMode = btrieveFileInformation.GetVariableLengthRecordsMode()) == Btrieve::VARIABLE_LENGTH_RECORDS_MODE_UNKNOWN)
{
status = btrieveFileInformation.GetLastStatusCode();
printf("Error: BtrieveFileInformation::GetVariableLengthRecordsMode():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
printf("VariableLengthRecordsMode = %s\n", Btrieve::VariableLengthRecordsModeToString(btrieveVariableLengthRecordsMode));
leave:
return status;
}
closeFile(BtrieveClient *btrieveClient, BtrieveFile *btrieveFile)
{
// If FileClose() fails.
if ((status = btrieveClient->FileClose(btrieveFile)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveClient::FileClose():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
leave:
return status;
}
deleteFile(BtrieveClient *btrieveClient)
{
// If FileDelete() fails.
if ((status = btrieveClient->FileDelete(btrieveFileName)) != Btrieve::STATUS_CODE_NO_ERROR)
{
printf("Error: BtrieveClient::FileDelete():%d:%s.\n", status, Btrieve::StatusCodeToString(status));
goto leave;
}
leave:
return status;
}
int
main(int argc, char *argv[])
{
BtrieveClient btrieveClient(0x4232, 0);
BtrieveFile btrieveFile;
// If the incorrect number of arguments were given.
if (argc != 1)
{
printf("Usage: %s\n", argv[0]);
goto leave;
}
// If createFile() fails.
if ((status = createFile(&btrieveClient)) != Btrieve::STATUS_CODE_NO_ERROR)
{
goto leave;
}
// If openFile() fails.
if ((status = openFile(&btrieveClient, &btrieveFile)) != Btrieve::STATUS_CODE_NO_ERROR)
{
goto leave;
}
// If printFileInformation() fails.
if ((status = printFileInformation(&btrieveFile)) != Btrieve::STATUS_CODE_NO_ERROR)
{
goto leave;
}
// If closeFile() fails.
if ((status = closeFile(&btrieveClient, &btrieveFile)) != Btrieve::STATUS_CODE_NO_ERROR)
{
goto leave;
}
// If deleteFile() fails.
if ((status = deleteFile(&btrieveClient)) != Btrieve::STATUS_CODE_NO_ERROR)
{
goto leave;
}
leave:
// If there wasn't a failure.
return 0;
return 1;
}