sort: support sorting decimal numbers correctly
sorry not to have used strtold from the beginning
This commit is contained in:
		
							
								
								
									
										12
									
								
								sort.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								sort.c
									
									
									
									
									
								
							@@ -168,6 +168,7 @@ linecmp(const char **a, const char **b)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	char *s1, *s2;
 | 
						char *s1, *s2;
 | 
				
			||||||
	int res = 0;
 | 
						int res = 0;
 | 
				
			||||||
 | 
						long double x, y;
 | 
				
			||||||
	struct kdlist *node;
 | 
						struct kdlist *node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (node = head; node && res == 0; node = node->next) {
 | 
						for (node = head; node && res == 0; node = node->next) {
 | 
				
			||||||
@@ -176,12 +177,15 @@ linecmp(const char **a, const char **b)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		/* if -u is given, don't use default key definition
 | 
							/* if -u is given, don't use default key definition
 | 
				
			||||||
		 * unless it is the only one */
 | 
							 * unless it is the only one */
 | 
				
			||||||
		if (uflag && node == tail && head != tail)
 | 
							if (uflag && node == tail && head != tail) {
 | 
				
			||||||
			res = 0;
 | 
								res = 0;
 | 
				
			||||||
		else if (node->keydef.flags & MOD_N)
 | 
							} else if (node->keydef.flags & MOD_N) {
 | 
				
			||||||
			res = strtol(s1, 0, 10) - strtol(s2, 0, 10);
 | 
								x = strtold(s1, NULL);
 | 
				
			||||||
		else
 | 
								y = strtold(s2, NULL);
 | 
				
			||||||
 | 
								res = x < y ? -1 : x > y;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			res = strcmp(s1, s2);
 | 
								res = strcmp(s1, s2);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (node->keydef.flags & MOD_R)
 | 
							if (node->keydef.flags & MOD_R)
 | 
				
			||||||
			res = -res;
 | 
								res = -res;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user