Esempio n. 1
0
TIFILE_t* ImportVarData(FILE *infile, TIFILE_t *tifile, int varNumber) {
	switch (tifile->type) {
		case ROM_TYPE:
			return ImportROMFile(infile, tifile);
		case FLASH_TYPE:
			return ImportFlashFile(infile, tifile);
		case SAV_TYPE:
			tifile->save = ReadSave(infile);
			if (!tifile->save)
				return FreeTiFile(tifile);
			tifile->model = tifile->save->model;
			return tifile;
	}

	int i, tmp;
	unsigned short headersize;
	unsigned short length;
	unsigned char vartype, *ptr;

	if (varNumber == 0) {
		tmpread(infile);
		length2 = tmp;
		tmpread(infile);
		length2 += tmp << 8;
	}

	tmpread(infile);
	headersize = tmp;
	tmpread(infile);
	headersize += tmp << 8;

	tmpread(infile);
	length = tmp;
	tmpread(infile);
	length += tmp << 8;

	tmpread(infile);
	vartype = tmp;

	if ((tifile->model == TI_73 && vartype == 0x13) ||
		(tifile->model == TI_82 && vartype == 0x0F) ||
		(tifile->model == TI_85 && vartype == 0x1D)) {
		tifile->backup = (TIBACKUP_t *) malloc(sizeof(TIBACKUP_t));
		if (tifile->backup == NULL)
			return FreeTiFile(tifile);
		tifile->backup->headersize	= headersize;
		tifile->backup->length1		= length;
		tifile->backup->vartype		= vartype;
		return ImportBackup(infile, tifile);
	}

	if (length2 > length + 17 || tifile->type == GROUP_TYPE) {
		tifile->type = GROUP_TYPE;
		length2 -= 0x39;
	} else {
		tifile->type = VAR_TYPE;
	}

	tifile->var = (TIVAR_t *) malloc(sizeof(TIVAR_t));
	tifile->vars[varNumber] = tifile->var;
	if (tifile->var == NULL)
		return FreeTiFile(tifile);

	tifile->var->headersize		= headersize;
	tifile->var->length			= length;
	tifile->var->vartype		= vartype;
	ptr = tifile->var->name;
	for(i = 0; i < 8 && !feof(infile); i++) {
		tmpread(infile);
		ptr[i] = tmp;
	}

	if (tifile->model == TI_83P) {
		tmp = fgetc(infile);
		if (tmp == EOF) {
			fclose(infile);
			FreeTiFile(tifile);
			return NULL;
		}
		ptr[i++] = tmp;
		tmp = fgetc(infile);
		if (tmp == EOF)
			return FreeTiFile(tifile);
		ptr[i++] =tmp;
	} else {
		ptr[i++] = 0;
		ptr[i++] = 0;
	}
	tmp = fgetc(infile);
	if (tmp == EOF)
		return FreeTiFile(tifile);
	ptr[i++] = tmp;
	tmp = fgetc(infile);
	if (tmp == EOF)
		return FreeTiFile(tifile);
	ptr[i++] = tmp;

	tifile->var->data = (unsigned char *) malloc(tifile->var->length);
	if (tifile->var->data == NULL)
		return FreeTiFile(tifile);

	i = 0;
	if (tifile->model == TI_86)
		fgetc(infile);

	for(i = 0; i < tifile->var->length && !feof(infile); i++) {
		tmp = fgetc(infile);
		if (tmp == EOF)
			return FreeTiFile(tifile);
		tifile->var->data[i] = tmp;
	}

	if (tifile->type == GROUP_TYPE) {
		if (varNumber != 0)
			return tifile;
		while (tifile != NULL) {
			length2 -= tifile->var->length + tifile->var->headersize;
			if (length2 < 0)
				break;
			tifile = ImportVarData(infile, tifile, ++varNumber);
		}
	}

	tifile->chksum = (fgetc(infile) & 0xFF) + ((fgetc(infile) & 0xFF) << 8 );
	return tifile;
}
Esempio n. 2
0
File: xsm.c Progetto: aosm/X11
Status
StartSession(char *name, Bool use_default)
{
    int database_read = 0;
    Dimension width;
    char title[256];


    /*
     * If we're not using the default session, lock it.
     * If using the default session, it will be locked as
     * soon as the user assigns the session a name.
     */

    if (!use_default && !LockSession (name, True))
	return (0);


    /*
     * Get important environment variables.
     */

    GetEnvironment ();


    /*
     * Set the main window's title to the session name.
     */

    sprintf (title, "xsm: %s", name);

    XtVaSetValues (topLevel,
	XtNtitle, title,		/* session name */
	NULL);

    XtRealizeWidget (topLevel);


    /*
     * Set WM_DELETE_WINDOW support on main window.  If the user tries
     * to delete the main window, the shutdown prompt will come up.
     */

    SetWM_DELETE_WINDOW (topLevel, "DelMainWinAction()");


    /*
     * Read the session save file.  Make sure the session manager
     * has an SM_CLIENT_ID, so that other managers (like the WM) can
     * identify it.
     */

    set_session_save_file_name (name);

    if (use_default)
	need_to_name_session = True;
    else
    {
	database_read = ReadSave (name, &sm_id);
	need_to_name_session = !database_read;
    }

    if (!sm_id)
    {
	sm_id = SmsGenerateClientID (NULL);
	if (!sm_id) return (0);
    }
    XChangeProperty (XtDisplay (topLevel), XtWindow (topLevel),
	XInternAtom (XtDisplay (topLevel), "SM_CLIENT_ID", False),
	XA_STRING, 8, PropModeReplace,
	(unsigned char *) sm_id, strlen (sm_id));


    /*
     * Adjust some label widths
     */

    XtVaGetValues (clientInfoButton,
	XtNwidth, &width,
	NULL);

    XtVaSetValues (checkPointButton,
	XtNwidth, width,
	NULL);

    XtVaGetValues (logButton,
	XtNwidth, &width,
	NULL);

    XtVaSetValues (shutdownButton,
	XtNwidth, width,
	NULL);
    

    XtMapWidget (topLevel);


    if (!database_read)
    {
	/*
	 * Start default apps (e.g. twm, smproxy)
	 */

	StartDefaultApps ();
    }
    else
    {
	/*
	 * Restart window manager first.  When the session manager
	 * gets a WM_STATE stored on its top level window, we know
	 * the window manager is running.  At that time, we can start
	 * the rest of the applications.
	 */

	XtAddEventHandler (topLevel, PropertyChangeMask, False,
	    PropertyChangeXtHandler, NULL);

	if (!Restart (RESTART_MANAGERS))
	{
	    XtRemoveEventHandler (topLevel, PropertyChangeMask, False,
	        PropertyChangeXtHandler, NULL);

	    /*
	     * Restart the rest of the session aware clients.
	     */

	    Restart (RESTART_REST_OF_CLIENTS);

	    /*
	     * Start apps that aren't session aware that were specified
	     * by the user.
	     */
	    
	    StartNonSessionAwareApps ();
	}
    }

    return (1);
}