Lines Matching +full:abs +full:- +full:flat

1 /*  tables.c - tables serialization code
10 * to contract no. DE-AC03-76SF00098 between the United States
73 wr->out = out; in yytbl_writer_init()
74 wr->total_written = 0; in yytbl_writer_init()
88 th->th_magic = YYTBL_MAGIC; in yytbl_hdr_init()
89 th->th_hsize = (flex_uint32_t) (14 + strlen (version_str) + 1 + strlen (name) + 1); in yytbl_hdr_init()
90 th->th_hsize += yypad64 (th->th_hsize); in yytbl_hdr_init()
91 th->th_ssize = 0; // Not known at this point. in yytbl_hdr_init()
92 th->th_flags = 0; in yytbl_hdr_init()
93 th->th_version = xstrdup(version_str); in yytbl_hdr_init()
94 th->th_name = xstrdup(name); in yytbl_hdr_init()
107 td->td_id = id; in yytbl_data_init()
108 td->td_flags = YYTD_DATA32; in yytbl_data_init()
118 free(td->td_data); in yytbl_data_destroy()
119 td->td_data = 0; in yytbl_data_destroy()
124 /** Write enough padding to bring the file pointer to a 64-bit boundary. */
129 pad = yypad64 (wr->total_written); in yytbl_write_pad64()
130 while (pad-- > 0) in yytbl_write_pad64()
132 return -1; in yytbl_write_pad64()
141 * @return -1 on error, or bytes written on success.
148 if (yytbl_write32 (wr, th->th_magic) < 0 in yytbl_hdr_fwrite()
149 || yytbl_write32 (wr, th->th_hsize) < 0) in yytbl_hdr_fwrite()
153 if (fgetpos (wr->out, &(wr->th_ssize_pos)) != 0) in yytbl_hdr_fwrite()
156 if (yytbl_write32 (wr, th->th_ssize) < 0 in yytbl_hdr_fwrite()
157 || yytbl_write16 (wr, th->th_flags) < 0) in yytbl_hdr_fwrite()
161 sz = (int) strlen (th->th_version) + 1; in yytbl_hdr_fwrite()
162 if ((rv = yytbl_writen (wr, th->th_version, sz)) != sz) in yytbl_hdr_fwrite()
166 sz = (int) strlen (th->th_name) + 1; in yytbl_hdr_fwrite()
167 if ((rv = yytbl_writen (wr, th->th_name, sz)) != sz) in yytbl_hdr_fwrite()
177 if (bwritten != (int) th->th_hsize) in yytbl_hdr_fwrite()
187 * @return -1 on error, or bytes written on success.
196 if ((rv = yytbl_write16 (wr, td->td_id)) < 0) in yytbl_data_fwrite()
197 return -1; in yytbl_data_fwrite()
200 if ((rv = yytbl_write16 (wr, td->td_flags)) < 0) in yytbl_data_fwrite()
201 return -1; in yytbl_data_fwrite()
204 if ((rv = yytbl_write32 (wr, td->td_hilen)) < 0) in yytbl_data_fwrite()
205 return -1; in yytbl_data_fwrite()
208 if ((rv = yytbl_write32 (wr, td->td_lolen)) < 0) in yytbl_data_fwrite()
209 return -1; in yytbl_data_fwrite()
214 switch (YYTDFLAGS2BYTES (td->td_flags)) { in yytbl_data_fwrite()
229 return -1; in yytbl_data_fwrite()
235 if (bwritten != (12 + total_len * (int) YYTDFLAGS2BYTES (td->td_flags))) { in yytbl_data_fwrite()
237 return -1; in yytbl_data_fwrite()
243 return -1; in yytbl_data_fwrite()
248 if (fgetpos (wr->out, &pos) != 0 in yytbl_data_fwrite()
249 || fsetpos (wr->out, &(wr->th_ssize_pos)) != 0 in yytbl_data_fwrite()
250 || yytbl_write32 (wr, (flex_uint32_t) wr->total_written) < 0 in yytbl_data_fwrite()
251 || fsetpos (wr->out, &pos)) { in yytbl_data_fwrite()
253 return -1; in yytbl_data_fwrite()
257 wr->total_written -= (int) sizeof (flex_int32_t); in yytbl_data_fwrite()
265 * @return -1 on error. number of bytes written on success.
271 rv = (int) fwrite (v, 1, (size_t) len, wr->out); in yytbl_writen()
273 return -1; in yytbl_writen()
274 wr->total_written += len; in yytbl_writen()
281 * @return -1 on error. number of bytes written on success.
290 rv = (int) fwrite (&vnet, (size_t) bytes, 1, wr->out); in yytbl_write32()
292 return -1; in yytbl_write32()
293 wr->total_written += bytes; in yytbl_write32()
300 * @return -1 on error. number of bytes written on success.
309 rv = (int) fwrite (&vnet, (size_t) bytes, 1, wr->out); in yytbl_write16()
311 return -1; in yytbl_write16()
312 wr->total_written += bytes; in yytbl_write16()
319 * @return -1 on error. number of bytes written on success.
326 rv = (int) fwrite (&v, (size_t) bytes, 1, wr->out); in yytbl_write8()
328 return -1; in yytbl_write8()
329 wr->total_written += bytes; in yytbl_write8()
338 * @param i index into higher dimension array. i should be zero for one-dimensional arrays.
349 lo = tbl->td_lolen;
351 switch (YYTDFLAGS2BYTES (tbl->td_flags)) {
353 return ((flex_int8_t *) (tbl->td_data))[(i * lo + j) * (k + 1) +
356 return ((flex_int16_t *) (tbl->td_data))[(i * lo + j) * (k +
360 return ((flex_int32_t *) (tbl->td_data))[(i * lo + j) * (k +
372 /** Extract data element [i] from array data tables treated as a single flat array of integers.
373 * Be careful for 2-dimensional arrays or for YYTD_ID_TRANSITION, which is an array
382 switch (YYTDFLAGS2BYTES (tbl->td_flags)) { in yytbl_data_geti()
384 return ((flex_int8_t *) (tbl->td_data))[i]; in yytbl_data_geti()
386 return ((flex_int16_t *) (tbl->td_data))[i]; in yytbl_data_geti()
388 return ((flex_int32_t *) (tbl->td_data))[i]; in yytbl_data_geti()
396 /** Set data element [i] in array data tables treated as a single flat array of integers.
397 * Be careful for 2-dimensional arrays or for YYTD_ID_TRANSITION, which is an array
407 switch (YYTDFLAGS2BYTES (tbl->td_flags)) { in yytbl_data_seti()
409 ((flex_int8_t *) (tbl->td_data))[i] = (flex_int8_t) newval; in yytbl_data_seti()
412 ((flex_int16_t *) (tbl->td_data))[i] = (flex_int16_t) newval; in yytbl_data_seti()
415 ((flex_int32_t *) (tbl->td_data))[i] = (flex_int32_t) newval; in yytbl_data_seti()
438 n = abs (yytbl_data_geti (tbl, i)); in min_int_size()
467 yytbl_data_init (&newtbl, tbl->td_id); in yytbl_data_compress()
468 newtbl.td_hilen = tbl->td_hilen; in yytbl_data_compress()
469 newtbl.td_lolen = tbl->td_lolen; in yytbl_data_compress()
470 newtbl.td_flags = tbl->td_flags; in yytbl_data_compress()
475 if (newsz == YYTDFLAGS2BYTES (tbl->td_flags)) in yytbl_data_compress()
479 if (newsz > YYTDFLAGS2BYTES (tbl->td_flags)) { in yytbl_data_compress()
498 free (tbl->td_data); in yytbl_data_compress()