[go: up one dir, main page]

File: README

package info (click to toggle)
libhs 0.1.3
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 104 kB
  • ctags: 26
  • sloc: ansic: 336; makefile: 67; sh: 26
file content (83 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
VERSION 0.1.2

THE DESING OF THE LIBHS, THE HIGHSCORE LIBRARY
==============================================

struct hs_table
{
  int fd;
  char * progname;
  char * branch;
  int datasize;
  struct hs_item *head;
};

struct hs_item
{
  void *data;
  struct hs_item *next;
};

  the hs_item is a chained list, which stores datas in order (from the highest
  to the lowest)

READ-WRITE LOCKING WAY (for modify the highscore table)
-------------------------------------------------------

struct hs_table * hs_open(char *progname, char *branch, void **defaultdata, int datasize);
  OPENS A HIGHSCORE TABLE AND LOCK THE FILE
  progname: the name of the game
  branch: easy, medium, etc.
    the filename in /var/games/libhs will be progname.branch, so the
    branch can be "" (empty) for the default operation, in this case the
    progname. filename will be used.
  defaultdata: an array of pointers as default data if the file doesn't exist 
                closed with NULL, or a NULL if you are sure that the file is 
		exists.
		
	        WARNING! WARNING! WARNING!
		if the file doesn't exists, then the file will be created
		by the call of this function.
		
  the return points to the struct which stores the datas or NULL if error occ.
  
int hs_insert(struct hs_table *table, void *data, hs_compfn compfn);
  INSERTS AN ITEM TO THE HIGHSCORE TABLE USING THE HS_COMPFN FUNCTION
  the compfn must return -1 if the first argument is less then the second,
  0 if they are equal, and 1 if the first argument is greater then the second.
  in this way the new score will be put to the good place in the list.
  the hs_compfn type:
  typedef int hs_compfn (void *, void *);
  
  the result value is the number of the item in the queue.
  For example:
  name          point
  James		1000
  Wichert	500
  Joey		100
  
  and you run the insert function with name=Branden point=1,
  the return value will be 4, because it was given to the list as the 4. item.
  an example compfn:
  int compfn (void *a, void *b)
  {
    struct my_struct *da = (struct my_struct *) a;
    struct my_struct *db = (struct my_struct *) b;
    
    return (da->point>db->point) - (da->point<db->point);
  }

int hs_write(struct hs_table table, int n);
  WRITES BACK THE FIRST N ITEM
  n: the number of the item which you want to be stored
  returns the success of the write

void hs_free(struct hs_table *table);
  CLOSE, UNLOCK THE FILE AND FREES THE MEMORY

READ ONLY LOCKING WAY (for read the full table only)
----------------------------------------------------
struct hs_table * hs_readtable(char *progname, char *branch, int datasize);
  READ OUT THE DATAS FROM THE PROGNAME.BRANCH TABLE WITH READ-ONLY LOCKING
  
  the return is the result or NULL if error occured