diff options
author | jozan <jozan@noemail.net> | 2020-11-08 15:12:45 +0000 |
---|---|---|
committer | jozan <jozan@noemail.net> | 2020-11-08 15:12:45 +0000 |
commit | 265692f3d2009b49cd7436c1034b0846cbc856a5 (patch) | |
tree | 0d115f62e45b7e3ca243db9948223f5af892cb17 | |
parent | Trying wchar_t (diff) | |
download | unixize-265692f3d2009b49cd7436c1034b0846cbc856a5.tar.gz unixize-265692f3d2009b49cd7436c1034b0846cbc856a5.tar.bz2 unixize-265692f3d2009b49cd7436c1034b0846cbc856a5.tar.xz unixize-265692f3d2009b49cd7436c1034b0846cbc856a5.tar.zst unixize-265692f3d2009b49cd7436c1034b0846cbc856a5.zip |
I can use unicode now!
FossilOrigin-Name: 4ca709ec2cb6da28780e0135b3be84c028c5db3513437844cb1e48a2180332cd
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/c_subst.c | 131 | ||||
-rw-r--r-- | src/c_subst.h | 55 | ||||
-rw-r--r-- | src/u_utils.c | 8 | ||||
-rw-r--r-- | src/u_utils.h | 2 |
5 files changed, 192 insertions, 5 deletions
@@ -28,6 +28,7 @@ CFLAGS = -std=c89 CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Werror +CFLAGS += -Wno-unicode CFLAGS += -pedantic RM = rm -rf diff --git a/src/c_subst.c b/src/c_subst.c new file mode 100644 index 0000000..95595ea --- /dev/null +++ b/src/c_subst.c @@ -0,0 +1,131 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * unixize: src/c_subst.c + * 2020-11-08 02:50 + * Joe + * + * This is were we subsitute the new names and return them into a + * new lfiles_s linked list. + */ + +#include <sys/param.h> + +#include <ctype.h> +#include <stddef.h> +#include <string.h> + +#include "c_lfiles.h" +#include "c_unixize.h" +#include "u_utils.h" + +#include <stdio.h> +#include <unistd.h> + +static void +c_subst_normal +(char filename[], + const bool_t hyphen) +{ + char *p; + + dprintf(STDOUT_FILENO, "%s\n", filename); + p = (char*)filename; + while (*p != 0x00) { + if (u_ischarset(*p, "\u00f0") == TRUE) { + memmove( + p, + p + 1, + (strlen(p + 1) + 1) * sizeof(char) + ); + *p = 'd'; + c_subst_normal(filename, hyphen); + } + if (u_ischarset(*p, " -") == TRUE) { + *p = (hyphen == FALSE) ? ('_') : ('-'); + c_subst_normal(filename, hyphen); + } + p++; + } +} + +static void +c_subst_current +(char new_fname[MAXPATHLEN], + const char og_fname[], + const bool_t hyphen) +{ + unsigned char* p; + + strlcpy(new_fname, og_fname, MAXPATHLEN); + p = (unsigned char*)new_fname; + while (*p != 0x00) { + *p = tolower(*p); + p++; + } + c_subst_normal(new_fname, hyphen); +} + +struct lfiles_s* +c_subst_filenames +(struct lfiles_s* og_head, + bool_t hyphen) +{ + struct lfiles_s* dup_head; + struct lfiles_s* link; + struct lfiles_s* origin; + char tmp[MAXPATHLEN]; + + dup_head = NULL; + link = NULL; + origin = og_head; + while (origin != NULL) { + c_subst_current(tmp, origin->filename, hyphen); + link = c_lfiles_new(tmp, origin->filetype); + if (link == NULL) { + u_dump_errno(); + c_lfiles_clear(&dup_head); + return (NULL); + } + c_lfiles_add_back(&dup_head, link); + origin = origin->next; + } + return (dup_head); +} diff --git a/src/c_subst.h b/src/c_subst.h new file mode 100644 index 0000000..1ce743f --- /dev/null +++ b/src/c_subst.h @@ -0,0 +1,55 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2020 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * unixize: src/c_subst.h + * 2020-11-08 02:48 + * Joe + * + * This is the main function and entrypoint of the program. + */ + +#ifndef __C_SUBST_H__ +#define __C_SUBST_H__ + +#include "c_unixize.h" + +struct lfiles_s* c_subst_filenames(struct lfiles_s*, bool_t); + +#endif /* ifndef __C_SUBST_H__ */ diff --git a/src/u_utils.c b/src/u_utils.c index cc2f893..75406c8 100644 --- a/src/u_utils.c +++ b/src/u_utils.c @@ -218,12 +218,12 @@ u_decrease_subpath(char subp[]) bool_t u_ischarset -(wchar_t c, - const wchar_t cs[]) +(wchar_t c, + const char cs[]) { - wchar_t *p; + char *p; - p = (wchar_t*)cs; + p = (char*)cs; while (*p != 0x00 && *p != c) { p++; } diff --git a/src/u_utils.h b/src/u_utils.h index 499b15a..058ef7a 100644 --- a/src/u_utils.h +++ b/src/u_utils.h @@ -54,4 +54,4 @@ void u_del_nargv(char** nargv); char** u_get_nargv(struct opts_s*); void u_increase_subpath(char[], const char[]); void u_decrease_subpath(char[]); -bool_t u_ischarset(wchar_t, const wchar_t[]); +bool_t u_ischarset(wchar_t, const char[]); |