/*ARGSUSED*/ static void AcceptSaveFile(Widget w, XEvent *e, String *argv, Cardinal *argc) { char *filename; Boolean success; Arg args[1]; filename = XawDialogGetValueString (fileDialog); success = XawAsciiSaveAsFile (XawTextGetSource (text), filename); XtPopdown (fileDialogShell); if (!success) { char *failMessage; XtAsprintf (&failMessage, "Can't open file \"%s\"", filename); XtSetArg (args[0], XtNlabel, failMessage); XtSetValues (failDialog, args, 1); CenterWidgetOnEvent (failDialogShell, e); XtPopup (failDialogShell, XtGrabNone); XtFree (failMessage); } else { if (currentClip->filename) free (currentClip->filename); currentClip->filename = malloc (strlen (filename) + 1); if (currentClip->filename) strcpy (currentClip->filename, filename); } }
static void CombineAppUserDefaults( Display *dpy, XrmDatabase *pdb) { char* filename; char* path = NULL; Boolean deallocate = False; if (!(path = getenv("XUSERFILESEARCHPATH"))) { #if !defined(WIN32) || !defined(__MINGW32__) char *old_path; char homedir[PATH_MAX]; GetRootDirName(homedir, PATH_MAX); if (!(old_path = getenv("XAPPLRESDIR"))) { XtAsprintf(&path, "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N", homedir, homedir, homedir, homedir, homedir, homedir); } else { XtAsprintf(&path, "%s/%%L/%%N%%C:%s/%%l/%%N%%C:%s/%%N%%C:%s/%%N%%C:%s/%%L/%%N:%s/%%l/%%N:%s/%%N:%s/%%N", old_path, old_path, old_path, homedir, old_path, old_path, old_path, homedir); } deallocate = True; #endif } filename = XtResolvePathname(dpy, NULL, NULL, NULL, path, NULL, 0, NULL); if (filename) { (void)XrmCombineFileDatabase(filename, pdb, False); XtFree(filename); } if (deallocate) XtFree(path); }
static void GetEnvironment(void) { static char envDISPLAY[]="DISPLAY"; static char envSESSION_MANAGER[]="SESSION_MANAGER"; static char envAUDIOSERVER[]="AUDIOSERVER"; char *p, *temp; remote_allowed = 1; display_env = NULL; if((p = cmd_line_display) || (p = (char *) getenv(envDISPLAY))) { XtAsprintf(&display_env, "%s=%s", envDISPLAY, p); /* * When we restart a remote client, we have to make sure the * display environment we give it has the SM's hostname. */ if ((temp = strchr (p, '/')) == NULL) temp = p; else temp++; if (*temp != ':') { /* we have a host name */ non_local_display_env = (char *) XtMalloc ( strlen (display_env) + 1); if (!non_local_display_env) nomem(); strcpy (non_local_display_env, display_env); } else { char hostnamebuf[256]; gethostname (hostnamebuf, sizeof hostnamebuf); XtAsprintf(&non_local_display_env, "%s=%s%s", envDISPLAY, hostnamebuf, temp); } } session_env = NULL; if((p = (char *) getenv(envSESSION_MANAGER))) { XtAsprintf(&session_env, "%s=%s", envSESSION_MANAGER, p); /* * When we restart a remote client, we have to make sure the * session environment does not have the SM's local connection port. */ non_local_session_env = (char *) XtMalloc (strlen (session_env) + 1); if (!non_local_session_env) nomem(); strcpy (non_local_session_env, session_env); if ((temp = Strstr (non_local_session_env, "local/")) != NULL) { char *delim = strchr (temp, ','); if (delim == NULL) { if (temp == non_local_session_env + strlen (envSESSION_MANAGER) + 1) { *temp = '\0'; remote_allowed = 0; } else *(temp - 1) = '\0'; } else { int bytes = strlen (delim + 1); memmove (temp, delim + 1, bytes); *(temp + bytes) = '\0'; } } } audio_env = NULL; if((p = (char *) getenv(envAUDIOSERVER))) { XtAsprintf(&audio_env, "%s=%s", envAUDIOSERVER, p); } }
/* * Main program */ int main(int argc, char *argv[]) { char *p; char errormsg[256]; static char environment_name[] = "SESSION_MANAGER"; int success, found_command_line_name, i; Argc = argc; Argv = argv; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'd': /* -display */ if (++i >= argc) goto usage; cmd_line_display = (char *) XtNewString (argv[i]); continue; case 's': /* -session */ if (++i >= argc) goto usage; session_name = XtNewString (argv[i]); continue; case 'v': /* -verbose */ verbose = 1; continue; } } usage: fprintf (stderr, "usage: xsm [-display display] [-session session_name] [-verbose]\n"); exit (1); } topLevel = XtVaAppInitialize (&appContext, "XSm", NULL, 0, &argc, argv, NULL, XtNmappedWhenManaged, False, XtNwindowRole, "xsm main window", NULL); wmStateAtom = XInternAtom ( XtDisplay (topLevel), "WM_STATE", False); wmDeleteAtom = XInternAtom ( XtDisplay (topLevel), "WM_DELETE_WINDOW", False); register_signals (appContext); /* * Install an IO error handler. For an explanation, * see the comments for InstallIOErrorHandler(). */ InstallIOErrorHandler (); /* * Init SM lib */ if (!SmsInitialize ("SAMPLE-SM", "1.0", NewClientProc, NULL, HostBasedAuthProc, 256, errormsg)) { fprintf (stderr, "%s\n", errormsg); exit (1); } if (!IceListenForConnections (&numTransports, &listenObjs, 256, errormsg)) { fprintf (stderr, "%s\n", errormsg); exit (1); } atexit(CloseListeners); if (!SetAuthentication (numTransports, listenObjs, &authDataEntries)) { fprintf (stderr, "Could not set authorization\n"); exit (1); } InitWatchProcs (appContext); for (i = 0; i < numTransports; i++) { XtAppAddInput (appContext, IceGetListenConnectionNumber (listenObjs[i]), (XtPointer) XtInputReadMask, NewConnectionXtProc, (XtPointer) listenObjs[i]); } /* the sizeof includes the \0, so we don't need to count the '=' */ networkIds = IceComposeNetworkIdList (numTransports, listenObjs); XtAsprintf(&p, "%s=%s", environment_name, networkIds); putenv(p); if (cmd_line_display) { /* * If a display was passed on the command line, set the DISPLAY * environment in this process so all applications started by * the session manager will run on the specified display. */ XtAsprintf(&p, "DISPLAY=%s", cmd_line_display); putenv(p); } if (verbose) printf ("setenv %s %s\n", environment_name, networkIds); create_choose_session_popup (); create_main_window (); create_client_info_popup (); create_save_popup (); create_log_popup (); /* * Initalize all lists */ RunningList = ListInit(); if(!RunningList) nomem(); PendingList = ListInit(); if(!PendingList) nomem(); RestartAnywayList = ListInit(); if(!RestartAnywayList) nomem(); RestartImmedList = ListInit(); if(!RestartImmedList) nomem(); WaitForSaveDoneList = ListInit(); if (!WaitForSaveDoneList) nomem(); InitialSaveList = ListInit(); if (!InitialSaveList) nomem(); FailedSaveList = ListInit(); if (!FailedSaveList) nomem(); WaitForInteractList = ListInit(); if (!WaitForInteractList) nomem(); WaitForPhase2List = ListInit(); if (!WaitForPhase2List) nomem(); /* * Get list of session names. If a session name was found on the * command line, and it is in the list of session names we got, then * use that session name. If there were no session names found, then * use the default session name. Otherwise, present a list of session * names for the user to choose from. */ success = GetSessionNames (&sessionNameCount, &sessionNamesShort, &sessionNamesLong, &sessionsLocked); found_command_line_name = 0; if (success && session_name) { for (i = 0; i < sessionNameCount; i++) if (strcmp (session_name, sessionNamesShort[i]) == 0) { found_command_line_name = 1; if (sessionsLocked[i]) { fprintf (stderr, "Session '%s' is locked\n", session_name); exit (1); } break; } } if (!success || found_command_line_name) { FreeSessionNames (sessionNameCount, sessionNamesShort, sessionNamesLong, sessionsLocked); if (!found_command_line_name) session_name = XtNewString (DEFAULT_SESSION_NAME); if (!StartSession (session_name, !found_command_line_name)) UnableToLockSession (session_name); } else { ChooseSession (); } /* * Main loop */ XtAppMainLoop (appContext); exit(0); }