home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #3
/
amigamamagazinepolishissue1998.iso
/
bazy
/
kingfisher-distribution
/
developer
/
reorder.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-03
|
5KB
|
171 lines
/****************************************************************************
* KingFisher 2.0 Database ReOrdering Tool
* Copyright © 1994 by Udo Schuermann
* All rights reserved
* ------------------------------------------------------------------------
* Demonstration of a KingFisher 2.0 API-based interface.
* This program uses two handles to the database.
* This program is available only to registered users of KingFisher.
* DO NOT REDISTRIBUTE!
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "kf-api.h"
#define VERSION "1.3"
#ifndef __MYDATE__
#define __MYDATE__ __AMIGADATE__
#endif
char Version[] = "$VER: ReOrder "VERSION" for KingFisher "__MYDATE__;
int brk(void) {
printf("\n(CTRL-C RECEIVED)");
fflush(stdout);
ExitRequested = TRUE;
return 0;
}
void SwapBuffers( struct KFMsg *M1, struct KFMsg *M2 );
void main(int argc, char *argv[]) {
struct KFMsg *Handle1,*Handle2;
BOOL happy=TRUE,ExitRequestReported=FALSE;
onbreak(&brk);
printf("ReOrder "VERSION" for KingFisher Release 2\n"
"Copyright \© 1994 by Udo Schuermann\n"
"All rights reserved\n\n");
if( argc < 3 ) {
printf("Usage: ReOrder input output [ start [ count ] ]\n"
" input The name of a .kfdb database from which ReOrder will read\n"
" output The name of a .kfdb database to which ReOrder will append\n"
" records read from the input database.\n"
" start The record (1+) at which the transfer is to begin.\n"
" count The maximum number of records (1+) to be transferred.\n"
"\n"
"This tool allows you to easily alter the partitioning of a database\n"
"by specifying a new .kfdb file with a different partitioning. Care\n"
"should be exercised to assure that filenames in the new database do\n"
"not conflict with the old one, and that enough sections are defined\n"
"to store the output.\n"
" Data will be appended to the end of the output database, without\n"
"disturbing existing records.\n"
" ReOrder uses two logins to the KingFisher Server.\n");
return;
}
if( Handle1 = KFLogin( "ReOrder Input Client" ) ) {
if( Handle2 = KFLogin( "ReOrder Output Client" ) ) {
if( KFSelectDatabase( Handle1, argv[1] ) ) {
if( KFSelectDatabase( Handle2, argv[2] ) ) {
ULONG Counter = -1L;
ULONG FishID = 0;
BOOL ExitRequestReported = FALSE;
/* Process additional (optional) parameters */
if( argc > 2 )
if( KFSelectFish( Handle1, FishID=atol(argv[3]) ) )
printf("Beginning transfer with record %d\n",FishID);
else {
printf("Unable to select record \"%s\"\n",FishID);
happy = FALSE;
} /* if */
if( happy && (argc > 3) ) {
if( (Counter = atol(argv[4])) > 0 )
printf("Transfer will copy up to %d records\n",Counter);
else {
printf("Unable to determine how many \"%s\" records is.\n",argv[4]);
happy = FALSE;
}
}
if( happy )
printf("Now transferring records from one to the other database...");
fflush(stdout);
/* Main Loop */
while( happy && Counter ) {
if( ExitRequested )
if( !ExitRequestReported ) {
printf("\n***** RECEIVED REQUEST TO SHUT DOWN (USE ^C TO HONOR IT)\n"
"Continuing with transfer until done or canceled...");
ExitRequestReported = TRUE;
ExitRequested = FALSE; /* speed up the loop a little */
}
if( !KFGetFish( Handle1, FishID ) ) {
printf("\nUnable to load fish!\n");
happy = FALSE;
} else
if( !KFCurDisk( Handle1 ) ) {
printf("\nUnable to get fish's disk number!\n");
happy = FALSE;
} else {
/* Swapping buffers is faster than a strcpy() of buffer contents */
SwapBuffers( Handle1, Handle2 );
happy = KFAddFish( Handle2, KF_DISK(Handle1), KF_FLAGS(Handle1), KF_NIL_FISH, KF_NIL_FISH );
/* Technically, this is not required, as both buffers ought to be
* the same size and both sufficient for the operations. We'll
* just do it here for orthogonality and stylistic correctness.
*/
SwapBuffers( Handle1, Handle2 );
if( happy ) {
if( !KFNextFish( Handle1 ) ) {
if( KF_ERR(Handle1) == kfeNOMORE )
printf("\nTransfer completed!\n");
else
printf("\nUnable to advance to next fish!\n");
happy = FALSE;
} else {
Counter--;
FishID++;
}
} else {
printf("\nUnable to add fish to the database!\n");
happy = FALSE;
}
}
} /* while */
} else
printf("Unable to open the output database \"%s\"\n",argv[2]);
} else
printf("Unable to open the input database \"%s\"\n",argv[1]);
KFLogout( Handle2 );
} else
printf("Unable to obtain second (output) connection to server!\n");
KFLogout( Handle1 );
if( ExitRequested || ExitRequestReported )
printf("\nExit request has been honored!\n");
printf("Bye-bye!\n");
} else
printf("KingFisher Release 2 Server is not running or has no free connections!\n"
"Please start the server first and/or try again later!\n");
} /* main() */
void SwapBuffers( struct KFMsg *M1, struct KFMsg *M2 ) {
char *tBuffer = M1->Buffer;
ULONG tBufSize = M1->BufferSize;
M1->Buffer = M2->Buffer;
M1->BufferSize = M2->BufferSize;
M2->Buffer = tBuffer;
M2->BufferSize = tBufSize;
} /* SwapBuffers() */