summaryrefslogtreecommitdiff
path: root/perl/junk.xs
blob: a3f023768cea7c2efe35de04c5862482a13d7ea2 (plain)
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
/*
 * This file includes misc functions that were once implemented and retired
 * later in the process
 *
 * $Id: junk.xs,v 1.2 1999/07/14 17:23:30 gafton Exp $
 */

SV *
HeaderRawItem(header, item)
  Header *	header
  int		item
  PREINIT:
	int_32 count, type;
	int rc;
	void * value;
	AV * array;
	char ** src;
  CODE:
	rc = headerGetEntry(*header, item, &type, &value, &count);
	RETVAL = &PL_sv_undef;
	if (rc != 0) {
	  switch(type) {
	    case RPM_CHAR_TYPE:
	        RETVAL = newSViv((char) (int)value);
	        break;
	    case RPM_INT8_TYPE:
	        RETVAL = newSViv((int_8) (int) value);
	        break;
	    case RPM_INT16_TYPE:
	        RETVAL = newSViv((int_16) (int) value);
	        break;
	    case RPM_INT32_TYPE:
	        RETVAL = newSViv((int_32)value);
	        break;
	    case RPM_STRING_TYPE:
	        RETVAL = newSVpv((char *)value, 0);
   	        break;
	    case RPM_BIN_TYPE:
	        /* XXX: this looks mostly unused - how do we deal with it? */
	        break;
	    case RPM_STRING_ARRAY_TYPE:
	    case RPM_I18NSTRING_TYPE:
		/* we have to build an array first */
		array = newAV();
		src = (char **) value;
		while (count--) {
		  av_push(array, newSVpv(*src++, 0));
		}
		RETVAL = newRV_inc((SV*)array);
	        free(value);
	        break;
	  }
	}
  OUTPUT:
	RETVAL