stotest.c File Reference

Test and demo program for storage containers. More...

#include "dk.h"
#include "dkmem.h"
#include "dktypes.h"
#include "dksto.h"
#include "dkstr.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

Data Structures

struct  Person
 Description of a person. More...

Functions

static void read_file (FILE *in)
 Read input file.
unsigned long age_fct (void *p, int cr)
 Retrieve age from pointer.
int compare_fct (void *p1, void *p2, int cr)
 Compare object against other object or text.
static void print_prompt (void)
 Print a prompt.
static void print_person (Person *pers, FILE *fout)
 Print one persons record.
static void print_it (dk_storage_iterator_t *i, FILE *fout)
 Print persons record from an iterators current position until the end of the container.
void print_node (dk_storage_node_t *n, int num, FILE *f, char c)
 Print storage tree node including subtree.
void print_tree (dk_storage_t *s, FILE *f)
 Print the tree structure.
static void free_person (Person *pers)
 Free a persons record (release memory.
static void handle_cmd_1 (char *str)
 Handle command without arguments.
static void handle_cmd_2 (char *cmd, char *arg1)
 Handle command with one argument.
static void handle_cmd_3 (char *cmd, char *arg1, char *arg2)
 Handle command with 2 arguments.
static void handle_cmd_4 (char *cmd, char *arg1, char *arg2, char *arg3)
 Handle command with 3 arguments.
int main (int argc, char *argv[])
 Main program.

Variables

static dk_storage_ts1
 Storage, persons sorted by family name.
static dk_storage_ts2
 Storage, persons sorted by surname.
static dk_storage_ts3
 Storage, persons sorted by age.
static dk_storage_ts4
 Storage, persons unsorted.
static int can_continue
 Flag, input processing can be continued.
static int stdin_is_tty = 1
 Flag, stdin is connected to terminal.
static char sccs_id []
 SCCS string.
static dk_storage_iterator_ti1
 Storage iterators.
static dk_storage_iterator_ti2
static dk_storage_iterator_ti3
static dk_storage_iterator_ti4


Detailed Description

Test and demo program for storage containers.


Function Documentation

unsigned long age_fct ( void *  p,
int  cr 
)

Retrieve age from pointer.

The function retrieves an age evaluation of a pointer. The pointer target is either a struct Person or an unsigned long.

Parameters:
p Pointer to person or unsigned long.
cr Pointer object type:
  • 1: p points to a struct Person,
  • anything else: p points to an unsigned long.
Returns:
The age.
Examples:
stotest.c.

int compare_fct ( void *  p1,
void *  p2,
int  cr 
)

Compare object against other object or text.

Parameters:
p1 Left pointer (from storage).
p2 Right pointer (from dksto_it_find_like()).
cr Comparison criteria:
  • 0 indicates: p1 and p2 are pointers to struct Person, compare by family name.
  • 1 indicates: p1 is a pointer to a struct Person, p2 is a pointer to a string. Compare the family name of p1 against the string.
  • 2 indicates: p1 and p2 are pointers to struct Person, compare by surname.
  • 3 indicates: p1 is a pointer to a struct person, p2 is a pointer to a string. Compare the surname of p1 against the string.
Returns:
Comparison result:
  • Positive value, if left pointer is larger (or behind),
  • Negative value, if left pointer is smaller (or before),
  • 0 if both pointers evaluate equal.
Examples:
stotest.c.

static void free_person ( Person pers  )  [static]

Free a persons record (release memory.

)

Parameters:
pers Pointer to record to release.
Examples:
stotest.c.

static void handle_cmd_1 ( char *  str  )  [static]

Handle command without arguments.

Parameters:
str Command (first text in input line).
Examples:
stotest.c.

static void handle_cmd_2 ( char *  cmd,
char *  arg1 
) [static]

Handle command with one argument.

Parameters:
cmd Command to handle.
arg1 Command argument.
Examples:
stotest.c.

static void handle_cmd_3 ( char *  cmd,
char *  arg1,
char *  arg2 
) [static]

Handle command with 2 arguments.

Parameters:
cmd Command to handle.
arg1 Command argument 1.
arg2 Command argument 2.
Examples:
stotest.c.

static void handle_cmd_4 ( char *  cmd,
char *  arg1,
char *  arg2,
char *  arg3 
) [static]

Handle command with 3 arguments.

Parameters:
cmd Command to handle.
arg1 Command argument 1.
arg2 Command argument 2.
arg3 Command argument 3.
Examples:
stotest.c.

void print_node ( dk_storage_node_t n,
int  num,
FILE *  f,
char  c 
)

Print storage tree node including subtree.

This function is used to show the tree structure. In your applications you should not access the internal members of a dk_storage_t or dk_storage_node_t directly.

Examples:
stotest.c.

void print_tree ( dk_storage_t s,
FILE *  f 
)

Print the tree structure.

In your applications you should not access the internal members of a dk_storage_t or dk_storage_node_t directly.

Examples:
stotest.c.

void read_file ( FILE *  in  )  [static]

Read input file.

Parameters:
in File to read from.
Examples:
stotest.c.


Variable Documentation

int can_continue [static]

Flag, input processing can be continued.

Examples:
stotest.c.

Storage iterators.

Examples:
stotest.c.

dk_storage_t* s1 [static]

Storage, persons sorted by family name.

Examples:
stotest.c.

dk_storage_t* s2 [static]

Storage, persons sorted by surname.

Examples:
stotest.c.

dk_storage_t* s3 [static]

Storage, persons sorted by age.

Examples:
stotest.c.

dk_storage_t* s4 [static]

Storage, persons unsorted.

Examples:
stotest.c.

char sccs_id[] [static]

Initial value:

 {
  "@(#)stotest.ctr 1.19 02/03/09\t(krause) - dksto demo program"
}
SCCS string.

Examples:
stotest.c.

int stdin_is_tty = 1 [static]

Flag, stdin is connected to terminal.

Examples:
stotest.c.


Generated on Mon Feb 16 17:12:05 2009 for dklibs by  doxygen 1.5.6