next up previous
Next: References Up: An ASCII Database Previous: 10 Discussion

11 Packaging

Qddb is available as a set of utility programs and a library of routines that are useful for building other programs. This code and documentation is available by anonymous ftp from ftp.ms.uky.edu:pub/unix/qddb/. A listing for the qs program is given in Figure 8 to demonstrate how utility programs are easily built upon the library routines.




void main(argc, argv)
    int               argc;
    char              *argv[];
{
    Schema            *schema;
    char              String[BUFSIZ];
    char              Relation[BUFSIZ], *rel;
    KeyList           *list = NULL;
    size_t            Length;
    Qddb_SearchArg    search_args;

    Qddb_Init();
    rel = Qddb_FindRelation(argv[1]);
    strcpy(Relation, rel);
    schema = Qddb_InitSchema(Relation);
    while (fgets(String, sizeof(String), stdin) != NULL) {
    char        *ptr;
    KeyList        *LastList = NULL;
    ptr = String;
    while (*ptr != '\0') {
        char    *token;
        
        token = ptr;
        while (!isspace(*ptr) && *ptr != '\0')
        ptr++;
        if (*ptr != '\0') {
            *ptr++ = '\0';
            while (isspace(*ptr))
                ptr++;
        }
        search_args.Alpha = token;
        search_args.Type  = ALPHA;
        list = Qddb_Search(schema, &search_args, &Length, -1);
        if (LastList != NULL)
            list = LastList = 
                Qddb_KeyListOp(schema, list, LastList,
                      QDDB_KEYLIST_OP_INTERSECTION, 
                      QDDB_KEYLIST_FLAG_DELDUP_SAMEENTRY);
        else
            LastList = list;
    }
    if ((argc == 3 && strcmp(argv[2],"-p") == 0) || (argc == 2))
        PrintKeyList(schema, list, True);
    else if (argc == 3 && strcmp(argv[2],"-n") == 0)
        PrintKeyList(schema, list, False);
    }
    exit(0);
}

void PrintKeyList(schema, list, Print)
    Schema          *schema;
    KeyList         *list;
    Boolean         Print;
{
    char            *Buffer = Malloc(BUFSIZ), Valid;
    int             DBFile;
    unsigned        len = BUFSIZ;

    DBFile = OpenDatabase(schema->RelationName, 0);
    while (list != NULL) {
    switch(QDDB_KEYLIST_TYPE(list)) {
    case ORIGINAL:
        if (list->Length > len) {
            len = list->Length;
            free(Buffer);
            Buffer = Malloc(len);
        }
        lseek(DBFile, list->Start, 0);
        Read(DBFile, Buffer, list->Length);
        sscanf(Buffer, "%%0 %c", &Valid);
        if (Valid == 'I')
            break;
        if (Print == True)
            Write(1, Buffer, list->Length);
        break;
    case CHANGE:
        if (Print == False)
            break;
        sprintf(Buffer, "cat %s/Changes/%d", schema->RelationName, (int)list->Number);
        system(Buffer);
        break;
    case ADDITION:
        if (Print == False)
            break;
        sprintf(Buffer, "cat %s/Additions/%d", schema->RelationName, 
            (int)list->Number);
        system(Buffer);
        break;
    default:
        PANIC("BAD TYPE IN KeyList");
    }    
    if (Print == True)
        write(1, "\n", 1);
        list = list->next;
    }
    free(Buffer);
    close(DBFile);
}

  
Figure 8: C Listing forqs




Some of the programs in the suite are:

The principal library routines are:


next up previous
Next: References Up: An ASCII Database Previous: 10 Discussion

Herrin Software Development, Inc.