mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
*** empty log message ***
This commit is contained in:
164
sfile.c
164
sfile.c
@ -1,23 +1,5 @@
|
|||||||
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
/* Lac - Library for asynchronous communication
|
|
||||||
* Copyright (C) 2004 Søren Sandmann (sandmann@daimi.au.dk)
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -463,8 +445,7 @@ state_transition_end (const State *state, const char *element,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const State *
|
static const State *
|
||||||
state_transition_text (const State *state, const char *text,
|
state_transition_text (const State *state, TransitionType *type, GError **err)
|
||||||
TransitionType *type, GError **err)
|
|
||||||
{
|
{
|
||||||
GList *list;
|
GList *list;
|
||||||
|
|
||||||
@ -484,7 +465,7 @@ state_transition_text (const State *state, const char *text,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_invalid_content_error (err, "Unexpected text data unexpected (%s)", text);
|
set_invalid_content_error (err, "Unexpected text data");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,8 +477,7 @@ struct BuildContext
|
|||||||
{
|
{
|
||||||
const State *state;
|
const State *state;
|
||||||
|
|
||||||
Action *actions;
|
GArray *actions;
|
||||||
int n_actions;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParseNode
|
struct ParseNode
|
||||||
@ -679,6 +659,7 @@ handle_begin_element (GMarkupParseContext *parse_context,
|
|||||||
build->state = state_transition_begin (build->state, element_name, &action.type, err);
|
build->state = state_transition_begin (build->state, element_name, &action.type, err);
|
||||||
|
|
||||||
/* FIXME create action/add to list */
|
/* FIXME create action/add to list */
|
||||||
|
/* FIXME figure out how to best count the number of items if action.type is a list */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -705,14 +686,29 @@ handle_text (GMarkupParseContext *context,
|
|||||||
BuildContext *build = user_data;
|
BuildContext *build = user_data;
|
||||||
Action action;
|
Action action;
|
||||||
|
|
||||||
build->state = state_transition_text (build->state, text, &action.type, err);
|
build->state = state_transition_text (build->state, &action.type, err);
|
||||||
|
|
||||||
/* FIXME create acxtion/add to list */
|
/* FIXME create acxtion/add to list */
|
||||||
|
/* FIXME check that the text makes sense according to action.type */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_actions (Action *actions, int n_actions)
|
free_actions (Action *actions, int n_actions)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < n_actions; ++i)
|
||||||
|
{
|
||||||
|
Action *action = &(actions[i]);
|
||||||
|
|
||||||
|
if (action->name)
|
||||||
|
g_free (action->name);
|
||||||
|
|
||||||
|
if (action->type == STRING)
|
||||||
|
g_free (action->u.string.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Action *
|
static Action *
|
||||||
@ -735,17 +731,18 @@ build_actions (const char *contents, SFormat *format, int *n_actions, GError **e
|
|||||||
{
|
{
|
||||||
set_invalid_content_error (err, "Unexpected end of file\n");
|
set_invalid_content_error (err, "Unexpected end of file\n");
|
||||||
|
|
||||||
free_actions (build.actions, build.n_actions);
|
free_actions ((Action *)build.actions->data, build.actions->len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_markup_parse_context_parse (parse_context, contents, -1, err))
|
if (!g_markup_parse_context_parse (parse_context, contents, -1, err))
|
||||||
{
|
{
|
||||||
free_actions (build.actions, build.n_actions);
|
free_actions ((Action *)build.actions->data, build.actions->len);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return build.actions;
|
*n_actions = build.actions->len;
|
||||||
|
return (Action *)g_array_free (build.actions, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SFileInput *
|
SFileInput *
|
||||||
@ -775,3 +772,116 @@ sfile_load (const char *filename,
|
|||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Writing */
|
||||||
|
|
||||||
|
struct SFileOutput
|
||||||
|
{
|
||||||
|
SFormat *format;
|
||||||
|
const State *state;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SFileOutput *
|
||||||
|
sfile_output_mew (SFormat *format)
|
||||||
|
{
|
||||||
|
SFileOutput *output = g_new (SFileOutput, 1);
|
||||||
|
|
||||||
|
output->format = format;
|
||||||
|
output->state = sformat_get_start_state (format);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_begin_add_record (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
|
gpointer id)
|
||||||
|
{
|
||||||
|
TransitionType type;
|
||||||
|
|
||||||
|
file->state = state_transition_begin (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && type == BEGIN_RECORD);
|
||||||
|
|
||||||
|
/* FIXME: add action including id */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_begin_add_list (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
|
gpointer id)
|
||||||
|
{
|
||||||
|
TransitionType type;
|
||||||
|
|
||||||
|
file->state = state_transition_begin (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && type == BEGIN_LIST);
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_end_add (SFileOutput *file,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
TransitionType type;
|
||||||
|
|
||||||
|
file->state = state_transition_end (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && (type == END_RECORD || type == END_LIST));
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_add_string (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
|
const char *string)
|
||||||
|
{
|
||||||
|
TransitionType type;
|
||||||
|
|
||||||
|
file->state = state_transition_begin (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && type == BEGIN_STRING);
|
||||||
|
|
||||||
|
file->state = state_transition_text (file->state, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && type == STRING);
|
||||||
|
|
||||||
|
file->state = state_transition_end (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
g_return_if_fail (file->state && type == END_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_add_integer (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
|
int integer)
|
||||||
|
{
|
||||||
|
TransitionType type;
|
||||||
|
|
||||||
|
/* FIXME: check intermediate states */
|
||||||
|
|
||||||
|
file->state = state_transition_begin (file->state, name, &type, NULL);
|
||||||
|
|
||||||
|
file->state = state_transition_text (file->state, &type, NULL);
|
||||||
|
|
||||||
|
file->state = state_transition_end (file->state, name, &type, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sfile_add_pointer (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
|
gpointer pointer)
|
||||||
|
{
|
||||||
|
/* FIMXE */
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
sfile_save (SFileOutput *sfile,
|
||||||
|
const char *filename,
|
||||||
|
GError **err)
|
||||||
|
{
|
||||||
|
return FALSE; /* FIXME */
|
||||||
|
}
|
||||||
|
|||||||
14
sfile.h
14
sfile.h
@ -44,17 +44,29 @@ void sfile_loader_free (SFileLoader *loader);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* - Writing - */
|
/* - Writing - */
|
||||||
|
|
||||||
|
/* FIXME: see if we can't get rid of the names. It should be
|
||||||
|
* possible to pass NULL to state_transition_check() and
|
||||||
|
* have it interprete that as "whatever"
|
||||||
|
*/
|
||||||
|
|
||||||
SFileOutput * sfile_output_mew (SFormat *format);
|
SFileOutput * sfile_output_mew (SFormat *format);
|
||||||
void sfile_begin_add_record (SFileOutput *file,
|
void sfile_begin_add_record (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
gpointer id);
|
gpointer id);
|
||||||
void sfile_begin_add_list (SFileOutput *file,
|
void sfile_begin_add_list (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
gpointer id);
|
gpointer id);
|
||||||
void sfile_end_add (SFileOutput *file);
|
void sfile_end_add (SFileOutput *file,
|
||||||
|
const char *name);
|
||||||
void sfile_add_string (SFileOutput *file,
|
void sfile_add_string (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
const char *string);
|
const char *string);
|
||||||
void sfile_add_integer (SFileOutput *file,
|
void sfile_add_integer (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
int integer);
|
int integer);
|
||||||
void sfile_add_pointer (SFileOutput *file,
|
void sfile_add_pointer (SFileOutput *file,
|
||||||
|
const char *name,
|
||||||
gpointer pointer);
|
gpointer pointer);
|
||||||
gboolean sfile_save (SFileOutput *sfile,
|
gboolean sfile_save (SFileOutput *sfile,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
|
|||||||
Reference in New Issue
Block a user