-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgettok.c
133 lines (101 loc) · 2.5 KB
/
gettok.c
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
122
123
124
125
126
127
128
129
130
131
132
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2009 by Phorward Software Technologies
http://www.phorward-software.com ++ contact<at>phorward<dash>software<dot>com
File: gettok.c
Author:
Usage:
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
extern BOOLEAN REGEX_ENABLED;
extern BOOLEAN CASE_INSENSITIVITY;
/*
* Functions
*/
/*RBDOC
%%function
gettok( string, separator, count )
%%desc:en
Description of gettok
%%desc:ge
Beschreibung von gettok
%%parm:en
string
separator
count
%%parm:ge
string
separator
count
%%return:en
Return value of gettok
%%return:ge
Rückgabewert von gettok
%%notice:en
%%notice:ge
RBDOC*/
RB_FCT( gettok )
{
char* string;
char* separator;
int count;
int flags = PREGEX_COMP_NOREF
| PREGEX_COMP_NOERRORS
;
int res;
char** result;
parray* parts;
/*RBAUTOIMPORT function gettok vvv*/
PROC( "gettok" );
RB_FCT_DUMP_PARMS();
string = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 0 ) );
VARS( "string", "%s", string );
separator = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 1 ) );
VARS( "separator", "%s", separator );
count = (int)RB_PARM_VAL_GET_LONG( RB_FCT_PARM_ACCESS( 2 ) );
VARS( "count", "%d", count );
VARS( "CASE_INSENSITIVITY", "%d", CASE_INSENSITIVITY );
if( CASE_INSENSITIVITY )
flags |= PREGEX_COMP_INSENSITIVE;
VARS( "REGEX_ENABLED", "%d", REGEX_ENABLED );
if( !REGEX_ENABLED )
flags |= PREGEX_COMP_STATIC;
if( !( CASE_INSENSITIVITY && REGEX_ENABLED ) )
{
MSG( "Calling Turbo-mode string tokenizer" );
if( ( res = pstrsplit( &result, string, separator, count ) ) < 0 )
OUTOFMEM;
if( res == count )
RB_PARM_VAL_SET_STR( RB_FCT_RET, pstrdup( result[ res - 1 ] ) );
pfree( result );
}
else
{
/* TODO 06.10.2017 NOT FOR PORTING NOW!! */
/*
MSG( "Calling Power-mode regular expression string splitter" );
if( ( res = pregex_split( separator, string, flags, &parts ) ) < 0 )
OUTOFMEM;
if( res >= count )
{
if( !( string = (char*)pmalloc(
( parts[ count - 1 ].end - parts[ count - 1 ].begin + 1 )
* sizeof( char ) ) ) )
OUTOFMEM;
pstrncpy( string, parts[ count - 1 ].begin,
parts[ count - 1 ].end - parts[ count - 1 ].begin );
string[ parts[ count - 1 ].end - parts[ count - 1 ].begin ] = '\0';
VARS( "string", "%s", string );
RB_PARM_VAL_SET_STR( RB_FCT_RET, string );
}
pfree( parts );
*/
}
RETURN( 0 );
}