~klang/epics-base/epics-color

« back to all changes in this revision

Viewing changes to src/ioc/dbtemplate/dbLoadTemplate.y

  • Committer: Keenan Lang
  • Date: 2013-12-20 16:08:57 UTC
  • Revision ID: klang@aps.anl.gov-20131220160857-ma2jsx9ec7yx1y65
DB template loading now colorizes errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "dbAccess.h"
21
21
#include "dbLoadTemplate.h"
22
22
 
 
23
#include "epicsColor.h"
 
24
 
23
25
static int line_num;
24
26
static int yyerror(char* str);
25
27
 
140
142
        fprintf(stderr, "pattern_name: [%d] = %s\n", var_count, $1);
141
143
    #endif
142
144
        if (var_count >= dbTemplateMaxVars) {
 
145
                        TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
143
146
            fprintf(stderr,
144
147
                "More than dbTemplateMaxVars = %d macro variables used\n",
145
148
                dbTemplateMaxVars);
 
149
                        setTerminalColor(stderr, prior);
146
150
            yyerror(NULL);
147
151
        }
148
152
        else {
179
183
    }
180
184
    | WORD O_BRACE pattern_values C_BRACE
181
185
    {   /* DEPRECATED SYNTAX */
 
186
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
182
187
        fprintf(stderr,
183
188
            "dbLoadTemplate: Substitution file uses deprecated syntax.\n"
184
189
            "    the string '%s' on line %d that comes just before the\n"
185
190
            "    '{' character is extraneous and should be removed.\n",
186
191
            $1, line_num);
 
192
                setTerminalColor(stderr, prior);
187
193
    #ifdef ERROR_STUFF
188
194
        fprintf(stderr, "pattern_definition:\n");
189
195
        fprintf(stderr, "    dbLoadRecords(%s)\n", sub_collect+1);
213
219
            strcat(sub_locals, "\"");
214
220
            sub_count++;
215
221
        } else {
 
222
                        TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
216
223
            fprintf(stderr, "dbLoadTemplate: Too many values given, line %d.\n",
217
224
                line_num);
 
225
                        setTerminalColor(stderr, prior);
218
226
        }
219
227
        dbmfFree($1);
220
228
    }
230
238
            strcat(sub_locals, $1);
231
239
            sub_count++;
232
240
        } else {
 
241
                        TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
233
242
            fprintf(stderr, "dbLoadTemplate: Too many values given, line %d.\n",
234
243
                line_num);
 
244
                        setTerminalColor(stderr, prior);
235
245
        }
236
246
        dbmfFree($1);
237
247
    }
261
271
    }
262
272
    | WORD O_BRACE variable_definitions C_BRACE
263
273
    {   /* DEPRECATED SYNTAX */
 
274
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
264
275
        fprintf(stderr,
265
276
            "dbLoadTemplate: Substitution file uses deprecated syntax.\n"
266
277
            "    the string '%s' on line %d that comes just before the\n"
267
278
            "    '{' character is extraneous and should be removed.\n",
268
279
            $1, line_num);
 
280
                setTerminalColor(stderr, prior);
269
281
    #ifdef ERROR_STUFF
270
282
        fprintf(stderr, "variable_substitution:\n");
271
283
        fprintf(stderr, "    dbLoadRecords(%s)\n", sub_collect+1);
312
324
 
313
325
static int yyerror(char* str)
314
326
{
315
 
    if (str)
 
327
        TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
 
328
 
 
329
        if (str)
316
330
        fprintf(stderr, "Substitution file error: %s\n", str);
317
331
    else
318
332
        fprintf(stderr, "Substitution file error.\n");
319
333
    fprintf(stderr, "line %d: '%s'\n", line_num, yytext);
 
334
        
 
335
        setTerminalColor(stderr, prior);
320
336
    return 0;
321
337
}
322
338
 
330
346
    line_num = 1;
331
347
 
332
348
    if (!sub_file || !*sub_file) {
 
349
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
333
350
        fprintf(stderr, "must specify variable substitution file\n");
 
351
                setTerminalColor(stderr, prior);
334
352
        return -1;
335
353
    }
336
354
 
337
355
    if (dbTemplateMaxVars < 1)
338
356
    {
 
357
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
339
358
        fprintf(stderr,"Error: dbTemplateMaxVars = %d, must be +ve\n",
340
359
                dbTemplateMaxVars);
 
360
                setTerminalColor(stderr, prior);
341
361
        return -1;
342
362
    }
343
363
 
344
364
    fp = fopen(sub_file, "r");
345
365
    if (!fp) {
 
366
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
346
367
        fprintf(stderr, "dbLoadTemplate: error opening sub file %s\n", sub_file);
 
368
                setTerminalColor(stderr, prior);
347
369
        return -1;
348
370
    }
349
371
 
353
375
        free(vars);
354
376
        free(sub_collect);
355
377
        fclose(fp);
 
378
                TERMINAL_COLOR prior = setTerminalColor(stderr, getColor("EPICS_ERROR_COLOR"));
356
379
        fprintf(stderr, "dbLoadTemplate: Out of memory!\n");
 
380
                setTerminalColor(stderr, prior);
357
381
        return -1;
358
382
    }
359
383
    strcpy(sub_collect, ",");