File: op_fnzpiece.c

package info (click to toggle)
fis-gtm 6.3-014-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 36,680 kB
  • sloc: ansic: 333,039; asm: 5,180; csh: 4,956; sh: 1,924; awk: 291; makefile: 66; sed: 13
file content (97 lines) | stat: -rwxr-xr-x 2,818 bytes parent folder | download | duplicates (2)
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
/****************************************************************
 *								*
 * Copyright (c) 2006-2020 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"
#include "op.h"
#include "matchc.h"
#include "fnpc.h"

#include "gtm_utf8.h"

/* --------------------------------------------------------------------
 * NOTE: This module is a near copy of sr_unix/op_fnpiece.c differing
 * only in that it calls "matchb" instead of "matchc" to do matching.
 * --------------------------------------------------------------------
 */

/*
 * -----------------------------------------------
 * op_fnzpiece()
 * MUMPS $ZPIece function
 *
 * Arguments:
 *	src	- Pointer to Source string mval
 *	del	- Pointer to delimiter mval
 *	first	- starting piece number
 *	last	- last piece number
 *	dst	- destination buffer to save the piece in
 *
 * Return:
 *	none
 * -----------------------------------------------
 */
void op_fnzpiece(mval *src, mval *del, int first, int last, mval *dst)
{
	int		piece_cnt, del_len, src_len;
	char		*del_str, *src_str;
	char		*match_start;
	int		match_res;
	delimfmt	unichar;

	DCL_THREADGBL_ACCESS;
	SETUP_THREADGBL_ACCESS;

	assert(!is_gtm_chset_utf8 || !TREF(compile_time) || valid_utf_string(&src->str));

	if (--first < 0)
		first = 0;
	if ((piece_cnt = last - first) < 1)
	{
		dst->str.len = 0;
		dst->mvtype = MV_STR;
		return;
	}
	MV_FORCE_STR(src);
	MV_FORCE_STR(del);
	/* See if we can take a short cut to op_fnzp1 (need to reformat delim argument) */
	if ((1 == del->str.len) && (1 == piece_cnt))
	{
		unichar.unichar_val = 0;
		unichar.unibytes_val[0] = *del->str.addr;
		op_fnzp1(src, unichar.unichar_val, last, dst);	/* Last is the one that counts as first may be too low */
		return;
	}
	src_len = src->str.len;
	src_str = src->str.addr;
	del_len = del->str.len;
	del_str = del->str.addr;
	if (first)
	{
		match_start = (char *)matchb(del_len, (uchar_ptr_t)del_str, src_len, (uchar_ptr_t)src_str, &match_res, &first);
		if (0 == match_res)
		{	/* reached end of input string */
			dst->str.len = 0;
			dst->mvtype = MV_STR;
			return;
		}
		src_len -= INTCAST(match_start - src_str);
		src_str = match_start;
	} else
		match_start = src_str;
	src_str = (char *)matchb(del_len, (uchar_ptr_t)del_str, src_len, (uchar_ptr_t)src_str, &match_res, &piece_cnt);
	if (0 != match_res)
		src_str -= del_len;
	dst->str.addr = match_start;
	dst->str.len = INTCAST(src_str - match_start);
	dst->mvtype = MV_STR;
	return;
}