Category : C Source Code
Archive   : BTREE2.ZIP
Filename : EXAMPLE.C

 
Output of file : EXAMPLE.C contained in archive : BTREE2.ZIP
/* **** EXAMPLE.C ****
* This program is an example of how to use Ray Swartz's btree library.
* To use this program, a key file must be initialized first.
* This program maintains no data entries besides the keys entered
* into the key file.
*
*
*
*
* Author: Ray Swartz
* P.O. Box 2528
* Santa Cruz, Calif. 95063
* Last Modified: 4/28/85
*
* ANY USE OF THESE LIBRARY ROUTINES EITHER PERSONAL OR COMMERCIAL
* IS ALLOWED UPON THE CONDITION THAT THE USER IDENTIFY THEM
* AS BEING USED IN THE PROGRAM. IDENTIFYING INFORMATION MUST
* APPEAR IN THE PROGRAM DOCUMENTATION OR ON THE TERMINAL SCREEN.
*
* #################################
* # UNATTRIBUTED USE IS FORBIDDEN #
* #################################
*
*/



#include "stdio.h"
#include "btree.h"


main()
{
extern char instr[]; /* general input string */

struct keyinfo header; /* keyfile being used */
struct node current_node; /* stores current node's information */
char *key1; /* key to search for */
char *malloc();
int choice; /* user's menu choice */
long node_nbr; /* number of current_ node */
long pop_right_stack(), pop_left_stack();
FILE *open_keyfile();

printf("Key file to use: ");
gets(instr);
header.file = open_keyfile(instr, &header);
/* must allocate space for the key pointers */
key1 = malloc(header.keylength + 1);
current_node.key = malloc(header.keylength + 1);
cursor(1,1);
CLEAR_END_OF_PAGE
while ((choice = main_prompt("Choice: ")) != QUIT) {
if (choice == FIND) {
cursor(1,1);
CLEAR_END_OF_PAGE
get_key("Key to Find: ", key1, &header);
if(find_key(key1, &node_nbr, ¤t_node, &header)==NOT_FOUND) {
print_msg("Key not found");
show_rec(¤t_node); /* show key node "found" */
}
else if(node_nbr == END) /* no undeleted node found */
printf("node_nbr == END\n"); /* tree "empty" */
else
show_rec(¤t_node); /* exact match found */
}
else if (choice == NEXT) {
cursor(1,1);
CLEAR_END_OF_PAGE
switch (get_next(&node_nbr, ¤t_node, &header)) {
case(NO):
continue; /* no current node */
break;
case(YES):
show_rec(¤t_node); /* found one */
break;
case(AT_END):
print_msg("At end of file");
show_rec(¤t_node);
}
}
else if (choice == PREVIOUS) {
cursor(1,1);
CLEAR_END_OF_PAGE
switch (get_previous(&node_nbr, ¤t_node, &header)) {
case(NO):
continue; /* no current node */
break;
case(YES):
show_rec(¤t_node); /* found one */
break;
case(AT_END):
print_msg("At end of file");
show_rec(¤t_node);
}
}
else if (choice == INSERT) {
cursor(1,1);
CLEAR_END_OF_PAGE
enter_data(¤t_node, &header); /* get key to insert */
insert(current_node.key, header.next_avail, &header);
}
else if (choice == DELETE) {
if (yes_or_no("Delete this record? (y/n) ") == YES)
delete_key(node_nbr, ¤t_node, &header);
}
} /* QUIT chosen by user */
close_keyfile(&header);
exit(0);
}


show_rec(current_node)
struct node *current_node;
{
cursor(1,1);
CLEAR_END_OF_PAGE
print_node(current_node);
return;
}


enter_data(current_node, fileinfo)
struct keyinfo *fileinfo;
struct node *current_node;
{
extern char instr[];

printf("Enter a key: ");
gets(instr);
strncpy(current_node->key, instr, fileinfo->keylength);
current_node->key[fileinfo->keylength] = '\0';
return;
}



  3 Responses to “Category : C Source Code
Archive   : BTREE2.ZIP
Filename : EXAMPLE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/