Live data from Hacker News

Show HN: I wrote a program to convert lines of text into trees

github.com

51–58 of 58 posts

Re: Show HN: I wrote a program to convert lines of text into trees

#51
post #41
post #34

Earlier quoted context omitted.

You've been breaking the site guidelines badly. If you keep doing this we will have to ban you. Please review https://news.ycombinator.com/newsguidelines.html and stick to the rules from now on.

Yes, sorry

No worries mate. Your point is basically 'What a fuss over a very simple bit of code.'? I'm as surprised as you are.

Re: Show HN: I wrote a program to convert lines of text into trees

#52
post #49

Earlier quoted context omitted.

C version. Maybe this logic should be built into GNU find as an option! $ find /etc/network | ./frangi-cheat /etc/network /if-post-down.d /wireless-tools /wpasupplicant /avahi-daemon /if-down.d /resolvconf /wpasupplicant /avahi-autoipd /interfaces.d /interfaces /if-pre-up.d /wireless-tools /wpasupplicant /ethtool /if-up.d /ntpdate /wpasupplicant /000resolvconf /openssh-server /ethtool /avahi-autoipd /slrn /avahi-daem…

I love your enthusiasm, and thanks for the code. But 1) the above only works with sorted input and 2) adding it to find that would be like adding '-v' to 'cat' which as we know is considered harmful. http://harmful.cat-v.org/cat-v/

Actually, what it works with is a partially sorted input: an input in some tree-order input, which is what any recursive file system traversal will always put out. It will work with depth first or breadth-first order, with usefully different results, and that order preserved.

All it is doing is hiding the redundancy with spaces to improve the human readability of find's output.

Here it is on the same data in breadth-first. Note the lack of any lexicographic sort: "interfaces" is flanked by "if-down.d" and "if-pre-up.d":

  /etc/network
              /if-post-down.d
              /if-down.d
              /interfaces.d
              /interfaces
              /if-pre-up.d
              /if-up.d
              /if-post-down.d/wireless-tools
                             /wpasupplicant
                             /avahi-daemon
              /if-down.d/resolvconf
                        /wpasupplicant
                        /avahi-autoipd
              /if-pre-up.d/wireless-tools
                          /wpasupplicant
                          /ethtool
              /if-up.d/ntpdate
                      /wpasupplicant
                      /000resolvconf
                      /openssh-server
                      /ethtool
                      /avahi-autoipd
                      /slrn
                      /avahi-daemon
My first program in TXR Lisp in the grandparent comment builds the tree structure from the paths in any order and then prints that, so the paths could be scrambled into random order, yet it will recover the tree structure.

However, not munging the the output in that way and just tweaking the original output for readability has some advantages

Re: Show HN: I wrote a program to convert lines of text into trees

#53

$ find /etc/network | ./frangi.tl etc: network: if-post-down.d: wireless-tools wpasupplicant avahi-daemon if-down.d: resolvconf wpasupplicant avahi-autoipd interfaces.d interfaces if-pre-up.d: wireless-tools wpasupplicant ethtool if-up.d: ntpdate wpasupplicant 000resolvconf openssh-server ethtool avahi-autoipd slrn avahi-daemon $ find /etc/network | ./frangi-cheat.tl /etc/network /if-post-down.d /wireless-tools /wpas…

C version. Maybe this logic should be built into GNU find as an option! $ find /etc/network | ./frangi-cheat /etc/network /if-post-down.d /wireless-tools /wpasupplicant /avahi-daemon /if-down.d /resolvconf /wpasupplicant /avahi-autoipd /interfaces.d /interfaces /if-pre-up.d /wireless-tools /wpasupplicant /ethtool /if-up.d /ntpdate /wpasupplicant /000resolvconf /openssh-server /ethtool /avahi-autoipd /slrn /avahi-daem…

[deleted]

Re: Show HN: I wrote a program to convert lines of text into trees

#54

$ find /etc/network | ./frangi.tl etc: network: if-post-down.d: wireless-tools wpasupplicant avahi-daemon if-down.d: resolvconf wpasupplicant avahi-autoipd interfaces.d interfaces if-pre-up.d: wireless-tools wpasupplicant ethtool if-up.d: ntpdate wpasupplicant 000resolvconf openssh-server ethtool avahi-autoipd slrn avahi-daemon $ find /etc/network | ./frangi-cheat.tl /etc/network /if-post-down.d /wireless-tools /wpas…

C version. Maybe this logic should be built into GNU find as an option! $ find /etc/network | ./frangi-cheat /etc/network /if-post-down.d /wireless-tools /wpasupplicant /avahi-daemon /if-down.d /resolvconf /wpasupplicant /avahi-autoipd /interfaces.d /interfaces /if-pre-up.d /wireless-tools /wpasupplicant /ethtool /if-up.d /ntpdate /wpasupplicant /000resolvconf /openssh-server /ethtool /avahi-autoipd /slrn /avahi-daem…

New version:

- swap pointers to flip buffers instead of strcpy

- handle corner case of directory printed after contents (find -depth) by avoiding printing nothing but spaces, or nothing but spaces followed by a slash

  #include 
  #include 
  #include 

  int main(void)
  {
    typedef char buf_t[FILENAME_MAX];
    buf_t buf[2] = { "" };
    buf_t *pline = &buf[0], *line = &buf[1];

    while (fgets(*line, sizeof *line, stdin)) {
      buf_t *tmp;
      char *l = *line, *p = *pline, *nl = strchr(l, '\n');

      if (nl)
        *nl = 0;

      while (*l && *p) {
        char *op = l;

        if (*p == '/' && *l == '/')
          p++, l++;

        size_t lp = strcspn(l, "/");
        size_t lo = strcspn(p, "/");

        if (lp == lo && !strncmp(l, p, lp)) {
          l += lp;
          p += lp;
          continue;
        }

        l = op;
        break;
      }

      if (l[0] && (l[1] || l[0] != '/'))
        printf("%*s%s\n", (int) (l - *line), "", l);
      else
        puts(*line);

      tmp = pline, pline = line, line = tmp;
    }

    return feof(stdin) ? EXIT_SUCCESS : EXIT_FAILURE;
  }

Re: Show HN: I wrote a program to convert lines of text into trees

#56
post #2

Author here: Often I have to digest log files and lists of Azure resource names. I prefer to work with hierarchies of things, so I wrote this simple filter. Turns out to quite handy, especially when combined with awk and its friends.

Ah yes, I was just thinking that this could be useful for `aws s3 ls` and similar.

(Really I just want `tree` on `s3`. There's `s3-tree` but that uses the entire bucket rather than a prefix)

Re: Show HN: I wrote a program to convert lines of text into trees

#57
post #47

Earlier quoted context omitted.

really cool! But I think you should have called it "birch"! :) Any way you could add build instructions to the README?

Sure. https://github.com/birchb1024/frangipanni/issues/6

Done

Re: Show HN: I wrote a program to convert lines of text into trees

#58
post #6

Earlier quoted context omitted.

Very cool tool! Any chance that you're going to add it to Homebrew?

https://github.com/birchb1024/frangipanni/issues/2

Mac binary https://github.com/birchb1024/frangipanni/releases/download/...
Post reply on HN