extern const f_string_static_t f_path_home_wildcard_s;
extern const f_string_static_t f_path_present_working_s;
extern const f_string_static_t f_path_present_working_old_s;
+
+ /**
+ * Provide Kevux ARCHITECTURE_BITS environment variable handling support.
+ *
+ * Non-Kevux systems should not need this and enabling this might cause problems.
+ *
+ * This uses the defines for customizing the architecture bits (and scripts) path:
+ * - _en_kevux_path_architecture_bits_default_name_
+ * - _en_kevux_path_architecture_bits_default_length_
+ * - _en_kevux_path_architecture_bits_scripts_name_
+ * - _en_kevux_path_architecture_bits_scripts_length_
+ *
+ * The path separator should not be specified for these defines because it is automatically appended.
+ * Disable either the default or scripts by setting the length to 0.
+ *
+ * F_path_*_s:
+ * - architecture_bits: The architecture bits environment variable (usually is "ARCHITECTURE_BITS").
+ * - architecture_bits_default: The default architecture bits string with a trailing path separator, such as "x64/".
+ * - architecture_bits_scripts: The default architecture bits string with a trailing path separator, such as "scripts/".
+ */
+ #ifdef _en_kevux_path_architecture_bits_
+ #define F_path_architecture_bits_s "ARCHITECTURE_BITS"
+
+ #define F_path_architecture_bits_s_length 17
+
+ #if defined(_en_kevux_path_architecture_bits_default_name_) && defined(_en_kevux_path_architecture_bits_default_length_)
+ #if _en_kevux_path_architecture_bits_default_length_ == 0
+ #define F_path_architecture_bits_default_s F_string_empty_s
+
+ #define F_path_architecture_bits_default_s_length F_string_empty_s_length
+ #else
+ #define F_path_architecture_bits_default_s _en_kevux_path_architecture_bits_default_name_
+
+ #define F_path_architecture_bits_default_s_length _en_kevux_path_architecture_bits_default_length_ + F_path_separator_s_length
+ #endif // _en_kevux_path_architecture_bits_default_length_ == 0
+ #else
+ #define F_path_architecture_bits_default_s "x64" F_path_separator_s
+
+ #define F_path_architecture_bits_default_s_length 3 + F_path_separator_s_length
+ #endif // !defined(_en_kevux_path_architecture_bits_default_name_) || !defined(_en_kevux_path_architecture_bits_default_length_)
+
+ #if defined(_en_kevux_path_architecture_bits_scripts_name_) && defined(_en_kevux_path_architecture_bits_scripts_length_)
+ #if _en_kevux_path_architecture_bits_scripts_length_ == 0
+ #define F_path_architecture_bits_scripts_s F_string_empty_s
+
+ #define F_path_architecture_bits_scripts_s_length F_string_empty_s_length
+ #else
+ #define F_path_architecture_bits_scripts_s _en_kevux_path_architecture_bits_scripts_name_
+
+ #define F_path_architecture_bits_scripts_s_length _en_kevux_path_architecture_bits_scripts_length_ + F_path_separator_s_length
+ #endif // _en_kevux_path_architecture_bits_scripts_length_ == 0
+ #else
+ #define F_path_architecture_bits_scripts_s "scripts" F_path_separator_s
+
+ #define F_path_architecture_bits_scripts_s_length 7 + F_path_separator_s_length
+ #endif // !defined(_en_kevux_path_architecture_bits_scripts_name_) || !defined(_en_kevux_path_architecture_bits_scripts_length_)
+
+ extern const f_string_static_t f_path_architecture_bits_s;
+ extern const f_string_static_t f_path_architecture_bits_default_s;
+ extern const f_string_static_t f_path_architecture_bits_scripts_s;
+ #endif // _en_kevux_path_architecture_bits_
#endif // _di_f_path_defines_
/**
f_array_length_t first = 0;
f_array_length_t total = 0;
+ // Do a quick pre-process of PATH to approximate the amount of parts needed, reducing the number of allocations.
for (; i <= path.used; ++i) {
+ if (path.string[i] == f_path_separator_variable_s.string[0]) ++total;
+ } // for
- if (i == path.used || path.string[i] == f_path_separator_variable_s.string[0]) {
- status = f_string_dynamics_increase(F_memory_default_allocation_small_d, paths);
+ #ifdef _en_kevux_path_architecture_bits_
+ total *= 3;
+ #endif // _en_kevux_path_architecture_bits_
+
+ if (total) {
+ status = f_string_dynamics_increase_by(total, paths);
+ if (F_status_is_error(status)) return status;
+
+ total = 0;
+ }
+
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_t architecture_bits = f_string_dynamic_t_initialize;
+
+ if (f_path_architecture_bits_s.used) {
+ status = f_environment_get(f_path_architecture_bits_s, &architecture_bits);
if (F_status_is_error(status)) return status;
+ }
+
+ if (architecture_bits.used) {
+ status = f_string_dynamic_append_assure(f_path_separator_s, &architecture_bits);
+
+ if (F_status_is_error(status)) {
+ f_string_dynamic_resize(0, &architecture_bits);
+
+ return status;
+ }
+ } else if (!architecture_bits.used && f_path_architecture_bits_default_s.used) {
+ architecture_bits.string = f_path_architecture_bits_default_s.string;
+ architecture_bits.used = f_path_architecture_bits_default_s.used;
+ architecture_bits.size = f_path_architecture_bits_default_s.size;
+ }
+ #endif // _en_kevux_path_architecture_bits_
+
+ for (i = 0; i <= path.used; ++i) {
+
+ if (i == path.used || path.string[i] == f_path_separator_variable_s.string[0]) {
+ #ifdef _en_kevux_path_architecture_bits_
+ if (paths->used + 3 > paths->size) {
+ status = f_string_dynamics_increase(F_memory_default_allocation_small_d + 2, paths);
+ }
+ #else
+ status = f_string_dynamics_increase(F_memory_default_allocation_small_d, paths);
+ #endif // _en_kevux_path_architecture_bits_
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
if (!i) {
paths->array[paths->used++].used = 0;
buffer[k++] = f_path_separator_s.string[0];
}
+ #ifdef _en_kevux_path_architecture_bits_
+ if (f_path_architecture_bits_s.used) {
+ status = f_string_dynamic_increase_by(k + f_path_architecture_bits_s.used, &paths->array[paths->used]);
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
+
+ memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
+ memcpy(paths->array[paths->used].string + k, architecture_bits.string, sizeof(f_char_t) * architecture_bits.used);
+
+ paths->array[paths->used++].used = k + architecture_bits.used;
+ }
+
+ if (f_path_architecture_bits_scripts_s.used) {
+ status = f_string_dynamic_increase_by(k + f_path_architecture_bits_scripts_s.used, &paths->array[paths->used]);
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
+
+ memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
+ memcpy(paths->array[paths->used].string + k, f_path_architecture_bits_scripts_s.string, sizeof(f_char_t) * f_path_architecture_bits_scripts_s.used);
+
+ paths->array[paths->used++].used = k + f_path_architecture_bits_scripts_s.used;
+ }
+ #endif // _en_kevux_path_architecture_bits_
+
status = f_string_dynamic_increase_by(k, &paths->array[paths->used]);
- if (F_status_is_error(status)) return status;
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
}
} // for
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
return F_none;
}
#endif // _di_fl_environment_path_explode_
f_array_length_t last = path.used;
f_array_length_t total = 0;
+ // Do a quick pre-process of PATH to approximate the amount of parts needed, reducing the number of allocations.
+ for (; i <= path.used; ++i) {
+ if (path.string[i] == f_path_separator_variable_s.string[0]) ++total;
+ } // for
+
+ #ifdef _en_kevux_path_architecture_bits_
+ total *= 3;
+ #endif // _en_kevux_path_architecture_bits_
+
+ if (total) {
+ status = f_string_dynamics_increase_by(total, paths);
+ if (F_status_is_error(status)) return status;
+
+ total = 0;
+ }
+
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_t architecture_bits = f_string_dynamic_t_initialize;
+
+ if (f_path_architecture_bits_s.used) {
+ status = f_environment_get(f_path_architecture_bits_s, &architecture_bits);
+ if (F_status_is_error(status)) return status;
+ }
+
+ if (architecture_bits.used) {
+ status = f_string_dynamic_append_assure(f_path_separator_s, &architecture_bits);
+
+ if (F_status_is_error(status)) {
+ f_string_dynamic_resize(0, &architecture_bits);
+
+ return status;
+ }
+ } else if (!architecture_bits.used && f_path_architecture_bits_default_s.used) {
+ architecture_bits.string = f_path_architecture_bits_default_s.string;
+ architecture_bits.used = f_path_architecture_bits_default_s.used;
+ architecture_bits.size = f_path_architecture_bits_default_s.size;
+ }
+ #endif // _en_kevux_path_architecture_bits_
+
for (; i <= path.used; ++i, --r) {
if (i == path.used || path.string[r] == f_path_separator_variable_s.string[0]) {
- status = f_string_dynamics_increase(F_memory_default_allocation_small_d, paths);
- if (F_status_is_error(status)) return status;
+ #ifdef _en_kevux_path_architecture_bits_
+ if (paths->used + 3 > paths->size) {
+ status = f_string_dynamics_increase(F_memory_default_allocation_small_d + 2, paths);
+ }
+ #else
+ status = f_string_dynamics_increase(F_memory_default_allocation_small_d, paths);
+ #endif // _en_kevux_path_architecture_bits_
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
if (!i) {
paths->array[paths->used++].used = 0;
buffer[k++] = f_path_separator_s.string[0];
}
+ #ifdef _en_kevux_path_architecture_bits_
+ if (f_path_architecture_bits_s.used) {
+ status = f_string_dynamic_increase_by(k + f_path_architecture_bits_s.used, &paths->array[paths->used]);
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
+
+ memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
+ memcpy(paths->array[paths->used].string + k, architecture_bits.string, sizeof(f_char_t) * architecture_bits.used);
+
+ paths->array[paths->used++].used = k + architecture_bits.used;
+ }
+
+ if (f_path_architecture_bits_scripts_s.used) {
+ status = f_string_dynamic_increase_by(k + f_path_architecture_bits_scripts_s.used, &paths->array[paths->used]);
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
+
+ memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
+ memcpy(paths->array[paths->used].string + k, f_path_architecture_bits_scripts_s.string, sizeof(f_char_t) * f_path_architecture_bits_scripts_s.used);
+
+ paths->array[paths->used++].used = k + f_path_architecture_bits_scripts_s.used;
+ }
+ #endif // _en_kevux_path_architecture_bits_
+
status = f_string_dynamic_increase_by(k, &paths->array[paths->used]);
- if (F_status_is_error(status)) return status;
+
+ if (F_status_is_error(status)) {
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
+ return status;
+ }
memcpy(paths->array[paths->used].string, buffer, sizeof(f_char_t) * k);
}
} // for
+ #ifdef _en_kevux_path_architecture_bits_
+ f_string_dynamic_resize(0, &architecture_bits);
+ #endif // _en_kevux_path_architecture_bits_
+
return F_none;
}
#endif // _di_fl_environment_path_explode_reverse_