在OS X 10.5使用的readline的rl_insert_text [英] Using readline's rl_insert_text on OS X 10.5

查看:198
本文介绍了在OS X 10.5使用的readline的rl_insert_text的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我尝试使用的readline到一些东西默认文本到用户输入,遇到麻烦就在OSX 10.5工作:

So, I'm trying to stuff some default text into a user input using readline, and having trouble getting it to work on OSX 10.5:

// rl_insert_text_ex.c
// gcc -o rl_insert_text_ex rl_insert_text_ex.c -lreadline
#include <stdio.h>
#include <readline/readline.h>

int my_startup_hook(void) {
  return rl_insert_text("ponycorns");
}
int main(int argc, char *argv[]) {
  char *line;
  rl_startup_hook = (Function*) my_startup_hook;
  line = readline("What's your favorite mythical animal? ");
  if (NULL == line || '\0' == *line) {
    printf("Nothing given... :(\n");
  }
  else {
    printf("That's funny, I love %s too!\n", line);
  }
  return 0;
}

这code甚至不上10.4编译(因为没有定义 _rl_insert_text 10.4,这是一个有点令人失望的),但编译10.5 。但是, rl_insert_text()'D文本从未显示屏幕,也没有返回用户输入。回调正在使用和 rl_insert_text()返回正确的值,(谢谢你,的printf ),所以我不能确定这是怎么回事的。

This code doesn't even compile on 10.4 (no definition for _rl_insert_text on 10.4, which is a bit of a bummer), but does compile on 10.5. However, the rl_insert_text()'d text is never shown to screen, nor returned as user input. The callback is being used and rl_insert_text() returns the proper value, (thank you, printf), so I'm not sure what's going on here.

我检查 /usr/include/readline/readline.h rl_insert_text()正在

/* supported functions */

这是在混淆的:

/*
 * The following is not implemented
 */

我也是SOL,还是我只是做错了?

So am I SOL, or am I just doing it wrong?

推荐答案

不幸的是,你可能是出于运气,至少readline库包含在OS X因为许可证的兼容性问题,苹果使用的 libedit ,它(显然)提供不完整的ReadLine仿真。 (该库记录,在包含OS X中的 readline.h 的名称为editline)。

Unfortunately, you may be out of luck, at least with the readline library included in OS X. Due to license compatibility issues, Apple uses libedit, which (apparently) provides incomplete readline emulation. (This library is documented with the name "editline" in the readline.h included with OS X.)

GNU Readline库(一个真正的readline库)是GPL,它(下作为一个非盈利版权许可证)不能与code,它是不完全的开源发挥出色。如果它归结为(A)的开放式采购所有的X code,OS X等,或使用你真正喜欢使用,苹果敲落(B)的(最喜欢的公司)是总是会选择B.这是一个令人失望,但这就是生活。

GNU Readline Library (the "one true" readline library) is under GPL, which (being a copyleft license) does not play well with code that is not entirely open-source. If it comes down to (A) open-sourcing all of Xcode, OS X, etc. or (B) using a knock-off of what you're really like to use, Apple (like most companies) is always going to choose B. It's a bummer, but that's life.

我个人认为,这是一个原因是GPL的code是在土地上的一大祸患几分的,因为它粘在人的行为,它往往还隐瞒了code从谁购买软件的群众。该{BSD,MIT,Apache的风格}许可证更利于在闭源系统中使用,并且仍然允许商业实体贡献背补丁,等等。我的猜测是, libedit 还没有收到足够的重视,妥善解决。社区补丁肯定会受到欢迎,但它是如此的好得多,如果我们可以用code,而无需破解它自己...; - )

Personally, I think this is one reason that GPL'd code is somewhat of a blight on the land, since in the act of "sticking it to the man", it often also withholds the code from the masses who purchase software. The {BSD,MIT,Apache}-style licenses are much more conducive to use in closed-source systems, and still allow commercial entities to contribute back patches, etc. My guess is that libedit hasn't received enough attention to be fixed properly. Community patches would certainly be welcome, although it's so much nicer if we can use code without having to hack on it ourselves... ;-)

顺便说一句,同样的道理也适用于其他GPL项目 - <击>只要{git的,反复无常,商场}仍然遵循GPL协议,不要屏住呼吸苹果以x code运一体化为他们。 : - (

BTW, the same thing applies to other GPL projects — as long as {git,mercurial,bazaar} remains under GPL, don't hold your breath for Apple to ship integration for them in Xcode. :-(

更新:新推出的X code 4提供的Git支持。好哇!我的理解是,这是由于从主X code codeBase的隔离GPL的code新的插件架构。不过,我要强调指出的copyleft许可证仍然是code应该人人受益错误的解决方案。显然,有些人不同意(你是一个好朋友,匿名downvoter),但事实是,的 GPL可以限制自由太 - 通常是其不同的人比封闭源代码/专有软件通常的做法,但GPL也处于preventing非法使用源$ C ​​$ C的相当有效的...不同的是道德优越感的感觉。

UPDATE: The new Xcode 4 offers git support. Huzzah! My understanding is that this is due to the new plugin architecture which isolates GPL'd code from the main Xcode codebase. However, I emphasize that copyleft licenses are still the wrong solution for code that should benefit everyone. Obviously some people don't agree (you're a pal, anonymous downvoter) but the fact is that GPL can restrict freedoms too — usually its different ones than closed-source/proprietary software generally does, but GPL is also quite effective at preventing illegal use of source code... The difference is a feeling of moral superiority.

这篇关于在OS X 10.5使用的readline的rl_insert_text的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆