diff options
-rw-r--r-- | .fossil-settings/ignore-glob | 1 | ||||
-rw-r--r-- | TODO.org | 12 | ||||
-rw-r--r-- | src/c_opts.c | 6 | ||||
-rw-r--r-- | src/c_opts.h | 3 | ||||
-rw-r--r-- | src/c_subst.c | 50 | ||||
-rw-r--r-- | src/c_subst.h | 2 | ||||
-rw-r--r-- | src/c_unixize.c | 1 |
7 files changed, 56 insertions, 19 deletions
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob index ad8fb99..14b1716 100644 --- a/.fossil-settings/ignore-glob +++ b/.fossil-settings/ignore-glob @@ -2,3 +2,4 @@ obj unixize git compile_flags.txt +test @@ -1,10 +1,12 @@ #+TITLE: TODO list for unixize -* TODO subst - -* TODO remove malloc for recursive main [0/2] - - [ ] Remove them / go stack - - [ ] Check "= \0" int c_opts.c:c_recursive_parse +* DONE remove malloc for recursive main [2/2] + - [X] Remove them / go stack + - [X] Check "= \0" int c_opts.c:c_recursive_parse * DONE scanf static-like issue CLOSED: [2020-11-06 Fri 5:04] + +* TODO subst extended ascii + +* TODO subst unicode diff --git a/src/c_opts.c b/src/c_opts.c index ed3eca8..f129cbf 100644 --- a/src/c_opts.c +++ b/src/c_opts.c @@ -59,11 +59,7 @@ static void c_dump_usage(void) { - dprintf( - STDERR_FILENO, - C_USAGE_FMT, - "ahinpRv" - ); + dprintf(STDERR_FILENO, C_USAGE_FMT); } static bool_t diff --git a/src/c_opts.h b/src/c_opts.h index 16ec1de..6587f51 100644 --- a/src/c_opts.h +++ b/src/c_opts.h @@ -50,7 +50,8 @@ #define C_OPTS "ahinpRve:" #define C_RECURSIVE_CHAR 'r' -#define C_USAGE_FMT "usage: unixize [-%s] [-e version] [directory]\n" +#define C_USAGE_FMT \ + "usage: unixize [-ahinpRv] [-e version] [directory]\n" #define C_C_OPT_FMT \ "unixize: unsupported -e value '%s' (must be always 0, 1 or 2)\n" diff --git a/src/c_subst.c b/src/c_subst.c index eca90d0..3fce51f 100644 --- a/src/c_subst.c +++ b/src/c_subst.c @@ -53,6 +53,7 @@ #include <string.h> #include "c_lfiles.h" +#include "c_subst.h" #include "c_unixize.h" #include "u_utils.h" @@ -119,28 +120,62 @@ c_classic_subst const bool_t hyphen) { char *p; + const char sep = (hyphen == FALSE) ? ('_') : ('-'); + const char c_sep = (hyphen == FALSE) ? ('-') : ('_'); p = (char*)filename; while (*p != 0x00) { - if (hyphen == TRUE && *p == '_') { - *p = '-'; + if (*p == c_sep) { + *p = sep; c_classic_subst(filename, hyphen); } - if (hyphen == FALSE && *p == '-') { - *p = '_'; + if (*p == sep && *(p + 1) == sep) { + memmove(p, p + 1, strlen(p + 1) * sizeof(char)); c_classic_subst(filename, hyphen); } if (*p == ' ') { - *p = (hyphen == FALSE) ? ('_') : ('-'); + *p = sep; c_classic_subst(filename, hyphen); } + if ( + isalnum(*p) == 0 && + u_ischarset(*p, C_CHARSET_VALID) == FALSE + ) { + } + p++; + } +} + +static void +c_num_prefix_subst(char filename[]) +{ + char *p; + char *p_probe; + + p = filename; + while (*p != 0x00) { + if (isdigit(*p) == 0) { + if (*p != '.') { + return; + } + else { + p_probe = p + 1; + while (*p_probe != 0x00 && *p_probe == '.') { + p_probe++; + } + if (*p_probe != 0x00) { + *p = '_'; + } + return; + } + } p++; } } static void c_subst_current -(char new_fname[MAXPATHLEN], +(char new_fname[], const char og_fname[], const bool_t hyphen, const unsigned char cxx) @@ -154,8 +189,9 @@ c_subst_current p++; } c_ext_subst(new_fname, cxx); - /* c_unicode_subst(new_fname, hyphen); */ + c_num_prefix_subst(new_fname); /* c_exascii_subst(new_fname, hyphen); */ + /* c_unicode_subst(new_fname, hyphen); */ c_classic_subst(new_fname, hyphen); } diff --git a/src/c_subst.h b/src/c_subst.h index 3f46893..3ca4d65 100644 --- a/src/c_subst.h +++ b/src/c_subst.h @@ -50,6 +50,8 @@ #include "c_unixize.h" +#define C_CHARSET_VALID "_." + struct lfiles_s* c_subst_filenames(struct lfiles_s*, const bool_t, const unsigned char); diff --git a/src/c_unixize.c b/src/c_unixize.c index f040011..324d358 100644 --- a/src/c_unixize.c +++ b/src/c_unixize.c @@ -97,7 +97,6 @@ main new_files = c_subst_filenames(og_files, opts.hyphen, opts.cxx); if (new_files == NULL) { c_lfiles_clear(&og_files); - printf("qwe\n"); return (1); } og_files_head = og_files; |