Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/sort/bwstring.h
Show All 40 Lines | |||||
#include "sort.h" | #include "sort.h" | ||||
#include "mem.h" | #include "mem.h" | ||||
extern bool byte_sort; | extern bool byte_sort; | ||||
/* wchar_t is of 4 bytes: */ | /* wchar_t is of 4 bytes: */ | ||||
#define SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t)) | #define SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t)) | ||||
struct wstr { | |||||
size_t len; | |||||
wchar_t str[]; | |||||
}; | |||||
struct cstr { | |||||
size_t len; | |||||
char str[]; | |||||
}; | |||||
/* | /* | ||||
* Binary "wide" string | * Binary "wide" string | ||||
*/ | */ | ||||
struct bwstring | struct bwstring | ||||
{ | { | ||||
size_t len; | union { | ||||
union | struct wstr wdata; | ||||
{ | struct cstr cdata; | ||||
wchar_t wstr[0]; | |||||
unsigned char cstr[0]; | |||||
} data; | |||||
}; | }; | ||||
}; | |||||
struct reader_buffer | struct reader_buffer | ||||
{ | { | ||||
wchar_t *fgetwln_z_buffer; | wchar_t *fgetwln_z_buffer; | ||||
size_t fgetwln_z_buffer_size; | size_t fgetwln_z_buffer_size; | ||||
}; | }; | ||||
typedef void *bwstring_iterator; | typedef void *bwstring_iterator; | ||||
#define BWSLEN(s) ((s)->len) | #define BWSLEN(s) ((mb_cur_max == 1) ? (s)->cdata.len : (s)->wdata.len) | ||||
markj: Can't this be `mb_cur_max` instead? I guess it ought to be irrelevant since both branches do… | |||||
Done Inline ActionsAh good catch, I missed this one while rebasing. arichardson: Ah good catch, I missed this one while rebasing. | |||||
struct bwstring *bwsalloc(size_t sz); | struct bwstring *bwsalloc(size_t sz); | ||||
size_t bwsrawlen(const struct bwstring *bws); | size_t bwsrawlen(const struct bwstring *bws); | ||||
const void* bwsrawdata(const struct bwstring *bws); | const void* bwsrawdata(const struct bwstring *bws); | ||||
void bws_setlen(struct bwstring *bws, size_t newlen); | void bws_setlen(struct bwstring *bws, size_t newlen); | ||||
size_t bws_memsize(const struct bwstring *bws); | size_t bws_memsize(const struct bwstring *bws); | ||||
double bwstod(struct bwstring *s0, bool *empty); | double bwstod(struct bwstring *s0, bool *empty); | ||||
int bws_month_score(const struct bwstring *s0); | int bws_month_score(const struct bwstring *s0); | ||||
Show All 18 Lines | |||||
int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset); | int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset); | ||||
size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended); | size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended); | ||||
struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb); | struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb); | ||||
static inline bwstring_iterator | static inline bwstring_iterator | ||||
bws_begin(struct bwstring *bws) | bws_begin(struct bwstring *bws) | ||||
{ | { | ||||
return (bwstring_iterator) (&(bws->data)); | return ((bwstring_iterator)bws->wdata.str); | ||||
} | } | ||||
static inline bwstring_iterator | static inline bwstring_iterator | ||||
bws_end(struct bwstring *bws) | bws_end(struct bwstring *bws) | ||||
{ | { | ||||
return ((mb_cur_max == 1) ? | return ((mb_cur_max == 1) ? | ||||
(bwstring_iterator) (bws->data.cstr + bws->len) : | (bwstring_iterator) (bws->cdata.str + bws->cdata.len) : | ||||
(bwstring_iterator) (bws->data.wstr + bws->len)); | (bwstring_iterator) (bws->wdata.str + bws->wdata.len)); | ||||
} | } | ||||
static inline bwstring_iterator | static inline bwstring_iterator | ||||
bws_iterator_inc(bwstring_iterator iter, size_t pos) | bws_iterator_inc(bwstring_iterator iter, size_t pos) | ||||
{ | { | ||||
if (mb_cur_max == 1) | if (mb_cur_max == 1) | ||||
return ((unsigned char *) iter) + pos; | return ((unsigned char *) iter) + pos; | ||||
Show All 9 Lines | if (mb_cur_max == 1) | ||||
return *((unsigned char *) iter); | return *((unsigned char *) iter); | ||||
else | else | ||||
return *((wchar_t*) iter); | return *((wchar_t*) iter); | ||||
} | } | ||||
int | int | ||||
bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len); | bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len); | ||||
#define BWS_GET(bws, pos) ((mb_cur_max == 1) ? ((bws)->data.cstr[(pos)]) : (bws)->data.wstr[(pos)]) | #define BWS_GET(bws, pos) ((mb_cur_max == 1) ? (bws->cdata.str[(pos)]) : bws->wdata.str[(pos)]) | ||||
void initialise_months(void); | void initialise_months(void); | ||||
#endif /* __BWSTRING_H__ */ | #endif /* __BWSTRING_H__ */ |
Can't this be mb_cur_max instead? I guess it ought to be irrelevant since both branches do the same thing.