forked from bonsai/harakit
strcmp(1): adds copyright header, formatting, removes unused #include
This commit is contained in:
parent
5d2872d050
commit
59de0262bd
47
src/strcmp.c
47
src/strcmp.c
@ -1,24 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 DTB <trinity@trinity.moe>
|
||||||
|
* Copyright (c) 2023–2024 Emma Tebibyte <emma@tebibyte.media>
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU Affero General Public License as published by the Free
|
||||||
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
* later version.
|
||||||
|
*
|
||||||
|
* 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 Affero General Public License for more
|
||||||
|
* details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h> /* fprintf(3), stderr */
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
#include <stdlib.h> /* EXIT_FAILURE */
|
|
||||||
#include <sysexits.h>
|
#include <sysexits.h>
|
||||||
|
|
||||||
static char *program_name = "strcmp";
|
static char *program_name = "strcmp";
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argc < 3){
|
if (argc < 3) {
|
||||||
fprintf(stderr, "Usage: %s string string...\n",
|
fprintf(
|
||||||
argv[0] == NULL ? program_name : argv[0]);
|
stderr,
|
||||||
|
"Usage: %s string string...\n",
|
||||||
|
argv[0] == NULL ? program_name : argv[0]
|
||||||
|
);
|
||||||
|
|
||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; *argv[1] != '\0'; ++argv[1])
|
for (; *argv[1] != '\0'; ++argv[1]) {
|
||||||
for(i = 2; i < argc; ++i)
|
for(i = 2; i < argc; ++i) {
|
||||||
if(*argv[i-1] > *argv[i])
|
if (*argv[i-1] > *argv[i]) {
|
||||||
return 1;
|
return 1;
|
||||||
else if(*argv[i-1] < *argv[i]++)
|
} else if (*argv[i-1] < *argv[i]++) {
|
||||||
return -1; /* actually 255 */
|
return 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return EX_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user