/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GScanner: Flexible lexical scanner for general purpose.
* Copyright (C) 1997, 1998 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* MT safe
*/
#define __gscanner_c__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "glib.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#include <sys/types.h> /* needed for sys/stat.h */
#include <sys/stat.h>
#ifdef _MSC_VER
#include <io.h> /* For _read() */
#endif
/* --- defines --- */
#define to_lower(c) ( \
(guchar) ( \
( (((guchar)(c))>='A' && ((guchar)(c))<='Z') * ('a'-'A') ) | \
( (((guchar)(c))>=192 && ((guchar)(c))<=214) * (224-192) ) | \
( (((guchar)(c))>=216 && ((guchar)(c))<=222) * (248-216) ) | \
((guchar)(c)) \
) \
)
#define READ_BUFFER_SIZE (4000)
/* --- typedefs --- */
typedef struct _GScannerKey GScannerKey;
struct _GScannerKey
{
guint scope_id;
gchar *symbol;
gpointer value;
};
/* --- variables --- */
static GScannerConfig g_scanner_config_template =
{
(
" \t\r\n"
) /* cset_skip_characters */,
(
G_CSET_a_2_z
"_"
G_CSET_A_2_Z
) /* cset_identifier_first */,
(
G_CSET_a_2_z
"_0123456789"
G_CSET_A_2_Z
G_CSET_LATINS
G_CSET_LATINC
) /* cset_identifier_nth */,
( "#\n" ) /* cpair_comment_single */,
FALSE /* case_sensitive */,
TRUE /* skip_comment_multi */,
TRUE /* skip_comment_single */,
TRUE /* scan_comment_multi */,
TRUE /* scan_identifier */,
FALSE /* scan_identifier_1char */,
FALSE /* scan_identifier_NULL */,
TRUE /* scan_symbols */,
FALSE /* scan_binary */,
TRUE /* scan_octal */,
TRUE /* scan_float */,
TRUE /* scan_hex */,
FALSE /* scan_hex_dollar */,
TRUE /* scan_string_sq */,
TRUE /* scan_string_dq */,
TRUE /* numbers_2_int */,
FALSE /* int_2_float */,
FALSE /* identifier_2_string */,
TRUE /* char_2_token */,
FALSE /* symbol_2_token */,
FALSE /* scope_0_fallback */,
};
/* --- prototypes --- */
static inline
GScannerKey* g_scanner_lookup_internal (GScanner *scanner,
guint scope_id,
const gchar *symbol);
static gint g_scanner_key_equal (gconstpointer v1,
gconstpointer v2);
static guint g_scanner_key_hash (gconstpointer v);
static void g_scanner_get_token_ll (GScanner *scanner,
GTokenType *token_p,
GTokenValue *value_p,
guint *line_p,
guint *position_p);
static void g_scanner_get_token_i (GScanner *scanner,
GTokenType *token_p,
GTokenValue *value_p,
guint *line_p,
guint *position_p);
static guchar g_scanner_peek_next_char (GScanner *scanner);
static guchar g_scanner_get_char (GScanner *scanner,
guint *line_p,
guint *position_p);
static void g_scanner_msg_handler (GScanner *scanner,
gchar *message,
gint is_error);
/* --- functions --- */
static inline gint
g_scanner_char_2_num (guchar c,
guchar base)
{
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'A' && c <= 'Z')
c -= 'A' - 10;
else if (c >= 'a' && c <= 'z')
c -= 'a' - 10;
else
return -1;
if (c < base)
return c;
return -1;
}
GScanner*
g_scanner_new (GScannerConfig *config_templ)
{
register GScanner *scanner;
if (!config_templ)
config_templ = &g_scanner_config_template;
scanner = g_new0 (GScanner, 1);
scanner->user_data = NULL;
scanner->max_parse_errors = 0;
scanner->parse_errors = 0;
scanner->input_name = NULL;
scanner->derived_data = NULL;
scanner->config = g_new0 (GScannerConfig, 1);
scanner->config->case_sensitive = config_templ->case_sensitive;
scanner->config->cset_skip_characters = config_templ->cset_skip_characters;
scanner->config->cset_identifier_first= config_templ->cset_identifier_first;
scanner->config->cset_identifier_nth = config_templ->cset_identifier_nth;
scanner->config->cpair_comment_single = config_templ->cpair_comment_single;
scanner->config->skip_comment_multi = config_templ->skip_comment_multi;
scanner->config->skip_comment_single = config_templ->skip_comment_single;
scanner->config->scan_comment_multi = config_templ->scan_comment_multi;
scanner->config->scan_identifier = config_templ->scan_identifier;
scanner->config->scan_identifier_1char= config_templ->scan_identifier_1char;
scanner->config->scan_identifier_NULL = config_templ->scan_identifier_NULL;
scanner->config->scan_symbols = config_templ->scan_symbols;
scanner->config->scan_binary = config_templ->scan_binary;
scanner->config->scan_octal = config_templ->scan_octal;
scanner->config->scan_float = config_templ->scan_float;
scanner->config->scan_hex = config_templ->scan_hex;
scanner->config->scan_hex_dollar = config_templ->scan_hex_dollar;
scanner->config->scan_string_sq = config_templ->scan_string_sq;
scanner->config->scan_string_dq = config_templ->scan_string_dq;
scanner->config->numbers_2_int = config_templ->numbers_2_int;
scanner->config->int_2_float = config_templ->int_2_float;
scanner->config->identifier_2_string = config_templ->identifier_2_string;
scanner->config->char_2_token = config_templ->char_2_token;
scanner->config->symbol_2_token = config_templ->symbol_2_token;
scanner->config->scope_0_fallback = config_templ->scope_0_fallback;
scanner->token = G_TOKEN_NONE;
scanner->value.v_int = 0;
scanner->line = 1;
scanner->position = 0;
scanner->next_token = G_TOKEN_NONE;
scanner->next_value.v_int = 0;
scanner->next_line = 1;
scanner->next_position = 0;
scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
scanner->input_fd = -1;
scanner->text = NULL;
scanner->text_end = NULL;
scanner->buffer = NULL;
scanner->scope_id = 0;
scanner->msg_handler = g_scanner_msg_handler;
return scanner;
}
static inline void
g_scanner_free_value (GTokenType *token_p,
GTokenValue *value_p)
{
switch (*token_p)
{
case G_TOKEN_STRING:
case G_TOKEN_IDENTIFIER:
case G_TOKEN_IDENTIFIER_NULL:
case G_TOKEN_COMMENT_SINGLE:
case G_TOKEN_COMMENT_MULTI:
g_free (value_p->v_string);
break;
default:
break;
}
*token_p = G_TOKEN_NONE;
}
static void
g_scanner_destroy_symbol_table_entry (gpointer _key,
gpointer _value,
gpointer _data)
{
GScannerKey *key = _key;
g_free (key->symbol);
g_free (key);
}
void
g_scanner_destroy (GScanner *scanner)
{
g_return_if_fail (scanner != NULL);
g_hash_table_foreach (scanner->symbol_table,
g_scanner_destroy_symbol_table_entry, NULL);
g_hash_table_destroy (scanner->symbol_table);
g_scanner_free_value (&scanner->token, &scanner->value);
g_scanner_free_value (&scanner->next_token, &scanner->next_value);
g_free (scanner->config);
g_free (scanner->buffer);
g_free (scanner);
}
static void
g_scanner_msg_handler (GScanner *scanner,
gchar *message,
gint is_error)
{
g_return_if_fail (scanner != NULL);
fprintf (stdout, "%s:%d: ", scanne
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
glib源码包 1.1.12版 (104个子文件)
glib-config.1 2KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 609B
Makefile.am 577B
Makefile.am 337B
AUTHORS 679B
AUTHORS 25B
gscanner.c 40KB
gdate.c 28KB
gmem.c 25KB
gstrfuncs.c 25KB
testglib.c 24KB
gmain.c 20KB
gnode.c 18KB
gmessages.c 16KB
gtree.c 15KB
gutils.c 15KB
testgdate.c 15KB
gdataset.c 13KB
ghook.c 13KB
glist.c 11KB
garray.c 10KB
gslist.c 10KB
gstring.c 10KB
grel.c 10KB
gmodule.c 9KB
ghash.c 9KB
giounix.c 7KB
gthread-nspr.c 6KB
node-test.c 6KB
gerror.c 6KB
gcompletion.c 6KB
testgmodule.c 6KB
gcache.c 5KB
gmutex.c 5KB
gthread-posix.c 5KB
gthread-solaris.c 5KB
string-test.c 5KB
testgthread.c 5KB
gtimer.c 4KB
gmodule-dld.c 4KB
relation-test.c 4KB
list-test.c 3KB
slist-test.c 3KB
gmodule-dl.c 3KB
hash-test.c 3KB
array-test.c 3KB
gthread.c 3KB
giochannel.c 3KB
tree-test.c 3KB
alloca-test.c 2KB
gmodule-win32.c 2KB
testgdateparser.c 2KB
libgplugin_a.c 2KB
libgplugin_b.c 2KB
gprimes.c 1KB
gthread-none.c 1KB
ChangeLog 74KB
ChangeLog 5KB
ChangeLog 1KB
configure 162KB
COPYING 25KB
COPYING 25KB
glib.def 6KB
gmodule.def 174B
config.guess 24KB
glib.h 87KB
gmodule.h 3KB
acconfig.h 3KB
glib.html 19KB
glib_toc.html 2KB
configure.in 31KB
Makefile.in 19KB
Makefile.in 11KB
Makefile.in 11KB
Makefile.in 9KB
Makefile.in 9KB
config.h.in 4KB
glib-config.in 2KB
gmoduleconf.h.in 1KB
stamp-h.in 10B
glib.info 15KB
INSTALL 2KB
install-sh 5KB
makefile.lcc 2KB
ltconfig 44KB
aclocal.m4 15KB
glib.m4 8KB
acinclude.m4 8KB
acglib.m4 4KB
missing 6KB
mkinstalldirs 727B
makefile.msc 3KB
NEWS 6KB
README 2KB
sanity_check 777B
ltmain.sh 73KB
glib.spec 2KB
config.sub 19KB
共 104 条
- 1
- 2
资源评论
王连丰
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功