source: git/src/readval.c

Last change on this file was 64544daf, checked in by Olly Betts <olly@…>, 2 months ago

Use "info" to limit warnings about deprecated feature

Previously this was a warning, but the newer "info" category is
more appropriate here.

  • Property mode set to 100644
File size: 19.5 KB
Line 
1/* readval.c
2 * Routines to read a prefix or number from the current input file
3 * Copyright (C) 1991-2024 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18 */
19
20#include <config.h>
21
22#include <limits.h>
23#include <stddef.h> /* for offsetof */
24
25#include "cavern.h"
26#include "commands.h" /* For match_tok(), etc */
27#include "date.h"
28#include "debug.h"
29#include "filename.h"
30#include "message.h"
31#include "readval.h"
32#include "datain.h"
33#include "netbits.h"
34#include "osalloc.h"
35#include "str.h"
36
37#ifdef HAVE_SETJMP_H
38# define LONGJMP(JB) longjmp((JB), 1)
39#else
40# define LONGJMP(JB) exit(1)
41#endif
42
43int root_depr_count = 0;
44
45static prefix *
46new_anon_station(void)
47{
48    prefix *name = osnew(prefix);
49    name->pos = NULL;
50    name->ident = NULL;
51    name->shape = 0;
52    name->stn = NULL;
53    name->up = pcs->Prefix;
54    name->down = NULL;
55    name->filename = file.filename;
56    name->line = file.line;
57    name->min_export = name->max_export = 0;
58    name->sflags = BIT(SFLAGS_ANON);
59    /* Keep linked list of anon stations for node stats. */
60    name->right = anon_list;
61    anon_list = name;
62    return name;
63}
64
65/* if prefix is omitted: if PFX_OPT set return NULL, otherwise use longjmp */
66extern prefix *
67read_prefix(unsigned pfx_flags)
68{
69   bool f_optional = !!(pfx_flags & PFX_OPT);
70   bool fSurvey = !!(pfx_flags & PFX_SURVEY);
71   bool fSuspectTypo = !!(pfx_flags & PFX_SUSPECT_TYPO);
72   prefix *back_ptr, *ptr;
73   char *name;
74   size_t name_len = 32;
75   size_t i;
76   bool fNew;
77   bool fImplicitPrefix = true;
78   int depth = -1;
79   filepos here;
80   filepos fp_firstsep;
81
82   skipblanks();
83   get_pos(&here);
84#ifndef NO_DEPRECATED
85   if (isRoot(ch)) {
86      if (!(pfx_flags & PFX_ALLOW_ROOT)) {
87         compile_diagnostic(DIAG_ERR|DIAG_COL, /*ROOT is deprecated*/25);
88         LONGJMP(file.jbSkipLine);
89      }
90      if (root_depr_count < 5) {
91         compile_diagnostic(DIAG_WARN|DIAG_COL, /*ROOT is deprecated*/25);
92         if (++root_depr_count == 5)
93            compile_diagnostic(DIAG_INFO, /*Further uses of this deprecated feature will not be reported*/95);
94      }
95      nextch();
96      ptr = root;
97      if (!isNames(ch)) {
98         if (!isSep(ch)) return ptr;
99         /* Allow optional SEPARATOR after ROOT */
100         get_pos(&fp_firstsep);
101         nextch();
102      }
103      fImplicitPrefix = false;
104#else
105   if (0) {
106#endif
107   } else {
108      if ((pfx_flags & PFX_ANON) &&
109          (isSep(ch) || (pcs->dash_for_anon_wall_station && ch == '-'))) {
110         int first_ch = ch;
111         nextch();
112         if (isBlank(ch) || isEol(ch)) {
113            if (!isSep(first_ch))
114               goto anon_wall_station;
115            /* A single separator alone ('.' by default) is an anonymous
116             * station which is on a point inside the passage and implies
117             * the leg to it is a splay.
118             */
119            if (TSTBIT(pcs->flags, FLAGS_ANON_ONE_END)) {
120               set_pos(&here);
121               compile_diagnostic(DIAG_ERR|DIAG_WORD, /*Can't have a leg between two anonymous stations*/3);
122               LONGJMP(file.jbSkipLine);
123            }
124            pcs->flags |= BIT(FLAGS_ANON_ONE_END) | BIT(FLAGS_IMPLICIT_SPLAY);
125            return new_anon_station();
126         }
127         if (isSep(first_ch) && ch == first_ch) {
128            nextch();
129            if (isBlank(ch) || isEol(ch)) {
130               /* A double separator ('..' by default) is an anonymous station
131                * which is on the wall and implies the leg to it is a splay.
132                */
133               prefix * pfx;
134anon_wall_station:
135               if (TSTBIT(pcs->flags, FLAGS_ANON_ONE_END)) {
136                  set_pos(&here);
137                  compile_diagnostic(DIAG_ERR|DIAG_WORD, /*Can't have a leg between two anonymous stations*/3);
138                  LONGJMP(file.jbSkipLine);
139               }
140               pcs->flags |= BIT(FLAGS_ANON_ONE_END) | BIT(FLAGS_IMPLICIT_SPLAY);
141               pfx = new_anon_station();
142               pfx->sflags |= BIT(SFLAGS_WALL);
143               return pfx;
144            }
145            if (ch == first_ch) {
146               nextch();
147               if (isBlank(ch) || isEol(ch)) {
148                  /* A triple separator ('...' by default) is an anonymous
149                   * station, but otherwise not handled specially (e.g. for
150                   * a single leg down an unexplored side passage to a station
151                   * which isn't refindable).
152                   */
153                  if (TSTBIT(pcs->flags, FLAGS_ANON_ONE_END)) {
154                     set_pos(&here);
155                     compile_diagnostic(DIAG_ERR|DIAG_WORD, /*Can't have a leg between two anonymous stations*/3);
156                     LONGJMP(file.jbSkipLine);
157                  }
158                  pcs->flags |= BIT(FLAGS_ANON_ONE_END);
159                  return new_anon_station();
160               }
161            }
162         }
163         set_pos(&here);
164      }
165      ptr = pcs->Prefix;
166   }
167
168   i = 0;
169   name = NULL;
170   do {
171      fNew = false;
172      if (name == NULL) {
173         /* Need a new name buffer */
174         name = osmalloc(name_len);
175      }
176      /* i==0 iff this is the first pass */
177      if (i) {
178         i = 0;
179         nextch();
180      }
181      while (isNames(ch)) {
182         if (i < pcs->Truncate) {
183            /* truncate name */
184            name[i++] = (pcs->Case == LOWER ? tolower(ch) :
185                         (pcs->Case == OFF ? ch : toupper(ch)));
186            if (i >= name_len) {
187               name_len = name_len + name_len;
188               name = osrealloc(name, name_len);
189            }
190         }
191         nextch();
192      }
193      if (isSep(ch)) {
194         fImplicitPrefix = false;
195         get_pos(&fp_firstsep);
196      }
197      if (i == 0) {
198         osfree(name);
199         if (!f_optional) {
200            if (isEol(ch)) {
201               if (fSurvey) {
202                  compile_diagnostic(DIAG_ERR|DIAG_COL, /*Expecting survey name*/89);
203               } else {
204                  compile_diagnostic(DIAG_ERR|DIAG_COL, /*Expecting station name*/28);
205               }
206            } else {
207               /* TRANSLATORS: Here "station" is a survey station, not a train station. */
208               compile_diagnostic(DIAG_ERR|DIAG_COL, /*Character “%c” not allowed in station name (use *SET NAMES to set allowed characters)*/7, ch);
209            }
210            LONGJMP(file.jbSkipLine);
211         }
212         return (prefix *)NULL;
213      }
214
215      name[i++] = '\0';
216
217      back_ptr = ptr;
218      ptr = ptr->down;
219      if (ptr == NULL) {
220         /* Special case first time around at each level */
221         name = osrealloc(name, i);
222         ptr = osnew(prefix);
223         ptr->ident = name;
224         name = NULL;
225         ptr->right = ptr->down = NULL;
226         ptr->pos = NULL;
227         ptr->shape = 0;
228         ptr->stn = NULL;
229         ptr->up = back_ptr;
230         ptr->filename = file.filename;
231         ptr->line = file.line;
232         ptr->min_export = ptr->max_export = 0;
233         ptr->sflags = BIT(SFLAGS_SURVEY);
234         if (fSuspectTypo && !fImplicitPrefix)
235            ptr->sflags |= BIT(SFLAGS_SUSPECTTYPO);
236         back_ptr->down = ptr;
237         fNew = true;
238      } else {
239         /* Use caching to speed up adding an increasing sequence to a
240          * large survey */
241         static prefix *cached_survey = NULL, *cached_station = NULL;
242         prefix *ptrPrev = NULL;
243         int cmp = 1; /* result of strcmp ( -ve for <, 0 for =, +ve for > ) */
244         if (cached_survey == back_ptr) {
245            cmp = strcmp(cached_station->ident, name);
246            if (cmp <= 0) ptr = cached_station;
247         }
248         while (ptr && (cmp = strcmp(ptr->ident, name)) < 0) {
249            ptrPrev = ptr;
250            ptr = ptr->right;
251         }
252         if (cmp) {
253            /* ie we got to one that was higher, or the end */
254            prefix *newptr;
255            name = osrealloc(name, i);
256            newptr = osnew(prefix);
257            newptr->ident = name;
258            name = NULL;
259            if (ptrPrev == NULL)
260               back_ptr->down = newptr;
261            else
262               ptrPrev->right = newptr;
263            newptr->right = ptr;
264            newptr->down = NULL;
265            newptr->pos = NULL;
266            newptr->shape = 0;
267            newptr->stn = NULL;
268            newptr->up = back_ptr;
269            newptr->filename = file.filename;
270            newptr->line = file.line;
271            newptr->min_export = newptr->max_export = 0;
272            newptr->sflags = BIT(SFLAGS_SURVEY);
273            if (fSuspectTypo && !fImplicitPrefix)
274               newptr->sflags |= BIT(SFLAGS_SUSPECTTYPO);
275            ptr = newptr;
276            fNew = true;
277         }
278         cached_survey = back_ptr;
279         cached_station = ptr;
280      }
281      depth++;
282      f_optional = false; /* disallow after first level */
283      if (isSep(ch)) {
284         get_pos(&fp_firstsep);
285         if (!TSTBIT(ptr->sflags, SFLAGS_SURVEY)) {
286            /* TRANSLATORS: Here "station" is a survey station, not a train station.
287             *
288             * Here "survey" is a "cave map" rather than list of questions - it should be
289             * translated to the terminology that cavers using the language would use.
290             */
291            compile_diagnostic(DIAG_ERR|DIAG_FROM(here), /*“%s” can’t be both a station and a survey*/27,
292                               sprint_prefix(ptr));
293         }
294      }
295   } while (isSep(ch));
296   if (name) osfree(name);
297
298   /* don't warn about a station that is referred to twice */
299   if (!fNew) ptr->sflags &= ~BIT(SFLAGS_SUSPECTTYPO);
300
301   if (fNew) {
302      /* fNew means SFLAGS_SURVEY is currently set */
303      SVX_ASSERT(TSTBIT(ptr->sflags, SFLAGS_SURVEY));
304      if (!fSurvey) {
305         ptr->sflags &= ~BIT(SFLAGS_SURVEY);
306         if (TSTBIT(pcs->infer, INFER_EXPORTS)) ptr->min_export = USHRT_MAX;
307      }
308   } else {
309      /* check that the same name isn't being used for a survey and station */
310      if (fSurvey ^ TSTBIT(ptr->sflags, SFLAGS_SURVEY)) {
311         /* TRANSLATORS: Here "station" is a survey station, not a train station.
312          *
313          * Here "survey" is a "cave map" rather than list of questions - it should be
314          * translated to the terminology that cavers using the language would use.
315          */
316         compile_diagnostic(DIAG_ERR|DIAG_FROM(here), /*“%s” can’t be both a station and a survey*/27,
317                            sprint_prefix(ptr));
318      }
319      if (!fSurvey && TSTBIT(pcs->infer, INFER_EXPORTS)) ptr->min_export = USHRT_MAX;
320   }
321
322   /* check the export level */
323#if 0
324   printf("R min %d max %d depth %d pfx %s\n",
325          ptr->min_export, ptr->max_export, depth, sprint_prefix(ptr));
326#endif
327   if (ptr->min_export == 0 || ptr->min_export == USHRT_MAX) {
328      if (depth > ptr->max_export) ptr->max_export = depth;
329   } else if (ptr->max_export < depth) {
330      prefix *survey = ptr;
331      char *s;
332      const char *p;
333      int level;
334      for (level = ptr->max_export + 1; level; level--) {
335         survey = survey->up;
336         SVX_ASSERT(survey);
337      }
338      s = osstrdup(sprint_prefix(survey));
339      p = sprint_prefix(ptr);
340      if (survey->filename) {
341         compile_diagnostic_pfx(DIAG_ERR, survey,
342                                /*Station “%s” not exported from survey “%s”*/26,
343                                p, s);
344      } else {
345         compile_diagnostic(DIAG_ERR, /*Station “%s” not exported from survey “%s”*/26, p, s);
346      }
347      osfree(s);
348#if 0
349      printf(" *** pfx %s warning not exported enough depth %d "
350             "ptr->max_export %d\n", sprint_prefix(ptr),
351             depth, ptr->max_export);
352#endif
353   }
354   if (!fImplicitPrefix && (pfx_flags & PFX_WARN_SEPARATOR)) {
355      filepos fp_tmp;
356      get_pos(&fp_tmp);
357      set_pos(&fp_firstsep);
358      compile_diagnostic(DIAG_WARN|DIAG_COL, /*Separator in survey name*/392);
359      set_pos(&fp_tmp);
360   }
361   return ptr;
362}
363
364/* if numeric expr is omitted: if f_optional return HUGE_REAL, else longjmp */
365static real
366read_number(bool f_optional, bool f_unsigned)
367{
368   bool fPositive = true, fDigits = false;
369   real n = (real)0.0;
370   filepos fp;
371   int ch_old;
372
373   get_pos(&fp);
374   ch_old = ch;
375   if (!f_unsigned) {
376      fPositive = !isMinus(ch);
377      if (isSign(ch)) nextch();
378   }
379
380   while (isdigit(ch)) {
381      n = n * (real)10.0 + (char)(ch - '0');
382      nextch();
383      fDigits = true;
384   }
385
386   if (isDecimal(ch)) {
387      real mult = (real)1.0;
388      nextch();
389      while (isdigit(ch)) {
390         mult *= (real).1;
391         n += (char)(ch - '0') * mult;
392         fDigits = true;
393         nextch();
394      }
395   }
396
397   /* !'fRead' => !fDigits so fDigits => 'fRead' */
398   if (fDigits) return (fPositive ? n : -n);
399
400   /* didn't read a valid number.  If it's optional, reset filepos & return */
401   set_pos(&fp);
402   if (f_optional) {
403      return HUGE_REAL;
404   }
405
406   if (isOmit(ch_old)) {
407      compile_diagnostic(DIAG_ERR|DIAG_COL, /*Field may not be omitted*/8);
408   } else {
409      compile_diagnostic_token_show(DIAG_ERR, /*Expecting numeric field, found “%s”*/9);
410   }
411   LONGJMP(file.jbSkipLine);
412   return 0.0; /* for brain-fried compilers */
413}
414
415static real
416read_quadrant(bool f_optional)
417{
418   enum {
419      POINT_N = 0,
420      POINT_E = 1,
421      POINT_S = 2,
422      POINT_W = 3,
423      POINT_NONE = -1
424   };
425   static const sztok pointtab[] = {
426        {"E", POINT_E },
427        {"N", POINT_N },
428        {"S", POINT_S },
429        {"W", POINT_W },
430        {NULL, POINT_NONE }
431   };
432   static const sztok pointewtab[] = {
433        {"E", POINT_E },
434        {"W", POINT_W },
435        {NULL, POINT_NONE }
436   };
437   if (f_optional && isOmit(ch)) {
438      return HUGE_REAL;
439   }
440   const int quad = 90;
441   filepos fp;
442   get_pos(&fp);
443   get_token_no_blanks();
444   int first_point = match_tok(pointtab, TABSIZE(pointtab));
445   if (first_point == POINT_NONE) {
446      set_pos(&fp);
447      if (isOmit(ch)) {
448         compile_diagnostic(DIAG_ERR|DIAG_COL, /*Field may not be omitted*/8);
449      }
450      compile_diagnostic_token_show(DIAG_ERR, /*Expecting quadrant bearing, found “%s”*/483);
451      LONGJMP(file.jbSkipLine);
452      return 0.0; /* for brain-fried compilers */
453   }
454   real r = read_number(true, true);
455   if (r == HUGE_REAL) {
456      if (isSign(ch) || isDecimal(ch)) {
457         /* Give better errors for S-0E, N+10W, N.E, etc. */
458         set_pos(&fp);
459         compile_diagnostic_token_show(DIAG_ERR, /*Expecting quadrant bearing, found “%s”*/483);
460         LONGJMP(file.jbSkipLine);
461         return 0.0; /* for brain-fried compilers */
462      }
463      /* N, S, E or W. */
464      return first_point * quad;
465   }
466   if (first_point == POINT_E || first_point == POINT_W) {
467      set_pos(&fp);
468      compile_diagnostic_token_show(DIAG_ERR, /*Expecting quadrant bearing, found “%s”*/483);
469      LONGJMP(file.jbSkipLine);
470      return 0.0; /* for brain-fried compilers */
471   }
472
473   get_token_no_blanks();
474   int second_point = match_tok(pointewtab, TABSIZE(pointewtab));
475   if (second_point == POINT_NONE) {
476      set_pos(&fp);
477      compile_diagnostic_token_show(DIAG_ERR, /*Expecting quadrant bearing, found “%s”*/483);
478      LONGJMP(file.jbSkipLine);
479      return 0.0; /* for brain-fried compilers */
480   }
481
482   if (r > quad) {
483      set_pos(&fp);
484      compile_diagnostic_token_show(DIAG_ERR|DIAG_COL, /*Suspicious compass reading*/59);
485      LONGJMP(file.jbSkipLine);
486      return 0.0; /* for brain-fried compilers */
487   }
488
489   if (first_point == POINT_N) {
490      if (second_point == POINT_W) {
491         r = quad * 4 - r;
492      }
493   } else {
494      if (second_point == POINT_W) {
495         r += quad * 2;
496      } else {
497         r = quad * 2 - r;
498      }
499   }
500   return r;
501}
502
503extern real
504read_numeric(bool f_optional)
505{
506   skipblanks();
507   return read_number(f_optional, false);
508}
509
510extern real
511read_numeric_multi(bool f_optional, bool f_quadrants, int *p_n_readings)
512{
513   size_t n_readings = 0;
514   real tot = (real)0.0;
515
516   skipblanks();
517   if (!isOpen(ch)) {
518      real r = 0;
519      if (!f_quadrants)
520          r = read_number(f_optional, false);
521      else
522          r = read_quadrant(f_optional);
523      if (p_n_readings) *p_n_readings = (r == HUGE_REAL ? 0 : 1);
524      return r;
525   }
526   nextch();
527
528   skipblanks();
529   do {
530      if (!f_quadrants)
531         tot += read_number(false, false);
532      else
533         tot += read_quadrant(false);
534      ++n_readings;
535      skipblanks();
536   } while (!isClose(ch));
537   nextch();
538
539   if (p_n_readings) *p_n_readings = n_readings;
540   /* FIXME: special averaging for bearings ... */
541   /* And for percentage gradient */
542   return tot / n_readings;
543}
544
545/* read numeric expr or omit (return HUGE_REAL); else longjmp */
546extern real
547read_bearing_multi_or_omit(bool f_quadrants, int *p_n_readings)
548{
549   real v;
550   v = read_numeric_multi(true, f_quadrants, p_n_readings);
551   if (v == HUGE_REAL) {
552      if (!isOmit(ch)) {
553         compile_diagnostic_token_show(DIAG_ERR, /*Expecting numeric field, found “%s”*/9);
554         LONGJMP(file.jbSkipLine);
555         return 0.0; /* for brain-fried compilers */
556      }
557      nextch();
558   }
559   return v;
560}
561
562/* Don't skip blanks, variable error code */
563static unsigned int
564read_uint_internal(int errmsg, const filepos *fp)
565{
566   unsigned int n = 0;
567   if (!isdigit(ch)) {
568      if (fp) set_pos(fp);
569      compile_diagnostic_token_show(DIAG_ERR, errmsg);
570      LONGJMP(file.jbSkipLine);
571   }
572   while (isdigit(ch)) {
573      n = n * 10 + (char)(ch - '0');
574      nextch();
575   }
576   return n;
577}
578
579extern unsigned int
580read_uint(void)
581{
582   skipblanks();
583   return read_uint_internal(/*Expecting numeric field, found “%s”*/9, NULL);
584}
585
586extern int
587read_int(int min_val, int max_val)
588{
589    skipblanks();
590    unsigned n = 0;
591    filepos fp;
592
593    get_pos(&fp);
594    bool negated = isMinus(ch);
595    unsigned limit;
596    if (negated) {
597        limit = (unsigned)(min_val == INT_MIN ? INT_MIN : -min_val);
598    } else {
599        limit = (unsigned)max_val;
600    }
601    if (isSign(ch)) nextch();
602
603    if (!isdigit(ch)) {
604bad_value:
605        set_pos(&fp);
606        /* TRANSLATORS: The first %d will be replaced by the (inclusive) lower
607         * bound and the second by the (inclusive) upper bound, for example:
608         * Expecting integer in range -60 to 60
609         */
610        compile_diagnostic(DIAG_ERR|DIAG_NUM, /*Expecting integer in range %d to %d*/489);
611        LONGJMP(file.jbSkipLine);
612    }
613
614    while (isdigit(ch)) {
615        unsigned old_n = n;
616        n = n * 10 + (char)(ch - '0');
617        if (n > limit || n < old_n) {
618            goto bad_value;
619        }
620        nextch();
621    }
622    if (isDecimal(ch)) goto bad_value;
623
624    if (negated) {
625        if (n > (unsigned)INT_MAX) {
626            // Avoid unportable casting.
627            return INT_MIN;
628        }
629        return -(int)n;
630    }
631    return (int)n;
632}
633
634extern void
635read_string(string *pstr)
636{
637   s_clear(pstr);
638
639   skipblanks();
640   if (ch == '\"') {
641      /* String quoted in "" */
642      nextch();
643      while (1) {
644         if (isEol(ch)) {
645            compile_diagnostic(DIAG_ERR|DIAG_COL, /*Missing \"*/69);
646            LONGJMP(file.jbSkipLine);
647         }
648
649         if (ch == '\"') break;
650
651         s_catchar(pstr, ch);
652         nextch();
653      }
654      nextch();
655   } else {
656      /* Unquoted string */
657      while (1) {
658         if (isEol(ch) || isComm(ch)) {
659            if (s_empty(pstr)) {
660               compile_diagnostic(DIAG_ERR|DIAG_COL, /*Expecting string field*/121);
661               LONGJMP(file.jbSkipLine);
662            }
663            return;
664         }
665
666         if (isBlank(ch)) break;
667
668         s_catchar(pstr, ch);
669         nextch();
670      }
671   }
672}
673
674extern void
675read_date(int *py, int *pm, int *pd)
676{
677   unsigned int y = 0, m = 0, d = 0;
678   filepos fp_date;
679
680   skipblanks();
681
682   get_pos(&fp_date);
683   y = read_uint_internal(/*Expecting date, found “%s”*/198, &fp_date);
684   /* Two digit year is 19xx. */
685   if (y < 100) {
686      filepos fp_save;
687      get_pos(&fp_save);
688      y += 1900;
689      set_pos(&fp_date);
690      /* TRANSLATORS: %d will be replaced by the assumed year, e.g. 1918 */
691      compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Assuming 2 digit year is %d*/76, y);
692      set_pos(&fp_save);
693   }
694   if (y < 1900 || y > 2078) {
695      set_pos(&fp_date);
696      compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid year (< 1900 or > 2078)*/58);
697      LONGJMP(file.jbSkipLine);
698      return; /* for brain-fried compilers */
699   }
700   if (ch == '.') {
701      filepos fp;
702      nextch();
703      get_pos(&fp);
704      m = read_uint_internal(/*Expecting date, found “%s”*/198, &fp_date);
705      if (m < 1 || m > 12) {
706         set_pos(&fp);
707         compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid month*/86);
708         LONGJMP(file.jbSkipLine);
709         return; /* for brain-fried compilers */
710      }
711      if (ch == '.') {
712         nextch();
713         get_pos(&fp);
714         d = read_uint_internal(/*Expecting date, found “%s”*/198, &fp_date);
715         if (d < 1 || d > last_day(y, m)) {
716            set_pos(&fp);
717            /* TRANSLATORS: e.g. 31st of April, or 32nd of any month */
718            compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid day of the month*/87);
719            LONGJMP(file.jbSkipLine);
720            return; /* for brain-fried compilers */
721         }
722      }
723   }
724   if (py) *py = y;
725   if (pm) *pm = m;
726   if (pd) *pd = d;
727}
Note: See TracBrowser for help on using the repository browser.