1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Japanese Version Copyright (c) 2002 Akihiro MOTOKI
24 .\" all rights reserved.
25 .\" Translated Sat Sep 21 08:34:42 2002
26 .\" by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .TH STRVERSCMP 3 2001-12-19 "GNU" "Linux Programmer's Manual"
31 .\"O strverscmp \- compare two version strings
32 strverscmp \- 2つのバージョン文字列を比較する
36 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
37 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
39 .B #include <string.h>
41 .BI "int strverscmp(const char *" s1 ", const char *" s2 );
45 .\"O Often one has files
46 .\"O .IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..."
47 .\"O and it feels wrong when
50 .\"O .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9 .
51 .IR jan1 ", " jan2 ", ..., " jan9 ", " jan10 ", ..."
52 といった名前のファイルがある状況はよくあるが、
55 .IR jan1 ", " jan10 ", ..., " jan2 ", ..., " jan9
57 .\"O .\" classical solution: "rename jan jan0 jan?"
58 .\" これまでの解決方法: "rename jan jan0 jan?"
59 .\"O In order to rectify this, GNU introduced the
63 .\"O which is implemented using
64 .\"O .BR versionsort (3),
66 .\"O .BR strverscmp ().
78 .\"O Thus, the task of
79 .\"O .BR strverscmp ()
80 .\"O is to compare two strings and find the "right" order, while
82 .\"O only finds the lexicographic order.
83 .\"O This function does not use
84 .\"O the locale category
86 .\"O so is meant mostly for situations
87 .\"O where the strings are expected to be in ASCII.
90 の役目は2つの文字列を比較して「正しい」順序を探すことである。
99 このことから、この関数が主にアスキー文字から成る文字列を
102 .\"O What this function does is the following.
104 .\"O If both strings are equal, return 0.
105 .\"O Otherwise find the position
106 .\"O between two bytes with the property that before it both strings are equal,
107 .\"O while directly after it there is a difference.
109 それ以外の場合、その直前までは両方の文字列が等しく、
110 その直後のバイトで両者に違いがあるような、バイトの境界を探す。
111 .\"O Find the largest consecutive digit strings containing (or starting at,
112 .\"O or ending at) this position.
113 .\"O If one or both of these is empty,
114 見つかったバイト境界を含む数字列(数字だけの文字列)の最長一致検索を行う。
115 (数字列は境界から始まっていても、境界で終わっていてもよい)。
116 .\"O then return what
118 .\"O would have returned (numerical ordering of byte values).
119 2つの文字列から得られた数字列の一方または両方が空であれば、
123 .\"O Otherwise, compare both digit strings numerically, where digit strings with
124 .\"O one or more leading zeros are interpreted as if they have a decimal point
125 .\"O in front (so that in particular digit strings with more leading zeros
126 .\"O come before digit strings with fewer leading zeros).
127 それ以外の(数字列が両方とも空でない)場合、両方の数字列を数字順で比較する。
128 このとき、1つ以上の 0 が先頭にある数字列は、前に小数点がついているものと
129 解釈される。(先頭に 0 が多くある数字列ほど前に来ることになる)
130 .\"O Thus, the ordering is
131 .\"O .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10 .
133 .IR 000 ", " 00 ", " 01 ", " 010 ", " 09 ", " 0 ", " 1 ", " 9 ", " 10
134 .\"O .SH "RETURN VALUE"
137 .\"O .BR strverscmp ()
138 .\"O function returns an integer
139 .\"O less than, equal to, or greater than zero if \fIs1\fP
140 .\"O is found, respectively, to be earlier than, equal to,
141 .\"O or later than \fIs2\fP.
145 1)小さい、2)等しい、3)大きいのいずれかの整数を返す。
146 それぞれは、\fIs1\fP が \fIs2\fP よりも、
147 1)小さい、2)等しい、3)大きい ことを示す。
148 .\"O .SH "CONFORMING TO"
150 .\"O This function is a GNU extension.