-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreplacevar.c
More file actions
99 lines (79 loc) · 1.9 KB
/
replacevar.c
File metadata and controls
99 lines (79 loc) · 1.9 KB
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
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2009 by Phorward Software Technologies
http://www.phorward-software.com ++ contact<at>phorward<dash>software<dot>com
File: replacevar.c
Author: Jan Max Meyer
Usage: Implements the function REPLACEVAR.
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
extern BOOLEAN REGEX_ENABLED;
extern BOOLEAN CASE_INSENSITIVITY;
/*
* Functions
*/
/*RBDOC
%%function
replacevar( string, find, replace )
%%desc:en
Description of replacevar
%%desc:ge
Beschreibung von replacevar
%%parm:en
string
find
replace
%%parm:ge
string
find
replace
%%return:en
Return value of replacevar
%%return:ge
Rückgabewert von replacevar
%%notice:en
%%notice:ge
RBDOC*/
RB_FCT( replacevar )
{
/*RBAUTOIMPORT function replacevar vvv*/
char* str;
char* find;
char* replace;
int flags = PREGEX_COMP_NOREF
| PREGEX_COMP_NOERRORS
;
PROC( "replacevar" );
RB_FCT_DUMP_PARMS();
str = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 0 ) );
find = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 1 ) );
replace = RB_PARM_VAL_GET_STR( RB_FCT_PARM_ACCESS( 2 ) );
VARS( "str", "%s", str );
VARS( "find", "%s", find );
VARS( "replace", "%s", replace );
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 replacer" );
if( !( str = pstrreplace( str, find, replace ) ) )
OUTOFMEM;
}
else
{
MSG( "Calling Power-mode regular expression string replacer" );
str = pregex_qreplace( find, str, replace, flags );
}
RB_PARM_VAL_SET_STR( RB_FCT_RET, str );
RETURN( 0 );
}