usr/src/cmd/localedef/scanner.c
author Garrett D'Amore <garrett@dey-sys.com>
Tue, 27 Aug 2013 18:16:23 -0700
changeset 14265 8ae0bbd9e7cc
parent 13222 02526851ba75
permissions -rw-r--r--
2408 CJK character width handled incorrectly in terminal emulators 3019 localedef(1) manpage is pretty out of date Reviewed by: Yuri Pankov <[email protected]> Reviewed by: Lauri Tirkkonen <[email protected]> Reviewed by: Andy Stormont <[email protected]> Approved by: Gordon Ross <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     1
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     2
 * This file and its contents are supplied under the terms of the
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     3
 * Common Development and Distribution License ("CDDL"), version 1.0.
13222
02526851ba75 357 fix license on strptime.c
Garrett D'Amore <garrett@nexenta.com>
parents: 13200
diff changeset
     4
 * You may only use this file in accordance with the terms of version
02526851ba75 357 fix license on strptime.c
Garrett D'Amore <garrett@nexenta.com>
parents: 13200
diff changeset
     5
 * 1.0 of the CDDL.
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     6
 *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     7
 * A full copy of the text of the CDDL should have accompanied this
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     8
 * source.  A copy of the CDDL is also available via the Internet at
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
     9
 * http://www.illumos.org/license/CDDL.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    10
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    11
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    12
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    13
 * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
    14
 * Copyright 2013 DEY Storage Systems, Inc.
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    15
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    16
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    17
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    18
 * This file contains the "scanner", which tokenizes the input files
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    19
 * for localedef for processing by the higher level grammar processor.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    20
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    21
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    22
#include <stdio.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    23
#include <stdlib.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    24
#include <ctype.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    25
#include <limits.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    26
#include <string.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    27
#include <widec.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    28
#include <sys/types.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    29
#include <assert.h>
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    30
#include "localedef.h"
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    31
#include "parser.tab.h"
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    32
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    33
int			com_char = '#';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    34
int			esc_char = '\\';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    35
int			mb_cur_min = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    36
int			mb_cur_max = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    37
int			lineno = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    38
int			warnings = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    39
static int		nextline;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    40
static FILE		*input = stdin;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    41
static const char	*filename = "<stdin>";
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    42
static int		instring = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    43
static int		escaped = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    44
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    45
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    46
 * Token space ... grows on demand.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    47
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    48
static char *token = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    49
static int tokidx;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    50
static int toksz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    51
static int hadtok = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    52
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    53
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    54
 * Wide string space ... grows on demand.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    55
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    56
static wchar_t *widestr = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    57
static int wideidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    58
static int widesz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    59
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    60
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    61
 * The last keyword seen.  This is useful to trigger the special lexer rules
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    62
 * for "copy" and also collating symbols and elements.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    63
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    64
int	last_kw = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    65
static int	category = T_END;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    66
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    67
static struct token {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    68
	int id;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    69
	const char *name;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    70
} keywords[] = {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    71
	{ T_COM_CHAR,		"comment_char" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    72
	{ T_ESC_CHAR,		"escape_char" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    73
	{ T_END,		"END" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    74
	{ T_COPY,		"copy" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    75
	{ T_MESSAGES,		"LC_MESSAGES" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    76
	{ T_YESSTR,		"yesstr" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    77
	{ T_YESEXPR,		"yesexpr" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    78
	{ T_NOSTR,		"nostr" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    79
	{ T_NOEXPR,		"noexpr" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    80
	{ T_MONETARY,		"LC_MONETARY" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    81
	{ T_INT_CURR_SYMBOL,	"int_curr_symbol" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    82
	{ T_CURRENCY_SYMBOL,	"currency_symbol" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    83
	{ T_MON_DECIMAL_POINT,	"mon_decimal_point" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    84
	{ T_MON_THOUSANDS_SEP,	"mon_thousands_sep" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    85
	{ T_POSITIVE_SIGN,	"positive_sign" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    86
	{ T_NEGATIVE_SIGN,	"negative_sign" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    87
	{ T_MON_GROUPING,	"mon_grouping" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    88
	{ T_INT_FRAC_DIGITS,	"int_frac_digits" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    89
	{ T_FRAC_DIGITS,	"frac_digits" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    90
	{ T_P_CS_PRECEDES,	"p_cs_precedes" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    91
	{ T_P_SEP_BY_SPACE,	"p_sep_by_space" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    92
	{ T_N_CS_PRECEDES,	"n_cs_precedes" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    93
	{ T_N_SEP_BY_SPACE,	"n_sep_by_space" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    94
	{ T_P_SIGN_POSN,	"p_sign_posn" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    95
	{ T_N_SIGN_POSN,	"n_sign_posn" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    96
	{ T_INT_P_CS_PRECEDES,	"int_p_cs_precedes" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    97
	{ T_INT_N_CS_PRECEDES,	"int_n_cs_precedes" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    98
	{ T_INT_P_SEP_BY_SPACE,	"int_p_sep_by_space" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
    99
	{ T_INT_N_SEP_BY_SPACE,	"int_n_sep_by_space" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   100
	{ T_INT_P_SIGN_POSN,	"int_p_sign_posn" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   101
	{ T_INT_N_SIGN_POSN,	"int_n_sign_posn" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   102
	{ T_COLLATE,		"LC_COLLATE" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   103
	{ T_COLLATING_SYMBOL,	"collating-symbol" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   104
	{ T_COLLATING_ELEMENT,	"collating-element" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   105
	{ T_FROM,		"from" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   106
	{ T_ORDER_START,	"order_start" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   107
	{ T_ORDER_END,		"order_end" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   108
	{ T_FORWARD,		"forward" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   109
	{ T_BACKWARD,		"backward" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   110
	{ T_POSITION,		"position" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   111
	{ T_IGNORE,		"IGNORE" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   112
	{ T_UNDEFINED,		"UNDEFINED" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   113
	{ T_NUMERIC,		"LC_NUMERIC" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   114
	{ T_DECIMAL_POINT,	"decimal_point" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   115
	{ T_THOUSANDS_SEP,	"thousands_sep" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   116
	{ T_GROUPING,		"grouping" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   117
	{ T_TIME,		"LC_TIME" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   118
	{ T_ABDAY,		"abday" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   119
	{ T_DAY,		"day" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   120
	{ T_ABMON,		"abmon" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   121
	{ T_MON,		"mon" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   122
	{ T_D_T_FMT,		"d_t_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   123
	{ T_D_FMT,		"d_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   124
	{ T_T_FMT,		"t_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   125
	{ T_AM_PM,		"am_pm" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   126
	{ T_T_FMT_AMPM,		"t_fmt_ampm" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   127
	{ T_ERA,		"era" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   128
	{ T_ERA_D_FMT,		"era_d_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   129
	{ T_ERA_T_FMT,		"era_t_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   130
	{ T_ERA_D_T_FMT,	"era_d_t_fmt" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   131
	{ T_ALT_DIGITS,		"alt_digits" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   132
	{ T_CTYPE,		"LC_CTYPE" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   133
	{ T_ISUPPER,		"upper" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   134
	{ T_ISLOWER,		"lower" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   135
	{ T_ISALPHA,		"alpha" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   136
	{ T_ISDIGIT,		"digit" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   137
	{ T_ISPUNCT,		"punct" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   138
	{ T_ISXDIGIT,		"xdigit" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   139
	{ T_ISSPACE,		"space" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   140
	{ T_ISPRINT,		"print" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   141
	{ T_ISGRAPH,		"graph" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   142
	{ T_ISBLANK,		"blank" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   143
	{ T_ISCNTRL,		"cntrl" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   144
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   145
	 * These entries are local additions, and not specified by
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   146
	 * TOG.  Note that they are not guaranteed to be accurate for
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   147
	 * all locales, and so applications should not depend on them.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   148
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   149
	{ T_ISSPECIAL,		"special" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   150
	{ T_ISENGLISH,		"english" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   151
	{ T_ISPHONOGRAM,	"phonogram" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   152
	{ T_ISIDEOGRAM,		"ideogram" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   153
	{ T_ISNUMBER,		"number" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   154
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   155
	 * We have to support this in the grammar, but it would be a
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   156
	 * syntax error to define a character as one of these without
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   157
	 * also defining it as an alpha or digit.  We ignore it in our
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   158
	 * parsing.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   159
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   160
	{ T_ISALNUM,		"alnum" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   161
	{ T_TOUPPER,		"toupper" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   162
	{ T_TOLOWER,		"tolower" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   163
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   164
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   165
	 * These are keywords used in the charmap file.  Note that
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   166
	 * Solaris orginally used angle brackets to wrap some of them,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   167
	 * but we removed that to simplify our parser.  The first of these
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   168
	 * items are "global items."
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   169
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   170
	{ T_CHARMAP,		"CHARMAP" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   171
	{ T_WIDTH,		"WIDTH" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   172
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   173
	{ -1, NULL },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   174
};
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   175
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   176
/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   177
 * These special words are only used in a charmap file, enclosed in <>.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   178
 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   179
static struct token symwords[] = {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   180
	{ T_COM_CHAR,		"comment_char" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   181
	{ T_ESC_CHAR,		"escape_char" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   182
	{ T_CODE_SET,		"code_set_name" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   183
	{ T_MB_CUR_MAX,		"mb_cur_max" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   184
	{ T_MB_CUR_MIN,		"mb_cur_min" },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   185
	{ -1, NULL },
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   186
};
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   187
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   188
static int categories[] = {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   189
	T_CHARMAP,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   190
	T_CTYPE,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   191
	T_COLLATE,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   192
	T_MESSAGES,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   193
	T_MONETARY,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   194
	T_NUMERIC,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   195
	T_TIME,
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   196
	T_WIDTH,
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   197
	0
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   198
};
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   199
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   200
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   201
reset_scanner(const char *fname)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   202
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   203
	if (fname == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   204
		filename = "<stdin>";
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   205
		input = stdin;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   206
	} else {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   207
		if (input != stdin)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   208
			(void) fclose(input);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   209
		if ((input = fopen(fname, "r")) == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   210
			perror("fopen");
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   211
			exit(4);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   212
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   213
		filename = fname;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   214
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   215
	com_char = '#';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   216
	esc_char = '\\';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   217
	instring = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   218
	escaped = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   219
	lineno = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   220
	nextline = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   221
	tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   222
	wideidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   223
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   224
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   225
#define	hex(x)	\
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   226
	(isdigit(x) ? (x - '0') : ((islower(x) ? (x - 'a') : (x - 'A')) + 10))
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   227
#define	isodigit(x)	((x >= '0') && (x <= '7'))
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   228
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   229
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   230
scanc(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   231
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   232
	int	c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   233
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   234
	c = getc(input);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   235
	lineno = nextline;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   236
	if (c == '\n') {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   237
		nextline++;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   238
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   239
	return (c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   240
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   241
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   242
static void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   243
unscanc(int c)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   244
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   245
	if (c == '\n') {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   246
		nextline--;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   247
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   248
	if (ungetc(c, input) < 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   249
		yyerror(_("ungetc failed"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   250
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   251
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   252
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   253
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   254
scan_hex_byte(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   255
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   256
	int	c1, c2;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   257
	int	v;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   258
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   259
	c1 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   260
	if (!isxdigit(c1)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   261
		yyerror(_("malformed hex digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   262
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   263
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   264
	c2 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   265
	if (!isxdigit(c2)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   266
		yyerror(_("malformed hex digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   267
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   268
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   269
	v = ((hex(c1) << 4) | hex(c2));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   270
	return (v);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   271
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   272
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   273
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   274
scan_dec_byte(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   275
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   276
	int	c1, c2, c3;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   277
	int	b;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   278
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   279
	c1 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   280
	if (!isdigit(c1)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   281
		yyerror(_("malformed decimal digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   282
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   283
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   284
	b = c1 - '0';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   285
	c2 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   286
	if (!isdigit(c2)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   287
		yyerror(_("malformed decimal digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   288
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   289
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   290
	b *= 10;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   291
	b += (c2 - '0');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   292
	c3 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   293
	if (!isdigit(c3)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   294
		unscanc(c3);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   295
	} else {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   296
		b *= 10;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   297
		b += (c3 - '0');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   298
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   299
	return (b);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   300
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   301
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   302
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   303
scan_oct_byte(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   304
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   305
	int c1, c2, c3;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   306
	int	b;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   307
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   308
	b = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   309
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   310
	c1 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   311
	if (!isodigit(c1)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   312
		yyerror(_("malformed octal digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   313
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   314
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   315
	b = c1 - '0';
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   316
	c2 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   317
	if (!isodigit(c2)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   318
		yyerror(_("malformed octal digit"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   319
		return (0);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   320
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   321
	b *= 8;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   322
	b += (c2 - '0');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   323
	c3 = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   324
	if (!isodigit(c3)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   325
		unscanc(c3);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   326
	} else {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   327
		b *= 8;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   328
		b += (c3 - '0');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   329
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   330
	return (b);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   331
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   332
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   333
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   334
add_tok(int c)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   335
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   336
	if ((tokidx + 1) >= toksz) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   337
		toksz += 64;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   338
		if ((token = realloc(token, toksz)) == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   339
			yyerror(_("out of memory"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   340
			tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   341
			toksz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   342
			return;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   343
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   344
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   345
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   346
	token[tokidx++] = (char)c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   347
	token[tokidx] = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   348
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   349
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   350
add_wcs(wchar_t c)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   351
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   352
	if ((wideidx + 1) >= widesz) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   353
		widesz += 64;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   354
		widestr = realloc(widestr, (widesz * sizeof (wchar_t)));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   355
		if (widestr == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   356
			yyerror(_("out of memory"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   357
			wideidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   358
			widesz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   359
			return;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   360
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   361
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   362
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   363
	widestr[wideidx++] = c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   364
	widestr[wideidx] = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   365
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   366
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   367
wchar_t *
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   368
get_wcs(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   369
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   370
	wchar_t *ws = widestr;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   371
	wideidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   372
	widestr = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   373
	widesz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   374
	if (ws == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   375
		if ((ws = wsdup(L"")) == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   376
			yyerror(_("out of memory"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   377
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   378
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   379
	return (ws);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   380
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   381
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   382
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   383
get_byte(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   384
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   385
	int	c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   386
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   387
	if ((c = scanc()) != esc_char) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   388
		unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   389
		return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   390
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   391
	c = scanc();
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   392
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   393
	switch (c) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   394
	case 'd':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   395
	case 'D':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   396
		return (scan_dec_byte());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   397
	case 'x':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   398
	case 'X':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   399
		return (scan_hex_byte());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   400
	case '0':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   401
	case '1':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   402
	case '2':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   403
	case '3':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   404
	case '4':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   405
	case '5':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   406
	case '6':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   407
	case '7':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   408
		/* put the character back so we can get it */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   409
		unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   410
		return (scan_oct_byte());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   411
	default:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   412
		unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   413
		unscanc(esc_char);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   414
		return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   415
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   416
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   417
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   418
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   419
get_escaped(int c)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   420
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   421
	switch (c) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   422
	case 'n':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   423
		return ('\n');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   424
	case 'r':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   425
		return ('\r');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   426
	case 't':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   427
		return ('\t');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   428
	case 'f':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   429
		return ('\f');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   430
	case 'v':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   431
		return ('\v');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   432
	case 'b':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   433
		return ('\b');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   434
	case 'a':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   435
		return ('\a');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   436
	default:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   437
		return (c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   438
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   439
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   440
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   441
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   442
get_wide(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   443
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   444
	static char mbs[MB_LEN_MAX + 1] = "";
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   445
	static int mbi = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   446
	int c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   447
	wchar_t	wc;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   448
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   449
	if (mb_cur_max >= sizeof (mbs)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   450
		yyerror(_("max multibyte character size too big"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   451
		mbi = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   452
		return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   453
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   454
	for (;;) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   455
		if ((mbi == mb_cur_max) || ((c = get_byte()) == EOF)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   456
			/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   457
			 * end of the byte sequence reached, but no
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   458
			 * valid wide decoding.  fatal error.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   459
			 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   460
			mbi = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   461
			yyerror(_("not a valid character encoding"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   462
			return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   463
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   464
		mbs[mbi++] = c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   465
		mbs[mbi] = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   466
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   467
		/* does it decode? */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   468
		if (to_wide(&wc, mbs) >= 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   469
			break;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   470
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   471
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   472
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   473
	mbi = 0;
14265
8ae0bbd9e7cc 2408 CJK character width handled incorrectly in terminal emulators
Garrett D'Amore <garrett@dey-sys.com>
parents: 13222
diff changeset
   474
	if ((category != T_CHARMAP) && (category != T_WIDTH)) {
13200
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   475
		if (check_charmap(wc) < 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   476
			yyerror(_("no symbolic name for character"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   477
			return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   478
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   479
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   480
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   481
	yylval.wc = wc;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   482
	return (T_CHAR);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   483
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   484
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   485
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   486
get_symbol(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   487
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   488
	int	c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   489
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   490
	while ((c = scanc()) != EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   491
		if (escaped) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   492
			escaped = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   493
			if (c == '\n')
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   494
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   495
			add_tok(get_escaped(c));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   496
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   497
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   498
		if (c == esc_char) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   499
			escaped = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   500
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   501
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   502
		if (c == '\n') {	/* well that's strange! */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   503
			yyerror(_("unterminated symbolic name"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   504
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   505
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   506
		if (c == '>') {		/* end of symbol */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   507
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   508
			/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   509
			 * This restarts the token from the beginning
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   510
			 * the next time we scan a character.  (This
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   511
			 * token is complete.)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   512
			 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   513
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   514
			if (token == NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   515
				yyerror(_("missing symbolic name"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   516
				return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   517
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   518
			tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   519
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   520
			/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   521
			 * A few symbols are handled as keywords outside
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   522
			 * of the normal categories.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   523
			 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   524
			if (category == T_END) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   525
				int i;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   526
				for (i = 0; symwords[i].name != 0; i++) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   527
					if (strcmp(token, symwords[i].name) ==
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   528
					    0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   529
						last_kw = symwords[i].id;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   530
						return (last_kw);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   531
					}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   532
				}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   533
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   534
			/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   535
			 * Contextual rule: Only literal characters are
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   536
			 * permitted in CHARMAP.  Anywhere else the symbolic
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   537
			 * forms are fine.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   538
			 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   539
			if ((category != T_CHARMAP) &&
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   540
			    (lookup_charmap(token, &yylval.wc)) != -1) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   541
				return (T_CHAR);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   542
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   543
			if ((yylval.collsym = lookup_collsym(token)) != NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   544
				return (T_COLLSYM);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   545
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   546
			if ((yylval.collelem = lookup_collelem(token)) !=
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   547
			    NULL) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   548
				return (T_COLLELEM);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   549
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   550
			/* its an undefined symbol */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   551
			yylval.token = strdup(token);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   552
			token = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   553
			toksz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   554
			tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   555
			return (T_SYMBOL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   556
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   557
		add_tok(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   558
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   559
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   560
	yyerror(_("unterminated symbolic name"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   561
	return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   562
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   563
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   564
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   565
get_category(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   566
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   567
	return (category);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   568
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   569
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   570
static int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   571
consume_token(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   572
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   573
	int	len = tokidx;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   574
	int	i;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   575
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   576
	tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   577
	if (token == NULL)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   578
		return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   579
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   580
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   581
	 * this one is special, because we don't want it to alter the
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   582
	 * last_kw field.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   583
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   584
	if (strcmp(token, "...") == 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   585
		return (T_ELLIPSIS);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   586
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   587
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   588
	/* search for reserved words first */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   589
	for (i = 0; keywords[i].name; i++) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   590
		int j;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   591
		if (strcmp(keywords[i].name, token) != 0) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   592
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   593
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   594
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   595
		last_kw = keywords[i].id;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   596
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   597
		/* clear the top level category if we're done with it */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   598
		if (last_kw == T_END) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   599
			category = T_END;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   600
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   601
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   602
		/* set the top level category if we're changing */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   603
		for (j = 0; categories[j]; j++) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   604
			if (categories[j] != last_kw)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   605
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   606
			category = last_kw;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   607
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   608
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   609
		return (keywords[i].id);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   610
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   611
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   612
	/* maybe its a numeric constant? */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   613
	if (isdigit(*token) || (*token == '-' && isdigit(token[1]))) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   614
		char *eptr;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   615
		yylval.num = strtol(token, &eptr, 10);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   616
		if (*eptr != 0)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   617
			yyerror(_("malformed number"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   618
		return (T_NUMBER);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   619
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   620
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   621
	/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   622
	 * A single lone character is treated as a character literal.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   623
	 * To avoid duplication of effort, we stick in the charmap.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   624
	 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   625
	if (len == 1) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   626
		yylval.wc = token[0];
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   627
		return (T_CHAR);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   628
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   629
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   630
	/* anything else is treated as a symbolic name */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   631
	yylval.token = strdup(token);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   632
	token = NULL;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   633
	toksz = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   634
	tokidx = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   635
	return (T_NAME);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   636
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   637
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   638
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   639
scan_to_eol(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   640
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   641
	int	c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   642
	while ((c = scanc()) != '\n') {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   643
		if (c == EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   644
			/* end of file without newline! */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   645
			errf(_("missing newline"));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   646
			return;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   647
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   648
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   649
	assert(c == '\n');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   650
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   651
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   652
int
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   653
yylex(void)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   654
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   655
	int		c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   656
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   657
	while ((c = scanc()) != EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   658
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   659
		/* special handling for quoted string */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   660
		if (instring) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   661
			if (escaped) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   662
				escaped = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   663
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   664
				/* if newline, just eat and forget it */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   665
				if (c == '\n')
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   666
					continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   667
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   668
				if (strchr("xXd01234567", c)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   669
					unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   670
					unscanc(esc_char);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   671
					return (get_wide());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   672
				}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   673
				yylval.wc = get_escaped(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   674
				return (T_CHAR);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   675
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   676
			if (c == esc_char) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   677
				escaped = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   678
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   679
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   680
			switch (c) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   681
			case '<':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   682
				return (get_symbol());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   683
			case '>':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   684
				/* oops! should generate syntax error  */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   685
				return (T_GT);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   686
			case '"':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   687
				instring = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   688
				return (T_QUOTE);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   689
			default:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   690
				yylval.wc = c;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   691
				return (T_CHAR);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   692
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   693
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   694
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   695
		/* escaped characters first */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   696
		if (escaped) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   697
			escaped = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   698
			if (c == '\n') {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   699
				/* eat the newline */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   700
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   701
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   702
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   703
			if (tokidx) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   704
				/* an escape mid-token is nonsense */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   705
				return (T_NULL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   706
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   707
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   708
			/* numeric escapes are treated as wide characters */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   709
			if (strchr("xXd01234567", c)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   710
				unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   711
				unscanc(esc_char);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   712
				return (get_wide());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   713
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   714
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   715
			add_tok(get_escaped(c));
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   716
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   717
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   718
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   719
		/* if it is the escape charter itself note it */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   720
		if (c == esc_char) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   721
			escaped = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   722
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   723
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   724
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   725
		/* remove from the comment char to end of line */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   726
		if (c == com_char) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   727
			while (c != '\n') {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   728
				if ((c = scanc()) == EOF) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   729
					/* end of file without newline! */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   730
					return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   731
				}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   732
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   733
			assert(c == '\n');
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   734
			if (!hadtok) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   735
				/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   736
				 * If there were no tokens on this line,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   737
				 * then just pretend it didn't exist at all.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   738
				 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   739
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   740
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   741
			hadtok = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   742
			return (T_NL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   743
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   744
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   745
		if (strchr(" \t\n;()<>,\"", c) && (tokidx != 0)) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   746
			/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   747
			 * These are all token delimiters.  If there
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   748
			 * is a token already in progress, we need to
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   749
			 * process it.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   750
			 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   751
			unscanc(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   752
			return (consume_token());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   753
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   754
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   755
		switch (c) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   756
		case '\n':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   757
			if (!hadtok) {
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   758
				/*
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   759
				 * If the line was completely devoid of tokens,
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   760
				 * then just ignore it.
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   761
				 */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   762
				continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   763
			}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   764
			/* we're starting a new line, reset the token state */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   765
			hadtok = 0;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   766
			return (T_NL);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   767
		case ',':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   768
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   769
			return (T_COMMA);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   770
		case ';':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   771
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   772
			return (T_SEMI);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   773
		case '(':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   774
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   775
			return (T_LPAREN);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   776
		case ')':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   777
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   778
			return (T_RPAREN);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   779
		case '>':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   780
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   781
			return (T_GT);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   782
		case '<':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   783
			/* symbol start! */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   784
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   785
			return (get_symbol());
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   786
		case ' ':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   787
		case '\t':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   788
			/* whitespace, just ignore it */
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   789
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   790
		case '"':
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   791
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   792
			instring = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   793
			return (T_QUOTE);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   794
		default:
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   795
			hadtok = 1;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   796
			add_tok(c);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   797
			continue;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   798
		}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   799
	}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   800
	return (EOF);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   801
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   802
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   803
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   804
yyerror(const char *msg)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   805
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   806
	(void) fprintf(stderr, _("%s: %d: error: %s\n"),
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   807
	    filename, lineno, msg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   808
	exit(4);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   809
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   810
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   811
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   812
errf(const char *fmt, ...)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   813
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   814
	char	*msg;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   815
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   816
	va_list	va;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   817
	va_start(va, fmt);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   818
	(void) vasprintf(&msg, fmt, va);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   819
	va_end(va);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   820
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   821
	(void) fprintf(stderr, _("%s: %d: error: %s\n"),
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   822
	    filename, lineno, msg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   823
	free(msg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   824
	exit(4);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   825
}
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   826
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   827
void
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   828
warn(const char *fmt, ...)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   829
{
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   830
	char	*msg;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   831
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   832
	va_list	va;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   833
	va_start(va, fmt);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   834
	(void) vasprintf(&msg, fmt, va);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   835
	va_end(va);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   836
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   837
	(void) fprintf(stderr, _("%s: %d: warning: %s\n"),
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   838
	    filename, lineno, msg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   839
	free(msg);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   840
	warnings++;
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   841
	if (!warnok)
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   842
		exit(4);
e35262a09b82 8 libc locale work needs updated license files
Garrett D'Amore <garrett@nexenta.com>
parents:
diff changeset
   843
}