-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmidasutil.c
60 lines (51 loc) · 1.13 KB
/
midasutil.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
#include <Mrm/MrmAppl.h> /* Motif Toolkit and MRM */
#include <string.h>
#include "midasoperand.h"
/*
* General utility functions
*/
static MidasOperand Locate(needle,haystack)
char *needle;
char *haystack;
{
MidasOperand Temp;
char *p = strstr(haystack,needle);
Temp.Value.I = p ? p-haystack : strlen(haystack);
Temp.Type = MInt;
Temp.Dynamic = FALSE;
return Temp;
}
static MidasOperand Extract(start,length,string)
int start;
int length;
char *string;
{
MidasOperand Temp;
int len = strlen(string);
char *p;
if (start>=len) p = NULL;
else
{
p = string + start;
if (start+length < len) *(p+length) = '\0';
}
Temp.Value.P = XtNewString(p);
Temp.Type = MString;
Temp.Dynamic = TRUE;
return Temp;
}
static MidasOperand Length(string)
char *string;
{
MidasOperand Temp;
Temp.Value.I = strlen(string);
Temp.Type = MInt;
Temp.Dynamic = FALSE;
return Temp;
}
void MidasUtilInit()
{
MidasDeclareFunction("LENGTH(name)" ,Length);
MidasDeclareFunction("EXTRACT(Int,Int,name)",Extract);
MidasDeclareFunction("LOCATE(name,name)" ,Locate);
}