Merge branch 'dj-formatting'

This commit is contained in:
2024-07-29 22:40:18 -06:00
11 changed files with 631 additions and 375 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 20222024 DTB <trinity@trinity.moe>
* Copyright (c) 2023 DTB <trinity@trinity.moe>
* Copyright (c) 20232024 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
@@ -15,29 +16,35 @@
* 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 <stdlib.h> /* size_t */
#include <sysexits.h> /* EX_USAGE */
#include <sysexits.h> /* EX_OK, EX_USAGE */
char *program_name = "strcmp";
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
int i;
if (argc < 3) {
fprintf(stderr, "Usage: %s string string...\n",
(void)fprintf(
stderr,
"Usage: %s string string...\n",
argv[0] == NULL ? program_name : argv[0]
);
return EX_USAGE;
}
/* This compares the Nth character of arg[2] onward with argv[1]'s Nth
* character, rather than comparing each arg with argv[1] sequentially. */
for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in argv[1] */
for (size_t i = 2; i < argc; ++argv[i], ++i) { /* iterate &argv[2] */
/* this never overruns because of nul termination */
if (*argv[i-1] != *argv[i]) { return *argv[i-1] - *argv[i]; }
for (; *argv[1] != '\0'; ++argv[1]) {
for (i = 2; i < argc; ++i) {
/* a former string has a greater byte value */
if (*argv[i-1] > *argv[i]) {
return 1;
/* a latter string has a greater byte value */
} else if (*argv[i-1] < *argv[i]++) {
return -1; /* actually 255 */
}
}
}
return 0;
return EX_OK;
}