Author: peter
Date: 2007-10-15 18:30:14 +0000 (Mon, 15 Oct 2007)
New Revision: 26132

Added:
   squeeze/trunk/libsqueeze/parser-context.c
   squeeze/trunk/libsqueeze/parser-context.h
   squeeze/trunk/libsqueeze/parser.c
   squeeze/trunk/libsqueeze/parser.h
   squeeze/trunk/libsqueeze/scanf-parser.c
   squeeze/trunk/libsqueeze/scanf-parser.h
Modified:
   squeeze/trunk/libsqueeze/archive-iter.c
Log:
beggining of the scanf parser


Modified: squeeze/trunk/libsqueeze/archive-iter.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-iter.c     2007-10-14 20:41:42 UTC (rev 
26131)
+++ squeeze/trunk/libsqueeze/archive-iter.c     2007-10-15 18:30:14 UTC (rev 
26132)
@@ -327,16 +327,16 @@
 #endif
        /* reverse the parent list */
        const LSQArchiveIter *parent = iter->parent;
-       if(!parent)
+       if(G_UNLIKELY(!parent))
        {
                /* the root entry is archive root entry */
-               if(iter->entry != iter->archive->root_entry)
+               if(G_UNLIKELY(iter->entry != iter->archive->root_entry))
                        return FALSE;
        }
        else
        {
                /* find the childeren */
-               if(iter->entry != lsq_archive_entry_get_child(parent->entry, 
lsq_archive_entry_get_filename(iter->entry)))
+               if(G_UNLIKELY(iter->entry != 
lsq_archive_entry_get_child(parent->entry, 
lsq_archive_entry_get_filename(iter->entry))))
                        return FALSE;
        }
        return TRUE;

Added: squeeze/trunk/libsqueeze/parser-context.c
===================================================================
--- squeeze/trunk/libsqueeze/parser-context.c                           (rev 0)
+++ squeeze/trunk/libsqueeze/parser-context.c   2007-10-15 18:30:14 UTC (rev 
26132)
@@ -0,0 +1,94 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or 
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib-object.h> 
+#include <signal.h>
+
+#include "libsqueeze.h"
+
+#include "parser-context.h"
+
+enum {
+       LSQ_PARSER_CONTEXT_PROPERTY_ARCHIVE = 1
+};
+
+static void lsq_parser_context_set_property(GObject*, guint, const GValue*, 
GParamSpec*);
+static void lsq_parser_context_get_property(GObject*, guint, GValue*, 
GParamSpec*);
+
+G_DEFINE_TYPE(LSQParserContext, lsq_parser_context, G_TYPE_OBJECT);
+
+static void
+lsq_parser_context_init(LSQParser *self)
+{
+       self->archive = NULL;
+}
+
+static void
+lsq_parser_context_class_init(LSQParserClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS(klass);
+       GParamSpec *pspec;
+
+       object_class->set_property = lsq_parser_context_set_property;
+       object_class->get_property = lsq_parser_context_get_property;
+
+       pspec = g_param_spec_object("archive", NULL, NULL, LSQ_TYPE_ARCHIVE, 
G_PARAM_READABLE|G_PARAM_CONSTRUCT_ONLY);
+       g_object_class_install_property(object_clas, 
LSQ_PARSER_CONTEXT_PROPERTY_ARCHIVE, pspec);
+}
+
+static void
+lsq_parser_context_set_property(GObject *object, guint property_id, const 
GValue *value, GParamSpec *pspec)
+{
+       switch(property_id)
+       {
+               case LSQ_PARSER_CONTEXT_PROPERTY_ARCHIVE:
+                       LSQ_PARSER_CONTEXT(object)->archive = 
g_value_get_object(value);
+               break;
+       }
+}
+
+static void
+lsq_parser_context_get_property(GObject *object, guint property_id, GValue 
*value, GParamSpec *pspec)
+{
+       switch(property_id)
+       {
+               case LSQ_PARSER_CONTEXT_PROPERTY_ARCHIVE:
+                       g_value_set_object(value, 
LSQ_PARSER_CONTEXT(object)->archive);
+               break;
+       }
+}
+
+LSQParserContext*
+lsq_parser_context_new(LSQArchive *archive)
+{
+       LSQParserContext *ctx
+       
+       g_return_val_if_fail(LSQ_IS_ARCHIVE(archive), NULL);
+
+       ctx = g_object_new(LSQ_PARSER_CONTEXT_TYPE, "archive", archive);
+
+       return ctx;
+}
+
+gboolean
+lsq_parser_context_get_line(LSQParserContext *ctx, gchar **line, gsize *length)
+{
+       GIOStatus stat;
+
+       stat = g_io_channel_read_line
+}

Added: squeeze/trunk/libsqueeze/parser-context.h
===================================================================
--- squeeze/trunk/libsqueeze/parser-context.h                           (rev 0)
+++ squeeze/trunk/libsqueeze/parser-context.h   2007-10-15 18:30:14 UTC (rev 
26132)
@@ -0,0 +1,66 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software 
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 
+ */
+
+#ifndef __LIBSQUEEZE_PARSER_CONTEXT_H__
+#define __LIBSQUEEZE_PARSER_CONTEXT_H__ 
+
+G_BEGIN_DECLS
+
+#define LSQ_TYPE_PARSER_CONTEXT lsq_parser_context_get_type()
+
+#define LSQ_PARSER_CONTEXT(obj) (               \
+               G_TYPE_CHECK_INSTANCE_CAST ((obj),  \
+                       LSQ_TYPE_PARSER_CONTEXT,                  \
+                       LSQParserContext))
+
+#define LSQ_IS_PARSER_CONTEXT(obj) (            \
+               G_TYPE_CHECK_INSTANCE_TYPE ((obj),  \
+                       LSQ_TYPE_PARSER_CONTEXT))
+
+#define LSQ_PARSER_CONTEXT_CLASS(class) (      \
+               G_TYPE_CHECK_CLASS_CAST ((class),  \
+                       LSQ_TYPE_PARSER_CONTEXT,                 \
+                       LSQParserContextClass))
+
+#define LSQ_IS_PARSER_CONTEXT_CLASS(class) (   \
+               G_TYPE_CHECK_CLASS_TYPE ((class),  \
+                       LSQ_TYPE_PARSER_CONTEXT))
+
+typedef struct _LSQParserContext LSQParserContext;
+
+struct _LSQParserContext
+{
+       GObject parent;
+
+       LSQArchive *archive;
+};
+
+typedef struct _LSQParserContextClass LSQParserContextClass;
+
+struct _LSQParserContextClass
+{
+       GObjectClass parent;
+};
+
+GType             lsq_parser_context_get_type (void);
+
+LSQParserContext *lsq_parser_context_new      (LSQArchive *archive);
+
+gboolean          lsq_parser_context_get_line (LSQParserContext *, gchar **, 
gsize *);
+
+G_END_DECLS
+
+#endif /* __LIBSQUEEZE_PARSER_CONTEXT_H__ */
+

Added: squeeze/trunk/libsqueeze/parser.c
===================================================================
--- squeeze/trunk/libsqueeze/parser.c                           (rev 0)
+++ squeeze/trunk/libsqueeze/parser.c   2007-10-15 18:30:14 UTC (rev 26132)
@@ -0,0 +1,49 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or 
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <glib-object.h> 
+#include <signal.h>
+
+#include "libsqueeze.h"
+
+#include "parser-context.h"
+#include "parser.h"
+
+G_DEFINE_ABSTRACT_TYPE(LSQParser, lsq_parser, G_TYPE_OBJECT);
+
+static void
+lsq_parser_init(LSQParser *self)
+{
+}
+
+static void
+lsq_parser_class_init(LSQParserClass *klass)
+{
+       klass->get_context = NULL;
+}
+
+LSQParserContext*
+lsq_parser_get_context(LSQParser *self, LSQArchive *archive)
+{
+       LSQParserClass *klass = LSQ_PARSER_GET_CLASS(self);
+
+       g_return_val_if_fail(klass->get_context, NULL);
+
+       return klass->get_context(self, archive);
+}
+

Added: squeeze/trunk/libsqueeze/parser.h
===================================================================
--- squeeze/trunk/libsqueeze/parser.h                           (rev 0)
+++ squeeze/trunk/libsqueeze/parser.h   2007-10-15 18:30:14 UTC (rev 26132)
@@ -0,0 +1,67 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software 
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 
+ */
+
+#ifndef __LIBSQUEEZE_PARSER_H__
+#define __LIBSQUEEZE_PARSER_H__ 
+
+G_BEGIN_DECLS
+
+#define LSQ_TYPE_PARSER lsq_parser_get_type()
+
+#define LSQ_PARSER(obj) (               \
+               G_TYPE_CHECK_INSTANCE_CAST ((obj),  \
+                       LSQ_TYPE_PARSER,                  \
+                       LSQParser))
+
+#define LSQ_IS_PARSER(obj) (            \
+               G_TYPE_CHECK_INSTANCE_TYPE ((obj),  \
+                       LSQ_TYPE_PARSER))
+
+#define LSQ_PARSER_CLASS(class) (      \
+               G_TYPE_CHECK_CLASS_CAST ((class),  \
+                       LSQ_TYPE_PARSER,                 \
+                       LSQParserClass))
+
+#define LSQ_IS_PARSER_CLASS(class) (   \
+               G_TYPE_CHECK_CLASS_TYPE ((class),  \
+                       LSQ_TYPE_PARSER))
+
+
+typedef struct _LSQParser LSQParser;
+
+struct _LSQParser
+{
+       GObject parent;
+};
+
+
+typedef struct _LSQParserClass LSQParserClass;
+
+struct _LSQParserClass
+{
+       GObjectClass parent;
+
+       LSQParserContext*(*get_context)(LSQParser *, LSQArchive *);
+};
+
+
+GType             lsq_parser_get_type(void);
+
+LSQParserContext* lsq_parser_get_context(LSQParser *, LSQArchive *);
+
+G_END_DECLS
+
+#endif /* __LIBSQUEEZE_PARSER_H__ */
+

Added: squeeze/trunk/libsqueeze/scanf-parser.c
===================================================================
--- squeeze/trunk/libsqueeze/scanf-parser.c                             (rev 0)
+++ squeeze/trunk/libsqueeze/scanf-parser.c     2007-10-15 18:30:14 UTC (rev 
26132)
@@ -0,0 +1,768 @@
+/* 
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or 
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib-object.h> 
+
+#include "libsqueeze-archive.h"
+#include "archive-iter.h"
+#include "scanf-parser.h"
+#include "archive.h"
+
+typedef struct _parse_part parse_part;
+
+typedef guint (*)(gchar*, guint, parse_part*) parse_func;
+
+struct _parse_part
+{
+       gchar *delimiter;
+       parse_func function;
+       guint index;
+       guint width;
+       //gtype
+};
+
+/*{{{ skip functions*/
+guint skip_byte(gchar *str, guint lng, parse_part *part)
+{
+       if(lng < 1)
+               return 0;
+       
+       return 1;
+}
+
+guint skip_word(gchar *str, guint lng, parse_part *part)
+{
+       if(lng < 2)
+               return 0;
+       
+       return 2;
+}
+
+guint skip_dword(gchar *str, guint lng, parse_part *part)
+{
+       if(lng < 4)
+               return 0;
+       
+       return 4;
+}
+
+guint skip_qword(gchar *str, guint lng, parse_part *part)
+{
+       if(lng < 8)
+               return 0;
+       
+       return 8;
+}
+
+guint skip_char(gchar *str, guint lng, parse_part *part)
+{
+       const gchar ptr;
+
+       if(!lng)
+               return 0;
+
+       if(!part->delim[0])
+               return 1;
+
+       //for(ptr = str; g_ascii_isspace(*ptr); ptr++);
+
+       ptr = g_strstr_len(str, lng, part->delim);
+       
+       return ptr - str;
+}
+
+guint skip_decimal(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+#ifdef DO_EXSTENSIVE_CHECKING
+       gchar ptr2;
+#endif
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+       {
+               g_ascii_strtoll(str, &ptr, 10);
+               return ptr - str;
+       }
+
+       for(ptr = str; g_ascii_isspace(*ptr); ptr++);
+
+       ptr = g_strstr_len(ptr, lng, part->delimiter);
+#ifdef DO_EXSTENSIVE_CHECKING
+       g_ascii_strtoll(str, &ptr2, 10);
+       if(ptr > ptr2)
+               return 0;
+#endif
+       
+       return ptr - str;
+}
+
+guint skip_floatingpoint(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+#ifdef DO_EXSTENSIVE_CHECKING
+       gchar ptr2;
+#endif
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+       {
+               g_ascii_strtod(str, &ptr);
+               return ptr - str;
+       }
+
+       for(ptr = str; g_ascii_isspace(*ptr); ptr++);
+
+       ptr = g_strstr_len(ptr, lng, part->delimiter);
+#ifdef DO_EXSTENSIVE_CHECKING
+       g_ascii_strtod(str, &ptr2);
+       if(ptr > ptr2)
+               return 0;
+#endif
+       
+       return ptr - str;
+}
+
+guint skip_octal(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+#ifdef DO_EXSTENSIVE_CHECKING
+       gchar ptr2;
+#endif
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+       {
+               g_ascii_strtoll(str, &ptr, 010);
+               return ptr - str;
+       }
+
+       for(ptr = str; g_ascii_isspace(*ptr); ptr++);
+
+       ptr = g_strstr_len(ptr, lng, part->delimiter);
+#ifdef DO_EXSTENSIVE_CHECKING
+       g_ascii_strtoll(str, &ptr2, 010);
+       if(ptr > ptr2)
+               return 0;
+#endif
+       
+       return ptr - str;
+}
+
+guint skip_string(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+               return 0;
+
+       for(ptr = str; g_ascii_isspace(*ptr); ptr++);
+
+       ptr = g_strstr_len(ptr, lng, part->delimiter);
+       
+       return ptr - str;
+}
+
+guint skip_unsigned(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+#ifdef DO_EXSTENSIVE_CHECKING
+       gchar ptr2;
+#endif
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+       {
+               g_ascii_strtoull(str, &ptr, 10);
+               return ptr - str;
+       }
+
+       ptr = g_strstr_len(str, lng, part->delimiter);
+#ifdef DO_EXSTENSIVE_CHECKING
+       g_ascii_strtoull(str, &ptr2, 10);
+       if(ptr > ptr2)
+               return 0;
+#endif
+       
+       return ptr - str;
+}
+
+guint skip_hexadecimal(gchar *str, guint lng, parse_part *part)
+{
+       gchar ptr;
+#ifdef DO_EXSTENSIVE_CHECKING
+       gchar ptr2;
+#endif
+
+       if(!lng)
+               return 0;
+
+       if(!part->delimiter[0])
+       {
+               g_ascii_strtoll(str, &ptr, 0x10);
+               return ptr - str;
+       }
+
+       ptr = g_strstr_len(str, lng, part->delimiter);
+#ifdef DO_EXSTENSIVE_CHECKING
+       g_ascii_strtoll(str, &ptr2, 0x10);
+       if(ptr > ptr2)
+               return 0;
+#endif
+       
+       return ptr - str;
+}
+/*}}}*/
+
+/*{{{ parse functions*/
+guint parse_byte(gchar *str, guint lng, parse_part *part)
+{
+       if(lng < 1)
+               return 0;
+       
+       *part->
+
+       return 1;
+}
+/*}}}*/
+
+gchar* strdup_escaped(const gchar *str, guint lng)/*{{{*/
+{
+       guint i;
+       gchar *new_str;
+       gchar ch;
+       guint size = 0;
+
+       for(i = 0; i < lng; i++)
+       {
+               switch(str[i])
+               {
+                       case '%':
+                               i++;
+                       break;
+                       case '\\':
+                               i++;
+                               switch(str[i])
+                               {
+                                       case 'x':
+                                               if(g_ascii_isxdigit(str[i+1]))
+                                               {
+                                                       i++;
+                                                       
if(g_ascii_isxdigit(str[i+1]))
+                                                       {
+                                                               i++;
+                                                       }
+                                               }
+                                       break;
+                                       default:
+                                               ch = str[i+1];
+                                               if(ch>='0' && ch < '8')
+                                               {
+                                                       i++;
+                                                       ch = str[i+1];
+                                                       if(ch>='0' && ch < '8')
+                                                       {
+                                                               ch = str[i];
+                                                               i++;
+                                                               if(ch < '4')
+                                                               {
+                                                                       ch = 
str[i+1];
+                                                                       
if(str[i+1]>='0' && str[i+1] < '8')
+                                                                       {
+                                                                               
i++;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       break;
+                               }
+                       break;
+               }
+               size++;
+       }
+
+       new_str = g_new(gchar, size+1)
+       new_str[size] = '\0';
+
+       size = 0;
+       for(i = 0; i < lng; i++)
+       {
+               switch(ch = str[i])
+               {
+                       case '%':
+                               i++;
+                               ch = str[i];
+                       break;
+                       case '\\':
+                               i++;
+                               switch(ch = str[i])
+                               {
+                                       case 'a':
+                                               ch = '\a';
+                                       break;
+                                       case 'b':
+                                               ch = '\b';
+                                       break;
+                                       case 'f':
+                                               ch = '\f';
+                                       break;
+                                       case 'n':
+                                               ch = '\n';
+                                       break;
+                                       case 'r':
+                                               ch = '\r';
+                                       break;
+                                       case 't':
+                                               ch = '\t';
+                                       break;
+                                       case 'v':
+                                               ch = '\v';
+                                       break;
+                                       case 'x':
+                                               if(g_ascii_isxdigit(str[i+1]))
+                                               {
+                                                       i++;
+                                                       ch = 
g_ascii_xdigit_value(str[i]);
+                                                       
if(g_ascii_isxdigit(str[i+1]))
+                                                       {
+                                                               i++;
+                                                               ch = (ch*0x10) 
+ g_ascii_xdigit_value(str[i]);
+                                                       }
+                                               }
+                                       break;
+                                       default:
+                                               if(str[i+1]>='0' && str[i+1] < 
'8')
+                                               {
+                                                       i++;
+                                                       ch = str[i]-'0';
+                                                       if(str[i+1]>='0' && 
str[i+1] < '8')
+                                                       {
+                                                               i++;
+                                                               if((ch = 
(ch*010) + (str[i]-'0')) < 040)
+                                                               {
+                                                                       
if(str[i+1]>='0' && str[i+1] < '8')
+                                                                       {
+                                                                               
i++;
+                                                                               
ch = (ch*010) + (str[i]-'0');
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       break;
+                               }
+                       break;
+               }
+               new_str[size++] = ch;
+       }
+
+       return new_str;
+}/*}}}*/
+
+build_parser(LSQArchive *archive, const gchar *parse_string)
+{
+       const gchar *ptr;
+       const gchar *cur;
+       const gchar *pos;
+       gchar ch;
+       enum {
+               SIZE_NORMAL = FALSE,
+               SIZE_SHORT,
+               SIZE_LONG,
+               SIZE_LONGLONG
+       } size_flag;
+       gboolean skip_flag;
+       guint width_flag;
+       guint index_flag;
+
+       parse_part *part = g_new0(parse_part, 1);
+       GSList *parts = g_slist_prepend(NULL, part);
+       guint part_count = 0;
+
+       cur = ptr = parse_string;
+
+       while((ch = *ptr++))
+       {
+               if(ch == '\\' && *ptr == 'n')
+               {
+                       part->delimiter = strdup_escaped(cur, ptr-cur);
+                       part = g_new0(parse_part, 1);
+                       parts = g_slist_prepend(parts, part);
+                       cur = ptr++;
+               }
+               if(ch == '%')
+               {
+                       skip_flag = FALSE;
+                       size_flag = SIZE_NORMAL;
+                       width_flag = 0;
+                       index = part_count;
+
+                       ch = *ptr++;
+
+                       if(ch == '%')
+                               continue;
+
+                       part->delimiter = strdup_escaped(cur, ptr-cur-1);
+
+                       /*{{{ check differend index %.$*/
+                       if(g_ascii_isdigit(ch))
+                       {
+                               index_flag = strtoul(ptr-1, &pos, 10);
+                               if(*pos == '$')
+                               {
+                                       ptr = pos+1;
+                                       index = index_flag-1;
+                                       ch = *ptr;
+                               }
+                       }
+                       /*}}}*/
+
+                       /*{{{ check skip flag %*.*/
+                       if(ch == '*')
+                       {
+                               skip_flag = TRUE;
+                               ch = *ptr++;
+                       }
+                       /*}}}*/
+
+                       /*{{{ check max characters %.*/
+                       //ignored for now
+                       if(g_ascii_isdigit(ch))
+                       {
+                               width_flag = strtoul(ptr-1, &ptr, 10);
+                               cp = *ptr;
+                       }
+                       /*}}}*/
+
+                       /*{{{ check size flag %[hlL].*/
+                       switch(ch)
+                       {
+                               case 'h':
+                                       size_flag = SIZE_SHORT;
+                                       ch = *ptr++;
+                               break;
+                               case 'l':
+                                       size_flag = SIZE_LONG;
+                                       ch = *ptr++;
+                                       if(ch != 'l')
+                                               break;
+                               case 'L':
+                                       size_flag = SIZE_LONGLONG;
+                                       ch = *ptr++;
+                               break;
+                       }
+                       /*}}}*/
+
+                       switch(ch)
+                       {
+                               /*{{{ byte %b*/
+                               case 'b':
+                                       if(width_flag)
+                                               return;
+                                       part = g_new0(parse_part, 1);
+                                       if(skip_flag)
+                                       {
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= skip_byte;
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= skip_word;
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= skip_dword;
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= skip_qword;
+                                                       break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_byte;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= parse_word;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= parse_dword;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_ULONG);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_qword;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT64);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ character %c*/
+                               case 'c':
+                                       if(size_flag || width_flag)
+                                               return;
+                                       part = g_new0(parse_part, 1);
+                                       if(skip_flag)
+                                       {
+                                               part->function = skip_char;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               part->function = parse_char;
+                                               
lsq_archive_set_property_type(archive, index, G_TYPE_CHAR);
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ decimal %d*/
+                               case 'd':
+                               //case 'i':
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = skip_decimal;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_decimal;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_INT);
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= parse_decimal16;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_INT);
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= parse_decimal32;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_LONG);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_decimal64;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_INT64);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ floating point %d*/
+                               case 'f':
+                                       if(size_flag && size_flag != 
SIZE_LONGLONG)
+                                               return;
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = 
skip_floatingpoint;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_floatingpoint;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_FLOAT);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_double;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_DOUBLE);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ octal %o*/
+                               case 'o':
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = skip_octal;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_octal;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= parse_octal16;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= parse_octal32;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_ULONG);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_octal64;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT64);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ string %s*/
+                               case 's':
+                                       if(size_flag)
+                                               return;
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = skip_string;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               part->function = parse_string;
+                                               
lsq_archive_set_property_type(archive, index, G_TYPE_STRING);
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ unsigned decimal %u*/
+                               case 'u':
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = skip_unsigned;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_unsigned;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= parse_unsigned16;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= parse_unsigned32;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_ULONG);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_unsigned64;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT64);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ hexadecimal %x %X*/
+                               case 'x':
+                               case 'X':
+                                       part = g_new0(parse_part, 1);
+                                       part->width = width_flag;
+                                       if(skip_flag)
+                                       {
+                                               part->function = 
skip_hexadecimal;
+                                       }
+                                       else
+                                       {
+                                               part_count++;
+                                               part->index = index;
+                                               switch(size_flag)
+                                               {
+                                                       case SIZE_NORMAL:
+                                                               part->function 
= parse_hexadecimal;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_SHORT:
+                                                               part->function 
= parse_hexadecimal16;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT);
+                                                       break;
+                                                       case SIZE_LONG:
+                                                               part->function 
= parse_hexadecimal32;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_ULONG);
+                                                       break;
+                                                       case SIZE_LONGLONG:
+                                                               part->function 
= parse_hexadecimal64;
+                                                               
lsq_archive_set_property_type(archive, index, G_TYPE_UINT64);
+                                                       break;
+                                               }
+                                       }
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               /*{{{ filename %F*/
+                               case 'F':
+                                       if(skip_flag || size_flag || width_flag)
+                                               return;
+                                       part = g_new0(parse_part, 1);
+                                       part->function = parse_filename;
+                                       g_slist_prepend(parts, part);
+                               break;
+                               /*}}}*/
+                               default:
+                                       return;
+                       }
+                       cur = ptr;
+               }
+       }
+
+       lsq_archive archive
+}
+
+parse()
+{
+
+}
+

Added: squeeze/trunk/libsqueeze/scanf-parser.h
===================================================================
--- squeeze/trunk/libsqueeze/scanf-parser.h                             (rev 0)
+++ squeeze/trunk/libsqueeze/scanf-parser.h     2007-10-15 18:30:14 UTC (rev 
26132)
@@ -0,0 +1,26 @@
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License
+ *  along with this program; if not, write to the Free Software 
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 
+ */
+
+#ifndef __LIBSQUEEZE_SCANF_PARSER_H__
+#define __LIBSQUEEZE_SCANF_PARSER_H__ 
+
+G_BEGIN_DECLS
+
+
+
+G_END_DECLS
+
+#endif /* __LIBSQUEEZE_SCANF_PARSER_H__ */
+

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to