PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/other/netcdf_write_matrix/src/ncgen/ncgen.y

http://github.com/jbeezley/wrf-fire
Happy | 839 lines | 803 code | 36 blank | 0 comment | 0 complexity | 2826e51081e3812e5e46cc3af4c28515 MD5 | raw file
Possible License(s): AGPL-1.0
  1. /*********************************************************************
  2. * Copyright 1993, UCAR/Unidata
  3. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  4. * $Id: ncgen.y,v 1.25 2004/11/16 21:37:24 russ Exp $
  5. *********************************************************************/
  6. /* yacc source for "ncgen", a netCDL parser and netCDF generator */
  7. %{
  8. #ifndef lint
  9. static char SccsId[] = "$Id: ncgen.y,v 1.25 2004/11/16 21:37:24 russ Exp $";
  10. #endif
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <netcdf.h>
  14. #include "generic.h"
  15. #include "ncgen.h"
  16. #include "genlib.h" /* for grow_darray() et al */
  17. typedef struct Symbol { /* symbol table entry */
  18. char *name;
  19. struct Symbol *next;
  20. unsigned is_dim : 1; /* appears as netCDF dimension */
  21. unsigned is_var : 1; /* appears as netCDF variable */
  22. unsigned is_att : 1; /* appears as netCDF attribute */
  23. int dnum; /* handle as a dimension */
  24. int vnum; /* handle as a variable */
  25. } *YYSTYPE1;
  26. /* True if string a equals string b*/
  27. #define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
  28. #define NC_UNSPECIFIED ((nc_type)0) /* unspecified (as yet) type */
  29. #define YYSTYPE YYSTYPE1
  30. YYSTYPE symlist; /* symbol table: linked list */
  31. extern int derror_count; /* counts errors in netcdf definition */
  32. extern int lineno; /* line number for error messages */
  33. static int not_a_string; /* whether last constant read was a string */
  34. static char termstring[MAXTRST]; /* last terminal string read */
  35. static double double_val; /* last double value read */
  36. static float float_val; /* last float value read */
  37. static int int_val; /* last int value read */
  38. static short short_val; /* last short value read */
  39. static char char_val; /* last char value read */
  40. static signed char byte_val; /* last byte value read */
  41. static nc_type type_code; /* holds declared type for variables */
  42. static nc_type atype_code; /* holds derived type for attributes */
  43. static char *netcdfname; /* to construct netcdf file name */
  44. static void *att_space; /* pointer to block for attribute values */
  45. static nc_type valtype; /* type code for list of attribute values */
  46. static char *char_valp; /* pointers used to accumulate data values */
  47. static signed char *byte_valp;
  48. static short *short_valp;
  49. static int *int_valp;
  50. static float *float_valp;
  51. static double *double_valp;
  52. static void *rec_cur; /* pointer to where next data value goes */
  53. static void *rec_start; /* start of space for data */
  54. %}
  55. /* DECLARATIONS */
  56. %token
  57. NC_UNLIMITED_K /* keyword for unbounded record dimension */
  58. BYTE_K /* keyword for byte datatype */
  59. CHAR_K /* keyword for char datatype */
  60. SHORT_K /* keyword for short datatype */
  61. INT_K /* keyword for int datatype */
  62. FLOAT_K /* keyword for float datatype */
  63. DOUBLE_K /* keyword for double datatype */
  64. IDENT /* name for a dimension, variable, or attribute */
  65. TERMSTRING /* terminal string */
  66. BYTE_CONST /* byte constant */
  67. CHAR_CONST /* char constant */
  68. SHORT_CONST /* short constant */
  69. INT_CONST /* int constant */
  70. FLOAT_CONST /* float constant */
  71. DOUBLE_CONST /* double constant */
  72. DIMENSIONS /* keyword starting dimensions section, if any */
  73. VARIABLES /* keyword starting variables section, if any */
  74. NETCDF /* keyword declaring netcdf name */
  75. DATA /* keyword starting data section, if any */
  76. FILLVALUE /* fill value, from _FillValue attribute or default */
  77. %start ncdesc /* start symbol for grammar */
  78. %%
  79. /* RULES */
  80. ncdesc: NETCDF
  81. '{'
  82. { init_netcdf(); }
  83. dimsection /* dimension declarations */
  84. vasection /* variable and attribute declarations */
  85. {
  86. if (derror_count == 0)
  87. define_netcdf(netcdfname);
  88. if (derror_count > 0)
  89. exit(6);
  90. }
  91. datasection /* data, variables loaded as encountered */
  92. '}'
  93. {
  94. if (derror_count == 0)
  95. close_netcdf();
  96. }
  97. ;
  98. dimsection: /* empty */
  99. | DIMENSIONS dimdecls
  100. ;
  101. dimdecls: dimdecline ';'
  102. | dimdecls dimdecline ';'
  103. ;
  104. dimdecline: dimdecl
  105. | dimdecline ',' dimdecl
  106. ;
  107. dimdecl: dimd '=' INT_CONST
  108. { if (int_val <= 0)
  109. derror("dimension length must be positive");
  110. dims[ndims].size = int_val;
  111. ndims++;
  112. }
  113. | dimd '=' DOUBLE_CONST
  114. { /* for rare case where 2^31 < dimsize < 2^32 */
  115. if (double_val <= 0)
  116. derror("dimension length must be positive");
  117. if (double_val > 4294967295.0)
  118. derror("dimension too large");
  119. if (double_val - (size_t) double_val > 0)
  120. derror("dimension length must be an integer");
  121. dims[ndims].size = (size_t) double_val;
  122. ndims++;
  123. }
  124. | dimd '=' NC_UNLIMITED_K
  125. { if (rec_dim != -1)
  126. derror("only one NC_UNLIMITED dimension allowed");
  127. rec_dim = ndims; /* the unlimited (record) dimension */
  128. dims[ndims].size = NC_UNLIMITED;
  129. ndims++;
  130. }
  131. ;
  132. dimd: dim
  133. { if ($1->is_dim == 1) {
  134. derror( "duplicate dimension declaration for %s",
  135. $1->name);
  136. }
  137. $1->is_dim = 1;
  138. $1->dnum = ndims;
  139. /* make sure dims array will hold dimensions */
  140. grow_darray(ndims, /* must hold ndims+1 dims */
  141. &dims); /* grow as needed */
  142. dims[ndims].name = (char *) emalloc(strlen($1->name)+1);
  143. (void) strcpy(dims[ndims].name, $1->name);
  144. /* name for use in generated Fortran and C variables */
  145. dims[ndims].lname = decodify($1->name);
  146. }
  147. ;
  148. dim: IDENT
  149. ;
  150. vasection: /* empty */
  151. | VARIABLES vadecls
  152. | gattdecls
  153. ;
  154. vadecls: vadecl ';'
  155. | vadecls vadecl ';'
  156. ;
  157. vadecl: vardecl | attdecl
  158. ;
  159. gattdecls: gattdecl ';'
  160. | gattdecls gattdecl ';'
  161. ;
  162. gattdecl: attdecl /* causes a shift/reduce conflict */
  163. ;
  164. vardecl: type varlist
  165. ;
  166. type: BYTE_K { type_code = NC_BYTE; }
  167. | CHAR_K { type_code = NC_CHAR; }
  168. | SHORT_K { type_code = NC_SHORT; }
  169. | INT_K { type_code = NC_INT; }
  170. | FLOAT_K { type_code = NC_FLOAT; }
  171. | DOUBLE_K{ type_code = NC_DOUBLE; }
  172. ;
  173. varlist: varspec
  174. | varlist ',' varspec
  175. ;
  176. varspec: var
  177. {
  178. static struct vars dummyvar;
  179. dummyvar.name = "dummy";
  180. dummyvar.type = NC_DOUBLE;
  181. dummyvar.ndims = 0;
  182. dummyvar.dims = 0;
  183. dummyvar.fill_value.doublev = NC_FILL_DOUBLE;
  184. dummyvar.has_data = 0;
  185. nvdims = 0;
  186. /* make sure variable not re-declared */
  187. if ($1->is_var == 1) {
  188. derror( "duplicate variable declaration for %s",
  189. $1->name);
  190. }
  191. $1->is_var = 1;
  192. $1->vnum = nvars;
  193. /* make sure vars array will hold variables */
  194. grow_varray(nvars, /* must hold nvars+1 vars */
  195. &vars); /* grow as needed */
  196. vars[nvars] = dummyvar; /* to make Purify happy */
  197. vars[nvars].name = (char *) emalloc(strlen($1->name)+1);
  198. (void) strcpy(vars[nvars].name, $1->name);
  199. /* name for use in generated Fortran and C variables */
  200. vars[nvars].lname = decodify($1->name);
  201. vars[nvars].type = type_code;
  202. /* set default fill value. You can override this with
  203. * the variable attribute "_FillValue". */
  204. nc_getfill(type_code, &vars[nvars].fill_value);
  205. vars[nvars].has_data = 0; /* has no data (yet) */
  206. }
  207. dimspec
  208. {
  209. vars[nvars].ndims = nvdims;
  210. nvars++;
  211. }
  212. ;
  213. var: IDENT
  214. ;
  215. dimspec: /* empty */
  216. | '(' dimlist ')'
  217. ;
  218. dimlist: vdim
  219. | dimlist ',' vdim
  220. ;
  221. vdim: dim
  222. {
  223. if (nvdims >= NC_MAX_VAR_DIMS) {
  224. derror("%s has too many dimensions",vars[nvars].name);
  225. }
  226. if ($1->is_dim == 1)
  227. dimnum = $1->dnum;
  228. else {
  229. derror( "%s is not declared as a dimension",
  230. $1->name);
  231. dimnum = ndims;
  232. }
  233. if (rec_dim != -1 && dimnum == rec_dim && nvdims != 0) {
  234. derror("unlimited dimension must be first");
  235. }
  236. grow_iarray(nvdims, /* must hold nvdims+1 ints */
  237. &vars[nvars].dims); /* grow as needed */
  238. vars[nvars].dims[nvdims] = dimnum;
  239. nvdims++;
  240. }
  241. ;
  242. attdecl: att
  243. {
  244. valnum = 0;
  245. valtype = NC_UNSPECIFIED;
  246. /* get a large block for attributes, realloc later */
  247. att_space = emalloc(MAX_NC_ATTSIZE);
  248. /* make all kinds of pointers point to it */
  249. char_valp = (char *) att_space;
  250. byte_valp = (signed char *) att_space;
  251. short_valp = (short *) att_space;
  252. int_valp = (int *) att_space;
  253. float_valp = (float *) att_space;
  254. double_valp = (double *) att_space;
  255. }
  256. '=' attvallist
  257. {
  258. { /* check if duplicate attribute for this var */
  259. int i;
  260. for(i=0; i<natts; i++) { /* expensive */
  261. if(atts[i].var == varnum &&
  262. STREQ(atts[i].name,atts[natts].name)) {
  263. derror("duplicate attribute %s:%s",
  264. vars[varnum].name,atts[natts].name);
  265. }
  266. }
  267. }
  268. atts[natts].var = varnum ;
  269. atts[natts].type = valtype;
  270. atts[natts].len = valnum;
  271. /* shrink space down to what was really needed */
  272. att_space = erealloc(att_space, valnum*nctypesize(valtype));
  273. atts[natts].val = att_space;
  274. if (STREQ(atts[natts].name, _FillValue) &&
  275. atts[natts].var != NC_GLOBAL) {
  276. nc_putfill(atts[natts].type,
  277. atts[natts].val,
  278. &vars[atts[natts].var].fill_value);
  279. if(atts[natts].type != vars[atts[natts].var].type) {
  280. derror("variable %s: %s type mismatch",
  281. vars[atts[natts].var].name, _FillValue);
  282. }
  283. }
  284. natts++;
  285. }
  286. ;
  287. att: avar ':' attr
  288. | ':' attr
  289. {
  290. varnum = NC_GLOBAL; /* handle of "global" attribute */
  291. }
  292. ;
  293. avar: var
  294. { if ($1->is_var == 1)
  295. varnum = $1->vnum;
  296. else {
  297. derror("%s not declared as a variable, fatal error",
  298. $1->name);
  299. YYABORT;
  300. }
  301. }
  302. ;
  303. attr: IDENT
  304. {
  305. /* make sure atts array will hold attributes */
  306. grow_aarray(natts, /* must hold natts+1 atts */
  307. &atts); /* grow as needed */
  308. atts[natts].name = (char *) emalloc(strlen($1->name)+1);
  309. (void) strcpy(atts[natts].name,$1->name);
  310. /* name for use in generated Fortran and C variables */
  311. atts[natts].lname = decodify($1->name);
  312. }
  313. ;
  314. attvallist: aconst
  315. | attvallist ',' aconst
  316. ;
  317. aconst: attconst
  318. {
  319. if (valtype == NC_UNSPECIFIED)
  320. valtype = atype_code;
  321. if (valtype != atype_code)
  322. derror("values for attribute must be all of same type");
  323. }
  324. ;
  325. attconst: CHAR_CONST
  326. {
  327. atype_code = NC_CHAR;
  328. *char_valp++ = char_val;
  329. valnum++;
  330. }
  331. | TERMSTRING
  332. {
  333. atype_code = NC_CHAR;
  334. {
  335. /* don't null-terminate attribute strings */
  336. size_t len = strlen(termstring);
  337. if (len == 0) /* need null if that's only value */
  338. len = 1;
  339. (void)strncpy(char_valp,termstring,len);
  340. valnum += len;
  341. char_valp += len;
  342. }
  343. }
  344. | BYTE_CONST
  345. {
  346. atype_code = NC_BYTE;
  347. *byte_valp++ = byte_val;
  348. valnum++;
  349. }
  350. | SHORT_CONST
  351. {
  352. atype_code = NC_SHORT;
  353. *short_valp++ = short_val;
  354. valnum++;
  355. }
  356. | INT_CONST
  357. {
  358. atype_code = NC_INT;
  359. *int_valp++ = int_val;
  360. valnum++;
  361. }
  362. | FLOAT_CONST
  363. {
  364. atype_code = NC_FLOAT;
  365. *float_valp++ = float_val;
  366. valnum++;
  367. }
  368. | DOUBLE_CONST
  369. {
  370. atype_code = NC_DOUBLE;
  371. *double_valp++ = double_val;
  372. valnum++;
  373. }
  374. ;
  375. datasection: /* empty */
  376. | DATA datadecls
  377. | DATA
  378. ;
  379. datadecls: datadecl ';'
  380. | datadecls datadecl ';'
  381. ;
  382. datadecl: avar
  383. {
  384. valtype = vars[varnum].type; /* variable type */
  385. valnum = 0; /* values accumulated for variable */
  386. vars[varnum].has_data = 1;
  387. /* compute dimensions product */
  388. var_size = nctypesize(valtype);
  389. if (vars[varnum].ndims == 0) { /* scalar */
  390. var_len = 1;
  391. } else if (vars[varnum].dims[0] == rec_dim) {
  392. var_len = 1; /* one record for unlimited vars */
  393. } else {
  394. var_len = dims[vars[varnum].dims[0]].size;
  395. }
  396. for(dimnum = 1; dimnum < vars[varnum].ndims; dimnum++)
  397. var_len = var_len*dims[vars[varnum].dims[dimnum]].size;
  398. /* allocate memory for variable data */
  399. if (var_len*var_size != (size_t)(var_len*var_size)) {
  400. derror("variable %s too large for memory",
  401. vars[varnum].name);
  402. exit(9);
  403. }
  404. rec_len = var_len;
  405. rec_start = malloc ((size_t)(rec_len*var_size));
  406. if (rec_start == 0) {
  407. derror ("out of memory\n");
  408. exit(3);
  409. }
  410. rec_cur = rec_start;
  411. switch (valtype) {
  412. case NC_CHAR:
  413. char_valp = (char *) rec_start;
  414. break;
  415. case NC_BYTE:
  416. byte_valp = (signed char *) rec_start;
  417. break;
  418. case NC_SHORT:
  419. short_valp = (short *) rec_start;
  420. break;
  421. case NC_INT:
  422. int_valp = (int *) rec_start;
  423. break;
  424. case NC_FLOAT:
  425. float_valp = (float *) rec_start;
  426. break;
  427. case NC_DOUBLE:
  428. double_valp = (double *) rec_start;
  429. break;
  430. }
  431. }
  432. '=' constlist
  433. {
  434. if (valnum < var_len) { /* leftovers */
  435. nc_fill(valtype,
  436. var_len - valnum,
  437. rec_cur,
  438. vars[varnum].fill_value);
  439. }
  440. /* put out var_len values */
  441. /* vars[varnum].nrecs = valnum / rec_len; */
  442. vars[varnum].nrecs = var_len / rec_len;
  443. if (derror_count == 0)
  444. put_variable(rec_start);
  445. free ((char *) rec_start);
  446. }
  447. ;
  448. constlist: dconst
  449. | constlist ',' dconst
  450. ;
  451. dconst:
  452. {
  453. if(valnum >= var_len) {
  454. if (vars[varnum].dims[0] != rec_dim) { /* not recvar */
  455. derror("too many values for this variable, %d >= %d",
  456. valnum, var_len);
  457. exit (4);
  458. } else { /* a record variable, so grow data
  459. container and increment var_len by
  460. multiple of record size */
  461. ptrdiff_t rec_inc = (char *)rec_cur
  462. - (char *)rec_start;
  463. var_len = rec_len * (1 + valnum / rec_len);
  464. rec_start = erealloc(rec_start, var_len*var_size);
  465. rec_cur = (char *)rec_start + rec_inc;
  466. char_valp = (char *) rec_cur;
  467. byte_valp = (signed char *) rec_cur;
  468. short_valp = (short *) rec_cur;
  469. int_valp = (int *) rec_cur;
  470. float_valp = (float *) rec_cur;
  471. double_valp = (double *) rec_cur;
  472. }
  473. }
  474. not_a_string = 1;
  475. }
  476. const
  477. {
  478. if (not_a_string) {
  479. switch (valtype) {
  480. case NC_CHAR:
  481. rec_cur = (void *) char_valp;
  482. break;
  483. case NC_BYTE:
  484. rec_cur = (void *) byte_valp;
  485. break;
  486. case NC_SHORT:
  487. rec_cur = (void *) short_valp;
  488. break;
  489. case NC_INT:
  490. rec_cur = (void *) int_valp;
  491. break;
  492. case NC_FLOAT:
  493. rec_cur = (void *) float_valp;
  494. break;
  495. case NC_DOUBLE:
  496. rec_cur = (void *) double_valp;
  497. break;
  498. }
  499. }
  500. }
  501. ;
  502. const: CHAR_CONST
  503. {
  504. atype_code = NC_CHAR;
  505. switch (valtype) {
  506. case NC_CHAR:
  507. *char_valp++ = char_val;
  508. break;
  509. case NC_BYTE:
  510. *byte_valp++ = char_val;
  511. break;
  512. case NC_SHORT:
  513. *short_valp++ = char_val;
  514. break;
  515. case NC_INT:
  516. *int_valp++ = char_val;
  517. break;
  518. case NC_FLOAT:
  519. *float_valp++ = char_val;
  520. break;
  521. case NC_DOUBLE:
  522. *double_valp++ = char_val;
  523. break;
  524. }
  525. valnum++;
  526. }
  527. | TERMSTRING
  528. {
  529. not_a_string = 0;
  530. atype_code = NC_CHAR;
  531. {
  532. size_t len = strlen(termstring);
  533. if(valnum + len > var_len) {
  534. if (vars[varnum].dims[0] != rec_dim) {
  535. derror("too many values for this variable, %d>%d",
  536. valnum+len, var_len);
  537. exit (5);
  538. } else {/* a record variable so grow it */
  539. ptrdiff_t rec_inc = (char *)rec_cur
  540. - (char *)rec_start;
  541. var_len += rec_len * (len + valnum - var_len)/rec_len;
  542. rec_start = erealloc(rec_start, var_len*var_size);
  543. rec_cur = (char *)rec_start + rec_inc;
  544. char_valp = (char *) rec_cur;
  545. }
  546. }
  547. switch (valtype) {
  548. case NC_CHAR:
  549. {
  550. int ld;
  551. size_t i, sl;
  552. (void)strncpy(char_valp,termstring,len);
  553. ld = vars[varnum].ndims-1;
  554. if (ld > 0) {/* null-fill to size of last dim */
  555. sl = dims[vars[varnum].dims[ld]].size;
  556. for (i =len;i<sl;i++)
  557. char_valp[i] = '\0';
  558. if (sl < len)
  559. sl = len;
  560. valnum += sl;
  561. char_valp += sl;
  562. } else { /* scalar or 1D strings */
  563. valnum += len;
  564. char_valp += len;
  565. }
  566. rec_cur = (void *) char_valp;
  567. }
  568. break;
  569. case NC_BYTE:
  570. case NC_SHORT:
  571. case NC_INT:
  572. case NC_FLOAT:
  573. case NC_DOUBLE:
  574. derror("string value invalid for %s variable",
  575. nctype(valtype));
  576. break;
  577. }
  578. }
  579. }
  580. | BYTE_CONST
  581. {
  582. atype_code = NC_BYTE;
  583. switch (valtype) {
  584. case NC_CHAR:
  585. *char_valp++ = byte_val;
  586. break;
  587. case NC_BYTE:
  588. *byte_valp++ = byte_val;
  589. break;
  590. case NC_SHORT:
  591. *short_valp++ = byte_val;
  592. break;
  593. case NC_INT:
  594. *int_valp++ = byte_val;
  595. break;
  596. case NC_FLOAT:
  597. *float_valp++ = byte_val;
  598. break;
  599. case NC_DOUBLE:
  600. *double_valp++ = byte_val;
  601. break;
  602. }
  603. valnum++;
  604. }
  605. | SHORT_CONST
  606. {
  607. atype_code = NC_SHORT;
  608. switch (valtype) {
  609. case NC_CHAR:
  610. *char_valp++ = short_val;
  611. break;
  612. case NC_BYTE:
  613. *byte_valp++ = short_val;
  614. break;
  615. case NC_SHORT:
  616. *short_valp++ = short_val;
  617. break;
  618. case NC_INT:
  619. *int_valp++ = short_val;
  620. break;
  621. case NC_FLOAT:
  622. *float_valp++ = short_val;
  623. break;
  624. case NC_DOUBLE:
  625. *double_valp++ = short_val;
  626. break;
  627. }
  628. valnum++;
  629. }
  630. | INT_CONST
  631. {
  632. atype_code = NC_INT;
  633. switch (valtype) {
  634. case NC_CHAR:
  635. *char_valp++ = int_val;
  636. break;
  637. case NC_BYTE:
  638. *byte_valp++ = int_val;
  639. break;
  640. case NC_SHORT:
  641. *short_valp++ = int_val;
  642. break;
  643. case NC_INT:
  644. *int_valp++ = int_val;
  645. break;
  646. case NC_FLOAT:
  647. *float_valp++ = int_val;
  648. break;
  649. case NC_DOUBLE:
  650. *double_valp++ = int_val;
  651. break;
  652. }
  653. valnum++;
  654. }
  655. | FLOAT_CONST
  656. {
  657. atype_code = NC_FLOAT;
  658. switch (valtype) {
  659. case NC_CHAR:
  660. *char_valp++ = float_val;
  661. break;
  662. case NC_BYTE:
  663. *byte_valp++ = float_val;
  664. break;
  665. case NC_SHORT:
  666. *short_valp++ = float_val;
  667. break;
  668. case NC_INT:
  669. *int_valp++ = float_val;
  670. break;
  671. case NC_FLOAT:
  672. *float_valp++ = float_val;
  673. break;
  674. case NC_DOUBLE:
  675. *double_valp++ = float_val;
  676. break;
  677. }
  678. valnum++;
  679. }
  680. | DOUBLE_CONST
  681. {
  682. atype_code = NC_DOUBLE;
  683. switch (valtype) {
  684. case NC_CHAR:
  685. *char_valp++ = double_val;
  686. break;
  687. case NC_BYTE:
  688. *byte_valp++ = double_val;
  689. break;
  690. case NC_SHORT:
  691. *short_valp++ = double_val;
  692. break;
  693. case NC_INT:
  694. *int_valp++ = double_val;
  695. break;
  696. case NC_FLOAT:
  697. if (double_val == NC_FILL_DOUBLE)
  698. *float_valp++ = NC_FILL_FLOAT;
  699. else
  700. *float_valp++ = double_val;
  701. break;
  702. case NC_DOUBLE:
  703. *double_valp++ = double_val;
  704. break;
  705. }
  706. valnum++;
  707. }
  708. | FILLVALUE
  709. {
  710. /* store fill_value */
  711. switch (valtype) {
  712. case NC_CHAR:
  713. nc_fill(valtype, 1, (void *)char_valp++,
  714. vars[varnum].fill_value);
  715. break;
  716. case NC_BYTE:
  717. nc_fill(valtype, 1, (void *)byte_valp++,
  718. vars[varnum].fill_value);
  719. break;
  720. case NC_SHORT:
  721. nc_fill(valtype, 1, (void *)short_valp++,
  722. vars[varnum].fill_value);
  723. break;
  724. case NC_INT:
  725. nc_fill(valtype, 1, (void *)int_valp++,
  726. vars[varnum].fill_value);
  727. break;
  728. case NC_FLOAT:
  729. nc_fill(valtype, 1, (void *)float_valp++,
  730. vars[varnum].fill_value);
  731. break;
  732. case NC_DOUBLE:
  733. nc_fill(valtype, 1, (void *)double_valp++,
  734. vars[varnum].fill_value);
  735. break;
  736. }
  737. valnum++;
  738. }
  739. ;
  740. /* END OF RULES */
  741. %%
  742. /* PROGRAMS */
  743. #ifdef vms
  744. void
  745. #else
  746. int
  747. #endif
  748. yyerror( /* called for yacc syntax error */
  749. char *s)
  750. {
  751. derror(s);
  752. #ifndef vms
  753. return -1;
  754. #endif
  755. }
  756. /* undefine yywrap macro, in case we are using bison instead of yacc */
  757. #ifdef yywrap
  758. #undef yywrap
  759. #endif
  760. int
  761. yywrap(void) /* returns 1 on EOF if no more input */
  762. {
  763. return 1;
  764. }
  765. /* Symbol table operations for ncgen tool */
  766. YYSTYPE lookup( /* find sname in symbol table (linear search) */
  767. const char *sname)
  768. {
  769. YYSTYPE sp;
  770. for (sp = symlist; sp != (YYSTYPE) 0; sp = sp -> next)
  771. if (STREQ(sp -> name, sname)) {
  772. return sp;
  773. }
  774. return 0; /* 0 ==> not found */
  775. }
  776. YYSTYPE install( /* install sname in symbol table */
  777. const char *sname)
  778. {
  779. YYSTYPE sp;
  780. sp = (YYSTYPE) emalloc (sizeof (struct Symbol));
  781. sp -> name = (char *) emalloc (strlen (sname) + 1);/* +1 for '\0' */
  782. (void) strcpy (sp -> name, sname);
  783. sp -> next = symlist; /* put at front of list */
  784. sp -> is_dim = 0;
  785. sp -> is_var = 0;
  786. sp -> is_att = 0;
  787. symlist = sp;
  788. return sp;
  789. }
  790. void
  791. clearout(void) /* reset symbol table to empty */
  792. {
  793. YYSTYPE sp, tp;
  794. for (sp = symlist; sp != (YYSTYPE) 0;) {
  795. tp = sp -> next;
  796. free (sp -> name);
  797. free ((char *) sp);
  798. sp = tp;
  799. }
  800. symlist = 0;
  801. }
  802. /* get lexical input routine generated by lex */
  803. #include "ncgenyy.c"