jcs ratpoison hax
at oldjcs 198 lines 4.5 kB view raw
1/* This file was taken from the Linux kernel and is 2 * Copyright (C) 2003 Linus Torvalds 3 * 4 * Modified by Shawn Betts. Portions created by Shawn Betts are 5 * Copyright (C) 2003, 2004 Shawn Betts 6 * 7 * This file is part of ratpoison. 8 * 9 * ratpoison is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2, or (at your option) 12 * any later version. 13 * 14 * ratpoison is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this software; see the file COPYING. If not, write to 21 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 22 * Boston, MA 02111-1307 USA 23 */ 24 25#include "linkedlist.h" 26 27/* 28 * Insert a new entry between two known consecutive entries. 29 * 30 * This is only for internal list manipulation where we know 31 * the prev/next entries already! 32 */ 33void 34__list_add(struct list_head *new, 35 struct list_head *prev, 36 struct list_head *next) 37{ 38 next->prev = new; 39 new->next = next; 40 new->prev = prev; 41 prev->next = new; 42} 43 44/** 45 * list_add - add a new entry 46 * @new: new entry to be added 47 * @head: list head to add it after 48 * 49 * Insert a new entry after the specified head. 50 * This is good for implementing stacks. 51 */ 52void 53list_add(struct list_head *new, struct list_head *head) 54{ 55 __list_add(new, head, head->next); 56} 57 58/** 59 * list_add_tail - add a new entry 60 * @new: new entry to be added 61 * @head: list head to add it before 62 * 63 * Insert a new entry before the specified head. 64 * This is useful for implementing queues. 65 */ 66void 67list_add_tail(struct list_head *new, struct list_head *head) 68{ 69 __list_add(new, head->prev, head); 70} 71 72/* 73 * Delete a list entry by making the prev/next entries 74 * point to each other. 75 * 76 * This is only for internal list manipulation where we know 77 * the prev/next entries already! 78 */ 79void 80__list_del(struct list_head * prev, struct list_head * next) 81{ 82 next->prev = prev; 83 prev->next = next; 84} 85 86/** 87 * list_del - deletes entry from list. 88 * @entry: the element to delete from the list. 89 * Note: list_empty on entry does not return true after this, the entry is 90 * in an undefined state. 91 */ 92void 93list_del(struct list_head *entry) 94{ 95 __list_del(entry->prev, entry->next); 96} 97 98/** 99 * list_del_init - deletes entry from list and reinitialize it. 100 * @entry: the element to delete from the list. 101 */ 102void 103list_del_init(struct list_head *entry) 104{ 105 __list_del(entry->prev, entry->next); 106 INIT_LIST_HEAD(entry); 107} 108 109/** 110 * list_move - delete from one list and add as another's head 111 * @list: the entry to move 112 * @head: the head that will precede our entry 113 */ 114void 115list_move(struct list_head *list, struct list_head *head) 116{ 117 __list_del(list->prev, list->next); 118 list_add(list, head); 119} 120 121/** 122 * list_move_tail - delete from one list and add as another's tail 123 * @list: the entry to move 124 * @head: the head that will follow our entry 125 */ 126void 127list_move_tail(struct list_head *list, 128 struct list_head *head) 129{ 130 __list_del(list->prev, list->next); 131 list_add_tail(list, head); 132} 133 134/** 135 * list_empty - tests whether a list is empty 136 * @head: the list to test. 137 */ 138int 139list_empty(struct list_head *head) 140{ 141 return head->next == head; 142} 143 144void 145__list_splice(struct list_head *list, 146 struct list_head *head) 147{ 148 struct list_head *first = list->next; 149 struct list_head *last = list->prev; 150 struct list_head *at = head->next; 151 152 first->prev = head; 153 head->next = first; 154 155 last->next = at; 156 at->prev = last; 157} 158 159/** 160 * list_splice - join two lists 161 * @list: the new list to add. 162 * @head: the place to add it in the first list. 163 */ 164void 165list_splice(struct list_head *list, struct list_head *head) 166{ 167 if (!list_empty(list)) 168 __list_splice(list, head); 169} 170 171/** 172 * list_splice_init - join two lists and reinitialise the emptied list. 173 * @list: the new list to add. 174 * @head: the place to add it in the first list. 175 * 176 * The list at @list is reinitialised 177 */ 178void 179list_splice_init(struct list_head *list, 180 struct list_head *head) 181{ 182 if (!list_empty(list)) { 183 __list_splice(list, head); 184 INIT_LIST_HEAD(list); 185 } 186} 187 188int 189list_size (struct list_head *list) 190{ 191 struct list_head *cur; 192 193 int i = 0; 194 list_for_each (cur, list) 195 i++; 196 197 return i; 198}