MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / CmdTextSave

Function CmdTextSave

source/Debugger/Debug.cpp:5945–6003  ·  view source on GitHub ↗

===========================================================================

Source from the content-addressed store, hash-verified

5943
5944//===========================================================================
5945int CmdTextSave (int nArgs)
5946{
5947 // Save the TEXT1 40-colomn to text file (Default: AppleWin_Text40.txt"
5948 // TSAVE ["Filename"]
5949 // TSAVE ["Filename"]
5950 // 1
5951 if (nArgs > 1)
5952 return Help_Arg_1( CMD_TEXT_SAVE );
5953
5954 bool bHaveFileName = false;
5955
5956 if (g_aArgs[1].bType & TYPE_QUOTED_2)
5957 bHaveFileName = true;
5958
5959 char *pText;
5960 size_t nSize = Util_GetTextScreen( pText );
5961
5962 std::string sLoadSaveFilePath = g_sCurrentDir; // g_sProgramDir
5963
5964 if ( bHaveFileName )
5965 g_sMemoryLoadSaveFileName = g_aArgs[ 1 ].sArg;
5966 else
5967 {
5968 if ( GetVideo().VideoGetSW80COL() )
5969 g_sMemoryLoadSaveFileName = "AppleWin_Text80.txt";
5970 else
5971 g_sMemoryLoadSaveFileName = "AppleWin_Text40.txt";
5972 }
5973
5974 sLoadSaveFilePath += g_sMemoryLoadSaveFileName;
5975
5976 FILE *hFile = fopen( sLoadSaveFilePath.c_str(), "rb" );
5977 if (hFile)
5978 {
5979 ConsoleBufferPush( "Warning: File already exists. Overwriting." );
5980 fclose( hFile );
5981 }
5982
5983 hFile = fopen( sLoadSaveFilePath.c_str(), "wb" );
5984 if (hFile)
5985 {
5986 size_t nWrote = fwrite( pText, nSize, 1, hFile );
5987 if (nWrote == 1)
5988 {
5989 ConsoleBufferPushFormat( "Saved: %s", g_sMemoryLoadSaveFileName.c_str() );
5990 }
5991 else
5992 {
5993 ConsoleBufferPush( "Error saving." );
5994 }
5995 fclose( hFile );
5996 }
5997 else
5998 {
5999 ConsoleBufferPush( "Error opening file." );
6000 }
6001
6002 return ConsoleUpdate();

Callers

nothing calls this directly

Calls 6

Help_Arg_1Function · 0.85
Util_GetTextScreenFunction · 0.85
ConsoleBufferPushFormatFunction · 0.85
VideoGetSW80COLMethod · 0.80
ConsoleBufferPushFunction · 0.70
ConsoleUpdateFunction · 0.70

Tested by

no test coverage detected