mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-09-20 01:06:15 +02:00
indentation fixes.
This commit is contained in:
parent
b813e192c6
commit
ce85619724
407
gcompletion.c
407
gcompletion.c
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
@ -20,219 +20,258 @@
|
|||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void completion_check_cache (GCompletion* cmp, gchar** new_prefix);
|
static void completion_check_cache (GCompletion* cmp,
|
||||||
|
gchar** new_prefix);
|
||||||
|
|
||||||
GCompletion*
|
GCompletion*
|
||||||
g_completion_new (GCompletionFunc func) {
|
g_completion_new (GCompletionFunc func)
|
||||||
GCompletion* gcomp;
|
{
|
||||||
|
GCompletion* gcomp;
|
||||||
|
|
||||||
|
gcomp = g_new (GCompletion, 1);
|
||||||
|
gcomp->items = NULL;
|
||||||
|
gcomp->cache = NULL;
|
||||||
|
gcomp->prefix = NULL;
|
||||||
|
gcomp->func = func;
|
||||||
|
|
||||||
gcomp = g_new(GCompletion, 1);
|
return gcomp;
|
||||||
gcomp->items = NULL;
|
|
||||||
gcomp->cache = NULL;
|
|
||||||
gcomp->prefix = NULL;
|
|
||||||
if ( func )
|
|
||||||
gcomp->func = func;
|
|
||||||
else
|
|
||||||
gcomp->func = NULL;
|
|
||||||
return gcomp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_add_items (GCompletion* cmp, GList* items) {
|
g_completion_add_items (GCompletion* cmp,
|
||||||
GList* it;
|
GList* items)
|
||||||
|
{
|
||||||
|
GList* it;
|
||||||
|
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
|
g_return_if_fail (items != NULL);
|
||||||
|
|
||||||
|
/* optimize adding to cache? */
|
||||||
|
if (cmp->cache)
|
||||||
|
{
|
||||||
|
g_list_free (cmp->cache);
|
||||||
|
cmp->cache = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_if_fail( cmp != NULL);
|
if (cmp->prefix)
|
||||||
g_return_if_fail( items != NULL);
|
{
|
||||||
|
g_free (cmp->prefix);
|
||||||
/* optimize adding to cache? */
|
cmp->prefix = NULL;
|
||||||
if ( cmp->cache ) {
|
}
|
||||||
g_list_free(cmp->cache);
|
|
||||||
cmp->cache = NULL;
|
it = items;
|
||||||
}
|
while (it)
|
||||||
if ( cmp->prefix ) {
|
{
|
||||||
g_free(cmp->prefix);
|
cmp->items = g_list_prepend (cmp->items, it->data);
|
||||||
cmp->prefix = NULL;
|
it = it->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
it = items;
|
|
||||||
while ( it ) {
|
|
||||||
cmp->items = g_list_prepend(cmp->items, it->data);
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_remove_items (GCompletion* cmp, GList* items) {
|
g_completion_remove_items (GCompletion* cmp,
|
||||||
GList* it;
|
GList* items)
|
||||||
|
{
|
||||||
g_return_if_fail( cmp != NULL);
|
GList* it;
|
||||||
g_return_if_fail( items != NULL);
|
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
|
g_return_if_fail (items != NULL);
|
||||||
|
|
||||||
|
it = items;
|
||||||
|
while (cmp->items && it)
|
||||||
|
{
|
||||||
|
cmp->items = g_list_remove (cmp->items, it->data);
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
|
||||||
it = items;
|
it = items;
|
||||||
while ( cmp->items && it ) {
|
while (cmp->cache && it)
|
||||||
cmp->items = g_list_remove(cmp->items, it->data);
|
{
|
||||||
it = it->next;
|
cmp->cache = g_list_remove(cmp->cache, it->data);
|
||||||
}
|
it = it->next;
|
||||||
it = items;
|
}
|
||||||
while ( cmp->cache && it ) {
|
|
||||||
cmp->cache = g_list_remove(cmp->cache, it->data);
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_clear_items (GCompletion* cmp) {
|
g_completion_clear_items (GCompletion* cmp)
|
||||||
g_return_if_fail(cmp != NULL);
|
{
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
g_list_free(cmp->items);
|
|
||||||
cmp->items = NULL;
|
g_list_free (cmp->items);
|
||||||
g_list_free(cmp->cache);
|
cmp->items = NULL;
|
||||||
cmp->cache = NULL;
|
g_list_free (cmp->cache);
|
||||||
g_free(cmp->prefix);
|
cmp->cache = NULL;
|
||||||
cmp->prefix = NULL;
|
g_free (cmp->prefix);
|
||||||
|
cmp->prefix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
completion_check_cache (GCompletion* cmp, gchar** new_prefix) {
|
completion_check_cache (GCompletion* cmp,
|
||||||
register GList* list;
|
gchar** new_prefix)
|
||||||
register gint len;
|
{
|
||||||
register gint i;
|
register GList* list;
|
||||||
register gint plen;
|
register gint len;
|
||||||
gchar* postfix=NULL;
|
register gint i;
|
||||||
gchar* s;
|
register gint plen;
|
||||||
|
gchar* postfix=NULL;
|
||||||
if ( !new_prefix )
|
gchar* s;
|
||||||
return;
|
|
||||||
if ( !cmp->cache ) {
|
if (!new_prefix)
|
||||||
*new_prefix = NULL;
|
return;
|
||||||
return;
|
if (!cmp->cache)
|
||||||
|
{
|
||||||
|
*new_prefix = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strlen(cmp->prefix);
|
||||||
|
list = cmp->cache;
|
||||||
|
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||||
|
postfix = s + len;
|
||||||
|
plen = strlen (postfix);
|
||||||
|
list = list->next;
|
||||||
|
|
||||||
|
while (list && plen)
|
||||||
|
{
|
||||||
|
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||||
|
s += len;
|
||||||
|
for (i = 0; i < plen; ++i)
|
||||||
|
{
|
||||||
|
if (postfix[i] != s[i])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
plen = i;
|
||||||
len = strlen(cmp->prefix);
|
list = list->next;
|
||||||
list = cmp->cache;
|
}
|
||||||
s = cmp->func?(*cmp->func)(list->data):(gchar*)list->data;
|
|
||||||
postfix = s + len;
|
*new_prefix = g_new0 (gchar, len + plen + 1);
|
||||||
plen = strlen(postfix);
|
strncpy (*new_prefix, cmp->prefix, len);
|
||||||
list = list->next;
|
strncpy (*new_prefix + len, postfix, plen);
|
||||||
|
|
||||||
while (list && plen) {
|
|
||||||
s = cmp->func?(*cmp->func)(list->data):(gchar*)list->data;
|
|
||||||
s += len;
|
|
||||||
for (i=0; i < plen; ++i) {
|
|
||||||
if ( postfix[i] != s[i] )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
plen = i;
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
*new_prefix = g_new0(gchar, len+plen+1);
|
|
||||||
strncpy(*new_prefix, cmp->prefix, len);
|
|
||||||
strncpy(*new_prefix+len, postfix, plen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GList*
|
GList*
|
||||||
g_completion_complete (GCompletion* cmp, gchar* prefix, gchar** new_prefix) {
|
g_completion_complete (GCompletion* cmp,
|
||||||
gint plen, len;
|
gchar* prefix,
|
||||||
gint done=0;
|
gchar** new_prefix)
|
||||||
GList* list;
|
{
|
||||||
|
gint plen, len;
|
||||||
g_return_val_if_fail(cmp != NULL, NULL);
|
gint done = 0;
|
||||||
g_return_val_if_fail(prefix != NULL, NULL);
|
GList* list;
|
||||||
|
|
||||||
len = strlen(prefix);
|
g_return_val_if_fail (cmp != NULL, NULL);
|
||||||
if ( cmp->prefix && cmp->cache ) {
|
g_return_val_if_fail (prefix != NULL, NULL);
|
||||||
plen = strlen(cmp->prefix);
|
|
||||||
if ( plen <= len && !strncmp(prefix, cmp->prefix, plen) ) {
|
len = strlen (prefix);
|
||||||
/* use the cache */
|
if (cmp->prefix && cmp->cache)
|
||||||
list = cmp->cache;
|
{
|
||||||
while ( list ) {
|
plen = strlen (cmp->prefix);
|
||||||
if ( strncmp(prefix, cmp->func?(*cmp->func)(list->data):(gchar*)list->data, len) ) {
|
if (plen <= len && !strncmp (prefix, cmp->prefix, plen))
|
||||||
list = g_list_remove_link(cmp->cache, list);
|
{
|
||||||
if ( list != cmp->cache )
|
/* use the cache */
|
||||||
cmp->cache = list;
|
list = cmp->cache;
|
||||||
} else
|
while (list)
|
||||||
list = list->next;
|
{
|
||||||
}
|
if (strncmp (prefix,
|
||||||
done = 1;
|
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||||
|
len))
|
||||||
|
{
|
||||||
|
list = g_list_remove_link (cmp->cache, list);
|
||||||
|
if (list != cmp->cache)
|
||||||
|
cmp->cache = list;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
done = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!done) { /* normal code */
|
|
||||||
g_list_free(cmp->cache);
|
if (!done)
|
||||||
cmp->cache = NULL;
|
{
|
||||||
list = cmp->items;
|
/* normal code */
|
||||||
while (*prefix && list) {
|
g_list_free (cmp->cache);
|
||||||
if ( !strncmp(prefix, cmp->func?(*cmp->func)(list->data):(gchar*)list->data, len) )
|
cmp->cache = NULL;
|
||||||
cmp->cache = g_list_prepend(cmp->cache, list->data);
|
list = cmp->items;
|
||||||
list = list->next;
|
while (*prefix && list)
|
||||||
}
|
{
|
||||||
|
if (!strncmp (prefix,
|
||||||
|
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||||
|
len))
|
||||||
|
cmp->cache = g_list_prepend (cmp->cache, list->data);
|
||||||
|
list = list->next;
|
||||||
}
|
}
|
||||||
if ( cmp->prefix ) {
|
}
|
||||||
g_free(cmp->prefix);
|
if (cmp->prefix)
|
||||||
cmp->prefix = NULL;
|
{
|
||||||
}
|
g_free (cmp->prefix);
|
||||||
if ( cmp->cache )
|
cmp->prefix = NULL;
|
||||||
cmp->prefix = g_strdup(prefix);
|
}
|
||||||
completion_check_cache(cmp, new_prefix);
|
if (cmp->cache)
|
||||||
return *prefix?cmp->cache:cmp->items;
|
cmp->prefix = g_strdup (prefix);
|
||||||
|
completion_check_cache (cmp, new_prefix);
|
||||||
|
|
||||||
|
return *prefix ? cmp->cache : cmp->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_free (GCompletion* cmp) {
|
g_completion_free (GCompletion* cmp)
|
||||||
g_return_if_fail(cmp != NULL);
|
{
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
g_completion_clear_items(cmp);
|
|
||||||
g_free(cmp);
|
g_completion_clear_items (cmp);
|
||||||
|
g_free (cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_COMPLETION
|
#ifdef TEST_COMPLETION
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
int
|
||||||
int main (int argc, char* argv[]) {
|
main (int argc,
|
||||||
|
char* argv[])
|
||||||
FILE * file;
|
{
|
||||||
gchar buf[1024];
|
FILE *file;
|
||||||
GList *list;
|
gchar buf[1024];
|
||||||
GList *result;
|
GList *list;
|
||||||
GList *tmp;
|
GList *result;
|
||||||
GCompletion * cmp;
|
GList *tmp;
|
||||||
gint i;
|
GCompletion *cmp;
|
||||||
gchar* longp=NULL;
|
gint i;
|
||||||
|
gchar *longp = NULL;
|
||||||
if ( argc < 3 ) {
|
|
||||||
g_warning("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
|
if (argc < 3)
|
||||||
return 1;
|
{
|
||||||
}
|
g_warning ("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
|
||||||
|
return 1;
|
||||||
if ( !(file=fopen(argv[1], "r")) ) {
|
}
|
||||||
g_warning("Cannot open %s\n", argv[1]);
|
|
||||||
return 1;
|
file = fopen (argv[1], "r");
|
||||||
}
|
if (!file)
|
||||||
|
{
|
||||||
cmp = g_completion_new(NULL);
|
g_warning ("Cannot open %s\n", argv[1]);
|
||||||
list = g_list_alloc();
|
return 1;
|
||||||
while (fgets(buf, 1024, file)) {
|
}
|
||||||
list->data = g_strdup(buf);
|
|
||||||
g_completion_add_items(cmp, list);
|
cmp = g_completion_new (NULL);
|
||||||
}
|
list = g_list_alloc ();
|
||||||
fclose(file);
|
while (fgets (buf, 1024, file))
|
||||||
|
{
|
||||||
for ( i= 2; i < argc; ++i) {
|
list->data = g_strdup (buf);
|
||||||
printf("COMPLETING: %s\n", argv[i]);
|
g_completion_add_items (cmp, list);
|
||||||
result = g_completion_complete(cmp, argv[i], &longp);
|
}
|
||||||
g_list_foreach(result, (GFunc)printf, NULL);
|
fclose (file);
|
||||||
printf("LONG MATCH: %s\n", longp);
|
|
||||||
g_free(longp);
|
for (i = 2; i < argc; ++i)
|
||||||
longp = NULL;
|
{
|
||||||
}
|
printf ("COMPLETING: %s\n", argv[i]);
|
||||||
|
result = g_completion_complete (cmp, argv[i], &longp);
|
||||||
g_list_foreach(cmp->items, (GFunc)g_free, NULL);
|
g_list_foreach (result, (GFunc) printf, NULL);
|
||||||
g_completion_free(cmp);
|
printf ("LONG MATCH: %s\n", longp);
|
||||||
g_list_free(list);
|
g_free (longp);
|
||||||
return 0;
|
longp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_foreach (cmp->items, (GFunc) g_free, NULL);
|
||||||
|
g_completion_free (cmp);
|
||||||
|
g_list_free (list);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
58
glib.h
58
glib.h
@ -469,6 +469,7 @@ typedef struct _GDebugKey GDebugKey;
|
|||||||
typedef struct _GScannerConfig GScannerConfig;
|
typedef struct _GScannerConfig GScannerConfig;
|
||||||
typedef struct _GScanner GScanner;
|
typedef struct _GScanner GScanner;
|
||||||
typedef union _GValue GValue;
|
typedef union _GValue GValue;
|
||||||
|
typedef struct _GCompletion GCompletion;
|
||||||
typedef struct _GRelation GRelation;
|
typedef struct _GRelation GRelation;
|
||||||
typedef struct _GTuples GTuples;
|
typedef struct _GTuples GTuples;
|
||||||
|
|
||||||
@ -497,6 +498,7 @@ typedef void (*GDestroyNotify) (gpointer data);
|
|||||||
typedef guint (*GHashFunc) (gconstpointer key);
|
typedef guint (*GHashFunc) (gconstpointer key);
|
||||||
typedef gint (*GCompareFunc) (gconstpointer a,
|
typedef gint (*GCompareFunc) (gconstpointer a,
|
||||||
gconstpointer b);
|
gconstpointer b);
|
||||||
|
typedef gchar* (*GCompletionFunc) (gpointer);
|
||||||
|
|
||||||
struct _GList
|
struct _GList
|
||||||
{
|
{
|
||||||
@ -855,7 +857,7 @@ gint g_snprintf (gchar *string,
|
|||||||
gchar* g_basename (const gchar *file_name);
|
gchar* g_basename (const gchar *file_name);
|
||||||
gchar* g_getcwd (void);
|
gchar* g_getcwd (void);
|
||||||
gchar* g_dirname (const gchar *file_name);
|
gchar* g_dirname (const gchar *file_name);
|
||||||
|
|
||||||
|
|
||||||
/* We make the assumption that if memmove isn't available, then
|
/* We make the assumption that if memmove isn't available, then
|
||||||
* bcopy will do the job. This isn't safe everywhere. (bcopy can't
|
* bcopy will do the job. This isn't safe everywhere. (bcopy can't
|
||||||
@ -880,6 +882,7 @@ void g_stack_trace (const gchar *progname,
|
|||||||
gint query);
|
gint query);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* String Chunks
|
/* String Chunks
|
||||||
*/
|
*/
|
||||||
GStringChunk* g_string_chunk_new (gint size);
|
GStringChunk* g_string_chunk_new (gint size);
|
||||||
@ -1163,31 +1166,31 @@ struct _GScanner
|
|||||||
/* unused fields */
|
/* unused fields */
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
guint max_parse_errors;
|
guint max_parse_errors;
|
||||||
|
|
||||||
/* g_scanner_error() increments this field */
|
/* g_scanner_error() increments this field */
|
||||||
guint parse_errors;
|
guint parse_errors;
|
||||||
|
|
||||||
/* name of input stream, featured by the default message handler */
|
/* name of input stream, featured by the default message handler */
|
||||||
const gchar *input_name;
|
const gchar *input_name;
|
||||||
|
|
||||||
/* data pointer for derived structures */
|
/* data pointer for derived structures */
|
||||||
gpointer derived_data;
|
gpointer derived_data;
|
||||||
|
|
||||||
/* link into the scanner configuration */
|
/* link into the scanner configuration */
|
||||||
GScannerConfig *config;
|
GScannerConfig *config;
|
||||||
|
|
||||||
/* fields filled in after g_scanner_get_next_token() */
|
/* fields filled in after g_scanner_get_next_token() */
|
||||||
GTokenType token;
|
GTokenType token;
|
||||||
GValue value;
|
GValue value;
|
||||||
guint line;
|
guint line;
|
||||||
guint position;
|
guint position;
|
||||||
|
|
||||||
/* fields filled in after g_scanner_peek_next_token() */
|
/* fields filled in after g_scanner_peek_next_token() */
|
||||||
GTokenType next_token;
|
GTokenType next_token;
|
||||||
GValue next_value;
|
GValue next_value;
|
||||||
guint next_line;
|
guint next_line;
|
||||||
guint next_position;
|
guint next_position;
|
||||||
|
|
||||||
/* to be considered private */
|
/* to be considered private */
|
||||||
GHashTable *symbol_table;
|
GHashTable *symbol_table;
|
||||||
const gchar *text;
|
const gchar *text;
|
||||||
@ -1195,7 +1198,7 @@ struct _GScanner
|
|||||||
gint input_fd;
|
gint input_fd;
|
||||||
gint peeked_char;
|
gint peeked_char;
|
||||||
guint scope_id;
|
guint scope_id;
|
||||||
|
|
||||||
/* handler function for _warn and _error */
|
/* handler function for _warn and _error */
|
||||||
GScannerMsgFunc msg_handler;
|
GScannerMsgFunc msg_handler;
|
||||||
};
|
};
|
||||||
@ -1263,29 +1266,26 @@ gint g_scanner_stat_mode (const gchar *filename);
|
|||||||
|
|
||||||
/* Completion */
|
/* Completion */
|
||||||
|
|
||||||
typedef gchar* (*GCompletionFunc)(gpointer);
|
struct _GCompletion
|
||||||
|
{
|
||||||
typedef struct _GCompletion GCompletion;
|
GList* items;
|
||||||
|
GCompletionFunc func;
|
||||||
struct _GCompletion {
|
|
||||||
GList* items;
|
gchar* prefix;
|
||||||
GCompletionFunc func;
|
GList* cache;
|
||||||
|
|
||||||
gchar* prefix;
|
|
||||||
GList* cache;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GCompletion* g_completion_new (GCompletionFunc func);
|
GCompletion* g_completion_new (GCompletionFunc func);
|
||||||
void g_completion_add_items (GCompletion* cmp,
|
void g_completion_add_items (GCompletion* cmp,
|
||||||
GList* items);
|
GList* items);
|
||||||
void g_completion_remove_items (GCompletion* cmp,
|
void g_completion_remove_items (GCompletion* cmp,
|
||||||
GList* items);
|
GList* items);
|
||||||
void g_completion_clear_items (GCompletion* cmp);
|
void g_completion_clear_items (GCompletion* cmp);
|
||||||
GList* g_completion_complete (GCompletion* cmp,
|
GList* g_completion_complete (GCompletion* cmp,
|
||||||
gchar* prefix,
|
gchar* prefix,
|
||||||
gchar** new_prefix);
|
gchar** new_prefix);
|
||||||
void g_completion_free (GCompletion* cmp);
|
void g_completion_free (GCompletion* cmp);
|
||||||
|
|
||||||
|
|
||||||
/* GRelation: Indexed Relations. Imagine a really simple table in a
|
/* GRelation: Indexed Relations. Imagine a really simple table in a
|
||||||
* database. Relations are not ordered. This data type is meant for
|
* database. Relations are not ordered. This data type is meant for
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Library General Public License for more details.
|
* Library General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Library General Public
|
* You should have received a copy of the GNU Library General Public
|
||||||
@ -20,219 +20,258 @@
|
|||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void completion_check_cache (GCompletion* cmp, gchar** new_prefix);
|
static void completion_check_cache (GCompletion* cmp,
|
||||||
|
gchar** new_prefix);
|
||||||
|
|
||||||
GCompletion*
|
GCompletion*
|
||||||
g_completion_new (GCompletionFunc func) {
|
g_completion_new (GCompletionFunc func)
|
||||||
GCompletion* gcomp;
|
{
|
||||||
|
GCompletion* gcomp;
|
||||||
|
|
||||||
|
gcomp = g_new (GCompletion, 1);
|
||||||
|
gcomp->items = NULL;
|
||||||
|
gcomp->cache = NULL;
|
||||||
|
gcomp->prefix = NULL;
|
||||||
|
gcomp->func = func;
|
||||||
|
|
||||||
gcomp = g_new(GCompletion, 1);
|
return gcomp;
|
||||||
gcomp->items = NULL;
|
|
||||||
gcomp->cache = NULL;
|
|
||||||
gcomp->prefix = NULL;
|
|
||||||
if ( func )
|
|
||||||
gcomp->func = func;
|
|
||||||
else
|
|
||||||
gcomp->func = NULL;
|
|
||||||
return gcomp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_add_items (GCompletion* cmp, GList* items) {
|
g_completion_add_items (GCompletion* cmp,
|
||||||
GList* it;
|
GList* items)
|
||||||
|
{
|
||||||
|
GList* it;
|
||||||
|
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
|
g_return_if_fail (items != NULL);
|
||||||
|
|
||||||
|
/* optimize adding to cache? */
|
||||||
|
if (cmp->cache)
|
||||||
|
{
|
||||||
|
g_list_free (cmp->cache);
|
||||||
|
cmp->cache = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
g_return_if_fail( cmp != NULL);
|
if (cmp->prefix)
|
||||||
g_return_if_fail( items != NULL);
|
{
|
||||||
|
g_free (cmp->prefix);
|
||||||
/* optimize adding to cache? */
|
cmp->prefix = NULL;
|
||||||
if ( cmp->cache ) {
|
}
|
||||||
g_list_free(cmp->cache);
|
|
||||||
cmp->cache = NULL;
|
it = items;
|
||||||
}
|
while (it)
|
||||||
if ( cmp->prefix ) {
|
{
|
||||||
g_free(cmp->prefix);
|
cmp->items = g_list_prepend (cmp->items, it->data);
|
||||||
cmp->prefix = NULL;
|
it = it->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
it = items;
|
|
||||||
while ( it ) {
|
|
||||||
cmp->items = g_list_prepend(cmp->items, it->data);
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_remove_items (GCompletion* cmp, GList* items) {
|
g_completion_remove_items (GCompletion* cmp,
|
||||||
GList* it;
|
GList* items)
|
||||||
|
{
|
||||||
g_return_if_fail( cmp != NULL);
|
GList* it;
|
||||||
g_return_if_fail( items != NULL);
|
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
|
g_return_if_fail (items != NULL);
|
||||||
|
|
||||||
|
it = items;
|
||||||
|
while (cmp->items && it)
|
||||||
|
{
|
||||||
|
cmp->items = g_list_remove (cmp->items, it->data);
|
||||||
|
it = it->next;
|
||||||
|
}
|
||||||
|
|
||||||
it = items;
|
it = items;
|
||||||
while ( cmp->items && it ) {
|
while (cmp->cache && it)
|
||||||
cmp->items = g_list_remove(cmp->items, it->data);
|
{
|
||||||
it = it->next;
|
cmp->cache = g_list_remove(cmp->cache, it->data);
|
||||||
}
|
it = it->next;
|
||||||
it = items;
|
}
|
||||||
while ( cmp->cache && it ) {
|
|
||||||
cmp->cache = g_list_remove(cmp->cache, it->data);
|
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_clear_items (GCompletion* cmp) {
|
g_completion_clear_items (GCompletion* cmp)
|
||||||
g_return_if_fail(cmp != NULL);
|
{
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
g_list_free(cmp->items);
|
|
||||||
cmp->items = NULL;
|
g_list_free (cmp->items);
|
||||||
g_list_free(cmp->cache);
|
cmp->items = NULL;
|
||||||
cmp->cache = NULL;
|
g_list_free (cmp->cache);
|
||||||
g_free(cmp->prefix);
|
cmp->cache = NULL;
|
||||||
cmp->prefix = NULL;
|
g_free (cmp->prefix);
|
||||||
|
cmp->prefix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
completion_check_cache (GCompletion* cmp, gchar** new_prefix) {
|
completion_check_cache (GCompletion* cmp,
|
||||||
register GList* list;
|
gchar** new_prefix)
|
||||||
register gint len;
|
{
|
||||||
register gint i;
|
register GList* list;
|
||||||
register gint plen;
|
register gint len;
|
||||||
gchar* postfix=NULL;
|
register gint i;
|
||||||
gchar* s;
|
register gint plen;
|
||||||
|
gchar* postfix=NULL;
|
||||||
if ( !new_prefix )
|
gchar* s;
|
||||||
return;
|
|
||||||
if ( !cmp->cache ) {
|
if (!new_prefix)
|
||||||
*new_prefix = NULL;
|
return;
|
||||||
return;
|
if (!cmp->cache)
|
||||||
|
{
|
||||||
|
*new_prefix = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strlen(cmp->prefix);
|
||||||
|
list = cmp->cache;
|
||||||
|
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||||
|
postfix = s + len;
|
||||||
|
plen = strlen (postfix);
|
||||||
|
list = list->next;
|
||||||
|
|
||||||
|
while (list && plen)
|
||||||
|
{
|
||||||
|
s = cmp->func ? cmp->func (list->data) : (gchar*) list->data;
|
||||||
|
s += len;
|
||||||
|
for (i = 0; i < plen; ++i)
|
||||||
|
{
|
||||||
|
if (postfix[i] != s[i])
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
plen = i;
|
||||||
len = strlen(cmp->prefix);
|
list = list->next;
|
||||||
list = cmp->cache;
|
}
|
||||||
s = cmp->func?(*cmp->func)(list->data):(gchar*)list->data;
|
|
||||||
postfix = s + len;
|
*new_prefix = g_new0 (gchar, len + plen + 1);
|
||||||
plen = strlen(postfix);
|
strncpy (*new_prefix, cmp->prefix, len);
|
||||||
list = list->next;
|
strncpy (*new_prefix + len, postfix, plen);
|
||||||
|
|
||||||
while (list && plen) {
|
|
||||||
s = cmp->func?(*cmp->func)(list->data):(gchar*)list->data;
|
|
||||||
s += len;
|
|
||||||
for (i=0; i < plen; ++i) {
|
|
||||||
if ( postfix[i] != s[i] )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
plen = i;
|
|
||||||
list = list->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
*new_prefix = g_new0(gchar, len+plen+1);
|
|
||||||
strncpy(*new_prefix, cmp->prefix, len);
|
|
||||||
strncpy(*new_prefix+len, postfix, plen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GList*
|
GList*
|
||||||
g_completion_complete (GCompletion* cmp, gchar* prefix, gchar** new_prefix) {
|
g_completion_complete (GCompletion* cmp,
|
||||||
gint plen, len;
|
gchar* prefix,
|
||||||
gint done=0;
|
gchar** new_prefix)
|
||||||
GList* list;
|
{
|
||||||
|
gint plen, len;
|
||||||
g_return_val_if_fail(cmp != NULL, NULL);
|
gint done = 0;
|
||||||
g_return_val_if_fail(prefix != NULL, NULL);
|
GList* list;
|
||||||
|
|
||||||
len = strlen(prefix);
|
g_return_val_if_fail (cmp != NULL, NULL);
|
||||||
if ( cmp->prefix && cmp->cache ) {
|
g_return_val_if_fail (prefix != NULL, NULL);
|
||||||
plen = strlen(cmp->prefix);
|
|
||||||
if ( plen <= len && !strncmp(prefix, cmp->prefix, plen) ) {
|
len = strlen (prefix);
|
||||||
/* use the cache */
|
if (cmp->prefix && cmp->cache)
|
||||||
list = cmp->cache;
|
{
|
||||||
while ( list ) {
|
plen = strlen (cmp->prefix);
|
||||||
if ( strncmp(prefix, cmp->func?(*cmp->func)(list->data):(gchar*)list->data, len) ) {
|
if (plen <= len && !strncmp (prefix, cmp->prefix, plen))
|
||||||
list = g_list_remove_link(cmp->cache, list);
|
{
|
||||||
if ( list != cmp->cache )
|
/* use the cache */
|
||||||
cmp->cache = list;
|
list = cmp->cache;
|
||||||
} else
|
while (list)
|
||||||
list = list->next;
|
{
|
||||||
}
|
if (strncmp (prefix,
|
||||||
done = 1;
|
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||||
|
len))
|
||||||
|
{
|
||||||
|
list = g_list_remove_link (cmp->cache, list);
|
||||||
|
if (list != cmp->cache)
|
||||||
|
cmp->cache = list;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
done = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!done) { /* normal code */
|
|
||||||
g_list_free(cmp->cache);
|
if (!done)
|
||||||
cmp->cache = NULL;
|
{
|
||||||
list = cmp->items;
|
/* normal code */
|
||||||
while (*prefix && list) {
|
g_list_free (cmp->cache);
|
||||||
if ( !strncmp(prefix, cmp->func?(*cmp->func)(list->data):(gchar*)list->data, len) )
|
cmp->cache = NULL;
|
||||||
cmp->cache = g_list_prepend(cmp->cache, list->data);
|
list = cmp->items;
|
||||||
list = list->next;
|
while (*prefix && list)
|
||||||
}
|
{
|
||||||
|
if (!strncmp (prefix,
|
||||||
|
cmp->func ? cmp->func (list->data) : (gchar*) list->data,
|
||||||
|
len))
|
||||||
|
cmp->cache = g_list_prepend (cmp->cache, list->data);
|
||||||
|
list = list->next;
|
||||||
}
|
}
|
||||||
if ( cmp->prefix ) {
|
}
|
||||||
g_free(cmp->prefix);
|
if (cmp->prefix)
|
||||||
cmp->prefix = NULL;
|
{
|
||||||
}
|
g_free (cmp->prefix);
|
||||||
if ( cmp->cache )
|
cmp->prefix = NULL;
|
||||||
cmp->prefix = g_strdup(prefix);
|
}
|
||||||
completion_check_cache(cmp, new_prefix);
|
if (cmp->cache)
|
||||||
return *prefix?cmp->cache:cmp->items;
|
cmp->prefix = g_strdup (prefix);
|
||||||
|
completion_check_cache (cmp, new_prefix);
|
||||||
|
|
||||||
|
return *prefix ? cmp->cache : cmp->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_completion_free (GCompletion* cmp) {
|
g_completion_free (GCompletion* cmp)
|
||||||
g_return_if_fail(cmp != NULL);
|
{
|
||||||
|
g_return_if_fail (cmp != NULL);
|
||||||
g_completion_clear_items(cmp);
|
|
||||||
g_free(cmp);
|
g_completion_clear_items (cmp);
|
||||||
|
g_free (cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_COMPLETION
|
#ifdef TEST_COMPLETION
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
int
|
||||||
int main (int argc, char* argv[]) {
|
main (int argc,
|
||||||
|
char* argv[])
|
||||||
FILE * file;
|
{
|
||||||
gchar buf[1024];
|
FILE *file;
|
||||||
GList *list;
|
gchar buf[1024];
|
||||||
GList *result;
|
GList *list;
|
||||||
GList *tmp;
|
GList *result;
|
||||||
GCompletion * cmp;
|
GList *tmp;
|
||||||
gint i;
|
GCompletion *cmp;
|
||||||
gchar* longp=NULL;
|
gint i;
|
||||||
|
gchar *longp = NULL;
|
||||||
if ( argc < 3 ) {
|
|
||||||
g_warning("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
|
if (argc < 3)
|
||||||
return 1;
|
{
|
||||||
}
|
g_warning ("Usage: %s filename prefix1 [prefix2 ...]\n", argv[0]);
|
||||||
|
return 1;
|
||||||
if ( !(file=fopen(argv[1], "r")) ) {
|
}
|
||||||
g_warning("Cannot open %s\n", argv[1]);
|
|
||||||
return 1;
|
file = fopen (argv[1], "r");
|
||||||
}
|
if (!file)
|
||||||
|
{
|
||||||
cmp = g_completion_new(NULL);
|
g_warning ("Cannot open %s\n", argv[1]);
|
||||||
list = g_list_alloc();
|
return 1;
|
||||||
while (fgets(buf, 1024, file)) {
|
}
|
||||||
list->data = g_strdup(buf);
|
|
||||||
g_completion_add_items(cmp, list);
|
cmp = g_completion_new (NULL);
|
||||||
}
|
list = g_list_alloc ();
|
||||||
fclose(file);
|
while (fgets (buf, 1024, file))
|
||||||
|
{
|
||||||
for ( i= 2; i < argc; ++i) {
|
list->data = g_strdup (buf);
|
||||||
printf("COMPLETING: %s\n", argv[i]);
|
g_completion_add_items (cmp, list);
|
||||||
result = g_completion_complete(cmp, argv[i], &longp);
|
}
|
||||||
g_list_foreach(result, (GFunc)printf, NULL);
|
fclose (file);
|
||||||
printf("LONG MATCH: %s\n", longp);
|
|
||||||
g_free(longp);
|
for (i = 2; i < argc; ++i)
|
||||||
longp = NULL;
|
{
|
||||||
}
|
printf ("COMPLETING: %s\n", argv[i]);
|
||||||
|
result = g_completion_complete (cmp, argv[i], &longp);
|
||||||
g_list_foreach(cmp->items, (GFunc)g_free, NULL);
|
g_list_foreach (result, (GFunc) printf, NULL);
|
||||||
g_completion_free(cmp);
|
printf ("LONG MATCH: %s\n", longp);
|
||||||
g_list_free(list);
|
g_free (longp);
|
||||||
return 0;
|
longp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_foreach (cmp->items, (GFunc) g_free, NULL);
|
||||||
|
g_completion_free (cmp);
|
||||||
|
g_list_free (list);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
58
glib/glib.h
58
glib/glib.h
@ -469,6 +469,7 @@ typedef struct _GDebugKey GDebugKey;
|
|||||||
typedef struct _GScannerConfig GScannerConfig;
|
typedef struct _GScannerConfig GScannerConfig;
|
||||||
typedef struct _GScanner GScanner;
|
typedef struct _GScanner GScanner;
|
||||||
typedef union _GValue GValue;
|
typedef union _GValue GValue;
|
||||||
|
typedef struct _GCompletion GCompletion;
|
||||||
typedef struct _GRelation GRelation;
|
typedef struct _GRelation GRelation;
|
||||||
typedef struct _GTuples GTuples;
|
typedef struct _GTuples GTuples;
|
||||||
|
|
||||||
@ -497,6 +498,7 @@ typedef void (*GDestroyNotify) (gpointer data);
|
|||||||
typedef guint (*GHashFunc) (gconstpointer key);
|
typedef guint (*GHashFunc) (gconstpointer key);
|
||||||
typedef gint (*GCompareFunc) (gconstpointer a,
|
typedef gint (*GCompareFunc) (gconstpointer a,
|
||||||
gconstpointer b);
|
gconstpointer b);
|
||||||
|
typedef gchar* (*GCompletionFunc) (gpointer);
|
||||||
|
|
||||||
struct _GList
|
struct _GList
|
||||||
{
|
{
|
||||||
@ -855,7 +857,7 @@ gint g_snprintf (gchar *string,
|
|||||||
gchar* g_basename (const gchar *file_name);
|
gchar* g_basename (const gchar *file_name);
|
||||||
gchar* g_getcwd (void);
|
gchar* g_getcwd (void);
|
||||||
gchar* g_dirname (const gchar *file_name);
|
gchar* g_dirname (const gchar *file_name);
|
||||||
|
|
||||||
|
|
||||||
/* We make the assumption that if memmove isn't available, then
|
/* We make the assumption that if memmove isn't available, then
|
||||||
* bcopy will do the job. This isn't safe everywhere. (bcopy can't
|
* bcopy will do the job. This isn't safe everywhere. (bcopy can't
|
||||||
@ -880,6 +882,7 @@ void g_stack_trace (const gchar *progname,
|
|||||||
gint query);
|
gint query);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* String Chunks
|
/* String Chunks
|
||||||
*/
|
*/
|
||||||
GStringChunk* g_string_chunk_new (gint size);
|
GStringChunk* g_string_chunk_new (gint size);
|
||||||
@ -1163,31 +1166,31 @@ struct _GScanner
|
|||||||
/* unused fields */
|
/* unused fields */
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
guint max_parse_errors;
|
guint max_parse_errors;
|
||||||
|
|
||||||
/* g_scanner_error() increments this field */
|
/* g_scanner_error() increments this field */
|
||||||
guint parse_errors;
|
guint parse_errors;
|
||||||
|
|
||||||
/* name of input stream, featured by the default message handler */
|
/* name of input stream, featured by the default message handler */
|
||||||
const gchar *input_name;
|
const gchar *input_name;
|
||||||
|
|
||||||
/* data pointer for derived structures */
|
/* data pointer for derived structures */
|
||||||
gpointer derived_data;
|
gpointer derived_data;
|
||||||
|
|
||||||
/* link into the scanner configuration */
|
/* link into the scanner configuration */
|
||||||
GScannerConfig *config;
|
GScannerConfig *config;
|
||||||
|
|
||||||
/* fields filled in after g_scanner_get_next_token() */
|
/* fields filled in after g_scanner_get_next_token() */
|
||||||
GTokenType token;
|
GTokenType token;
|
||||||
GValue value;
|
GValue value;
|
||||||
guint line;
|
guint line;
|
||||||
guint position;
|
guint position;
|
||||||
|
|
||||||
/* fields filled in after g_scanner_peek_next_token() */
|
/* fields filled in after g_scanner_peek_next_token() */
|
||||||
GTokenType next_token;
|
GTokenType next_token;
|
||||||
GValue next_value;
|
GValue next_value;
|
||||||
guint next_line;
|
guint next_line;
|
||||||
guint next_position;
|
guint next_position;
|
||||||
|
|
||||||
/* to be considered private */
|
/* to be considered private */
|
||||||
GHashTable *symbol_table;
|
GHashTable *symbol_table;
|
||||||
const gchar *text;
|
const gchar *text;
|
||||||
@ -1195,7 +1198,7 @@ struct _GScanner
|
|||||||
gint input_fd;
|
gint input_fd;
|
||||||
gint peeked_char;
|
gint peeked_char;
|
||||||
guint scope_id;
|
guint scope_id;
|
||||||
|
|
||||||
/* handler function for _warn and _error */
|
/* handler function for _warn and _error */
|
||||||
GScannerMsgFunc msg_handler;
|
GScannerMsgFunc msg_handler;
|
||||||
};
|
};
|
||||||
@ -1263,29 +1266,26 @@ gint g_scanner_stat_mode (const gchar *filename);
|
|||||||
|
|
||||||
/* Completion */
|
/* Completion */
|
||||||
|
|
||||||
typedef gchar* (*GCompletionFunc)(gpointer);
|
struct _GCompletion
|
||||||
|
{
|
||||||
typedef struct _GCompletion GCompletion;
|
GList* items;
|
||||||
|
GCompletionFunc func;
|
||||||
struct _GCompletion {
|
|
||||||
GList* items;
|
gchar* prefix;
|
||||||
GCompletionFunc func;
|
GList* cache;
|
||||||
|
|
||||||
gchar* prefix;
|
|
||||||
GList* cache;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GCompletion* g_completion_new (GCompletionFunc func);
|
GCompletion* g_completion_new (GCompletionFunc func);
|
||||||
void g_completion_add_items (GCompletion* cmp,
|
void g_completion_add_items (GCompletion* cmp,
|
||||||
GList* items);
|
GList* items);
|
||||||
void g_completion_remove_items (GCompletion* cmp,
|
void g_completion_remove_items (GCompletion* cmp,
|
||||||
GList* items);
|
GList* items);
|
||||||
void g_completion_clear_items (GCompletion* cmp);
|
void g_completion_clear_items (GCompletion* cmp);
|
||||||
GList* g_completion_complete (GCompletion* cmp,
|
GList* g_completion_complete (GCompletion* cmp,
|
||||||
gchar* prefix,
|
gchar* prefix,
|
||||||
gchar** new_prefix);
|
gchar** new_prefix);
|
||||||
void g_completion_free (GCompletion* cmp);
|
void g_completion_free (GCompletion* cmp);
|
||||||
|
|
||||||
|
|
||||||
/* GRelation: Indexed Relations. Imagine a really simple table in a
|
/* GRelation: Indexed Relations. Imagine a really simple table in a
|
||||||
* database. Relations are not ordered. This data type is meant for
|
* database. Relations are not ordered. This data type is meant for
|
||||||
|
@ -208,14 +208,14 @@ g_scanner_new (GScannerConfig *config_templ)
|
|||||||
scanner->next_value.v_int = 0;
|
scanner->next_value.v_int = 0;
|
||||||
scanner->next_line = 1;
|
scanner->next_line = 1;
|
||||||
scanner->next_position = 0;
|
scanner->next_position = 0;
|
||||||
|
|
||||||
scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
|
scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
|
||||||
scanner->text = NULL;
|
scanner->text = NULL;
|
||||||
scanner->text_len = 0;
|
scanner->text_len = 0;
|
||||||
scanner->input_fd = -1;
|
scanner->input_fd = -1;
|
||||||
scanner->peeked_char = -1;
|
scanner->peeked_char = -1;
|
||||||
scanner->scope_id = 0;
|
scanner->scope_id = 0;
|
||||||
|
|
||||||
scanner->msg_handler = g_scanner_msg_handler;
|
scanner->msg_handler = g_scanner_msg_handler;
|
||||||
|
|
||||||
return scanner;
|
return scanner;
|
||||||
@ -227,7 +227,7 @@ g_scanner_destroy_symbol_table_entry (gpointer _key,
|
|||||||
gpointer _data)
|
gpointer _data)
|
||||||
{
|
{
|
||||||
GScannerKey *key = _key;
|
GScannerKey *key = _key;
|
||||||
|
|
||||||
g_free (key->symbol);
|
g_free (key->symbol);
|
||||||
g_free (key);
|
g_free (key);
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ g_scanner_msg_handler (GScanner *scanner,
|
|||||||
gint is_error)
|
gint is_error)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line);
|
fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line);
|
||||||
if (is_error)
|
if (is_error)
|
||||||
fprintf (stdout, "error: ");
|
fprintf (stdout, "error: ");
|
||||||
@ -266,9 +266,9 @@ g_scanner_error (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
g_return_if_fail (format != NULL);
|
g_return_if_fail (format != NULL);
|
||||||
|
|
||||||
scanner->parse_errors++;
|
scanner->parse_errors++;
|
||||||
|
|
||||||
if (scanner->msg_handler)
|
if (scanner->msg_handler)
|
||||||
{
|
{
|
||||||
va_list args, args2;
|
va_list args, args2;
|
||||||
@ -279,11 +279,11 @@ g_scanner_error (GScanner *scanner,
|
|||||||
string = g_vsprintf ((gchar*) format, &args, &args2);
|
string = g_vsprintf ((gchar*) format, &args, &args2);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
va_end (args2);
|
va_end (args2);
|
||||||
|
|
||||||
string = g_strdup (string);
|
string = g_strdup (string);
|
||||||
|
|
||||||
scanner->msg_handler (scanner, string, TRUE);
|
scanner->msg_handler (scanner, string, TRUE);
|
||||||
|
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ g_scanner_key_equal (gconstpointer v1,
|
|||||||
{
|
{
|
||||||
register const GScannerKey *key1 = v1;
|
register const GScannerKey *key1 = v1;
|
||||||
register const GScannerKey *key2 = v2;
|
register const GScannerKey *key2 = v2;
|
||||||
|
|
||||||
return (key1->scope_id == key2->scope_id) && (strcmp (key1->symbol, key2->symbol) == 0);
|
return (key1->scope_id == key2->scope_id) && (strcmp (key1->symbol, key2->symbol) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,12 +368,12 @@ g_scanner_key_hash (gconstpointer v)
|
|||||||
register const GScannerKey *key = v;
|
register const GScannerKey *key = v;
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
register guint h;
|
register guint h;
|
||||||
|
|
||||||
h = key->scope_id;
|
h = key->scope_id;
|
||||||
for (c = key->symbol; *c; c++)
|
for (c = key->symbol; *c; c++)
|
||||||
{
|
{
|
||||||
register guint g;
|
register guint g;
|
||||||
|
|
||||||
h = (h << 4) + *c;
|
h = (h << 4) + *c;
|
||||||
g = h & 0xf0000000;
|
g = h & 0xf0000000;
|
||||||
if (g)
|
if (g)
|
||||||
@ -382,7 +382,7 @@ g_scanner_key_hash (gconstpointer v)
|
|||||||
h = h ^ g;
|
h = h ^ g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ g_scanner_lookup_internal (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
register GScannerKey *key_p;
|
register GScannerKey *key_p;
|
||||||
GScannerKey key;
|
GScannerKey key;
|
||||||
|
|
||||||
key.scope_id = scope_id;
|
key.scope_id = scope_id;
|
||||||
|
|
||||||
if (!scanner->config->case_sensitive)
|
if (!scanner->config->case_sensitive)
|
||||||
@ -439,7 +439,7 @@ g_scanner_scope_add_symbol (GScanner *scanner,
|
|||||||
if (!scanner->config->case_sensitive)
|
if (!scanner->config->case_sensitive)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
c = key->symbol;
|
c = key->symbol;
|
||||||
while (*c != 0)
|
while (*c != 0)
|
||||||
{
|
{
|
||||||
@ -462,7 +462,7 @@ g_scanner_scope_remove_symbol (GScanner *scanner,
|
|||||||
|
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
g_return_if_fail (symbol != NULL);
|
g_return_if_fail (symbol != NULL);
|
||||||
|
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
@ -484,7 +484,7 @@ g_scanner_lookup_symbol (GScanner *scanner,
|
|||||||
|
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
scope_id = scanner->scope_id;
|
scope_id = scanner->scope_id;
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
||||||
if (!key && scope_id && scanner->config->scope_0_fallback)
|
if (!key && scope_id && scanner->config->scope_0_fallback)
|
||||||
@ -521,12 +521,12 @@ g_scanner_set_scope (GScanner *scanner,
|
|||||||
guint scope_id)
|
guint scope_id)
|
||||||
{
|
{
|
||||||
register guint old_scope_id;
|
register guint old_scope_id;
|
||||||
|
|
||||||
g_return_val_if_fail (scanner != NULL, 0);
|
g_return_val_if_fail (scanner != NULL, 0);
|
||||||
|
|
||||||
old_scope_id = scanner->scope_id;
|
old_scope_id = scanner->scope_id;
|
||||||
scanner->scope_id = scope_id;
|
scanner->scope_id = scope_id;
|
||||||
|
|
||||||
return old_scope_id;
|
return old_scope_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,13 +540,13 @@ g_scanner_foreach_internal (gpointer _key,
|
|||||||
register GHFunc func;
|
register GHFunc func;
|
||||||
register gpointer func_data;
|
register gpointer func_data;
|
||||||
register guint *scope_id;
|
register guint *scope_id;
|
||||||
|
|
||||||
d = _user_data;
|
d = _user_data;
|
||||||
func = (GHFunc) d[0];
|
func = (GHFunc) d[0];
|
||||||
func_data = d[1];
|
func_data = d[1];
|
||||||
scope_id = d[2];
|
scope_id = d[2];
|
||||||
key = _value;
|
key = _value;
|
||||||
|
|
||||||
if (key->scope_id == *scope_id)
|
if (key->scope_id == *scope_id)
|
||||||
func (key->symbol, key->value, func_data);
|
func (key->symbol, key->value, func_data);
|
||||||
}
|
}
|
||||||
@ -558,13 +558,13 @@ g_scanner_scope_foreach_symbol (GScanner *scanner,
|
|||||||
gpointer func_data)
|
gpointer func_data)
|
||||||
{
|
{
|
||||||
gpointer d[3];
|
gpointer d[3];
|
||||||
|
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
d[0] = (gpointer) func;
|
d[0] = (gpointer) func;
|
||||||
d[1] = func_data;
|
d[1] = func_data;
|
||||||
d[2] = &scope_id;
|
d[2] = &scope_id;
|
||||||
|
|
||||||
g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d);
|
g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ void
|
|||||||
g_scanner_freeze_symbol_table (GScanner *scanner)
|
g_scanner_freeze_symbol_table (GScanner *scanner)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
g_hash_table_freeze (scanner->symbol_table);
|
g_hash_table_freeze (scanner->symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +580,7 @@ void
|
|||||||
g_scanner_thaw_symbol_table (GScanner *scanner)
|
g_scanner_thaw_symbol_table (GScanner *scanner)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
g_hash_table_thaw (scanner->symbol_table);
|
g_hash_table_thaw (scanner->symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,15 +1046,15 @@ g_scanner_stat_mode (const gchar *filename)
|
|||||||
{
|
{
|
||||||
struct stat *stat_buf;
|
struct stat *stat_buf;
|
||||||
gint st_mode;
|
gint st_mode;
|
||||||
|
|
||||||
stat_buf = g_new0 (struct stat, 1);
|
stat_buf = g_new0 (struct stat, 1);
|
||||||
|
|
||||||
lstat (filename, stat_buf);
|
lstat (filename, stat_buf);
|
||||||
|
|
||||||
st_mode = stat_buf->st_mode;
|
st_mode = stat_buf->st_mode;
|
||||||
|
|
||||||
g_free (stat_buf);
|
g_free (stat_buf);
|
||||||
|
|
||||||
return st_mode;
|
return st_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1634,7 +1634,7 @@ g_scanner_get_token_ll (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
register GScannerKey *key;
|
register GScannerKey *key;
|
||||||
register guint scope_id;
|
register guint scope_id;
|
||||||
|
|
||||||
scope_id = scanner->scope_id;
|
scope_id = scanner->scope_id;
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, value.v_identifier);
|
key = g_scanner_lookup_internal (scanner, scope_id, value.v_identifier);
|
||||||
if (!key && scope_id && scanner->config->scope_0_fallback)
|
if (!key && scope_id && scanner->config->scope_0_fallback)
|
||||||
@ -1647,7 +1647,7 @@ g_scanner_get_token_ll (GScanner *scanner,
|
|||||||
value.v_symbol = key->value;
|
value.v_symbol = key->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token == G_TOKEN_IDENTIFIER &&
|
if (token == G_TOKEN_IDENTIFIER &&
|
||||||
config->scan_identifier_NULL &&
|
config->scan_identifier_NULL &&
|
||||||
strlen (value.v_identifier) == 4)
|
strlen (value.v_identifier) == 4)
|
||||||
|
@ -86,23 +86,23 @@ g_strtod (const gchar *nptr,
|
|||||||
gchar *fail_pos_2;
|
gchar *fail_pos_2;
|
||||||
gdouble val_1;
|
gdouble val_1;
|
||||||
gdouble val_2 = 0;
|
gdouble val_2 = 0;
|
||||||
|
|
||||||
g_return_val_if_fail (nptr != NULL, 0);
|
g_return_val_if_fail (nptr != NULL, 0);
|
||||||
|
|
||||||
fail_pos_1 = NULL;
|
fail_pos_1 = NULL;
|
||||||
fail_pos_2 = NULL;
|
fail_pos_2 = NULL;
|
||||||
|
|
||||||
val_1 = strtod (nptr, &fail_pos_1);
|
val_1 = strtod (nptr, &fail_pos_1);
|
||||||
|
|
||||||
if (fail_pos_1 && fail_pos_1[0] != 0)
|
if (fail_pos_1 && fail_pos_1[0] != 0)
|
||||||
{
|
{
|
||||||
gchar *old_locale;
|
gchar *old_locale;
|
||||||
|
|
||||||
old_locale = setlocale (LC_NUMERIC, "C");
|
old_locale = setlocale (LC_NUMERIC, "C");
|
||||||
val_2 = strtod (nptr, &fail_pos_2);
|
val_2 = strtod (nptr, &fail_pos_2);
|
||||||
setlocale (LC_NUMERIC, old_locale);
|
setlocale (LC_NUMERIC, old_locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
|
if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
|
||||||
{
|
{
|
||||||
if (endptr)
|
if (endptr)
|
||||||
@ -542,11 +542,11 @@ g_strerror (gint errnum)
|
|||||||
#else /* NO_SYS_ERRLIST */
|
#else /* NO_SYS_ERRLIST */
|
||||||
extern int sys_nerr;
|
extern int sys_nerr;
|
||||||
extern char *sys_errlist[];
|
extern char *sys_errlist[];
|
||||||
|
|
||||||
if ((errnum > 0) && (errnum <= sys_nerr))
|
if ((errnum > 0) && (errnum <= sys_nerr))
|
||||||
return sys_errlist [errnum];
|
return sys_errlist [errnum];
|
||||||
#endif /* NO_SYS_ERRLIST */
|
#endif /* NO_SYS_ERRLIST */
|
||||||
|
|
||||||
sprintf (msg, "unknown error (%d)", errnum);
|
sprintf (msg, "unknown error (%d)", errnum);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -555,7 +555,7 @@ gchar*
|
|||||||
g_strsignal (gint signum)
|
g_strsignal (gint signum)
|
||||||
{
|
{
|
||||||
static char msg[64];
|
static char msg[64];
|
||||||
|
|
||||||
#ifdef HAVE_STRSIGNAL
|
#ifdef HAVE_STRSIGNAL
|
||||||
extern char *strsignal (int sig);
|
extern char *strsignal (int sig);
|
||||||
return strsignal (signum);
|
return strsignal (signum);
|
||||||
@ -660,7 +660,7 @@ g_strsignal (gint signum)
|
|||||||
extern char *sys_siglist[];
|
extern char *sys_siglist[];
|
||||||
return sys_siglist [signum];
|
return sys_siglist [signum];
|
||||||
#endif /* NO_SYS_SIGLIST */
|
#endif /* NO_SYS_SIGLIST */
|
||||||
|
|
||||||
sprintf (msg, "unknown signal (%d)", signum);
|
sprintf (msg, "unknown signal (%d)", signum);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -669,11 +669,11 @@ void
|
|||||||
g_strdown (gchar *string)
|
g_strdown (gchar *string)
|
||||||
{
|
{
|
||||||
register gchar *s;
|
register gchar *s;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
s = string;
|
s = string;
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
*s = tolower (*s);
|
*s = tolower (*s);
|
||||||
@ -682,14 +682,14 @@ g_strdown (gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strup (gchar *string)
|
g_strup (gchar *string)
|
||||||
{
|
{
|
||||||
register gchar *s;
|
register gchar *s;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
s = string;
|
s = string;
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
*s = toupper (*s);
|
*s = toupper (*s);
|
||||||
@ -698,14 +698,14 @@ g_strup (gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strreverse (gchar *string)
|
g_strreverse (gchar *string)
|
||||||
{
|
{
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
if (*string)
|
if (*string)
|
||||||
{
|
{
|
||||||
register gchar *h, *t;
|
register gchar *h, *t;
|
||||||
|
|
||||||
h = string;
|
h = string;
|
||||||
t = string + strlen (string) - 1;
|
t = string + strlen (string) - 1;
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ g_strcasecmp (const gchar *s1,
|
|||||||
return strcasecmp (s1, s2);
|
return strcasecmp (s1, s2);
|
||||||
#else
|
#else
|
||||||
gint c1, c2;
|
gint c1, c2;
|
||||||
|
|
||||||
while (*s1 && *s2)
|
while (*s1 && *s2)
|
||||||
{
|
{
|
||||||
/* According to A. Cox, some platforms have islower's that
|
/* According to A. Cox, some platforms have islower's that
|
||||||
@ -739,26 +739,26 @@ g_strcasecmp (const gchar *s1,
|
|||||||
c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
|
c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
|
||||||
c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
|
c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
|
||||||
if (c1 != c2)
|
if (c1 != c2)
|
||||||
return (c1 - c2);
|
return (c1 - c2);
|
||||||
s1++; s2++;
|
s1++; s2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strdelimit (gchar *string,
|
g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delim)
|
gchar new_delim)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
if (!delimiters)
|
if (!delimiters)
|
||||||
delimiters = G_STR_DELIMITERS;
|
delimiters = G_STR_DELIMITERS;
|
||||||
|
|
||||||
for (c = string; *c; c++)
|
for (c = string; *c; c++)
|
||||||
{
|
{
|
||||||
if (strchr (delimiters, *c))
|
if (strchr (delimiters, *c))
|
||||||
|
@ -141,11 +141,11 @@ g_dirname (const gchar *file_name)
|
|||||||
while (base > file_name && *base == '/')
|
while (base > file_name && *base == '/')
|
||||||
base--;
|
base--;
|
||||||
len = (guint) 1 + base - file_name;
|
len = (guint) 1 + base - file_name;
|
||||||
|
|
||||||
base = g_new (gchar, len + 1);
|
base = g_new (gchar, len + 1);
|
||||||
g_memmove (base, file_name, len);
|
g_memmove (base, file_name, len);
|
||||||
base[len] = 0;
|
base[len] = 0;
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ void
|
|||||||
g_set_prgname (const gchar *prgname)
|
g_set_prgname (const gchar *prgname)
|
||||||
{
|
{
|
||||||
gchar *c = g_prgname;
|
gchar *c = g_prgname;
|
||||||
|
|
||||||
g_prgname = g_strdup (prgname);
|
g_prgname = g_strdup (prgname);
|
||||||
g_free (c);
|
g_free (c);
|
||||||
}
|
}
|
||||||
|
68
gscanner.c
68
gscanner.c
@ -208,14 +208,14 @@ g_scanner_new (GScannerConfig *config_templ)
|
|||||||
scanner->next_value.v_int = 0;
|
scanner->next_value.v_int = 0;
|
||||||
scanner->next_line = 1;
|
scanner->next_line = 1;
|
||||||
scanner->next_position = 0;
|
scanner->next_position = 0;
|
||||||
|
|
||||||
scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
|
scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal);
|
||||||
scanner->text = NULL;
|
scanner->text = NULL;
|
||||||
scanner->text_len = 0;
|
scanner->text_len = 0;
|
||||||
scanner->input_fd = -1;
|
scanner->input_fd = -1;
|
||||||
scanner->peeked_char = -1;
|
scanner->peeked_char = -1;
|
||||||
scanner->scope_id = 0;
|
scanner->scope_id = 0;
|
||||||
|
|
||||||
scanner->msg_handler = g_scanner_msg_handler;
|
scanner->msg_handler = g_scanner_msg_handler;
|
||||||
|
|
||||||
return scanner;
|
return scanner;
|
||||||
@ -227,7 +227,7 @@ g_scanner_destroy_symbol_table_entry (gpointer _key,
|
|||||||
gpointer _data)
|
gpointer _data)
|
||||||
{
|
{
|
||||||
GScannerKey *key = _key;
|
GScannerKey *key = _key;
|
||||||
|
|
||||||
g_free (key->symbol);
|
g_free (key->symbol);
|
||||||
g_free (key);
|
g_free (key);
|
||||||
}
|
}
|
||||||
@ -252,7 +252,7 @@ g_scanner_msg_handler (GScanner *scanner,
|
|||||||
gint is_error)
|
gint is_error)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line);
|
fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line);
|
||||||
if (is_error)
|
if (is_error)
|
||||||
fprintf (stdout, "error: ");
|
fprintf (stdout, "error: ");
|
||||||
@ -266,9 +266,9 @@ g_scanner_error (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
g_return_if_fail (format != NULL);
|
g_return_if_fail (format != NULL);
|
||||||
|
|
||||||
scanner->parse_errors++;
|
scanner->parse_errors++;
|
||||||
|
|
||||||
if (scanner->msg_handler)
|
if (scanner->msg_handler)
|
||||||
{
|
{
|
||||||
va_list args, args2;
|
va_list args, args2;
|
||||||
@ -279,11 +279,11 @@ g_scanner_error (GScanner *scanner,
|
|||||||
string = g_vsprintf ((gchar*) format, &args, &args2);
|
string = g_vsprintf ((gchar*) format, &args, &args2);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
va_end (args2);
|
va_end (args2);
|
||||||
|
|
||||||
string = g_strdup (string);
|
string = g_strdup (string);
|
||||||
|
|
||||||
scanner->msg_handler (scanner, string, TRUE);
|
scanner->msg_handler (scanner, string, TRUE);
|
||||||
|
|
||||||
g_free (string);
|
g_free (string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ g_scanner_key_equal (gconstpointer v1,
|
|||||||
{
|
{
|
||||||
register const GScannerKey *key1 = v1;
|
register const GScannerKey *key1 = v1;
|
||||||
register const GScannerKey *key2 = v2;
|
register const GScannerKey *key2 = v2;
|
||||||
|
|
||||||
return (key1->scope_id == key2->scope_id) && (strcmp (key1->symbol, key2->symbol) == 0);
|
return (key1->scope_id == key2->scope_id) && (strcmp (key1->symbol, key2->symbol) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,12 +368,12 @@ g_scanner_key_hash (gconstpointer v)
|
|||||||
register const GScannerKey *key = v;
|
register const GScannerKey *key = v;
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
register guint h;
|
register guint h;
|
||||||
|
|
||||||
h = key->scope_id;
|
h = key->scope_id;
|
||||||
for (c = key->symbol; *c; c++)
|
for (c = key->symbol; *c; c++)
|
||||||
{
|
{
|
||||||
register guint g;
|
register guint g;
|
||||||
|
|
||||||
h = (h << 4) + *c;
|
h = (h << 4) + *c;
|
||||||
g = h & 0xf0000000;
|
g = h & 0xf0000000;
|
||||||
if (g)
|
if (g)
|
||||||
@ -382,7 +382,7 @@ g_scanner_key_hash (gconstpointer v)
|
|||||||
h = h ^ g;
|
h = h ^ g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ g_scanner_lookup_internal (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
register GScannerKey *key_p;
|
register GScannerKey *key_p;
|
||||||
GScannerKey key;
|
GScannerKey key;
|
||||||
|
|
||||||
key.scope_id = scope_id;
|
key.scope_id = scope_id;
|
||||||
|
|
||||||
if (!scanner->config->case_sensitive)
|
if (!scanner->config->case_sensitive)
|
||||||
@ -439,7 +439,7 @@ g_scanner_scope_add_symbol (GScanner *scanner,
|
|||||||
if (!scanner->config->case_sensitive)
|
if (!scanner->config->case_sensitive)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
c = key->symbol;
|
c = key->symbol;
|
||||||
while (*c != 0)
|
while (*c != 0)
|
||||||
{
|
{
|
||||||
@ -462,7 +462,7 @@ g_scanner_scope_remove_symbol (GScanner *scanner,
|
|||||||
|
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
g_return_if_fail (symbol != NULL);
|
g_return_if_fail (symbol != NULL);
|
||||||
|
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
||||||
|
|
||||||
if (key)
|
if (key)
|
||||||
@ -484,7 +484,7 @@ g_scanner_lookup_symbol (GScanner *scanner,
|
|||||||
|
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
scope_id = scanner->scope_id;
|
scope_id = scanner->scope_id;
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
key = g_scanner_lookup_internal (scanner, scope_id, symbol);
|
||||||
if (!key && scope_id && scanner->config->scope_0_fallback)
|
if (!key && scope_id && scanner->config->scope_0_fallback)
|
||||||
@ -521,12 +521,12 @@ g_scanner_set_scope (GScanner *scanner,
|
|||||||
guint scope_id)
|
guint scope_id)
|
||||||
{
|
{
|
||||||
register guint old_scope_id;
|
register guint old_scope_id;
|
||||||
|
|
||||||
g_return_val_if_fail (scanner != NULL, 0);
|
g_return_val_if_fail (scanner != NULL, 0);
|
||||||
|
|
||||||
old_scope_id = scanner->scope_id;
|
old_scope_id = scanner->scope_id;
|
||||||
scanner->scope_id = scope_id;
|
scanner->scope_id = scope_id;
|
||||||
|
|
||||||
return old_scope_id;
|
return old_scope_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,13 +540,13 @@ g_scanner_foreach_internal (gpointer _key,
|
|||||||
register GHFunc func;
|
register GHFunc func;
|
||||||
register gpointer func_data;
|
register gpointer func_data;
|
||||||
register guint *scope_id;
|
register guint *scope_id;
|
||||||
|
|
||||||
d = _user_data;
|
d = _user_data;
|
||||||
func = (GHFunc) d[0];
|
func = (GHFunc) d[0];
|
||||||
func_data = d[1];
|
func_data = d[1];
|
||||||
scope_id = d[2];
|
scope_id = d[2];
|
||||||
key = _value;
|
key = _value;
|
||||||
|
|
||||||
if (key->scope_id == *scope_id)
|
if (key->scope_id == *scope_id)
|
||||||
func (key->symbol, key->value, func_data);
|
func (key->symbol, key->value, func_data);
|
||||||
}
|
}
|
||||||
@ -558,13 +558,13 @@ g_scanner_scope_foreach_symbol (GScanner *scanner,
|
|||||||
gpointer func_data)
|
gpointer func_data)
|
||||||
{
|
{
|
||||||
gpointer d[3];
|
gpointer d[3];
|
||||||
|
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
d[0] = (gpointer) func;
|
d[0] = (gpointer) func;
|
||||||
d[1] = func_data;
|
d[1] = func_data;
|
||||||
d[2] = &scope_id;
|
d[2] = &scope_id;
|
||||||
|
|
||||||
g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d);
|
g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ void
|
|||||||
g_scanner_freeze_symbol_table (GScanner *scanner)
|
g_scanner_freeze_symbol_table (GScanner *scanner)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
g_hash_table_freeze (scanner->symbol_table);
|
g_hash_table_freeze (scanner->symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,7 +580,7 @@ void
|
|||||||
g_scanner_thaw_symbol_table (GScanner *scanner)
|
g_scanner_thaw_symbol_table (GScanner *scanner)
|
||||||
{
|
{
|
||||||
g_return_if_fail (scanner != NULL);
|
g_return_if_fail (scanner != NULL);
|
||||||
|
|
||||||
g_hash_table_thaw (scanner->symbol_table);
|
g_hash_table_thaw (scanner->symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1046,15 +1046,15 @@ g_scanner_stat_mode (const gchar *filename)
|
|||||||
{
|
{
|
||||||
struct stat *stat_buf;
|
struct stat *stat_buf;
|
||||||
gint st_mode;
|
gint st_mode;
|
||||||
|
|
||||||
stat_buf = g_new0 (struct stat, 1);
|
stat_buf = g_new0 (struct stat, 1);
|
||||||
|
|
||||||
lstat (filename, stat_buf);
|
lstat (filename, stat_buf);
|
||||||
|
|
||||||
st_mode = stat_buf->st_mode;
|
st_mode = stat_buf->st_mode;
|
||||||
|
|
||||||
g_free (stat_buf);
|
g_free (stat_buf);
|
||||||
|
|
||||||
return st_mode;
|
return st_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1634,7 +1634,7 @@ g_scanner_get_token_ll (GScanner *scanner,
|
|||||||
{
|
{
|
||||||
register GScannerKey *key;
|
register GScannerKey *key;
|
||||||
register guint scope_id;
|
register guint scope_id;
|
||||||
|
|
||||||
scope_id = scanner->scope_id;
|
scope_id = scanner->scope_id;
|
||||||
key = g_scanner_lookup_internal (scanner, scope_id, value.v_identifier);
|
key = g_scanner_lookup_internal (scanner, scope_id, value.v_identifier);
|
||||||
if (!key && scope_id && scanner->config->scope_0_fallback)
|
if (!key && scope_id && scanner->config->scope_0_fallback)
|
||||||
@ -1647,7 +1647,7 @@ g_scanner_get_token_ll (GScanner *scanner,
|
|||||||
value.v_symbol = key->value;
|
value.v_symbol = key->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token == G_TOKEN_IDENTIFIER &&
|
if (token == G_TOKEN_IDENTIFIER &&
|
||||||
config->scan_identifier_NULL &&
|
config->scan_identifier_NULL &&
|
||||||
strlen (value.v_identifier) == 4)
|
strlen (value.v_identifier) == 4)
|
||||||
|
56
gstrfuncs.c
56
gstrfuncs.c
@ -86,23 +86,23 @@ g_strtod (const gchar *nptr,
|
|||||||
gchar *fail_pos_2;
|
gchar *fail_pos_2;
|
||||||
gdouble val_1;
|
gdouble val_1;
|
||||||
gdouble val_2 = 0;
|
gdouble val_2 = 0;
|
||||||
|
|
||||||
g_return_val_if_fail (nptr != NULL, 0);
|
g_return_val_if_fail (nptr != NULL, 0);
|
||||||
|
|
||||||
fail_pos_1 = NULL;
|
fail_pos_1 = NULL;
|
||||||
fail_pos_2 = NULL;
|
fail_pos_2 = NULL;
|
||||||
|
|
||||||
val_1 = strtod (nptr, &fail_pos_1);
|
val_1 = strtod (nptr, &fail_pos_1);
|
||||||
|
|
||||||
if (fail_pos_1 && fail_pos_1[0] != 0)
|
if (fail_pos_1 && fail_pos_1[0] != 0)
|
||||||
{
|
{
|
||||||
gchar *old_locale;
|
gchar *old_locale;
|
||||||
|
|
||||||
old_locale = setlocale (LC_NUMERIC, "C");
|
old_locale = setlocale (LC_NUMERIC, "C");
|
||||||
val_2 = strtod (nptr, &fail_pos_2);
|
val_2 = strtod (nptr, &fail_pos_2);
|
||||||
setlocale (LC_NUMERIC, old_locale);
|
setlocale (LC_NUMERIC, old_locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
|
if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2)
|
||||||
{
|
{
|
||||||
if (endptr)
|
if (endptr)
|
||||||
@ -542,11 +542,11 @@ g_strerror (gint errnum)
|
|||||||
#else /* NO_SYS_ERRLIST */
|
#else /* NO_SYS_ERRLIST */
|
||||||
extern int sys_nerr;
|
extern int sys_nerr;
|
||||||
extern char *sys_errlist[];
|
extern char *sys_errlist[];
|
||||||
|
|
||||||
if ((errnum > 0) && (errnum <= sys_nerr))
|
if ((errnum > 0) && (errnum <= sys_nerr))
|
||||||
return sys_errlist [errnum];
|
return sys_errlist [errnum];
|
||||||
#endif /* NO_SYS_ERRLIST */
|
#endif /* NO_SYS_ERRLIST */
|
||||||
|
|
||||||
sprintf (msg, "unknown error (%d)", errnum);
|
sprintf (msg, "unknown error (%d)", errnum);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -555,7 +555,7 @@ gchar*
|
|||||||
g_strsignal (gint signum)
|
g_strsignal (gint signum)
|
||||||
{
|
{
|
||||||
static char msg[64];
|
static char msg[64];
|
||||||
|
|
||||||
#ifdef HAVE_STRSIGNAL
|
#ifdef HAVE_STRSIGNAL
|
||||||
extern char *strsignal (int sig);
|
extern char *strsignal (int sig);
|
||||||
return strsignal (signum);
|
return strsignal (signum);
|
||||||
@ -660,7 +660,7 @@ g_strsignal (gint signum)
|
|||||||
extern char *sys_siglist[];
|
extern char *sys_siglist[];
|
||||||
return sys_siglist [signum];
|
return sys_siglist [signum];
|
||||||
#endif /* NO_SYS_SIGLIST */
|
#endif /* NO_SYS_SIGLIST */
|
||||||
|
|
||||||
sprintf (msg, "unknown signal (%d)", signum);
|
sprintf (msg, "unknown signal (%d)", signum);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@ -669,11 +669,11 @@ void
|
|||||||
g_strdown (gchar *string)
|
g_strdown (gchar *string)
|
||||||
{
|
{
|
||||||
register gchar *s;
|
register gchar *s;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
s = string;
|
s = string;
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
*s = tolower (*s);
|
*s = tolower (*s);
|
||||||
@ -682,14 +682,14 @@ g_strdown (gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strup (gchar *string)
|
g_strup (gchar *string)
|
||||||
{
|
{
|
||||||
register gchar *s;
|
register gchar *s;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
s = string;
|
s = string;
|
||||||
|
|
||||||
while (*s)
|
while (*s)
|
||||||
{
|
{
|
||||||
*s = toupper (*s);
|
*s = toupper (*s);
|
||||||
@ -698,14 +698,14 @@ g_strup (gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strreverse (gchar *string)
|
g_strreverse (gchar *string)
|
||||||
{
|
{
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
if (*string)
|
if (*string)
|
||||||
{
|
{
|
||||||
register gchar *h, *t;
|
register gchar *h, *t;
|
||||||
|
|
||||||
h = string;
|
h = string;
|
||||||
t = string + strlen (string) - 1;
|
t = string + strlen (string) - 1;
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ g_strcasecmp (const gchar *s1,
|
|||||||
return strcasecmp (s1, s2);
|
return strcasecmp (s1, s2);
|
||||||
#else
|
#else
|
||||||
gint c1, c2;
|
gint c1, c2;
|
||||||
|
|
||||||
while (*s1 && *s2)
|
while (*s1 && *s2)
|
||||||
{
|
{
|
||||||
/* According to A. Cox, some platforms have islower's that
|
/* According to A. Cox, some platforms have islower's that
|
||||||
@ -739,26 +739,26 @@ g_strcasecmp (const gchar *s1,
|
|||||||
c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
|
c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1;
|
||||||
c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
|
c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2;
|
||||||
if (c1 != c2)
|
if (c1 != c2)
|
||||||
return (c1 - c2);
|
return (c1 - c2);
|
||||||
s1++; s2++;
|
s1++; s2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_strdelimit (gchar *string,
|
g_strdelimit (gchar *string,
|
||||||
const gchar *delimiters,
|
const gchar *delimiters,
|
||||||
gchar new_delim)
|
gchar new_delim)
|
||||||
{
|
{
|
||||||
register gchar *c;
|
register gchar *c;
|
||||||
|
|
||||||
g_return_if_fail (string != NULL);
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
if (!delimiters)
|
if (!delimiters)
|
||||||
delimiters = G_STR_DELIMITERS;
|
delimiters = G_STR_DELIMITERS;
|
||||||
|
|
||||||
for (c = string; *c; c++)
|
for (c = string; *c; c++)
|
||||||
{
|
{
|
||||||
if (strchr (delimiters, *c))
|
if (strchr (delimiters, *c))
|
||||||
|
6
gutils.c
6
gutils.c
@ -141,11 +141,11 @@ g_dirname (const gchar *file_name)
|
|||||||
while (base > file_name && *base == '/')
|
while (base > file_name && *base == '/')
|
||||||
base--;
|
base--;
|
||||||
len = (guint) 1 + base - file_name;
|
len = (guint) 1 + base - file_name;
|
||||||
|
|
||||||
base = g_new (gchar, len + 1);
|
base = g_new (gchar, len + 1);
|
||||||
g_memmove (base, file_name, len);
|
g_memmove (base, file_name, len);
|
||||||
base[len] = 0;
|
base[len] = 0;
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ void
|
|||||||
g_set_prgname (const gchar *prgname)
|
g_set_prgname (const gchar *prgname)
|
||||||
{
|
{
|
||||||
gchar *c = g_prgname;
|
gchar *c = g_prgname;
|
||||||
|
|
||||||
g_prgname = g_strdup (prgname);
|
g_prgname = g_strdup (prgname);
|
||||||
g_free (c);
|
g_free (c);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user