コード例 #1
0
ファイル: get.c プロジェクト: svn2github/irssi
CONFIG_NODE *config_node_section_index(CONFIG_NODE *parent, const char *key,
				       int index, int new_type)
{
	CONFIG_NODE *node;
        int nindex;

	g_return_val_if_fail(parent != NULL, NULL);
	g_return_val_if_fail(is_node_list(parent), NULL);

	node = key == NULL ? NULL : config_node_find(parent, key);
	if (node != NULL) {
		g_return_val_if_fail(new_type == -1 || new_type == node->type, NULL);
		nindex = g_slist_index(parent->value, node);
		if (index >= 0 && nindex != index &&
		    nindex <= g_slist_length(parent->value)) {
			/* move it to wanted position */
			parent->value = g_slist_remove(parent->value, node);
			parent->value = g_slist_insert(parent->value, node, index);
		}
		return node;
	}

	if (new_type == -1)
		return NULL;

	node = g_new0(CONFIG_NODE, 1);
	parent->value = index < 0 ? g_slist_append(parent->value, node) :
		g_slist_insert(parent->value, node, index);

	node->type = new_type;
	node->key = key == NULL ? NULL : g_strdup(key);

	return node;
}
コード例 #2
0
ファイル: clist.c プロジェクト: CraneMTG/ScrapWars-2
gint gtk_clist_insert(GtkCList *clist, gint row, gchar *text[])
{
  GtkWidget *widget = GTK_WIDGET(clist);
  HWND hWnd;
  GtkCListRow *new_row;
  gint i;

  if (row < 0)
    row = clist->rows;

  new_row = g_new0(GtkCListRow, 1);
  new_row->text = g_new0(gchar *, clist->cols);

  for (i = 0; i < clist->cols; i++) {
    new_row->text[i] = g_strdup(text[i]);
  }
  gtk_clist_update_widths(clist, new_row->text);
  gtk_clist_do_auto_resize(clist);
  clist->rowdata = g_slist_insert(clist->rowdata, (gpointer)new_row, row);
  clist->rows = g_slist_length(clist->rowdata);

  if (GTK_WIDGET_REALIZED(widget)) {
    hWnd = widget->hWnd;
    SendMessage(hWnd, LB_INSERTSTRING, (WPARAM)row, (LPARAM)NULL);
  }

  return row;
}
コード例 #3
0
ファイル: combo-flags.c プロジェクト: GNOME/anjuta
static void
cg_combo_flags_cell_layout_reorder (GtkCellLayout *layout,
                                    GtkCellRenderer *cell,
                                    gint position)
{
	CgComboFlags *combo;
	CgComboFlagsPrivate *priv;
	CgComboFlagsCellInfo *info;
	GSList *link;

	combo = CG_COMBO_FLAGS (layout);
	priv = CG_COMBO_FLAGS_PRIVATE (combo);

	info = cg_combo_flags_get_cell_info (combo, cell);
	g_return_if_fail (info != NULL);

	link = g_slist_find (priv->cells, info);
	g_return_if_fail (link != NULL);

	priv->cells = g_slist_remove_link (priv->cells, link);
	priv->cells = g_slist_insert (priv->cells, info, position);

	if (priv->column != NULL)
		gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->column), cell, position);

	gtk_widget_queue_draw (GTK_WIDGET (combo));
}
コード例 #4
0
ファイル: tinto.c プロジェクト: roomcays/tinto-panel
void event_button_motion_notify(XEvent* e) {
    Panel* panel = get_panel(e->xany.window);
    if (!panel || !task_drag) return;

    // Find the taskbar on the event's location
    point_T point = {e->xbutton.x, e->xbutton.y};
    Taskbar* event_taskbar = click_taskbar(panel, point);
    if (event_taskbar == NULL) return;

    // Find the task on the event's location

    Task* event_task = click_task(panel, point);

    // If the event takes place on the same taskbar as the task being dragged
    if (event_taskbar == task_drag->area.parent) {
        // Swap the task_drag with the task on the event's location (if they differ)
        if (event_task && event_task != task_drag) {
            GSList* drag_iter = g_slist_find(event_taskbar->area.list, task_drag);
            GSList* task_iter = g_slist_find(event_taskbar->area.list, event_task);
            if (drag_iter && task_iter) {
                gpointer temp = task_iter->data;
                task_iter->data = drag_iter->data;
                drag_iter->data = temp;
                event_taskbar->area.resize = 1;
                panel_refresh = 1;
                task_dragged = 1;
            }
        }
    } else {  // The event is on another taskbar than the task being dragged
        if (task_drag->desktop == ALLDESKTOP || panel_mode != MULTI_DESKTOP) return;

        Taskbar* drag_taskbar = (Taskbar*)task_drag->area.parent;
        drag_taskbar->area.list =
            g_slist_remove(drag_taskbar->area.list, task_drag);

        if (event_taskbar->area.posx > drag_taskbar->area.posx ||
                event_taskbar->area.posy > drag_taskbar->area.posy) {
            int i = (taskbarname_enabled) ? 1 : 0;
            event_taskbar->area.list =
                g_slist_insert(event_taskbar->area.list, task_drag, i);
        } else
            event_taskbar->area.list =
                g_slist_append(event_taskbar->area.list, task_drag);

        // Move task to other desktop (but avoid the 'Window desktop changed' code
        // in 'event_property_notify')
        task_drag->area.parent = event_taskbar;
        task_drag->desktop = event_taskbar->desktop;

        windows_set_desktop(task_drag->win, event_taskbar->desktop);

        event_taskbar->area.resize = 1;
        drag_taskbar->area.resize = 1;
        task_dragged = 1;
        panel_refresh = 1;
    }
}
コード例 #5
0
ファイル: feed.c プロジェクト: ctubio/claws
gboolean feed_insert_item(Feed *feed, FeedItem *item, gint pos)
{
	g_return_val_if_fail(feed != NULL, FALSE);
	g_return_val_if_fail(item != NULL, FALSE);
	g_return_val_if_fail(pos < 0, FALSE);

	feed->items = g_slist_insert(feed->items, item, pos);
	return TRUE;
}
コード例 #6
0
ファイル: tape.c プロジェクト: RoestVrijStaal/xpectrum
libspectrum_error
libspectrum_tape_insert_block( libspectrum_tape *tape,
			       libspectrum_tape_block *block,
			       size_t position )
{
  tape->blocks = g_slist_insert( tape->blocks, block, position );

  return LIBSPECTRUM_ERROR_NONE;
}
コード例 #7
0
ファイル: fl_local.c プロジェクト: Tilka/ncdc
// Add to the hash index
static void fl_hashindex_insert(fl_list_t *fl) {
  GSList *cur = g_hash_table_lookup(fl_hash_index, fl->tth);
  if(cur) {
    g_return_if_fail(cur == g_slist_insert(cur, fl, 1)); // insert item without modifying the pointer
  } else {
    cur = g_slist_prepend(cur, fl);
    g_hash_table_insert(fl_hash_index, fl->tth, cur);
    fl_local_list_size += fl->size;
  }
  fl_local_list_length = g_hash_table_size(fl_hash_index);
}
コード例 #8
0
void
libspectrum_rzx_insert_snap( libspectrum_rzx *rzx, libspectrum_snap *snap,
			     int where )
{
  rzx_block_t *block;

  block_alloc( &block, LIBSPECTRUM_RZX_SNAPSHOT_BLOCK );
  block->types.snap.snap = snap;
  block->types.snap.automatic = 0;

  rzx->blocks = g_slist_insert( rzx->blocks, block, where );
}
コード例 #9
0
ファイル: node.c プロジェクト: lwindolf/liferea
void
node_set_parent (nodePtr node, nodePtr parent, gint position)
{
	g_assert (NULL != parent);

	parent->children = g_slist_insert (parent->children, node, position);
	node->parent = parent;

	/* new nodes may be provided by another node source, if
	   not they are handled by the parents node source */
	if (!node->source)
		node->source = parent->source;
}
コード例 #10
0
ファイル: sipmsg.c プロジェクト: wosigh/messaging-plugins
/**
 * Adds header to current message headers at specified position
 */
void sipmsg_add_header_now_pos(struct sipmsg *msg, const gchar *name, const gchar *value, int pos) {
	struct sipnameval *element = g_new0(struct sipnameval,1);

	/* SANITY CHECK: the calling code must be fixed if this happens! */
	if (!value) {
		SIPE_DEBUG_ERROR("sipmsg_add_header_now_pos: NULL value for %s (%d)",
				 name, pos);
		value = "";
	}

	element->name = g_strdup(name);
	element->value = g_strdup(value);
	msg->headers = g_slist_insert(msg->headers, element,pos);
}
コード例 #11
0
ファイル: chart.c プロジェクト: dylex/stripchart
ChartDatum *
chart_parameter_add(Chart *chart,
                    gdouble (*user_func)(), gpointer user_data,
                    const gchar *color_names, ChartAdjustment *adj, int pageno,
                    gdouble bot_min, gdouble bot_max, gdouble top_min, gdouble top_max)
{
    ChartDatum *datum = g_malloc(sizeof(*datum));

    datum->chart = chart;
    datum->user_func = user_func;
    datum->user_data = user_data;
    datum->rescale = FALSE;
    datum->active = TRUE;
    datum->idle = datum->newest = datum->history_count = 0;

    datum->top_max = top_max;
    datum->bot_max = bot_max;
    datum->top_min = top_min;
    datum->bot_min = bot_min;

    if (adj == NULL)
    {
        adj = g_malloc(sizeof(*adj));
        adj->upper = datum->top_min;
        adj->lower = datum->bot_max;
    }
    datum->adj = adj;

#ifdef DEBUG
    printf("Initial bounds %d: %lf - %lf | %lf - %lf (%f...%f)\n", pageno,
           datum->bot_min, datum->bot_max, datum->top_min, datum->top_max, datum->adj->lower, datum->adj->upper);
#endif

    datum->colors = 0;
    datum->color_names = g_strdup(color_names);
    datum->gdk_gc = NULL;
    datum->gdk_color = NULL;
    chart->param = g_slist_insert(chart->param, datum, pageno);

    datum->plot_style = chart->default_plot_style;
    datum->scale_style = chart->default_scale_style;

    datum->skip = 2;
    datum->history_size = chart->default_history_size;
    datum->history = g_malloc(datum->history_size * sizeof(*datum->history));

    return datum;
}
コード例 #12
0
ファイル: icontainer.c プロジェクト: jcupitt/nip2
/* pos == 0 ... move to start
 * pos == -1 ... move to end
 * pos == n ... move before sibling at position n
 */
void
icontainer_child_move( iContainer *child, int pos )
{
	iContainer *parent = child->parent;

	parent->children = g_slist_remove( parent->children, child );

        if( pos >= 0 )
                parent->children = g_slist_insert( parent->children,
                        child, pos );
        else
                parent->children = g_slist_append( parent->children, child );

        icontainer_pos_renumber( parent );
	iobject_changed( IOBJECT( child ) );
}
コード例 #13
0
ファイル: servlistgui.c プロジェクト: TingPing/conspire
static void
servlist_move_network (ircnet *net, int delta)
{
	int pos;

	pos = g_slist_index (network_list, net);
	if (pos >= 0)
	{
		pos += delta;
		if (pos >= 0)
		{
			network_list = g_slist_remove (network_list, net);
			network_list = g_slist_insert (network_list, net, pos);
			servlist_networks_populate (networks_tree, network_list);
		}
	}
}
コード例 #14
0
ファイル: servlistgui.c プロジェクト: TingPing/conspire
static void
servlist_move_server (ircserver *serv, int delta)
{
	int pos;

	pos = g_slist_index (selected_net->servlist, serv);
	if (pos >= 0)
	{
		pos += delta;
		if (pos >= 0)
		{
			selected_net->servlist = g_slist_remove (selected_net->servlist, serv);
			selected_net->servlist = g_slist_insert (selected_net->servlist, serv, pos);
			servlist_servers_populate (selected_net, edit_tree);
		}
	}
}
コード例 #15
0
ファイル: mx-combo-box.c プロジェクト: ebassi/mx
/**
 * mx_combo_box_insert_text:
 * @box: A #MxComboBox
 * @position: zero indexed position to insert the item at
 * @text: name of the item
 *
 * Insert an item into the combo box list.
 *
 */
void
mx_combo_box_insert_text (MxComboBox  *box,
                          gint         position,
                          const gchar *text)
{
  MxAction *action;

  g_return_if_fail (MX_IS_COMBO_BOX (box));

  action = mx_action_new ();
  mx_action_set_display_name (action, text);

  box->priv->actions = g_slist_insert (box->priv->actions,
                                       g_object_ref_sink (action),
                                       position);
  mx_combo_box_update_menu (box);
}
コード例 #16
0
static void
xkb_layouts_dnd_data_received (GtkWidget * widget, GdkDragContext * dc,
			       gint x, gint y,
			       GtkSelectionData * selection_data,
			       guint info, guint t, GtkBuilder * dialog)
{
	gint sidx = find_selected_layout_idx (dialog);
	GtkWidget *tree_view = WID ("xkb_layouts_selected");
	GtkTreePath *path = NULL;
	GtkTreeViewDropPosition pos;
	gint didx;
	gchar *id;
	GSList *layouts_list;
	GSList *node2Remove;

	if (sidx == -1)
		return;

	layouts_list = xkb_layouts_get_selected_list ();
	node2Remove = g_slist_nth (layouts_list, sidx);

	id = (gchar *) node2Remove->data;
	layouts_list = g_slist_delete_link (layouts_list, node2Remove);

	if (!gtk_tree_view_get_dest_row_at_pos
	    (GTK_TREE_VIEW (tree_view), x, y, &path, &pos)) {
		/* Move to the very end */
		layouts_list =
		    g_slist_append (layouts_list, g_strdup (id));
		xkb_layouts_set_selected_list (layouts_list);
	} else if (path != NULL) {
		gint *indices = gtk_tree_path_get_indices (path);
		didx = indices[0];
		gtk_tree_path_free (path);
		/* Move to the new position */
		if (sidx != didx) {
			layouts_list =
			    g_slist_insert (layouts_list, g_strdup (id),
					    didx);
			xkb_layouts_set_selected_list (layouts_list);
		}
	}
	g_free (id);
	clear_xkb_elements_list (layouts_list);
}
コード例 #17
0
ファイル: icontainer.c プロジェクト: jcupitt/nip2
static void
icontainer_link( iContainer *parent, iContainer *child, int pos )
{
        if( pos >= 0 ) 
                parent->children = g_slist_insert( parent->children,
                        child, pos );
        else
                parent->children = g_slist_append( parent->children, child );
        child->parent = parent;
        child->pos = pos;
	if( parent->child_hash ) {
		g_assert( !g_hash_table_lookup( parent->child_hash, 
			IOBJECT( child )->name ) );

		g_hash_table_insert( parent->child_hash, 
			IOBJECT( child )->name, child );
	}
}
コード例 #18
0
ファイル: flt-player.c プロジェクト: svn2github/xqf
static void pattern_clist_row_move_callback (GtkWidget *widget, 
                                                       int source, int dest, gpointer data) {
  GtkCList *clist = GTK_CLIST (widget);
  GSList *link;
  struct player_pattern *pp;

  debug(5,"pattern_clist_row_move_callback(widget=%d,source=%d,dest=%d)",widget,source,dest);

  if (source < 0 || dest < 0 || source == dest || 
                                 source > clist->rows || dest > clist->rows) {
    return;
  }

  link = g_slist_nth (curplrs, source);
  pp = (struct player_pattern *) link->data;
  curplrs = g_slist_remove_link (curplrs, link);
  curplrs = g_slist_insert (curplrs, pp, dest);

  current_row = dest;
}
コード例 #19
0
ファイル: node.c プロジェクト: lwindolf/liferea
void
node_reparent (nodePtr node, nodePtr new_parent)
{
	nodePtr old_parent;

	g_assert (NULL != new_parent);
	g_assert (NULL != node);

	debug2 (DEBUG_GUI, "Reparenting node '%s' to a parent '%s'", node_get_title(node), node_get_title(new_parent));

	old_parent = node->parent;
	if (NULL != old_parent)
		old_parent->children = g_slist_remove (old_parent->children, node);

	new_parent->children = g_slist_insert (new_parent->children, node, -1);
	node->parent = new_parent;

	feed_list_view_remove_node (node);
	feed_list_view_add_node (node);
}
コード例 #20
0
ファイル: server-idle.c プロジェクト: svn2github/irssi
/* Add new idle command to specified position of queue */
int server_idle_insert(IRC_SERVER_REC *server, const char *cmd, const char *arg, int tag, int last, ...)
{
	va_list args;
	SERVER_IDLE_REC *rec;
	int pos;

	g_return_val_if_fail(server != NULL, -1);

	va_start(args, last);

	/* find the position of tag in idle list */
	rec = server_idle_find_rec(server, tag);
	pos = g_slist_index(server->idles, rec);

	rec = server_idle_create(cmd, arg, last, args);
        server->idles = pos < 0 ?
		g_slist_append(server->idles, rec) :
		g_slist_insert(server->idles, rec, pos);
	va_end(args);
	return rec->tag;
}
コード例 #21
0
ファイル: dcc-queue.c プロジェクト: Brijen/MacIrssi
void dcc_queue_add(int queue, int mode, const char *nick, const char *fname,
		   const char *servertag, CHAT_DCC_REC *chat, int passive)
{
	DCC_QUEUE_REC *rec;
	GSList **qlist;

	g_assert(queue >= 0 && queue < queuelist->len);

	rec = g_new0(DCC_QUEUE_REC, 1);
	rec->chat = chat;
	rec->servertag = g_strdup(servertag);
	rec->nick = g_strdup(nick);
	rec->file = g_strdup(fname);
	rec->passive = passive;

	qlist = (GSList **) &g_ptr_array_index(queuelist, queue);
	if (mode == DCC_QUEUE_PREPEND)
		*qlist = g_slist_insert(*qlist, rec, 1);
	else
		*qlist = g_slist_append(*qlist, rec);
}
コード例 #22
0
static void
move_down_selected_layout (GtkWidget * button, GtkBuilder * dialog)
{
	gint idx = find_selected_layout_idx (dialog);

	if (idx != -1) {
		GSList *layouts_list = xkb_layouts_get_selected_list ();
		GSList *node2Remove = g_slist_nth (layouts_list, idx);

		layouts_list =
		    g_slist_remove_link (layouts_list, node2Remove);
		layouts_list =
		    g_slist_insert (layouts_list, node2Remove->data,
				    idx + 1);
		g_slist_free_1 (node2Remove);

		idx2select = idx + 1;
		xkb_layouts_set_selected_list (layouts_list);
		clear_xkb_elements_list (layouts_list);
	}
}
コード例 #23
0
ファイル: logview-app.c プロジェクト: GNOME/gnome-system-log
/* adapted from sysklogd sources */
static GSList*
parse_syslog ()
{
  char cbuf[BUFSIZ];
  char *cline, *p;
  FILE *cf;
  GSList *logfiles = NULL;

  if ((cf = fopen ("/etc/syslog.conf", "r")) == NULL) {
    return NULL;
  }

  cline = cbuf;
  while (fgets (cline, sizeof (cbuf) - (cline - cbuf), cf) != NULL) {
    gchar **list;
    gint i;

    for (p = cline; g_ascii_isspace (*p); ++p);
    if (*p == '\0' || *p == '#' || *p == '\n')
      continue;

    list = g_strsplit_set (p, ", -\t()\n", 0);

    for (i = 0; list[i]; ++i) {
      if (*list[i] == '/' &&
          g_slist_find_custom (logfiles, list[i],
                               (GCompareFunc) g_ascii_strcasecmp) == NULL)
      {
        logfiles = g_slist_insert (logfiles,
                                   g_strdup (list[i]), 0);
      }
    }

    g_strfreev (list);
  }

  fclose (cf);

  return logfiles;
}
コード例 #24
0
guint files_not_saved_check(void) {
  /** This function is called by application exit to check is some files still unsaved and reference it at the same time. **/

  #ifdef DEBUG
    DEBUG_FUNC_MARK
  #endif


  gint number_of_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(gui->editor_notebook)) ;

  int counter = 0 ;

  int c ;

  for (c=0 ; c < number_of_pages ; c++) {

    GtkWidget *notebook_page        = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui->editor_notebook), c) ;
    GtkWidget *current_textview     = gtk_bin_get_child(GTK_BIN(notebook_page)) ;
    GtkTextBuffer *current_buffer   = gtk_text_view_get_buffer(GTK_TEXT_VIEW(current_textview)) ;

    if (gtk_text_buffer_get_modified(current_buffer)) {
      /** The editor content has not being saved **/

      struct Unsaved_File *unsaved_file = g_malloc(sizeof(struct Unsaved_File)) ;

      unsaved_file->filepath = g_strdup((char *) g_object_get_data(G_OBJECT(current_buffer), "filepath")) ;

      unsaved_file->page_number = c ;

      unsaved_files = g_slist_insert(unsaved_files, (gpointer) unsaved_file, -1 ) ;

      counter++ ;
    }

  }

  return counter ;

}
コード例 #25
0
/**
 * empathy_irc_network_set_server_position:
 * @network: an #EmpathyIrcNetwork
 * @server: the #EmpathyIrcServer to move
 * @pos: the position to move the server. If this is negative, or is larger than
 * the number of servers in the list, the server is moved to the end of the
 * list.
 *
 * Move an #EmpathyIrcServer in the servers list of the given
 * #EmpathyIrcNetwork.
 *
 */
void
empathy_irc_network_set_server_position (EmpathyIrcNetwork *self,
                                         EmpathyIrcServer *server,
                                         gint pos)
{
  EmpathyIrcNetworkPriv *priv;
  GSList *l;

  g_return_if_fail (EMPATHY_IS_IRC_NETWORK (self));
  g_return_if_fail (server != NULL && EMPATHY_IS_IRC_SERVER (server));

  priv = GET_PRIV (self);

  l = g_slist_find (priv->servers, server);
  if (l == NULL)
    return;

  priv->servers = g_slist_delete_link (priv->servers, l);
  priv->servers = g_slist_insert (priv->servers, server, pos);

  g_signal_emit (self, signals[MODIFIED], 0);
}
コード例 #26
0
ファイル: flt-player.c プロジェクト: svn2github/xqf
static void new_pattern_callback (GtkWidget *widget, gpointer data) {
  struct player_pattern *pp;
  int row;

  pp = player_pattern_new (NULL);

  if (current_row >= 0) {
    row = current_row;
    current_row++;
  }
  else {
    row = 0;
  }

  curplrs = g_slist_insert (curplrs, pp, row);
  pattern_clist_insert_row (pp, row);

  if (curplrs && curplrs->next)
    gtk_clist_select_row (GTK_CLIST (pattern_clist), row, 0);

  gtk_widget_grab_focus (pattern_entry);
}
コード例 #27
0
ファイル: connpoint_line.c プロジェクト: krattai/monoflow
static void
cpl_add_connectionpoint_at(ConnPointLine *cpl, int pos,ConnectionPoint *cp) 
{
  if (pos == 0) {
    /* special case handling so that the order of CPL groups in 
       the parent's CP list is preserved. */
    int fpos,i;
    ConnectionPoint *fcp;
    g_assert(cpl->connections);
    fpos = -1;
    fcp = (ConnectionPoint *)(cpl->connections->data);
    g_assert(fcp);
    for (i=0; i<cpl->parent->num_connections; i++) {
      if (cpl->parent->connections[i] == fcp) {
	fpos = i;
	break;
      }
    }
    g_assert(fpos >= 0);
    object_add_connectionpoint_at(cpl->parent,cp,fpos);
  }else {
    /* XXX : make this a little better ; try to insert at the correct
       position right away to eliminate cpl_reorder_connection */
    object_add_connectionpoint(cpl->parent,cp);
  }
  if (pos < 0) {
    cpl->connections = g_slist_append(cpl->connections,(gpointer)cp);
  }
  else {
    cpl->connections = g_slist_insert(cpl->connections,(gpointer)cp,pos);
  }
  cpl->num_connections++;

  /* we should call
     cpl_reorder_connections(cpl);
     before we leave the object !! However, this is delayed, for the case
     several CP's are added at once (initialisation). */
}
コード例 #28
0
ファイル: fvkbd-key.c プロジェクト: stringtang/pad-keyboard
static gboolean
key_actions_insert_sort_unique (GSList **lists_p, FvkbdKeyAction *action)
{
	gint i;
	gboolean ret = TRUE;
	FvkbdKeyAction *current = NULL;

	g_return_val_if_fail(lists_p != NULL, FALSE);
	
	for (i = 0; i < g_slist_length(*lists_p); i++) {
		current = (FvkbdKeyAction *)g_slist_nth_data(*lists_p, i);
		if (current->mode_id	> action->mode_id)
			break;

		if (current->mode_id	== action->mode_id) {
			ret = FALSE;
			goto done;
		}
	}

	*lists_p = g_slist_insert(*lists_p, action, i);
done:
	return ret;
}
コード例 #29
0
ファイル: rzx.c プロジェクト: CiaranG/ZXdroid
void
libspectrum_rzx_insert_snap( libspectrum_rzx *rzx, libspectrum_snap *snap,
			     int where )
{
  rzx->blocks = g_slist_insert( rzx->blocks, snap, where );
}
コード例 #30
0
/* insert_chunk function will recalculate the free_chunk_list, the data_size,
   the end_of_file, and the data_gathered as appropriate.
   It will also insert the data chunk that is coming in the right
   place of the file in memory.
   HINTS:
   file->data_gathered     contains the real data gathered independently
             from the file length
   file->file_length     contains the length of the file in memory, i.e.,
            the last offset captured. In most cases, the real
            file length would be different.
*/
static void
insert_chunk(active_file   *file, export_object_entry_t *entry, const smb_eo_t *eo_info)
{
gint       nfreechunks      = g_slist_length(file->free_chunk_list);
gint       i;
free_chunk *current_free_chunk;
free_chunk *new_free_chunk;
guint64     chunk_offset     = eo_info->smb_file_offset;
guint64     chunk_length     = eo_info->payload_len;
guint64     chunk_end_offset = chunk_offset + chunk_length-1;
/* Size of file in memory */
guint64     calculated_size  = chunk_offset + chunk_length;
gpointer    dest_memory_addr;

	/* Let's recalculate the file length and data gathered */
	if ((file->data_gathered == 0) && (nfreechunks == 0)) {
		/* If this is the first entry for this file, we first
		create an initial free chunk */
		new_free_chunk = (free_chunk *)g_malloc(sizeof(free_chunk));
		new_free_chunk->start_offset = 0;
		new_free_chunk->end_offset = MAX(file->file_length, chunk_end_offset+1) - 1;
		file->free_chunk_list = NULL;
		file->free_chunk_list = g_slist_append(file->free_chunk_list, new_free_chunk);
		nfreechunks += 1;
	} else {
		if (chunk_end_offset > file->file_length-1) {
			new_free_chunk = (free_chunk *)g_malloc(sizeof(free_chunk));
			new_free_chunk->start_offset = file->file_length;
			new_free_chunk->end_offset = chunk_end_offset;
			file->free_chunk_list = g_slist_append(file->free_chunk_list, new_free_chunk);
			nfreechunks += 1;
		}
	}
	file->file_length = MAX(file->file_length, chunk_end_offset+1);

	/* Recalculate each free chunk according with the incoming data chunk */
	for (i=0; i<nfreechunks; i++) {
		current_free_chunk = (free_chunk *)g_slist_nth_data(file->free_chunk_list, i);
		/* 1. data chunk before the free chunk? */
		/* -> free chunk is not altered and no new data gathered */
		if (chunk_end_offset<current_free_chunk->start_offset) {
			continue;
		}
		/* 2. data chunk overlaps the first part of free_chunk */
		/* -> free chunk shrinks from the beginning */
		if (chunk_offset<=current_free_chunk->start_offset && chunk_end_offset>=current_free_chunk->start_offset && chunk_end_offset<current_free_chunk->end_offset) {
			file->data_gathered += chunk_end_offset-current_free_chunk->start_offset+1;
			current_free_chunk->start_offset=chunk_end_offset+1;
			continue;
		}
		/* 3. data chunk overlaps completely the free chunk */
		/* -> free chunk is removed */
		if (chunk_offset<=current_free_chunk->start_offset && chunk_end_offset>=current_free_chunk->end_offset) {
			file->data_gathered += current_free_chunk->end_offset-current_free_chunk->start_offset+1;
			file->free_chunk_list = g_slist_remove(file->free_chunk_list, current_free_chunk);
			nfreechunks -= 1;
			if (nfreechunks == 0) { /* The free chunk list is empty */
				g_slist_free(file->free_chunk_list);
				file->free_chunk_list = NULL;
				break;
			}
			i--;
			continue;
		}
		/* 4. data chunk is inside the free chunk */
		/* -> free chunk is splitted into two */
		if (chunk_offset>current_free_chunk->start_offset && chunk_end_offset<current_free_chunk->end_offset) {
			new_free_chunk = (free_chunk *)g_malloc(sizeof(free_chunk));
			new_free_chunk->start_offset = chunk_end_offset + 1;
			new_free_chunk->end_offset = current_free_chunk->end_offset;
			current_free_chunk->end_offset = chunk_offset-1;
			file->free_chunk_list = g_slist_insert(file->free_chunk_list, new_free_chunk, i + 1);
			file->data_gathered += chunk_length;
			continue;
		}
		/* 5.- data chunk overlaps the end part of free chunk */
		/* -> free chunk shrinks from the end */
		if (chunk_offset>current_free_chunk->start_offset && chunk_offset<=current_free_chunk->end_offset && chunk_end_offset>=current_free_chunk->end_offset) {
			file->data_gathered += current_free_chunk->end_offset-chunk_offset+1;
			current_free_chunk->end_offset = chunk_offset-1;
			continue;
		}
		/* 6.- data chunk is after the free chunk */
		/* -> free chunk is not altered and no new data gathered */
		if (chunk_offset>current_free_chunk->end_offset) {
			continue;
		}
	}

	/* Now, let's insert the data chunk into memory
	...first, we shall be able to allocate the memory */
	if (!entry->payload_data) {
		/* This is a New file */
		if (calculated_size > G_MAXSIZE) {
			/*
			* The argument to g_try_malloc() is
			* a gsize, the maximum value of which is
			* G_MAXSIZE.  If the calculated size is
			* bigger than that, we just say the attempt
			* to allocate memory failed.
			*/
			entry->payload_data = NULL;
		} else {
			entry->payload_data = (guint8 *)g_try_malloc((gsize)calculated_size);
			entry->payload_len  = calculated_size;
		}
		if (!entry->payload_data) {
			/* Memory error */
			file->is_out_of_memory = TRUE;
		}
	} else {
		/* This is an existing file in memory */
		if (calculated_size > (guint64) entry->payload_len &&
			!file->is_out_of_memory) {
			/* We need more memory */
			if (calculated_size > G_MAXSIZE) {
				/*
				* As for g_try_malloc(), so for
				* g_try_realloc().
				*/
				dest_memory_addr = NULL;
			} else {
				dest_memory_addr = g_try_realloc(
				entry->payload_data,
				(gsize)calculated_size);
			}
			if (!dest_memory_addr) {
				/* Memory error */
				file->is_out_of_memory = TRUE;
				/* We don't have memory for this file.
				Free the current file content from memory */
				g_free(entry->payload_data);
				entry->payload_data = NULL;
				entry->payload_len = 0;
			} else {
				entry->payload_data = (guint8 *)dest_memory_addr;
				entry->payload_len = calculated_size;
			}
		}
	}
	/* ...then, put the chunk of the file in the right place */
	if (!file->is_out_of_memory) {
		dest_memory_addr = entry->payload_data + chunk_offset;
		memmove(dest_memory_addr, eo_info->payload_data, eo_info->payload_len);
	}
}