Exemplo n.º 1
0
struct cli_state *cli_state_create()
{
    cli_state = malloc(sizeof(*cli_state));

    if (cli_state) {
        cli_state->dev = NULL;
        cli_state->last_lib_error = 0;
        cli_state->scripts = NULL;

        pthread_mutex_init(&cli_state->dev_lock, NULL);

        cli_state->rx = rxtx_data_alloc(BLADERF_MODULE_RX);
        if (!cli_state->rx) {
            goto cli_state_create_fail;
        }

        cli_state->tx = rxtx_data_alloc(BLADERF_MODULE_TX);
        if (!cli_state->tx) {
            goto cli_state_create_fail;
        }
    }

    init_signal_handling();

    return cli_state;

cli_state_create_fail:
    cli_state_destroy(cli_state);
    return NULL;
}
Exemplo n.º 2
0
void main(int argc, char **argv){
	init_logging();
	disruptor_command_line_options(argc, argv);
	init_signal_handling();
	disruptor_nfq_init();
	disruptor_nfq_bind();
	//stream->scenario.qh = d_nfq.qh;
	disruptor_nfq_handle_traffic();
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  signed char op;
  parserinfo_ls_t pinfo;

  struct option longopts[] = {
    { "version", 0, NULL, LS_VERSION },
    { "help", 0, NULL, LS_HELP },
    { "attributes", 0, NULL, LS_ATTRIBUTES },
    { 0 }
  };

  progname = "xml-ls";
  inputfile = "";
  inputline = 0;

  if( create_parserinfo_ls(&pinfo) ) {

    while( (op = getopt_long(argc, argv, "a",
			     longopts, NULL)) > -1 ) {
      set_option_ls(op, optarg, &pinfo);
    }

    init_signal_handling(SIGNALS_DEFAULT);
    init_file_handling();

    open_stdout();
    puts_stdout(get_headwrap());
    puts_stdout(get_open_root());

    stdparse(MAXFILES, argv + optind, (stdparserinfo_t *)&pinfo);

    putc_stdout('\n');
    puts_stdout(get_close_root());
    puts_stdout(get_footwrap());
    close_stdout();

    exit_file_handling();
    exit_signal_handling();
    
    free_parserinfo_ls(&pinfo);
  }

  return EXIT_SUCCESS;
}
Exemplo n.º 4
0
Arquivo: fgets.c Projeto: pakt/bladeRF
int interactive_init()
{

    if (input || line_buf) {
        interactive_deinit();
    }

    input = stdin;

    line_buf = calloc(line_buf_size, 1);
    if (!line_buf) {
        interactive_deinit();
        return CMD_RET_MEM;
    }

    init_signal_handling();
    caught_signal = false;

    return 0;
}
Exemplo n.º 5
0
struct cli_state *cli_state_create()
{
    cli_state = malloc(sizeof(*cli_state));

    if (cli_state) {
        cli_state->dev = NULL;
        cli_state->last_lib_error = 0;
        cli_state->scripts = NULL;

        cli_state->rx = rxtx_data_alloc(BLADERF_MODULE_RX);
        if (!cli_state->rx) {
            goto cli_state_create_fail;
        }

        cli_state->tx = rxtx_data_alloc(BLADERF_MODULE_TX);
        if (!cli_state->tx) {
            goto cli_state_create_fail;
        }

        if (rxtx_startup(cli_state, BLADERF_MODULE_RX)) {
            rxtx_data_free(cli_state->rx);
            cli_state->rx = NULL;
            goto cli_state_create_fail;
        }

        if (rxtx_startup(cli_state, BLADERF_MODULE_TX)) {
            rxtx_data_free(cli_state->tx);
            cli_state->tx = NULL;
            goto cli_state_create_fail;
        }
    }

    init_signal_handling();

    return cli_state;

cli_state_create_fail:
    cli_state_destroy(cli_state);
    return NULL;
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
  signed char op;
  parserinfo_cut_t pinfo;

  struct option longopts[] = {
    { "version", 0, NULL, CUT_VERSION },
    { "help", 0, NULL, CUT_HELP },
    { 0 }
  };

  progname = "xml-cut";
  inputfile = "";
  inputline = 0;

  if( create_parserinfo_cut(&pinfo) ) {

    while( (op = getopt_long(argc, argv, "c:f:t:",
			     longopts, NULL)) > -1 ) {
      set_option_cut(op, optarg, &pinfo);
    }
    sanity_check(&pinfo);

    init_signal_handling(SIGNALS_DEFAULT);
    init_file_handling();

    output_wrapper_start(&pinfo);

    stdparse(MAXFILES, argv + optind, (stdparserinfo_t *)&pinfo);

    output_wrapper_end(&pinfo);

    exit_file_handling();
    exit_signal_handling();

    free_parserinfo_cut(&pinfo);
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    init_signal_handling();
    init_logging(argc, argv);

    namespace po = boost::program_options;
    po::options_description desc("ZeroMQ proxy service");
    std::string configFile;
    unsigned int frontend_port = 0;
    unsigned int backend_port = 0;
    unsigned int publisher_port = 0;
    bool ack_pub_sub = false;

    desc.add_options()
        ("help,h", "Show help")

        ("config-file,c", po::value<std::string>(&configFile),
                "ZeroMQ proxy configuration file")

        ("frontend-port,front", po::value<unsigned int>(&frontend_port),
                "Frontend ROUTER port. RPC clients connect to frontend")

        ("backend-port,back", po::value<unsigned int>(&backend_port),
                "Backend ROUTER port. RPC servers connect to backend.")

        ("publisher-port,pub", po::value<unsigned int>(&publisher_port),
                "Publisher port. Fanout messages go over this port if PUB/SUB is used.")

        ("ack-pub-sub,ack", po::bool_switch(&ack_pub_sub),
                "Acknowledge received PUB/SUB messages or not.");

    po::variables_map vm;

    try
    {
        po::parsed_options parsed = po::command_line_parser(argc, argv)
                .options(desc).allow_unregistered().run();
        po::store(parsed, vm);
        po::notify(vm);

        zmqproxy::Configuration config(configFile);

        if (frontend_port)
            config.set_frontend_port(frontend_port);

        if (backend_port)
            config.set_backend_port(backend_port);

        if (publisher_port)
            config.set_publisher_port(publisher_port);

        if (ack_pub_sub)
            config.set_ack_pub_sub(ack_pub_sub);

        zmqproxy::CentralProxy proxy(config);

        while (true)
        {
            proxy.poll_for_messages();
            if( quit )
                // exit normally after SIGINT
                throw zmqproxy::SystemExit();
        }
    }
    catch(const zmqproxy::SystemExit& e)
    {
        LOG(error) << "Catched expected!" << e.what();
    }
    catch(const std::runtime_error& e)
    {
        LOG(error) << e.what();
    }
    catch(const std::exception& e)
    {
        LOG(error) << e.what();
    }
    catch(...)
    {
        LOG(error) << "Unexpected exception.";
    }

	return 0;
}
Exemplo n.º 8
0
int main(int argc, char **argv) {
  signed char op;
  parserinfo_mv_t pinfo;
  filelist_t fl;

  struct option longopts[] = {
    { "version", 0, NULL, MV_VERSION },
    { "help", 0, NULL, MV_HELP },
    { "write-files", 0, NULL, MV_FILES },
    { "prepend", 0, NULL, MV_PREPEND },
    { "replace", 0, NULL, MV_REPLACE },
    { "append", 0, NULL, MV_APPEND },
    { 0 }
  };

  progname = "xml-mv";
  inputfile = "";
  inputline = 0;

  if( create_parserinfo_mv(&pinfo) ) {

    while( (op = getopt_long(argc, argv, "",
			     longopts, NULL)) > -1 ) {
      set_option_mv(op, optarg, &pinfo);
    }

    init_signal_handling(SIGNALS_DEFAULT);
    init_file_handling();
    init_tempfile_handling();
    init_rollback_handling();

    if( !checkflag(pinfo.rcm.flags,RCM_CP_PREPEND|RCM_CP_APPEND) ) {
      setflag(&pinfo.rcm.flags,RCM_CP_APPEND);
      setflag(&pinfo.rcm.flags,RCM_CP_REPLACE);
    } 

    if( create_filelist(&fl, -1, argv + optind, FILELIST_MIN2) ) {

      pinfo.files = getfiles_filelist(&fl);
      pinfo.xpaths = getxpaths_filelist(&fl);
      pinfo.n = getsize_filelist(&fl);
    
      if( pinfo.n < 2 ) { 
	errormsg(E_FATAL, "no target specified (try --help).\n");
      }

      pinfo.target = pinfo.files[pinfo.n - 1];
      pinfo.tpaths = pinfo.xpaths[pinfo.n - 1];

      if( !checkflag(pinfo.rcm.flags,RCM_WRITE_FILES) ) {
	/* When --write-files is not selected, we cannot write
	 * to the files on the command line. So we use the following
	 * trick to implement moves within the target file (last on command
	 * line): we replace all instances of the target with a common
	 * tempfile, which we can write to as required. The first instance
	 * of the target is not replaced, since it must be read (to copy
	 * its contents into the tempfile).
	 */
	substitute_target(&pinfo);
      }

      if( stdparse2(pinfo.n - 1, pinfo.files, pinfo.xpaths, &pinfo.std) ) {

	if( reinit_parserinfo_mv(&pinfo) ) {
	  /* output always to stdout */
	  setflag(&pinfo.rcm.flags, RCM_CP_OUTPUT);
	  clearflag(&pinfo.rcm.flags, RCM_RM_OUTPUT);

	  stdparse2(1, &pinfo.files[pinfo.n - 1], 
		    &pinfo.xpaths[pinfo.n - 1], &pinfo.std);

	}

      }

      free_filelist(&fl);
    }

    exit_rollback_handling();
    exit_tempfile_handling();
    exit_file_handling();      
    exit_signal_handling();

    free_parserinfo_mv(&pinfo);
  }

  return EXIT_SUCCESS;
}
Exemplo n.º 9
0
Arquivo: hmine.c Projeto: arekfu/dbacl
int main(int argc, char **argv) {

  FILE *input;
  signed char op;

  void (*preprocess_fun)(void) = NULL;
  void (*postprocess_fun)(void) = print_summary;

  progname = "hmine";
  inputfile = "stdin";
  inputline = 0;

  /* set up internationalization */
  if( !setlocale(LC_ALL, "") ) {
    errormsg(E_WARNING,
	    "could not set locale, internationalization disabled\n");
  } else {
    if( u_options & (1<<U_OPTION_VERBOSE) ) {
      errormsg(E_WARNING,
	      "international locales not supported\n");
    }
  }

#if defined(HAVE_GETPAGESIZE)
  system_pagesize = getpagesize();
#endif
  if( system_pagesize == -1 ) { system_pagesize = BUFSIZ; }

  init_signal_handling();

  /* parse the options */
  while( (op = getopt(argc, argv, 
		      "aDvV")) > -1 ) {
    hset_option(op, optarg);
  }


  /* set up callbacks */


  if( preprocess_fun ) { (*preprocess_fun)(); }


  init_header_handling();

  /* now process only the first file on the command line,
     or if none provided read stdin */
  if( (optind > -1) && *(argv + optind) ) {
    /* if it's a filename, process it */
    input = fopen(argv[optind], "rb");
    if( input ) {
      inputfile = argv[optind];

      u_options |= (1<<U_OPTION_STDIN);

      if( (u_options & (1<<U_OPTION_VERBOSE)) && 
	  !(u_options & (1<<U_OPTION_CLASSIFY))) {
	fprintf(stdout, "processing file %s\n", argv[optind]);
      }

      /* set some initial options */
      hprocess_file(input, &head);

      fclose(input);

    } else { /* unrecognized file name */

      errormsg(E_ERROR, "couldn't open %s\n", argv[optind]);
      usage(argv);
      return 0;

    }

  }
  /* in case no files were specified, get input from stdin */
  if( !(u_options & (1<<U_OPTION_STDIN)) &&
      (input = fdopen(fileno(stdin), "rb")) ) {

    if( (u_options & (1<<U_OPTION_VERBOSE)) && 
	!(u_options & (1<<U_OPTION_CLASSIFY)) ) {
      fprintf(stdout, "taking input from stdin\n");
    }

    hprocess_file(input, &head);

    /* must close before freeing in_iobuf, in case setvbuf was called */
    fclose(input); 

  }
  
  if( postprocess_fun ) { (*postprocess_fun)(); }

  cleanup_header_handling();

  cleanup_signal_handling();

  return exit_code;
}
Exemplo n.º 10
0
int main(int argc, char **argv)
{
  int num_queued;
  time_t start_time;
  double t;
  long num_frames, fast_skip = 200, fast_rewind = 200;
  unsigned int width, height;
  XEvent xevent;
  const char *prgname = argv[0];
  const char *classname = "XLndmovie";
  char *pixel_file_name = NULL;
  FILE *pixel_file;
  unsigned char *buffer = NULL, *huff = NULL;
  XImage *shm_image;
  XShmSegmentInfo shminfo;
  int shm_major, shm_minor;
  Bool shm_pixmaps;
  int ShmCompletionType;
  int shmtransfer_completed;
  int i, count, step_key = 0;
  char xkey[32];
  KeySym keysym;
  XComposeStatus compose;
  int oc;
  extern int optind;
  extern char *optarg;


  init_signal_handling();
  display = xwin_init(NULL, prgname, classname, argc, argv, &screen_no, &width, &height);
  fixed_font = XLoadQueryFont(display, "fixed");
  mit_shm = XShmQueryVersion(display, &shm_major, &shm_minor, &shm_pixmaps);
  mit_shm = XShmQueryExtension(display);
  if (mit_shm == True)
  {
    /* printf("Shared memory extension used (found V %d.%d)\n", shm_major, shm_minor); */
    ShmCompletionType = XShmGetEventBase(display) + ShmCompletion;
  }
/*
  else
    printf("Standard Xlib used, no shared memory\n");
*/
  while ((oc = getopt(argc, argv, "c:f:r:h")) != -1)
  {
    switch (oc)
    {
    case 'c':
      cell_boxsize = strtol(optarg, NULL, 10);
      break;
    case 'f':
      fast_skip = strtol(optarg, NULL, 10);
      if (fast_skip < 1)
	fast_skip = 200;
      break;
    case 'r':
      fast_rewind = strtol(optarg, NULL, 10);
      if (fast_rewind < 1)
	fast_rewind = 200;
      break;
    default:
      fprintf(stderr, "Unknown option \'-%c\' -- ignored\n", oc);
      break;
    }
  }
  if (optind < argc)
    pixel_file_name = argv[optind++];
  else
  {
    fprintf(stderr, "No pixel file specified -- exit\n");
    exit (EXIT_FAILURE);
  }
  pixel_file = fopen(pixel_file_name, "rb");
  if (pixel_file == NULL)
  {
    fprintf(stderr, "Failed to open pixel file \"%s\" -- exit\n", pixel_file_name);
    exit (EXIT_FAILURE);
  }
  read_pixheader(pixel_file);
  if ((cell_boxsize <= 0) || ((width / world_width) < cell_boxsize))
    cell_boxsize = width / world_width;
  if ((height / world_height) < cell_boxsize)
    cell_boxsize = height / world_height;
  if (cell_boxsize <= 0)
    cell_boxsize = 1;
  if ((height / world_height) < cell_boxsize)
    cell_boxsize = height / world_height;
  window_width = world_width * cell_boxsize;
  pixmap_height = world_height * cell_boxsize;
  if (fixed_font)
    window_height = pixmap_height + fixed_font->ascent + fixed_font->descent + 5;
  else
    window_height = pixmap_height;
  buffer = (unsigned char *) malloc(world_width * world_height * sizeof(char));
  if (buffer == NULL)
  {
    fprintf(stderr, "Failed to allocate internal buffer\n");
    exit (EXIT_FAILURE);
  }
  huff = (unsigned char *) malloc(world_width * world_height * sizeof(char));
  if (buffer == NULL)
  {
    fprintf(stderr, "Failed to allocate internal buffer\n");
    free(buffer);
    exit (EXIT_FAILURE);
  }
  window = create_window(MOVER | FULLER | CLOSER | RTARROW | LFARROW | UPARROW | DNARROW,
	  window_width, window_height, redraw_pixworld, close_pixwindow, 100, 100, window_width, window_height);
  XSelectInput(display, window, WH_EVENTMASK | WH_SELECTMASK);
  map_window(window);
  if (create_lndgcs(lnd_gc, lndx_gc, background_gc, &text_gc))
  {
    fprintf(stderr, "Failed to create necessary GCs (insufficient colors?)\n");
    free(buffer);
    free(huff);
    exit (EXIT_FAILURE);
  }
  if (mit_shm)
  {
    shm_image = XShmCreateImage(display, DefaultVisual(display, screen_no),
	    DefaultDepth(display, screen_no), ZPixmap, NULL, &shminfo, window_width, pixmap_height);
/*
    printf("XImage Structure:\n");
    printf("width = %d, height = %d, depth = %d\n", shm_image->width, shm_image->height, shm_image->depth);
    printf("format: ");
    switch (shm_image->format)
    {
    case XYBitmap:
      printf("XYBitmap\n");
      break;
    case XYPixmap:
      printf("XYPixmap\n");
      break;
    case ZPixmap:
      printf("ZPixmap\n");
      break;
    default:
      printf("UNKNOWN (%d)\n", shm_image->format);
      break;
    }
    printf("%d bytes per line, %d bits per pixel\n", shm_image->bytes_per_line, shm_image->bits_per_pixel);
    switch (shm_image->byte_order)
    {
    case MSBFirst:
      printf("byte order: MSBFirst\n");
      break;
    case LSBFirst:
      printf("byte order: LSBFirst\n");
      break;
    default:
      printf("byte order UNKNOWN (%d)\n", shm_image->byte_order);
      break;
    }
    switch (shm_image->bitmap_bit_order)
    {
    case MSBFirst:
      printf("bitmap bit order: MSBFirst\n");
      break;
    case LSBFirst:
      printf("bitmap bit order: LSBFirst\n");
      break;
    default:
      printf("bitmap bit order UNKNOWN (%d)\n", shm_image->bitmap_bit_order);
      break;
    }
*/
    shminfo.shmid = shmget(IPC_PRIVATE, shm_image->bytes_per_line * shm_image->height, IPC_CREAT | 0777);
    if (shminfo.shmid == -1)
    {
      fprintf(stderr, "Failed to get shared memory segment, falling back to standard Xlib\n");
      mit_shm = 0;
    }
    else
    {
      shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
      shm_image->data = shminfo.shmaddr;
      shminfo.readOnly = False;
      if (XShmAttach(display, &shminfo))
	; /* printf("Shared mem successfully attached to server\n"); */
      else
      {
	mit_shm = 0;
	XDestroyImage(shm_image);
	shmdt(shminfo.shmaddr);
	shmctl(shminfo.shmid, IPC_RMID, 0);
	printf("Shared memory released\n");
      }
    }
  }
  if (!mit_shm)
  {
    paint_pixmap = XCreatePixmap(display, window, window_width, pixmap_height, DefaultDepth(display, screen_no));
    XFillRectangle(display, paint_pixmap, background_gc[15], 0, 0, window_width, pixmap_height);
  }
  redraw_pixmap = XCreatePixmap(display, window, window_width, pixmap_height, DefaultDepth(display, screen_no));
  XFillRectangle(display, redraw_pixmap, background_gc[15], 0, 0, window_width, pixmap_height);
/*
  for (i = 0; i < 6; i++)
  {
    XPutPixel(shm_image, 0, 0, lnd_pixel[i]);
    printf("lnd_pixel[%d]=%08lx -> data=%02x\n", i, lnd_pixel[i], shm_image->data[0]);
    XPutPixel(shm_image, 0, 0, lndx_pixel[i]);
    printf("lndx_pixel[%d]=%08lx -> data=%02x\n", i, lndx_pixel[i], shm_image->data[0]);
  }
  XPutPixel(shm_image, 0, 0, back_pixel);
  printf("back_pixel=%08lx -> data=%02x\n", back_pixel, shm_image->data[0]);
*/
  do
  {
    XNextEvent(display, &xevent);
    num_queued = XEventsQueued(display, QueuedAfterFlush);
    process_xevent(&xevent);
  }
  while (!((xevent.type == Expose) && (xevent.xexpose.window == window)));
  shmtransfer_completed = 1;
  start_time = time(NULL);
  num_frames = 0;
  while (!game_over)
  {
    if(feof(pixel_file) || ferror(pixel_file))
    {
      if (resume_fpos != -1)
      {
	mode = SINGLE_STEP;
	/* printf("switched to single step due to feof / ferror\n"); */
	step_key = 0;
	/*
	printf("rewinding to resume pos %ld\n", resume_fpos);
	fseek(pixel_file, resume_fpos, SEEK_SET);
	*/
      }
      else
      {
	fprintf(stderr, "Encountered EOF without finding any entry point -- quitting\n");
	game_over = 1;
      }
    }
    num_queued = XEventsQueued(display, QueuedAfterFlush);
    while ((num_queued) || ((mode == SINGLE_STEP) && !step_key))
    {
      XNextEvent(display, &xevent);
      num_queued = XEventsQueued(display, QueuedAfterFlush);
      /* printf("received event: %s, window: %d\n", event_name[xevent.type], (int) xevent.xany.window); */
      if (process_xevent(&xevent))
	continue;
      if (xevent.type == ShmCompletionType)
      {
        /* printf("shm transfer completed\n"); */
	shmtransfer_completed = 1;
      }
      if (xevent.type == KeyPress)
      {
        count = XLookupString(&(xevent.xkey), xkey, 32, &keysym, &compose);
	if (count)
	{
	  switch(xkey[0])
	  {
	  case 'f':
	    /* printf("fast forward\n"); */
	    /* printf("rewind position: %ld\n", resume_fpos); */
	    mode = FAST_FORWARD;
	    break;
	  case 'r':
	    /* printf("fast rewind\n"); */
	    /* printf("rewind position: %ld\n", resume_fpos); */
	    mode = FAST_REWIND;
	    break;
	  case 'b':
	    /* printf("backward play\n"); */
	    /* printf("rewind position: %ld\n", resume_fpos); */
	    mode = BACKWARD_PLAY;
	    rewind_generation(pixel_file);
	    break;
	  case 's':
	    /* printf("single step\n"); */
	    mode = SINGLE_STEP;
	    step_key = 0;
	    break;
	  case 'n':
	    /* printf("normal play\n"); */
	    /* printf("rewind position: %ld\n", resume_fpos); */
	    mode = NORMAL_PLAY;
	    break;
	  case 'q': case 'Q':
	    /* printf("game over, bye bye\n"); */
            mode = NORMAL_PLAY;
            step_key = 1;
	    game_over = 1;
	    break;
	  default:
	    step_key = 1;
	    break;
	  }
	}
      }
    }
    if ((mode == NORMAL_PLAY) || (mode == BACKWARD_PLAY) || ((mode == SINGLE_STEP) && step_key)
            || ((mode == FAST_FORWARD) && ((generation % fast_skip) == (fast_skip - 1)))
            || ((mode == FAST_REWIND) && ((generation % fast_rewind) == 1)))
    {
      if (mit_shm && shmtransfer_completed)
      {
	if (shm_draw_generation(pixel_file, shm_image, buffer, huff))
	{
	  mode = SINGLE_STEP;
	  /* printf("switched to single step after shm_draw_generation\n"); */
	  step_key = 0;
	}
	else
	{
	  if (window != BadValue)
	    XShmPutImage(display, window, background_gc[15], shm_image, 0, 0, 0, window_height - pixmap_height, window_width, pixmap_height, True);
	  if (redraw_pixmap != BadValue)
	  XShmPutImage(display, redraw_pixmap, background_gc[15], shm_image, 0, 0, 0, 0, window_width, pixmap_height, True);
	  shmtransfer_completed = 0;
	  num_frames++;
	}
      }
      else
      {
	if (draw_generation(pixel_file, paint_pixmap, buffer, huff))
	{
	  mode = SINGLE_STEP;
	  /* printf("switched to single step after draw_generation\n"); */
	  step_key = 0;
	}
	else
	{
	  if (window != BadValue)
	    XCopyArea(display, paint_pixmap, window, background_gc[15], 0, 0, window_width, pixmap_height, 0, window_height - pixmap_height);
	  if (redraw_pixmap != BadValue)
	    XCopyArea(display, paint_pixmap, redraw_pixmap, background_gc[15], 0, 0, window_width, pixmap_height, 0, 0);
	  num_frames++;
	}
      }
      redraw_text();
      if (mode == FAST_REWIND)
      {
	if (rewind_generation(pixel_file))
	{
	  mode = SINGLE_STEP;
	  /* printf("switched to single step after rewind_generation\n"); */
	  step_key = 0;
	}
      }
      step_key = 0;
    }
    switch (mode)
    {
    case BACKWARD_PLAY:
      if (rewind_generation(pixel_file))
      {
	mode = SINGLE_STEP;
	/* printf("switched to single step after rewind_generation\n"); */
	step_key = 0;
      }
      /* fall through */
    case FAST_REWIND:
      if (rewind_generation(pixel_file))
      {
	mode = SINGLE_STEP;
	/* printf("switched to single step after rewind_generation\n"); */
	step_key = 0;
      }
      redraw_text();
      break;
    case FAST_FORWARD:
      if (skip_frame(pixel_file))
      {
	mode = SINGLE_STEP;
	/* printf("switched to single step after skip_frame\n"); */
	step_key = 0;
      }
      redraw_text();
      break;
    }
  }
  t = difftime(time(NULL), start_time);
  /* printf("%ld frames in %f seconds (%f frames/sec)\n", num_frames, t, num_frames / t); */
  if (mit_shm)
  {
    XShmDetach(display, &shminfo);
    XDestroyImage(shm_image);
    shmdt(shminfo.shmaddr);
    shmctl(shminfo.shmid, IPC_RMID, 0);
    printf("Shared memory released\n");
  }
  free_lndgcs();
  if (window != BadValue)
    remove_window(window);
  if (redraw_pixmap != BadValue)
    XFreePixmap(display, redraw_pixmap);
  if (paint_pixmap != BadValue)
    XFreePixmap(display, paint_pixmap);
  free(buffer);
  free(huff);
  return (EXIT_SUCCESS);
}