-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIFile.c
165 lines (137 loc) · 3.65 KB
/
MIFile.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/******************************************************************************\
* MIFile.c - Extended libmi support for -file-* commands.
*
* Copyright 2013-2014 Cray Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MIResult.h"
#include "MIString.h"
#include "MIList.h"
#include "MIValue.h"
#include "MIFile.h"
MISource *
MISourceNew(void)
{
MISource * source;
source = (MISource *)malloc(sizeof(MISource));
source->line = 0;
source->file = NULL;
source->fullname = NULL;
source->macro_info = 0;
return source;
}
void
MISourceFree(MISource *source)
{
if (source->file != NULL)
free(source->file);
if (source->fullname != NULL)
free(source->fullname);
free(source);
}
MISources *
MISourcesNew(void)
{
MISources * sources;
sources = (MISources *)malloc(sizeof(MISources));
sources->file = NULL;
sources->fullname = NULL;
return sources;
}
void
MISourcesFree(MISources *sources)
{
if (sources->file != NULL)
free(sources->file);
if (sources->fullname != NULL)
free(sources->fullname);
free(sources);
}
MISource *
MIGetFileListExecSourceFileInfo(MICommand *cmd)
{
MIResultRecord * rr;
MIResult * result;
MISource * source = MISourceNew();
if (!cmd->completed || cmd->output == NULL || cmd->output->rr == NULL)
return NULL;
rr = cmd->output->rr;
for (MIListSet(rr->results); (result = (MIResult *)MIListGet(rr->results)) != NULL; )
{
if (result->value == NULL || result->value->type != MIValueTypeConst)
continue;
if (strcmp(result->variable, "line") == 0)
{
source->line = (int)strtol(result->value->cstring, NULL, 10);
} else if (strcmp(result->variable, "file") == 0)
{
source->file = strdup(result->value->cstring);
} else if (strcmp(result->variable, "fullname") == 0)
{
source->fullname = strdup(result->value->cstring);
} else if (strcmp(result->variable, "macro-info") == 0)
{
source->macro_info = (int)strtol(result->value->cstring, NULL, 10);
}
}
return source;
}
static MISources *
MISourcesParse(MIValue *tuple)
{
MIList * results = tuple->results;
MIResult * result;
MISources * sources = MISourcesNew();
for (MIListSet(results); (result = (MIResult *)MIListGet(results)) != NULL; )
{
if (result->value == NULL || result->value->type != MIValueTypeConst)
continue;
if (strcmp(result->variable, "file") == 0)
{
sources->file = strdup(result->value->cstring);
} else if (strcmp(result->variable, "fullname") == 0)
{
sources->fullname = strdup(result->value->cstring);
}
}
return sources;
}
MIList *
MIGetFileListExecSourceFilesInfo(MICommand *cmd)
{
MIResultRecord * rr;
MIResult * result;
MIValue * res_val;
MIValue * val;
MIList * sources = MIListNew();
if (!cmd->completed || cmd->output == NULL || cmd->output->rr == NULL)
return NULL;
rr = cmd->output->rr;
for (MIListSet(rr->results); (result = (MIResult *)MIListGet(rr->results)) != NULL; )
{
if (strcmp(result->variable, "files") == 0)
{
val = result->value;
// only expect to have a list of tuple values here
if (val->type == MIValueTypeList)
{
for (MIListSet(val->values); (res_val = (MIValue *)MIListGet(val->values)) != NULL; )
{
MIListAdd(sources, MISourcesParse(res_val));
}
}
}
}
return sources;
}