Compare commits
	
		
			4 Commits
		
	
	
		
			9addfc9284
			...
			16f23e11c0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 16f23e11c0 | |||
| d87c278be5 | |||
| 5caefbb465 | |||
| 8d743dab7a | 
@ -4,7 +4,7 @@
 | 
				
			|||||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
 | 
					.\" 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/>.
 | 
					.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
 | 
				
			||||||
.\"
 | 
					.\"
 | 
				
			||||||
.TH STRCMP 1 2024-06-17 "Harakit X.X.X"
 | 
					.TH STRCMP 1 2024-07-15 "Harakit X.X.X"
 | 
				
			||||||
.SH NAME
 | 
					.SH NAME
 | 
				
			||||||
strcmp \(en compare strings
 | 
					strcmp \(en compare strings
 | 
				
			||||||
.\"
 | 
					.\"
 | 
				
			||||||
@ -20,15 +20,15 @@ Check whether string arguments are the same.
 | 
				
			|||||||
.SH DIAGNOSTICS
 | 
					.SH DIAGNOSTICS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The program will exit successfully if the strings are identical. Otherwise, it
 | 
					The program will exit successfully if the strings are identical. Otherwise, it
 | 
				
			||||||
will exit with an error code of 1 if a string passed has a lesser byte value
 | 
					will exit with an error code less than 128 if a string passed has a lesser byte
 | 
				
			||||||
than one of the prior strings:
 | 
					value than one of the prior strings:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.RS
 | 
					.RS
 | 
				
			||||||
strcmp b a
 | 
					strcmp b a
 | 
				
			||||||
.RE
 | 
					.RE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
or with an error code of 255 if it has a greater byte value than one of the
 | 
					or with an error code greater than 128 if it has a greater byte value than one
 | 
				
			||||||
prior strings:
 | 
					of the prior strings:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.RS
 | 
					.RS
 | 
				
			||||||
strcmp a b
 | 
					strcmp a b
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										46
									
								
								src/strcmp.c
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								src/strcmp.c
									
									
									
									
									
								
							@ -1,24 +1,42 @@
 | 
				
			|||||||
#include <stdio.h> /* fprintf(3), stderr */
 | 
					/*
 | 
				
			||||||
#include <stdlib.h> /* EXIT_FAILURE */
 | 
					 * Copyright (c) 2022–2024 DTB <trinity@trinity.moe>
 | 
				
			||||||
#include <sysexits.h>
 | 
					 * 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/.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *program_name = "strcmp";
 | 
					#include <stdio.h> /* fprintf(3), stderr */
 | 
				
			||||||
 | 
					#include <stdlib.h> /* size_t */
 | 
				
			||||||
 | 
					#include <sysexits.h> /* EX_USAGE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static *program_name = "strcmp";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[]){
 | 
					int main(int argc, char *argv[]){
 | 
				
			||||||
	int i;
 | 
						if (argc < 3) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if(argc < 3){
 | 
					 | 
				
			||||||
		fprintf(stderr, "Usage: %s string string...\n",
 | 
							fprintf(stderr, "Usage: %s string string...\n",
 | 
				
			||||||
			argv[0] == NULL ? program_name : argv[0]);
 | 
								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]) { /* iterate chars in ref */
 | 
				
			||||||
		for(i = 2; i < argc; ++i)
 | 
							/* iterate argc */
 | 
				
			||||||
			if(*argv[i-1] > *argv[i])
 | 
							for (size_t i = 2 /* ref cmp */; i < argc; ++argv[i], ++i) {
 | 
				
			||||||
				return 1;
 | 
								/* this doesn't overrun because of nul termination */
 | 
				
			||||||
			else if(*argv[i-1] < *argv[i]++)
 | 
								if (*argv[i-1] != *argv[i]) { return *argv[i-1] - *argv[i]; }
 | 
				
			||||||
				return -1; /* actually 255 */
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user