File: genpat.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (80 lines) | stat: -rw-r--r-- 2,170 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
/****************************************************************
 *								*
 *	Copyright 2001, 2010 Fidelity Information Services, Inc	*
 *								*
 *	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 "gtm_string.h"

#include "patcode.h"
#include "compiler.h"

/* This routine translates system specific wildcarded strings into MUMPS patterns,
	and generates the internal pattern matching literal string into a local buffer
	by calling the PATSTR() hook into the compiler.  The result can be passed
	directly to DO_PATTERN() to match input.

    This routine uses the UNIX pattern matching characters of * and ? for multiple
	and single character wildcarding.

*/

void genpat(mstr *input, mval *patbuf)
{
	uint4 	ecount, status;
	bool		patopen;
	char		source_buffer[MAX_SRCLINE];
	char		*top, *fpat, *pat_str;
	ptstr		pat_ptstr;
	mstr		instr;

	pat_str = source_buffer;
	fpat = input->addr;
	top = fpat + input->len;
	patopen = FALSE;
	while (fpat < top)
	{	if (*fpat == '?')
		{	for (ecount = 0; fpat < top && *fpat == '?'; ecount++)
				fpat++;
			if (patopen)
			{	*pat_str++ = '"';
				patopen = FALSE;
			}
			pat_str = (char *)i2asc((uchar_ptr_t)pat_str, ecount);
			*pat_str++ = 'E';
		}
		else if (*fpat == '*')
		{	while(fpat < top && *fpat == '*')
				fpat++;
			if (patopen)
			{	*pat_str++ = '"';
				patopen = FALSE;
			}
			*pat_str++ = '.';
			*pat_str++ = 'E';
		}
		else
		{	patopen = TRUE;
			*pat_str++ = '1';
			*pat_str++ = '"';
			while(fpat < top && *fpat != '*' && *fpat != '?')
				*pat_str++ = *fpat++;
		}
	}
	if (patopen)
		*pat_str++ = '"';
	instr.addr = source_buffer;
	instr.len = INTCAST(pat_str - source_buffer);
	if (status = patstr(&instr, &pat_ptstr, NULL))
		rts_error(VARLSTCNT(1) status);
	assert(pat_ptstr.len <= MAX_PATOBJ_LENGTH);
	patbuf->str.len = pat_ptstr.len * SIZEOF(uint4);
	memcpy(patbuf->str.addr, &pat_ptstr.buff[0], patbuf->str.len);
}