[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  Extra spaces with 'script_editor_argument' causes errors with VS

Extra spaces with 'script_editor_argument' causes errors with VS

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Thu 15 Jul 2010 08:03 PM (UTC)
Message
Hey Nick,

I wanted to check out the Visual Studio 2010 IDE with Lua. using

SetAlphaOption ("script_editor_argument", "/edit '%file'")

so that devenv would recycle the running instance and add a tab. This causes an error in devenv that " /edit 'C:\Users\Me\Documents\Scriptfile.lua'" can't find that file and will not be added.

So it doesn't open the file.

Without /edit, you get multiple instances. /edit works from a cmd prompt.


The Shell can be DL'd from http://www.microsoft.com/downloads/details.aspx?familyid=8E5AA7B6-8436-43F0-B778-00C3BCA733D3&displaylang=en

If you were curious.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 15 Jul 2010 09:15 PM (UTC)
Message
Are you saying the problem is with "<space>/edit", or is the problem that /edit is not recognized? If the problem is just the space, can't you omit it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #2 on Thu 15 Jul 2010 09:35 PM (UTC)

Amended on Thu 15 Jul 2010 09:40 PM (UTC) by WillFa

Message
Okay... looked at the code. Totally bogus guess to the problem before.

  // replace %file
  strArgument.Replace ("%file", strName);

  HINSTANCE hInst = ShellExecute (Frame, _T("open"), m_strScriptEditor, 
            CFormat ("\"%s\"", (LPCTSTR) strArgument),   // quote argument
            NULL, SW_SHOWNORMAL);
in doc.cpp


It's quoting everything.
"/edit C:\Users\Foo\Whatever\Blah.lua"


[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Thu 15 Jul 2010 09:42 PM (UTC)
Message
That does seem very plausible.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #4 on Fri 16 Jul 2010 08:58 AM (UTC)

Amended on Fri 16 Jul 2010 08:59 AM (UTC) by WillFa

Message
In theory

// replace %file
  strArgument.Replace ("%file", "\"%file\""); //Should really check that the user didn't include quotes himself.
  strArgument.Replace ("%file", strName);

  HINSTANCE hInst = ShellExecute (Frame, _T("open"), m_strScriptEditor, 
            CFormat ("%s", (LPCTSTR) strArgument),   // This is unnecessary, but I'm unsure if 
                //strArgument needs to be cast for ShellExecute.
            NULL, SW_SHOWNORMAL);

Would rectify the problem?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Fri 16 Jul 2010 10:13 AM (UTC)

Amended on Fri 16 Jul 2010 10:14 AM (UTC) by Twisol

Message
WillFa said:

CFormat ("%s", (LPCTSTR) strArgument),   // This is unnecessary, but I'm unsure if 
    //strArgument needs to be cast for ShellExecute.


It is definitely unneccesary. A CString has an implicit LPCTSTR conversion where applicable; the only reason it's explicitly cast in CFormat is because it uses the varargs construct, which isn't type-safe. You could almost certainly pass in strArgument without any extras and it would work.


// replace %file
  strArgument.Replace ("%file", "\"%file\""); //Should really check that the user didn't include quotes himself.
  strArgument.Replace ("%file", strName);

  HINSTANCE hInst = ShellExecute (Frame, _T("open"), m_strScriptEditor, 
            strArgument,
            NULL, SW_SHOWNORMAL);


Theoretically, yeah, I think that would do it.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 16 Jul 2010 10:17 AM (UTC)
Message
Twisol said:

It is definitely unneccesary. A CString has an implicit LPCTSTR conversion where applicable; the only reason it's explicitly cast in CFormat is because it uses the varargs construct, which isn't type-safe.


It's necessary because in a varargs situation it doesn't do the typecast, and it will crash if you don't explicitly cast. This is done all over the place in the code.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #7 on Fri 16 Jul 2010 10:22 AM (UTC)

Amended on Fri 16 Jul 2010 10:24 AM (UTC) by Twisol

Message
Nick Gammon said:

Twisol said:

It is definitely unneccesary. A CString has an implicit LPCTSTR conversion where applicable; the only reason it's explicitly cast in CFormat is because it uses the varargs construct, which isn't type-safe.


It's necessary because in a varargs situation it doesn't do the typecast, and it will crash if you don't explicitly cast. This is done all over the place in the code.


I'm talking about removing the CFormat(), because it just does "%s", making CFormat() unneccesary as well as the explicit typecast used therein, as my example shows. ShellExecute doesn't use varargs, and I literally just explained the typecast issue and why the explicit cast was used in your quote. :P

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Fri 16 Jul 2010 10:36 AM (UTC)
Message
Ah you see I read that in a linear way...

Quote:

Willfa: ... I'm unsure if strArgument needs to be cast for ShellExecute.

Twisol: It is definitely unneccesary.


So I took "it" to mean the cast.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Fri 16 Jul 2010 06:38 PM (UTC)

Amended on Fri 16 Jul 2010 06:39 PM (UTC) by Twisol

Message
Heh, it was a bit muddy all around. I took this:

CFormat ("%s", (LPCTSTR) strArgument)


to be the intended target of the "unneccesary" note, because the "%s" is redundant, so you can just pass strArgument.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #10 on Fri 16 Jul 2010 07:17 PM (UTC)
Message
Twisol read it right. I was commenting on the line of code.

I was unsure what CFormat returned, what strArgument was to begin with, and what ShellExecute expected; and I was too tired to look it up so I figured that it'd work as is and the comment would lead to Twisol or Nick knowing a more efficient way. :)
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Fri 16 Jul 2010 09:06 PM (UTC)
Message
Well OK I changed it to get rid of the quotes, but I should warn you that I found without them that things like Crimson Editor failed with a path like:


C:\Program Files\MUSHclient\scripts\test.lua


It tried to open two files:


C:\Program
Files\MUSHclient\scripts\test.lua


So I made it do this:


  CString strArgument = m_strScriptEditorArgument;

  if (strArgument.IsEmpty ())
    strArgument = "\"%file\"";          // default

  // replace %file
  strArgument.Replace ("%file", strName);

  HINSTANCE hInst = ShellExecute (Frame, _T("open"), m_strScriptEditor, 
            strArgument,   // quote argument
            NULL, SW_SHOWNORMAL);


So the default behaviour (if you don't use 'script_editor_argument') is to take the supplied file name, and quote it.

However if you use the 'script_editor_argument' feature, then quoting the appropriate part of the string is your job.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Fri 16 Jul 2010 10:32 PM (UTC)
Message
That sounds perfectly reasonable to me. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


24,881 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]