哪个 C 库具有执行 zsh 递归 glob 的功能?

发布于 2024-10-12 02:37:53 字数 1055 浏览 5 评论 0原文

我编写了一个与 glob.h 绑定的 Nodejs(npm install glob 使用它)。

我真的很想支持 zsh 的花哨的 lib/**/*.js 类型的东西,但我似乎无法弄清楚哪个库具有该功能。

我当然不想尝试自己实现它,我也不想寻找任何聪明的解决方案来解决编程难题。我只想要这样的东西:

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

有什么指示吗?我很确定 Ruby 对此有绑定,不是吗?


编辑:

我做了一些研究,发现了有趣的事情。

Guido Van Rossum(因 Python 闻名)编写了一个实现,现在可以在 BSD 和其他一些 UNIX 上找到。它不包括所谓的“扩展”全局模式(** 等)。当您在程序中执行 #include 时,您很可能会得到这样的结果。 man 3 glob 描述了它的行为。

然而,据我所知,Bash、Zsh 和 Ksh 现在都具有扩展的 glob 实现,所有这些实现都是从头开始编写的。 NetBSD 有一个明显的 GVR 实现的后代,添加了扩展的 glob。Ruby 在 dir.c 中实现了扩展的 glob,作为其标准库的一部分(肯定是用 C 编写的,而不是 ruby​​)。 Perl 似乎已经绑定或实现了所有现有的 glob 库,我想这是可以预料的。

在我发现的所有这些中,NetBSD 似乎最接近我使用典型的非扩展 libc glob(3) 编写的代码,并且它的许可证最适合我的项目。

另一种方法是从头开始重写它。我可以这样做,但我似乎找不到任何明确的规范或测试套件。有什么建议吗?


编辑2:我用JS重写了它。 https://github.com/isaacs/node-glob

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-10-19 02:37:53

我很确定 Ruby 自己会做这件事,而且很可能是 Ruby 代码在做这件事。除了解析字符串和遍历文件系统之外,实现这一点没有太多障碍。我不确定,但我认为 zsh 也没有为此使用库,它只是在 zsh 代码中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文