MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / read_until

Function read_until

libsigrok4DSL/input/in_vcd.c:84–123  ·  view source on GitHub ↗

Read until specific type of character occurs in file. * Skip input if dest is NULL. * Modes: * 'W' read until whitespace * 'N' read until non-whitespace, and ungetc() the character * '$' read until $end */

Source from the content-addressed store, hash-verified

82 * '$' read until $end
83 */
84static gboolean read_until(FILE *file, GString *dest, char mode)
85{
86 char prev[4] = "";
87 long startpos = ftell(file);
88 for(;;)
89 {
90 int c = fgetc(file);
91
92 if (c == EOF)
93 {
94 if (mode == '$')
95 sr_err("Unexpected EOF, read started at %ld.", startpos);
96 return FALSE;
97 }
98
99 if (mode == 'W' && isspace(c))
100 return TRUE;
101
102 if (mode == 'N' && !isspace(c))
103 {
104 ungetc(c, file);
105 return TRUE;
106 }
107
108 if (mode == '$')
109 {
110 prev[0] = prev[1]; prev[1] = prev[2]; prev[2] = prev[3]; prev[3] = c;
111 if (prev[0] == '$' && prev[1] == 'e' && prev[2] == 'n' && prev[3] == 'd')
112 {
113 if (dest != NULL)
114 g_string_truncate(dest, dest->len - 3);
115
116 return TRUE;
117 }
118 }
119
120 if (dest != NULL)
121 g_string_append_c(dest, c);
122 }
123}
124
125/* Reads a single VCD section from input file and parses it to structure.
126 * e.g. $timescale 1ps $end => "timescale" "1ps"

Callers 2

parse_sectionFunction · 0.85
parse_contentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected