Re: git smart http for busybox repo

2020-04-13 Thread wdlkmpx
[sending again without duplicated text cos this mail madness is too confusing]

I apologize for the previous message and the following message. It's a
mistake I know, but here it goes. And I hope it goes unpunished.

I'm not sure why the busybox git repo hasn't enabled the smart git
http, depth=1

It's true, github is smart. It lets you search git history, the pull
request history, the issues history, the history of mankind, and let's
you do many things, see statistics, the network of forks and see the
big picture.

Pull requests can be discussed and changed accordingly, and in fact
people can see how your pull request evolves, with colors and
everything. When in doubt, people usually open issues first to see if
a feature or a possible patch is desired.

Anything that can be done through email can also be done through
github issues, you can attach images, files, patches, etc, that anyone
can download and see.

I found that github is the closest thing to `git bisect` when it comes
to try to identify an issue.

And no, I'm not posting any patch to this mailing list or any mailing
list for that matter.

That's smart, fact. And I can't think of anything smarter than that.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: git smart http for busybox repo

2020-04-13 Thread wdlkmpx
[sending to the correct recipient]

I apologize for the previous message and the following message. It's a
mistake I know, but here it goes. And I hope it goes unpunished.

I'm not sure why the busybox git repo hasn't enabled the smart git
http, --depth=1, but github already supports that among many other
smart features.

It's true, github is smart. It lets you search git history, the pull
request history, the issues history, the history of mankind, and let's
you do many things, see statistics, the network of forks and see the
big picture.

Pull requests can be discussed and changed accordingly, and in fact
people can see how your pull request evolves, with colors and
everything. When in doubt, people usually open issues first to see if
a feature or a possible patch is desired.

Anything that can be done through email can also be done through
github issues, you can attach images, files, patches, etc, that anyone
can download and see.

I found that github is the closest thing to `git bisect` when it comes
to try to identify an issue.

And no, I'm not posting any patch to this mailing list or any mailing
list for that matter.

That's smart, fact. And I can't think of anything smarter than that.
>
I apologize for the previous message and the following message. It's a
mistake I know, but here it goes. And I hope it goes unpunished.

I'm not sure why the busybox git repo hasn't enabled the smart git
http, --depth=1

It's true, github is smart. It lets you search git history, the pull
request history, the issues history, the history of mankind, and let's
you do many things, see statistics, the network of forks and see the
big picture.

Pull requests can be discussed and changed accordingly, and in fact
people can see how your pull request evolves, with colors and
everything. When in doubt, people usually open issues first to see if
a feature or a possible patch is desired.

Anything that can be done through email can also be done through
github issues, you can attach images, files, patches, etc, that anyone
can download and see.

I found that github is the closest thing to `git bisect` when it comes
to try to identify an issue.

And no, I'm not posting any patch to this mailing list or any mailing
list for that matter.

That's smart, fact. And I can't think of anything smarter than that.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: git smart http for busybox repo

2020-04-13 Thread wdlkmpx
busybox should be moved to github or gitlab, that's really smart http

But tracker + git repo + releases + pull requests. As complete as it gets.

No need to send patches through email, even people who don't have git
installed can use the web site to edit files and open pull requests.

It's just too smart.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] xz/unxz --help: -t is supported

2019-11-07 Thread wdlkmpx
patch attached
From 780c945a3d65ae19f5ee5e2b1824e7cf29303f5c Mon Sep 17 00:00:00 2001
From: wdlkmpx 
Date: Fri, 8 Nov 2019 00:15:20 +0800
Subject: [PATCH] xz/unxz --help: -t is supported

---
 archival/bbunzip.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index d31aaf7f3..51b06ff21 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -536,6 +536,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
 //usage: "\n	-c	Write to stdout"
 //usage: "\n	-f	Force"
 //usage: "\n	-k	Keep input files"
+//usage: "\n	-t	Test compressed file integrity"
 //usage:
 //usage:#define xz_trivial_usage
 //usage:   "-d [-cfk] [FILE]..."
@@ -545,6 +546,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
 //usage: "\n	-c	Write to stdout"
 //usage: "\n	-f	Force"
 //usage: "\n	-k	Keep input files"
+//usage: "\n	-t	Test compressed file integrity"
 //usage:
 //usage:#define xzcat_trivial_usage
 //usage:   "[FILE]..."
-- 
2.11.0

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] dc: support GNU dc options (-e/--expression -f/--file)

2018-04-05 Thread wdlkmpx
I see the patch title might be misleading.. this just adds a
compatibility layer through -e and -f, but does not implement any
additional DC commands. In fact i'm reading the gnu dc manual for the
first time ahaha.

The busybox dc can be considered a subset of the gnu dc.. with a few
incompatibilies... the gnu dc does not recognize 'add mul mod div' but
'+ * % /' etc.. the busybox dc recognizes both..

Testing the patch..

In this quick test providing the same "portable" params you can see
that both dc's behave the same..

However this is something i just found out:
The busybox dc expects a EXPRESSION if no -opts are provided.. this is
the default behavior that is not changing... but the gnu dc expects a
FILE if no -opts are provided...

// BUSYBOX DC

# ./busybox dc "10 10 * p"
100

# ./busybox dc -e
dc: option requires an argument -- 'e'
...
# ./busybox dc -e "10 10 * p"
100
# ./busybox dc --expression=

# ./busybox dc --expresion="10 10 * p"
100

# echo "10 10 * p" > dc.in

# ./busybox dc -f dc.in
100
# ./busybox dc --file=
dc: : No such file or directory
# ./busybox dc --file=dc.in
100
# ./busybox dc -a
dc: invalid option -- 'a'



// GNU DC

# dc "10 10 * p"
dc: Could not open file 10 10 * p

# dc -e
dc: option requires an argument -- 'e'
.
# dc -e "10 10 * p"
100
# dc --expression=

# dc --expression="10 10 * p"
100

# echo "10 10 * p" > dc.in

# dc -f dc.in
100
# dc --file=
dc: Could not open file
# dc --file=dc.in
100
# dc -a
dc: invalid option -- 'a'
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] dc: support GNU dc options (-e/--expression -f/--file)

2018-04-04 Thread wdlkmpx
keep the current behavior but also take arguments: -e and -f
to make it compatible with GNU dc.

dc expr = dc -e expr = dc --expression=expr
---
 miscutils/dc.c | 46 --
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/miscutils/dc.c b/miscutils/dc.c
index b922a7184..42771f125 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -22,7 +22,8 @@
 //kbuild:lib-$(CONFIG_DC) += dc.o
 
 //usage:#define dc_trivial_usage
-//usage:   "EXPRESSION..."
+//usage:   "[-e] EXPRESSION\n"
+//usage:   "or:dc  -f  FILE"
 //usage:
 //usage:#define dc_full_usage "\n\n"
 //usage:   "Tiny RPN calculator. Operations:\n"
@@ -287,8 +288,7 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
 {
INIT_G();
 
-   argv++;
-   if (!argv[0]) {
+   if (argc < 2) {
/* take stuff from stdin if no args are given */
char *line;
while ((line = xmalloc_fgetline(stdin)) != NULL) {
@@ -296,9 +296,43 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
free(line);
}
} else {
-   do {
-   stack_machine(*argv);
-   } while (*++argv);
+
+   unsigned opts;
+   char *file_str, *exp_str = NULL;
+   enum {
+   OPT_EXPRESSION  = (1 << 0),
+   OPT_FILE = (1 << 1),
+   };
+
+#if ENABLE_LONG_OPTS
+   static const char dc_longopts[] ALIGN1 =
+   /* name has_arg short */
+   "expression\0"  Required_argument   "e"
+   "file\0"Required_argument   "f";
+   opts = getopt32long(argv, "e:f:" "\0", dc_longopts, &exp_str, 
&file_str);
+#else
+   opts = getopt32(argv, "e:f:" "\0", &exp_str, &file_str);
+#endif
+   argv += optind;
+
+   if (!(opts & OPT_FILE)) {
+   if (exp_str) { // -e
+   stack_machine(exp_str);
+   } else { // no opts
+   do {
+   stack_machine(*argv);
+   } while (*++argv);
+   }
+   } else { // -f
+   char *line;
+   FILE *cmdfile;
+   cmdfile = xfopen_stdin(file_str);
+   while ((line = xmalloc_fgetline(cmdfile)) != NULL) {
+   stack_machine(line);
+   free(line);
+   }
+   fclose_if_not_stdin(cmdfile);
+   }
}
return EXIT_SUCCESS;
 }
-- 
2.11.0

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: bbox: musl versus uclibc

2017-08-14 Thread wdlkmpx
I'm sure there was plenty of people willing to contribute  to uclibc,
there is even an updated fork.

The project has been badly managed.. thats the only reason i can think
of for this situation  to happen

On 8/14/17, Denys Vlasenko  wrote:
> As uclibc is increasingly aging, I am finally forced
> to switch to musl: I'm bitten by a nasty bug in
> getopt() - hush is using it in a slightly unusual way,
> which uclibc does not expect.
>
> I built a toolchain using
> https://github.com/richfelker/musl-cross-make
> (Rich, is this the thing I should be using?)
> and it worked with no issues at all.
>
> (I can probably only wish for the README
> to also mention how to make this a _static_
> toolchain... I have a box with 32-bit userspace,
> would be awesome to be able to copy this fresh
> 64-bit toolchain to it and have it working).
>
> Then I built busybox. Impressions:
>
> Only a few options did not build:
> EXTRA_COMPAT and FEATURE_VI_REGEX_SEARCH
> failed because they need GNU regexp extensions.
> FEATURE_MOUNT_NFS and FEATURE_INETD_RPC do not build
> because they need rpc/rpc.h.
> Not complaining, since them being in libc was a mistake
> in the first place.
>
> Now, the good news - musl has smaller data!
> 6695 bytes versus 7129 bytes for uclibc:
>
>text  data   bss dechex filename
>  894902   465  6664  902031  dc38f busybox.uclibc
>  912538   563  6132  919233  e06c1 busybox.musl
>
> Whee!
> ___
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] (v2) volume_id: add minix detection

2016-05-30 Thread wdlkmpx
---
 util-linux/volume_id/minix.c  | 98 +++
 util-linux/volume_id/unused_minix.c   | 86 ---
 util-linux/volume_id/volume_id.c  |  2 +-
 util-linux/volume_id/volume_id_internal.h |  2 +-
 4 files changed, 100 insertions(+), 88 deletions(-)
 create mode 100644 util-linux/volume_id/minix.c
 delete mode 100644 util-linux/volume_id/unused_minix.c

diff --git a/util-linux/volume_id/minix.c b/util-linux/volume_id/minix.c
new file mode 100644
index 000..debda63
--- /dev/null
+++ b/util-linux/volume_id/minix.c
@@ -0,0 +1,98 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2005 Kay Sievers 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+//kbuild: lib-$(CONFIG_FEATURE_VOLUMEID_MINIX) += minix.o
+
+//config:
+//config: config FEATURE_VOLUMEID_MINIX
+//config:  bool "minix filesystem"
+//config:  default n
+//config:  depends on VOLUMEID
+//config:  help
+//config:TODO
+//config:
+
+#include "volume_id_internal.h"
+
+struct minix_super_block {
+   uint16_ts_ninodes;
+   uint16_ts_nzones;
+   uint16_ts_imap_blocks;
+   uint16_ts_zmap_blocks;
+   uint16_ts_firstdatazone;
+   uint16_ts_log_zone_size;
+   uint32_ts_max_size;
+   uint16_ts_magic;
+   uint16_ts_state;
+   uint32_ts_zones;
+} PACKED;
+
+/* V3 minix super-block data on disk */
+struct minix3_super_block {
+   uint32_ts_ninodes;
+   uint16_ts_pad0;
+   uint16_ts_imap_blocks;
+   uint16_ts_zmap_blocks;
+   uint16_ts_firstdatazone;
+   uint16_ts_log_zone_size;
+   uint16_ts_pad1;
+   uint32_ts_max_size;
+   uint32_ts_zones;
+   uint16_ts_magic;
+   uint16_ts_pad2;
+   uint16_ts_blocksize;
+   uint8_t s_disk_version;
+} PACKED;
+
+#define MINIX_SUPERBLOCK_OFFSET0x400
+
+int FAST_FUNC volume_id_probe_minix(struct volume_id *id /*, uint64_t off*/)
+{
+#define off ((uint64_t)0)
+   struct minix_super_block *ms;
+   struct minix3_super_block *ms3;
+
+   dbg("probing at offset 0x%llx", (unsigned long long) off);
+
+   ms = volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200);
+   if (ms == NULL)
+   return -1;
+   if (ms->s_magic == cpu_to_le16(0x137F)) /* minix V1 fs, 14 char names */
+   goto found;
+   if (ms->s_magic == cpu_to_le16(0x138F)) /* minix V1 fs, 30 char names */
+   goto found;
+   if (ms->s_magic == cpu_to_le16(0x2468)) /* minix V2 fs, 14 char names */
+   goto found;
+   if (ms->s_magic == cpu_to_le16(0x2478)) /* minix V2 fs, 30 char names */
+   goto found;
+
+   ms3 = volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200);
+   if (ms3 == NULL)
+   return -1;
+   if (ms3->s_magic == cpu_to_le16(0x4d5a)) /* minix V3 fs, 60 char names 
*/
+   goto found;
+
+   return -1;
+
+ found:
+// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
+   IF_FEATURE_BLKID_TYPE(id->type = "minix";)
+   return 0;
+}
diff --git a/util-linux/volume_id/unused_minix.c 
b/util-linux/volume_id/unused_minix.c
deleted file mode 100644
index 50afd5c..000
--- a/util-linux/volume_id/unused_minix.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * volume_id - reads filesystem label and uuid
- *
- * Copyright (C) 2005 Kay Sievers 
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * Lic

[PATCH] volume_id: add minix detection

2016-05-30 Thread wdlkmpx
---
 util-linux/volume_id/minix.c  | 71 +
 util-linux/volume_id/unused_minix.c   | 86 ---
 util-linux/volume_id/volume_id.c  |  2 +-
 util-linux/volume_id/volume_id_internal.h |  2 +-
 4 files changed, 73 insertions(+), 88 deletions(-)
 create mode 100644 util-linux/volume_id/minix.c
 delete mode 100644 util-linux/volume_id/unused_minix.c

diff --git a/util-linux/volume_id/minix.c b/util-linux/volume_id/minix.c
new file mode 100644
index 000..f9edf3e
--- /dev/null
+++ b/util-linux/volume_id/minix.c
@@ -0,0 +1,71 @@
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2005 Kay Sievers 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+//kbuild: lib-$(CONFIG_FEATURE_VOLUMEID_MINIX) += minix.o
+
+//config:
+//config: config FEATURE_VOLUMEID_MINIX
+//config:  bool "minix filesystem"
+//config:  default n
+//config:  depends on VOLUMEID
+//config:  help
+//config:TODO
+//config:
+
+#include "volume_id_internal.h"
+
+struct minix_super_block {
+   uint16_ts_ninodes;
+   uint16_ts_nzones;
+   uint16_ts_imap_blocks;
+   uint16_ts_zmap_blocks;
+   uint16_ts_firstdatazone;
+   uint16_ts_log_zone_size;
+   uint32_ts_max_size;
+   uint16_ts_magic;
+   uint16_ts_state;
+   uint32_ts_zones;
+} PACKED;
+
+#define MINIX_SUPERBLOCK_OFFSET0x400
+
+int FAST_FUNC volume_id_probe_minix(struct volume_id *id /*, uint64_t off*/)
+{
+#define off ((uint64_t)0)
+   struct minix_super_block *ms;
+
+   dbg("probing at offset 0x%llx", (unsigned long long) off);
+
+   ms = volume_id_get_buffer(id, off + MINIX_SUPERBLOCK_OFFSET, 0x200);
+   if (ms == NULL)
+   return -1;
+
+   if (ms->s_magic == cpu_to_le16(0x137F)) goto found; /* minix V1 fs, 14 
char names */
+   if (ms->s_magic == cpu_to_le16(0x138F)) goto found; /* minix V1 fs, 30 
char names */
+   if (ms->s_magic == cpu_to_le16(0x2468)) goto found; /* minix V2 fs, 14 
char names */
+   if (ms->s_magic == cpu_to_le16(0x2478)) goto found; /* minix V2 fs, 30 
char names */
+   if (ms->s_magic == cpu_to_le16(0x4d5a)) goto found; /* minix V3 fs, 60 
char names */
+   return -1;
+
+ found:
+// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
+   IF_FEATURE_BLKID_TYPE(id->type = "minix";)
+   return 0;
+}
diff --git a/util-linux/volume_id/unused_minix.c 
b/util-linux/volume_id/unused_minix.c
deleted file mode 100644
index 50afd5c..000
--- a/util-linux/volume_id/unused_minix.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * volume_id - reads filesystem label and uuid
- *
- * Copyright (C) 2005 Kay Sievers 
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MINIX) += minix.o
-
-//config:
-//config:### config FEATURE_VOLUMEID_MINIX
-//config:###   bool "minix filesystem"
-//config:###   default y
-//config:###   depends on VOLUMEID
-//config:###   help
-//config:### TODO
-//config:
-
-#include "volume_id_internal.h"
-
-struct minix_super_block {
-   uint16_ts_ninodes;
-   uint16_ts_nzones;
-   uint16_ts_imap_blocks;
-   uint16_ts_zmap_blocks;
-   uint16_ts_firstdatazone;
-   uint16_ts_log_zone_size;
-   uint32_ts_max_size;
-   uint16_ts_magic;
-   uint16

[PATCH] New applet: vercmp (compare version strings)

2016-05-27 Thread wdlkmpx
Usage: vercmp version1 lt|gt|le|ge|eq version2
return value 0 if true, else 1

It's a shorter version of this:
http://svn.openmoko.org/trunk/src/host/opkg-utils/opkg-compare-versions.c

It produces the same results..

It's meant to work like this:

ver1="3.1.2-9"
ver2="3.1.3-1"

if vercmp ${ver1} gt ${ver2} ; then
..actions..
fi

or you can uncomment this line:

//printf("%s\n", res == 0 ? "true" : "false");

Then it will print true or false, it's up to you..

This is just a suggestion in the form of a patch..
---
 miscutils/vercmp.c | 83 ++
 1 file changed, 83 insertions(+)
 create mode 100644 miscutils/vercmp.c

diff --git a/miscutils/vercmp.c b/miscutils/vercmp.c
new file mode 100644
index 000..67af35b
--- /dev/null
+++ b/miscutils/vercmp.c
@@ -0,0 +1,83 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * libdpkg - Debian packaging suite library routines
+ * vercmp.c - comparison of version numbers
+ *
+ * Copyright (C) 1995 Ian Jackson 
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree
+ */
+
+//applet:IF_VERCMP(APPLET(vercmp, BB_DIR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_VERCMP) += vercmp.o
+
+//config:config VERCMP
+//config:  bool "vercmp"
+//config:  default n
+//config:  help
+//config:Compare version strings
+
+//usage:#define vercmp_trivial_usage
+//usage:   "version1 lt|gt|le|ge|eq version2"
+//usage:#define vercmp_full_usage "\n\n"
+//usage:   "return value 0 if true, else 1\n\n"
+//usage:   "l = less, g = greater, t = than, e|eq = equal"
+
+#include "libbb.h"
+
+static int ver_cmp(const char *val, const char *ref)
+{
+   int vc, rc;
+   long vl, rl;
+   const char *vp, *rp;
+   const char *vsep, *rsep;
+
+   for (;;) {
+   vp= val;  while (*vp && !isdigit(*vp)) vp++;
+   rp= ref;  while (*rp && !isdigit(*rp)) rp++;
+   for (;;) {
+   vc= val == vp ? 0 : *val++;
+   rc= ref == rp ? 0 : *ref++;
+   if (!rc && !vc) break;
+   if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII 
character set */
+   if (rc && !isalpha(rc)) rc += 256;
+   if (vc != rc) return vc - rc;
+   }
+   val= vp;
+   ref= rp;
+   vl=0;  if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
+   rl=0;  if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
+   if (vl != rl) return vl - rl;
+
+   vc = *val;
+   rc = *ref;
+   vsep = strchr(".-", vc);
+   rsep = strchr(".-", rc);
+   if (vsep && !rsep) return -1;
+   if (!vsep && rsep) return +1;
+
+   if (!*val && !*ref) return 0;
+   if (!*val) return -1;
+   if (!*ref) return +1;
+   }
+}
+
+int vercmp_main (int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int vercmp_main (int argc, char **argv)
+{
+   int r, res;
+   if (argc < 4) bb_show_usage();
+   if (*argv[1] == '\0' || *argv[3] == '\0') bb_show_usage();
+   r = ver_cmp(argv[1], argv[3]);
+
+   if  (!strcmp(argv[2], "le")) res = !(r <= 0);
+   else if (!strcmp(argv[2], "ge")) res = !(r >= 0);
+   else if (!strcmp(argv[2], "lt")) res = !(r < 0);
+   else if (!strcmp(argv[2], "gt")) res = !(r > 0);
+   else if (!strcmp(argv[2], "eq")) res = !(r == 0);
+   else bb_error_msg_and_die("unknown operator: %s", argv[2]);
+
+   //printf("%s\n", res == 0 ? "true" : "false");
+   return res;
+}
-- 
2.8.3

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] (v2) cp: add -u/--update and --remove-destination

2016-05-22 Thread wdlkmpx
This matches the behavior of GNU coreutils cp
when ENABLE_FEATURE_NON_POSIX_CP is not set
and ENABLE_FEATURE_CP_LONG_OPTIONS is defined

The verbose option now shows the same message
when --remove-destination is used

It works the same in most combinations.
Needs more testing to detect issues...
---
 coreutils/cp.c| 15 ---
 include/libbb.h   |  2 ++
 libbb/copy_file.c | 21 +
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/coreutils/cp.c b/coreutils/cp.c
index 247ed0f..b42c3b2 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -31,6 +31,7 @@
 //usage: "\n   -f  Overwrite"
 //usage: "\n   -i  Prompt before overwrite"
 //usage: "\n   -l,-s   Create (sym)links"
+//usage: "\n   -u  Copy if SOURCE file is newer than the 
destination"
 
 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
@@ -53,8 +54,10 @@ int cp_main(int argc, char **argv)
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
+   OPT_u = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
-   OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+   OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+   OPT_rmdest  = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+5),
 #endif
};
 
@@ -76,10 +79,12 @@ int cp_main(int argc, char **argv)
"recursive\0"  No_argument "R"
"symbolic-link\0"  No_argument "s"
"verbose\0"No_argument "v"
-   "parents\0"No_argument "\xff"
+   "update\0" No_argument "u"
+   "parents\0"No_argument "\xfe"
+   "remove-destination\0" No_argument "\xff"
;
 #endif
-   flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
+   flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPvu");
/* Options of cp from GNU coreutils 6.10:
 * -a, --archive
 * -f, --force
@@ -161,6 +166,10 @@ int cp_main(int argc, char **argv)
bb_error_msg_and_die("with --parents, the 
destination must be a directory");
}
}
+   if (flags & OPT_rmdest) {
+   flags |= FILEUTILS_FORCE;
+   flags |= FILEUTILS_RMDEST;
+   }
 #endif
 
/* ...if neither is a directory...  */
diff --git a/include/libbb.h b/include/libbb.h
index fd40ef7..ece5f32 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -368,6 +368,8 @@ enum {  /* DO NOT CHANGE THESE VALUES!  cp.c, mv.c, 
install.c depend on them. */
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
/* -v */
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
+   FILEUTILS_UPDATE  = 1 << 13, /* -u */
+   FILEUTILS_RMDEST  = 1 << 14, /* cp --remove-destination */
 };
 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
 extern int remove_file(const char *path, int flags) FAST_FUNC;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4be875..23bcf2e 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -64,6 +64,11 @@ static int ask_and_unlink(const char *dest, int flags)
bb_perror_msg("can't create '%s'", dest);
return -1; /* error */
}
+#if ENABLE_FEATURE_CP_LONG_OPTIONS
+   if (flags & FILEUTILS_RMDEST)
+   if (flags & FILEUTILS_VERBOSE)
+   printf("removed '%s'\n", dest);
+#endif
return 1; /* ok (to try again) */
 }
 
@@ -210,6 +215,22 @@ int FAST_FUNC copy_file(const char *source, const char 
*dest, int flags)
goto preserve_mode_ugid_time;
}
 
+   if (dest_exists) {
+   if (flags & FILEUTILS_UPDATE) {
+   if (source_stat.st_mtime <= dest_stat.st_mtime) {
+   return 0; /* source file must be newer */
+   }
+   }
+#if ENABLE_FEATURE_CP_LONG_OPTIONS
+   if (flags & FILEUTILS_RMDEST) {
+   ovr = ask_and_unlink(dest, flags);
+   if (ovr <= 0)
+   return ovr;
+   dest_exists = 0;
+   }
+#endif
+   }
+
if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
int (*lf)(const char *oldpath, const char *newpath);
  make_links:
-- 
2.8.3

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] cp: add -u/--update and --remove-destination

2016-05-21 Thread wdlkmpx
This matches the behavior of GNU coreutils
---
 coreutils/cp.c| 14 +++---
 include/libbb.h   |  2 ++
 libbb/copy_file.c | 22 ++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/coreutils/cp.c b/coreutils/cp.c
index 247ed0f..cd947be 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
@@ -31,6 +31,7 @@
 //usage: "\n   -f  Overwrite"
 //usage: "\n   -i  Prompt before overwrite"
 //usage: "\n   -l,-s   Create (sym)links"
+//usage: "\n   -u  Copy if SOURCE file is newer than the 
destination"
 
 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
@@ -53,8 +54,10 @@ int cp_main(int argc, char **argv)
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
+   OPT_u = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
-   OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+   OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+   OPT_rmdest  = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+5),
 #endif
};
 
@@ -76,10 +79,12 @@ int cp_main(int argc, char **argv)
"recursive\0"  No_argument "R"
"symbolic-link\0"  No_argument "s"
"verbose\0"No_argument "v"
-   "parents\0"No_argument "\xff"
+   "update\0" No_argument "u"
+   "parents\0"No_argument "\xfe"
+   "remove-destination\0" No_argument "\xff"
;
 #endif
-   flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
+   flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPvu");
/* Options of cp from GNU coreutils 6.10:
 * -a, --archive
 * -f, --force
@@ -161,6 +166,9 @@ int cp_main(int argc, char **argv)
bb_error_msg_and_die("with --parents, the 
destination must be a directory");
}
}
+   if (flags & OPT_rmdest) {
+   flags |= FILEUTILS_RMDEST;
+   }
 #endif
 
/* ...if neither is a directory...  */
diff --git a/include/libbb.h b/include/libbb.h
index fd40ef7..ece5f32 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -368,6 +368,8 @@ enum {  /* DO NOT CHANGE THESE VALUES!  cp.c, mv.c, 
install.c depend on them. */
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
/* -v */
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
+   FILEUTILS_UPDATE  = 1 << 13, /* -u */
+   FILEUTILS_RMDEST  = 1 << 14, /* cp --remove-destination */
 };
 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
 extern int remove_file(const char *path, int flags) FAST_FUNC;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4be875..44031f2 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -208,6 +208,28 @@ int FAST_FUNC copy_file(const char *source, const char 
*dest, int flags)
/* retval = -1; - WRONG! copy *WAS* made */
}
goto preserve_mode_ugid_time;
+   } else {
+   /* Not a directory */
+   if (dest_exists) {
+   if (flags & FILEUTILS_UPDATE) {
+   if (source_stat.st_mtime <= dest_stat.st_mtime) 
{
+   return 0; /* source file must be newer 
*/
+   }
+   }
+   if (flags & FILEUTILS_RMDEST) {
+   if (unlink(dest) < 0) {
+   if (flags & FILEUTILS_VERBOSE) {
+   printf("can't remove '%s'\n", 
dest);
+   }
+   return -1;
+   } else {
+   if (flags & FILEUTILS_VERBOSE) {
+   printf("removed '%s'\n", dest);
+   }
+   dest_exists = 0;
+   }
+   }
+   }
}
 
if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
-- 
2.8.3

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox