static char * scriptify(const char *command) { FILE *fp; char *cmd, *name, *s, *p; int i; if((name = tempnam(".", "pip")) == NULL) return(NULL); p = getenv("COMSPEC"); s = getenv("SHELL"); cmd = malloc(strlen(name) + (s ? strlen(s) : 0) + 9); *cmd = '\0'; if (s) { slashify(strcpy(cmd, s), p); p = s; } slashify(name, p); if (! (i = unixshell(p))) { char *p = (char *) realloc(name, strlen(name) + 5); if (p == NULL) return NULL; name = p; strcat(name, ".bat"); } if (s) sprintf(cmd + strlen(cmd), " %cc ", unixshell(s) ? '-' : '/'); strcpy(p = cmd + strlen(cmd), name); free(name); if ((fp = fopen(p, i ? "wb" : "w")) != NULL) { if (! i) fputs("@echo off\n", fp); i = strlen(command); if ((fwrite(command, 1, i, fp) < i) || (fputc('\n', fp) == EOF)) cmd = NULL; } else cmd = NULL; if (fp) fclose(fp); return(cmd); }
/* * Canonize file and paths names. E.g. convert this: * g:\mingw32\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include * into something more readable: * g:\mingw32\lib\gcc\x86_64-w64-mingw32\4.8.1\include * * I.e. turns 'path' into a fully-qualified path. * * Note: the 'path' doesn't have to exist. * assumes 'result' is at least '_MAX_PATH' characters long (if non-NULL). */ char *_fixpath (const char *path, char *result) { if (!path || !*path) { DEBUGF (1, "given a bogus 'path'\n"); errno = EINVAL; return (NULL); } if (!result) result = CALLOC (_MAX_PATH, 1); /* GetFullPathName() doesn't seems to handle * '/' in 'path'. Convert to '\\'. * Note: the 'result' file or path may not exists. * Use 'FILE_EXISTS()' to test. * * to-do: maybe use GetLongPathName()? */ path = slashify (path, '\\'); if (!GetFullPathName(path, _MAX_PATH, result, NULL)) { DEBUGF (2, "GetFullPathName(\"%s\") failed: %s\n", path, win_strerror(GetLastError())); _strlcpy (result, path, _MAX_PATH); } return (result); }
void QUrl::setPath( const QString& path ) { d->path = path; slashify( d->path ); d->cleanPathDirty = TRUE; d->isValid = TRUE; }
/* * Return current user's home directory. Try: * - %HOME% * - %APPDATA% * - %USERPROFILE%\\Application Data * - else EC's dir. * * Not used yet. */ const char *ec_win_get_user_dir (void) { static char path[MAX_PATH] = ""; char *home; if (path[0]) return (path); home = getenv ("HOME"); if (home) strncpy (path, home, sizeof(path)-1); else { home = getenv ("APPDATA"); /* Win-9x/ME */ if (home) strncpy (path, home, sizeof(path)-1); else { home = getenv ("USERPROFILE"); /* Win-2K/XP */ if (home) snprintf (path, sizeof(path)-1, "%s\\Application Data", home); else strncpy (path, ec_win_get_ec_dir(), sizeof(path)-1); } } path [sizeof(path)-1] = '\0'; return slashify (path); }
void Q3Url::setPath( const QString& path ) { d->path = path; slashify( d->path ); d->cleanPathDirty = true; d->isValid = true; }
static char * ScrubRetpath (char * const retpath) { char * sspath = (char *)retpath; // // Check for null path because Win32 doesn't like them. // I.E.: Path lists of c:/foo;;c:/bar need changed to // c:/foo;c:/bar. // // This need be executed only if we actually converted the path. // while (*sspath) { if (*sspath == ';' && sspath[1] == ';') for (char *i = sspath; *i; i++) *i = *(i + 1); else sspath++; } if (*(sspath - 1) == ';') *(sspath - 1) = '\0'; // // If we modified the path then convert all / to \ if we have a path list // else convert all \ to /. // if ((strchr (retpath, ';'))) { backslashify (retpath, retpath, 0); } else { slashify (retpath, retpath, 0); } debug_printf("returning: %s", retpath); return retpath; }
void QUrl::setFileName( const QString& name ) { QString fn( name ); slashify( fn ); while ( fn[ 0 ] == '/' ) fn.remove( (uint)0, 1 ); QString p; if ( path().isEmpty() ) { p = "/"; } else { p = path(); int slash = p.findRev( QChar( '/' ) ); if ( slash == -1 ) { p = "/"; } else if ( p[ (int)p.length() - 1 ] != '/' ) { p.truncate( slash + 1 ); } } p += fn; if ( !d->queryEncoded.isEmpty() ) p += "?" + d->queryEncoded; setEncodedPathAndQuery( p ); }
void QFileInfo::setFile( const QFile &file ) { fn = file.name(); slashify( fn ); delete fic; fic = 0; }
void QFileInfo::setFile( const QDir &d, const QString &fileName ) { fn = d.filePath( fileName ); slashify( fn ); delete fic; fic = 0; }
void QFileInfo::setFile( const QString &file ) { fn = file; slashify( fn ); delete fic; fic = 0; }
QString QDir::homeDirPath() { QString d; d = QFile::decodeName(getenv("HOME")); slashify( d ); if ( d.isNull() ) d = rootDirPath(); return d; }
/* * Return directory of running program. */ const char *ec_win_get_ec_dir (void) { static char path[MAX_PATH] = "c:\\"; char *slash; if (GetModuleFileName(NULL,path,sizeof(path)) && (slash = strrchr(path,'\\')) != NULL) *slash = '\0'; return slashify (path); }
QFileInfo::QFileInfo( const QDir &d, const QString &fileName ) { fn = d.filePath( fileName ); slashify( fn ); fic = 0; cache = TRUE; #if defined(Q_OS_UNIX) symLink = FALSE; #endif }
QFileInfo::QFileInfo( const QFile &file ) { fn = file.name(); slashify( fn ); fic = 0; cache = TRUE; #if defined(Q_OS_UNIX) symLink = FALSE; #endif }
QUrl::QUrl( const QUrl& url, const QString& relUrl, bool checkSlash ) { d = new QUrlPrivate; QString rel = relUrl; slashify( rel ); QUrl urlTmp( url ); if ( !urlTmp.isValid() ) { urlTmp.reset(); } if ( isRelativeUrl( rel ) ) { if ( rel[ 0 ] == '#' ) { *this = urlTmp; rel.remove( (uint)0, 1 ); decode( rel ); setRef( rel ); } else if ( rel[ 0 ] == '?' ) { *this = urlTmp; rel.remove( (uint)0, 1 ); setQuery( rel ); } else { decode( rel ); *this = urlTmp; setRef( QString::null ); if ( checkSlash && d->cleanPath[(int)path().length()-1] != '/' ) { if ( isRelativeUrl( path() ) ) setEncodedPathAndQuery( rel ); else setFileName( rel ); } else { QString p = urlTmp.path(); if ( p.isEmpty() ) { // allow URLs like "file:foo" if ( !d->host.isEmpty() && !d->user.isEmpty() && !d->pass.isEmpty() ) p = "/"; } if ( !p.isEmpty() && p.right(1)!="/" ) p += "/"; p += rel; d->path = p; d->cleanPathDirty = TRUE; } } } else { if ( rel[ 0 ] == QChar( '/' ) ) { *this = urlTmp; setEncodedPathAndQuery( rel ); } else { *this = rel; } } }
QString QDir::canonicalPath() const { QString r; char cur[ PATH_MAX ]; char tmp[ PATH_MAX ]; QT_GETCWD( cur, PATH_MAX ); if ( QT_CHDIR( QFile::encodeName( dPath ) ) >= 0 ) { QT_GETCWD( tmp, PATH_MAX ); r = QFile::decodeName( tmp ); } QT_CHDIR( cur ); slashify( r ); return r; }
QString QDir::canonicalPath() const { QString r; char cur[PATH_MAX+1]; if ( ::getcwd( cur, PATH_MAX ) ) { char tmp[PATH_MAX+1]; // need the cast for old solaris versions of realpath that doesn't take // a const char*. if( ::realpath( (char*)QFile::encodeName( dPath ).data(), tmp ) ) r = QFile::decodeName( tmp ); slashify( r ); // always make sure we go back to the current dir ::chdir( cur ); } return r; }
QString QDir::homeDirPath() { QString d = p_getenv ( "HOME" ); if ( d.isNull () ) { d = p_getenv ( "USERPROFILE" ); if ( d.isNull () ) { QString homeDrive = p_getenv ( "HOMEDRIVE" ); QString homePath = p_getenv ( "HOMEPATH" ); if ( !homeDrive.isNull () && !homePath.isNull () ) { d = homeDrive + homePath; } else { d = rootDirPath (); } } } slashify( d ); return d; }
QString QDir::canonicalPath() const { QString r; char cur[PATH_MAX]; char tmp[PATH_MAX]; if (GETCWD( cur, PATH_MAX )) { if ( CHDIR(QFile::encodeName(dPath)) >= 0 ) { if (GETCWD( tmp, PATH_MAX )) { r = QFile::decodeName(tmp); } (void)CHDIR( cur ); } } slashify( r ); return r; }
QString QDir::currentDirPath() { QString result; STATBUF st; if ( STAT( ".", &st ) == 0 ) { char currentName[PATH_MAX]; if ( GETCWD( currentName, PATH_MAX ) != 0 ) result = QFile::decodeName(currentName); #if defined(DEBUG) if ( result.isNull() ) qWarning( "QDir::currentDirPath: getcwd() failed" ); #endif } else { #if defined(DEBUG) qWarning( "QDir::currentDirPath: stat(\".\") failed" ); #endif } slashify( result ); return result; }
QString QDir::currentDirPath() { QString result; struct stat st; if ( ::stat( ".", &st ) == 0 ) { char currentName[PATH_MAX+1]; if ( ::getcwd( currentName, PATH_MAX ) ) result = QFile::decodeName(currentName); #if defined(QT_DEBUG) if ( result.isNull() ) qWarning( "QDir::currentDirPath: getcwd() failed" ); #endif } else { #if defined(QT_DEBUG) qWarning( "QDir::currentDirPath: stat(\".\") failed" ); #endif } slashify( result ); return result; }
void Q3Url::addPath( const QString& pa ) { if ( pa.isEmpty() ) return; QString p( pa ); slashify( p ); if ( path().isEmpty() ) { if ( p[ 0 ] != QLatin1Char( '/' ) ) d->path = QLatin1String("/") + p; else d->path = p; } else { if ( p[ 0 ] != QLatin1Char( '/' ) && d->path[ (int)d->path.length() - 1 ] != QLatin1Char('/') ) d->path += QLatin1String("/") + p; else d->path += p; } d->cleanPathDirty = true; }
void QUrl::addPath( const QString& pa ) { if ( pa.isEmpty() ) return; QString p( pa ); slashify( p ); if ( path().isEmpty() ) { if ( p[ 0 ] != QChar( '/' ) ) d->path = "/" + p; else d->path = p; } else { if ( p[ 0 ] != QChar( '/' ) && d->path[ (int)d->path.length() - 1 ] != '/' ) d->path += "/" + p; else d->path += p; } d->cleanPathDirty = TRUE; }
/*! Returns the path of the URL. If \a correct is true, the path is cleaned (deals with too many or too few slashes, cleans things like "/../..", etc). Otherwise path() returns exactly the path that was parsed or set. \sa setPath() hasPath() */ QString Q3Url::path( bool correct ) const { if ( !correct ) return d->path; if ( d->cleanPathDirty ) { bool check = true; if ( QDir::isRelativePath( d->path ) ) { d->cleanPath = d->path; } else if ( isLocalFile() ) { #if defined(Q_OS_WIN32) // hack for stuff like \\machine\path and //machine/path on windows if ( ( d->path.left( 1 ) == QLatin1String("/") || d->path.left( 1 ) == QLatin1String("\\") ) && d->path.length() > 1 ) { d->cleanPath = d->path; bool share = (d->cleanPath[0] == QLatin1Char('\\') && d->cleanPath[1] == QLatin1Char('\\')) || (d->cleanPath[0] == QLatin1Char('/') && d->cleanPath[1] == QLatin1Char('/')); slashify( d->cleanPath, false ); d->cleanPath = QDir::cleanDirPath( d->cleanPath ); if ( share ) { check = false; while (d->cleanPath.at(0) != QLatin1Char('/') || d->cleanPath.at(1) != QLatin1Char('/')) d->cleanPath.prepend(QLatin1String("/")); } } #endif if ( check ) { QFileInfo fi( d->path ); if ( !fi.exists() ) d->cleanPath = d->path; else if ( fi.isDir() ) { QString canPath = QDir( d->path ).canonicalPath(); QString dir; if ( qt_resolve_symlinks && !canPath.isNull() ) dir = QDir::cleanDirPath( canPath ); else dir = QDir::cleanDirPath( QDir( d->path ).absPath() ); dir += QLatin1String("/"); if ( dir == QLatin1String("//") ) d->cleanPath = QLatin1String("/"); else d->cleanPath = dir; } else { QString p = QDir::cleanDirPath( (qt_resolve_symlinks ? fi.dir().canonicalPath() : fi.dir().absPath()) ); d->cleanPath = p + QLatin1String("/") + fi.fileName(); } } } else { if ( d->path != QLatin1String("/") && d->path[ (int)d->path.length() - 1 ] == QLatin1Char('/') ) d->cleanPath = QDir::cleanDirPath( d->path ) + QLatin1String("/"); else d->cleanPath = QDir::cleanDirPath( d->path ); } if ( check ) slashify( d->cleanPath, false ); d->cleanPathDirty = false; } return d->cleanPath; }
bool QUrl::parse( const QString& url ) { QString url_( url ); slashify( url_ ); if ( url_.isEmpty() ) { d->isValid = FALSE; return FALSE; } d->cleanPathDirty = TRUE; d->isValid = TRUE; QString oldProtocol = d->protocol; d->protocol = QString::null; const int Init = 0; const int Protocol = 1; const int Separator1= 2; // : const int Separator2= 3; // :/ const int Separator3= 4; // :// or more slashes const int User = 5; const int Pass = 6; const int Host = 7; const int Path = 8; const int Ref = 9; const int Query = 10; const int Port = 11; const int Done = 12; const int InputAlpha= 1; const int InputDigit= 2; const int InputSlash= 3; const int InputColon= 4; const int InputAt = 5; const int InputHash = 6; const int InputQuery= 7; static uchar table[ 12 ][ 8 ] = { /* None InputAlpha InputDigit InputSlash InputColon InputAt InputHash InputQuery */ { 0, Protocol, 0, Path, 0, 0, 0, 0, }, // Init { 0, Protocol, Protocol, 0, Separator1, 0, 0, 0, }, // Protocol { 0, Path, Path, Separator2, 0, 0, 0, 0, }, // Separator1 { 0, Path, Path, Separator3, 0, 0, 0, 0, }, // Separator2 { 0, User, User, Separator3, Pass, Host, 0, 0, }, // Separator3 { 0, User, User, User, Pass, Host, User, User, }, // User { 0, Pass, Pass, Pass, Pass, Host, Pass, Pass, }, // Pass { 0, Host, Host, Path, Port, Host, Ref, Query, }, // Host { 0, Path, Path, Path, Path, Path, Ref, Query, }, // Path { 0, Ref, Ref, Ref, Ref, Ref, Ref, Query, }, // Ref { 0, Query, Query, Query, Query, Query, Query, Query, }, // Query { 0, 0, Port, Path, 0, 0, 0, 0, } // Port }; bool relPath = FALSE; relPath = FALSE; bool forceRel = FALSE; // If ':' is at pos 1, we have only one letter // before that separator => that's a drive letter! if ( url_.length() >= 2 && url_[1] == ':' ) relPath = forceRel = TRUE; int hasNoHost = -1; int cs = url_.find( ":/" ); if ( cs != -1 ) // if a protocol is there, find out if there is a host or directly the path after it hasNoHost = url_.find( "///", cs ); table[ 4 ][ 1 ] = User; table[ 4 ][ 2 ] = User; if ( cs == -1 || forceRel ) { // we have a relative file if ( url.find( ':' ) == -1 || forceRel ) { table[ 0 ][ 1 ] = Path; // Filenames may also begin with a digit table[ 0 ][ 2 ] = Path; } else { table[ 0 ][ 1 ] = Protocol; } relPath = TRUE; } else { // some checking table[ 0 ][ 1 ] = Protocol; // find the part between the protocol and the path as the meaning // of that part is dependend on some chars ++cs; while ( url_[ cs ] == '/' ) ++cs; int slash = url_.find( "/", cs ); if ( slash == -1 ) slash = url_.length() - 1; QString tmp = url_.mid( cs, slash - cs + 1 ); if ( !tmp.isEmpty() ) { // if this part exists // look for the @ in this part int at = tmp.find( "@" ); if ( at != -1 ) at += cs; // we have no @, which means host[:port], so directly // after the protocol the host starts, or if the protocol // is file or there were more than 2 slashes, it´s the // path if ( at == -1 ) { if ( url_.left( 4 ) == "file" || hasNoHost != -1 ) table[ 4 ][ 1 ] = Path; else table[ 4 ][ 1 ] = Host; table[ 4 ][ 2 ] = table[ 4 ][ 1 ]; } } } int state = Init; // parse state int input; // input token QChar c = url_[ 0 ]; int i = 0; QString port; for ( ;; ) { switch ( c ) { case '?': input = InputQuery; break; case '#': input = InputHash; break; case '@': input = InputAt; break; case ':': input = InputColon; break; case '/': input = InputSlash; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': input = InputDigit; break; default: input = InputAlpha; } state = table[ state ][ input ]; switch ( state ) { case Protocol: d->protocol += c; break; case User: d->user += c; break; case Pass: d->pass += c; break; case Host: d->host += c; break; case Path: d->path += c; break; case Ref: d->refEncoded += c; break; case Query: d->queryEncoded += c; break; case Port: port += c; break; default: break; } ++i; if ( i > (int)url_.length() - 1 || state == Done || state == 0 ) break; c = url_[ i ]; } if ( !port.isEmpty() ) { port.remove( (uint)0, 1 ); d->port = atoi( port.latin1() ); } // error if ( i < (int)url_.length() - 1 ) { d->isValid = FALSE; return FALSE; } if ( d->protocol.isEmpty() ) d->protocol = oldProtocol; if ( d->path.isEmpty() ) d->path = "/"; // hack for windows if ( d->path.length() == 2 && d->path[ 1 ] == ':' ) d->path += "/"; // #### do some corrections, should be done nicer too if ( !d->pass.isEmpty() ) { if ( d->pass[ 0 ] == ':' ) d->pass.remove( (uint)0, 1 ); decode( d->pass ); } if ( !d->user.isEmpty() ) { decode( d->user ); } if ( !d->path.isEmpty() ) { if ( d->path[ 0 ] == '@' || d->path[ 0 ] == ':' ) d->path.remove( (uint)0, 1 ); if ( d->path[ 0 ] != '/' && !relPath && d->path[ 1 ] != ':' ) d->path.prepend( "/" ); } if ( !d->refEncoded.isEmpty() && d->refEncoded[ 0 ] == '#' ) d->refEncoded.remove( (uint)0, 1 ); if ( !d->queryEncoded.isEmpty() && d->queryEncoded[ 0 ] == '?' ) d->queryEncoded.remove( (uint)0, 1 ); if ( !d->host.isEmpty() && d->host[ 0 ] == '@' ) d->host.remove( (uint)0, 1 ); #if defined(Q_OS_WIN32) || defined(Q_OS_OS2) // hack for windows file://machine/path syntax if ( d->protocol == "file" ) { if ( url.left( 7 ) == "file://" && d->path.length() > 1 && d->path[ 1 ] != ':' ) d->path.prepend( "/" ); } #endif decode( d->path ); d->cleanPathDirty = TRUE; #if 0 qDebug( "URL: %s", url.latin1() ); qDebug( "protocol: %s", d->protocol.latin1() ); qDebug( "user: %s", d->user.latin1() ); qDebug( "pass: %s", d->pass.latin1() ); qDebug( "host: %s", d->host.latin1() ); qDebug( "path: %s", path().latin1() ); qDebug( "ref: %s", d->refEncoded.latin1() ); qDebug( "query: %s", d->queryEncoded.latin1() ); qDebug( "port: %d\n\n----------------------------\n\n", d->port ); #endif return TRUE; }
/*! Returns the path of the URL. If \a correct is TRUE, the path is cleaned (deals with too many or too few slashes, cleans things like "/../..", etc). Otherwise path() returns exactly the path that was parsed or set. \sa setPath() hasPath() */ QString QUrl::path( bool correct ) const { if ( !correct ) return d->path; if ( d->cleanPathDirty ) { bool check = TRUE; if ( QDir::isRelativePath( d->path ) ) { d->cleanPath = d->path; } else if ( isLocalFile() ) { #if defined(Q_OS_WIN32) || defined(Q_OS_OS2) // hack for stuff like \\machine\path and //machine/path on windows if ( ( d->path.left( 1 ) == "/" || d->path.left( 1 ) == "\\" ) && d->path.length() > 1 ) { d->cleanPath = d->path; bool share = (d->cleanPath[0] == '\\' && d->cleanPath[1] == '\\') || (d->cleanPath[0] == '/' && d->cleanPath[1] == '/'); slashify( d->cleanPath, FALSE ); d->cleanPath = QDir::cleanDirPath( d->cleanPath ); if ( share ) { check = FALSE; while (d->cleanPath.at(0) != '/' || d->cleanPath.at(1) != '/') d->cleanPath.prepend("/"); } } #endif if ( check ) { QFileInfo fi( d->path ); if ( !fi.exists() ) d->cleanPath = d->path; else if ( fi.isDir() ) { QString dir = QDir::cleanDirPath( (qt_resolve_symlinks ? QDir( d->path ).canonicalPath() : QDir( d->path ).absPath()) ) + "/"; if ( dir == "//" ) d->cleanPath = "/"; else d->cleanPath = dir; } else { QString p = QDir::cleanDirPath( (qt_resolve_symlinks ? fi.dir().canonicalPath() : fi.dir().absPath()) ); d->cleanPath = p + "/" + fi.fileName(); } } } else { if ( d->path != "/" && d->path[ (int)d->path.length() - 1 ] == '/' ) d->cleanPath = QDir::cleanDirPath( d->path ) + "/"; else d->cleanPath = QDir::cleanDirPath( d->path ); } if ( check ) slashify( d->cleanPath, FALSE ); d->cleanPathDirty = FALSE; } return d->cleanPath; }
int runIdc(int argc, char **argv) { QString error; QString tlbfile; QString idlfile; QString input; QString version = QLatin1String("1.0"); int i = 1; while (i < argc) { QString p = QString::fromLocal8Bit(argv[i]).toLower(); if (p == QLatin1String("/idl") || p == QLatin1String("-idl")) { ++i; if (i > argc) { error = QLatin1String("Missing name for interface definition file!"); break; } idlfile = QLatin1String(argv[i]); idlfile = idlfile.trimmed().toLower(); } else if (p == QLatin1String("/version") || p == QLatin1String("-version")) { ++i; if (i > argc) version = QLatin1String("1.0"); else version = QLatin1String(argv[i]); } else if (p == QLatin1String("/tlb") || p == QLatin1String("-tlb")) { ++i; if (i > argc) { error = QLatin1String("Missing name for type library file!"); break; } tlbfile = QLatin1String(argv[i]); tlbfile = tlbfile.trimmed().toLower(); } else if (p == QLatin1String("/v") || p == QLatin1String("-v")) { fprintf(stdout, "Qt Interface Definition Compiler version 1.0\n"); return 0; } else if (p == QLatin1String("/regserver") || p == QLatin1String("-regserver")) { if (!registerServer(input)) { fprintf(stderr, "Failed to register server!\n"); return 1; } fprintf(stderr, "Server registered successfully!\n"); return 0; } else if (p == QLatin1String("/unregserver") || p == QLatin1String("-unregserver")) { if (!unregisterServer(input)) { fprintf(stderr, "Failed to unregister server!\n"); return 1; } fprintf(stderr, "Server unregistered successfully!\n"); return 0; } else if (p[0] == QLatin1Char('/') || p[0] == QLatin1Char('-')) { error = QLatin1String("Unknown option \"") + p + QLatin1Char('\"'); break; } else { input = QLatin1String(argv[i]); input = input.trimmed().toLower(); } i++; } if (!error.isEmpty()) { fprintf(stderr, "%s", error.toLatin1().data()); fprintf(stderr, "\n"); return 5; } if (input.isEmpty()) { fprintf(stderr, "No input file specified!\n"); return 1; } if (input.endsWith(QLatin1String(".exe")) && tlbfile.isEmpty() && idlfile.isEmpty()) { fprintf(stderr, "No type output file specified!\n"); return 2; } if (input.endsWith(QLatin1String(".dll")) && idlfile.isEmpty() && tlbfile.isEmpty()) { fprintf(stderr, "No interface definition file and no type library file specified!\n"); return 3; } slashify(input); if (!tlbfile.isEmpty()) { slashify(tlbfile); QFile file(tlbfile); if (!file.open(QIODevice::ReadOnly)) { fprintf(stderr, "Couldn't open %s for read\n", (const char*)tlbfile.toLocal8Bit().data()); return 4; } QByteArray data = file.readAll(); QString error; bool ok = attachTypeLibrary(input, 1, data, &error); fprintf(stderr, "%s", error.toLatin1().data()); fprintf(stderr, "\n"); return ok ? 0 : 4; } else if (!idlfile.isEmpty()) { slashify(idlfile); idlfile = quotePath(idlfile); fprintf(stderr, "\n\n%s\n\n", (const char*)idlfile.toLocal8Bit().data()); quotePath(input); HRESULT res = dumpIdl(input, idlfile, version); switch(res) { case S_OK: break; case E_FAIL: fprintf(stderr, "IDL generation failed trying to run program %s!\n", (const char*)input.toLocal8Bit().data()); return res; case -1: fprintf(stderr, "Couldn't open %s for writing!\n", (const char*)idlfile.toLocal8Bit().data()); return res; case 1: fprintf(stderr, "Malformed appID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 2: fprintf(stderr, "Malformed typeLibID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 3: fprintf(stderr, "Class has no metaobject information (error in %s)!\n", (const char*)input.toLocal8Bit().data()); return res; case 4: fprintf(stderr, "Malformed classID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 5: fprintf(stderr, "Malformed interfaceID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; case 6: fprintf(stderr, "Malformed eventsID value in %s!\n", (const char*)input.toLocal8Bit().data()); return res; default: fprintf(stderr, "Unknown error writing IDL from %s\n", (const char*)input.toLocal8Bit().data()); return 7; } } return 0; }
bool checkDriveType(char *name, ULONG *pid) { HANDLE hDevice; PSTORAGE_DEVICE_DESCRIPTOR pDevDesc; DEVICE_NUMBER deviceInfo; bool retVal = false; char *nameWithSlash; char *nameNoSlash; int driveType; DWORD cbBytesReturned; // some calls require no tailing slash, some require a trailing slash... if ( !(slashify(name, &nameWithSlash, &nameNoSlash)) ) { return(retVal); } driveType = GetDriveType(nameWithSlash); switch( driveType ) { case DRIVE_REMOVABLE: // The media can be removed from the drive. case DRIVE_FIXED: // The media cannot be removed from the drive. hDevice = CreateFile(nameNoSlash, FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == INVALID_HANDLE_VALUE) { //printf("error - not able to get handle on device"); //setbuf(stdout, NULL); } else { int arrSz = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1; pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[arrSz]; pDevDesc->Size = arrSz; // get the device number if the drive is // removable or (fixed AND on the usb bus, SD, or MMC (undefined in XP/mingw)) if(GetDisksProperty(hDevice, pDevDesc, &deviceInfo) && ( ((driveType == DRIVE_REMOVABLE) && (pDevDesc->BusType != BusTypeSata)) || ( (driveType == DRIVE_FIXED) && ((pDevDesc->BusType == BusTypeUsb) || (pDevDesc->BusType == /*BusTypeSd*/0xC ) || (pDevDesc->BusType == /*BusTypeMmc*/0xD )) ) ) ) { // ensure that the drive is actually accessible // multi-card hubs were reporting "removable" even when empty if(DeviceIoControl(hDevice, IOCTL_STORAGE_CHECK_VERIFY2, NULL, 0, NULL, 0, &cbBytesReturned, (LPOVERLAPPED) NULL)) { *pid = deviceInfo.DeviceNumber; retVal = true; } else // IOCTL_STORAGE_CHECK_VERIFY2 fails on some devices under XP/Vista, try the other (slower) method, just in case. { CloseHandle(hDevice); hDevice = CreateFile(nameNoSlash, FILE_READ_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if(DeviceIoControl(hDevice, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &cbBytesReturned, (LPOVERLAPPED) NULL)) { *pid = deviceInfo.DeviceNumber; retVal = true; } } } delete[] pDevDesc; CloseHandle(hDevice); } break; default: retVal = false; } // free the strings allocated by slashify free(nameWithSlash); free(nameNoSlash); return(retVal); }