fix ASCII issues, not a great fix but a fix
This commit is contained in:
		
							parent
							
								
									4500a05757
								
							
						
					
					
						commit
						c20f3d08d3
					
				@ -26,7 +26,7 @@ Str will print a message to standard error and exit unsuccessfully if used impro
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
There's no way of knowing which argument failed the test without re-testing arguments individually.
 | 
					There's no way of knowing which argument failed the test without re-testing arguments individually.
 | 
				
			||||||
.PP
 | 
					.PP
 | 
				
			||||||
If a character in a string isn't valid ASCII the behavior of this program is undefined.
 | 
					If a character in a string isn't valid ASCII str will exit unsuccessfully.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.SH SEE ALSO
 | 
					.SH SEE ALSO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								str/str.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								str/str.c
									
									
									
									
									
								
							@ -1,8 +1,7 @@
 | 
				
			|||||||
#include <ctype.h>
 | 
					 | 
				
			||||||
#include <stddef.h> /* NULL */
 | 
					#include <stddef.h> /* NULL */
 | 
				
			||||||
#include <stdio.h> /* fprintf(3) */
 | 
					#include <stdio.h> /* fprintf(3) */
 | 
				
			||||||
#include <string.h> /* strcmp(3) */
 | 
					#include <string.h> /* strcmp(3) */
 | 
				
			||||||
#ifdef DONT_USE_SYSTEM_SYSEXITS
 | 
					#if defined DONT_USE_SYSTEM_SYSEXITS
 | 
				
			||||||
#	include "../include/sysexits.h" /* EX_USAGE */
 | 
					#	include "../include/sysexits.h" /* EX_USAGE */
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#	include <sysexits.h> /* EX_USAGE */
 | 
					#	include <sysexits.h> /* EX_USAGE */
 | 
				
			||||||
@ -11,9 +10,22 @@
 | 
				
			|||||||
static char *program_name = "str";
 | 
					static char *program_name = "str";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* don't use this */
 | 
					/* don't use this */
 | 
				
			||||||
#include "isempty.c"
 | 
					/* #include "isempty.c" */
 | 
				
			||||||
 | 
					/* An isempty() won't work; see implementation - the default behavior of str(1)
 | 
				
			||||||
 | 
					 * is to return 1, so it would return 1 (false) no matter what. I'm not adding
 | 
				
			||||||
 | 
					 * a special case, just do something like `! str isvalue "$input"` in the
 | 
				
			||||||
 | 
					 * higher level.
 | 
				
			||||||
 | 
					 * However, if you wanna make it work, the file is included, just hack on this
 | 
				
			||||||
 | 
					 * source file after removing the comment on the include. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <ctype.h>
 | 
				
			||||||
#include "isvalue.c"
 | 
					#include "isvalue.c"
 | 
				
			||||||
 | 
					/* This is a special addition to the command that lets `str isvalue "$input"`
 | 
				
			||||||
 | 
					 * function as a lightweight replacement to the common `test -n "$input"` or
 | 
				
			||||||
 | 
					 * `[ -n "$input" ]`. This will speed up your shellscript execution by a tad
 | 
				
			||||||
 | 
					 * ONLY if test(1) isn't already built into your shell (most of the time, it
 | 
				
			||||||
 | 
					 * is, and saves you the overhead of spawning a new process, which is greater
 | 
				
			||||||
 | 
					 * than the savings of switching from test(1) to this program). */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct {
 | 
					static struct {
 | 
				
			||||||
	char *name;
 | 
						char *name;
 | 
				
			||||||
@ -58,7 +70,10 @@ usage:		fprintf(stderr, "Usage: %s [type] [string...]\n",
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
pass:	for(argv += 2, r = 1; *argv != NULL; ++argv)
 | 
					pass:	for(argv += 2, r = 1; *argv != NULL; ++argv)
 | 
				
			||||||
		for(i = 0; argv[0][i] != '\0'; ++i)
 | 
							for(i = 0; argv[0][i] != '\0'; ++i)
 | 
				
			||||||
			if(!ctypes[ctype].f(argv[0][i]))
 | 
								/* First checks if argv[0][i] is valid ASCII; ctypes(3)
 | 
				
			||||||
 | 
								 * don't handle non-ASCII.
 | 
				
			||||||
 | 
								 * This is bad. */
 | 
				
			||||||
 | 
								if(argv[0][i] < 0x80 && !ctypes[ctype].f(argv[0][i]))
 | 
				
			||||||
				return 1;
 | 
									return 1;
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
				r = 0;
 | 
									r = 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user