insque.c 1.62 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1
/*
Paul Eggert's avatar
Paul Eggert committed
2
Copyright (C) 1993-1998, 2001-2020 Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
3

4
This program is free software: you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
5
it under the terms of the GNU General Public License as published by
6 7
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Richard M. Stallman's avatar
Richard M. Stallman committed
8 9 10 11 12 13 14

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 General Public License for more details.

You should have received a copy of the GNU General Public License
15
along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16

Dave Love's avatar
#  
Dave Love committed
17
/* This file implements the emacs_insque and emacs_remque functions,
Richard M. Stallman's avatar
Richard M. Stallman committed
18
   clones of the insque and remque functions of BSD.  They and all
Dave Love's avatar
#  
Dave Love committed
19 20 21
   their callers have been renamed to emacs_mumble to allow us to
   include this file in the menu library on all systems.  */

22
#include "XMenuInt.h"
Dave Love's avatar
#  
Dave Love committed
23 24 25 26 27 28 29 30 31 32

struct qelem {
  struct    qelem *q_forw;
  struct    qelem *q_back;
  char q_data[1];
};

/* Insert ELEM into a doubly-linked list, after PREV.  */

void
33
emacs_insque (void *velem, void *vprev)
Dave Love's avatar
#  
Dave Love committed
34
{
35 36
  struct qelem *elem = velem;
  struct qelem *prev = vprev;
Dave Love's avatar
#  
Dave Love committed
37 38 39 40 41 42 43 44 45 46
  struct qelem *next = prev->q_forw;
  prev->q_forw = elem;
  if (next)
    next->q_back = elem;
  elem->q_forw = next;
  elem->q_back = prev;
}

/* Unlink ELEM from the doubly-linked list that it is in.  */

47 48
void
emacs_remque (void *velem)
Dave Love's avatar
#  
Dave Love committed
49
{
50
  struct qelem *elem = velem;
Dave Love's avatar
#  
Dave Love committed
51 52 53 54 55 56 57
  struct qelem *next = elem->q_forw;
  struct qelem *prev = elem->q_back;
  if (next)
    next->q_back = prev;
  if (prev)
    prev->q_forw = next;
}