File: row.c

package info (click to toggle)
tablix2 0.3.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,816 kB
  • ctags: 2,970
  • sloc: ansic: 21,647; xml: 12,230; sh: 9,879; makefile: 762; perl: 564; yacc: 288
file content (73 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (5)
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
#include <stdio.h>
#include <stdlib.h>
#include "module.h"

#define	RESTYPE		"dummy-type"

static resourcetype *dummy;
static int width, height;

int handler(char *restriction, char *content, tupleinfo *tuple)
{
	int row;
	int result;
	int typeid;

	int *resid_list;
	int resid_num;

	int n;

	domain *dom;

	result=sscanf(content, "%d", &row);
	if(result!=1) {
		error(_("Row index must be an integer"));
		return -1;
	}

	if(row<0||row>height-1) {
		error(_("Row index must be between 0 and %d"), height-1);
		return -1;
	}

	typeid=dummy->typeid;

	resid_list=malloc(sizeof(*resid_list)*width);
	if(resid_list==NULL) {
		error(_("Can't allocate memory"));
		return -1;
	}

	for(n=0;n<width;n++) resid_list[n]=row+n*height;
	resid_num=width;

	dom=tuple->dom[typeid];

	domain_and(dom, resid_list, resid_num);

	free(resid_list);
	
	return 0;
}

int module_init(moduleoption *opt)
{
	int result;

	dummy=restype_find(RESTYPE);
	if(dummy==NULL) {
		error(_("Resource type '%s' not found"), RESTYPE);
		return -1;
	}

	result=res_get_matrix(dummy, &width, &height);
	if(result) {
		error(_("Resource type " RESTYPE " is not a matrix"));
		return -1;
	}

	if(handler_tup_new("row-" RESTYPE, handler)==NULL) return -1;

	return(0);
}