annotate netinstall/hash.cc @ 2597:d6a2e12b8411

[xemacs-hg @ 2005-02-19 16:18:52 by stephent] autoconf and Xft docs <874qg8msql.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Sat, 19 Feb 2005 16:18:56 +0000
parents 3078fd1074e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
1 /*
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
2 * Copyright (c) 2000, Red Hat, Inc.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
3 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
7 * (at your option) any later version.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
8 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
9 * A copy of the GNU General Public License can be found at
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
10 * http://www.gnu.org/
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
11 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
12 * Written by DJ Delorie <dj@cygnus.com>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
13 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
14 */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
15
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
16 /* Simple hash class for install.cc */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
17
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
18 #include "win32.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
19 #include <stdlib.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
20 #include <string.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
21
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
22 #include "hash.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
23
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
24 class hash_internals {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
25 public:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
26 char **keys;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
27 int numkeys;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
28 int maxkeys;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
29 int prev_index;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
30 };
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
31
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
32 hash::hash ()
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
33 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
34 h = new hash_internals;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
35 h->numkeys = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
36 h->maxkeys = 10;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
37 h->keys = (char **) malloc (h->maxkeys * sizeof (char *));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
38 h->prev_index = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
39 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
40
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
41 hash::~hash ()
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
42 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
43 free (h->keys);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
44 free (h);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
45 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
46
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
47
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
48 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
49 hash::add (char *string)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
50 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
51 int i;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
52 for (i=0; i<h->numkeys; i++)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
53 if (strcmp (h->keys[i], string) == 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
54 return;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
55 if (h->numkeys >= h->maxkeys)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
56 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
57 h->maxkeys += 10;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
58 h->keys = (char **) realloc (h->keys, h->maxkeys * sizeof (char *));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
59 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
60
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
61 h->keys[h->numkeys] = _strdup (string);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
62 h->numkeys ++;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
63 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
64
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
65
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
66 int
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
67 hash::has (char *string)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
68 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
69 int i;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
70 for (i=0; i<h->numkeys; i++)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
71 if (strcmp (h->keys[i], string) == 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
72 return 1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
73 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
74 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
75
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
76 char *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
77 hash::enumerate (char *prev)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
78 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
79 if (prev == 0)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
80 h->prev_index = -1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
81 h->prev_index ++;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
82 if (h->prev_index >= h->numkeys)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
83 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
84 return h->keys[h->prev_index];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
85 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
86
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
87 static int CDECL
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
88 rev_len (const void *va, const void *vb)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
89 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
90 char *a = *(char **)va;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
91 char *b = *(char **)vb;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
92 return strcmp (b, a);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
93 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
94
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
95 void
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
96 hash::reverse_sort ()
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
97 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
98 qsort (h->keys, h->numkeys, sizeof (h->keys[0]), rev_len);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
99 }