]> cygwin.com Git - cygwin-apps/setup.git/blob - category_list.cc
2001-11-29 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / category_list.cc
1 /*
2 * Copyright (c) 2001, Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16 /* categories for packages */
17
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include "category_list.h"
22 #include "category.h"
23
24 CategoryList::CategoryList ():_categories (0), ncategories (0),
25 categoriesspace (0)
26 {
27 }
28
29 Category & CategoryList::register_category (const char *catname)
30 {
31 Category *
32 tempcat =
33 getcategorybyname (catname);
34 if (!tempcat)
35 {
36 if (ncategories == categoriesspace)
37 {
38 Category **
39 newcategories = (Category **)
40 realloc (_categories,
41 sizeof (Category *) * (categoriesspace + 20));
42 if (!newcategories)
43 {
44 //die
45 exit (100);
46 }
47 _categories = newcategories;
48 if (categoriesspace == 0)
49 _categories[0] = 0;
50 categoriesspace += 20;
51 }
52 tempcat = new Category (catname);
53 size_t n;
54 for (n = 0;
55 n < ncategories
56 && strcasecmp (_categories[n]->name, tempcat->name) < 0; n++);
57 /* insert at n */
58 if (n)
59 _categories[n - 1]->next = tempcat;
60 if (n < ncategories)
61 tempcat->next = _categories[n];
62 memmove (&_categories[n + 1], &_categories[n],
63 (ncategories - n) * sizeof (Category *));
64 _categories[n] = tempcat;
65 ncategories++;
66 }
67 return *tempcat;
68 }
69
70 Category *
71 CategoryList::getcategorybyname (const char *name)
72 {
73 for (size_t n = 0; n < ncategories; n++)
74 if (strcasecmp (_categories[n]->name, name) == 0)
75 return _categories[n];
76 return 0;
77 }
This page took 0.037571 seconds and 5 git commands to generate.