if (!*windowOpened) { nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = appStartup->CreateStartupState(width, height, windowOpened); if (NS_FAILED(rv)) return rv; }
nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool *windowOpened){  NS_ENSURE_ARG(windowOpened);  *windowOpened = PR_FALSE;  nsresult rv;  PRInt32 height = nsIAppShellService::SIZE_TO_CONTENT;  PRInt32 width  = nsIAppShellService::SIZE_TO_CONTENT;  nsXPIDLCString tempString;  // Get the value of -width option  rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString));  if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())    PR_sscanf(tempString.get(), "%d", &width);  // Get the value of -height option  rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString));  if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())    PR_sscanf(tempString.get(), "%d", &height);    //first apply command line options   PRInt32 argc = 0;  rv = cmdLineArgs->GetArgc(&argc);  if (NS_FAILED(rv))     return rv;  char **argv = nsnull;  rv = cmdLineArgs->GetArgv(&argv);  if (NS_FAILED(rv))     return rv;  PRInt32 i = 0;  for (i=1;i<argc;i++) {#ifdef DEBUG_CMD_LINE     printf("XXX argv[%d] = %s\n",i,argv[i]);#endif /* DEBUG_CMD_LINE */     if (IsStartupCommand(argv[i])) {       // skip over the - (or / on windows)       char *command = argv[i] + 1;#ifdef XP_UNIX       // unix allows -mail and --mail       if ((argv[i][0] == '-') && (argv[i][1] == '-')) {          command = argv[i] + 2;       }#endif /* XP_UNIX */        // this can fail, as someone could do -foo, where -foo is not handled        rv = LaunchApplicationWithArgs((const char *)(argv[i]),                                       cmdLineArgs, command,                                       height, width, windowOpened);        if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT)          return rv;     }  }  // second if no window opened then apply the startup preferences  if (!*windowOpened) {    nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));    if (NS_FAILED(rv))       return rv;    rv = appStartup->CreateStartupState(width, height, windowOpened);    if (NS_FAILED(rv))       return rv;  }     return NS_OK;}