开发者

Glob function (c) and backup file (file~)

开发者 https://www.devze.com 2022-12-26 23:23 出处:网络
I\'m using glob function for a autocompletion function. I\'m showing you the problem becaus开发者_StackOverflow社区e it\'s difficult to explain:

I'm using glob function for a autocompletion function. I'm showing you the problem becaus开发者_StackOverflow社区e it's difficult to explain:

matched = ~/.tcsh
glob(matched, 0, NULL, &pglob);

glob put all matched files in a char ** and when I print it I have:

case[0] = .tcshrc
case[1] = 

I should have .tcshrc~ in case[1], but nothing =S, I've seen a flag "GLOB_TILDE" like this "

 glob(matched, GLOB_TILDE, NULL, &pglob);

But it doesn't change anything! Can someone help me?


The GLOB_TILDE flag only affects the output when the ~ appears at the beginning of the glob. See here:

http://www.gnu.org/s/libc/manual/html_node/More-Flags-for-Globbing.html

As for your problem, it appears to me that your matched value is wrong. Seems like you should be sticking a * at the end of it for it to be useful for autocompletion, i.e.:

matched = ~/.tcsh*

I'm a little bit confused as how your previous example found even the first one. The bottom part of this man page article has some interesting examples too:

http://www.opengroup.org/onlinepubs/000095399/functions/glob.html

0

精彩评论

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