Btrieve 2
Loading...
Searching...
No Matches
bfileattributes.cpp

This is an example of file attributes use written in C++.

#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[])
{
static const char *usage = "Usage: %s\n";
BtrieveClient btrieveClient;
BtrieveFile btrieveFile;
// If the incorrect number of arguments were given.
if (argc != 1)
{
printf(usage, 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;
}
The Btrieve client class.
Definition btrieveCpp.h:1388
Btrieve::StatusCode FileCreate(BtrieveFileAttributes *btrieveFileAttributes, const char *fileName, Btrieve::CreateMode createMode, Btrieve::LocationMode locationMode=Btrieve::LOCATION_MODE_NO_PREFERENCE)
Create a file.
Btrieve::StatusCode FileClose(BtrieveFile *btrieveFile)
Close a file.
Btrieve::StatusCode FileDelete(const char *fileName)
Delete a file.
Btrieve::StatusCode FileOpen(BtrieveFile *btrieveFile, const char *fileName, const char *ownerName, Btrieve::OpenMode openMode, Btrieve::LocationMode locationMode=Btrieve::LOCATION_MODE_NO_PREFERENCE)
Open a file.
The Btrieve file attributes class.
Definition btrieveCpp.h:2448
Btrieve::StatusCode SetFileVersion(Btrieve::FileVersion fileVersion)
Set the file version.
Btrieve::StatusCode SetVariableLengthRecordsMode(Btrieve::VariableLengthRecordsMode variableLengthRecordsMode)
Set the variable length records mode.
Btrieve::StatusCode SetPageSize(Btrieve::PageSize pageSize, bool enablePageCompression=false)
Set the page size.
Btrieve::StatusCode SetPreallocatedPageCount(int preallocatedPageCount)
Set the preallocated page count.
Btrieve::StatusCode SetReservedDuplicatePointerCount(int reservedDuplicatePointerCount)
Set the reserved duplicate pointer count.
Btrieve::StatusCode SetRecordCompressionMode(Btrieve::RecordCompressionMode recordCompressionMode)
Set record compression mode.
Btrieve::StatusCode SetSystemDataMode(Btrieve::SystemDataMode systemDataMode)
Set the system data mode.
Btrieve::StatusCode SetFreeSpaceThreshold(Btrieve::FreeSpaceThreshold freeSpaceThreshold)
Set the free space threshold.
Btrieve::StatusCode SetBalancedIndexes(bool enableBalancedIndexes)
Set balanced indexes.
Btrieve::StatusCode SetFixedRecordLength(int fixedRecordLength)
Set the fixed record length.
The Btrieve file information class.
Definition btrieveCpp.h:2576
int GetUnusedPageCount()
Get the unused page count.
Btrieve::RecordCompressionMode GetRecordCompressionMode()
Get the record compression mode.
int GetBalancedIndexes()
Get balanced indexes.
Btrieve::SystemDataMode GetSystemDataMode()
Get the system data mode.
Btrieve::FileVersion GetFileVersion()
Get the file version.
int GetUnusedDuplicatePointerCount()
Get the unused duplicate pointer count.
Btrieve::StatusCode GetLastStatusCode()
Get the last status code.
int GetPageCompression()
Get page compression.
int GetPagePreallocation()
Get page preallocation.
Btrieve::PageSize GetPageSize()
Get the page size.
Btrieve::VariableLengthRecordsMode GetVariableLengthRecordsMode()
Get the variable length records mode.
int GetFixedRecordLength()
Get the fixed record length.
Btrieve::FreeSpaceThreshold GetFreeSpaceThreshold()
Get the free space threshold.
The Btrieve file class.
Definition btrieveCpp.h:1729
Btrieve::StatusCode GetInformation(BtrieveFileInformation *btrieveFileInformation)
Get the file information.
VariableLengthRecordsMode
The Btrieve variable length records modes.
Definition btrieveCpp.h:1239
@ VARIABLE_LENGTH_RECORDS_MODE_UNKNOWN
Unknown.
Definition btrieveCpp.h:1247
@ VARIABLE_LENGTH_RECORDS_MODE_YES_VARIABLE_ALLOCATION_TAILS
Yes with variable allocation tails.
Definition btrieveCpp.h:1245
static const char * PageSizeToString(PageSize pageSize)
Return a page size as a string.
static const char * FreeSpaceThresholdToString(FreeSpaceThreshold freeSpaceThreshold)
Return a free space threshold as a string.
static const char * VariableLengthRecordsModeToString(VariableLengthRecordsMode variableLengthRecordsMode)
Return a variable length records mode as a string.
static const char * RecordCompressionModeToString(RecordCompressionMode recordCompressionMode)
Return an record compression mode as a string.
SystemDataMode
The Btrieve system data modes.
Definition btrieveCpp.h:1200
@ SYSTEM_DATA_MODE_NO
No.
Definition btrieveCpp.h:1204
@ SYSTEM_DATA_MODE_UNKNOWN
Unknown.
Definition btrieveCpp.h:1210
FileVersion
The Btrieve file versions.
Definition btrieveCpp.h:267
@ FILE_VERSION_9_5
File version 9.5.
Definition btrieveCpp.h:279
@ FILE_VERSION_UNKNOWN
Unknown.
Definition btrieveCpp.h:287
static const char * StatusCodeToString(StatusCode statusCode)
Return a status code as a string.
PageSize
The Btrieve page sizes.
Definition btrieveCpp.h:671
@ PAGE_SIZE_16384
Page size 16384.
Definition btrieveCpp.h:689
@ PAGE_SIZE_UNKNOWN
Unknown.
Definition btrieveCpp.h:693
@ CREATE_MODE_OVERWRITE
Overwrite.
Definition btrieveCpp.h:72
StatusCode
The Btrieve status codes.
Definition btrieveCpp.h:713
@ STATUS_CODE_UNKNOWN
-7 - Unknown.
Definition btrieveCpp.h:1194
@ STATUS_CODE_NO_ERROR
0 - No error.
Definition btrieveCpp.h:715
static const char * SystemDataModeToString(SystemDataMode systemDataMode)
Return a system data mode as a string.
FreeSpaceThreshold
The Btrieve free space thresholds.
Definition btrieveCpp.h:293
@ FREE_SPACE_THRESHOLD_UNKNOWN
Unknown.
Definition btrieveCpp.h:303
@ FREE_SPACE_THRESHOLD_10_PERCENT
Free space threshold 10%.
Definition btrieveCpp.h:295
@ OPEN_MODE_NORMAL
Normal.
Definition btrieveCpp.h:606
RecordCompressionMode
The Btrieve record compression modes.
Definition btrieveCpp.h:699
@ RECORD_COMPRESSION_MODE_RUN_LENGTH_ENCODING
Run length encoding.
Definition btrieveCpp.h:705
@ RECORD_COMPRESSION_MODE_UNKNOWN
Unknown.
Definition btrieveCpp.h:707
static const char * FileVersionToString(FileVersion fileVersion)
Return a file version as a string.