[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with "ed"
From: |
Dave Gibson |
Subject: |
Re: Problem with "ed" |
Date: |
Wed, 19 Oct 2005 18:51:42 +0100 |
User-agent: |
tin/1.7.10-20050929 ("Tahay") (UNIX) (Linux/2.6.13-1 (i686)) |
Bob Proulx <address@hidden> wrote:
> Mike McElroy wrote:
>> Bob Proulx wrote:
>> >The 'ed' command appears to be not stopping option processing with the
>> >"--". Instead it appears to be processing -infile as an option and
>> >erroring.
>> >
>> >Try this:
>> >
>> > ed -s ./-infile < cmdfile
>> >
>> >That should work.
>>
>> Thank you. That works. Unfortunately I can't change the filename
>> because it is part of an Xopen testsuite. Is it sufficient to post here
>> or do I have to send mail here to somewhere else in Gnu to get this
>> looked at?
>
> Unfortunately the ed maintainer has not been responsive to my emails.
> But it has not been long enough yet to draw conclusions. Therefore I
> do not know if he is still active or if he has orphaned the project.I
> will keep a reminder to keep looking for him.
>
> I think that posting bugs here is at this moment the best that you can
> do. If you dig into the code and make a fix please send patches back
> here too.
The problem stems from "-" being an ordinary option to ed but having a
special meaning to getopt_long(). The following patch scans the command
line arguments and replaces instances of "-" with its "-s" equivalent
where appropriate.
--- main.c.orig 1994-11-19 12:38:02.000000000 +0000
+++ main.c 2005-10-18 17:46:25.000000000 +0100
@@ -164,10 +164,34 @@
{
int c, n;
long status = 0;
+ char *p;
program_name = argv[0];
red = (n = strlen (argv[0])) > 2 && argv[0][n - 3] == 'r';
-top:
+
+ n = (getenv("POSIXLY_CORRECT") != NULL);
+ for (c = 1; c < argc; c++)
+ {
+ if (argv[c][0] == '-')
+ {
+ /* Replace '-' with '-s'. Break on '--'. Skip an arg if '-p'
+ * ('-Gp' etc) or '--prompt' is given with no argument attached. */
+ if (argv[c][1] == '\0')
+ argv[c] = "-s";
+ else if (argv[c][1] == '-' && argv[c][2] == '\0')
+ break;
+ else if ((argv[c][1] != '-' &&
+ (p = strchr(argv[c], 'p')) && p[1] == '\0') ||
+ strcmp(argv[c], "--prompt") == 0)
+ ++c;
+ }
+ else if (n)
+ {
+ /* Non-option argument and POSIXLY_CORRECT is set; stop here. */
+ break;
+ }
+ }
+
while ((c = getopt_long (argc, argv, "Gp:s", long_options, NULL)) != EOF)
switch (c)
{
@@ -194,17 +218,6 @@
usage (0);
argv += optind;
argc -= optind;
- if (argc && **argv == '-')
- {
- scripted = 1;
- if (argc > 1)
- {
- optind = 0;
- goto top;
- }
- argv++;
- argc--;
- }
#if HAVE_LOCALE_H
setlocale(LC_CTYPE, "");
#endif