char *getVolumeLabel(int drive, ulg *vtime, ulg *vmode, time_t* vutim) //int drive; /* drive name: 'A' .. 'Z' or '\0' for current drive */ //ulg *vtime; /* volume label creation time (DOS format) */ //ulg *vmode; /* volume label file mode */ //time_t *vutim;/* volume label creationtime (UNIX format) */ /* If a volume label exists for the given drive, return its name and pretend to set its time and mode. The returned name is static data. */ { char rootpath[4]; static char vol[14]; DWORD fnlen, flags; *vmode = A_ARCHIVE | A_LABEL; /* this is what msdos returns */ *vtime = dostime(1980, 1, 1, 0, 0, 0); /* no true date info available */ *vutim = dos2unixtime(*vtime); strcpy(rootpath, "x:\\"); rootpath[0] = (char)drive; if (GetVolumeInformation(drive ? rootpath : NULL, vol, 13, NULL, &fnlen, &flags, NULL, 0)) #ifdef __RSXNT__ /* RSXNT/EMX C rtl uses OEM charset */ return (AnsiToOem(vol, vol), vol); #else return vol; #endif else return NULL;
BOOL ReadMacro(LPTSTR lpFileName, LPLIST lpMacroList, BOOL fReadFirstPacketOnly) /***********************************************************************/ { LPTSTR lpCommand; MACRO_FILE_HANDLE fh; LPCMDPKT lpCmdPkt; BOOL fError; FNAME OEMName; // zero out the list ListInit(lpMacroList); // Open the macro file #ifdef BUFFERED_IO AnsiToOem(lpFileName, OEMName); fh = fopen(OEMName, _T("rb")); if (fh == NULL) #else fh = FileOpen(lpFileName, FO_READ); if (fh == MACRO_FILE_HANDLE_INVALID) #endif { Message(IDS_EOPEN, lpFileName); return(FALSE); } // Allocate a buffer to read the commands into if (!(lpCommand = (LPTSTR)Alloc(MAX_CMD_LEN))) { #ifdef BUFFERED_IO fclose(fh); #else FileClose(fh); #endif Message(IDS_EMEMALLOC); return(FALSE); } AstralCursor(IDC_WAIT); while (lpCmdPkt = ReadPacket(fh, lpCommand, &fError)) { ListAddTail(lpMacroList, lpCmdPkt); if (fReadFirstPacketOnly) break; } AstralCursor(NULL); FreeUp(lpCommand); #ifdef BUFFERED_IO fclose(fh); #else FileClose(fh); #endif if (fError) { DestroyPacketList(lpMacroList); return(FALSE); } return(TRUE); }
// display a line to the user. Assumes line doesn't end with a newline. VOID FAR DisplayLine(CHAR * szOutput) { if (hFileOutput) { #ifndef MAC // convert szOutput in-place to OEM char set AnsiToOem(szOutput, szOutput); #endif // !MAC fputs(szOutput, hFileOutput); fputs("\n", hFileOutput); #ifndef MAC // convert back to ANSI in case the caller reuses this string OemToAnsi(szOutput, szOutput); #endif // !MAC } else { #ifdef NO_MPW MacMessageBox(szOutput); #else //NO_MPW #ifndef WIN16 #ifndef MAC // convert szOutput in-place to OEM char set AnsiToOem(szOutput, szOutput); #endif // !MAC printf("%s\n", szOutput); #ifndef MAC // convert back to ANSI in case the caller reuses this string OemToAnsi(szOutput, szOutput); #endif // !MAC #else //!WIN16 // poor man's output under Windows MessageBox(NULL, szOutput, szAppTitle, MB_OK); #endif //!WIN16 #endif //NO_MPW } }
/** * setzt den Text. * * @param[in] text Der Text der gesetzt werden soll, falls @p NULL, wird * evtl vorhandener Text gelöscht * @param[in] conversion Soll ggf. ANSI-Charset in OEM umgewandelt werden? * @param[in] length Länge des Textes, bei @p 0 wird @p strlen verwendet * * @author FloSoft */ void libsiedler2::ArchivItem_Text::setText(const std::string& text, bool conversion) { if(conversion){ std::vector<char> tmp(text.size() + 1); AnsiToOem(text.data(), &tmp.front()); this->text = &tmp.front(); }else this->text = text; // Name setzen if(getName().empty()) setName(this->text); }
LOCAL int CountType(LPTSTR lpFileName, COMMAND_TYPE Type) /***********************************************************************/ { LPVOID lpParms; LPTSTR lpCommand; int i; int nType = 0; MACRO_FILE_HANDLE fh; FNAME OEMName; if (!(lpCommand = (LPTSTR)Alloc(MAX_CMD_LEN))) { Message(IDS_EMEMALLOC); return(-1); } #ifdef BUFFERED_IO AnsiToOem(lpFileName, OEMName); fh = fopen(OEMName, _T("rb")); if (fh == NULL) #else fh = FileOpen(lpFileName, FO_READ); if (fh == MACRO_FILE_HANDLE_INVALID) #endif { FreeUp((LPTR)lpCommand); Message(IDS_EOPEN, lpFileName); return(-1); } while (ReadLine(fh, lpCommand, MAX_CMD_LEN)) { i = ReadParms(fh, lpCommand, &lpParms); if (i < 0) continue; if (GetCommandType(GetCommandId(i)) == Type) ++nType; if (lpParms) FreeUpParms(GetCommandId(i), lpParms); } #ifdef BUFFERED_IO fclose(fh); #else FileClose(fh); #endif FreeUp((LPTR)lpCommand); return(nType); }
BOOL RecordMacro(LPTSTR lpFileName) /***********************************************************************/ { STRING szString, szAppName; FNAME OEMName; lpMacroFormat = (LPTSTR)Alloc(MAX_CMD_LEN); lpMacroString = (LPTSTR)Alloc(MAX_CMD_LEN); if (!lpMacroString || !lpMacroFormat) { Message(IDS_EMEMALLOC); if (lpMacroFormat) FreeUp(lpMacroFormat); if (lpMacroString) FreeUp(lpMacroString); return(FALSE); } #ifdef BUFFERED_IO AnsiToOem(lpFileName, OEMName); MacroFileHandle = fopen(OEMName, _T("w+b")); if (MacroFileHandle == NULL) #else MacroFileHandle = FileOpen(lpFileName, FO_CREATE|FO_WRITE); if (MacroFileHandle == MACRO_FILE_HANDLE_INVALID) #endif { FreeUp(lpMacroFormat); FreeUp(lpMacroString); return(FALSE); } lstrcpy(szMacroFileName, lpFileName); if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) { if ( AstralStrEx( IDS_MACRORECORD, szString, sizeof(szString) ) ) { lstrcat( szAppName, szString ); SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); } } Control.UntitledNo = 0; MacroMode = MM_RECORD; return(TRUE); }
/** * schreibt dem Text in eine Datei. * * @param[in] file Dateihandle in die der Text geschrieben werden soll * @param[in] conversion Soll ggf. ANSI-Charset in OEM umgewandelt werden? * * @return liefert Null bei Erfolg, ungleich Null bei Fehler * * @author FloSoft */ int libsiedler2::ArchivItem_Text::write(FILE* file, bool conversion) const { if(file == NULL) return 1; // Wenn Länge 0, nix schreiben, ist ja kein Fehler! if(text.size() == 0) return 0; unsigned int length = text.size(); std::vector<char> text(length * 2 + 1); for(unsigned int i = 0, j = 0; i < length; ++i) { if(this->text[i] == '\n') { text[j++] = '@'; text[j++] = '@'; } else if(this->text[i] == '\r') continue; else text[j++] = this->text[i]; } //memcpy(text, this->text, length); // ggf umwandeln if(conversion) AnsiToOem(&text.front(), &text.front()); // Schreiben if(libendian::le_write_c(&text.front(), length + 1, file) != (int)length + 1) return 2; return 0; }
/* Return error string for win32 API error * return pointer to malloc'ed string or NULL */ char *W32APIstrerror(int errnum) { char *st, *cp=NULL; int len; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errnum, 0, /* Default language */ (LPTSTR) &cp, 0, NULL ); if( !cp || !(*cp) ){ st = malloc(56); if(st) sprintf(st, "{W32 API error %u} Unknown Win32API error", errnum); }else{ len = strlen(cp)+30; st=malloc(len); if(st){ len = sprintf(st, "{W32 API error %u} ",errnum); AnsiToOem(cp,st+len); LocalFree(cp); /* Win32 API free() implementation */ }else st=cp; for(cp=st+len; *cp; cp++) switch(*cp){ /* Replace '\r' and '\n' with space */ case '\r': case '\n': *cp=' '; } } return st; }
// pre-process input file, creating a tmp file // In order to get the return code of the C pre-processor, I'm // spawing a batch file that invokes CL, and creates a signal file // if it is successful. VOID NEAR DoPreProcess ( ) { char szBuffer[255]; HANDLE hInstCpp; TASKENTRY taskentry; FILE * hFile; CHAR * szTempBatch; CHAR * szTempSig; CHAR * szTempRoot; ERR err = ERR_CPP; // assume error int cbTempFilenames; char * szComSpec; // figure out the names of the temp files // (note: uses OEM char set) szTempRoot = tempnam(".", "~mkt"); // get base name for temp files hFile = fopen(szTempRoot, "w"); // create the file now, to if (hFile == NULL) // reserve this set of names ParseError(ERR_CPP); fclose(hFile); cbTempFilenames = strlen(szTempRoot)+1+3+1; // base name + ext + null szTempBatch = malloc(cbTempFilenames); // for .BAT file strcpy(szTempBatch, szTempRoot); strcat(szTempBatch, ".bat"); szTempSig = malloc(cbTempFilenames); // for .SIG file strcpy(szTempSig, szTempRoot); strcat(szTempSig, ".sig"); szTempFile = malloc(cbTempFilenames); // for pre-processed oupput strcpy(szTempFile, szTempRoot); strcat(szTempFile, ".inp"); // CONSIDER: Check for existence of any of these files, if any exist, then // CONSIDER: try a different base name for the files. // open the temp .BAT file hFile = fopen(szTempBatch, "w"); if (hFile == NULL) goto cleanup2; // all errors after this point should go to 'cleanup' if (fputs(szBatchStart, hFile) < 0) // write the first part goto cleanup; sprintf(szBuffer, "%s %s%s %s>", szCppExe, szCppOpts, szCppDefs, szInputFile); // convert this string to the OEM char set AnsiToOem(szBuffer, szBuffer); // append szTempFile strcat(szBuffer, szTempFile); strcat(szBuffer, "\n"); if (fputs(szBuffer, hFile) < 0) // write the CPP command goto cleanup; sprintf(szBuffer, szBatchEnd, szTempSig); if (fputs(szBuffer, hFile) < 0) // write the error check code goto cleanup; fclose(hFile); hFile = NULL; // file no longer open szComSpec = getenv("COMSPEC"); if (szComSpec == NULL) szComSpec = "command.com"; sprintf(szBuffer, "%s /c %s", szComSpec, szTempBatch); hInstCpp = WinExec(szBuffer, SW_SHOWMINIMIZED); // shell the pre-processor if (hInstCpp < 32) // if error spawning pre-processor goto cleanup; Yield(); // give it a chance to start // find task associated with this instance. In extreme cases it may have // finished even before we're executing this code. taskentry.dwSize = sizeof(TASKENTRY); if (TaskFirst(&taskentry) == 0) { goto taskdone; } while (taskentry.hInst != hInstCpp) { if (TaskNext(&taskentry) == 0) { goto taskdone; } } hTaskCpp = taskentry.hTask; while (IsTask(hTaskCpp)) { SideAssert(TaskFindHandle(&taskentry, hTaskCpp) != 0); if (taskentry.hInst != hInstCpp) { // different hInst associated with this htask, // so the app must have terminated break; } Yield(); // wait until it's done } taskdone: // If signal file doesn't exist, then there was a problem pre-processing // the input file. If it exists, then it worked. if (!MyRemove(szTempSig)) err = ERR_NONE; // it worked! cleanup: if (hFile) // close tmp batch file if fclose(hFile); // error during write SideAssert(MyRemove(szTempBatch) == 0); // delete tmp batch file cleanup2: SideAssert(MyRemove(szTempRoot) == 0); // delete placeholder file if (err != ERR_NONE) // report any error ParseError(err); }
// MkTypLib entry point VOID main ( #ifndef NO_MPW int argc, /* Number of strings in array argv */ CHAR *argv[] /* Array of command-line argument strings */ #endif // NO_MPW ) { #ifdef USE_DIMALLOC IMalloc FAR *pmalloc; #endif //USE_DIMALLOC #ifdef NO_MPW #define MAX_ARGS 21 int argc; /* Number of strings in array argv */ CHAR *argv[MAX_ARGS]; /* Array of command-line argument strings */ FILE * hFileArgs; #endif // NO_MPW int fArgErr; HRESULT res; #ifndef MAC OPENFILENAME ofn; #endif #ifdef NODEBUGALERTS WINDEBUGINFO debuginfo; GetWinDebugInfo(&debuginfo, WDI_OPTIONS); Olddebuginfo = debuginfo; // save for restoration debuginfo.dwOptions |= DBO_SILENT; SetWinDebugInfo(&debuginfo); #endif //NODEBUGALERTS // init key fields in the main 'typlib' structure before we use them typlib.pEntry = NULL; // no entries seen so far typlib.pImpLib = NULL; // no imported libraries initially #ifdef MAC #ifdef NO_MPW // Do mysterious MAC init stuff MaxApplZone(); #endif //NO_MPW InitGraf((Ptr) &qd.thePort); #ifdef NO_MPW InitFonts(); InitWindows(); InitMenus(); InitDialogs(nil); InitCursor(); #endif //NO_MPW PPCInit(); // required by OleInitialize // init the OLE Applet if ((res = InitOleManager(0)) != NOERROR) ParseError(ERR_OM); // UNDONE: correct error? fAppletInitialized = TRUE; #ifdef NO_MPW // If a file exists called "MKTYPLIB.ARG", load up argc, argv[] to satisfy // our command line parser. if (hFileArgs = fopen("mktyplib.arg", "r")) { argc = 1; while (argc < MAX_ARGS) { argv[argc] = malloc(50); if (fscanf(hFileArgs, " %s ", argv[argc]) == EOF) break; argc++; } fclose(hFileArgs); } else { // activate to output to file instead of using lame MAC MessageBox's // szOutputFile = "m.log"; // redirected output szInputFile = "m.odl"; // input file fHFile = TRUE; // want a .H file fArgErr = FALSE; // no arg error goto ArgsParsed; } #endif //NO_MPW #endif //MAC InitLeadByteTable(); fArgErr = FParseCl(argc, argv); // parse the command line #ifdef MAC #ifdef NO_MPW ArgsParsed: #endif //NO_MPW #endif //MAC if (szOutputFile) { #ifdef WIN16 // perform in-place conversion to OEM char set AnsiToOem(szOutputFile, szOutputFile); // (don't bother converting back - this string is not used again) #endif // WIN16 hFileOutput = fopen(szOutputFile, "w"); // if problem opening output file, then just revert to normal // MessageBox output. // CONSIDER: give an error, too? } if (!fNologo) { DisplayLine(szBanner); // display the copyright banner // add a blank line in some cases to make it look better if (hFileOutput) fputs("\n", hFileOutput); #ifndef WIN16 #ifndef NO_MPW else printf("\n"); #endif //NO_MPW #endif //!WIN16 } if (fArgErr || fGiveUsage) { GiveUsage: DisplayLine(szUsage); ErrorExit(); // clean up and exit(1) } #ifndef MAC // use common dialog to get input filename if user didn't specify one if (szInputFile == NULL) { szInputFile = malloc(CB_MAX_PATHNAME+1); memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); // ofn.hwndOwner = g_hwndMain; ofn.hwndOwner = NULL; ofn.lpstrFile = szInputFile; ofn.nMaxFile = CB_MAX_PATHNAME+1; *szInputFile = '\0'; ofn.lpstrFilter = "Object Description Lang.\0*.odl\0\0"; ofn.nFilterIndex = 1; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // if anything went wrong -- just give the usage message if (GetOpenFileName(&ofn) == 0) goto GiveUsage; } #endif //!MAC Assert(szInputFile); // now compute filenames based off the input filename if (szTypeLibFile == NULL) // if output file not specified { // use input filename with ".tlb" extension szTypeLibFile = CloneNameAddExt(szInputFile, ".tlb"); } if (fHFile && szHFile == NULL) // if header filename not specified { // use input filename with ".h" extension szHFile = CloneNameAddExt(szInputFile, ".h"); } // If output file ends up with the same name as the input file, then // the user is screwed. Just give the usage message. if (!strcmp(szInputFile, szTypeLibFile)) goto GiveUsage; // If .h file ends up with the same name as either the input file or output // file, then the user is screwed. Just give the usage message. if (szHFile && (!strcmp(szInputFile, szHFile) || !strcmp(szTypeLibFile, szHFile))) goto GiveUsage; #ifdef USE_DIMALLOC // Use the dimalloc implementation, since the default implementation // doesn't work yet in mac ole. if (!GetDebIMalloc(&pmalloc)) ParseError(ERR_OM); // UNDONE: correct error? res = OLEINITIALIZE(pmalloc); pmalloc->lpVtbl->Release(pmalloc); #else // must init OLE res = OLEINITIALIZE(NULL); #endif if (FAILED(res)) ParseError(ERR_OM); // UNDONE: correct error? fOLEInitialized = TRUE; #ifndef MAC hcrsWait = LoadCursor(NULL, (LPSTR)IDC_WAIT); SetCursor(hcrsWait); // turn on the hourglass cursor // UNDONE: this doesn't always stay on in WIN16, nor does it seem to // UNDONE: have any affect in WIN32. #endif //!MAC #if FV_CPP if (fCPP) // if we're to pre-process input file DoPreProcess(); #endif //FV_CPP strcpy(szFileCur, szInputFile); // init current file name (for // error reporting) #if FV_CPP ParseOdlFile(fCPP ? szTempFile : szInputFile); // parse the input file #else ParseOdlFile(szInputFile); // parse the input file #endif #if FV_CPP if (szTempFile) { SideAssert(MyRemove(szTempFile) == 0); // delete tmp file created above szTempFile = NULL; } #endif //FV_CPP if (fHFile) // output .H file if desired OutputHFile(szHFile); // Now emit the type library OutputTyplib(szTypeLibFile); #ifdef NO_MPW // Now dump the type library DumpTypeLib(szTypeLibFile); #endif CleanupImportedTypeLibs(); // release any imported typelibs OLEUNINITIALIZE(); // terminate OLE #ifdef MAC UninitOleManager(); // clean up applet #endif //MAC DisplaySuccess(szTypeLibFile); // holy *&*%&^%, it worked!!! if (hFileOutput) // close redirected output file fclose(hFileOutput); #ifdef NODEBUGALERTS SetWinDebugInfo(&Olddebuginfo); #endif //NODEBUGALERTS exit(0); }
VOID FAR OutputHFile ( CHAR * szHFile ) { LPENTRY pEntry; #ifdef WIN16 // convert szHFile in-place to OEM char set AnsiToOem(szHFile, szHFile); // don't bother converting back since this string is not used again #endif // WIN16 // open the file hHFile = fopen(szHFile, "w"); // open output file if (hHFile == NULL) ParseError(ERR_CANT_OPEN_HFILE); Assert (SYS_WIN16 == 0 && SYS_WIN32 == 1 && SYS_MAC == 2 && SysKind <= SYS_MAX); HOut(szHeadFile); // output file header HOutF(typlib.szLibName); // output type library name HOut(" */\n\n#ifndef _"); // output: #ifndef _<libname>_H_ HOutF(typlib.szLibName); // #define _<libname>_H_ HOut("_H_\n#define _"); HOutF(typlib.szLibName); HOut("_H_\n"); HOutGuid(&typlib.attr, szHeadGuidLIBID, typlib.szLibName); if (fSpecifiedInterCC) { HOut(szCCHeader); } if (typlib.pEntry) { pEntry = (LPENTRY)ListFirst(typlib.pEntry); // point to first entry #pragma warning(disable:4127) while (TRUE) #pragma warning(default:4127) { switch (pEntry->type.tentrykind & ~tFORWARD) { case tTYPEDEF: HOutTypedef(&pEntry->type); break; case tENUM: HOutEnum(&pEntry->type); break; case tSTRUCT: case tUNION: HOutStructUnion(&pEntry->type); break; case tMODULE: HOutModule(pEntry); break; case tCOCLASS: HOutCoclass(pEntry); break; case tINTERFACE: case tDISPINTER: HOutInterface(pEntry); // fall through case tINTRINSIC: case tREF: break; // nothing to output #ifdef DEBUG default: if (pEntry->type.tentrykind & tIMPORTED) break; // noting to output for imported types Assert(FALSE); #endif //DEBUG } // advance to next entry if not all done if (pEntry == (LPENTRY)ListLast(typlib.pEntry)) break; // exit if all done pEntry = (LPENTRY)pEntry->type.pNext; } // WHILE } HOut("\n#endif\n"); fclose(hHFile); // done writing .H file hHFile = NULL; // close done // check for possible alignment problems if (iAlignMax != iAlignDef) ParseError(WARN_STRANGE_ALIGNMENT); #ifdef PROFILE printf("\n\ntotal functions: %d\n", cFuncsTotal); printf("total function args: %d\n", cArgsTotal); printf("total variables: %d\n", cVarsTotal); ParseError(ERR_OM); // bogus early quit #endif //PROFILE }
DoFileSaveAs(void) { /* This routine handles input to the Save dialog box. */ static CHAR szDefault[ cchMaxFile ]; extern int vfTextOnlySave; extern DoSaveAsFilenameGet(LPSTR,LPSTR,int *,int *,int * ,int *); BOOL bDontDelPictures=FALSE; int fWordFmt, fTextOnly, fBackup, fOldWrite; CHAR szFullNameNewDoc[ cchMaxFile ]; // full name of selection CHAR szShortNameNewDoc[ cchMaxFile ]; // file name of selection CHAR szDocName[ cchMaxFile ]; // file name of current #define szFullNameCurDoc (**((**hpdocdod)[docCur].hszFile)) // full name of current #define pDod ((struct DOD *)&(**hpdocdod)[docCur]) { int cch = 0; CHAR szDOSPath[ cchMaxFile ]; if (FNormSzFile( szDOSPath, "", dtyNormal )) { if ((cch=CchSz( szDOSPath )-2) > 2) { Assert( szDOSPath[ cch ] == '\\'); szDOSPath [cch] = '\0'; } #if 0 if (cch > 3) szDOSPath [cch] = '\\'; #endif } else szDOSPath[0] = '\0'; if (szFullNameCurDoc [0] != '\0') { /* Set default string for filename edit area */ CHAR szDocPath[ cchMaxFile ]; // path to current FreezeHp(); SplitSzFilename( szFullNameCurDoc, szDocPath, szDocName ); /* Default filename does not include the document's path if it is == the current directory path */ if (WCompSz( szDOSPath, szDocPath ) == 0) bltsz(szDocName, szDefault); else bltsz(szFullNameCurDoc, szDefault); MeltHp(); } else { szDefault[0] = szDocName[0] = '\0'; } } fTextOnly = vfTextOnlySave; fBackup = vfBackupSave; fWordFmt = vWordFmtMode & ~CONVFROMWORD; fOldWrite = vfOldWriteFmt; EnableOtherModeless(FALSE); while(1) { if (!DoSaveAsFilenameGet(szDefault,szFullNameNewDoc,&fBackup,&fTextOnly,&fWordFmt,&fOldWrite)) goto end; else { int dty; if (szFullNameNewDoc[0] == '\0') goto end; if (fOldWrite || fWordFmt || fTextOnly) { if (!WannaDeletePictures(docCur,fOldWrite ? SF_OLDWRITE : SF_WORD)) continue; } StartLongOp(); szFileExtract(szFullNameNewDoc, szShortNameNewDoc); #ifdef INTL /* International version */ /* Read the "Microsoft Word Format" button */ /* vWordFmtMode is used in WriteFn. If true, will convert to Word format, if false, no conversion is done. Another value, CONVFROMWORD, can be given during an open to allow saving a Word document in Write format. */ if (fWordFmt) /* if set, make the default extension be doc instead of wri for word docs */ dty = dtyWordDoc; else #endif /* International version */ dty = dtyNormal; #if WINVER >= 0x300 /* Currently: FNormSzFile *TAKES* an OEM sz, and *RETURNS* an ANSI sz ..pault */ #endif if ( pDod->fReadOnly && WCompSz( szFullNameNewDoc, szFullNameCurDoc ) == 0) { /* Must save read-only file under a different name */ Error( IDPMTReadOnly ); goto NSerious; /* Error not serious, stay in dialog */ } #if WINVER >= 0x300 else if (WCompSz(szFullNameCurDoc, szFullNameNewDoc) == 0 && vWordFmtMode == CONVFROMWORD && vfTextOnlySave == fTextOnly) /* User has loaded a text file and is going to save under the same name without changing formats, *OR* has loaded a Word document and is going to save in the same format -- don't prompt "replace file?" ..pault 1/17/90 */ ; #endif else if ((WCompSz(szFullNameCurDoc, szFullNameNewDoc) != 0 #ifdef INTL /* International version */ /* vWordFmtMode hasn't be reset yet */ || ( vWordFmtMode == CONVFROMWORD) #endif /* International version */ ) && FExistsSzFile( dtyNormal, szFullNameNewDoc ) ) { /* User changed the default string and specified a filename for which the file already exists. Or, we did a Word format conversion, forcing the .WRI extension on the file, and a file with that name exists.(International version only).o Note that vfWordFmtMode will be set to True or False below, so this check is made only on the first save after a Word conversion. Prompt to make sure it's ok to trash the existing one */ CHAR szFileUp[ cchMaxFile ]; CHAR szUserOEM[cchMaxFile]; /* ..converted to OEM */ CHAR szT[ cchMaxSz ]; CchCopyUpperSz( szShortNameNewDoc, szFileUp ); MergeStrings (IDSTRReplaceFile, szFileUp, szT); #if WINVER >= 0x300 /* access() expects OEM! */ AnsiToOem((LPSTR) szFullNameNewDoc, (LPSTR) szUserOEM); /* Make sure we don't let someone try to save to a file to which we do not have r/w permission */ Diag(CommSzNum("fnSaveAs: access(write_perm)==", access(szUserOEM, WRITE_PERMISSION))); Diag(CommSzNum(" szExists()==", FExistsSzFile( dtyNormal, szFullNameNewDoc ))); if (access(szUserOEM, WRITE_PERMISSION) == -1) { /* THIS COULD BE A CASE OF WRITING TO A FILE WITH R/O ATTRIBUTE, *OR* A SHARING ERROR! IMPROVE ERROR MESSAGE HERE ..pault 11/2/89 */ //Error( IDPMTSDE2 ); Error( IDPMTReadOnly ); goto NSerious; /* Error not serious, stay in dialog */ } #endif } vfTextOnlySave = fTextOnly; vfBackupSave = fBackup; vfOldWriteFmt = fOldWrite; #ifdef INTL /* International version */ /* vWordFmtMode is used in WriteFn. If true, will convert to Word format, if false, no conversion is done. Another value, CONVFROMWORD, can be given during an open to allow saving a Word document in Write format. */ vWordFmtMode = fWordFmt; #endif /* International version */ /* Record whether a backup was made or not. */ WriteProfileString( (LPSTR)szWriteProduct, (LPSTR)szBackup, vfBackupSave ? (LPSTR)"1" : (LPSTR)"0" ); /* Save the document */ CmdXfSave( szFullNameNewDoc,!vfTextOnlySave, vfBackupSave, vhcArrow); if (vfDiskFull || vfSysFull) goto NSerious; /* Case 1: Serious error. Leave the dialog. */ if (vfDiskError) { EndLongOp( vhcArrow ); goto end; } /* Case 2: Saved OK: set the new title, leave the dialog. */ else if (!WCompSz( szFullNameNewDoc, szFullNameCurDoc )) { #if defined(OLE) ObjRenamedDoc(szFullNameNewDoc); ObjSavedDoc(); #endif SetTitle(szShortNameNewDoc); #if WINVER >= 0x300 FreeUnreferencedFns(); #endif /* Update the fReadOnly attribute (9.10.91) v-dougk */ pDod->fReadOnly = FALSE; // can't be readonly if just saved EndLongOp( vhcArrow ); goto end; } /* Case 3: Nonserious error (disk full, bad path, etc.). stay in dialog. */ else { NSerious: ferror = FALSE; EndLongOp( vhcArrow ); StayInDialog: CloseEveryRfn( TRUE ); } } } // end of while(1) end: EnableOtherModeless(FALSE); } /* end of DoFileSaveAs */
char *ziptyp(char *s) //char *s; /* file name to force to zip */ /* If the file name *s has a dot (other than the first char), or if the -A option is used (adjust self-extracting file) then return the name, otherwise append .zip to the name. Allocate the space for the name in either case. Return a pointer to the new name, or NULL if malloc() fails. */ { char *q; /* temporary pointer */ char *t; /* pointer to malloc'ed string */ #ifdef THEOS char *r; /* temporary pointer */ char *disk; #endif if ((t = (char*)malloc(strlen(s) + 5)) == NULL) return NULL; strcpy(t, s); #ifdef __human68k__ _toslash(t); #endif #ifdef MSDOS for (q = t; *q; INCSTR(q)) if (*q == '\\') *q = '/'; #endif /* MSDOS */ #ifdef __RSXNT__ /* RSXNT/EMX C rtl uses OEM charset */ AnsiToOem(t, t); #endif if (adjust) return t; #ifndef RISCOS # ifndef QDOS # ifdef AMIGA if ((q = MBSRCHR(t, '/')) == NULL) q = MBSRCHR(t, ':'); if (MBSRCHR((q ? q + 1 : t), '.') == NULL) # else /* !AMIGA */ # ifdef THEOS /* the argument expansion add a dot to the end of file names when * there is no extension and at least one of a argument has wild cards. * So check for at least one character in the extension if there is a dot * in file name */ if ((q = MBSRCHR((q = MBSRCHR(t, PATHCUT)) == NULL ? t : q + 1, '.')) == NULL || q[1] == '\0') { # else /* !THEOS */ # ifdef TANDEM if (MBSRCHR((q = MBSRCHR(t, '.')) == NULL ? t : q + 1, ' ') == NULL) # else /* !TANDEM */ if (MBSRCHR((q = MBSRCHR(t, PATHCUT)) == NULL ? t : q + 1, '.') == NULL) # endif /* ?TANDEM */ # endif /* ?THEOS */ # endif /* ?AMIGA */ # ifdef CMS_MVS if (strncmp(t,"dd:",3) != 0 && strncmp(t,"DD:",3) != 0) # endif /* CMS_MVS */ # ifdef THEOS /* insert .zip extension before disk name */ if ((r = MBSRCHR(t, ':')) != NULL) { /* save disk name */ if ((disk = strdup(r)) == NULL) return NULL; strcpy(r[-1] == '.' ? r - 1 : r, ".zip"); strcat(t, disk); free(disk); } else { if (q != NULL && *q == '.') strcpy(q, ".zip"); else strcat(t, ".zip"); } } # else /* !THEOS */ # ifdef TANDEM /* Tandem can't cope with extensions */ strcat(t, " ZIP"); # else /* !TANDEM */ strcat(t, ".zip"); # endif /* ?TANDEM */ # endif /* ?THEOS */ # else /* QDOS */ q = LastDir(t); if(MBSRCHR(q, '_') == NULL && MBSRCHR(q, '.') == NULL) { strcat(t, "_zip"); } # endif /* QDOS */ #endif /* !RISCOS */ return t; }