Paul A. Rubin wrote:

> Angus Leeming <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]:
> 
>> Having said that, if you (that's a collective you, I guess) can
>> provide us with a cast-iron prescription to obtain the 8.3 version of
>> the name from its pretty-printing wrapper, then you may all just be in
>> luck. Does Win32 have such a function in its API for example?
>> 
> 
> Apparently so:  http://support.microsoft.com/default.aspx?
> 
scid=http://support.microsoft.com:80/support/kb/articles/Q192/8/27.asp&NoWe
> bContent=1.  The function is GetShortPathName.  Don't know about the
> "cast- iron" part, but since it seems to be in the Kernel32 DLL, my guess
> is it's relatively reliable.

Thanks, Paul. So the first goal is to create a wrapper
std::string const getPortableName(std::string const & input);

On unix it would be

#include <iostream>
#include <string>

// On unix this is just a pass through function.
std::string const getPortableName(std::string const & input)
{
        if (input.find(' ') != std::string::npos) {
                std::cerr << "Warning: path \""
                          << input
                          << "\" contains spaces. "
                          << "LaTeX will have problems!\n"
        }
        return input;
}

int main(int argv, char * argc[])
{
        for (int i = 1; i < argv; ++i) {
                std::cout << getPortableName(argc[i]) << '\n';
        }
        std::flush(std::cout);
        return 0;
}

Could you (or indeed anyone else with access to a compiler environment on a 
Win32 box) write and test the equivalent function?

I'd imagine it would be something like

#include <iostream>
#include <string>
#include <windows.h>

std::string const getPortableName(std::string const & input)
{
        if (input.empty())
                return std::string();

        if (input.size() > MAX_PATH) {
                std::cerr << "Warning: path \""
                          << input
                          << "\" contains more than MAX_PATH chars.\n";
                return input;
        }

        char * output = new char [MAX_PATH];
        for (size_t i=0; i<MAX_PATH; ++i)
                output[i] = '\0';
        size_t const size =
                GetShortPathName(input.c_str(), output, MAX_PATH);
        std::string const result = size ? output : std::string();
        delete [] output;
        return result;
}

-- 
Angus

Reply via email to