File: priority.c

package info (click to toggle)
cdebconf 0.227
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,552 kB
  • sloc: ansic: 16,568; sh: 549; makefile: 456; sql: 52; perl: 13
file content (40 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (9)
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
#include "common.h"
#include "priority.h"
#include <string.h>

/**
 * @brief returns an integer value suitable for comparison priorities
 * @param const char *p - priority string
 * @return int - integer value representing priority
 */
static int priority_code(const char *p)
{
	if (p == 0) return -1;
	if (strcmp(p, "low") == 0)
		return 0;
	if (strcmp(p, "medium") == 0)
		return 1;
	if (strcmp(p, "high") == 0)
		return 2;
	if (strcmp(p, "critical") == 0)
		return 3;
	return -1;
}

int priority_compare(const char *p1, const char *p2)
{
	int i1, i2;

	i1 = priority_code(p1);
	i2 = priority_code(p2);

	INFO(INFO_VERBOSE, "Comparing priorities %s (%d) with %s (%d)",
		p1, i1, p2, i2);

	if (i1 > i2)
		return 1;
	else if (i1 == i2)
		return 0;
	else
		return -1;
}