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
Show HN: I wrote a program to convert lines of text into trees
51–58 of 58 posts
Re: Show HN: I wrote a program to convert lines of text into trees
#52Earlier 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/
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…
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…
- 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
#55 tree --fromfile
e.g. echo a/b1 a/b2/c | xargs -n1 | tree --fromfile
.
└── a
├── b1
└── b2
└── c
2 directories, 2 filesRe: Show HN: I wrote a program to convert lines of text into trees
#56Author 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.
(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
#57Re: Show HN: I wrote a program to convert lines of text into trees
#58Earlier quoted context omitted.
Very cool tool! Any chance that you're going to add it to Homebrew?
https://github.com/birchb1024/frangipanni/issues/2