int gs_chdir(char *dirname) { int rc = 0; DosError(FERR_DISABLEHARDERR); #ifdef __BORLANDC__ if (isalpha(dirname[0]) && (dirname[1]==':')) (void) setdisk(toupper(dirname[0])-'A'); if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':'))) chdir(dirname); rc = 1; #else #ifdef __IBMC__ if (isalpha(dirname[0]) && (dirname[1]==':')) if (_chdrive(toupper(dirname[0])-'A'+1)) rc = -1; if (!rc && !((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':'))) rc = _chdir(dirname); #else if (isalpha((int)(dirname[0])) && (dirname[1]==':')) if (_chdrive(dirname[0])) rc = -1; rc = _chdir2(dirname); #endif #endif DosError(FERR_ENABLEHARDERR); return rc; }
/** Returns if a given drive exists. * * @param drive * @return */ int LbDriveExists(const unsigned int drive) { int result; #if defined(WIN32)||defined(DOS)||defined(GO32) unsigned int lastdrive=_getdrive(); if ( _chdrive(drive) ) { result = -1; } else { result = 1; _chdrive(lastdrive); } #else //Let's assume we have only 'C' drive on Unix if ( drive!=3 ) { result = -1; } else { result = 1; } #endif return result; }
int make_path(char *s) { SEH_PUSH("make_path"); char current_path[MAX_PATH], *p, *flp; p = flp = _strdup(s); _getdcwd(0, current_path, MAX_PATH); int current_drive = toupper(*current_path) - '@'; if (LAST(p) == WWIV_FILE_SEPERATOR_CHAR) { LAST(p) = 0; } if (p[1] == ':') { int drive = toupper(p[0]) - 'A' + 1; if (_chdrive(drive)) { _chdir(current_path); _chdrive(current_drive); return -2; } p += 2; } if ( *p == WWIV_FILE_SEPERATOR_CHAR ) { _chdir( WWIV_FILE_SEPERATOR_STRING ); p++; } for (; (p = strtok(p, WWIV_FILE_SEPERATOR_STRING)) != 0; p = 0) { if (_chdir(p)) { if (_mkdir(p)) { _chdir(current_path); _chdrive(current_drive); return -1; } _chdir(p); } } _chdir(current_path); if (flp) { free(flp); } return 0; }
bool mmOperatingSystem::IsExistingDir(mmString p_sDirName) { bool v_bRes = false; // pobieram aktywny dysk i œcie¿kê int v_iDriveNo = _getdrive(); wchar_t* v_pcCurDir = _wgetcwd(NULL,_MAX_PATH); if(v_pcCurDir == NULL) { throw mmError(mmeBadAlloc); }; // prubujê przejœæ do œcie¿ki p_sDirName if(_wchdir(p_sDirName.c_str()) == 0) { v_bRes = true; }; // przywracam poprzedni dysk i œcie¿kê _chdrive(v_iDriveNo); if(_wchdir(v_pcCurDir) != 0) { throw mmError(mmeUnknownError); }; // zwalniam pamiêæ przydzielon¹ przez getcwd free(v_pcCurDir); return v_bRes; }
int main(int argc, char **argv) //argv = {gameDrive:gameDir, gameCommand} { int i; char currentDrive, newDrive; int driveVal; char *path; char **cmdargv = argv+2; if(argc < 3) { fprintf(stderr, "Usage: %s drive:dir cmd [args]\n", argv[0]); fprintf(stderr, "Args not supported yet.\n"); exit(1); } newDrive = argv[1][0]; path = argv[1]+2; driveVal = toupper(newDrive) - 'A' + 1; currentDrive = _getdrive(); // get current drive; if(driveVal != currentDrive) { if(_chdrive(driveVal)) { // change to game drive fprintf(stderr, "Error: exec: chdrive(%d) failed.\n", driveVal); fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal); exit(2); } } if(_chdir(path)) { // change to game directory fprintf(stderr, "Error: exec: chdir %s failed.\n", path); fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal); exit(2); } _execl(cmdargv[0], cmdargv[0], NULL); // start game. No args yet. fprintf(stderr, "Error: exec(%s...) failed.\n", cmdargv[0]); fprintf(stderr, "path %s, drive %c, driveVal %d\n", path, newDrive, driveVal); exit(2); }
int setdrive(int WXUNUSED_IN_WINCE(drive)) { #ifdef __WXWINCE__ return 0; #elif defined(__GNUWIN32__) && \ (defined(__MINGW32_MAJOR_VERSION) && __MINGW32_MAJOR_VERSION >= 1) return _chdrive(drive); #else wxChar newdrive[4]; if (drive < 1 || drive > 31) return -1; newdrive[0] = (wxChar)(wxT('A') + drive - 1); newdrive[1] = wxT(':'); #ifdef __OS2__ newdrive[2] = wxT('\\'); newdrive[3] = wxT('\0'); #else newdrive[2] = wxT('\0'); #endif #if defined(__WXMSW__) if (::SetCurrentDirectory(newdrive)) #else // VA doesn't know what LPSTR is and has its own set if (!DosSetCurrentDir((PSZ)newdrive)) #endif return 0; else return -1; #endif // !GNUWIN32 }
void cd_to( const char *s ) { char s1[81]; strcpy(s1, s); SEH_PUSH("cd_to()"); int i = strlen(s1) - 1; int db = (s1[i] == '\\'); if ( i == 0 ) { db = 0; } if ( i == 2 && s1[1] == ':' ) { db = 0; } if (db) { s1[i] = 0; } _chdir( s1 ); if ( s[1] == ':' ) { int drive = toupper(s[0]) - 'A' + 1; _chdrive(drive); // FIX, On Win32, _chdrive is 'A' = 1, etc.. if (s[2] == 0) { _chdir("\\"); } } }
/* * @implemented */ char* _getdcwd(int nDrive, char* caBuffer, int nBufLen) { int i =0; int dr = _getdrive(); if (nDrive < 1 || nDrive > 26) return NULL; if (dr != nDrive) { if ( _chdrive(nDrive) != 0 ) return NULL; } i = GetCurrentDirectoryA(nBufLen, caBuffer); if (i == nBufLen) return NULL; if (dr != nDrive) { if ( _chdrive(dr) != 0 ) return NULL; } return caBuffer; }
/* * Chdrive() changes the default drive. */ void chdrive(char *str) { char *ptr; char drive; if ((ptr = index(str, ':')) != (char *)0) { drive = toupper(*(ptr - 1)); _chdrive((drive - 'A') + 1); } }
/* * NAME: P->chdir() * DESCRIPTION: change the current directory (and drive) */ int P_chdir(const char *dir) { char buf[STRINGSZ]; if (path_file(buf, dir) == (char *) NULL || _chdir(buf) < 0) { return -1; } if (buf[1] == ':' && _chdrive(toupper(buf[0]) - 'A' + 1) < 0) { return -1; } return 0; }
char * DCirfile::PathRight(void) { if (SecFound) return SecFile->PathRight(); if (CurrRight == NULL) return NULL; char *chp = strncpy(NewName(RightLen + 1), CurrRight, RightLen); chp[RightLen] = '\0'; char *currdir = _getcwd(NewName(1024), 1024); char *inidir = this->getBasePath(); int currdrive = _getdrive(); int inidrive = 0; if (stricmp(currdir, inidir) && !PathIsURL(chp) && PathIsRelative(chp)) { // fix rel path if (*(inidir + 1) == ':') inidrive = (toupper(*inidir) - 'A') + 1; if (inidrive && (currdrive != inidrive)) _chdrive(inidrive); _chdir(inidir); char *nref = NewName(MAX_PATH); if (_fullpath(nref, chp, MAX_PATH)) { DeleteName(chp); chp = NewName(nref); } DeleteName(nref); if (inidrive && (currdrive != inidrive)) _chdrive(currdrive); _chdir(currdir); } DeleteName(currdir); return chp; }
// Changes to a drive if valid.. 1=A, 2=B, etc // If flag, then changes to it. // Returns 0 if not-valid, 1 if valid. int cfile_chdrive( int DriveNum, int flag ) { int Valid = 0; int n, org; org = -1; if (!flag) org = _getdrive(); _chdrive( DriveNum ); n = _getdrive(); if (n == DriveNum ) Valid = 1; if ( (!flag) && (n != org) ) _chdrive( org ); return Valid; }
int WWIV_make_path(const char *s) { char drive, current_path[MAX_PATH], current_drive, *p, *flp; p = flp = WWIV_STRDUP(s); _getdcwd(0, current_path, MAX_PATH); current_drive = static_cast< char >(*current_path - '@'); if (LAST(p) == WWIV_FILE_SEPERATOR_CHAR) { LAST(p) = 0; } if (p[1] == ':') { drive = static_cast< char >(wwiv::UpperCase<char>(p[0]) - 'A' + 1); if (_chdrive(drive)) { _chdir(current_path); _chdrive(current_drive); return -2; } p += 2; } if (*p == WWIV_FILE_SEPERATOR_CHAR) { _chdir(WWIV_FILE_SEPERATOR_STRING); p++; } for (; (p = strtok(p, WWIV_FILE_SEPERATOR_STRING)) != 0; p = 0) { if (_chdir(p)) { if (_mkdir(p)) { _chdir(current_path); _chdrive(current_drive); return -1; } _chdir(p); } } _chdir(current_path); if (flp) { free(flp); } return 0; }
int CanChangeDrive(int *drive) { for (auto test_drive = 1; test_drive <= 26; test_drive++) { if (!_chdrive(test_drive)) { if (test_drive + 'A' - 1 > 'D') { *drive = test_drive; return 0; } } } return -1; }
// restores the path from the variable passed. pDirSave stores the pointer // to the path string. returns an error if a path has never been pushed. NPError wfe_PopPath(LPSTR pPathSave) { // only allows "one deep" stack if(pPathSave == NULL) return NPERR_GENERIC_ERROR; // restore the drive int chdriveErr = _chdrive(wfe_MapAsciiToDriveNum(pPathSave[0])); // restore the CWD int chdirErr = _chdir(pPathSave); free(pPathSave); return NPERR_NO_ERROR; }
BOOL Getallparmapinfo() { BOOL bFindFloppy = FALSE,bFloppy; int i, j = 0; PARMAPINFO *pNew = NULL; DRIVE_MAP_INFO drvinfo; g_nTotalDrive = 0; for(i='A'; i<='Z'; i++) { if(!_chdrive(i-'A'+1)) { g_nTotalDrive ++; g_drives[i-'A'] = i; bFloppy = IsFloppyDisk(i-'A'+1); if (!bFindFloppy) { g_chLogDrive = i; bFindFloppy = bFloppy; } if (!bFloppy) { _fmemset(&drvinfo,0,sizeof(DRIVE_MAP_INFO)); if (GetDriveMapInfo(i - 'A' + 1, &drvinfo)) { pNew = (PARMAPINFO*)malloc(sizeof(PARMAPINFO)); pNew->cDrv=i; pNew->dmiInt13Unit = drvinfo.dmiInt13Unit; pNew->dmiPartitionStartRBA = drvinfo.dmiPartitionStartRBA[0]; pNew->pNext = g_pParMapInfo; g_pParMapInfo = pNew; } } } else { g_drives[i-'A'] = 0; } } return TRUE; }
/* Handle "CD XXX" command in same process */ bool sys_process_cd(RexxExitContext *context, const char *command, const char * cmd, RexxObjectPtr &res) { const char * st; int rc; res = NULLOBJECT; st = &cmd[3]; while ((*st) && (*st == ' ')) { st++; } if (!*st) { return false; } if ((strlen(st) == 2) && (st[1] == ':')) { rc = _chdrive(toupper( *st ) - 'A' + 1); } else { char *unquoted = unquote(st); if (unquoted == NULL) { return false; } rc = _chdir(unquoted); free(unquoted); } if (rc != 0) { context->RaiseCondition("ERROR", context->String(command), NULLOBJECT, context->WholeNumberToObject(GetLastError())); } else { res = context->False(); } return true; }
int main(int argc,char ** argv) { char * startupdir=getenv("PMC"); if(startupdir){ strupr(startupdir); if(startupdir[1] == ':'){ _chdrive(startupdir[0]-'A'+1); } chdir(startupdir); } for(int i=1; i<argc; i++){ if(!strcmp(argv[i], "--debug")){ g_bCommDebug = true; } } setlocale(LC_ALL,"chs"); utils_puts = rtk_logged_puts; twith(); serv.RegisterService(argc, argv); twithout(); return 0; }
int dcl_change_dir(char *vms) { char dos[MAX_TOKEN]; char wrk[MAX_TOKEN]; char token[MAX_TOKEN]; int recurse; if (vms == NULL) return(DCL_ERROR); *dos = 0; *wrk = 0; *token = 0; dcl_trim(vms, wrk); cvfs_vms_to_dos(wrk,dos,&recurse); /*(void) strupr(dos);***************************/ if (dos[strlen(dos)-1]==SLASH_CHR && strlen(dos) > 1 && dos[strlen(dos)-2]!=':') dos[strlen(dos)-1] = 0; #ifdef _WIN32 if (dos[1] == ':'){ (void) _chdrive(dos[0] - '@'); strcpy(vms,"SYS$DISK"); token[0] = dos[0]; token[1] = ':'; token[2] = 0; (void) logical_put(vms,token,LOG_SYSTEM); if (strlen(&dos[2])) { if (_chdir(dos)) { (void) dcl_printf(dcl[D].SYS_OUTPUT,"%s: %s\n",vms,strerror(errno)); } } } else #endif if (chdir(dos)) { (void) dcl_printf(dcl[D].SYS_OUTPUT,"%s: %s\n",vms,strerror(errno)); } return(0); }
// Changes the current disk drive into given one int LbDriveChange(const unsigned int drive) { int result; #if defined(WIN32)||defined(DOS)||defined(GO32) int reterror = _chdrive(drive); if ( reterror ) { result = -1; } else { result = 1; } #else //Let's assume we can only be on 'C' drive on Unix if ( drive!=3 ) { result = -1; } else { result = 1; } #endif return result; }
/*************************************************************************** * Function : FP_MakeDirW * * Description: create directories recursively * * Return: RESULT_ERROR/RESULT_OK * * Notes: * **************************************************************************/ LOGICAL FP_MakeDir( const char * path ) { #if (COMPILER != GNU) && (OSTYPE == WIN32) char p[PATH_MAX], currentdir[PATH_MAX]; char *start, *t, *pos; size_t i; int curd; if (!path) return RESULT_ERR; i = strlen(path); if (i>=PATH_MAX) { MSG_PrintError(MSG_CMD_LONG_NAME_s, path); return RESULT_ERR; } if (!FP_FullName(p, path)) { strcpy(p, path); FP_NormalizePath(p); } else i = strlen(p); if (p[i-1]=='\\') p[--i]=0; if (!p[0]) return RESULT_OK; /* save current drive and directory */ curd = _getdrive(); if (!getcwd(currentdir, PATH_MAX)) { MSG_PrintFileError(path); return RESULT_ERR; } start=&p[0]; /* check for share names */ if (p[0]=='\\' && p[1]=='\\' && p[2]!='?') { start = strchr(p+2, '\\'); /* if only server is specified */ if (!start) { /* check if server exists */ if (chdir(p)<0) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); /* if only share name is specified */ return RESULT_ERR; } _chdrive( curd); chdir( currentdir ); return RESULT_OK; } /* skip sequential slashes */ while ( '\\'== *start) start++; start = strchr(start, '\\'); /* if only server and share name specified */ if (!start) { /* check if server exists */ if (chdir(p)<0) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); /* if only share name is specified */ return RESULT_ERR; } _chdrive( curd); chdir( currentdir ); return RESULT_OK; } *start = 0; if (chdir(p)<0) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); /* if only share name is specified */ return RESULT_ERR; } *start = '\\'; /* skip sequential slashes */ while ( '\\'== *start) start++; } else if ((toupper(p[0])-'A')<26 && p[1]==':') { start = &p[2]; if (_chdrive(toupper(p[0])-'A'+1)==-1) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); return RESULT_ERR; }; if (*start == '\\') { start++; chdir("\\"); } } t=&p[i-1]; pos = t+2; /* find last directory which exists to workaround POSIX */ while (-1 == chdir(p)) { *pos='\\'; /* look backward for previous directory name */ while ('\\' != *t && t!=start) t--; if (t==start) break; /* we found the start of name */ pos = t; *t = 0; t--; } *pos='\\'; if (t==&p[i-1]) { _chdrive( curd); chdir( currentdir ); return RESULT_OK; } if ('\\' == t[1]) start = t+2; /* ASSERTION: start directory is really exists */ do { t = strchr( start, '\\' ); if ( t ) *t = 0; if ( -1 == chdir( start ) ) { if (-1 == mkdir( start ) && errno!=EEXIST) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); _chdrive( curd); chdir( currentdir ); return RESULT_ERR; } /* try to enter a directory*/ if (-1 == chdir( start )) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); _chdrive( curd); chdir( currentdir ); return RESULT_ERR; } } if ( t ) { *t = '\\'; start = t + 1; /* skip sequential slasses */ while ('\\' == *start) start++; } } while ( t ); /* restore previous directory */ _chdrive( curd); chdir( currentdir ); return RESULT_OK; #else /* next part is for non WINDOWS OS */ char p[PATH_MAX], currentdir[PATH_MAX]; char *start, *t, *pos; size_t i; if (!path) return RESULT_ERR; i = strlen(path); if (i>=PATH_MAX) { MSG_PrintError(MSG_CMD_LONG_NAME_s, path); return RESULT_ERR; } strcpy(currentdir, path); if (!realpath(currentdir, p)) { strcpy(p, currentdir); FP_NormalizePath(p); } else i = strlen(p); if (p[i-1]=='/') p[--i]=0; if (!p[0]) return RESULT_OK; if (!getcwd(currentdir, PATH_MAX)) { MSG_PrintFileError(path); return RESULT_ERR; } start=&p[0]; t=&p[i-1]; pos = t+2; /* find last directory which exists to workaround POSIX */ while (-1 == chdir(p)) { *pos='/'; /* look backward for previous directory name */ while (*t!='/' && t!=start) t--; if (t==start) break; /* we found the start of name */ pos = t; *t = 0; t--; } *pos='/'; if (t==&p[i-1]) { /* nothing to create */ chdir( currentdir ); return RESULT_OK; } if ('/' == t[1]) start = t+2; do { t = strchr( start, '/' ); if ( t ) *t = 0; if ( -1 == chdir( start ) ) { if ( -1 == mkdir(start, 0777 ) && errno!=EEXIST) { chdir( currentdir ); return RESULT_ERR; } if (-1 == chdir( start )) { MSG_PrintError(MSG_FILE_DIR_CANT_CREATE_s, path); chdir( currentdir ); return RESULT_ERR; } } if ( t ) { *t = '/'; start = t + 1; /* skip sequential slasses */ while ('/' == start) start++; } } while ( t ); /* restore previous directory */ chdir( currentdir ); return RESULT_OK; #endif }
DCirfile * DCirfile::SetConfigTemplate(const char *sect, const char *setting, bool link) { DCirfile *bottomIni = SecFile ? SecFile : this; bool secfound = false; char *startdir = _getcwd(NewName(1024), 1024); char *currdir = startdir; char *newdir = NULL; int startdrive = _getdrive(); int currdrive = startdrive; int newdrive = 0; IniLevel = 0; if (!LogEventFunc) LastConfigSetting = NewName(setting); if (SecFile != NULL) { IniFileList.add(SecFile, ++IniLevel); IniNameList.add(SecFile->getBaseName(), IniLevel); IniChainList.add(SecFile->getFilePath(), IniLevel); } IniFileList.add(this, ++IniLevel); IniNameList.add(getBaseName(), IniLevel); IniChainList.add(getFilePath(), IniLevel); DCirfile *configTpl = NULL; char *configTplName = NULL; // SecFile (specific ini) overrides tpl choice in this DCirfile *topIni = this; secfound = Section(sect); if (secfound && Find("Scope")) Scope = StrRight(); if (secfound && !stricmp(setting, "configs") && Find("Document")) { // insert document chain here DCirfile *topdoc = this; while (topdoc->Section(sect)) { if (!topdoc->Find("Document")) break; // end of chain with no end flag **** char *nm = topdoc->StrRight(); if (!nm) break; // end of chain with no end flag **** if (!stricmp(nm, "end")) { DeleteName(nm); topdoc->ChainEnded = true; break; // end of chain with end flag } DeleteName(nm); if ((configTplName = topdoc->PathRight()) == NULL) break; // end of chain with no end flag **** if ((configTpl = new DCirfile(configTplName)) == NULL) { LogEvent(logwarn, 1, topdoc->getFilePath(), " refers to unopenable ", "Document template", " ", NewName(configTplName)); DeleteName(configTplName); configTplName = NULL; break; } if (configTpl->FErr() != fok) { LogEvent(logwarn, 1, topdoc->getFilePath(), " refers to nonexistent ", "Document template", " ", NewName(configTpl->getFilePath())); DeleteName(configTplName); configTplName = NULL; delete configTpl; break; // file not found } newdir = configTpl->getBasePath(); if (*(newdir + 1) == ':') newdrive = (toupper(*newdir) - 'A') + 1; if (newdrive && (currdrive != newdrive)) _chdrive(currdrive = newdrive); if (stricmp(newdir, currdir)) _chdir(currdir = newdir); if (IniNameList(configTpl->getBaseName())) { LogEvent(logwarn, 1, topdoc->getFilePath(), " repeats ", "Document template", " ", NewName(configTpl->getFilePath())); DeleteName(configTplName); configTplName = NULL; delete configTpl; break; // deja vu, end of the line } topdoc = configTpl; // step up if (topdoc->Section("Templates") && topdoc->Find("Scope")) topdoc->Scope = topdoc->StrRight(); DeleteName(configTplName); configTplName = NULL; IniFileList.add(topdoc, ++IniLevel); IniNameList.add(topdoc->getBaseName(), IniLevel); IniChainList.add(topdoc->getFilePath(), IniLevel); } } if (!secfound || !Find(setting)) { // check for old setting if (!stricmp(setting, "configs")) { if (Section("Setup") && Find("ConfigTemplate")) { sect = "Setup"; setting = "ConfigTemplate"; } else if (Section("FDK") && Find("ConfigTemplate")) { sect = "FDK"; setting = "ConfigTemplate"; } } else if (!stricmp(setting, "languages")) { if (Section("Setup") && Find("LanguageText")) sect = "Setup"; setting = "LanguageText"; } else if (!stricmp(setting, "macros")) { if (Section("Macros") && Find("MacroFile")) { sect = "Macros"; setting = "MacroFile"; } } } while (topIni->Section(sect)) { if (!topIni->Find(setting)) break; // end of chain with no end flag **** char *nm = topIni->StrRight(); if (!nm) break; // end of chain with no end flag **** if (!stricmp(nm, "end")) { DeleteName(nm); topIni->ChainEnded = true; break; // end of chain with end flag } DeleteName(nm); if ((configTplName = topIni->PathRight()) == NULL) break; // end of chain with no end flag **** if ((configTpl = new DCirfile(configTplName)) == NULL) { LogEvent(logwarn, 1, topIni->getFilePath(), " refers to unopenable ", setting, " ", NewName(configTplName)); DeleteName(configTplName); configTplName = NULL; break; // can't open file } if (configTpl->FErr() != fok) { LogEvent(logwarn, 1, topIni->getFilePath(), " refers to nonexistent ", setting, " ", NewName(configTpl->getFilePath())); DeleteName(configTplName); configTplName = NULL; delete configTpl; break; // file not found } newdir = configTpl->getBasePath(); if (*(newdir + 1) == ':') newdrive = (toupper(*newdir) - 'A') + 1; if (newdrive && (currdrive != newdrive)) _chdrive(currdrive = newdrive); if (stricmp(newdir, currdir)) _chdir(currdir = newdir); if (IniNameList(configTpl->getBaseName())) { LogEvent(logwarn, 1, topIni->getFilePath(), " repeats ", setting, " ", NewName(configTpl->getFilePath())); DeleteName(configTplName); configTplName = NULL; delete configTpl; break; // deja vu, end of the line } topIni = configTpl; // step up if (topIni->Section("Templates") && topIni->Find("Scope")) topIni->Scope = topIni->StrRight(); DeleteName(configTplName); configTplName = NULL; IniFileList.add(topIni, ++IniLevel); IniNameList.add(topIni->getBaseName(), IniLevel); IniChainList.add(topIni->getFilePath(), IniLevel); } // topIni is now at the top of the chain, and // bottomIni is at the bottom, which may be same. if (link) { DCirfile *ifl = bottomIni; DCirfile *ift = NULL; for (long ilev = 1; ilev < IniLevel; ilev++) { ift = (DCirfile *) IniFileList.find(ilev + 1); if (!ift) break; ift->SetSecFile(ifl); ifl = ift; //if (ifl == topIni) // break; } } WriteIniChain(setting); if (currdrive != startdrive) _chdrive(startdrive); if (stricmp(startdir, currdir)) _chdir(startdir); if (this != topIni) { topIni->IniFileList = IniFileList; topIni->IniNameList = IniNameList; topIni->IniChainList = IniChainList; topIni->IniLevel = IniLevel; } return topIni; }
bool FileUtils::mkdirs( const String &path ) { bool res = false; ASSERT_D( path.length() > 0 ); #if defined(_WINDOWS) || defined(WIN32) TCHAR abspath[_MAX_PATH]; TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath_s( _tfullpath( abspath, path.c_str(), _MAX_PATH ), drive, dir, fname, ext ); // remember the current drive int curDrive = _getdrive(); // set the current drive _chdrive( toupper(drive[0]) - 'A' + 1 ); // now start parsing out the path and create all directoried in the // heirarchy String createPath; String dirStr(dir); dirStr += fname; StringUtils::trimBoth( FileUtils::PATH_SEP_PAT, dirStr ); StringTokenizer tok(dirStr, FileUtils::PATH_SEP_PAT); while( tok.hasMoreTokens() ) { createPath += FileUtils::PATH_SEP; createPath += tok.getNextToken(); res = FileUtils::mkdir( createPath ); if ( !res ) { break; } } _chdrive( curDrive ); #else // the first step is to figure out where the path // starts. If the path contains a .. or . prefix, then // we have to calculate the start of the creation path // if it does not contain such prefix, then we'll just create // the directories relative to the current working directory String rootPath; String parsePath; String::size_type startPos = path.find_first_not_of( NTEXT("/.") ); if ( startPos != 0 ) { // there was at least one of these delimiters as a prefix String prefixStr( path, 0, startPos ); rootPath = FileUtils::resolve( prefixStr ); if ( rootPath.length() > 0 ) { if ( rootPath[ rootPath.length() - 1 ] != NTEXT('/') ) { rootPath += FileUtils::PATH_SEP; } } parsePath = path.substr( startPos ); } else { // no delimiters, so just parse the path parsePath = path; } StringTokenizer tok( parsePath, FileUtils::PATH_SEP_PAT ); while( tok.hasMoreTokens() ) { rootPath += tok.getNextToken(); rootPath += FileUtils::PATH_SEP; res = FileUtils::mkdir( rootPath ); if ( !res ) { break; } } #endif return res; }
static void onCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) { char szCurDir[_MAX_PATH]; switch(id) { case ID_LIST_DIR: if(codeNotify == LBN_DBLCLK) { int index = ListBox_GetCurSel(hWndCtl); DWORD dwItemData = ListBox_GetItemData(hWndCtl, index); if(HIWORD(dwItemData) == ID_ICON_OPENSELECT) { shutDialog(hWnd); char szString[_MAX_PATH]; Edit_GetText(GetDlgItem(hWndDirPicker, ID_EDIT_DIR), szString, sizeof(szString)); lstrcpy(lpszStringToReturn, szString); EndDialog(hWnd, IDOK); break; } ListBox_GetText(hWndCtl, index, szCurDir); char szDir[_MAX_DIR]; LPSTR lpsz; if((HIWORD(dwItemData) == ID_ICON_FOLDEROPEN) && (index != 0)) { GetWindowText(hWndCtl, szDir, sizeof(szDir)); lpsz=_fstrstr(szDir, szCurDir); *(lpsz + lstrlen(szCurDir)) = '\0'; lstrcpy(szCurDir, szDir); } if (_chdir(szCurDir) == 0) { _getcwd(szCurDir, _MAX_PATH); fillListBox(hWndDirPicker, szCurDir); } } break; case ID_COMBO_DIR: if(codeNotify == CBN_SELCHANGE) { char szDrive[80]; int index = ComboBox_GetCurSel(hWndCtl); if(index == CB_ERR) break; ComboBox_GetLBText(hWndCtl, index, szDrive); int iCurDrive = _getdrive(); Retry: HCURSOR hCursorOld = SetCursor(LoadCursor(NULL, IDC_WAIT)); SetCapture(hWndDirPicker); if((0 == _chdrive((int)(szDrive[0] - 'a' + 1))) && (NULL != _getcwd(szCurDir, _MAX_PATH))) { fillListBox(hWndDirPicker, szCurDir); ListBox_SetTopIndex(GetDlgItem(hWndDirPicker, ID_LIST_DIR), 0); SetCursor(hCursorOld); ReleaseCapture(); break; } SetCursor(hCursorOld); ReleaseCapture(); char szText[80]; sprintf(szText, "Cannot read drive %c:", szDrive[0]); if(IDRETRY == MessageBox(hWndDirPicker, szText, "Choose Directory", MB_ICONEXCLAMATION|MB_RETRYCANCEL)) goto Retry; //Changing drives failed so restore drive and selection _chdrive(iCurDrive); sprintf(szDrive, "%c:", (char)(iCurDrive + 'a' - 1)); index = ComboBox_SelectString(hWndCtl, -1, szDrive); } break; case IDOK: shutDialog(hWnd); char szString[_MAX_PATH]; Edit_GetText(GetDlgItem(hWndDirPicker, ID_EDIT_DIR), szString, sizeof(szString)); lstrcpy(lpszStringToReturn, szString); EndDialog(hWnd, IDOK); break; case IDCANCEL: shutDialog(hWnd); lpszStringToReturn[0] = '\0'; EndDialog(hWnd, IDCANCEL); break; default: break; } }
void FiosGetDrives(FileList &file_list) { uint disk, disk2, save, total; #ifndef __INNOTEK_LIBC__ _dos_getdrive(&save); // save original drive #else save = _getdrive(); // save original drive char wd[MAX_PATH]; getcwd(wd, MAX_PATH); total = 'z'; #endif /* get an available drive letter */ #ifndef __INNOTEK_LIBC__ for (disk = 1;; disk++) { _dos_setdrive(disk, &total); #else for (disk = 'A';; disk++) { _chdrive(disk); #endif if (disk >= total) break; #ifndef __INNOTEK_LIBC__ _dos_getdrive(&disk2); #else disk2 = _getdrive(); #endif if (disk == disk2) { FiosItem *fios = file_list.Append(); fios->type = FIOS_TYPE_DRIVE; fios->mtime = 0; #ifndef __INNOTEK_LIBC__ snprintf(fios->name, lengthof(fios->name), "%c:", 'A' + disk - 1); #else snprintf(fios->name, lengthof(fios->name), "%c:", disk); #endif strecpy(fios->title, fios->name, lastof(fios->title)); } } /* Restore the original drive */ #ifndef __INNOTEK_LIBC__ _dos_setdrive(save, &total); #else chdir(wd); #endif } bool FiosGetDiskFreeSpace(const char *path, uint64 *tot) { #ifndef __INNOTEK_LIBC__ struct diskfree_t free; char drive = path[0] - 'A' + 1; if (tot != NULL && _getdiskfree(drive, &free) == 0) { *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; return true; } return false; #else uint64 free = 0; #ifdef HAS_STATVFS { struct statvfs s; if (statvfs(path, &s) != 0) return false; free = (uint64)s.f_frsize * s.f_bavail; } #endif if (tot != NULL) *tot = free; return true; #endif } bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb) { char filename[MAX_PATH]; snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, ent->d_name); return stat(filename, sb) == 0; }
// Load a plugin dll. "pluginType" is a handle to a plugin management data // structure created during FE_RegisterPlugins(). "pNavigatorFuncs" is // a table of entry points into Navigator, which are the services provided // by Navigator to plugins, such as requestread() and GetUrl(). These entry // points are stored and called by the plugin when services are needed. // The return val is a table of functions which are entry points to the // newly loaded plugin, such as NewStream() and Write(). NPPluginFuncs* FE_LoadPlugin(void* pluginType, NPNetscapeFuncs* pNavigatorFuncs, np_handle* handle) { if(pluginType == NULL) return NULL; NPPMgtBlk* pNPMgtBlock = (NPPMgtBlk*)pluginType; CString csPluginDir; wfe_GetPluginsDirectory(csPluginDir); LPSTR pPathSave = NULL; // storage for one dir spec wfe_PushPath(&pPathSave); // save the current drive and dir // change the default dir so that implib'd plugins won't fail if(_chdir(csPluginDir) != 0) { wfe_PopPath(pPathSave); // restore the path return NULL; } // must change the drive as well as the dir path if(isalpha(csPluginDir[0]) && csPluginDir[1] == ':') { if(_chdrive(wfe_MapAsciiToDriveNum(csPluginDir[0])) != 0) { wfe_PopPath(pPathSave); // restore the path return NULL; } } pNPMgtBlock->pLibrary = PR_LoadLibrary(pNPMgtBlock->pPluginFilename); // the cross platform code should take care of the 16/32 bit issues if(pNPMgtBlock->pLibrary == NULL) return NULL; NP_CREATEPLUGIN npCreatePlugin = #ifndef NSPR20 (NP_CREATEPLUGIN)PR_FindSymbol("NP_CreatePlugin", pNPMgtBlock->pLibrary); #else (NP_CREATEPLUGIN)PR_FindSymbol(pNPMgtBlock->pLibrary, "NP_CreatePlugin"); #endif if (npCreatePlugin != NULL) { if (thePluginManager == NULL) { static NS_DEFINE_IID(kIPluginManagerIID, NP_IPLUGINMANAGER_IID); if (nsPluginManager::Create(NULL, kIPluginManagerIID, (void**)&thePluginManager) != NS_OK) return NULL; } NPIPlugin* plugin = NULL; NPPluginError err = npCreatePlugin(thePluginManager, &plugin); handle->userPlugin = plugin; if (err == NPPluginError_NoError && plugin != NULL) { pNPMgtBlock->pPluginFuncs = (NPPluginFuncs*)-1; // something to say it's loaded, but != 0 } } else { NP_GETENTRYPOINTS getentrypoints = #ifndef NSPR20 (NP_GETENTRYPOINTS)PR_FindSymbol("NP_GetEntryPoints", pNPMgtBlock->pLibrary); #else (NP_GETENTRYPOINTS)PR_FindSymbol(pNPMgtBlock->pLibrary, "NP_GetEntryPoints"); #endif if(getentrypoints == NULL) { PR_UnloadLibrary(pNPMgtBlock->pLibrary); wfe_PopPath(pPathSave); // restore the path return NULL; } if(pNPMgtBlock->pPluginFuncs == NULL) { pNPMgtBlock->pPluginFuncs = new NPPluginFuncs; pNPMgtBlock->pPluginFuncs->size = sizeof NPPluginFuncs; pNPMgtBlock->pPluginFuncs->javaClass = NULL; if(pNPMgtBlock->pPluginFuncs == NULL) // fatal, can't continue { PR_UnloadLibrary(pNPMgtBlock->pLibrary); wfe_PopPath(pPathSave); // restore the path return NULL; } } if(getentrypoints(pNPMgtBlock->pPluginFuncs) != NPERR_NO_ERROR) { PR_UnloadLibrary(pNPMgtBlock->pLibrary); delete pNPMgtBlock->pPluginFuncs; pNPMgtBlock->pPluginFuncs = NULL; wfe_PopPath(pPathSave); // restore the path return NULL; } // if the plugin's major ver level is lower than the Navigator's, // then they are incompatible, and should return an error if(HIBYTE(pNPMgtBlock->pPluginFuncs->version) < NP_VERSION_MAJOR) { PR_UnloadLibrary(pNPMgtBlock->pLibrary); delete pNPMgtBlock->pPluginFuncs; pNPMgtBlock->pPluginFuncs = NULL; wfe_PopPath(pPathSave); // restore the path return NULL; } NP_PLUGININIT npinit = NULL; // if this DLL is not already loaded, call its initialization entry point if(pNPMgtBlock->uRefCount == 0) { // the NP_Initialize entry point was misnamed as NP_PluginInit, early // in plugin project development. Its correct name is documented // now, and new developers expect it to work. However, I don't want // to break the plugins already in the field, so I'll accept either // name npinit = #ifndef NSPR20 (NP_PLUGININIT)PR_FindSymbol("NP_Initialize", pNPMgtBlock->pLibrary); #else (NP_PLUGININIT)PR_FindSymbol(pNPMgtBlock->pLibrary, "NP_Initialize"); #endif if(!npinit) { npinit = #ifndef NSPR20 (NP_PLUGININIT)PR_FindSymbol("NP_PluginInit", pNPMgtBlock->pLibrary); #else (NP_PLUGININIT)PR_FindSymbol(pNPMgtBlock->pLibrary, "NP_PluginInit"); #endif } } if(npinit == NULL) { PR_UnloadLibrary(pNPMgtBlock->pLibrary); delete pNPMgtBlock->pPluginFuncs; pNPMgtBlock->pPluginFuncs = NULL; wfe_PopPath(pPathSave); // restore the path return NULL; } if (npinit(pNavigatorFuncs) != NPERR_NO_ERROR) { PR_UnloadLibrary(pNPMgtBlock->pLibrary); delete pNPMgtBlock->pPluginFuncs; pNPMgtBlock->pPluginFuncs = NULL; wfe_PopPath(pPathSave); // restore the path return NULL; } } pNPMgtBlock->uRefCount++; // all is well, remember it was loaded // can't pop the path until plugins have been completely loaded/init'd wfe_PopPath(pPathSave); // restore the path return pNPMgtBlock->pPluginFuncs; }
int main (int ac, char **av) { char rbuff[TBUF]; char buff[TBUF]; char savebuff[TBUF]; char cmd[TBUF]; char mffile[TBUF]; char *arg[4]; static char execfile[TBUF]; char kpsedot[TBUF]; char currdir[TBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul; int i, savo, savi; char *p, *fp, *fpp; int issetdest; char fontname[TBUF]; char texbindir[TBUF]; char fullbin[TBUF]; kpse_set_program_name (av[0], NULL); progname = kpse_program_name; /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; tmp = getenv ("TEMP"); if (!tmp) tmp = getenv ("TMP"); if (!tmp) tmp = getenv ("TMPDIR"); if (!tmp) { fprintf (stderr, "Please define TEMP | TMP | TMPDIR.\n"); return (100); } tmp = xstrdup(tmp); for (fpp = tmp; *fpp; fpp++) { if (IS_KANJI(fpp)) fpp++; else if (*fpp == '\\') *fpp = '/'; } /* issetdest = 0 : TDS issetdest = 1 : user setting issetdest = 2 : current directory */ issetdest = 0; if (ac < 2) { usage (); free(tmp); return (100); } if ((!strcmp (av[1], "--version")) || (!strcmp (av[1], "-version"))) { version (); free(tmp); return (100); } if ((!strcmp (av[1], "--help")) || (!strcmp (av[1], "-help"))) { help (); free(tmp); return (100); } for (i = 0; i < 4; i++) arg[i] = (char *) malloc (TBUF); if ((!strcmp (av[1], "--destdir")) || (!strcmp (av[1], "-destdir"))) { if (ac != 4) { usage (); relmem (arg); free(tmp); return (100); } issetdest = 1; if (strlen(av[2]) > TBUF - 1 || strlen(av[3]) > TBUF - 1) { fprintf (stderr, "Too long a string.\n"); return (100); } strcpy (buff, av[2]); strcpy (fontname, av[3]); for (p = buff; *p; p++) { if (IS_KANJI(p)) p++; else if (*p == '\\') *p = '/'; } } else { if (strlen(av[1]) > TBUF - 1) { fprintf (stderr, "Too long a string.\n"); return (100); } strcpy (fontname, av[1]); } /* fontname = font name */ if ((p = strrchr (fontname, '.'))) *p = '\0'; /* mffile is METAFONT file name */ strcpy (mffile, fontname); strcat (mffile, ".mf"); if (!(fp = kpse_var_value ("MFINPUTS"))) { fprintf (stderr, "Cannot get value of MFINPUTS\n"); relmem (arg); free(tmp); return (100); } free (fp); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mffile, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s.\n", mffile); relmem (arg); free(tmp); return (100); } fpp = _getcwd (currdir, TBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); free(tmp); return (100); } for (fpp = currdir; *fpp; fpp++) { if (IS_KANJI(fpp)) fpp++; else if (*fpp == '\\') *fpp = '/'; } i = (int)strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) { issetdest = 2; strcpy (buff, currdir); } if (issetdest == 0) { /* now path of ${name}.mf is in p */ strcpy (arg[0], "Dummy"); strcpy (arg[1], "tfm"); strcpy (arg[2], p); if (!(p = getdestdir (3, arg))) { fprintf (stderr, "Cannot get destination directory name.\n"); relmem (arg); free(tmp); return (100); } strcpy (buff, p); } /* Now buff is the destdir */ p = buff; i = (int)strlen (p); if (p[i - 1] != '/') strcat (p, "/"); strcat (p, fontname); strcat (p, ".tfm"); /* now p (or buff) is the full path name of the tfm font */ /* check if it exists */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists\n", p); printf ("%s\n", p); relmem (arg); free(tmp); return (0); } cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* connect stdin to nul device */ if (!(fnul = fopen ("nul", "r"))) { fprintf (stderr, "Cannot open nul device to read\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); free(tmp); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* METAFONT command line */ strcpy (cmd, "--progname=mf --base=mf "); strcat (cmd, "\\mode:=ljfour; \\mag:=1; nonstopmode; input "); strcat (cmd, fontname); strcat (cmd, ";"); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); /* return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* close nul device */ fclose (fnul); /* check consistency */ strcpy (cmd, fontname); strcat (cmd, ".600gf"); if (_access (cmd, 0) == -1) { fprintf (stderr, "METAFONT failed to make gf font.\n"); relmem (arg); _chdrive (cdrive); _chdir (currdir); free(tmp); return (100); } remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); /* copy the tfm file */ if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, TBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); strcpy(savebuff, buff); /* copy log file into the current directory in the case that issetdest == 2, because feynmf package requires the log file. */ if(issetdest == 2) { i = (int)strlen(buff); if(i > 3) { i -= 4; buff[i] = '\0'; strcat(buff, ".log"); strcpy(cmd, fontname); strcat(cmd, ".log"); if (!(fr = fopen (cmd, "rb"))) { fprintf (stderr, "Cannot open %s to read\n", cmd); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, TBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); } } relmem (arg); if(issetdest != 2) mktexupd (savebuff); /* erase files */ strcpy (cmd, fontname); strcat (cmd, ".log"); remove (cmd); strcpy (cmd, fontname); strcat (cmd, ".tfm"); remove (cmd); _chdrive (cdrive); _chdir (currdir); /* send message to Kpathsea */ printf ("%s\n", savebuff); free(tmp); return (0); }
int main (int ac, char **av) { static char execfile[SBUF]; char rbuff[LBUF]; char buff[LBUF]; char cmd[LBUF]; char mfname[TBUF]; char tfname[TBUF]; char pkname[TBUF]; char name[TBUF]; char dpi[TBUF]; char ydpi[TBUF]; char bdpi[TBUF]; char mag[TBUF]; char mode[TBUF]; char destdir[SBUF]; char designsize[64]; char *arg[4]; char currdir[SBUF]; char kpsedot[SBUF]; char *tmp; int cdrive, tdrive; FILE *fr, *fw, *fnul, *tfmfileptr; int i, savo, savi, ret; int style; int issetdest; int app; int oldform; int ps2pkok; char *env; char *p, *fpp; double Xdpi, Ydpi; char texname[TBUF], pfbname[TBUF], slant[TBUF], extend[TBUF], encname[TBUF]; char texbindir[256]; char fullbin[512]; /* * style = 0 : MAKETEXPK_STYLE undefined or other than dosnames * style = 1 : MAKETEXPK_STYLE = dosnames */ /* * issetdest = 0 : no destdir * issetdest = 1 : destdir * issetdest = 2 : current working dir */ /* * app = 0 : mf * app = 1 : ps2pk * app = 2 : gsftopk * app = 3 : ttf2pk * app = 4 : hbf2gf */ /* * oldform = 0 : newform of the command line * oldform = 1 : oldform of the command line */ /* * TEMP | TMP | TMPDIR (necessary) * */ tmp = getenv ("TEMP"); if (!tmp) tmp = getenv ("TMP"); if (!tmp) tmp = getenv ("TMPDIR"); if (!tmp) { tpkerr ("Please define TEMP | TMP | TMPDIR."); return (100); } tmp = xstrdup(tmp); /* * normalize directory separators */ normalize (tmp); for (i = 0; i < 4; i++) arg[i] = (char *) malloc (SBUF); kpse_set_program_name (av[0], NULL); progname = kpse_program_name; /* * get tex binary dir * */ p = kpse_var_value("SELFAUTOLOC"); if(p == 0) { fprintf(stderr, "I cannot get SELFAUTOLOC\n"); exit(100); } strcpy(texbindir, p); free(p); for(p=texbindir; *p; p++) { if(*p == '/') *p = '\\'; } *p = '\\'; *(p+1) = '\0'; if (ac < 2) { usage (); relmem (arg); free(tmp); return (100); } issetdest = 0; ps2pkok = 0; /* * oldform or newform ? * */ if (av[1][0] == '-') oldform = 0; else oldform = 1; /* * Old form of the command line */ if (oldform == 1) { if (ac < 5) { usage (); relmem (arg); free(tmp); return (100); } if((strlen(av[1]) > TBUF -1 ) || (strlen(av[2]) > TBUF -1 ) || (strlen(av[3]) > TBUF -1 ) || (strlen(av[4]) > TBUF -1 )) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (name, av[1]); strcpy (dpi, av[2]); strcpy (bdpi, av[3]); strcpy (mag, av[4]); if (ac > 5) { if(strlen(av[5]) > TBUF -1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } strcpy (mode, av[5]); } else mode[0] = '\0'; } else { /* * New form of the command line */ name[0] = dpi[0] = bdpi[0] = mag[0] = mode[0] = destdir[0] = '\0'; i = 1; while (i < ac) { if(strlen(av[i]) > TBUF - 1) { fprintf(stderr, "\nToo long a string.\n"); free(tmp); return 100; } if (av[i][0] != '-') { strcpy (name, av[i]); break; } if (!strcmp (av[i], "--dpi") || !strcmp (av[i], "-dpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (dpi, av[i]); i++; } else if (!strcmp (av[i], "--bdpi") || !strcmp (av[i], "-bdpi")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (bdpi, av[i]); i++; } else if (!strcmp (av[i], "--mag") || !strcmp (av[i], "-mag")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mag, av[i]); i++; } else if (!strcmp (av[i], "--mfmode") || !strcmp (av[i], "-mfmode")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (mode, av[i]); i++; } else if (!strcmp (av[i], "--destdir") || !strcmp (av[i], "-destdir")) { i++; if (i >= ac) { tpkerr ("Invalid arguments."); relmem (arg); free(tmp); return (100); } strcpy (destdir, av[i]); issetdest = 1; i++; } else if (!strcmp (av[i], "--version") || !strcmp (av[i], "-version")) { version (); relmem (arg); free(tmp); return (0); } else if (!strcmp (av[i], "--help") || !strcmp (av[i], "-help")) { help (); relmem (arg); free(tmp); return (0); } else { tpkerr ("Argument error."); relmem (arg); free(tmp); return (100); } } } /* End of command line analysis */ env = kpse_var_value ("MAKETEXPK_STYLE"); if ((env == NULL) || !(*env) || (env && strcmp (env, "dosnames"))) { style = 0; } else style = 1; /* * Default program is mf */ app = 0; /* * check if mfmode and bdpi are consistent or not */ if (bdpi[0] && mode[0] && mode[0] != '/') { FILE *frd; char buff[128]; int len; strcpy (fullbin, texbindir); strcat (fullbin, "mf-nowin.exe \"\\mode:="); strcat (fullbin, mode); strcat (fullbin, ";mode_setup;message"); strcat (fullbin, "(decimal round pixels_per_inch);"); strcat (fullbin, "end. <nul\""); frd = popen (fullbin, "r"); if (!frd) { tpkerr ("I cannot find METAFONT.\n"); relmem (arg); free(tmp); return (100); } (void) fgets (buff, 126, frd); (void) fgets (buff, 126, frd); pclose (frd); system("del /Q mfput.*"); len = (int)strlen (buff); if (buff[len - 1] == '\n') { buff[len - 1] = '\0'; if (buff[len - 2] == '\r') buff[len - 2] = '\0'; } if (strcmp (bdpi, buff)) { fprintf(stderr, "mode_dpi %s and bdpi %s are inconsistent.\n", buff, bdpi); fprintf(stderr, "therefore I reset mfmode.\n"); mode[0] = '\0'; } } /* * determine mfmode if not given */ if (mode[0] == 0 || mode[0] == '/') { if (bdpi[0] == 0) { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } else { strcpy (rbuff, "MAKETEXPK_MODE_"); strcat (rbuff, bdpi); if ((env = kpse_var_value ("MAKETEXPK_MODE")) && *env) strcpy (mode, env); else if ((env = kpse_var_value (rbuff))) strcpy (mode, env); else if (!strcmp (bdpi, "85")) strcpy (mode, "sun"); else if (!strcmp (bdpi, "100")) strcpy (mode, "nextscrn"); else if (!strcmp (bdpi, "118")) strcpy (mode, "pcprevw"); else if (!strcmp (bdpi, "160")) strcpy (mode, "nectzo"); else if (!strcmp (bdpi, "180")) strcpy (mode, "toshiba"); else if (!strcmp (bdpi, "200")) strcpy (mode, "highfax"); else if (!strcmp (bdpi, "240")) strcpy (mode, "canonlbp"); else if (!strcmp (bdpi, "300")) strcpy (mode, "cx"); else if (!strcmp (bdpi, "320")) strcpy (mode, "neclm"); else if (!strcmp (bdpi, "360")) strcpy (mode, "epstylus"); else if (!strcmp (bdpi, "400")) strcpy (mode, "nexthi"); else if (!strcmp (bdpi, "600")) strcpy (mode, "ljfour"); else if (!strcmp (bdpi, "720")) strcpy (mode, "epscszz"); else if (!strcmp (bdpi, "800")) strcpy (mode, "lwpro"); else if (!strcmp (bdpi, "1000")) strcpy (mode, "lmaster"); else if (!strcmp (bdpi, "1200")) strcpy (mode, "ultre"); else if (!strcmp (bdpi, "1270")) strcpy (mode, "linoone"); else if (!strcmp (bdpi, "1800")) strcpy (mode, "vtftzz"); else if (!strcmp (bdpi, "2400")) strcpy (mode, "supre"); else if (!strcmp (bdpi, "2540")) strcpy (mode, "linotzzh"); else if (!strcmp (bdpi, "3386")) strcpy (mode, "linolttz"); else if (!strcmp (bdpi, "8000")) strcpy (mode, "dpdfezzz"); else if (!strcmp (bdpi, "9600")) strcpy (mode, "ibx"); else { tpkerr ("Cannot determine the mode."); tpkerr ("I will try other possibilities."); app = 1; } } } if (env) free (env); if (name[0] == 0) { tpkerr ("Font name is not given."); relmem (arg); free(tmp); return (100); } if ((p = strrchr (name, '.'))) *p = '\0'; strcpy (mfname, name); strcat (mfname, ".mf"); if (app == 0) { if (!(p = kpse_var_value ("MFINPUTS"))) { tpkerr ("Cannot get value of MFINPUTS."); relmem (arg); free(tmp); return (100); } free (p); xputenv("MKTEXMF", "1"); if (!(p = kpse_find_file (mfname, kpse_mf_format, 1))) { fprintf (stderr, "Cannot find %s .\n", mfname); tpkerr ("I try ps2pk --> gsftopk --> ttf2pk --> hbf2gf."); app = 1; } } if (app != 0) { strcpy (mode, "modeless"); strcpy (tfname, name); strcat (tfname, ".tfm"); if (!(p = kpse_var_value ("TFMFONTS"))) { tpkerr ("Cannot get value of TFMFONTS."); relmem (arg); free(tmp); return (100); } free (p); /* I don't try to create nonexisting tfm here. */ if (!(p = kpse_find_file (tfname, kpse_tfm_format, 0))) { fprintf (stderr, "Cannot find %s .\n", tfname); relmem (arg); free(tmp); return 100; } tfmfileptr = fopen (p, "rb"); if (!tfmfileptr) { fprintf (stderr, "I cannot open %s.\n", p); relmem (arg); free(tmp); return 100; } i = 256 * getc (tfmfileptr); i += getc (tfmfileptr); fclose (tfmfileptr); if ((i == 9) || (i == 11)) { fprintf (stderr, "Current font seems to be a Japanese one.\n"); fprintf (stderr, "I give up to create a PK font.\n"); relmem (arg); free(tmp); return 100; } } if ((p[0] == '.') && (p[1] == '/') && (issetdest != 1)) issetdest = 2; fpp = _getcwd (currdir, SBUF); if (!fpp) { fprintf (stderr, "Failed to get current working directory.\n"); relmem (arg); free(tmp); return (100); } normalize (currdir); i = (int)strlen (currdir); if (currdir[i - 1] == '/') currdir[i - 1] = '\0'; strcpy (kpsedot, "KPSE_DOT=.;"); strcat (kpsedot, currdir); _putenv (kpsedot); if (issetdest == 2) { strcpy (destdir, currdir); } if (issetdest == 0) { strcpy (arg[0], "Dummy"); strcpy (arg[1], "pk"); strcpy (arg[2], p); strcpy (arg[3], mode); if (!(p = getdestdir (4, arg))) { tpkerr ("Cannot get destination directory name."); relmem (arg); free(tmp); return (100); } strcpy (rbuff, p); } else strcpy (rbuff, destdir); /* * Change backslash into slash */ normalize (rbuff); p = rbuff; i = (int)strlen (p); if (p[i - 1] == '/') p[i - 1] = '\0'; if (issetdest) { if (!is_dir (p)) { fprintf (stderr, "Destination %s is not found.\n", p); relmem (arg); free(tmp); return (100); } } else if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcpy (buff, p); p = buff; i = (int)strlen (p); if (p[i - 1] != '/') strcat (p, "/"); if (dpi[0] == 0) { tpkerr ("Cannot determine DPI."); relmem (arg); free(tmp); return (100); } if (style == 1 && issetdest != 2) { /* dosnames */ strcat (p, "dpi"); strcat (p, dpi); if (!is_dir (p)) { if (make_dir (p)) { tpkerr ("Error in make_dir."); relmem (arg); free(tmp); return (100); } } strcat (p, "/"); } strcat (p, name); strcat (p, "."); if (style != 1 || issetdest == 2) strcat (p, dpi); /* long suffix */ strcat (p, "pk"); /* Now buff and p is the full path name of pk file */ /* check the existence of pk file */ if (_access (p, 0) == 0) { fprintf (stderr, "%s exists.\n", p); relmem (arg); printf ("%s\n", p); free(tmp); return (0); } /* * Go to the temporary directory */ cdrive = _getdrive (); if (tmp[1] == ':') { tdrive = tolower (*tmp) - 'a' + 1; _chdrive (tdrive); } _chdir (tmp); /* * save stdout and stdin */ savo = _dup (fileno (stdout)); savi = _dup (fileno (stdin)); /* * connect stdout to stderr */ _dup2 (fileno (stderr), fileno (stdout)); /* * connect stdin to nul */ if (!(fnul = fopen ("nul", "rb"))) { fprintf (stderr, "Cannot open nul device to read.\n"); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } _dup2 (fileno (fnul), fileno (stdin)); /* * pkname is the filename of PK font */ sprintf (pkname, "%s.%spk", name, dpi); if (app == 0) { /* * METAFONT command line */ if (mag[0] == 0) { tpkerr ("Cannot determine MAG."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } sprintf (cmd, "--progname=mf --base=mf \\mode:=%s; \\mag:=%s; nonstopmode; input %s;", mode, mag, name); strcpy (execfile, "mf-nowin.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); sprintf (cmd, "%s.%sgf", name, dpi); /* * check the consistency */ if (_access (cmd, 0) != 0) { tpkerr ("Failed to make gf font by METAFONT."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * Change gf into pk */ strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("Failed to make pk from gf."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } /* * erase gf file */ remove (cmd); /* * erase log file */ sprintf (cmd, "%s.log", name); remove (cmd); /* * erase tfm file */ sprintf (cmd, "%s.tfm", name); remove (cmd); goto finale; } /* * app = 1 : ps2pk --> gsftopk --> ttf2pk --> hbf2gf */ p = kpse_find_file ("pspksupp.map", kpse_fontmap_format, 0); if(p) { fr = fopen (p, "r"); /* Read pspksupp.map */ free (p); if (!fr) { tpkerr ("Cannot open pspksupp.map to read."); ps2pkok = 0; goto do_ps2pk; } while (fgets (rbuff, SBUF, fr)) { if (rbuff[0] == '%' || rbuff[0] == '#' || rbuff[0] == '\n') continue; texname[0] = pfbname[0] = slant[0] = extend[0] = encname[0] = '\0'; i = sscanf (rbuff, "%s %s %s %s %s", texname, pfbname, slant, extend, encname); if (i == 2 && !strncmp (texname, "AspectRatio", 11)) { if (!sscanf (pfbname, "%lf", &AspectRatio)) { tpkerr ("File format of pspksupp.map is wrong."); fclose (fr); ps2pkok = 0; goto do_ps2pk; } UseAspectRatio = 1; continue; } else if (i > 0 && !stricmp (texname, name)) { p = kpse_var_value ("T1FONTS"); if (!p) { tpkerr ("T1FONTS is not defined."); ps2pkok = 0; break; } free (p); p = kpse_find_file (pfbname, kpse_type1_format, 0); if (!p) { fprintf (stderr, "%s is not found.\n", pfbname); ps2pkok = 0; break; } free (p); ps2pkok = 1; if(bdpi[0] == 0) i--; break; } } fclose (fr); goto do_ps2pk; } else { char *q; char a[SBUF]; char b[SBUF]; char psname[SBUF]; char pscommand[SBUF]; double slantval, extendval; texname[0] = pfbname[0] = encname[0] = '\0'; a[0] = b[0] = psname[0] = pscommand[0] = '\0'; FileName = 0; strcpy(slant, "0"); strcpy(extend, "1"); ps2pkok = 0; p = kpse_find_file ("ps2pk.map", kpse_fontmap_format, 0); if(!p) { tpkerr("Necessary map file for ps2pk is not found."); goto do_ps2pk; } fr = fopen(p,"rb"); free(p); if (!fr) { tpkerr ("Cannot open ps2pk.map to read."); goto do_ps2pk; } while ((ret=ffgets (rbuff, LBUF, fr)) != FFILE_END) { if(ret == BBUFF_FUL) { fprintf(stderr, "A line in ps2pk.map seems to be too long.\n"); fprintf(stderr, "I try to continue. But something may be wrong.\n"); } p = rbuff; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) continue; q = texname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; if(stricmp(texname, name)) continue; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } if(FileName) q = a; else q = psname; while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); /* skip flag */ if(!FileName) { while(isdigit(*p)) p++; skipchar(&p); } if((*p == '%') || (*p == '#') || (*p == '\n')) { tpkerr("I cannot use ps2pk due to lack of data."); break; } if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if(FileName && a[0] == '\0') q = a; else if(FileName && b[0] == '\0') q = b; else { tpkerr("Incorrect line in ps2pk.map."); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } if (FileName && a[0] == '\0') q = a; else if (FileName && b[0] == '\0') q = b; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } while(!isskip(*p) && (*p != '\n')) *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; if(*p == '\"') { q = pscommand; *q++ = *p++; while(*p != '\"') *q++ = *p++; *q++ = *p++; *q = '\0'; skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; } skipchar(&p); if((*p == '%') || (*p == '#') || (*p == '\n')) break; else { fprintf(stderr, "Incorrect line in \"ps2pk.map\".\n"); break; } } fclose(fr); if(pscommand[0]) { p = strstr(pscommand, "SlantFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf SlantFont", &slantval); sprintf(slant, "%lf", slantval); p = slant + strlen(slant) - 1; while(*p == '0') { *p = '\0'; p--; } } p = strstr(pscommand, "ExtendFont"); if(p) { p--; while(*p == ' ' || *p == '\t') p--; while(*p != ' ' && *p != '\t' && *p != '\"') p--; p++; sscanf(p, "%lf ExtendFont", &extendval); sprintf(extend, "%lf", extendval); p = extend + strlen(extend) - 1; while(*p == '0') { *p = '\0'; p--; } } } if(a[0]) { p = strrchr(a, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, a); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, a); } } if(b[0]) { p = strrchr(b, '.'); if(p && !stricmp(p, ".enc")) { *p = '\0'; strcpy(encname, b); } else if(p && !stricmp(p, ".pfb")) { *p = '\0'; strcpy(pfbname, b); } } if(pfbname[0] == '\0') goto do_ps2pk; p = kpse_find_file (pfbname, kpse_type1_format, 0); if(!p) goto do_ps2pk; free(p); ps2pkok = 1; if(encname[0] && bdpi[0]) { i = 5; } else if(!encname[0] && !bdpi[0]) { i = 3; } else { i = 4; } } do_ps2pk: if (ps2pkok) { if (UseAspectRatio) { sscanf (dpi, "%lf", &Xdpi); Ydpi = Xdpi * AspectRatio; sprintf (ydpi, "%d", (int) Ydpi); } else strcpy (ydpi, dpi); strcpy(tfname, name); strcat(tfname, ".tfm"); get_designsize(tfname, designsize); if (i == 3) { sprintf (cmd, "-X%s -Y%s -S%s -E%s -P%s %s %s", dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && bdpi[0]) { sprintf (cmd, "-X%s -Y%s -R%s -S%s -E%s -P%s %s %s", dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else if (i == 4 && encname[0]) { sprintf (cmd, "-e%s -X%s -Y%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, slant, extend, designsize, pfbname, pkname); } else if (i == 5) { sprintf (cmd, "-e%s -X%s -Y%s -R%s -S%s -E%s -P%s %s %s", encname, dpi, ydpi, bdpi, slant, extend, designsize, pfbname, pkname); } else { tpkerr ("File format of pspksupp.map is wrong."); goto do_gsftopk; } strcpy (execfile, "ps2pk.exe"); fprintf (stderr, "%s %s\n", execfile, cmd); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ps2pk failed to make pk font."); goto do_gsftopk; } goto finale; } /* * ps2pk is impossible to use */ do_gsftopk: tpkerr ("ps2pk cannot be used."); tpkerr ("I try gsftopk."); app = 2; strcpy (execfile, "gsftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("gsftopk cannot be used."); tpkerr ("Next I try ttf2pk."); app = 3; strcpy (execfile, "ttf2pk.exe"); fprintf (stderr, "%s -q %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q", name, dpi, NULL); if (_access (pkname, 0) != 0) { tpkerr ("ttf2pk failed."); tpkerr ("Finally I try hbf2gf."); app = 4; strcpy (execfile, "hbf2gf.exe"); fprintf (stderr, "%s -q -p %s %s\n", execfile, name, dpi); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, "-q -p", name, dpi, NULL); sprintf (cmd, "%s.%sgf", name, dpi); if (_access (cmd, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } strcpy (execfile, "gftopk.exe"); fprintf (stderr, "%s %s %s\n", execfile, cmd, pkname); strcpy(fullbin, texbindir); strcat(fullbin, execfile); (void) _spawnlp (_P_WAIT, fullbin, execfile, cmd, pkname, NULL); if (_access (pkname, 0) != 0) { tpkerr ("All trials failed."); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } remove (cmd); } } finale: /* * return to original stdout and stdin */ _dup2 (savo, fileno (stdout)); close (savo); _dup2 (savi, fileno (stdin)); close (savi); /* * close nul device */ fclose (fnul); /* * copy the pk file */ if (!(fr = fopen (pkname, "rb"))) { fprintf (stderr, "Cannot open %s to read.\n", pkname); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } if (!(fw = fopen (buff, "wb"))) { fprintf (stderr, "Cannot open %s to write.\n", buff); _chdrive (cdrive); _chdir (currdir); relmem (arg); free(tmp); return (100); } while ((i = (int)fread (rbuff, 1, LBUF, fr))) fwrite (rbuff, 1, i, fw); fclose (fr); fclose (fw); remove (pkname); relmem (arg); /* * update ls-R if it exists */ mktexupd (buff); /* * tell kpathsea */ printf ("%s\n", buff); _chdrive (cdrive); _chdir (currdir); free(tmp); return (0); }
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { //MessageBox(NULL, lpstrCmdLine, "Command line", MB_OK); HRESULT hRes = ::CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call instead to // make the EXE free threaded. This means that calls come in on a random RPC thread. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ATLASSERT(SUCCEEDED(hRes)); // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used ::DefWindowProc(NULL, 0, 0, 0L); AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls hRes = _Module.Init(NULL, hInstance); ATLASSERT(SUCCEEDED(hRes)); // don't allow multiple instances, wait for previous to terminate HANDLE mutex = ::CreateMutex(NULL, TRUE, _T("MoleculesInitMTX")); if(mutex && ::GetLastError() == ERROR_ALREADY_EXISTS) { DWORD state = WaitForSingleObject(mutex, 500); if(state == WAIT_TIMEOUT || state == WAIT_FAILED) { _Module.Term(); ::CoUninitialize(); return 0; } } // find out where our binary (.scr) is located // this is used to locate molecules folder later std::unique_ptr<TCHAR[]> mod(new TCHAR[MAX_PATH]); ::GetModuleFileName(NULL, mod.get(), MAX_PATH-1); *(_tcsrchr(mod.get(), '\\')+1) = '\0'; TCHAR drive; if(islower((int)mod[0])) drive = _toupper(mod[0]); else drive = mod[0]; int drv = (int)drive-64; _chdrive(drv); _tchdir(mod.get()); int nRet = 0; TCHAR szTokens[] = _T("-/"); HWND hwndParent = NULL; // check reason for a call ECallReason cr = eSettings; // when no parameter given, show settings LPCTSTR lpszToken = _Module.FindOneOf(::GetCommandLine(), szTokens); if (lpszToken != NULL) { // XXX this flag is no longer used by windows? //if(_tcsnicmp(lpszToken, _T("c"), 1) == 0) //{ // settings (configuration dialog) // cr = eSettings; // hwndParent = GetForegroundWindow(); //} if(_tcsnicmp(lpszToken, _T("p "), 2) == 0) { // preview cr = ePreview; int n = 0; _stscanf_s(lpszToken+1, _T("%i%n"), &hwndParent, &n); lpszToken += n+1; } else if(_tcsnicmp(lpszToken, _T("s"), 1) == 0) { // normal screen saver mode cr = eRun; } // lpszToken = _Module.FindOneOf(lpszToken, szTokens); } switch (cr) { default: case eRun: nRet = Run(lpstrCmdLine, nCmdShow); break; case ePreview: nRet = Preview(hwndParent); break; case eSettings: #ifdef DEBUG // in debug builds run saver instead of settings when launched nRet = Run(lpstrCmdLine, nCmdShow); #else nRet = Settings(hwndParent); #endif break; } _Module.Term(); ::CoUninitialize(); return nRet; }
int my_setwd(const char *dir, myf MyFlags) { int res; size_s length; my_string start,pos; #if defined(VMS) || defined(MSDOS) || defined(OS2) char buff[FN_REFLEN]; #endif DBUG_ENTER("my_setwd"); DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); start=(my_string) dir; #if defined(MSDOS) || defined(OS2) /* OS2/MSDOS chdir can't change drive */ #if !defined(_DDL) && !defined(WIN32) if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0) { uint drive,drives; pos++; /* Skip FN_DEVCHAR */ drive=(uint) (my_toupper(&my_charset_latin1,dir[0])-'A'+1); drives= (uint) -1; if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32) { #ifdef OS2 _chdrive(drive); drives = _getdrive(); #else _dos_setdrive(drive,&drives); _dos_getdrive(&drives); #endif } if (drive != drives) { *pos='\0'; /* Dir is now only drive */ my_errno=errno; my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); DBUG_RETURN(-1); } dir=pos; /* drive changed, change now path */ } #endif if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) { strmov(buff,dir)[-1]=0; /* Remove last '/' */ dir=buff; } #endif /* MSDOS*/ if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) dir=FN_ROOTDIR; #ifdef VMS { pos=strmov(buff,dir); if (pos[-1] != FN_LIBCHAR) { pos[0]=FN_LIBCHAR; /* Mark as directory */ pos[1]=0; } system_filename(buff,buff); /* Change to VMS format */ dir=buff; } #endif /* VMS */ if ((res=chdir((char*) dir)) != 0) { my_errno=errno; if (MyFlags & MY_WME) my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); } else { if (test_if_hard_path(start)) { /* Hard pathname */ pos=strmake(&curr_dir[0],start,(size_s) FN_REFLEN-1); if (pos[-1] != FN_LIBCHAR) { length=(uint) (pos-(char*) curr_dir); curr_dir[length]=FN_LIBCHAR; /* must end with '/' */ curr_dir[length+1]='\0'; } } else curr_dir[0]='\0'; /* Don't save name */ } DBUG_RETURN(res); } /* my_setwd */