OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / release / man3 / insque.3
1 .\" peter memishian -- meem@gnu.ai.mit.edu
2 .\" $Id: insque.3,v 1.2 1996/10/30 21:03:39 meem Exp meem $
3 .\" and Copyright (c) 2010, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" References consulted:
28 .\"   Linux libc source code (5.4.7)
29 .\"   Solaris 2.x, OSF/1, and HP-UX manpages
30 .\"   Curry's "UNIX Systems Programming for SVR4" (O'Reilly & Associates 1996)
31 .\"
32 .\" Changed to POSIX, 2003-08-11, aeb+wh
33 .\" mtk, 2010-09-09: Noted glibc 2.4 bug, added info on circular
34 .\"     lists, added example program
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .\"
42 .\" Japanese Version Copyright (c) 1998 AKAMATSU Kazuo
43 .\"         all rights reserved.
44 .\" Translated Thu Jan 7 16:00 JST 1999
45 .\"         by AKAMATSU Kazuo
46 .\" Updated Sun Sep 14 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
48 .\"
49 .TH INSQUE 3 2014\-08\-19 "" "Linux Programmer's Manual"
50 .SH 名前
51 insque, remque \- キューにアイテムを挿入/削除する
52 .SH 書式
53 .nf
54 \fB#include <search.h>\fP
55 .sp
56 \fBvoid insque(void *\fP\fIelem\fP\fB, void *\fP\fIprev\fP\fB);\fP
57
58 \fBvoid remque(void *\fP\fIelem\fP\fB);\fP
59 .fi
60 .sp
61 .in -4n
62 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
63 .in
64 .sp
65 .ad l
66 \fBinsque\fP(), \fBremque\fP():
67 .RS 4
68 _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
69 .RE
70 .ad
71 .SH 説明
72 関数 \fBinsque\fP() と \fBremque\fP() は双方向連結リスト (doubly\-linked list) を
73 操作する。リスト中のそれぞれの要素は、最初の二つの要素がそれぞれ次と前への
74 ポインターであるような構造体である。
75 リンクリストは、線形 (linear) か環状 (circular) のどちらかになる
76 (線形の場合には、リストの末尾では次へのポインターが NULL になり、
77 リストの先頭では前へのポインターが NULL になる)。
78
79 \fBinsque\fP() 関数は \fIelem\fP で示される要素を \fIprev\fP で示される
80 要素の直後に挿入する。
81
82 リストが線形の場合、\fIinsque(elem, NULL)\fP を呼び出すと、
83 リストの最初の要素を挿入することができる。
84 この呼び出しを行うと \fIelem\fP の次へのポインターと前へのポインターに
85 共に NULL が設定される。
86
87 リストが環状の場合、呼び出す側が、最初の要素の次へのポインターと前へのポインター
88 が自分自身を指し、また  \fBinsque\fP() の呼び出しで \fIprev\fP 引き数が最初の要素
89 を指すように保証しなければならない。
90
91 \fBremque\fP() 関数は \fIelem\fP で示される要素を双方向連結リストから取り除く。
92 .SH 準拠
93 POSIX.1\-2001.
94 .SH 注意
95 伝統的に (SunOS, Linux libc 4,5 では) これらの関数の引き数は \fIstruct qelem
96 *\fP型であり、これは以下のように定義されている。
97
98 .in +4n
99 .nf
100 struct qelem {
101     struct qelem *q_forw;
102     struct qelem *q_back;
103     char          q_data[1];
104 };
105 .fi
106 .in
107
108 この定義は \fI<search.h>\fP をインクルードする前に \fB_GNU_SOURCE\fP を定義することで得られる。
109
110 .\" Linux libc4 and libc 5 placed them
111 .\" in \fI<stdlib.h>\fP.
112 これらの関数のプロトタイプの置かれる場所は、UNIX の種類により異なる。
113 上記は POSIX 版である。 \fI<string.h>\fP にあるシステムもある。
114 .SH バグ
115 glibc 2.4 以前では \fIprev\fP に NULL を指定することができなかった。
116 その結果、線形のリストを作成するためには、
117 呼び出し側は、最初の呼び出しで、リストの最初の 2 つの要素を持ち、
118 各要素の次へのポインターと前へのポインターを適切に初期化したリストを
119 作成しなければならなかった。
120 .SH 例
121 次のプログラムは \fBinsque\fP() の使用法を示したものである。
122 下記はプログラムの実行例である。
123 .in +4n
124 .nf
125
126 $ \fB./a.out \-c a b c\fP
127 Traversing completed list:
128     a
129     b
130     c
131 That was a circular list
132 .fi
133 .in
134 .SS プログラムのソース
135 \&
136 .nf
137 #include <stdio.h>
138 #include <stdlib.h>
139 #include <unistd.h>
140 #include <search.h>
141
142 struct element {
143     struct element *forward;
144     struct element *backward;
145     char *name;
146 };
147
148 static struct element *
149 new_element(void)
150 {
151     struct element *e;
152
153     e = malloc(sizeof(struct element));
154     if (e == NULL) {
155         fprintf(stderr, "malloc() failed\en");
156         exit(EXIT_FAILURE);
157     }
158
159     return e;
160 }
161
162 int
163 main(int argc, char *argv[])
164 {
165     struct element *first, *elem, *prev;
166     int circular, opt, errfnd;
167
168     /* The "\-c" command\-line option can be used to specify that the
169        list is circular */
170
171     errfnd = 0;
172     circular = 0;
173     while ((opt = getopt(argc, argv, "c")) != \-1) {
174         switch (opt) {
175         case 'c':
176             circular = 1;
177             break;
178         default:
179             errfnd = 1;
180             break;
181         }
182     }
183
184     if (errfnd || optind >= argc) {
185         fprintf(stderr,  "Usage: %s [\-c] string...\en", argv[0]);
186         exit(EXIT_FAILURE);
187     }
188
189     /* Create first element and place it in the linked list */
190
191     elem = new_element();
192     first = elem;
193
194     elem\->name = argv[optind];
195
196     if (circular) {
197         elem\->forward = elem;
198         elem\->backward = elem;
199         insque(elem, elem);
200     } else {
201         insque(elem, NULL);
202     }
203
204     /* Add remaining command\-line arguments as list elements */
205
206     while (++optind < argc) {
207         prev = elem;
208
209         elem = new_element();
210         elem\->name = argv[optind];
211         insque(elem, prev);
212     }
213
214     /* Traverse the list from the start, printing element names */
215
216     printf("Traversing completed list:\en");
217     elem = first;
218     do {
219         printf("    %s\en", elem\->name);
220         elem = elem\->forward;
221     } while (elem != NULL && elem != first);
222
223     if (elem == first)
224         printf("That was a circular list\en");
225
226     exit(EXIT_SUCCESS);
227 }
228 .fi
229 .SH この文書について
230 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
231 である。プロジェクトの説明とバグ報告に関する情報は
232 http://www.kernel.org/doc/man\-pages/ に書かれている。