Beispiel #1
0
void MapObject::backup(mobj_backup_t* backup)
{
	// Save basic info
	backup->id = id;
	backup->type = type;

	// Save general properties to list
	properties.copyTo(backup->properties);

	// Object-specific properties
	writeBackup(backup);
}
Beispiel #2
0
saveCmd(int argc, char **argv)
{
windowStruct *w = globalData.activeWindow;
fileStruct *fs;
char tmp[512];
char *fName, *s;
int i, wrotePrimary=0, isNew=0;

    if( !(fs=w->fileInfo) )
	{
	emsg("No file in window to save");
	updateCursor(w);
	return(0);
	}
    if( argc == 1 )
	{	/* Save to existing name */
PRIMARY:
	if( fs->ro )
	    {
	    dingMsg("Read Only");
	    updateCursor(w);
	    return(0);
	    }
	fName = fs->fileName;
	if( fs->modified == 0 )
	    {
	    dingMsg("Nothing to save");
	    updateCursor(w);
	    return(0);
	    }
	if( fs->backupWritten == 0 && fs->created == 0 )
	    writeBackup(fs);
	wrotePrimary = 1;
	}
    else if(argc != 2 )
	{
	dingMsg("save command has 0 or 1 arguments");
	updateCursor(w);
	return(0);
	}
    else
	{
	if( argv[1][0] == '\0' )
	    goto PRIMARY;
	fName = argv[1];
	for(s=argv[1]; *s; s++)
	    if( iscntrl(*s) || isspace(*s) )
		{
		emsg("Filename has control or spaces; save skipped");
		updateCursor(w);
		return(0);
		}
	isNew = 1;
	}
    strcpy(tmp, "SAVE: ");
    for(s=fName, i=6; *s && i<globalData.winWidth/2; i++, s++)
	tmp[i] = *s;
    tmp[i] = '\0';
    emsg(tmp);
    if(writeFile(fs, fName, isNew))
	{
	if( wrotePrimary )
	    fs->modified = 0;
        strcpy(tmp, "SAVED");
        tmp[5] = ' ';
	emsg(tmp);
	return(1);
	}
    return(0);
}
Beispiel #3
0
exitCmd(int argc, char **argv)
{
char *arg;
fileStruct *fs;
int mode=0;

    if( argc > 2 )
	goto INVALID;
    arg = argv[1];
    if( argc > 1 )
	{	/* Precheck arg */
	if( strncasecmp(arg, "nosave", strlen(arg)) == 0 )
            ;   /* Don;t save any files */
        else if( strcasecmp(arg, "abort") == 0 )
            ;   /* Don't save files or write init */
        else if( strcasecmp(arg, "stop") == 0 )
	    ;   /* Suspend */
	else
	    {	/* Invalid */
INVALID:
	    dingMsg("exit [nosave|abort|stop]");
	    updateCursor(globalData.activeWindow);
	    return(0);
	    }
	}
    /* Go thru all files that have been touched and save as necessary */
    printf("\033[2J\033[1;1H\n\r");
    restoreTerm();
    globalData.mode = 0;	/* So emsg just prints */

    if( argc > 1 )
	{
        if( strncasecmp(arg, "nosave", strlen(arg)) == 0 )
            mode = 1;
        else if( strncasecmp(arg, "abort", strlen(arg)) == 0 )
            goto SKIP;
	else if( strcasecmp(arg, "stop") == 0 )
	    {
	    /* Can't seem to get timing right to restore the screen */
	    restoreTerm();
	    printf("\n");   /* Force a flush for restore screen */
	    sleep(1);
	    kill(getpid(), SIGSTOP);
	    sleep(1);
	    setupTerm();
	    globalData.mode = 1;
	    redrawScreen();
	    return(0);
	    }
	}
    writeStartup();
    if( mode == 1)
        goto SKIP;
    for(fs=globalData.fileList; fs; fs=fs->next)
	{
	if( fs->ro )
	    printf("Read only %s\n", fs->fileName);
	else if( fs->modified && !fs->nosave )
	    {
	    printf("Saving %s\n", fs->fileName);
	    if( fs->backupWritten == 0 && fs->created == 0)
		writeBackup(fs);
	    writeFile(fs, fs->fileName, 0);
	    }
	}
SKIP:
    exit(0);
}