Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////
// Sorts the list, then rewinds it...
//
int
LL_Sort (LinkedList * list, int compare (void *, void *))
{
	int i, j;						  // Junk / loop variables
	int numnodes;					  // number of nodes in list
	LL_node *best, *last;		  // best match and last node in the list
	LL_node *current;

	if (!list)
		return -1;
	if (!compare)
		return -1;

	numnodes = LL_Length (list); // get the number of nodes...
	if (0 > LL_End (list))
		return -1;					  // Find the last node.
	last = LL_GetNode (list);

	if (numnodes < 2)
		return 0;

	for (i = numnodes - 1; i > 0; i--) {
		LL_Rewind (list);			  // get the first node again
		best = last;				  // reset our "best" node

		for (j = 0; j < i; j++) {
			current = LL_GetNode (list);
			// If we found a better match...
			if (compare (current->data, best->data) > 0) {
				best = current;	  // keep track of the "best" match
			}
			LL_Next (list);		  // Go to the next node.
		}

		LL_SwapNodes (last, best);	// Switch two nodes...
		if (best)
			last = best->prev;
		else
			return -1;

		//last = LL_FindPrev(best);         // And go backwards by one node.
	}

	//return LLFindFirst(current);        // return pointer to the first node.
	LL_Rewind (list);

	return 0;

}
Ejemplo n.º 2
0
void *
LL_Shift (LinkedList * list)				  // Remove node from start of list
{
	if (!list)
		return NULL;

	if (0 > LL_Rewind (list))
		return NULL;

	return LL_DeleteNode (list);
}
Ejemplo n.º 3
0
void *
LL_GetFirst (LinkedList * list)			  // gets data from first node
{
	if (!list)
		return NULL;

	if (0 > LL_Rewind (list))
		return NULL;

	return LL_Get (list);
}
Ejemplo n.º 4
0
int
LL_Unshift (LinkedList * list, void *add)	// Add node to beginning of list
{
	if (!list)
		return -1;
	if (!add)
		return -1;

	LL_Rewind (list);

	return LL_InsertNode (list, add);
}
Ejemplo n.º 5
0
//////////////////////////////////////////////////////////////////////
// Removes a specific node...
void *
LL_Remove (LinkedList * list, void *data)
{
	void *find;

	if (!list)
		return NULL;

	LL_Rewind (list);
	do {
		find = LL_Get (list);
		if (find == data)
			return LL_DeleteNode (list);
	} while (LL_Next (list) == 0);

	return NULL;
}
Ejemplo n.º 6
0
/**
 * Read the next input event.
 * \param drvthis  Pointer to driver structure.
 * \retval         String representation of the key;
 *                 \c NULL for nothing available / error.
 */
MODULE_EXPORT const char *
linuxInput_get_key (Driver *drvthis)
{
	PrivateData *p = drvthis->private_data;
	struct input_event event;
	struct keycode *k;

	if (read(p->fd, &event, sizeof(event)) != sizeof(event))
		return NULL;

	/* Ignore release events and not-key events */
	if (event.type != EV_KEY || event.value == 0)
		return NULL;

	switch (event.code) {
	case KEY_ESC:
		return "Escape";

	case KEY_UP:
		return "Up";

	case KEY_LEFT:
		return "Left";

	case KEY_RIGHT:
		return "Right";

	case KEY_DOWN:
		return "Down";

	case KEY_ENTER:
	case KEY_KPENTER:
		return "Enter";

	default:
		LL_Rewind(p->buttonmap);
		k = LL_Find(p->buttonmap, compare_with_keycode, &event.code);
		if (k)
			return k->button;

		return NULL;
	}
}
Ejemplo n.º 7
0
int
LL_UnRoll (LinkedList * list)			  // Roll the other way...
{
	LL_node *node, *prev;

	if (!list)
		return -1;
	//if(!list->current) return -1;

	if (0 > LL_Rewind (list))
		return -1;

	// Avoid rolling an empty list, or unlinking the head/tail...
	if (list->current == &list->tail)
		list->current = list->current->prev;
	if (list->current == &list->head)
		list->current = list->current->next;
	// List is empty
	if (list->current == &list->tail)
		return 0;
	// List has one item
	if (list->current->next == &list->tail)
		return 0;

	node = list->current;

	LL_node_Unlink (node);

	if (0 > LL_End (list))
		return -1;

	prev = list->tail.prev;

	list->tail.prev = node;
	prev->next = node;
	node->next = &list->tail;
	node->prev = prev;

	return 0;
}
Ejemplo n.º 8
0
int
LL_Roll (LinkedList * list)				  // Make last node first
{
	LL_node *node, *next;

	if (!list)
		return -1;
	//if(!list->current) return -1;

	if (0 > LL_End (list))
		return -1;

	// Avoid rolling an empty list, or unlinking the head/tail...
	if (list->current == &list->head)
		list->current = list->current->next;
	if (list->current == &list->tail)
		list->current = list->current->prev;
	// List is empty
	if (list->current == &list->head)
		return 0;
	// List has one item
	if (list->current->prev == &list->head)
		return 0;

	node = list->current;

	LL_node_Unlink (node);

	if (0 > LL_Rewind (list))
		return -1;

	next = list->head.next;

	list->head.next = node;
	next->prev = node;
	node->prev = &list->head;
	node->next = next;

	return 0;
}
Ejemplo n.º 9
0
static int
render_frame(LinkedList *list,
		int left,	/* left edge of frame */
		int top,	/* top edge of frame */
		int right,	/* right edge of frame */
		int bottom,	/* bottom edge of frame */
		int fwid,	/* frame width? */
		int fhgt,	/* frame height? */
		char fscroll,	/* direction of scrolling */
		int fspeed,	/* speed of scrolling... */
		long timer)	/* current timer tick */
{
	int fy = 0;		/* Scrolling offset for the frame... */

	debug(RPT_DEBUG, "%s(list=%p, left=%d, top=%d, "
			  "right=%d, bottom=%d, fwid=%d, fhgt=%d, "
			  "fscroll='%c', fspeed=%d, timer=%ld)",
			  __FUNCTION__, list, left, top, right, bottom,
			  fwid, fhgt, fscroll, fspeed, timer);

	/* return on no data or illegal height */
	if ((list == NULL) || (fhgt <= 0))
		return -1;

	if (fscroll == 'v') {		/* vertical scrolling */
		// only set offset !=0 when fspeed is != 0 and there is something to scroll
		if ((fspeed != 0) && (fhgt > bottom - top)) {
			int fy_max = fhgt - (bottom - top) + 1;

			fy = (fspeed > 0)
			     ? (timer / fspeed) % fy_max
			     : (-fspeed * timer) % fy_max;

			fy = max(fy, 0);	// safeguard against negative values

			debug(RPT_DEBUG, "%s: fy=%d", __FUNCTION__, fy);
		}
	}
	else if (fscroll == 'h') {	/* horizontal scrolling */
		/* TODO:  Frames don't scroll horizontally yet! */
	}

	/* reset widget list */
	LL_Rewind(list);

	/* loop over all widgets */
	do {
		Widget *w = (Widget *) LL_Get(list);

		if (w == NULL)
			return -1;

		/* TODO:  Make this cleaner and more flexible! */
		switch (w->type) {
		case WID_STRING:
			render_string(w, left, top - fy, right, bottom, fy);
			break;
		case WID_HBAR:
			render_hbar(w, left, top - fy, right, bottom, fy);
			break;
		case WID_VBAR:	  /* FIXME:  Vbars don't work in frames! */
			render_vbar(w, left, top, right, bottom);
			break;
		case WID_ICON:	  /* FIXME:  Icons don't work in frames! */
			drivers_icon(w->x, w->y, w->length);
			break;
		case WID_TITLE:	  /* FIXME:  Doesn't work quite right in frames... */
			render_title(w, left, top, right, bottom, timer);
			break;
		case WID_SCROLLER: /* FIXME: doesn't work in frames... */
			render_scroller(w, left, top, right, bottom, timer);
			break;
		case WID_FRAME:
			{
				/* FIXME: doesn't handle nested frames quite right!
				 * doesn't handle scrolling in nested frames at all...
				 */
				int new_left = left + w->left - 1;
				int new_top = top + w->top - 1;
				int new_right = min(left + w->right, right);
				int new_bottom = min(top + w->bottom, bottom);

				if ((new_left < right) && (new_top < bottom))	/* Render only if it's visible... */
					render_frame(w->frame_screen->widgetlist, new_left, new_top,
							new_right, new_bottom, w->width, w->height,
							w->length, w->speed, timer);
			}
			break;
		case WID_NUM:	  /* FIXME: doesn't work in frames... */
			/* NOTE: y=10 means COLON (:) */
			if ((w->x > 0) && (w->y >= 0) && (w->y <= 10)) {
				drivers_num(w->x + left, w->y);
			}
			break;
		case WID_NONE:
			/* FALLTHROUGH */
		default:
			break;
		}
	} while (LL_Next(list) == 0);

	return 0;
}