コード例 #1
0
ファイル: cli.cpp プロジェクト: mgierlings/botan
int Command::run(const std::vector<std::string>& params)
   {
   try
      {
      m_args.reset(new Argument_Parser(m_spec,
                                       {"verbose", "help"},
                                       {"output", "error-output", "rng-type", "drbg-seed"}));

      m_args->parse_args(params);

      if(m_args->has_arg("output"))
         {
         const std::string output_file = get_arg("output");

         if(output_file != "")
            {
            m_output_stream.reset(new std::ofstream(output_file, std::ios::binary));
            if(!m_output_stream->good())
               throw CLI_IO_Error("opening", output_file);
            }
         }

      if(m_args->has_arg("error-output"))
         {
         const std::string output_file = get_arg("error-output");

         if(output_file != "")
            {
            m_error_output_stream.reset(new std::ofstream(output_file, std::ios::binary));
            if(!m_error_output_stream->good())
               throw CLI_IO_Error("opening", output_file);
            }
         }

      if(flag_set("help"))
         {
         output() << help_text() << "\n";
         return 2;
         }

      this->go();
      return m_return_code;
      }
   catch(CLI_Usage_Error& e)
      {
      error_output() << "Usage error: " << e.what() << "\n";
      error_output() << help_text() << "\n";
      return 1;
      }
   catch(std::exception& e)
      {
      error_output() << "Error: " << e.what() << "\n";
      return 2;
      }
   catch(...)
      {
      error_output() << "Error: unknown exception\n";
      return 2;
      }
   }
コード例 #2
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_undo(GtkWidget *text, gpointer data)
{
gdouble temp;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom Undo");
        help_text(
                " is used to revert to the previous zoom value used.  Undo"  
		" only works one level deep."
        );
        return;
        }


temp=GLOBALS->tims.zoom;
GLOBALS->tims.zoom=GLOBALS->tims.prevzoom;
GLOBALS->tims.prevzoom=temp;
GLOBALS->tims.timecache=0;
calczoom(GLOBALS->tims.zoom);
fix_wavehadj();

gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "changed"); /* force zoom update */
gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "value_changed"); /* force zoom update */

DEBUG(printf("Zoombuttons Undo\n"));
}
コード例 #3
0
ファイル: pagebuttons.c プロジェクト: Pidbip/egtkwave
void
service_left_page(GtkWidget *text, gpointer data)
{
  TimeType ntinc, ntfrac;

  if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nPage Left");
        help_text(
                " scrolls the display window left one page worth of data."
		"  The net action is that the data scrolls right a page."
#ifdef WAVE_USE_GTK2
    " Scrollwheel Up also hits this button in non-alternative wheel mode."
#endif
        );
        return;
        }

  ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);	/* really don't need this var but the speed of ui code is human dependent.. */
  ntfrac=ntinc*GLOBALS->page_divisor;
  if((ntfrac<1)||(ntinc<1))
    ntfrac= /*ntinc=*/ 1; /* scan-build */

  if((GLOBALS->tims.start-ntfrac)>GLOBALS->tims.first)
    GLOBALS->tims.timecache=GLOBALS->tims.start-ntfrac;
  else
    GLOBALS->tims.timecache=GLOBALS->tims.first;

  GTK_ADJUSTMENT(GLOBALS->wave_hslider)->value=GLOBALS->tims.timecache;
  time_update();

  DEBUG(printf("Left Page\n"));
}
コード例 #4
0
ファイル: help.c プロジェクト: embisi-github/embisi_gip
static void
help_realize_text (GtkWidget *text, gpointer data)
{
help_text("Click on any menu item or button that corresponds to a menu item"
		" for its full description.  Pressing a hotkey for a menu item"
		" is also allowed.");
}
コード例 #5
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_full(GtkWidget *text, gpointer data)
{
gdouble estimated;
int fixedwidth;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom Full");
        help_text(
		" attempts a \"best fit\" to get the whole trace onscreen."
		"  Note that the trace may be more or less than a whole screen since"
		" this isn't a \"perfect fit.\""
        );
        return;
        }

if(GLOBALS->wavewidth>4) { fixedwidth=GLOBALS->wavewidth-4; } else { fixedwidth=GLOBALS->wavewidth; }
estimated=-log(((gdouble)(GLOBALS->tims.last-GLOBALS->tims.first+1))/((gdouble)fixedwidth)*((gdouble)200.0))/log(GLOBALS->zoombase);
if(estimated>((gdouble)(0.0))) estimated=((gdouble)(0.0));
	
GLOBALS->tims.prevzoom=GLOBALS->tims.zoom;
GLOBALS->tims.timecache=0;
	
calczoom(estimated);
GLOBALS->tims.zoom=estimated;

fix_wavehadj();
	
gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "changed"); /* force zoom update */
gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "value_changed"); /* force zoom update */
	
DEBUG(printf("Zoombuttons Full\n"));
}
コード例 #6
0
ファイル: main.c プロジェクト: gaibo/C
int main(int argc, char *argv[])
{
  int quit = 0;
  bst *address_book = NULL;
  char *curr_file = (char *)malloc(0);
  fprintf(stdout,"Welcome to adrbook!\n\n");
  fflush(stdout);
  if (argc == 2) {
    free(curr_file);
    curr_file = strdup(argv[1]);
    address_book = addr_book_from_file(curr_file);
    printf("Read file %s.\n", curr_file);
    putchar('\n');
    fflush(stdout);
  }
  char buf[BUF_SZ];
  /* interactive i/o loop */
  help_text();
  short_prompt();
  while (1) {
    char *cmd;
    cmd = fgets(buf, BUF_SZ, stdin);
    cmd = trim_newline(cmd);
    /* printf("cmd=%s\n", cmd); */
    putchar('\n');
    if (!process_cmd(&curr_file, cmd, &address_book, &quit))
      fprintf(stdout, "unknown command: \"%s\"\n", cmd);
    free(cmd);
    if (quit)
      break;
    short_prompt();
  }
  return 0;
}
コード例 #7
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_in(GtkWidget *text, gpointer data)
{
if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom In");
        help_text(
                " is used to increase the zoom factor around the marker."
#ifdef WAVE_USE_GTK2
		" Alt + Scrollwheel Down also hits this button in non-alternative wheel mode."
#endif
        );
        return;
        }

if(GLOBALS->tims.zoom<0)		/* otherwise it's ridiculous and can cause */
	{		/* overflow problems in the scope          */
	TimeType middle=0, width;

	if(GLOBALS->do_zoom_center)
		{
		if((GLOBALS->tims.marker<0)||(GLOBALS->tims.marker<GLOBALS->tims.first)||(GLOBALS->tims.marker>GLOBALS->tims.last))
			{
			if(GLOBALS->tims.end>GLOBALS->tims.last) GLOBALS->tims.end=GLOBALS->tims.last;
			middle=(GLOBALS->tims.start/2)+(GLOBALS->tims.end/2);
			if((GLOBALS->tims.start&1)&&(GLOBALS->tims.end&1)) middle++;
			}
			else
			{
			middle=GLOBALS->tims.marker;
			}
		}

	GLOBALS->tims.prevzoom=GLOBALS->tims.zoom;

	GLOBALS->tims.zoom++;
	calczoom(GLOBALS->tims.zoom);

	if(GLOBALS->do_zoom_center)
		{
		width=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);
		GLOBALS->tims.start=time_trunc(middle-(width/2));
	        if(GLOBALS->tims.start+width>GLOBALS->tims.last) GLOBALS->tims.start=time_trunc(GLOBALS->tims.last-width);
		if(GLOBALS->tims.start<GLOBALS->tims.first) GLOBALS->tims.start=GLOBALS->tims.first;
		GTK_ADJUSTMENT(GLOBALS->wave_hslider)->value=GLOBALS->tims.timecache=GLOBALS->tims.start;
		}
		else
		{
		GLOBALS->tims.timecache=0;
		}	

	fix_wavehadj();
	
	gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "changed"); /* force zoom update */
	gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "value_changed"); /* force zoom update */
	
	DEBUG(printf("Zoombuttons in\n"));
	}
}
コード例 #8
0
void LLPanelGroupTab::handleClickHelp()
{
	// Display the help text.
	std::string help_text( getHelpText() );
	if ( !help_text.empty() )
	{
		LLSD args;
		args["MESSAGE"] = help_text;
		LLFloater* parent_floater = gFloaterView->getParentFloater(this);
		parent_floater->addContextualNotification("GenericAlert",args);
	}
}
コード例 #9
0
void LLPanelGroupTab::handleClickHelp()
{
	// Display the help text.
	std::string help_text( getHelpText() );
	if ( !help_text.empty() )
	{
		LLSD args;
		args["MESSAGE"] = help_text;
		LLFloater* parent_floater = gFloaterView->getParentFloater(this);
		LLNotification::Params params(parent_floater->contextualNotification("GenericAlert"));
		params.substitutions(args);
		LLNotifications::instance().add(params);
	}
}
コード例 #10
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_left(GtkWidget *text, gpointer data)
{
GtkAdjustment *hadj;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom To Start");
        help_text(
		" is used to jump scroll to the trace's beginning."
        );
        return;
        }

hadj=GTK_ADJUSTMENT(GLOBALS->wave_hslider);
hadj->value=GLOBALS->tims.timecache=GLOBALS->tims.first;
time_update();
}
コード例 #11
0
ファイル: llpanelgroup.cpp プロジェクト: Boy/rainbow
void LLPanelGroupTab::handleClickHelp()
{
	// Display the help text.
	std::string help_text( getHelpText() );
	if ( !help_text.empty() )
	{
		LLStringUtil::format_map_t args;
		args["[MESSAGE]"] = help_text;
		LLAlertDialog* dialogp = gViewerWindow->alertXml("GenericAlert", args);
		if (dialogp)
		{
			LLFloater* root_floater = gFloaterView->getParentFloater(this);;
			if (root_floater)
			{
				root_floater->addDependentFloater(dialogp);
			}
		}
	}
}
コード例 #12
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_fit(GtkWidget *text, gpointer data)
{
gdouble estimated;
int fixedwidth;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom Best Fit");
        help_text(
		" attempts a \"best fit\" to get the whole trace onscreen."
		"  Note that the trace may be more or less than a whole screen since"
		" this isn't a \"perfect fit.\" Also, if the middle button baseline"
		" marker is nailed down, the zoom instead of getting the whole trace"
		" onscreen will use the part of the trace between the primary"
		" marker and the baseline marker."
        );
        return;
        }

if((GLOBALS->tims.baseline>=0)&&(GLOBALS->tims.marker>=0))
	{
	service_dragzoom(GLOBALS->tims.baseline, GLOBALS->tims.marker); /* new semantics added to zoom between the two */
	}
	else
	{
	if(GLOBALS->wavewidth>4) { fixedwidth=GLOBALS->wavewidth-4; } else { fixedwidth=GLOBALS->wavewidth; }
	estimated=-log(((gdouble)(GLOBALS->tims.last-GLOBALS->tims.first+1))/((gdouble)fixedwidth)*((gdouble)200.0))/log(GLOBALS->zoombase);
	if(estimated>((gdouble)(0.0))) estimated=((gdouble)(0.0));
	
	GLOBALS->tims.prevzoom=GLOBALS->tims.zoom;
	GLOBALS->tims.timecache=0;
	
	calczoom(estimated);
	GLOBALS->tims.zoom=estimated;

	fix_wavehadj();
	
	gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "changed"); /* force zoom update */
	gtk_signal_emit_by_name (GTK_OBJECT (GTK_ADJUSTMENT(GLOBALS->wave_hslider)), "value_changed"); /* force zoom update */
	}
	
DEBUG(printf("Zoombuttons Fit\n"));
}
コード例 #13
0
ファイル: edgebuttons.c プロジェクト: Zak-Olyarnik/CS-281
void
service_right_edge(GtkWidget *text, gpointer data)
{
(void)text;
(void)data;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nFind Next Edge");
        help_text(
                " moves the marker to the closest transition to the right of the marker"
		" of the first highlighted trace.  If the marker is not nailed down, it starts from min time."
        );
        return;
        }

edge_search(STRACE_FORWARD);

DEBUG(printf("Edge Right\n"));
}
コード例 #14
0
ファイル: pagebuttons.c プロジェクト: Pidbip/egtkwave
void
service_right_page(GtkWidget *text, gpointer data)
{
  TimeType ntinc, ntfrac;

  if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nPage Right");
        help_text(
		" scrolls the display window right one page worth of data."
		"  The net action is that the data scrolls left a page."
#ifdef WAVE_USE_GTK2
    " Scrollwheel Down also hits this button in non-alternative wheel mode."
#endif
        );
        return;
        }

  ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);
  ntfrac=ntinc*GLOBALS->page_divisor;

  if((ntfrac<1)||(ntinc<1))
    ntfrac=ntinc=1;

  if((GLOBALS->tims.start+ntfrac)<(GLOBALS->tims.last-ntinc+1))
	{
	GLOBALS->tims.timecache=GLOBALS->tims.start+ntfrac;
	}
        else 
	{
	GLOBALS->tims.timecache=GLOBALS->tims.last-ntinc+1;
    if(GLOBALS->tims.timecache<GLOBALS->tims.first)
      GLOBALS->tims.timecache=GLOBALS->tims.first;
	}

  GTK_ADJUSTMENT(GLOBALS->wave_hslider)->value=GLOBALS->tims.timecache;
  time_update();

  DEBUG(printf("Right Page\n"));
}
コード例 #15
0
ファイル: zoombuttons.c プロジェクト: Pidbip/egtkwave
void service_zoom_right(GtkWidget *text, gpointer data)
{
GtkAdjustment *hadj;
TimeType ntinc;

if(GLOBALS->helpbox_is_active)
        {
        help_text_bold("\n\nZoom To End");
        help_text(
		" is used to jump scroll to the trace's end."
        );
        return;
        }

ntinc=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx);

GLOBALS->tims.timecache=GLOBALS->tims.last-ntinc+1;
        if(GLOBALS->tims.timecache<GLOBALS->tims.first) GLOBALS->tims.timecache=GLOBALS->tims.first;

hadj=GTK_ADJUSTMENT(GLOBALS->wave_hslider);
hadj->value=GLOBALS->tims.timecache;
time_update();
}
コード例 #16
0
ファイル: fasttext.c プロジェクト: bartgrantham/fasttext
int main(int argc, char ** argv)
{
    char **files;
    char path[MAXPATHLEN];
    int error, count, i;

    tr_params render_params;
    main_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, MAX_WIDTH, MAX_HEIGHT);
    main_context = cairo_create(main_surface);

    error = FT_Init_FreeType( &library ); 

    // ENOTDIR, ENOENT, EACCES
    getcwd(path, MAXPATHLEN);
    if ( argc > 1 ) {  count = scanfont(argv[1], files);  }
               else {  count = scanfont(default_font_path, files);  }
    chdir(path);
    addfont("./DEFAULT.ttf", "__DEFAULT__");

    // FCGI loop:
    while(FCGI_Accept() >= 0)
    {
        bzero(&render_params, sizeof(render_params));

        get_params(getenv("QUERY_STRING"), &render_params);

        if ( render_params.help != NULL && (strncmp(render_params.help, "textdebug", 10) == 0) )
        {
            printf("Content-type: text/html\n\n%s", help_text(&render_params));
        }
        else
        {
            printf("Content-type: image/png\n\n");
            draw(&render_params);
        }
    }
}
コード例 #17
0
ファイル: BAT_sender.c プロジェクト: peterand/BATsender
int main(void)
{
	char cbuf[20], s[20];
	ioinit();

	stdout = stdin = &uart_str;
	sender_init();
	sei();
	
	help_text();
	for (;;){
		printf_P(PSTR("Enter command: "));
		if (fgets(cbuf, sizeof cbuf - 1, stdin) == NULL) help_text();
		else{
		  switch (tolower(cbuf[0])){
			default:
				printf("Unknown command: %s\n", cbuf);
				help_text();
				break;
			case 'f':
				if (sscanf(cbuf, "%*s %s", s) == 1){
					switch (tolower(s[0])){
						default:
							printf("Illegal channel: %s\n", cbuf);
							help_text();
							break;
						case 'a':
							bat_command(0,0);
							break;
						case 'b':
							bat_command(0,1);
							break;
						case 'c':
							bat_command(0,2);
							break;
						case 'd':
							bat_command(0,3);
							break;
						case 'm':
							bat_command(0,4);
							break;
					}
				}
				else{
					printf("Syntax error\n");
					help_text();
				}
				break;
			case 'n':
				if (sscanf(cbuf, "%*s %s", s) == 1){
					switch (tolower(s[0])){
						default:
						printf("Illegal channel: %s\n", cbuf);
						help_text();
						break;
						case 'a':
						bat_command(1,0);
						break;
						case 'b':
						bat_command(1,1);
						break;
						case 'c':
						bat_command(1,2);
						break;
						case 'd':
						bat_command(1,3);
						break;
						case 'm':
						bat_command(1,4);
						break;
						case 'x':
						bat_command(1,5);
						break;
					}
				}
				else{
					printf("Syntax error\n");
					help_text();
				}
				break;
		  }
		}
	}
}				
コード例 #18
0
ファイル: fdupes.c プロジェクト: MartinThoma/fdupes
int main(int argc, char **argv) {
  int x;
  int opt;
  FILE *file1;
  FILE *file2;
  file_t *files = NULL;
  file_t *curfile;
  file_t **match = NULL;
  filetree_t *checktree = NULL;
  int filecount = 0;
  int progress = 0;
  char **oldargv;
  int firstrecurse;
  
#ifndef OMIT_GETOPT_LONG
  static struct option long_options[] = 
  {
    { "omitfirst", 0, 0, 'f' },
    { "recurse", 0, 0, 'r' },
    { "recursive", 0, 0, 'r' },
    { "recurse:", 0, 0, 'R' },
    { "recursive:", 0, 0, 'R' },
    { "quiet", 0, 0, 'q' },
    { "sameline", 0, 0, '1' },
    { "size", 0, 0, 'S' },
    { "symlinks", 0, 0, 's' },
    { "hardlinks", 0, 0, 'H' },
    { "relink", 0, 0, 'l' },
    { "noempty", 0, 0, 'n' },
    { "delete", 0, 0, 'd' },
    { "version", 0, 0, 'v' },
    { "help", 0, 0, 'h' },
    { "noprompt", 0, 0, 'N' },
    { "summarize", 0, 0, 'm'},
    { "summary", 0, 0, 'm' },
    { 0, 0, 0, 0 }
  };
#define GETOPT getopt_long
#else
#define GETOPT getopt
#endif

  program_name = argv[0];

  oldargv = cloneargs(argc, argv);

  while ((opt = GETOPT(argc, argv, "frRq1Ss::HlndvhNm"
#ifndef OMIT_GETOPT_LONG
          , long_options, NULL
#endif
          )) != EOF) {
    switch (opt) {
    case 'f':
      SETFLAG(flags, F_OMITFIRST);
      break;
    case 'r':
      SETFLAG(flags, F_RECURSE);
      break;
    case 'R':
      SETFLAG(flags, F_RECURSEAFTER);
      break;
    case 'q':
      SETFLAG(flags, F_HIDEPROGRESS);
      break;
    case '1':
      SETFLAG(flags, F_DSAMELINE);
      break;
    case 'S':
      SETFLAG(flags, F_SHOWSIZE);
      break;
    case 's':
      SETFLAG(flags, F_FOLLOWLINKS);
      break;
    case 'H':
      SETFLAG(flags, F_CONSIDERHARDLINKS);
      break;
    case 'n':
      SETFLAG(flags, F_EXCLUDEEMPTY);
      break;
    case 'd':
      SETFLAG(flags, F_DELETEFILES);
      break;
    case 'v':
      printf("fdupes %s\n", VERSION);
      exit(0);
    case 'h':
      help_text();
      exit(1);
    case 'N':
      SETFLAG(flags, F_NOPROMPT);
      break;
    case 'm':
      SETFLAG(flags, F_SUMMARIZEMATCHES);
      break;

    default:
      fprintf(stderr, "Try `fdupes --help' for more information.\n");
      exit(1);
    }
  }

  if (optind >= argc) {
    errormsg("no directories specified\n");
    exit(1);
  }

  if (ISFLAG(flags, F_RECURSE) && ISFLAG(flags, F_RECURSEAFTER)) {
    errormsg("options --recurse and --recurse: are not compatible\n");
    exit(1);
  }

  if (ISFLAG(flags, F_SUMMARIZEMATCHES) && ISFLAG(flags, F_DELETEFILES)) {
    errormsg("options --summarize and --delete are not compatible\n");
    exit(1);
  }

  if (ISFLAG(flags, F_RECURSEAFTER)) {
    firstrecurse = nonoptafter("--recurse:", argc, oldargv, argv, optind);
    
    if (firstrecurse == argc)
      firstrecurse = nonoptafter("-R", argc, oldargv, argv, optind);

    if (firstrecurse == argc) {
      errormsg("-R option must be isolated from other options\n");
      exit(1);
    }

    /* F_RECURSE is not set for directories before --recurse: */
    for (x = optind; x < firstrecurse; x++)
      filecount += grokdir(argv[x], &files);

    /* Set F_RECURSE for directories after --recurse: */
    SETFLAG(flags, F_RECURSE);

    for (x = firstrecurse; x < argc; x++)
      filecount += grokdir(argv[x], &files);
  } else {
    for (x = optind; x < argc; x++)
      filecount += grokdir(argv[x], &files);
  }

  if (!files) {
    if (!ISFLAG(flags, F_HIDEPROGRESS)) fprintf(stderr, "\r%40s\r", " ");
    exit(0);
  }
  
  curfile = files;

  while (curfile) {
    if (!checktree) 
      registerfile(&checktree, curfile);
    else 
      match = checkmatch(&checktree, checktree, curfile);

    if (match != NULL) {
      file1 = fopen(curfile->d_name, "rb");
      if (!file1) {
	curfile = curfile->next;
	continue;
      }
      
      file2 = fopen((*match)->d_name, "rb");
      if (!file2) {
	fclose(file1);
	curfile = curfile->next;
	continue;
      }

      if (confirmmatch(file1, file2)) {
	registerpair(match, curfile, sort_pairs_by_mtime);
	
	/*match->hasdupes = 1;
        curfile->duplicates = match->duplicates;
        match->duplicates = curfile;*/
      }
      
      fclose(file1);
      fclose(file2);
    }

    curfile = curfile->next;

    if (!ISFLAG(flags, F_HIDEPROGRESS)) {
      fprintf(stderr, "\rProgress [%d/%d] %d%% ", progress, filecount,
       (int)((float) progress / (float) filecount * 100.0));
      progress++;
    }
  }

  if (!ISFLAG(flags, F_HIDEPROGRESS)) fprintf(stderr, "\r%40s\r", " ");

  if (ISFLAG(flags, F_DELETEFILES))
  {
    if (ISFLAG(flags, F_NOPROMPT))
    {
      deletefiles(files, 0, 0);
    }
    else
    {
      stdin = freopen("/dev/tty", "r", stdin);
      deletefiles(files, 1, stdin);
    }
  }

  else 

    if (ISFLAG(flags, F_SUMMARIZEMATCHES))
      summarizematches(files);
      
    else

      printmatches(files);

  while (files) {
    curfile = files->next;
    free(files->d_name);
    free(files->crcsignature);
    free(files->crcpartial);
    free(files);
    files = curfile;
  }

  for (x = 0; x < argc; x++)
    free(oldargv[x]);

  free(oldargv);

  purgetree(checktree);

  return 0;
}
コード例 #19
0
ファイル: fdupes.c プロジェクト: tizenorg/toolchains.fdupes
int main(int argc, char **argv) {
  int x;
  int opt;
  FILE *file1;
  FILE *file2;
  file_t *files = NULL;
  file_t *curfile;
  file_t *match = NULL;
  filetree_t *checktree = NULL;
  int filecount = 0;
  int progress = 0;
 
  static struct option long_options[] = 
  {
    { "omitfirst", 0, 0, 'f' },
    { "recurse", 0, 0, 'r' },
    { "quiet", 0, 0, 'q' },
    { "sameline", 0, 0, '1' },
    { "size", 0, 0, 'S' },
    { "symlinks", 0, 0, 's' },
    { "hardlinks", 0, 0, 'H' },
    { "noempty", 0, 0, 'n' },
    { "delete", 0, 0, 'd' },
    { "version", 0, 0, 'v' },
    { "help", 0, 0, 'h' },
    { 0, 0, 0, 0 }
  };

  program_name = argv[0];

  while ((opt = getopt_long(argc, argv, "frq1SsHndvh", long_options, NULL)) != EOF) {
    switch (opt) {
    case 'f':
      SETFLAG(flags, F_OMITFIRST);
      break;
    case 'r':
      SETFLAG(flags, F_RECURSE);
      break;
    case 'q':
      SETFLAG(flags, F_HIDEPROGRESS);
      break;
    case '1':
      SETFLAG(flags, F_DSAMELINE);
      break;
    case 'S':
      SETFLAG(flags, F_SHOWSIZE);
      break;
    case 's':
      SETFLAG(flags, F_FOLLOWLINKS);
      break;
    case 'H':
      SETFLAG(flags, F_CONSIDERHARDLINKS);
      break;
    case 'n':
      SETFLAG(flags, F_EXCLUDEEMPTY);
      break;
    case 'd':
      SETFLAG(flags, F_DELETEFILES);
      break;
    case 'v':
      printf("fdupes %s\n", VERSION);
      exit(0);
    case 'h':
      help_text();
      exit(1);
    default:
      fprintf(stderr, "Try `fdupes --help' for more information\n");
      exit(1);
    }
  }

  if (optind >= argc) {
    errormsg("no directories specified\n");
    exit(1);
  }

  for (x = optind; x < argc; x++) filecount += grokdir(argv[x], &files);

  if (!files) exit(0);
  
  curfile = files;

  while (curfile) {
    if (!checktree) 
#ifndef EXPERIMENTAL_RBTREE
      registerfile(&checktree, curfile);
#else
      registerfile(&checktree, NULL, TREE_ROOT, curfile);
#endif
    else 
      match = checkmatch(&checktree, checktree, curfile);

    if (match != NULL) {
      file1 = fopen(curfile->d_name, "rb");
      if (!file1) {
	curfile = curfile->next;
	continue;
      }

      file2 = fopen(match->d_name, "rb");
      if (!file2) {
	fclose(file1);
	curfile = curfile->next;
	continue;
      }
 
      if (confirmmatch(file1, file2)) {
	match->hasdupes = 1;
        curfile->duplicates = match->duplicates;
        match->duplicates = curfile;
      }
      
      fclose(file1);
      fclose(file2);
    }

    curfile = curfile->next;

    if (!ISFLAG(flags, F_HIDEPROGRESS)) {
      fprintf(stderr, "\rProgress [%d/%d] %d%% ", progress, filecount,
       (int)((float) progress / (float) filecount * 100.0));
      progress++;
    }
  }
コード例 #20
0
ファイル: fasttext.c プロジェクト: bartgrantham/fasttext
int draw(tr_params * render)
{
    fontface * face = NULL;
    cairo_surface_t * sub_surface;
    cairo_t * sub_context;
    cairo_status_t status;
    cairo_text_extents_t text_extents, help_extents;
    int stride;
    cairo_matrix_t matrix;
    double elapsed;
#ifdef __linux
    struct timespec tp_start, tp_end;
#else
    clock_t start, end;
#endif

#ifdef __linux
    clock_gettime(CLOCK_REALTIME, &tp_start);
#else
    start = clock();
#endif

    if ( render->text == NULL || strlen(render->text) == 0 )
    {
        fwrite(nullpng, 1, sizeof(nullpng), stdout);
        return 0;
    }

    if ( render->font != NULL )
        face = hash_get(faces, render->font);
    if ( face == NULL )
        face = hash_get(faces, "__DEFAULT__");

    cairo_set_font_size(main_context, render->size);
    cairo_set_font_face(main_context, face->cface);

    // the help parameter will probably alter the text to draw, so let's check it first
    if ( render->help != NULL && strncmp(render->help, "debug", sizeof("debug")) != 0 )
        render->text = help_text(render);

    // how big will the rendered text be?
    cairo_text_extents(main_context, render->text, &text_extents);

    // we'll might also need to know the extents of the help text
    if ( render->help != NULL && strncmp(render->help, "debug", sizeof("debug")) == 0 )
        cairo_text_extents(main_context, help_text(render), &help_extents);

    // since Cairo origins it's draw from the lower-left (for l2r text) we have to adjust y
    if ( render->y == _DEFAULT_Y )
        render->y = text_extents.height;

    // TODO - if helptext, grow render w and h as needed...
    // 1.06 is a swizzle factor to compensate for the incorrect extents cairo produces
    if ( render->w == _DEFAULT_WIDTH )
    {  render->w = ceil(render->x) + ceil(text_extents.width * 1.06);  }
    if ( render->h == _DEFAULT_HEIGHT )
    {  render->h = ceil(render->y) + ceil(text_extents.height);  }

    stride = cairo_image_surface_get_stride(main_surface);

    // we know how big the image will be, create our sub_surface from the main_surface
    sub_surface = cairo_image_surface_create_for_data(cairo_image_surface_get_data(main_surface),
        CAIRO_FORMAT_ARGB32, render->w, render->h, stride);
    sub_context = cairo_create(sub_surface);

    // Remember, this is a new surface that just happens to share the same
    // buffer as main_surface so we have to set the font size and face for it
    cairo_set_font_size(sub_context, render->size);
    cairo_set_font_face(sub_context, face->cface);

    // clear the buffer of left-over data
    cairo_set_operator(sub_context, CAIRO_OPERATOR_CLEAR);
    cairo_paint(sub_context);

    // And now we're ready to draw!
    cairo_set_operator(sub_context, CAIRO_OPERATOR_OVER);

    // do we need to show a background color?
    if ( render->bgr != 0.0 || render->bgg != 0.0 || render->bgb != 0.0 || render->bga != 0.0 )
    {
        cairo_set_source_rgba(sub_context, render->bgr, render->bgg, render->bgb, render->bga);
        cairo_paint_with_alpha(sub_context, render->bga);
    }

    // set text color
    cairo_set_source_rgba(sub_context, render->r, render->g, render->b, render->a);

    cairo_move_to(sub_context, render->x, render->y);

/*
    // TODO: rotation currently rotates around the upper-left corner, fix to rotate around text center
    if ( render->th != 0.0 )
    {
        cairo_get_font_matrix(sub_context, &matrix);
        cairo_matrix_rotate(&matrix, render->th);
        cairo_set_font_matrix(sub_context, &matrix);
    }
*/

    cairo_show_text(sub_context, render->text);

    // if we're set to debug, we'll have attempted a render above, and now we draw a parameters placard
    if ( render->help != NULL && (strncmp(render->help, "debug", sizeof("debug")) == 0) )
    {
        // half-transparent black fill
        cairo_set_source_rgba(sub_context, 0, 0, 0, 1.0);
        cairo_paint_with_alpha(sub_context, 0.5);

        face = hash_get(faces, "__DEFAULT__");
        cairo_set_font_face(sub_context, face->cface);
        cairo_set_font_size(sub_context, 12);

        cairo_move_to(sub_context, 0, 12);
        cairo_set_source_rgba(sub_context, 1, 1, 1, 1.0);
        cairo_show_text(sub_context, help_text(render));
    }

    status = cairo_surface_write_to_png_stream(sub_surface, FCGI_cairo_write_stream, NULL);

    cairo_destroy(sub_context);
    cairo_surface_destroy(sub_surface);

#ifdef __linux
    clock_gettime(CLOCK_REALTIME, &tp_end);
    elapsed = tp_end.tv_sec - tp_start.tv_sec;
    elapsed += (tp_end.tv_nsec - tp_start.tv_nsec)/1000000000.0;
#else
    end = clock();
    elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
#endif
//    fprintf(stderr, "elapsed: %.3fms", elapsed*1000);  // logging
}
コード例 #21
0
ファイル: main.c プロジェクト: gaibo/C
/* curr_file pointer must point to a heap-allocated string */
int process_cmd(char **curr_file, char *cmd, bst **address_book, int *quit)
{
  int parse_succeeded;
  char *cnet;
  char *infile;
  char *first_char;
  switch (cmd[0]) {
  case 'q':
    if (strcmp(cmd,"q")==0) {
      *quit = 1;
      return 1;
    }
    return 0;
  case 's':
    if (strcmp(cmd,"s")==0) {
      if (strlen(*curr_file)>0)
	fprintf(stdout,"Current file: %s.\n",*curr_file);
      addr_book_stats(*address_book);
      return 1;
    }
    return 0;
  case 'r':
    infile = extract_arg(cmd, &parse_succeeded);
    if (parse_succeeded) {
      bst *tmp = *address_book;
      *address_book = admin_addr_book_from_file(infile);
      if (*address_book==NULL) {
	/* restore address book */
	*address_book = tmp;
      } else {
	free(*curr_file);
	*curr_file = infile;
	bst_free(tmp);	
      }
    }
    return parse_succeeded;
  case 'c':
    first_char = extract_arg(cmd, &parse_succeeded);
    if (parse_succeeded) {
      if (strlen(first_char)!=1)
	fprintf(stdout,"Please type exactly one character as argument to c.\n");
      else {
	unsigned int z = bst_c(*address_book, first_char[0]);
	printf("(found %u CNETs starting with '%c')\n",z,first_char[0]);
      }
      putchar('\n');
      free(first_char);
    }
    return parse_succeeded;
  case 'l':
    cnet = extract_arg(cmd, &parse_succeeded);
    if (parse_succeeded) {
      int n_comparisons = 0;
      vcard *c = bst_search(*address_book, cnet, &n_comparisons);
      if (c==NULL) 
	fprintf(stdout,"%s not found in current address book.\n", cnet);
      else
	vcard_show(c);
      fprintf(stdout,"(Performed %d comparisons in search.)\n", n_comparisons);
      putchar('\n');
    }
    free(cnet);
    return parse_succeeded;
  case 'h':
    help_text();
    return 1;
  default:
    return 0;
  }
}
コード例 #22
0
ファイル: main.cpp プロジェクト: mgierlings/botan
int main(int argc, char* argv[])
   {
   std::cerr << Botan::runtime_version_check(BOTAN_VERSION_MAJOR, BOTAN_VERSION_MINOR, BOTAN_VERSION_PATCH);

   try
      {
      const std::string arg_spec =
         "botan-test --verbose --help --data-dir= --pkcs11-lib= --provider= "
         "--log-success --abort-on-first-fail --no-avoid-undefined --skip-tests= "
         "--test-threads=1 --run-long-tests --run-online-tests --test-runs=1 --drbg-seed= "
         "*suites";

      Botan_CLI::Argument_Parser parser(arg_spec);

      parser.parse_args(std::vector<std::string>(argv + 1, argv + argc));

      if(parser.flag_set("help"))
         {
         std::cout << help_text(arg_spec);
         return 0;
         }

#if defined(BOTAN_TARGET_OS_HAS_POSIX1) && defined(BOTAN_TARGET_OS_HAS_THREADS)
      // The mlock pool becomes a major contention point when many
      // threads are running.
      if(parser.get_arg_sz("test-threads") != 1)
         {
         ::setenv("BOTAN_MLOCK_POOL_SIZE", "0", 1);
         }
#endif

      const Botan_Tests::Test_Options opts(
         parser.get_arg_list("suites"),
         parser.get_arg_list("skip-tests"),
         parser.get_arg_or("data-dir", "src/tests/data"),
         parser.get_arg("pkcs11-lib"),
         parser.get_arg("provider"),
         parser.get_arg("drbg-seed"),
         parser.get_arg_sz("test-runs"),
         parser.get_arg_sz("test-threads"),
         parser.flag_set("verbose"),
         parser.flag_set("log-success"),
         parser.flag_set("run-online-tests"),
         parser.flag_set("run-long-tests"),
         parser.flag_set("abort-on-first-fail"));

#if defined(BOTAN_HAS_OPENSSL)
      if(opts.provider().empty() || opts.provider() == "openssl")
         {
         ::ERR_load_crypto_strings();
         }
#endif

      Botan_Tests::Test_Runner tests(std::cout);

      int rc = tests.run(opts);

#if defined(BOTAN_HAS_OPENSSL)
      if(opts.provider().empty() || opts.provider() == "openssl")
         {
         ERR_free_strings();
         ::ERR_remove_thread_state(nullptr);
         }
#endif

      return rc;
      }
   catch(std::exception& e)
      {
      std::cerr << "Exiting with error: " << e.what() << std::endl;
      }
   catch(...)
      {
      std::cerr << "Exiting with unknown exception" << std::endl;
      }
   return 2;
   }