All of lore.kernel.org
 help / color / mirror / Atom feed
* New linux command "hexed"
@ 2015-05-08 11:36 Hypsurus
  2015-05-08 12:29 ` Stephan Müller
  2015-05-11  7:51 ` Karel Zak
  0 siblings, 2 replies; 4+ messages in thread
From: Hypsurus @ 2015-05-08 11:36 UTC (permalink / raw)
  To: util-linux

aSB3cm90ZSBhIG5ldyBMaW51eCBjb21tYW5kIGNhbGxlZCBoZXhlZAoKdG8gZW5jb2RlIGFuZCBk
ZWNvZGUgaGV4IHN0cmluZyBmcm9tIHRoZSBjb21tYW5kIGxpbmUuCgphbmQgaSB3YW50IHRvIGFk
ZCBpdCB0byB1dGlsIGxpbnV4LgoKaG93IGNhbiBoZWxwIG1lIHRvIGRvIHRoaXM/IGFuZCB3aGF0
IGkgbmVlZCB0byBkbz8KaSBhbHJlYWR5IGNoZWNrZWQgdGhlIERvY3MgaW4gZ2l0aHViIGJ1dCBp
J20gbm90IHN1cmUgd2hhdCB0byBkby4KClNvdXJjZSBjb2RlOgpodHRwczovL2dpdGh1Yi5jb20v
SHlwc3VydXMvaGV4ZWQKCnRoYW5rcyEKLS0gCmh5cHN1cnVzCg==

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: New linux command "hexed"
  2015-05-08 11:36 New linux command "hexed" Hypsurus
@ 2015-05-08 12:29 ` Stephan Müller
  2015-05-08 22:58   ` Ángel González
  2015-05-11  7:51 ` Karel Zak
  1 sibling, 1 reply; 4+ messages in thread
From: Stephan Müller @ 2015-05-08 12:29 UTC (permalink / raw)
  To: util-linux

Am 08.05.2015 um 13:36 schrieb Hypsurus:
> i wrote a new Linux command called hexed
> 
> to encode and decode hex string from the command line.
> 
> and i want to add it to util linux.
> 
> how can help me to do this? and what i need to do?
> i already checked the Docs in github but i'm not sure what to do.
> 
> Source code:
> https://github.com/Hypsurus/hexed
> 
> thanks!
> 

It seems you implemented a subset of the functionality of 'od' or 'xxd' from coreutils. I guess these are widely spread and there is no need for another converter (albeit the cooler name). If hexed provides some extra features, you can integrate those in the tools above.
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: New linux command "hexed"
  2015-05-08 12:29 ` Stephan Müller
@ 2015-05-08 22:58   ` Ángel González
  0 siblings, 0 replies; 4+ messages in thread
From: Ángel González @ 2015-05-08 22:58 UTC (permalink / raw)
  To: hypsurus; +Cc: Stephan Müller, util-linux

[-- Attachment #1: Type: text/plain, Size: 1711 bytes --]

On 08/05/15 14:29, Stephan Müller wrote:
> It seems you implemented a subset of the functionality of 'od' or 'xxd'
 >from coreutils. I guess these are widely spread and there is no need for
 >another converter (albeit the cooler name). If hexed provides some extra
 >features, you can integrate those in the tools above.

xxd seems a perfect replacement for hexed :P


FWIW, I see a number of quirks in your tool, Hypsurus:
a) Options have to be provided *after* the string
Usually options always appear at the beginning (just after the program 
name) and -when _POSIXLY_CORRECT is not set- the gnu optlib then allows 
placing them at any position.

b) The program crashes if the string begins with a dash (str is NULL).


c) You program requires the string to be passed as parameter.
All programs like this have *filenames* as parameters. Consistency is 
even more important for a program like this, that mimics the interfaces 
of many other programs working the other way.
And receiving filenames makes much more sense. Do you really want to 
type the binary contents as a program parameter? Does your OS even allow 
that large? etc.

With a program that receives a filename, you can provide a string with
  echo string | hexed

with a program that receives the string, you need a construct like:
  hexed "$(</etc/passwd)"
and only if you use bash, the file is small enough to be passed as a 
parameter and it doesn't contain any NUL (which defeats the point of an 
hexer).


d) You have a number of signedness warnings, you are assgning a size_t 
to an int and, generally, it would have been much easier for 
hexed_hex_encode to work with unsigned char and hexed_hex_decode with 
chars. See attached patch.

[-- Attachment #2: hexed.diff --]
[-- Type: text/x-patch, Size: 1188 bytes --]

--- hexed.c-original	2015-05-09 00:24:13.791707625 +0200
+++ hexed.c	2015-05-09 00:54:07.538368884 +0200
@@ -29,26 +29,29 @@
         int addx;
         int addCarray;
         int hexd;
-        unsigned char *str;
+        union {
+            char *str;
+            unsigned char *ustr;
+        };
 } hexed_t;
 
 void hexed_hex_encode(hexed_t *hexed) {
         int index = 0;
 
-        for( index = 0; hexed->str[index] != 0; index++ ) {
+        for( index = 0; hexed->ustr[index] != 0; index++ ) {
                 if ( hexed->addx )
-                        printf("\\x%x", hexed->str[index]);
+                        printf("\\x%x", hexed->ustr[index]);
                 else if ( hexed->addCarray )
-                        printf("0x%x,", hexed->str[index]);
+                        printf("0x%x,", hexed->ustr[index]);
                 else
-                        printf("%x", hexed->str[index]);
+                        printf("%x", hexed->ustr[index]);
         }
 
         putchar(0x0a);
 }
 
 void hexed_hex_decode(hexed_t *hexed) {
-        int index = 0;
+        size_t index = 0;
         short byte = 0x00;
         size_t len = strlen(hexed->str);
         

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: New linux command "hexed"
  2015-05-08 11:36 New linux command "hexed" Hypsurus
  2015-05-08 12:29 ` Stephan Müller
@ 2015-05-11  7:51 ` Karel Zak
  1 sibling, 0 replies; 4+ messages in thread
From: Karel Zak @ 2015-05-11  7:51 UTC (permalink / raw)
  To: Hypsurus; +Cc: util-linux

On Fri, May 08, 2015 at 02:36:58PM +0300, Hypsurus wrote:
> i wrote a new Linux command called hexed
> 
> to encode and decode hex string from the command line.

 It's very difficult to believe that after 40 years of unix
 development we have no tool to convert from/to hex :-)


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-05-11  7:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-08 11:36 New linux command "hexed" Hypsurus
2015-05-08 12:29 ` Stephan Müller
2015-05-08 22:58   ` Ángel González
2015-05-11  7:51 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.