Author Topic: prompt/history bug in DS 3.0?  (Read 2976 times)

Offline Xenophanes

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
prompt/history bug in DS 3.0?
« on: February 06, 2010, 04:05:33 PM »
Greetings all,

  I couldn't find any reference to this, and I'm not seeing a bug tracker for DS, so I figured I'd post it here.  Please let me know if I should posting/searching elsewhere.

  I'm a big fan of history counters in my prompt, so I tried to set it up in my shell on DS 3.0.

Code: [Select]

/lib> prompt $C $N@$M:$P>
$C Xenophanes@XenoMUD:/lib>


Not exactly what I expected. So, I dug a bit and discovered in line 355 of /lib/nmsh.c:

Code: [Select]

    if(grepp(ret,"$C")) ret = replace_string(ret,"",itoa( CmdNumber+1 ));


I changed it to:

Code: [Select]

    if(grepp(ret,"$C")) ret = replace_string(ret,"$C",itoa( this_object()->GetCommandNumber() ));


But this hasn't completely solved the problem.  I get a command number now, but it isn't working properly.  It appears that the history related code was taken out of /lib/nmsh.c and put into /lib/history.c, and the history code doesn't appear to be working quite right.  Some commands get put into the history, and some don't.  I haven't worked out all the details of it yet.

I thought it would be a simple fix in /lib/nmsh.c, but it appears it will be more involved.  Has anyone seen this issue, or is anyone working on it? Is there anyone familiar enough with the history code to provide a little (ahem) history or status on it?

-X

Offline Xenophanes

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
Re: prompt/history bug in DS 3.0?
« Reply #1 on: February 06, 2010, 05:23:08 PM »
Ok, I see what's happening now.  The history isn't broken, it just doesn't work the way I expected it to.  I mistakenly assumed it worked the same way as a *nix shell history, but it doesn't; therefore, the $C piece is practically useless in reference to the history buffer. (my opinion, of course)

I still think linke 355 in /lib/nmsh.c is incorrect.

Does anyone have opinions on how the history and command numbers should actually work?  Is it fine for most people as is or is it something that's on the infinitely growing TODO list to fix?

-X

Offline quixadhal

  • BFF
  • ***
  • Posts: 620
    • View Profile
    • A Waste of Time
Re: prompt/history bug in DS 3.0?
« Reply #2 on: February 06, 2010, 09:01:22 PM »
I guess the question (for me) is, how does it currently work?

In the unix shell, the only reason I ever care about the command number is on the rare occasion I do something like !34, which means go execute entry 34 again.  If that isn't what nmsh does, I wouldn't even know how to form an opinion about it. :)

Offline Xenophanes

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
Re: prompt/history bug in DS 3.0?
« Reply #3 on: February 06, 2010, 09:15:43 PM »
That is "sort of" how it works, but not exactly.  The problem is the history is a fixed size of 50 (can be changed, but that's the default), but it doesn't act like a queue.  Instead, it renumbers every command.  So you'll always have commands 1-50 in your history list (assuming you've typed that many commands, of course).

To find out which command to execute, you can do a history, and then !34 to run the command.  However, !34 won't always equal the same command.  This is because of the way it was implemented.  You'd have to type history again, then look for the command to run... it might be 32 instead of 34 the second time around.

In a shell (i.e. csh or bash), !34 is always the same command, unless you run out of buffer space, in which case !34 is nothing.

In my opinion, command 50 should always be the exact same thing... until you've executed 50 more commands (to get to 100), in which case your history list should show commands 51-100, not 1-50.

I hope I'm making sense.  I can recode it, but don't want to waste the effort unless others see it as worthwhile.