~ubuntu-branches/debian/sid/deborphan/sid

« back to all changes in this revision

Viewing changes to src/string.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Palfrader
  • Date: 2001-10-28 01:28:24 UTC
  • Revision ID: james.westby@ubuntu.com-20011028012824-0jvhpixo5ldm3h85
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
 
 
3
#include <deborphan.h>
 
4
#include <xalloc.h>
 
5
 
 
6
/* This function compares two 'dep' structures. It returns 1 if the packages
 
7
   match, 0 if they do not.
 
8
*/
 
9
inline unsigned int
 
10
pkgcmp(const dep a, const dep b)
 
11
{
 
12
    if (a.namehash == b.namehash)
 
13
        return (strcmp(a.name, b.name) ? 0 : 1);
 
14
 
 
15
    return 0;
 
16
}
 
17
 
 
18
/* Simple function to hash a string to an unsigned int. 
 
19
*/
 
20
inline unsigned int
 
21
strhash(const char *line)
 
22
{
 
23
    unsigned int r = 0;
 
24
 
 
25
    do {
 
26
        r ^= *line;
 
27
        r <<= 1;
 
28
    }
 
29
    while (*(line++));
 
30
 
 
31
    return r;
 
32
}
 
33
 
 
34
/* This function removes all occurences of the character 'c' from the
 
35
   string 's'.
 
36
*/
 
37
inline void
 
38
strstripchr(char *s, int c)
 
39
{
 
40
    register char *t;
 
41
 
 
42
    /* No need to shift while c is not found. Thank you, Wessel. */
 
43
    for (; *s && *s != c; s++);
 
44
    t = s;
 
45
 
 
46
    do {
 
47
        if (*s != c)
 
48
            *(t++) = *s;
 
49
    }
 
50
    while (*(s++));
 
51
 
 
52
    *t = '\0';
 
53
}
 
54
 
 
55
int
 
56
string_to_priority(const char *priority)
 
57
{
 
58
    switch (upcase(*priority)) {
 
59
    case 'R':                   /*equired */
 
60
        return 1;
 
61
    case 'I':                   /*mportant */
 
62
        return 2;
 
63
    case 'S':                   /*tandard */
 
64
        return 3;
 
65
    case 'O':                   /*ptional */
 
66
        return 4;
 
67
    case 'E':                   /*xtra */
 
68
        return 5;
 
69
    default:                    /*unknown/error */
 
70
        return 0;
 
71
    }
 
72
}
 
73
 
 
74
const char *
 
75
priority_to_string(unsigned int priority)
 
76
{
 
77
    static const char *priorities[] = { "unknown", "required", "important",
 
78
        "standard", "optional", "extra"
 
79
    };
 
80
 
 
81
    return priorities[priority > 5 ? 0 : priority];
 
82
}