Newer
Older
Microsoft / pdb / PDB.C
@tundra tundra on 24 May 2012 3 KB Initial revision
/* PDB.C -      Search PBASE Using Index
                Last Modified: 07-25-90
                By T.A. Daneliuk
*/

#include    <stdio.h>
#include    <bplus.h>
#include    <io.h>
#include    <string.h>

#define     DEBUG   0                   /* 0= No Debug */

#define     DUP     1                   /* Allow Duplicate Keys */  
#define     LF      0x0a                /* LineFeed */
#define     EOR     LF                  /* End-Of-Record */

char    data_file[255] = "P:\\PDBASE";
char    idx_file[255]  = "P:\\PDBASE.IDX";
char    work[100];                      /* Working Buffers */
char    scratch[100];
long    offset;                         /* Record Position In File */

static  void     display();

ENTRY   entry;
IX_DESC node;
FILE    *fp;

/*============================================================================*/


main(argc,argv)
int     argc;
char    **argv;

{

    int     x, y, z;

    printf("PDB - Version 1.3, Copyright (c) 1988, 1990 T.A. Daneliuk - TundraWare!\n");
    printf("Released To The Public Domain - No Warranties Expressed Or Implied!\n\n");
    if (argc < 2)
        printf("Bad Command Line!, Aborting ...\n");
    else
        {
        z = 0;
        while ((z++ < argc) && (argv[z][0] == '-'))
            {
            switch (argv[z][1])
                {
                case 'i':
                    strcpy(idx_file, argv[z]+2);
                    break;
                case 'd':
                    strcpy(data_file, argv[z]+2); 
                    break;
                default:
                    printf("Invalid Command Line Switch, Ignored!\n");
                }            
            }

        fp=fopen(data_file, "rb");
        if (fp == NULL)
            {
            printf("Can't Open %s, Aborting ... \n", data_file);
            exit();
            }
        open_index(idx_file, &node, DUP);

        for (x=z; x<argc; x++)
            { 
            y=0;
            while ((scratch[y] = toupper(argv[x][y])) != '\0')
                y++;
            scratch[y] = '\0';
            strcpy(entry.key, scratch);
            locate_key(&entry, &node);
            if (strnicmp(entry.key, scratch, strlen(scratch)) == 0)
                display();
            while ((next_key(&entry, &node) == IX_OK) &&
                    (strnicmp(entry.key, scratch, strlen(scratch)) == 0))
                display();
            }
        fclose(fp);
        close_index(&node);
        }
}

/*============================================================================*/
static void display()


{
    int y,z;    

    if (!fseek(fp, entry.recptr, SEEK_SET))
        {
        y=0;
        z = fgetc(fp);
        while ((z != EOR) && (z != EOF))
            {
            work[y++] = z;
            z = fgetc(fp);
            }
        work[y++] = z;
        work[y]   = '\0';
        printf("%s", work);
        }
    else
        printf("Seek Error At %lu!\n", entry.recptr);
}

/*============================================================================*/