开发者

What C library has the functionality to do zsh's recursive globs?

开发者 https://www.devze.com 2023-02-04 08:31 出处:网络
I wrote a nodejs binding to glob.h (npm install glob to use it). I\'d really like to support zsh\'s fancy lib/**/*.js type of stuff, but I can\'t seem to figure out which library has that functionali

I wrote a nodejs binding to glob.h (npm install glob to use it).

I'd really like to support zsh's fancy lib/**/*.js type of stuff, but I can't seem to figure out which library has that functionality.

I sure don't want to try to implement it myself, and I'm not looking for any clever solution to the programming puzzle. I just want something like this:

#include <fancy_glob.h>
int do_fancy_glob (etc) { ... }

Any pointers? I'm pretty sure Ruby has a binding to this, doesn't it?


EDIT:

I did some research, and found out interesting things.

Guido Van Rossum (of Python fame) wrote an implementation that is found now on BSD and some some other unixes. It did not include the so-called "extended" glob patterns (**, etc). When you do #include <glob.h> in your program, it is most likely that this is what you will开发者_开发百科 get. man 3 glob describes its behavior.

However, Bash, Zsh, and Ksh all now have extended glob implementations, all written from scratch, as far as I can tell. NetBSD has a recognizable descendent of GVR's implementation, with extended globs added in. Ruby has extended globs implemented in dir.c as part of its standard library (definitely written in C, not ruby). Perl seems to have bindings to or implementations of all the glob libraries in existence, which is to be expected, I suppose.

Of all the ones I found, NetBSD seems the closest to what I coded against with the typical non-extended libc glob(3), and its license is most amenable to my project.

Another approach would be to rewrite it from scratch. I'd be fine with doing that, but I can't seem to find any clear specification or suite of tests. Got any suggestions?


EDIT 2: I've rewritten it in JS. https://github.com/isaacs/node-glob


I'm pretty sure Ruby does this itself, and it's probably Ruby code doing it. Besides parsing the string and walking the filesystem, there aren't many hurdles to implement this. I'm not sure, but I don't think zsh uses a library for this either, it's just in the zsh code.

0

精彩评论

暂无评论...
验证码 换一张
取 消