aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_opts.c36
-rw-r--r--src/c_opts.h6
-rw-r--r--src/c_subst.c85
-rw-r--r--src/c_subst.h3
-rw-r--r--src/c_unixize.c2
-rw-r--r--src/c_unixize.h7
-rw-r--r--src/u_utils.c31
7 files changed, 135 insertions, 35 deletions
diff --git a/src/c_opts.c b/src/c_opts.c
index d9dd504..ed3eca8 100644
--- a/src/c_opts.c
+++ b/src/c_opts.c
@@ -62,7 +62,7 @@ c_dump_usage(void)
dprintf(
STDERR_FILENO,
C_USAGE_FMT,
- C_OPTS
+ "ahinpRv"
);
}
@@ -101,24 +101,32 @@ c_recursive_parse
ptr = (char**)argv + 1;
while (*ptr != NULL) {
- if ((*ptr)[1] == 'a') {
+ if ((*ptr)[0] == 'a') {
opts->hidden = TRUE;
}
- else if ((*ptr)[1] == 'i') {
+ else if ((*ptr)[0] == 'i') {
opts->confirm = TRUE;
}
- else if ((*ptr)[1] == 'n') {
+ else if ((*ptr)[0] == 'n') {
opts->hyphen = TRUE;
}
- else if ((*ptr)[1] == 'p') {
+ else if ((*ptr)[0] == 'p') {
opts->pretend = TRUE;
}
- else if ((*ptr)[1] == 'R') {
+ else if ((*ptr)[0] == 'R') {
opts->recursive = TRUE;
}
- else if ((*ptr)[1] == 'v') {
+ else if ((*ptr)[0] == 'v') {
opts->verbose = TRUE;
}
+ else if ((*ptr)[0] == 'e') {
+ if ((*ptr)[1] == '1') {
+ opts->cxx = 1;
+ }
+ else if ((*ptr)[1] == '2') {
+ opts->cxx = 2;
+ }
+ }
ptr++;
}
}
@@ -138,6 +146,7 @@ c_get_opts
opts->pretend = FALSE;
opts->recursive = FALSE;
opts->verbose = FALSE;
+ opts->cxx = 0;
while (
argv[0][0] != C_RECURSIVE_CHAR &&
(opt = getopt(argc, (char *const *)argv, C_OPTS)) != -1
@@ -164,6 +173,19 @@ c_get_opts
else if (opt == 'v') {
opts->verbose = TRUE;
}
+ else if (opt == 'e') {
+ if (u_ischarset(optarg[0], "012") == FALSE) {
+ dprintf(
+ STDERR_FILENO,
+ C_C_OPT_FMT,
+ optarg
+ );
+ exit(2);
+ }
+ else {
+ opts->cxx = optarg[0] - 48;
+ }
+ }
else if (opt == '?') {
c_dump_usage();
exit(1);
diff --git a/src/c_opts.h b/src/c_opts.h
index b7d734f..16ec1de 100644
--- a/src/c_opts.h
+++ b/src/c_opts.h
@@ -48,9 +48,11 @@
#include "c_unixize.h"
-#define C_OPTS "ahinpRv"
+#define C_OPTS "ahinpRve:"
#define C_RECURSIVE_CHAR 'r'
-#define C_USAGE_FMT "usage: unixize [-%s] [directory]\n"
+#define C_USAGE_FMT "usage: unixize [-%s] [-e version] [directory]\n"
+#define C_C_OPT_FMT \
+ "unixize: unsupported -e value '%s' (must be always 0, 1 or 2)\n"
bool_t c_get_opts(struct opts_s*, int, const char*[]);
diff --git a/src/c_subst.c b/src/c_subst.c
index 54a241a..eca90d0 100644
--- a/src/c_subst.c
+++ b/src/c_subst.c
@@ -60,25 +60,77 @@
#include <unistd.h>
static void
+c_ext_subst
+(char filename[],
+ const unsigned char cxx)
+{
+ const size_t len = strlen(filename);
+
+ if (cxx == 0 || len < 4) {
+ return;
+ }
+ if (
+ filename[len - 4] == '.' &&
+ filename[len - 3] == 't' &&
+ filename[len - 2] == 'x' &&
+ filename[len - 1] == 't'
+ ) {
+ filename[len - 4] = 0x00;
+ }
+ else if (
+ filename[len - 4] == '.' &&
+ filename[len - 3] == 'a' &&
+ filename[len - 2] == 's' &&
+ filename[len - 1] == 'm'
+ ) {
+ memcpy(filename + len - 3, "S", 2 * sizeof(char));
+ }
+ else if (
+ filename[len - 4] == '.' &&
+ filename[len - 3] == 'c' &&
+ filename[len - 2] == 'p' &&
+ filename[len - 1] == 'p'
+ ) {
+ if (cxx == 1) {
+ memcpy(filename + len - 3, "cc", 3 * sizeof(char));
+ }
+ else if (cxx == 2) {
+ memcpy(filename + len - 3, "cxx", 4 * sizeof(char));
+ }
+ }
+ else if (
+ filename[len - 4] == '.' &&
+ filename[len - 3] == 'h' &&
+ filename[len - 2] == 'p' &&
+ filename[len - 1] == 'p'
+ ) {
+ if (cxx == 1) {
+ memcpy(filename + len - 3, "hh", 3 * sizeof(char));
+ }
+ else if (cxx == 2) {
+ memcpy(filename + len - 3, "hxx", 4 * sizeof(char));
+ }
+ }
+}
+
+static void
c_classic_subst
(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';
+ if (hyphen == TRUE && *p == '_') {
+ *p = '-';
+ c_classic_subst(filename, hyphen);
+ }
+ if (hyphen == FALSE && *p == '-') {
+ *p = '_';
c_classic_subst(filename, hyphen);
}
- if (u_ischarset(*p, " -") == TRUE) {
+ if (*p == ' ') {
*p = (hyphen == FALSE) ? ('_') : ('-');
c_classic_subst(filename, hyphen);
}
@@ -88,9 +140,10 @@ c_classic_subst
static void
c_subst_current
-(char new_fname[MAXPATHLEN],
- const char og_fname[],
- const bool_t hyphen)
+(char new_fname[MAXPATHLEN],
+ const char og_fname[],
+ const bool_t hyphen,
+ const unsigned char cxx)
{
unsigned char* p;
@@ -100,6 +153,7 @@ c_subst_current
*p = tolower(*p);
p++;
}
+ c_ext_subst(new_fname, cxx);
/* c_unicode_subst(new_fname, hyphen); */
/* c_exascii_subst(new_fname, hyphen); */
c_classic_subst(new_fname, hyphen);
@@ -107,8 +161,9 @@ c_subst_current
struct lfiles_s*
c_subst_filenames
-(struct lfiles_s* og_head,
- bool_t hyphen)
+(struct lfiles_s* og_head,
+ const bool_t hyphen,
+ const unsigned char cxx)
{
struct lfiles_s* dup_head;
struct lfiles_s* link;
@@ -119,7 +174,7 @@ c_subst_filenames
link = NULL;
origin = og_head;
while (origin != NULL) {
- c_subst_current(tmp, origin->filename, hyphen);
+ c_subst_current(tmp, origin->filename, hyphen, cxx);
link = c_lfiles_new(tmp, origin->filetype);
if (link == NULL) {
u_dump_errno();
diff --git a/src/c_subst.h b/src/c_subst.h
index 1ce743f..3f46893 100644
--- a/src/c_subst.h
+++ b/src/c_subst.h
@@ -50,6 +50,7 @@
#include "c_unixize.h"
-struct lfiles_s* c_subst_filenames(struct lfiles_s*, bool_t);
+struct lfiles_s* c_subst_filenames(struct lfiles_s*,
+ const bool_t, const unsigned char);
#endif /* ifndef __C_SUBST_H__ */
diff --git a/src/c_unixize.c b/src/c_unixize.c
index e4b9797..f040011 100644
--- a/src/c_unixize.c
+++ b/src/c_unixize.c
@@ -94,7 +94,7 @@ main
if (og_files == NULL) {
return (0);
}
- new_files = c_subst_filenames(og_files, opts.hyphen);
+ new_files = c_subst_filenames(og_files, opts.hyphen, opts.cxx);
if (new_files == NULL) {
c_lfiles_clear(&og_files);
printf("qwe\n");
diff --git a/src/c_unixize.h b/src/c_unixize.h
index 965ff3f..6765d4b 100644
--- a/src/c_unixize.h
+++ b/src/c_unixize.h
@@ -63,12 +63,13 @@ struct opts_s {
bool_t recursive;
bool_t verbose;
char dir[MAXPATHLEN];
+ unsigned char cxx;
};
struct lfiles_s {
- struct lfiles_s* next;
- char* filename;
- unsigned char filetype;
+ struct lfiles_s* next;
+ char* filename;
+ unsigned char filetype;
};
#endif /* ifndef __C_UNIXIZE_H__ */
diff --git a/src/u_utils.c b/src/u_utils.c
index 75406c8..50f21f2 100644
--- a/src/u_utils.c
+++ b/src/u_utils.c
@@ -99,31 +99,50 @@ static char
u_get_extra_args(char args[], struct opts_s* opts)
{
char i;
+ char null_char;
i = 0;
+ null_char = 0;
args[0] = 0x00;
if (opts->hidden == TRUE) {
- memcpy((char*)args + (i * 3), "-a:", 4 * sizeof(char));
+ memcpy((char*)args + (i * 2), "a:", 3 * sizeof(char));
+ null_char += 2;
i++;
}
if (opts->confirm == TRUE) {
- memcpy((char*)args + (i * 3), "-i:", 4 * sizeof(char));
+ memcpy((char*)args + (i * 2), "i:", 3 * sizeof(char));
+ null_char += 2;
i++;
}
if (opts->hyphen == TRUE) {
- memcpy((char*)args + (i * 3), "-n:", 4 * sizeof(char));
+ memcpy((char*)args + (i * 2), "n:", 3 * sizeof(char));
+ null_char += 2;
i++;
}
if (opts->pretend == TRUE) {
- memcpy((char*)args + (i * 3), "-p:", 4 * sizeof(char));
+ memcpy((char*)args + (i * 2), "p:", 3 * sizeof(char));
+ null_char += 2;
i++;
}
if (opts->verbose == TRUE) {
- memcpy((char*)args + (i * 3), "-v:", 4 * sizeof(char));
+ memcpy((char*)args + (i * 2), "v:", 3 * sizeof(char));
+ null_char += 2;
i++;
}
+ if (opts->cxx != 0) {
+ if (opts->cxx == 1) {
+ memcpy((char*)args + (i * 2), "e1:", 4 * sizeof(char));
+ null_char += 3;
+ i++;
+ }
+ else {
+ memcpy((char*)args + (i * 2), "e2:", 4 * sizeof(char));
+ null_char += 3;
+ i++;
+ }
+ }
if (i > 0) {
- *(args + (i * 3) - 1) = 0x00;
+ *(args + null_char) = 0x00;
}
return (i);
}