Commit 38fc79fc authored by Tim Janik's avatar Tim Janik Committed by Tim Janik
Browse files

macros to facilitate the printf/scanf format argument checking of gcc.

Thu May  7 08:17:28 1998  Tim Janik  <timj@gtk.org>

        * glib.h (G_GNUC_PRINTF):
        (G_GNUC_SCANF): macros to facilitate the printf/scanf format argument
        checking of gcc.

        * gstring.c: const corrections, string!=NULL checks at function entry.
        (g_string_down): new function for tolower(3) conversion.
        (g_string_up): new function for toupper(3) conversion.

        * gutils.c: const corrections.
        (g_strdown): g_string_down() counterpart.
        (g_strup): g_string_up() counterpart.

        * gscanner.c (g_scanner_unexp_token):
        (g_scanner_error):
        (g_scanner_warn): new functions to let a scanner put out warnings
        or errors, especially to react on unexpected tokens.

        * gslist.c:
        (g_slist_index): find out about about the position of a
        certain data pointer.
        (g_slist_position): find out about about the position of a
        certain node.

        * glist.c:
        (g_list_index): find out about about the position of a
        certain data pointer.
parent 39ff37dc
Thu May 7 08:17:28 1998 Tim Janik <timj@gtk.org>
* glib.h (G_GNUC_PRINTF):
(G_GNUC_SCANF): macros to facilitate the printf/scanf format argument
checking of gcc.
* gstring.c: const corrections, string!=NULL checks at function entry.
(g_string_down): new function for tolower(3) conversion.
(g_string_up): new function for toupper(3) conversion.
* gutils.c: const corrections.
(g_strdown): g_string_down() counterpart.
(g_strup): g_string_up() counterpart.
* gscanner.c (g_scanner_unexp_token):
(g_scanner_error):
(g_scanner_warn): new functions to let a scanner put out warnings
or errors, especially to react on unexpected tokens.
* gslist.c:
(g_slist_index): find out about about the position of a
certain data pointer.
(g_slist_position): find out about about the position of a
certain node.
* glist.c:
(g_list_index): find out about about the position of a
certain data pointer.
Thu May 7 05:14:19 1998 Tim Janik <timj@gtk.org>
* ltmain.sh: added a new commandline flag -postfix similar to -release,
......
......@@ -55,7 +55,7 @@
static int do_query (char *prompt);
static void debug (char *progname, int method);
static void debug (const gchar *progname, int method);
static void stack_trace (char **);
static void stack_trace_sigchld (int);
......@@ -63,7 +63,7 @@ static void stack_trace_sigchld (int);
static int stack_trace_done;
void
g_debug (char *progname)
g_debug (const gchar *progname)
{
char buf[32];
......@@ -82,14 +82,16 @@ g_debug (char *progname)
}
void
g_attach_process (char *progname, int query)
g_attach_process (const gchar *progname,
int query)
{
if (!query || do_query ("attach to process"))
debug (progname, INTERACTIVE);
}
void
g_stack_trace (char *progname, int query)
g_stack_trace (const gchar *progname,
int query)
{
if (!query || do_query ("print stack trace"))
debug (progname, STACK_TRACE);
......@@ -114,7 +116,7 @@ do_query (char *prompt)
}
static void
debug (char *progname,
debug (const char *progname,
int method)
{
pid_t pid;
......@@ -124,7 +126,7 @@ debug (char *progname,
sprintf (buf, "%d", (int) getpid ());
args[1] = progname;
args[1] = (gchar*) progname;
args[2] = buf;
switch (method)
......
......@@ -285,8 +285,22 @@
#endif /* G_DISABLE_CHECKS */
/* Provide macros to feature the GCC printf format function attribute.
*/
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define G_GNUC_PRINTF( format_idx, arg_idx ) \
__attribute__((format (printf, format_idx, arg_idx)))
#define G_GNUC_SCANF( format_idx, arg_idx ) \
__attribute__((format (scanf, format_idx, arg_idx)))
#else /* !__GNUC__ */
#define G_GNUC_PRINTF( format_idx, arg_idx )
#define G_GNUC_SCANF( format_idx, arg_idx )
#endif /* !__GNUC__ */
#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */
/* Provide type definitions for commonly used types.
......@@ -344,35 +358,46 @@ typedef unsigned long guint32;
#endif /* SIZEOF_INT */
typedef struct _GList GList;
typedef struct _GSList GSList;
typedef struct _GHashTable GHashTable;
typedef struct _GCache GCache;
typedef struct _GTree GTree;
typedef struct _GTimer GTimer;
typedef struct _GMemChunk GMemChunk;
typedef struct _GListAllocator GListAllocator;
typedef struct _GStringChunk GStringChunk;
typedef struct _GString GString;
typedef struct _GArray GArray;
typedef struct _GDebugKey GDebugKey;
typedef void (*GFunc) (gpointer data, gpointer user_data);
typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data);
typedef guint (*GHashFunc) (gpointer key);
typedef gint (*GCompareFunc) (gpointer a, gpointer b);
typedef gpointer (*GCacheNewFunc) (gpointer key);
typedef gpointer (*GCacheDupFunc) (gpointer value);
typedef void (*GCacheDestroyFunc) (gpointer value);
typedef gint (*GTraverseFunc) (gpointer key,
gpointer value,
gpointer data);
typedef gint (*GSearchFunc) (gpointer key,
gpointer data);
typedef void (*GErrorFunc) (gchar *str);
typedef void (*GWarningFunc) (gchar *str);
typedef void (*GPrintFunc) (gchar *str);
typedef struct _GList GList;
typedef struct _GSList GSList;
typedef struct _GHashTable GHashTable;
typedef struct _GCache GCache;
typedef struct _GTree GTree;
typedef struct _GTimer GTimer;
typedef struct _GMemChunk GMemChunk;
typedef struct _GListAllocator GListAllocator;
typedef struct _GStringChunk GStringChunk;
typedef struct _GString GString;
typedef struct _GArray GArray;
typedef struct _GDebugKey GDebugKey;
typedef struct _GScannerConfig GScannerConfig;
typedef struct _GScanner GScanner;
typedef union _GValue GValue;
typedef void (*GFunc) (gpointer data,
gpointer user_data);
typedef void (*GHFunc) (gpointer key,
gpointer value,
gpointer user_data);
typedef guint (*GHashFunc) (gpointer key);
typedef gint (*GCompareFunc) (gpointer a,
gpointer b);
typedef gpointer (*GCacheNewFunc) (gpointer key);
typedef gpointer (*GCacheDupFunc) (gpointer value);
typedef void (*GCacheDestroyFunc) (gpointer value);
typedef gint (*GTraverseFunc) (gpointer key,
gpointer value,
gpointer data);
typedef gint (*GSearchFunc) (gpointer key,
gpointer data);
typedef void (*GErrorFunc) (gchar *str);
typedef void (*GWarningFunc) (gchar *str);
typedef void (*GPrintFunc) (gchar *str);
typedef void (*GScannerMsgFunc) (GScanner *scanner,
gchar *message,
gint error);
struct _GList
{
......@@ -445,9 +470,11 @@ GList* g_list_remove_link (GList *list,
GList* g_list_reverse (GList *list);
GList* g_list_nth (GList *list,
guint n);
GList* g_list_find (GList *list,
gpointer data);
gint g_list_position (GList *list,
GList *link);
GList* g_list_find (GList *list,
gint g_list_index (GList *list,
gpointer data);
GList* g_list_last (GList *list);
GList* g_list_first (GList *list);
......@@ -486,6 +513,10 @@ GSList* g_slist_nth (GSList *list,
guint n);
GSList* g_slist_find (GSList *list,
gpointer data);
gint g_slist_position (GSList *list,
GSList *link);
gint g_slist_index (GSList *list,
gpointer data);
GSList* g_slist_last (GSList *list);
guint g_slist_length (GSList *list);
void g_slist_foreach (GSList *list,
......@@ -648,31 +679,35 @@ gdouble g_timer_elapsed (GTimer *timer,
/* Output
*/
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
void g_error (gchar *format, ...) __attribute__ ((format (printf, 1, 2)));
void g_warning (gchar *format, ...) __attribute__ ((format (printf, 1, 2)));
void g_message (gchar *format, ...) __attribute__ ((format (printf, 1, 2)));
void g_print (gchar *format, ...) __attribute__ ((format (printf, 1, 2)));
#else
void g_error (gchar *format, ...);
void g_warning (gchar *format, ...);
void g_message (gchar *format, ...);
void g_print (gchar *format, ...);
#endif
void g_error (gchar *format, ...) G_GNUC_PRINTF (1, 2);
void g_warning (gchar *format, ...) G_GNUC_PRINTF (1, 2);
void g_message (gchar *format, ...) G_GNUC_PRINTF (1, 2);
void g_print (gchar *format, ...) G_GNUC_PRINTF (1, 2);
/* Utility functions
*/
gchar* g_strdup (const gchar *str);
gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */
gdouble g_strtod (const gchar *nptr, gchar **endptr);
gchar* g_strerror (gint errnum);
gchar* g_strsignal (gint signum);
gint g_strcasecmp (const gchar *s1, const gchar *s2);
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
gint g_snprintf (gchar *str, gulong n, gchar const *fmt, ...) __attribute__ ((format (printf, 3, 4)));
#else
gint g_snprintf (gchar *str, gulong n, gchar const *fmt, ...);
#endif
#define G_STR_DELIMITERS "_-|> <."
void g_strdelimit (gchar *string,
const gchar *delimiters,
gchar new_delimiter);
gchar* g_strdup (const gchar *str);
gchar* g_strconcat (const gchar *string1,
...); /* NULL terminated */
gdouble g_strtod (const gchar *nptr,
gchar **endptr);
gchar* g_strerror (gint errnum);
gchar* g_strsignal (gint signum);
gint g_strcasecmp (const gchar *s1,
const gchar *s2);
void g_strdown (gchar *string);
void g_strup (gchar *string);
guint g_parse_debug_string (const gchar *string,
GDebugKey *keys,
guint nkeys);
gint g_snprintf (gchar *string,
gulong n,
gchar const *format,
...) G_GNUC_PRINTF (3, 4);
/* We make the assumption that if memmove isn't available, then
* bcopy will do the job. This isn't safe everywhere. (bcopy can't
......@@ -690,13 +725,11 @@ GWarningFunc g_set_warning_handler (GWarningFunc func);
GPrintFunc g_set_message_handler (GPrintFunc func);
GPrintFunc g_set_print_handler (GPrintFunc func);
guint g_parse_debug_string (const gchar *string,
GDebugKey *keys,
guint nkeys);
void g_debug (char *progname);
void g_attach_process (char *progname, int query);
void g_stack_trace (char *progname, int query);
void g_debug (const gchar *progname);
void g_attach_process (const gchar *progname,
gint query);
void g_stack_trace (const gchar *progname,
gint query);
/* String Chunks
......@@ -710,47 +743,38 @@ gchar* g_string_chunk_insert_const (GStringChunk *chunk,
/* Strings
*/
GString* g_string_new (gchar *init);
void g_string_free (GString *string,
gint free_segment);
GString* g_string_assign (GString *lval,
gchar *rval);
GString* g_string_truncate (GString *string,
gint len);
GString* g_string_append (GString *string,
gchar *val);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
gchar *val);
GString* g_string_prepend_c (GString *string,
gchar c);
GString* g_string_insert (GString *fstring,
gint pos,
gchar *val);
GString* g_string_insert_c (GString *fstring,
gint pos,
gchar c);
GString* g_string_erase (GString *fstring,
gint pos,
gint len);
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
void g_string_sprintf (GString *string,
gchar *fmt,
...) __attribute__ ((format (printf, 2, 3)));
void g_string_sprintfa (GString *string,
gchar *fmt,
...) __attribute__ ((format (printf, 2, 3)));
#else
void g_string_sprintf (GString *string,
gchar *fmt,
...);
void g_string_sprintfa (GString *string,
gchar *fmt,
...);
#endif
GString* g_string_new (const gchar *init);
void g_string_free (GString *string,
gint free_segment);
GString* g_string_assign (GString *lval,
const gchar *rval);
GString* g_string_truncate (GString *string,
gint len);
GString* g_string_append (GString *string,
const gchar *val);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
const gchar *val);
GString* g_string_prepend_c (GString *string,
gchar c);
GString* g_string_insert (GString *string,
gint pos,
const gchar *val);
GString* g_string_insert_c (GString *string,
gint pos,
gchar c);
GString* g_string_erase (GString *string,
gint pos,
gint len);
GString* g_string_down (GString *string);
GString* g_string_up (GString *string);
void g_string_sprintf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
void g_string_sprintfa (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
/* Resizable arrays
*/
......@@ -794,7 +818,6 @@ guint g_direct_hash (gpointer key);
/* GScanner: Flexible lexical scanner for general purpose.
* Copyright (C) 1997 Tim Janik
*/
/* Character sets */
......@@ -809,10 +832,6 @@ guint g_direct_hash (gpointer key);
"\361\362\363\364\365\366"\
"\370\371\372\373\374\375\376\377"
typedef union _GValue GValue;
typedef struct _GScannerConfig GScannerConfig;
typedef struct _GScanner GScanner;
/* Error types */
typedef enum
{
......@@ -922,6 +941,7 @@ struct _GScanner
guint max_parse_errors;
/* maintained/used by the g_scanner_*() functions */
GScannerMsgFunc msg_handler;
GScannerConfig *config;
GTokenType token;
GValue value;
......@@ -961,6 +981,20 @@ gpointer g_scanner_lookup_symbol (GScanner *scanner,
const gchar *symbol);
void g_scanner_remove_symbol (GScanner *scanner,
const gchar *symbol);
void g_scanner_unexp_token (GScanner *scanner,
GTokenType expected_token,
const gchar *identifier_spec,
const gchar *symbol_spec,
const gchar *symbol_name,
const gchar *message,
gint is_error);
void g_scanner_error (GScanner *scanner,
const gchar *format,
...) G_GNUC_PRINTF (2,3);
void g_scanner_warn (GScanner *scanner,
const gchar *format,
...) G_GNUC_PRINTF (2,3);
gint g_scanner_stat_mode (const gchar *filename);
......
......@@ -300,33 +300,54 @@ g_list_nth (GList *list,
return list;
}
GList*
g_list_find (GList *list,
gpointer data)
{
while (list)
{
if (list->data == data)
break;
list = list->next;
}
return list;
}
gint
g_list_position (GList *list,
GList *link)
g_list_position (GList *list,
GList *link)
{
gint nth;
GList *curlink;
for(nth = 0, curlink = list; curlink; curlink = g_list_next(curlink), nth++)
gint i;
i = 0;
while (list)
{
if(curlink == link) return nth;
if (list == link)
return i;
i++;
list = list->next;
}
return -1;
}
GList*
g_list_find (GList *list,
gpointer data)
gint
g_list_index (GList *list,
gpointer data)
{
gint i;
i = 0;
while (list)
{
if (list->data == data)
break;
return i;
i++;
list = list->next;
}
return list;
return -1;
}
GList*
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GScanner: Flexible lexical scanner for general purpose.
* Copyright (C) 1997 Tim Janik
* 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
......@@ -22,9 +22,12 @@
#define __gscanner_c__
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "glib.h"
......@@ -32,9 +35,9 @@
/* --- 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))>='A' && ((guchar)(c))<='Z') * ('a'-'A') ) | \
( (((guchar)(c))>=192 && ((guchar)(c))<=214) * (224-192) ) | \
( (((guchar)(c))>=216 && ((guchar)(c))<=222) * (248-216) ) | \
((guchar)(c)) \
) \
)
......@@ -96,6 +99,7 @@ static GScannerConfig g_scanner_config_template =
/* --- prototypes --- */
extern char* g_vsprintf (gchar *fmt, va_list *args, va_list *args2);
static GScannerHashVal* g_scanner_lookup_internal (GScanner *scanner,
const gchar *symbol);
static void g_scanner_get_token_ll (GScanner *scanner,
......@@ -118,6 +122,9 @@ 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 --- */
......@@ -154,6 +161,7 @@ g_scanner_new (GScannerConfig *config_templ)
scanner->input_name = NULL;
scanner->parse_errors = 0;
scanner->max_parse_errors = 0;
scanner->msg_handler = g_scanner_msg_handler;
scanner->config = g_new0 (GScannerConfig, 1);
......@@ -224,6 +232,75 @@ g_scanner_destroy (GScanner *scanner)
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: ", scanner->input_name, scanner->line);
if (is_error)
fprintf (stdout, "error: ");
fprintf (stdout, "%s", message);
}
void
g_scanner_error (GScanner *scanner,
const gchar *format,
...)
{
g_return_if_fail (scanner != NULL);
g_return_if_fail (format != NULL);
scanner->parse_errors++;
if (scanner->msg_handler)
{
va_list args, args2;
gchar *string;
va_start (args, format);
va_start (args2, format);
string = g_vsprintf ((gchar*) format, &args, &args2);
va_end (args);
va_end (args2);
string = g_strdup (string);
scanner->msg_handler (scanner, string, TRUE);
g_free (string);
}
}
void
g_scanner_warn (GScanner *scanner,
const gchar *format,
...)
{
g_return_if_fail (scanner != NULL);
g_return_if_fail (format != NULL);
if (scanner->msg_handler)
{
va_list args, args2;
gchar *string;
va_start (args, format);
va_start (args2, format);
string = g_vsprintf ((gchar*) format, &args, &args2);
va_end (args);
va_end (args2);
string = g_strdup (string);
scanner->msg_handler (scanner, string, FALSE);
g_free (string);
}
}
void
g_scanner_input_file (GScanner *scanner,
gint input_fd)
......@@ -245,7 +322,7 @@ g_scanner_input_file (GScanner *scanner,
void
g_scanner_input_text (GScanner *scanner,
const gchar *text,
guint text_len)
guint text_len)
{
g_return_if_fail (text != NULL);
......@@ -530,6 +607,274 @@ g_scanner_get_char (GScanner *scanner,
return fchar;
}
void
g_scanner_unexp_token (GScanner *scanner,
GTokenType expected_token,
const gchar *identifier_spec,
const gchar *symbol_spec,
const gchar *symbol_name,
const gchar *message,
gint is_error)
{
register gchar *token_string;
register guint token_string_len;