smbd: Fix a typo in a few places
[samba.git] / source3 / modules / getdate.y
index aab37f4d23554163fcab0c5de345af340d58c9ee..8e349bafdd35a91e70098b2fc59890a3ac7590d5 100644 (file)
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
    at the University of North Carolina at Chapel Hill.  Later tweaked by
@@ -43,8 +42,9 @@
 #endif
 
 #include <ctype.h>
+#include <string.h>
 
-#if HAVE_STDLIB_H
+#ifdef HAVE_STDLIB_H
 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
 #endif
 
@@ -72,7 +72,7 @@
 # include <string.h>
 #endif
 
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+#ifndef HAVE___ATTRIBUTE__
 # define __attribute__(x)
 #endif
 
@@ -105,7 +105,7 @@ typedef struct
 enum { MERam, MERpm, MER24 };
 
 /* Information passed to and from the parser.  */
-typedef struct
+struct parser_control
 {
   /* The input string remaining to be parsed. */
   const char *input;
@@ -149,21 +149,17 @@ typedef struct
   int times_seen;
   int zones_seen;
 
-  /* Table of local time zone abbrevations, terminated by a null entry.  */
+  /* Table of local time zone abbreviations, terminated by a null entry.  */
   table local_time_zone_table[3];
-} parser_control;
-
-#define PC (* (parser_control *) parm)
-#define YYLEX_PARAM parm
-#define YYPARSE_PARAM parm
-
-static int yyerror ();
-static int yylex ();
+};
 
 %}
 
+%lex-param     {struct parser_control *pc}
+%parse-param   {struct parser_control *pc}
+
 /* We want a reentrant parser.  */
-%pure_parser
+%pure-parser
 
 /* This grammar has 13 shift/reduce conflicts. */
 %expect 13
@@ -174,6 +170,13 @@ static int yylex ();
   textint textintval;
 }
 
+%{
+
+static int yyerror(struct parser_control *, const char *);
+static int yylex(YYSTYPE *, struct parser_control *);
+
+%}
+
 %token tAGO tDST
 
 %token <intval> tDAY tDAY_UNIT tDAYZONE tHOUR_UNIT tLOCAL_ZONE tMERIDIAN
@@ -192,100 +195,100 @@ spec:
 
 item:
     time
-      { PC.times_seen++; }
+      { pc->times_seen++; }
   | local_zone
-      { PC.local_zones_seen++; }
+      { pc->local_zones_seen++; }
   | zone
-      { PC.zones_seen++; }
+      { pc->zones_seen++; }
   | date
-      { PC.dates_seen++; }
+      { pc->dates_seen++; }
   | day
-      { PC.days_seen++; }
+      { pc->days_seen++; }
   | rel
-      { PC.rels_seen++; }
+      { pc->rels_seen++; }
   | number
   ;
 
 time:
     tUNUMBER tMERIDIAN
       {
-       PC.hour = $1.value;
-       PC.minutes = 0;
-       PC.seconds = 0;
-       PC.meridian = $2;
+       pc->hour = $1.value;
+       pc->minutes = 0;
+       pc->seconds = 0;
+       pc->meridian = $2;
       }
   | tUNUMBER ':' tUNUMBER o_merid
       {
-       PC.hour = $1.value;
-       PC.minutes = $3.value;
-       PC.seconds = 0;
-       PC.meridian = $4;
+       pc->hour = $1.value;
+       pc->minutes = $3.value;
+       pc->seconds = 0;
+       pc->meridian = $4;
       }
   | tUNUMBER ':' tUNUMBER tSNUMBER
       {
-       PC.hour = $1.value;
-       PC.minutes = $3.value;
-       PC.meridian = MER24;
-       PC.zones_seen++;
-       PC.time_zone = $4.value % 100 + ($4.value / 100) * 60;
+       pc->hour = $1.value;
+       pc->minutes = $3.value;
+       pc->meridian = MER24;
+       pc->zones_seen++;
+       pc->time_zone = $4.value % 100 + ($4.value / 100) * 60;
       }
   | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid
       {
-       PC.hour = $1.value;
-       PC.minutes = $3.value;
-       PC.seconds = $5.value;
-       PC.meridian = $6;
+       pc->hour = $1.value;
+       pc->minutes = $3.value;
+       pc->seconds = $5.value;
+       pc->meridian = $6;
       }
   | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER
       {
-       PC.hour = $1.value;
-       PC.minutes = $3.value;
-       PC.seconds = $5.value;
-       PC.meridian = MER24;
-       PC.zones_seen++;
-       PC.time_zone = $6.value % 100 + ($6.value / 100) * 60;
+       pc->hour = $1.value;
+       pc->minutes = $3.value;
+       pc->seconds = $5.value;
+       pc->meridian = MER24;
+       pc->zones_seen++;
+       pc->time_zone = $6.value % 100 + ($6.value / 100) * 60;
       }
   ;
 
 local_zone:
     tLOCAL_ZONE
-      { PC.local_isdst = $1; }
+      { pc->local_isdst = $1; }
   | tLOCAL_ZONE tDST
-      { PC.local_isdst = $1 < 0 ? 1 : $1 + 1; }
+      { pc->local_isdst = $1 < 0 ? 1 : $1 + 1; }
   ;
 
 zone:
     tZONE
-      { PC.time_zone = $1; }
+      { pc->time_zone = $1; }
   | tDAYZONE
-      { PC.time_zone = $1 + 60; }
+      { pc->time_zone = $1 + 60; }
   | tZONE tDST
-      { PC.time_zone = $1 + 60; }
+      { pc->time_zone = $1 + 60; }
   ;
 
 day:
     tDAY
       {
-       PC.day_ordinal = 1;
-       PC.day_number = $1;
+       pc->day_ordinal = 1;
+       pc->day_number = $1;
       }
   | tDAY ','
       {
-       PC.day_ordinal = 1;
-       PC.day_number = $1;
+       pc->day_ordinal = 1;
+       pc->day_number = $1;
       }
   | tUNUMBER tDAY
       {
-       PC.day_ordinal = $1.value;
-       PC.day_number = $2;
+       pc->day_ordinal = $1.value;
+       pc->day_number = $2;
       }
   ;
 
 date:
     tUNUMBER '/' tUNUMBER
       {
-       PC.month = $1.value;
-       PC.day = $3.value;
+       pc->month = $1.value;
+       pc->day = $3.value;
       }
   | tUNUMBER '/' tUNUMBER '/' tUNUMBER
       {
@@ -296,139 +299,139 @@ date:
           you want portability, use the ISO 8601 format.  */
        if (4 <= $1.digits)
          {
-           PC.year = $1;
-           PC.month = $3.value;
-           PC.day = $5.value;
+           pc->year = $1;
+           pc->month = $3.value;
+           pc->day = $5.value;
          }
        else
          {
-           PC.month = $1.value;
-           PC.day = $3.value;
-           PC.year = $5;
+           pc->month = $1.value;
+           pc->day = $3.value;
+           pc->year = $5;
          }
       }
   | tUNUMBER tSNUMBER tSNUMBER
       {
        /* ISO 8601 format.  YYYY-MM-DD.  */
-       PC.year = $1;
-       PC.month = -$2.value;
-       PC.day = -$3.value;
+       pc->year = $1;
+       pc->month = -$2.value;
+       pc->day = -$3.value;
       }
   | tUNUMBER tMONTH tSNUMBER
       {
        /* e.g. 17-JUN-1992.  */
-       PC.day = $1.value;
-       PC.month = $2;
-       PC.year.value = -$3.value;
-       PC.year.digits = $3.digits;
+       pc->day = $1.value;
+       pc->month = $2;
+       pc->year.value = -$3.value;
+       pc->year.digits = $3.digits;
       }
   | tMONTH tUNUMBER
       {
-       PC.month = $1;
-       PC.day = $2.value;
+       pc->month = $1;
+       pc->day = $2.value;
       }
   | tMONTH tUNUMBER ',' tUNUMBER
       {
-       PC.month = $1;
-       PC.day = $2.value;
-       PC.year = $4;
+       pc->month = $1;
+       pc->day = $2.value;
+       pc->year = $4;
       }
   | tUNUMBER tMONTH
       {
-       PC.day = $1.value;
-       PC.month = $2;
+       pc->day = $1.value;
+       pc->month = $2;
       }
   | tUNUMBER tMONTH tUNUMBER
       {
-       PC.day = $1.value;
-       PC.month = $2;
-       PC.year = $3;
+       pc->day = $1.value;
+       pc->month = $2;
+       pc->year = $3;
       }
   ;
 
 rel:
     relunit tAGO
       {
-       PC.rel_seconds = -PC.rel_seconds;
-       PC.rel_minutes = -PC.rel_minutes;
-       PC.rel_hour = -PC.rel_hour;
-       PC.rel_day = -PC.rel_day;
-       PC.rel_month = -PC.rel_month;
-       PC.rel_year = -PC.rel_year;
+       pc->rel_seconds = -pc->rel_seconds;
+       pc->rel_minutes = -pc->rel_minutes;
+       pc->rel_hour = -pc->rel_hour;
+       pc->rel_day = -pc->rel_day;
+       pc->rel_month = -pc->rel_month;
+       pc->rel_year = -pc->rel_year;
       }
   | relunit
   ;
 
 relunit:
     tUNUMBER tYEAR_UNIT
-      { PC.rel_year += $1.value * $2; }
+      { pc->rel_year += $1.value * $2; }
   | tSNUMBER tYEAR_UNIT
-      { PC.rel_year += $1.value * $2; }
+      { pc->rel_year += $1.value * $2; }
   | tYEAR_UNIT
-      { PC.rel_year += $1; }
+      { pc->rel_year += $1; }
   | tUNUMBER tMONTH_UNIT
-      { PC.rel_month += $1.value * $2; }
+      { pc->rel_month += $1.value * $2; }
   | tSNUMBER tMONTH_UNIT
-      { PC.rel_month += $1.value * $2; }
+      { pc->rel_month += $1.value * $2; }
   | tMONTH_UNIT
-      { PC.rel_month += $1; }
+      { pc->rel_month += $1; }
   | tUNUMBER tDAY_UNIT
-      { PC.rel_day += $1.value * $2; }
+      { pc->rel_day += $1.value * $2; }
   | tSNUMBER tDAY_UNIT
-      { PC.rel_day += $1.value * $2; }
+      { pc->rel_day += $1.value * $2; }
   | tDAY_UNIT
-      { PC.rel_day += $1; }
+      { pc->rel_day += $1; }
   | tUNUMBER tHOUR_UNIT
-      { PC.rel_hour += $1.value * $2; }
+      { pc->rel_hour += $1.value * $2; }
   | tSNUMBER tHOUR_UNIT
-      { PC.rel_hour += $1.value * $2; }
+      { pc->rel_hour += $1.value * $2; }
   | tHOUR_UNIT
-      { PC.rel_hour += $1; }
+      { pc->rel_hour += $1; }
   | tUNUMBER tMINUTE_UNIT
-      { PC.rel_minutes += $1.value * $2; }
+      { pc->rel_minutes += $1.value * $2; }
   | tSNUMBER tMINUTE_UNIT
-      { PC.rel_minutes += $1.value * $2; }
+      { pc->rel_minutes += $1.value * $2; }
   | tMINUTE_UNIT
-      { PC.rel_minutes += $1; }
+      { pc->rel_minutes += $1; }
   | tUNUMBER tSEC_UNIT
-      { PC.rel_seconds += $1.value * $2; }
+      { pc->rel_seconds += $1.value * $2; }
   | tSNUMBER tSEC_UNIT
-      { PC.rel_seconds += $1.value * $2; }
+      { pc->rel_seconds += $1.value * $2; }
   | tSEC_UNIT
-      { PC.rel_seconds += $1; }
+      { pc->rel_seconds += $1; }
   ;
 
 number:
     tUNUMBER
       {
-       if (PC.dates_seen
-           && ! PC.rels_seen && (PC.times_seen || 2 < $1.digits))
-         PC.year = $1;
+       if (pc->dates_seen
+           && ! pc->rels_seen && (pc->times_seen || 2 < $1.digits))
+         pc->year = $1;
        else
          {
            if (4 < $1.digits)
              {
-               PC.dates_seen++;
-               PC.day = $1.value % 100;
-               PC.month = ($1.value / 100) % 100;
-               PC.year.value = $1.value / 10000;
-               PC.year.digits = $1.digits - 4;
+               pc->dates_seen++;
+               pc->day = $1.value % 100;
+               pc->month = ($1.value / 100) % 100;
+               pc->year.value = $1.value / 10000;
+               pc->year.digits = $1.digits - 4;
              }
            else
              {
-               PC.times_seen++;
+               pc->times_seen++;
                if ($1.digits <= 2)
                  {
-                   PC.hour = $1.value;
-                   PC.minutes = 0;
+                   pc->hour = $1.value;
+                   pc->minutes = 0;
                  }
                else
                  {
-                   PC.hour = $1.value / 100;
-                   PC.minutes = $1.value % 100;
+                   pc->hour = $1.value / 100;
+                   pc->minutes = $1.value % 100;
                  }
-               PC.seconds = 0;
-               PC.meridian = MER24;
+               pc->seconds = 0;
+               pc->meridian = MER24;
              }
          }
       }
@@ -449,13 +452,13 @@ o_merid:
 #include "modules/getdate.h"
 
 #ifndef gmtime
-struct tm *gmtime ();
+struct tm *gmtime (const time_t *);
 #endif
 #ifndef localtime
-struct tm *localtime ();
+struct tm *localtime (const time_t *);
 #endif
 #ifndef mktime
-time_t mktime ();
+time_t mktime (struct tm *);
 #endif
 
 static table const meridian_table[] =
@@ -670,7 +673,7 @@ to_year (textint textyear)
 }
 
 static table const *
-lookup_zone (parser_control const *pc, char const *name)
+lookup_zone (struct parser_control const *pc, char const *name)
 {
   table const *tp;
 
@@ -714,7 +717,7 @@ tm_diff (struct tm const *a, struct tm const *b)
 #endif /* ! HAVE_TM_GMTOFF */
 
 static table const *
-lookup_word (parser_control const *pc, char *word)
+lookup_word (struct parser_control const *pc, char *word)
 {
   char *p;
   char *q;
@@ -783,10 +786,10 @@ lookup_word (parser_control const *pc, char *word)
 }
 
 static int
-yylex (YYSTYPE *lvalp, parser_control *pc)
+yylex (YYSTYPE *lvalp, struct parser_control *pc)
 {
   unsigned char c;
-  int count;
+  size_t count;
 
   for (;;)
     {
@@ -825,18 +828,18 @@ yylex (YYSTYPE *lvalp, parser_control *pc)
       if (ISALPHA (c))
        {
          char buff[20];
-         char *p = buff;
+         size_t i = 0;
          table const *tp;
 
          do
            {
-             if (p < buff + sizeof buff - 1)
-               *p++ = c;
+             if (i < 20)
+               buff[i++] = c;
              c = *++pc->input;
            }
          while (ISALPHA (c) || c == '.');
 
-         *p = '\0';
+         buff[i] = '\0';
          tp = lookup_word (pc, buff);
          if (! tp)
            return '?';
@@ -863,7 +866,7 @@ yylex (YYSTYPE *lvalp, parser_control *pc)
 
 /* Do nothing if the parser reports an error.  */
 static int
-yyerror (char *s ATTRIBUTE_UNUSED)
+yyerror (struct parser_control *pc ATTRIBUTE_UNUSED, const char *s ATTRIBUTE_UNUSED)
 {
   return 0;
 }
@@ -879,7 +882,7 @@ get_date (const char *p, const time_t *now)
   struct tm *tmp = localtime (&Start);
   struct tm tm;
   struct tm tm0;
-  parser_control pc;
+  struct parser_control pc;
 
   if (! tmp)
     return -1;
@@ -908,7 +911,7 @@ get_date (const char *p, const time_t *now)
   pc.local_zones_seen = 0;
   pc.zones_seen = 0;
 
-#if HAVE_STRUCT_TM_TM_ZONE
+#ifdef HAVE_STRUCT_TM_TM_ZONE
   pc.local_time_zone_table[0].name = tmp->tm_zone;
   pc.local_time_zone_table[0].type = tLOCAL_ZONE;
   pc.local_time_zone_table[0].value = tmp->tm_isdst;
@@ -936,7 +939,7 @@ get_date (const char *p, const time_t *now)
       }
   }
 #else
-#if HAVE_TZNAME
+#ifdef HAVE_TZNAME
   {
 # ifndef tzname
     extern char *tzname[];
@@ -959,7 +962,7 @@ get_date (const char *p, const time_t *now)
       && ! strcmp (pc.local_time_zone_table[0].name,
                   pc.local_time_zone_table[1].name))
     {
-      /* This locale uses the same abbrevation for standard and
+      /* This locale uses the same abbreviation for standard and
         daylight times.  So if we see that abbreviation, we don't
         know whether it's daylight time.  */
       pc.local_time_zone_table[0].value = -1;