File: ChaSen.xs

package info (click to toggle)
chasen 2.4.5-44
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,556 kB
  • sloc: sh: 10,024; ansic: 5,983; cpp: 179; makefile: 111; perl: 10
file content (121 lines) | stat: -rw-r--r-- 1,970 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright(c) 1998-2000 NOKUBI Takatsugu <knok@daionet.gr.jp>
Copyright(c) 1997 Nara Institute of Science and Technorogy.
All Rights Reserved.

$Id: ChaSen.xs,v 1.2 2008/07/22 13:00:45 masayu-a Exp $
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif

/* for old version of perl (< 5.004_04?) */
#if !defined(PL_na) && defined(na)
#define PL_na na
#endif
#if !defined(PL_sv_undef) && defined(sv_undef)
#define PL_sv_undef sv_undef
#endif

extern int Cha_optind;
int chasen_getopt_argv(char **, FILE *);

/* FILE * could be set NULL */
/* return: 0 (1: wrong option) */

int chasen_fparse(FILE *, FILE *);
int chasen_sparse(char *, FILE *);
/* return: 0 (1: end) */
char *chasen_fparse_tostr(FILE *);
char *chasen_sparse_tostr(char *);
/* return: pointer to parsed string (NULL: end) */

#define INNER_BUFSIZE   8192
#define CHA_INPUT_SIZE      8192

static unsigned char *pos;

/*PROTOTYPES: DISABLE*/

MODULE = Text::ChaSen		PACKAGE = Text::ChaSen

int
getopt_argv(sv,...)
	SV* sv

	PREINIT:
	char **cargs;
	int i;

	CODE:
	cargs = (char **) malloc(sizeof(char *) * items + 1);
	for (i = 0; i < items; i ++) {
		cargs[i] = SvPV(ST(i), PL_na);
	}
	cargs[items] = NULL;
	RETVAL = chasen_getopt_argv(cargs, NULL);
	free(cargs);

	OUTPUT:
	RETVAL

SV*
sparse_tostr(sv)
	SV* sv

	PREINIT:
	char *r, *s;

	CODE:
	s = SvPV(sv, PL_na);
	r = chasen_sparse_tostr(s);
	RETVAL = newSVpv(r, 0);

	OUTPUT:
	RETVAL

SV*
fparse_tostr(sv)
	SV* sv

	PREINIT:
	char *fname, *out;
	FILE *fp;

	CODE:
	fname = SvPV(sv, PL_na);
	fp = fopen(fname, "r");
	if (fp == NULL) {
		RETVAL = &PL_sv_undef;
	} else {
		RETVAL = newSVpv("", 0);
		while ((out = chasen_fparse_tostr(fp)) != NULL) {
			sv_catpv(RETVAL, out);
		}
		fclose(fp);
	}

	OUTPUT:
	RETVAL

SV*
sparse_tostr_long(sv)
	SV* sv

	PREINIT:
	char *r, *s;

	CODE:
	s = SvPV(sv, PL_na);
	r = chasen_sparse_tostr(s);
	RETVAL = newSVpv(r, 0);

	OUTPUT:
	RETVAL