Make include_dir sort usefully case sensitive.

pull/1182/head
Roger A. Light 7 years ago
parent 321e566af6
commit 8350956a08

@ -351,13 +351,16 @@
contain the main configuration file.</para> contain the main configuration file.</para>
<para>The configuration files in <para>The configuration files in
<option>include_dir</option> are loaded in case <option>include_dir</option> are loaded in case
insensitive alphabetical order.</para> sensitive alphabetical order, with the upper case of
each letter ordered before the lower case of the same
letter.</para>
<example title="Load Order for include_dir" label="Load Order for include_dir"> <example title="Load Order for include_dir" label="Load Order for include_dir">
<para>Given the files <para>Given the files
<replaceable>b.conf</replaceable>, <replaceable>b.conf</replaceable>,
<replaceable>A.conf</replaceable>, <replaceable>A.conf</replaceable>,
<replaceable>01.conf</replaceable>, <replaceable>01.conf</replaceable>,
<replaceable>a.conf</replaceable>, and <replaceable>a.conf</replaceable>,
<replaceable>B.conf</replaceable>, and
<replaceable>00.conf</replaceable> inside <replaceable>00.conf</replaceable> inside
<option>include_dir</option>, the config files <option>include_dir</option>, the config files
would be loaded in this order:</para> would be loaded in this order:</para>
@ -366,6 +369,7 @@
01.conf 01.conf
A.conf A.conf
a.conf a.conf
B.conf
b.conf b.conf
</programlisting></example> </programlisting></example>
<para>If this option is used multiple times, then each <para>If this option is used multiple times, then each

@ -872,10 +872,10 @@
# in the main file. This option will only be processed from the main # in the main file. This option will only be processed from the main
# configuration file. The directory specified must not contain the # configuration file. The directory specified must not contain the
# main configuration file. # main configuration file.
# Files within include_dir will be loaded sorted in case-insensitive # Files within include_dir will be loaded sorted in case-sensitive
# alphabetical order. If this option is given multiple times, all of the files # alphabetical order, with capital letters ordered first. If this option is
# from the first instance will be processed before the next instance. See the # given multiple times, all of the files from the first instance will be
# man page for examples. # processed before the next instance. See the man page for examples.
#include_dir #include_dir
# ================================================================= # =================================================================

@ -16,6 +16,7 @@ Contributors:
#include "config.h" #include "config.h"
#include <ctype.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -47,12 +48,33 @@ Contributors:
#include "mqtt3_protocol.h" #include "mqtt3_protocol.h"
#ifdef WIN32
int scmp_p(const void *p1, const void *p2) int scmp_p(const void *p1, const void *p2)
{ {
return strcasecmp(*(const char **)p1, *(const char **)p2); const char *s1 = *(const char **)p1;
const char *s2 = *(const char **)p2;
int result;
while(s1[0] && s2[0]){
/* Sort by case insensitive part first */
result = toupper(s1[0]) - toupper(s2[0]);
if(result == 0){
/* Case insensitive part matched, now distinguish between case */
result = s1[0] - s2[0];
if(result != 0){
return result;
}
}else{
/* Return case insensitive match fail */
return result;
}
s1++;
s2++;
}
return s1[0] - s2[0];
} }
#ifdef WIN32
int config__get_dir_files(const char *include_dir, char ***files, int *file_count) int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{ {
int len; int len;
@ -112,10 +134,6 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
#ifndef WIN32 #ifndef WIN32
int scmp_p(const void *p1, const void *p2)
{
return strcmp(*(const char **)p1, *(const char **)p2);
}
int config__get_dir_files(const char *include_dir, char ***files, int *file_count) int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{ {

Loading…
Cancel
Save