MCPcopy Create free account
hub / github.com/coreboot/coreboot / process_input_file

Function process_input_file

util/nvramtool/input_file.c:49–120  ·  view source on GitHub ↗

* process_input_file * * Read the contents of file 'f' and return a pointer to a list of pending * write operations. Perform sanity checking on all write operations and * exit with an error message if there is a problem. ****************************************************************************/

Source from the content-addressed store, hash-verified

47 * exit with an error message if there is a problem.
48 ****************************************************************************/
49cmos_write_t *process_input_file(FILE * f)
50{
51 static const int LINE_BUF_SIZE = 256;
52 static const size_t N_MATCHES = 4;
53 char line[LINE_BUF_SIZE];
54 const char *name, *value;
55 cmos_write_t *list, *item, **p;
56 regex_t blank_or_comment, assignment;
57 regmatch_t match[N_MATCHES];
58 const cmos_entry_t *e;
59
60 list = NULL;
61 p = &list;
62
63 compile_reg_expr(REG_EXTENDED | REG_NEWLINE, blank_or_comment_regex, &blank_or_comment);
64 compile_reg_expr(REG_EXTENDED | REG_NEWLINE, assignment_regex, &assignment);
65
66 /* each iteration processes one line from input file */
67 for (line_num = 1; get_input_file_line(f, line, LINE_BUF_SIZE) == OK; line_num++) { /* skip comments and blank lines */
68 if (!regexec(&blank_or_comment, line, 0, NULL, 0))
69 continue;
70
71 /* Is this a valid assignment line? If not, then it's a syntax
72 * error.
73 */
74 if (regexec(&assignment, line, N_MATCHES, match, 0)) {
75 fprintf(stderr,
76 "%s: Syntax error on line %d of input file.\n",
77 prog_name, line_num);
78 exit(1);
79 }
80
81 /* OK, we found an assignment. Break the line into substrings
82 * representing the lefthand and righthand sides of the assignment.
83 */
84 line[match[1].rm_eo] = '\0';
85 line[match[2].rm_eo] = '\0';
86 name = &line[match[1].rm_so];
87 value = &line[match[2].rm_so];
88
89 /* now look up the coreboot parameter name */
90 if (is_checksum_name(name)
91 || (e = find_cmos_entry(name)) == NULL) {
92 fprintf(stderr,
93 "%s: Error on line %d of input file: CMOS parameter "
94 "%s not found.\n", prog_name, line_num, name);
95 exit(1);
96 }
97
98 /* At this point, we figure out what numeric value needs to be written
99 * to which location. At the same time, we perform sanity checking on
100 * the write operation.
101 */
102
103 if ((item = (cmos_write_t *) malloc(sizeof(*item))) == NULL)
104 out_of_memory();
105
106 item->bit = e->bit;

Callers 1

set_paramsFunction · 0.85

Calls 11

regexecFunction · 0.85
fprintfFunction · 0.85
exitFunction · 0.85
is_checksum_nameFunction · 0.85
out_of_memoryFunction · 0.85
try_prepare_cmos_writeFunction · 0.85
regfreeFunction · 0.85
compile_reg_exprFunction · 0.70
get_input_file_lineFunction · 0.70
find_cmos_entryFunction · 0.70
mallocFunction · 0.50

Tested by

no test coverage detected