forked from bonsai/harakit
considering a different project directory struture
inspired by freebsd source tree
This commit is contained in:
62
bin/strcmp/strcmp.1
Normal file
62
bin/strcmp/strcmp.1
Normal file
@@ -0,0 +1,62 @@
|
||||
.\" Copyright (c) 2023–2024 DTB <trinity@trinity.moe>
|
||||
.\" Copyright (c) 2023 Emma Tebibyte <emma@tebibyte.media>
|
||||
.\"
|
||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
||||
|
||||
.TH STRCMP 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
strcmp \(en compare strings
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
strcmp
|
||||
.RM [ string ]
|
||||
.RB [ strings... ]
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Strcmp checks whether the given strings are the same.
|
||||
Strcmp exits successfully if the strings are identical. Otherwise, strcmp exits
|
||||
with the value 1 if an earlier string has a greater byte value than a later
|
||||
string (e.g.
|
||||
.R strcmp b a
|
||||
)
|
||||
and 255 if an earlier string has a lesser byte value (e.g.
|
||||
.R strcmp a b
|
||||
).
|
||||
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
Strcmp will print an error message and exit unsuccessfully with a status
|
||||
described in sysexits(3) if used incorrectly (given less than two operands).
|
||||
|
||||
.SH UNICODE
|
||||
|
||||
Strcmp will exit unsuccessfully if the given strings are not identical;
|
||||
Unicode strings may need to be normalized if the intent is to check visual
|
||||
similarity and not byte similarity.
|
||||
|
||||
.SH RATIONALE
|
||||
|
||||
The traditional tool for string comparisons in POSIX and other Unix shells has
|
||||
been test(1). This tool also handles integer comparisons and file scrutiny.
|
||||
These parts of its functionality have been broken out into multiple utilities.
|
||||
|
||||
Strcmp’s functionality may be performed on a POSIX-compliant system with
|
||||
test(1p).
|
||||
|
||||
.SH AUTHOR
|
||||
|
||||
Written by DTB <trinity@trinity.moe>.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Copyright © 2023 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
||||
<https://gnu.org/licenses/gpl.html>.
|
||||
|
||||
.SH SEE ALSO
|
||||
|
||||
strcmp(3), intcmp(1), scrut(1), test(1p)
|
||||
24
bin/strcmp/strcmp.c
Normal file
24
bin/strcmp/strcmp.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h> /* fprintf(3), stderr */
|
||||
#include <stdlib.h> /* EXIT_FAILURE */
|
||||
#include <sysexits.h>
|
||||
|
||||
static char *program_name = "strcmp";
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int i;
|
||||
|
||||
if(argc < 3){
|
||||
fprintf(stderr, "Usage: %s [string] [string...]\n",
|
||||
argv[0] == NULL ? program_name : argv[0]);
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
for(; *argv[1] != '\0'; ++argv[1])
|
||||
for(i = 2; i < argc; ++i)
|
||||
if(*argv[i-1] > *argv[i])
|
||||
return 1;
|
||||
else if(*argv[i-1] < *argv[i]++)
|
||||
return -1; /* actually 255 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user