Exemplo n.º 1
0
void open_settings(void)
{
    if (h_aes_win == 0) {

        GRECT curr, area;
        struct gemtk_wm_scroll_info_s *slid;
        uint32_t kind = CLOSER | NAME | MOVER | VSLIDE | HSLIDE | UPARROW
                        | DNARROW | LFARROW | RTARROW | SIZER | FULLER;

        dlgtree = gemtk_obj_get_tree(SETTINGS);
        area.g_x = area.g_y = 0;
        area.g_w = MIN(dlgtree->ob_width, desk_area.g_w);
        area.g_h = MIN(dlgtree->ob_height, desk_area.g_h);
        wind_calc_grect(WC_BORDER, kind, &area, &area);
        h_aes_win = wind_create_grect(kind, &area);
        wind_set_str(h_aes_win, WF_NAME, "Settings");
        settings_guiwin = gemtk_wm_add(h_aes_win, GEMTK_WM_FLAG_DEFAULTS,
                                     on_aes_event);
        curr.g_w = MIN(dlgtree->ob_width, desk_area.g_w);
        curr.g_h = MIN(dlgtree->ob_height, desk_area.g_h-64);
        curr.g_x = 1;
        curr.g_y = (desk_area.g_h / 2) - (curr.g_h / 2);

        wind_calc_grect(WC_BORDER, kind, &curr, &curr);

        dlgtree->ob_x = curr.g_x;
        dlgtree->ob_y = curr.g_y;

        /* set current config values: */
        display_settings();

        wind_open_grect(h_aes_win, &curr);

        gemtk_wm_set_form(settings_guiwin, dlgtree, 0);
        gemtk_wm_set_scroll_grid(settings_guiwin, 32, 32);
        gemtk_wm_get_grect(settings_guiwin, GEMTK_WM_AREA_CONTENT, &area);

        slid = gemtk_wm_get_scroll_info(settings_guiwin);
        gemtk_wm_set_content_units(settings_guiwin,
                                 (dlgtree->ob_width/slid->x_unit_px),
                                 (dlgtree->ob_height/slid->y_unit_px));
        gemtk_wm_update_slider(settings_guiwin, GEMTK_WM_VH_SLIDER);
    }
}
Exemplo n.º 2
0
static void usage(int status) {
  fprintf(stderr, "\n%s - Kinetic Folding Program for Nucleic Acids -\n",
	  GAV.ProgramName);
  fprintf(stderr, "Usage: %s [OPTION] < FILE\n", GAV.ProgramName);
  fprintf(stderr,
	  "Options:\n"
	  " EnergyModel\n"
	  "  --dangle <0|1|2>  set dangling end model to (non|normal|double)\n"
	  "  --Temp <float>    set simulation temperature to <float>\n"
	  "  --Par <string>    use energy-parameter-file <string>\n"
	  "  --logML           use linear multiloop-function not logarithmic\n"
	  " MoveSet\n"
	  "  --noShift         turn off shift-moves\n"
	  "  --noLP            forbit structures with isolated base-pairs\n"
	  " Simulation\n"
	  "  --seed <int=int=int>  set random seed to <int=int=int>\n"
	  "  --time <float>        set maxtime of simulation to <float>\n"
	  "  --num <int>           set number of simulations to <int>\n"
	  "  --start               set start structure\n"
	  "  --stop                set stop structure(s)\n"
	  "  --met                 use Metropolis rule not Kawasaki rule\n"
	  "  --fpt                 stop stop structure(s) is reached\n"
	  "  --grow <float>        grow chain every <float> time steps\n"
	  "  --phi <double>        set phi value to <double>\n"
	  "  --pbounds <d1=d2=d3>  set phi_min to d1\n"
	  "                            phi_inc to d2\n"
	  "                            phi_max to d2\n"
	  "                            (d? is a double value)\n"
	  " Output\n"
	  "  --log <string>  set basename of log-file to <string>\n"
	  "  --err <string>  set basename of error-log-file to <string>\n"
	  "  --silent        no output to stdout\n"
	  "  --verbose       more information to stdout\n"
	  "  --lmin          output only local minima to stdout\n"
	  "  --cut <float>   output structures with E <= <float> to stdout\n");
  display_settings();
  display_fileformat();
  exit (status);
}
Exemplo n.º 3
0
static int netware_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
{
    apr_status_t status=0;

    pconf = _pconf;
    ap_server_conf = s;

    if (setup_listeners(s)) {
        ap_log_error(APLOG_MARK, APLOG_ALERT, status, s, APLOGNO(00223)
            "no listening sockets available, shutting down");
        return !OK;
    }

    restart_pending = shutdown_pending = 0;
    worker_thread_count = 0;

    if (!is_graceful) {
        if (ap_run_pre_mpm(s->process->pool, SB_NOT_SHARED) != OK) {
            return !OK;
        }
    }

    /* Only set slot 0 since that is all NetWare will ever have. */
    ap_scoreboard_image->parent[0].pid = getpid();
    ap_run_child_status(ap_server_conf,
                        ap_scoreboard_image->parent[0].pid,
                        ap_my_generation,
                        0,
                        MPM_CHILD_STARTED);

    set_signals();

    apr_pool_create(&pmain, pconf);
    ap_run_child_init(pmain, ap_server_conf);

    if (ap_threads_max_free < ap_threads_min_free + 1)  /* Don't thrash... */
        ap_threads_max_free = ap_threads_min_free + 1;
    request_count = 0;

    startup_workers(ap_threads_to_start);

     /* Allow the Apache screen to be closed normally on exit() only if it
        has not been explicitly forced to close on exit(). (ie. the -E flag
        was specified at startup) */
    if (hold_screen_on_exit > 0) {
        hold_screen_on_exit = 0;
    }

    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(00224)
            "%s configured -- resuming normal operations",
            ap_get_server_description());
    ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(00225)
            "Server built: %s", ap_get_server_built());
    ap_log_command_line(plog, s);
    ap_log_common(s);
    show_server_data();

    mpm_state = AP_MPMQ_RUNNING;
    while (!restart_pending && !shutdown_pending) {
        perform_idle_server_maintenance(pconf);
        if (show_settings)
            display_settings();
        apr_thread_yield();
        apr_sleep(SCOREBOARD_MAINTENANCE_INTERVAL);
    }
    mpm_state = AP_MPMQ_STOPPING;

    ap_run_child_status(ap_server_conf,
                        ap_scoreboard_image->parent[0].pid,
                        ap_my_generation,
                        0,
                        MPM_CHILD_EXITED);

    /* Shutdown the listen sockets so that we don't get stuck in a blocking call.
    shutdown_listeners();*/

    if (shutdown_pending) { /* Got an unload from the console */
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(00226)
            "caught SIGTERM, shutting down");

        while (worker_thread_count > 0) {
            printf ("\rShutdown pending. Waiting for %lu thread(s) to terminate...",
                    worker_thread_count);
            apr_thread_yield();
        }

        mpm_main_cleanup();
        return DONE;
    }
    else {  /* the only other way out is a restart */
        /* advance to the next generation */
        /* XXX: we really need to make sure this new generation number isn't in
         * use by any of the children.
         */
        ++ap_my_generation;
        ap_scoreboard_image->global->running_generation = ap_my_generation;

        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(00227)
                "Graceful restart requested, doing restart");

        /* Wait for all of the threads to terminate before initiating the restart */
        while (worker_thread_count > 0) {
            printf ("\rRestart pending. Waiting for %lu thread(s) to terminate...",
                    worker_thread_count);
            apr_thread_yield();
        }
        printf ("\nRestarting...\n");
    }

    mpm_main_cleanup();
    return OK;
}
Exemplo n.º 4
0
static int CommandLineInterpreter(scr_t screenID, const char *commandLine)
{
    char *szCommand = "APACHE2 ";
    int iCommandLen = 8;
    char szcommandLine[256];
    char *pID;
    screenID = screenID;


    if (commandLine == NULL)
        return NOTMYCOMMAND;
    if (strlen(commandLine) <= strlen(szCommand))
        return NOTMYCOMMAND;

    apr_cpystrn(szcommandLine, commandLine, sizeof(szcommandLine));

    /*  All added commands begin with "APACHE2 " */

    if (!strnicmp(szCommand, szcommandLine, iCommandLen)) {
        ActivateScreen (getscreenhandle());

        /* If an instance id was not given but the nlm is loaded in
            protected space, then the the command belongs to the
            OS address space instance to pass it on. */
        pID = strstr (szcommandLine, "-p");
        if ((pID == NULL) && nlmisloadedprotected())
            return NOTMYCOMMAND;

        /* If we got an instance id but it doesn't match this
            instance of the nlm, pass it on. */
        if (pID) {
            pID = &pID[2];
            while (*pID && (*pID == ' '))
                pID++;
        }
        if (pID && ap_my_addrspace && strnicmp(pID, ap_my_addrspace, strlen(ap_my_addrspace)))
            return NOTMYCOMMAND;

        /* If we have determined that this command belongs to this
            instance of the nlm, then handle it. */
        if (!strnicmp("RESTART",&szcommandLine[iCommandLen],3)) {
            printf("Restart Requested...\n");
            restart();
        }
        else if (!strnicmp("VERSION",&szcommandLine[iCommandLen],3)) {
            printf("Server version: %s\n", ap_get_server_description());
            printf("Server built:   %s\n", ap_get_server_built());
        }
        else if (!strnicmp("MODULES",&szcommandLine[iCommandLen],3)) {
            ap_show_modules();
        }
        else if (!strnicmp("DIRECTIVES",&szcommandLine[iCommandLen],3)) {
                ap_show_directives();
        }
        else if (!strnicmp("SHUTDOWN",&szcommandLine[iCommandLen],3)) {
            printf("Shutdown Requested...\n");
            shutdown_pending = 1;
        }
        else if (!strnicmp("SETTINGS",&szcommandLine[iCommandLen],3)) {
            if (show_settings) {
                show_settings = 0;
                ClearScreen (getscreenhandle());
                show_server_data();
            }
            else {
                show_settings = 1;
                display_settings();
            }
        }
        else {
            show_settings = 0;
            if (strnicmp("HELP",&szcommandLine[iCommandLen],3))
                printf("Unknown APACHE2 command %s\n", &szcommandLine[iCommandLen]);
            printf("Usage: APACHE2 [command] [-p <instance ID>]\n");
            printf("Commands:\n");
            printf("\tDIRECTIVES - Show directives\n");
            printf("\tHELP       - Display this help information\n");
            printf("\tMODULES    - Show a list of the loaded modules\n");
            printf("\tRESTART    - Reread the configuration file and restart Apache\n");
            printf("\tSETTINGS   - Show current thread status\n");
            printf("\tSHUTDOWN   - Shutdown Apache\n");
            printf("\tVERSION    - Display the server version information\n");
        }

        /*  Tell NetWare we handled the command */
        return HANDLEDCOMMAND;
    }

    /*  Tell NetWare that the command isn't mine */
    return NOTMYCOMMAND;
}
Exemplo n.º 5
0
/*==============================*/
static void
set_parameters(void)
{
  if(strncmp(args_info.method_arg, "F", 1)==0)
    opt.method = 'F';
  else if (strncmp(args_info.method_arg, "A", 1)==0)
    opt.method = 'A';

  if(strncmp(args_info.num_err_arg, "I", 1)==0)
    opt.num_err = 'I';
  else if (strncmp(args_info.num_err_arg, "R", 1)==0)
    opt.num_err = 'R';

  opt.FEPS = args_info.feps_arg;
  // determines double precision machine parameters
  extern double dlamch_(char *cmach);
  if (opt.FEPS<0.0) opt.FEPS = 2*dlamch_("S");

  opt.useplusI = args_info.useplusI_flag;

  if (args_info.fptfile_given) {
    opt.fpt_file = strdup(args_info.fptfile_arg);
  } else opt.fpt_file = NULL;

  if (args_info.equil_file_given) {
    opt.equil_file = args_info.equil_file_arg;
  } else opt.equil_file = NULL;

  if (args_info.p0_given) {
    int i, j=1, lmintmp;
    double poptmp = 0., probtmp = 0., *pinitmp=NULL;
    pinitmp = (double *)calloc(2*args_info.p0_given+1, sizeof(double));
    *pinitmp = 1;
    for (i=0; i<args_info.p0_given; i++,j+=2) {
      if (sscanf(args_info.p0_arg[i], "%d=%lg",&lmintmp, &poptmp) == 0)
        exit(EXIT_FAILURE);
      if(lmintmp <1) {
        fprintf(stderr, "States in --p0 must be >=1\n");
        exit (EXIT_FAILURE);
      }
      else if (poptmp >0. && poptmp < 1.01) {
        *(pinitmp + j)     = (double) lmintmp;
        *(pinitmp + j + 1) = poptmp;
        *pinitmp += 2;
      }
    }

    for (i = 2; i < *pinitmp; i +=2)
      probtmp += pinitmp[i];
    if (probtmp <= 0.99 || probtmp >= 1.01) {
      fprintf(stderr, "Values of --p0 must sum up to 1 (currently %5.2f)\n",
              probtmp);
      /* normalize input */
      for (i = 2; i < *pinitmp; i +=2)
        pinitmp[i] /= probtmp;

      probtmp = 0.0;
      for (i = 2; i < *pinitmp; i +=2)
        probtmp += pinitmp[i];
      if (!opt.quiet) fprintf(stderr, "WARNING:  --p0 values normalized sum up to %5.2f\n",
              probtmp);
    }
    opt.pini = pinitmp;
  } else opt.pini = NULL;

  if (args_info.absorb_given) {
    if( (opt.real_abs = opt.absrb = args_info.absorb_arg) <= 0 ) {
      fprintf(stderr, "Value of --absorb must be >= 0\n");
      exit (EXIT_FAILURE);
    }
  }

  if( (opt.t0 = args_info.t0_arg) < 0.0 ) {
    fprintf(stderr, "Value of --t0 must be >= 0.\n");
    exit (EXIT_FAILURE);
  }

  if( (opt.t8 = args_info.t8_arg) <= 0.0 ) {
    fprintf(stderr, "Value of --t8 must be > 0.\n");
    exit (EXIT_FAILURE);
  }

  if (args_info.tinc_given) {
    if( (opt.tinc = args_info.tinc_arg) <= 0. ) {
      fprintf(stderr, "Value of --tinc must be > 0.\n");
      exit (EXIT_FAILURE);
    }
  }

  if (args_info.Temp_given) {
    if( (opt.T = args_info.Temp_arg) < -273.15 ) {
      fprintf(stderr, "Value of --Temp must be > -273.15\n");
      exit (EXIT_FAILURE);
    }
  }
  if (args_info.visualize_given) {
    opt.vis_file = args_info.visualize_arg;
  }

  // use input as rate matrix if rate matrix is not specified
  if (!args_info.ratesfile_given && opt.method=='I') {
    if (!opt.quiet) fprintf(stderr, "Using input as a rate file!\n");
    opt.RATFILE = opt.INFILE;
    opt.INFILE = NULL;
  }

  if (args_info.minimal_rate_given) {
    if( (opt.minimal_rate = args_info.minimal_rate_arg) <= 0. ) {
      fprintf(stderr, "Value of --minimal-rate must be > 0.\n");
      exit (EXIT_FAILURE);
    }
  }

  if (args_info.hard_rescale_given) {
    if( (opt.hard_rescale = args_info.hard_rescale_arg) <= 0. ) {
      fprintf(stderr, "Value of --hard-rescale must be > 0.\n");
      exit (EXIT_FAILURE);
    }
  }

  if (args_info.times_given) {
    if( (opt.times = args_info.times_arg) <= 0. ) {
      fprintf(stderr, "Value of --times must be > 0.\n");
      exit (EXIT_FAILURE);
    }
  }

  if (args_info.nstates_given) {
    if( (opt.n = args_info.nstates_arg) <= 1 ) {
      fprintf(stderr, "Value of --nstates must be >= 1\n");
      exit (EXIT_FAILURE);
    }
  } else {
    // set opt.n to infinity
    opt.n = INT_MAX;
  }
  if (args_info.just_shorten_flag) {
    opt.just_sh = 1;
  }
  opt.max_decrease = args_info.max_decrease_arg;
  if (args_info.degeneracy_given) opt.want_degenerate = 1;
  if (args_info.quiet_flag) opt.quiet = 1;
  if (args_info.verbose_given) opt.want_verbose = 1;
  if (args_info.umatrix_given) opt.dumpU = 1;
  if (args_info.mathematicamatrix_given) opt.dumpMathematica = 1;
  if (args_info.bin_given) opt.binrates = 1;
  if (args_info.exponent_given) opt.matexp = 1;
  if (args_info.fpt_given) {
    opt.fpt = 1;
    if (strcmp(args_info.fpt_arg, "all") == 0) {
      opt.fpt_num = -1;
    } else {
      if (sscanf(args_info.fpt_arg, "%d", &opt.fpt_num) != 1 || opt.fpt_num<=0) {
        fprintf(stderr, "Value of --fpt (-t) must be either \"all\" or positive number. (it is \"%s\")\n", args_info.fpt_arg);
        exit (EXIT_FAILURE);
      }
    }
  }
  if (args_info.recover_given) opt.rrecover = 1;
  if (args_info.wrecover_given) opt.wrecover = 1;
  if (args_info.info_given) {
    display_settings();
    if (opt.pini != NULL) free(opt.pini);
    exit(EXIT_SUCCESS);
  }
  if (opt.rrecover && opt.wrecover) {
    opt.wrecover = 0;
    if (!opt.quiet) fprintf(stderr, "WARNING: both options -w and -r were given\n");
    if (!opt.quiet) fprintf(stderr, "         disabling -w now, since they are mutually exclusive !\n");
  }
}
Exemplo n.º 6
0
extern int main(int argc, char **argv)
#endif
{
	struct termios mode;
	enum   output_type output_type;
	int    optc;
	int    require_set_attr;
	int    speed_was_set;
	int    verbose_output;
	int    recoverable_output;
	int    k;
	int    noargs = 1;
	char * file_name = NULL;
	int    fd;
	const char *device_name;

	output_type = changed;
	verbose_output = 0;
	recoverable_output = 0;

	/* Don't print error messages for unrecognized options.  */
	opterr = 0;

	while ((optc = getopt(argc, argv, "agF:")) != -1) {
		switch (optc) {
		case 'a':
			verbose_output = 1;
			output_type = all;
			break;

		case 'g':
			recoverable_output = 1;
			output_type = recoverable;
			break;

		case 'F':
			if (file_name)
				error_msg_and_die("only one device may be specified");
			file_name = optarg;
			break;

		default:                /* unrecognized option */
			noargs = 0;
			break;
		}

		if (noargs == 0)
			break;
	}

	if (optind < argc)
		noargs = 0;

	/* Specifying both -a and -g gets an error.  */
	if (verbose_output && recoverable_output)
		error_msg_and_die ("verbose and stty-readable output styles are mutually exclusive");

	/* Specifying any other arguments with -a or -g gets an error.  */
	if (!noargs && (verbose_output || recoverable_output))
		error_msg_and_die ("modes may not be set when specifying an output style");

	/* FIXME: it'd be better not to open the file until we've verified
	   that all arguments are valid.  Otherwise, we could end up doing
	   only some of the requested operations and then failing, probably
	   leaving things in an undesirable state.  */

	if (file_name) {
		int fdflags;

		device_name = file_name;
		fd = open(device_name, O_RDONLY | O_NONBLOCK);
		if (fd < 0)
			perror_msg_and_die("%s", device_name);
		if ((fdflags = fcntl(fd, F_GETFL)) == -1
			|| fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
			perror_msg_and_die("%s: couldn't reset non-blocking mode",
							   device_name);
	} else {
		fd = 0;
		device_name = "standard input";
	}

	/* Initialize to all zeroes so there is no risk memcmp will report a
	   spurious difference in an uninitialized portion of the structure.  */
	memset(&mode, 0, sizeof(mode));
	if (tcgetattr(fd, &mode))
		perror_msg_and_die("%s", device_name);

	if (verbose_output || recoverable_output || noargs) {
		max_col = screen_columns();
		current_col = 0;
		display_settings(output_type, &mode, fd, device_name);
		return EXIT_SUCCESS;
	}

	speed_was_set = 0;
	require_set_attr = 0;
	k = 0;
	while (++k < argc) {
		int match_found = 0;
		int reversed = 0;
		int i;

		if (argv[k][0] == '-') {
			char *find_dev_opt;

			++argv[k];

     /* Handle "-a", "-ag", "-aF/dev/foo", "-aF /dev/foo", etc.
	Find the options that have been parsed.  This is really
	gross, but it's needed because stty SETTINGS look like options to
	getopt(), so we need to work around things in a really horrible
	way.  If any new options are ever added to stty, the short option
	MUST NOT be a letter which is the first letter of one of the
	possible stty settings.
     */
			find_dev_opt = strchr(argv[k], 'F'); /* find -*F* */
			if(find_dev_opt) {
				if(find_dev_opt[1]==0)  /* -*F   /dev/foo */
					k++;            /* skip  /dev/foo */
				continue;   /* else -*F/dev/foo - no skip */
			}
			if(argv[k][0]=='a' || argv[k][0]=='g')
				continue;
			/* Is not options - is reverse params */
			reversed = 1;
		}
		for (i = 0; i < NUM_mode_info; ++i)
			if (STREQ(argv[k], mode_info[i].name)) {
				match_found = set_mode(&mode_info[i], reversed, &mode);
				require_set_attr = 1;
				break;
			}

		if (match_found == 0 && reversed)
			error_msg_and_die("invalid argument `%s'", --argv[k]);

		if (match_found == 0)
			for (i = 0; i < NUM_control_info; ++i)
				if (STREQ(argv[k], control_info[i].name)) {
					if (k == argc - 1)
					    error_msg_and_die("missing argument to `%s'", argv[k]);
					match_found = 1;
					++k;
					set_control_char(&control_info[i], argv[k], &mode);
					require_set_attr = 1;
					break;
				}

		if (match_found == 0) {
			if (STREQ(argv[k], "ispeed")) {
				if (k == argc - 1)
				    error_msg_and_die("missing argument to `%s'", argv[k]);
				++k;
				set_speed(input_speed, argv[k], &mode);
				speed_was_set = 1;
				require_set_attr = 1;
			} else if (STREQ(argv[k], "ospeed")) {
				if (k == argc - 1)
				    error_msg_and_die("missing argument to `%s'", argv[k]);
				++k;
				set_speed(output_speed, argv[k], &mode);
				speed_was_set = 1;
				require_set_attr = 1;
			}
#ifdef TIOCGWINSZ
			else if (STREQ(argv[k], "rows")) {
				if (k == argc - 1)
				    error_msg_and_die("missing argument to `%s'", argv[k]);
				++k;
				set_window_size((int) parse_number(argv[k], stty_suffixes),
								-1, fd, device_name);
			} else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) {
				if (k == argc - 1)
				    error_msg_and_die("missing argument to `%s'", argv[k]);
				++k;
				set_window_size(-1,
						(int) parse_number(argv[k], stty_suffixes),
						fd, device_name);
			} else if (STREQ(argv[k], "size")) {
				max_col = screen_columns();
				current_col = 0;
				display_window_size(0, fd, device_name);
			}
#endif
#ifdef HAVE_C_LINE
			else if (STREQ(argv[k], "line")) {
				if (k == argc - 1)
					error_msg_and_die("missing argument to `%s'", argv[k]);
				++k;
				mode.c_line = parse_number(argv[k], stty_suffixes);
				require_set_attr = 1;
			}
#endif
			else if (STREQ(argv[k], "speed")) {
				max_col = screen_columns();
				display_speed(&mode, 0);
			} else if (recover_mode(argv[k], &mode) == 1)
				require_set_attr = 1;
			else if (string_to_baud(argv[k]) != (speed_t) - 1) {
				set_speed(both_speeds, argv[k], &mode);
				speed_was_set = 1;
				require_set_attr = 1;
			} else
				error_msg_and_die("invalid argument `%s'", argv[k]);
		}
	}

	if (require_set_attr) {
		struct termios new_mode;

		if (tcsetattr(fd, TCSADRAIN, &mode))
			perror_msg_and_die("%s", device_name);

		/* POSIX (according to Zlotnick's book) tcsetattr returns zero if
		   it performs *any* of the requested operations.  This means it
		   can report `success' when it has actually failed to perform
		   some proper subset of the requested operations.  To detect
		   this partial failure, get the current terminal attributes and
		   compare them to the requested ones.  */

		/* Initialize to all zeroes so there is no risk memcmp will report a
		   spurious difference in an uninitialized portion of the structure.  */
		memset(&new_mode, 0, sizeof(new_mode));
		if (tcgetattr(fd, &new_mode))
			perror_msg_and_die("%s", device_name);

		/* Normally, one shouldn't use memcmp to compare structures that
		   may have `holes' containing uninitialized data, but we have been
		   careful to initialize the storage of these two variables to all
		   zeroes.  One might think it more efficient simply to compare the
		   modified fields, but that would require enumerating those fields --
		   and not all systems have the same fields in this structure.  */

		if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
#ifdef CIBAUD
			/* SunOS 4.1.3 (at least) has the problem that after this sequence,
			   tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
			   sometimes (m1 != m2).  The only difference is in the four bits
			   of the c_cflag field corresponding to the baud rate.  To save
			   Sun users a little confusion, don't report an error if this
			   happens.  But suppress the error only if we haven't tried to
			   set the baud rate explicitly -- otherwise we'd never give an
			   error for a true failure to set the baud rate.  */

			new_mode.c_cflag &= (~CIBAUD);
			if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
#endif
				error_msg_and_die ("%s: unable to perform all requested operations",
					 device_name);
		}
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 7
0
Arquivo: gvccmd.c Projeto: 131/gsview
/* gsview menu commands */
int
gsview_command(int command)
{
    switch (command) {
    case IDM_NEXTHOME:
    case IDM_NEXT:
    case IDM_NEXTSKIP:
    case IDM_REDISPLAY:
    case IDM_PREVHOME:
    case IDM_PREVSKIP:
    case IDM_PREV:
    case IDM_GOBACK:
    case IDM_GOFWD:
    case IDM_MAGPLUS:
    case IDM_MAGMINUS:
    case IDM_FITWIN:
    case IDM_ZOOM:
    case IDM_FULLSCREEN:
        /* These don't close the full screen window */
        break;
    default:
        gsview_fullscreen_end();
    }
    switch (command) {
    case IDM_FULLSCREEN:
        gsview_fullscreen();
        return 0;
    case IDM_OPEN:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        gsview_display();
        return 0;
    case IDM_LASTFILE1:
    case IDM_LASTFILE2:
    case IDM_LASTFILE3:
    case IDM_LASTFILE4:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        make_cwd(last_files[command-IDM_LASTFILE1]);
        gsview_displayfile(last_files[command-IDM_LASTFILE1]);
        return 0;
    case IDM_CLOSE:
        /* doesn't unload DLL */
        /* close file */
        if (gsdll.open && (gsdll.state != GS_UNINIT)) {
            PSFILE *tpsfile;
            if (pending.psfile) {
                play_sound(SOUND_BUSY);
                return 0;
            }
            tpsfile = (PSFILE *)malloc(sizeof(PSFILE));
            if (tpsfile == NULL)
                return 0;
            memset((char *)tpsfile, 0, sizeof(PSFILE));
            pending.psfile = tpsfile;
            pending.now = TRUE;
            if (psfile.name[0] && psfile.dsc==(CDSC *)NULL)
                pending.abort = TRUE;
        }
        else {
            /* DLL isn't loaded */
            if (psfile.file)
                dfclose();	/* just to make sure */
            psfile_free(&psfile);
            post_img_message(WM_GSTITLE, 0);
            info_wait(IDS_NOWAIT);
        }
        return 0;
    case IDM_CLOSE_DONE:
        if (selectname[0] != '\0') {
            /* pending IDM_SELECT */
            PSFILE *tpsfile;
            tpsfile = gsview_openfile(selectname);
            if (tpsfile) {
                psfile = *tpsfile;
                free(tpsfile);
            }
            selectname[0] = '\0';
            post_img_message(WM_GSTITLE, 0);
            info_wait(IDS_NOWAIT);
        }
        return 0;
    case IDM_NEXTHOME:
#ifdef UNIX
        set_scroll(-1, 0);
#else
#ifdef _Windows
        PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L);
#else
        WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP));
#endif
#endif
    /* fall thru */
    case IDM_NEXT:
        if (not_open())
            return 0;
        gs_page_skip(1);
        return 0;
    case IDM_NEXTSKIP:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(page_skip);
        return 0;
    case IDM_REDISPLAY:
        if (dfchanged()) {
            PSFILE *tpsfile;
            if (dfchanged() < 0) {
                gs_addmess("File has been deleted\n");
                gsview_command(IDM_CLOSE);
                pending.unload = TRUE;
                pending.now = FALSE;
                return 0;
            }
            if (pending.psfile)
                tpsfile = pending.psfile;	/* new file, old file deleted */
            else
                tpsfile = gsview_openfile(psfile.name);
            if (tpsfile) {
                tpsfile->pagenum = psfile.pagenum;
                request_mutex();
                pending.psfile = tpsfile;
                if ( gsdll.hmodule &&  (psfile.dsc==(CDSC *)NULL) &&
                        (gsdll.state != GS_IDLE) )
                    /* don't know where we are so close and reopen */
                    pending.abort = TRUE;
                pending.now = TRUE;
                release_mutex();
            }
        }

        if (not_open())
            return 0;
        if (psfile.dsc==(CDSC *)NULL) {
            /* don't know where we are so close and reopen */
            if (gsdll.state != GS_IDLE) {
                if (!pending.psfile) {
                    pending.psfile = (PSFILE *)malloc(sizeof(PSFILE));
                    if (pending.psfile)
                        *pending.psfile = psfile;
                }
                pending.psfile->pagenum = pending.pagenum = 1;
                pending.abort = TRUE;
                pending.now = TRUE;
            }
        }
        else {
            pending.pagenum = -1;  /* default page number is current page */
            if (psfile.dsc->page_order == CDSC_SPECIAL)
                pending.pagenum = 1;	/* restart */
        }
        gsview_unzoom();
        pending.now = TRUE;
        return 0;
    case IDM_PREVHOME:
#ifdef UNIX
        set_scroll(-1, 0);
#else
#ifdef _Windows
        PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L);
#else
        WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP));
#endif
#endif
    /* fall thru */
    case IDM_PREV:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(-1);
        return 0;
    case IDM_PREVSKIP:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(-page_skip);
        return 0;
    case IDM_GOTO:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        if (psfile.dsc->page_count == 0) {
            gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
            return 0;
        }
        nHelpTopic = IDS_TOPICGOTO;
        {   int pagenum;
            pagenum = psfile.pagenum;
            if (get_page(&pagenum, FALSE, FALSE)) {
                gsview_goto_page(pagenum);
            }
        }
        return 0;
    case IDM_GOBACK:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        history_back();
        return 0;
    case IDM_GOFWD:
        if (not_open())
            return 0;
        if (psfile.dsc == (CDSC *)NULL)
            gsview_command(IDM_NEXT);
        else
            history_forward();
        return 0;
    case IDM_INFO:
        show_info();
        return 0;
    case IDM_SELECT:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        gsview_select();
        return 0;
#ifndef VIEWONLY
    case IDM_PRINT:
    case IDM_PRINTTOFILE:
    case IDM_CONVERTFILE:
        if (psfile.name[0] == '\0')
            gsview_select();
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (dfreopen() != 0)
            return 0;
        if (command == IDM_PRINTTOFILE)
            option.print_to_file = TRUE;
        if (psfile.name[0] != '\0')
            gsview_print(command == IDM_CONVERTFILE);
        dfclose();
        return 0;
    case IDM_SPOOL:
        gsview_spool((char *)NULL, (char *)NULL);
        return 0;
    case IDM_SAVEAS:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        if (psfile.name[0] != '\0')
            gsview_saveas();
        return 0;
    case IDM_EXTRACT:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        if (order_is_special())
            return 0;
        if (psfile.name[0] != '\0')
            gsview_extract();
        return 0;
    case IDM_PSTOEDIT:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        (void)order_is_special();    /* warn, but allow it anyway */
        if (dfreopen() != 0)
            return 0;
        if (psfile.name[0] != '\0')
            gsview_pstoedit();
        dfclose();
        return 0;
    case IDM_TEXTEXTRACT:
        if (psfile.name[0] == '\0')
            gsview_select();
        if (psfile.name[0] != '\0')
            gsview_text_extract();
        return 0;
    case IDM_TEXTEXTRACT_SLOW:
        gsview_text_extract_slow();
        return 0;
    case IDM_TEXTFIND:
        gsview_text_find();
        return 0;
    case IDM_TEXTFINDNEXT:
        gsview_text_findnext();
        return 0;
    case IDM_COPYCLIP:
        copy_clipboard();
        return 0;
    case IDM_PASTETO:
        paste_to_file();
        return 0;
    case IDM_CONVERT:
        clip_convert();
        return 0;
    case IDM_MEASURE:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        measure_show();
        return 0;
#endif /* !VIEWONLY */
    case IDM_GSMESS:
        gs_showmess();	/* show messages from Ghostscript */
        return 0;
    case IDM_EXIT:
        if (print_count) {
            /* Still busy printing.  Warn user. */
            TCHAR buf[MAXSTR];
            load_string(IDS_BUSYPRINTING, buf,
                        sizeof(buf)/sizeof(TCHAR)-1);
            if (message_box(buf, MB_OKCANCEL) != IDOK)
                return 0;
        }
        post_img_message(WM_CLOSE, 0);
        return 0;
    case IDM_CFG:	/* Easy configure */
        config_wizard(TRUE);
        return 0;
    case IDM_GSCOMMAND:	/* Advanced configure */
        if (install_gsdll() && gsdll.open)
            pending.unload = TRUE;
        return 0;
    case IDM_UNITPT:
    case IDM_UNITMM:
    case IDM_UNITINCH:
        gsview_unit(command);
        return 0;
    case IDM_UNITFINE:
        option.unitfine = !option.unitfine;
        check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine);
        return 0;
    case IDM_LANGMENU+1:
    case IDM_LANGMENU+2:
    case IDM_LANGMENU+3:
    case IDM_LANGMENU+4:
    case IDM_LANGMENU+5:
    case IDM_LANGMENU+6:
    case IDM_LANGMENU+7:
    case IDM_LANGMENU+8:
    case IDM_LANGMENU+9:
    case IDM_LANGMENU+10:
    case IDM_LANGMENU+11:
    case IDM_LANGMENU+12:
    case IDM_LANGMENU+13:
    case IDM_LANGMENU+14:
    case IDM_LANGMENU+15:
    case IDM_LANGMENU+16:
    case IDM_LANGMENU+17:
    case IDM_LANGMENU+18:
    case IDM_LANGMENU+19:
        gsview_language(command);
        return 0;
    case IDM_SAFER:
        option.safer = !option.safer;
        check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer);
        return 0;
    case IDM_SAVEDIR:
        option.save_dir = !option.save_dir;
        check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir);
        return 0;
    case IDM_BUTTONSHOW:
        option.button_show = !option.button_show;
        check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show);
        show_buttons();
        return 0;
    case IDM_FITPAGE:
        option.fit_page = !option.fit_page;
        check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page);
        /* should cause WM_SIZE message to be sent */
        return 0;
    case IDM_PSTOTEXTDIS:
    case IDM_PSTOTEXTNORM:
    case IDM_PSTOTEXTCORK:
        check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE);
        option.pstotext = command - IDM_PSTOTEXTMENU - 1;
        check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE);
        return 0;
    case IDM_AUTOREDISPLAY:
        option.redisplay = !option.redisplay;
        check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay);
        return 0;
    case IDM_EPSFCLIP:
        option.epsf_clip = !option.epsf_clip;
        check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip);
        gs_resize();
        return 0;
    case IDM_EPSFWARN:
        option.epsf_warn = !option.epsf_warn;
        check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn);
        return 0;
    case IDM_IGNOREDSC:
        option.ignore_dsc = !option.ignore_dsc;
        check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc);
        if (psfile.name[0]) {
            if (option.redisplay)
                gsview_displayfile(psfile.name);
            else
                gsview_selectfile(psfile.name);
        }
        return 0;
    case IDM_SHOWBBOX:
        option.show_bbox = !option.show_bbox;
        check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox);
#ifdef UNIX
        gtk_widget_draw(img, NULL);
#else
#ifdef _Windows
        PostMessage(hwndimg, WM_GSSYNC, 0, 0L);
#else
        if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE))
            error_message("error invalidating rect");
        if (!WinUpdateWindow(hwnd_bmp))
            error_message("error updating window");
#endif
#endif
        return 0;
#ifndef VIEWONLY
    case IDM_PSTOEPS:
        if (not_open())
            return 0;
        if (psfile.name[0] != '\0') {
            if (dfreopen() != 0)
                return 0;
            ps_to_eps();
            dfclose();
        }
        return 0;
    case IDM_MAKEEPSI:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_interchange(FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPST4:
    case IDM_MAKEEPST6U:
    case IDM_MAKEEPST6P:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_tiff(command, FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPSW:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_metafile(FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPSU:
        if (dfreopen() != 0)
            return 0;
        make_eps_user();
        dfclose();
        return 0;
    case IDM_EXTRACTPS:
    case IDM_EXTRACTPRE:
        if (dfreopen() != 0)
            return 0;
        extract_doseps(command);
        dfclose();
        return 0;
#endif
    case IDM_SETTINGS:
        write_profile();
        return 0;
    case IDM_SAVESETTINGS:
        option.settings = !option.settings;
        check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings);
        {   char buf[MAXSTR];
            PROFILE *prf = profile_open(szIniFile);
            sprintf(buf, "%d", (int)option.settings);
            profile_write_string(prf, INISECTION, "SaveSettings", buf);
            profile_close(prf);
        }
        return 0;
    case IDM_SOUNDS:
        change_sounds();
        return 0;
    case IDM_AUTOORIENT:
    case IDM_PORTRAIT:
    case IDM_LANDSCAPE:
    case IDM_UPSIDEDOWN:
    case IDM_SEASCAPE:
    case IDM_SWAPLANDSCAPE:
        gsview_orientation(command);
        return 0;
    case IDM_DSC_OFF:
    case IDM_DSC_ERROR:
    case IDM_DSC_WARN:
    case IDM_DSC_INFO:
        check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE);
        option.dsc_warn = command;
        check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE);
        return 0;
    case IDM_ZOOM:		/* called indirectly from Right Mouse Button */
        if (not_dsc()) {
            zoom = FALSE;
            return 0;
        }
        if (order_is_special()) {
            zoom = FALSE;
            return 0;
        }
        if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) {
            zoom = FALSE;
            gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
            return 0;
        }
        gs_resize();
        pending.pagenum = -1;  /* default page number is current page */
        pending.now = TRUE;
        return 0;
    case IDM_MAGPLUS:
        gs_magnify((float)1.2);
        return 0;
    case IDM_MAGMINUS:
        gs_magnify((float)0.8333);
        return 0;
    case IDM_FITWIN:
        /* fit media to size of current window */
        gsview_fitwin();
        return 0;
    case IDM_DISPLAYSETTINGS:
        display_settings();
        return 0;
    case IDM_MEDIAROTATE:
        option.media_rotate = !option.media_rotate;
        check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE,
                        option.media_rotate);
        zoom = FALSE;
        gs_resize();
        return 0;
    case IDM_11x17:
    case IDM_A3:
    case IDM_A4:
    case IDM_A5:
    case IDM_B4:
    case IDM_B5:
    case IDM_LEDGER:
    case IDM_LEGAL:
    case IDM_LETTER:
    case IDM_NOTE:
    case IDM_USERSIZE:
    case IDM_USERSIZE1:
    case IDM_USERSIZE2:
    case IDM_USERSIZE3:
    case IDM_USERSIZE4:
    case IDM_USERSIZE5:
    case IDM_USERSIZE6:
    case IDM_USERSIZE7:
    case IDM_USERSIZE8:
    case IDM_USERSIZE9:
    case IDM_USERSIZE10:
    case IDM_USERSIZE11:
    case IDM_USERSIZE12:
    case IDM_USERSIZE13:
        if (command == IDM_USERSIZE)
            if (!gsview_usersize())
                return 0;
        gsview_media(command);
        return 0;
    case IDM_HELPCONTENT:
#ifdef UNIX
        nHelpTopic = IDS_TOPICROOT;
        get_help();
#else
#ifdef _Windows
#ifdef USE_HTMLHELP
        nHelpTopic = IDS_TOPICROOT;
        get_help();
#else
        WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL);
#endif
#else
        WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L);
#endif
#endif
        return 0;
    case IDM_HELPSEARCH:
#ifdef UNIX
        gs_addmess("IDM_HELPSEARCH: not implemented\n");
#else
#ifdef _Windows
#ifdef USE_HTMLHELP
        HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT(""));
        gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName);
#else
        WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)"");
#endif
#else
        WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L);
#endif
#endif
        return 0;
    case IDM_HELPKEYS:
        nHelpTopic = IDS_TOPICKEYS;
        get_help();
        return 0;
    case IDM_ABOUT:
        show_about();
        return 0;
    case IDM_REGISTER:
        registration_nag();
        return 0;
    }
    return 0;
}