예제 #1
0
void solve_maze()
{
    if (false == g_from_std)
    {
        if (FALSE == check_file(g_input_file)) {
            exit(1);
        }
        ifstream fin(g_input_file);
        MazeData maze(fin);
        run_search(maze);
    } else {
        MazeData maze(std::cin);
        run_search(maze);
    }
}
예제 #2
0
RINGING_USING_NAMESPACE
RINGING_USING_STD

int main( int argc, char *argv[] )
{
  arguments args;

  {
    arg_parser ap(argv[0],
      "methsearch -- finds methods with particular properties.", 
		  "OPTIONS" );
    
    args.bind( ap );
    
    if ( !ap.parse(argc, argv) ) 
      {
	ap.usage();
	return 1;
      }

    if ( !args.validate( ap ) ) 
      return 1;
  }

  method_libraries::init();

  // So that errors with -M options are presented now rather than later.
  musical_analysis::force_init( args.bells );

  if ( formats_have_falseness_groups() )
    false_courses::optimise( args.bells );

  {
    method startmeth;
    try
      {
	startmeth = method( args.startmeth, args.bells );
      }
    catch ( const exception &e )
      {
	cerr << argv[0] 
	     << ": Unable to parse place-notation passed to start-at\n"
	     << e.what() << "\n";
	return 1;
      }

    try 
      {
	run_search( args, startmeth );
      }
    catch ( const exit_exception& ) 
      {}
  }

  if ( args.status ) clear_status();

  args.outputs.flush(); // Causes stats to be emitted.

  return 0;
}
예제 #3
0
파일: main.c 프로젝트: delrtye/Spot
int main(void)
{
	sp_error error;
	sp_session *session;

	// create the spotify session
	spconfig.application_key_size = g_appkey_size;
	error = sp_session_create(&spconfig, &session);
	if (error != SP_ERROR_OK) {
		fprintf(stderr, "Unable to create session: %s\n", sp_error_message(error));
		return 1;
	}

	// initialize audio
	audio_init(&g_audiofifo);

	// log in
	g_logged_in = 0;
	sp_session_login(session, username, password, 0, NULL);

	// main loop
	g_playing = 0;
	g_running = 1;
	int next_timeout = 0;
	while (g_running) {
		sp_session_process_events(session, &next_timeout);

		if (g_logged_in && !g_playing) {
			run_search(session);
			g_playing = 1;
		}
	}

	return 0;
}
예제 #4
0
static void
search_again (GeditViewFrame *frame,
              gboolean        search_backward)
{
	const gchar *entry_text;

	g_return_if_fail (frame->priv->search_mode == SEARCH);

	/* SEARCH mode */
	/* renew the flush timeout */
	if (frame->priv->typeselect_flush_timeout != 0)
	{
		g_source_remove (frame->priv->typeselect_flush_timeout);
		frame->priv->typeselect_flush_timeout =
			g_timeout_add (GEDIT_VIEW_FRAME_SEARCH_DIALOG_TIMEOUT,
			               (GSourceFunc)search_entry_flush_timeout,
			               frame);
	}

	entry_text = gtk_entry_get_text (GTK_ENTRY (frame->priv->search_entry));

	run_search (frame,
	            entry_text,
	            search_backward,
	            frame->priv->wrap_around,
	            FALSE);
}
static void
do_find (PlumaSearchDialog *dialog,
	 PlumaWindow       *window)
{
	PlumaView *active_view;
	PlumaDocument *doc;
	gchar *search_text;
	const gchar *entry_text;
	gboolean match_case;
	gboolean entire_word;
	gboolean wrap_around;
	gboolean search_backwards;
	guint flags = 0;
	guint old_flags = 0;
	gboolean found;

	/* TODO: make the dialog insensitive when all the tabs are closed
	 * and assert here that the view is not NULL */
	active_view = pluma_window_get_active_view (window);
	if (active_view == NULL)
		return;

	doc = PLUMA_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));

	entry_text = pluma_search_dialog_get_search_text (dialog);

	match_case = pluma_search_dialog_get_match_case (dialog);
	entire_word = pluma_search_dialog_get_entire_word (dialog);
	search_backwards = pluma_search_dialog_get_backwards (dialog);
	wrap_around = pluma_search_dialog_get_wrap_around (dialog);

	PLUMA_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
	PLUMA_SEARCH_SET_ENTIRE_WORD (flags, entire_word);

	search_text = pluma_document_get_search_text (doc, &old_flags);

	if ((search_text == NULL) ||
	    (strcmp (search_text, entry_text) != 0) ||
	    (flags != old_flags))
	{
		pluma_document_set_search_text (doc, entry_text, flags);
	}

	g_free (search_text);
	
	found = run_search (active_view,
			    wrap_around,
			    search_backwards);

	if (found)
		text_found (window, 0);
	else
		text_not_found (window, entry_text);

	gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
					   PLUMA_SEARCH_DIALOG_REPLACE_RESPONSE,
					   found);
}
static void
do_find_again (PlumaWindow *window,
	       gboolean     backward)
{
	PlumaView *active_view;
	gboolean wrap_around = TRUE;
	gpointer data;
	
	active_view = pluma_window_get_active_view (window);
	g_return_if_fail (active_view != NULL);

	data = g_object_get_data (G_OBJECT (window), PLUMA_SEARCH_DIALOG_KEY);
	
	if (data != NULL)
		wrap_around = pluma_search_dialog_get_wrap_around (PLUMA_SEARCH_DIALOG (data));
	
	run_search (active_view,
		    wrap_around,
		    backward);
}
예제 #7
0
static void winAtChess()
{

	char * fen[] = {

			"2rr3k/pp3pp1/1nnqbN1p/3pN3/2pP4/2P3Q1/PPB4P/R4RK1 w - - bm",
			"rnbqkbnr/pppp1ppp/4p3/8/6P1/5P2/PPPPP2P/RNBQKBNR b KQkq - 0 2",
			"rnbqkbnr/ppppp2p/8/5pp1/4P3/2N5/PPPP1PPP/R1BQKBNR w KQkq g6 0 3",
			"r4kr1/1b2R1n1/pq4p1/4Q3/1p4P1/5P2/PPP4P/1K2R3 w - - 0 1",
			"r3rk2/1p1n1p1Q/p1b1p3/2q3pN/8/2PB4/P1P2PP1/2KRR3 w - - 0 1",
			"8/8/8/8/8/7K/5k2/4R3 b - - 0 68",
			"5k2/6pp/p1qN4/1p1p4/3P4/2PKP2Q/PP3r2/3R4 b - - bm",   //wac005
			"2br2k1/2q3rn/p2NppQ1/2p1P3/Pp5R/4P3/1P3PPP/3R2K1 w - - bm", //wac010
			"r4q1k/p2bR1rp/2p2Q1N/5p2/5p2/2P5/PP3PPP/R5K1 w - - bm",
			"3qrbk1/ppp1r2n/3pP2p/3P4/2P4P/1P3Q2/PB6/R4R1K w - - bm",
			"6r1/3Pn1qk/p1p1P1rp/2Q2p2/2P5/1P4P1/P3R2P/5RK1 b - - bm"
	};
	char* answers[] = {
			"g3g6",
			"d8h4",
			"d1h5",
			"e7f7",
			"d3g6",
			"f2e1",
			"c6c4",
			"h4h7",
			"e7f7",
			"f3f7",
			"g6g3"
	};

	total=0;
	for (int i=0; i < 11; i++) {
		//printf("run search %s %s\n", fen[i], answers[i]);
		run_search( fen[i], answers[i]);
	}
	printf("Total %llu\n",  total);
}
예제 #8
0
gint
main (gint argc,
      gchar **argv)
{
	CamelService *service;
	CamelSession *session;
	CamelStore *store;
	CamelFolder *folder;
	CamelMimeMessage *msg;
	gint i, j;
	gint indexed;
	GPtrArray *uids;
	GError *error = NULL;

	camel_test_init (argc, argv);
	camel_test_provider_init (1, local_drivers);

	/* clear out any camel-test data */
	system ("/bin/rm -rf /tmp/camel-test");

	session = camel_test_session_new ("/tmp/camel-test");

	/* todo: cross-check everything with folder_info checks as well */
	/* todo: work out how to do imap/pop/nntp tests */

	/* we iterate over all stores we want to test, with indexing or indexing turned on or off */
	for (i = 0; i < G_N_ELEMENTS (stores); i++) {
		const gchar *name = stores[i];
		for (indexed = 0; indexed < 2; indexed++) {
			gchar *what = g_strdup_printf ("folder search: %s (%sindexed)", name, indexed?"":"non-");
			gchar *uid;
			gint flags;

			camel_test_start (what);
			test_free (what);

			push ("getting store");
			uid = g_strdup_printf ("test-uid-%d", i);
			service = camel_session_add_service (
				session, uid, stores[i],
				CAMEL_PROVIDER_STORE, &error);
			g_free (uid);
			check_msg (error == NULL, "adding store: %s", error->message);
			check (CAMEL_IS_STORE (service));
			store = CAMEL_STORE (service);
			g_clear_error (&error);
			pull ();

			push ("creating %sindexed folder", indexed?"":"non-");
			if (indexed)
				flags = CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX;
			else
				flags = CAMEL_STORE_FOLDER_CREATE;
			folder = camel_store_get_folder_sync (
				store, "testbox", flags, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);

			/* we need an empty folder for this to work */
			test_folder_counts (folder, 0, 0);
			g_clear_error (&error);
			pull ();

			/* append a bunch of messages with specific content */
			push ("appending 100 test messages");
			for (j = 0; j < 100; j++) {
				gchar *content, *subject;

				push ("creating test message");
				msg = test_message_create_simple ();
				content = g_strdup_printf ("data%d content\n", j);
				test_message_set_content_simple (
					(CamelMimePart *) msg, 0, "text/plain",
								content, strlen (content));
				test_free (content);
				subject = g_strdup_printf ("Test%d message%d subject", j, 100 - j);
				camel_mime_message_set_subject (msg, subject);

				camel_mime_message_set_date (msg, j * 60 * 24, 0);
				pull ();

				push ("appending simple message %d", j);
				camel_folder_append_message_sync (
					folder, msg, NULL, NULL, NULL, &error);
				check_msg (error == NULL, "%s", error->message);
				g_clear_error (&error);
				pull ();

				test_free (subject);

				check_unref (msg, 1);
			}
			pull ();

			push ("Setting up some flags &c");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < 100; j++) {
				gchar *uid = uids->pdata[j];

				if ((j / 13) * 13 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every13", TRUE);
				}
				if ((j / 17) * 17 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every17", TRUE);
				}
				if ((j / 7) * 7 == j) {
					gchar *tag = g_strdup_printf ("7tag%d", j / 7);
					camel_folder_set_message_user_tag (folder, uid, "every7", tag);
					test_free (tag);
				}
				if ((j / 11) * 11 == j) {
					camel_folder_set_message_user_tag (folder, uid, "every11", "11tag");
				}
			}
			camel_folder_free_uids (folder, uids);
			pull ();

			camel_test_nonfatal ("Index not guaranteed to be accurate before sync: should be fixed eventually");
			push ("Search before sync");
			run_search (folder, 100);
			pull ();
			camel_test_fatal ();

			push ("syncing folder, searching");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("syncing wiht expunge, search");
			camel_folder_synchronize_sync (
				folder, TRUE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("deleting every 2nd message");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < uids->len; j+=2) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 100);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 100);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			pull ();

			push ("closing and re-opening folder");
			check_unref (folder, 1);
			folder = camel_store_get_folder_sync (
				store, "testbox",
				flags & ~(CAMEL_STORE_FOLDER_CREATE),
				NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);
			g_clear_error (&error);

			push ("deleting remaining messages");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 50);
			for (j = 0; j < uids->len; j++) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 50);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 0);
			g_clear_error (&error);
			pull ();

			pull ();

			check_unref (folder, 1);
			pull ();

			push ("deleting test folder, with no messages in it");
			camel_store_delete_folder_sync (
				store, "testbox", NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);
			pull ();

			check_unref (store, 1);
			camel_test_end ();
		}
	}

	check_unref (session, 1);

	return 0;
}
예제 #9
0
/**
* Handler to check user input, and see if it matches any avaible commands.
* Will call the right methods for executing commands
*/
void handle_keyboard(sp_session *session, struct play_queue* node)
{
    char buffer[1024];

    fgets(buffer, sizeof(buffer), stdin);
    strtok(buffer, "\n");

    if (strcmp(buffer, "search") == 0) {
        player_reset();
        run_search(session);

    } else if ((strcmp(buffer, "list") == 0) || (strcmp(buffer, "ls") == 0 )) {
        print_playlists(session, pc);

    } else if(strcmp(buffer, "qshuffle") == 0) {
        queue_shuffle();

    } else if (strcmp(buffer, "queueadd") == 0) {
        sp_playlist* pl = parse_play_command(session, buffer, node);
        printf("done finding playlist \n");

        if(pl != NULL) printf("queueadd: %s\n", sp_playlist_name(pl));
        else {
            printf("no playlist\n");
            return;
        }

        int index;
        char input[10];
        fputs("Song number: ", stdout);
        fgets(input, sizeof(input) - 1, stdin);
        sscanf(input, "%d", &index);
        if(sp_playlist_num_tracks(pl) < index) {
            printf("index too high!\n");
            return;
        }

        sp_track* track = pl_find_song_by_id(pl, index);
        if(track != NULL) queue_add_first(track);

    } else if (strcmp(buffer, "list songs") == 0 ) {
        //release all threads
        sp_playlist* pl = playlist_find_by_num(session, pc);
        print_tracks_in_playlist(session, pl);

    } else if (strcmp(buffer, "help") == 0) {
        print_commands();

    } else if (strcmp(buffer, "queue") == 0) {
        queue_print(node);

    } else if (strcmp(buffer, "shuffle mode") == 0) {
        print_commands();

    } else if(strncmp(buffer, "play", strlen("play")) == 0) {
        player_reset();
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_go_next(session);


    } else if(strncmp(buffer, "shuffle", strlen("shuffle")) == 0) {
        player_reset();
        shuffle_mode = TRUE;
        sp_playlist* pl = parse_play_command(session, buffer, node);
        if(pl!=NULL) queue_add_playlist(pl);
        else {
            printf("ERROR playlist is null\n");
            return;
        }
        queue_shuffle();
        queue_go_next(session);

    } else if(strcmp(buffer, "pause") == 0 || strcmp(buffer, "p") == 0) {
        player_pause(session);
        play_info();

    } else if (strcmp(buffer, "next") == 0 || strcmp(buffer, "n") == 0) {
        end_track(session);

    } else if (strcmp(buffer, "stop") == 0) {

    } else if (strcmp(buffer, "info") == 0) {
        play_info();
    } else if (strcmp(buffer, "quit") == 0) {
        queue_free();
        quit_program(session);
    } else {
        printf("Unkown command!\n");
    }
    printf("> ");
    fflush(stdout);

    return;
}
예제 #10
0
파일: se.c 프로젝트: jnovotny-lmu/oracc
int
main(int argc, char * const*argv)
{
  struct token *toks = NULL;
  int ntoks = 0;

  f_log = stderr;
  exit_on_error = TRUE;
  setlocale(LC_ALL,LOCALE);
  options(argc, argv, "28acdg:j:o:p:P:stuvx:");
  if (!out_f)
    out_f = stdout;

  if (doing_debug)
    f_log = fopen("se.dbg","w");

  /*atf2utf8_init();*/
  charsets_init();
  langtag_init();
  tokinit();

  if (pretrim_file || pretrim_args)
    pretrim_setup();

  if (show_tokens)
    {
      if (xmldir)
	toks = tokenize(xmldir_toks(xmldir),&ntoks);
      else
	toks = tokenize((const char **)(argv+optind),&ntoks);
      showtoks(toks,ntoks);
    }
  else
    {
      if (any_index)
	{
	  const char *index[] = { "!cat" , "!txt" , "!tra" , "!lem", NULL, "!esp" , NULL };
	  struct Datum results[4];
	  int i, best_findset = -1;
	  char *hashproj = NULL;
	  FILE *anyout = stdout;
	  const char **toklist = NULL;

	  if (!project)
	    {
	      fprintf(stderr, "se: must give -j PROJECT option when using -a\n");
	      exit(1);
	    }

	  if (xmldir)
	    {
	      char *anyfile = malloc(strlen(xmldir)+5);
	      sprintf(anyfile,"%s/any",xmldir);
	      anyout = xfopen(anyfile,"w");
	    }

	  hashproj = malloc(strlen(project) + 2);
	  sprintf(hashproj, "#%s",project);

	  for (i = 0; index[i]; ++i)
	    {
	      if (!strcmp(index[i], "!lem"))
		{
		  if (best_findset > 0)
		    continue;
		}

	      toklist = anytoks(hashproj, index[i],
				xmldir ? xmldir_toks(xmldir) : (const char **)(argv+optind));
	      toks = tokenize(toklist,&ntoks);
	      /*showtoks(toks,ntoks);*/
	      run_search(toks);
	      results[i] = result;
	      if (result.count
		  && (best_findset < 0 
		      || (best_findset >= 0 && results[best_findset].count < result.count)))
		{
		  best_findset = i;
		  best_res_gran = res_gran;
		}
	    }
	  if (best_findset >= 0)
	    {
	      fprintf(anyout, "%s %lu\n", index[best_findset], 
		      (unsigned long)results[best_findset].count);
	      for (i = 0; index[i]; ++i)
		{
		  if (i == best_findset)
		    continue;
		  if (results[i].count)
		    fprintf(anyout, "%s %lu\n", index[i], (unsigned long)results[i].count);
		}
	      res_gran = best_res_gran;
	      return_index = &index[best_findset][1];
	      put_results(&results[best_findset]);
	    }
	  else
	    
	  fclose(anyout);
	}
      else
	{
	  toks = tokenize(xmldir ? xmldir_toks(xmldir) : (const char **)(argv+optind),&ntoks);
	  run_search(toks);
	  put_results(&result);
	}
    }

  if (pretrim)
    {
      hash_free(pretrim, NULL);
      pretrim = NULL;
      free(pretrim_lines);
      free(pretrim_content);
      pretrim_content = NULL;
      pretrim_lines = NULL;
      if (pretrim_args)
	{
	  list_free(pretrim_args, NULL);
	  pretrim_args = NULL;
	}
    }
  langtag_term();

  return 0;
}
예제 #11
0
static void
search_init (GtkWidget      *entry,
             GeditViewFrame *frame)
{
	const gchar *entry_text;

	/* renew the flush timeout */
	if (frame->priv->typeselect_flush_timeout != 0)
	{
		g_source_remove (frame->priv->typeselect_flush_timeout);
		frame->priv->typeselect_flush_timeout =
			g_timeout_add (GEDIT_VIEW_FRAME_SEARCH_DIALOG_TIMEOUT,
			               (GSourceFunc)search_entry_flush_timeout,
			               frame);
	}

	entry_text = gtk_entry_get_text (GTK_ENTRY (entry));

	if (frame->priv->search_mode == SEARCH)
	{
		update_search (frame);

		run_search (frame,
		            entry_text,
		            FALSE,
		            frame->priv->wrap_around,
		            TRUE);
	}
	else
	{
		if (*entry_text != '\0')
		{
			gboolean moved, moved_offset;
			gint line;
			gint offset_line = 0;
			gint line_offset = 0;
			gchar **split_text = NULL;
			const gchar *text;
			GtkTextIter iter;
			GeditDocument *doc;

			doc = gedit_view_frame_get_document (frame);

			gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc),
			                                  &iter,
			                                  frame->priv->start_mark);

			split_text = g_strsplit (entry_text, ":", -1);

			if (g_strv_length (split_text) > 1)
			{
				text = split_text[0];
			}
			else
			{
				text = entry_text;
			}

			if (*text == '-')
			{
				gint cur_line = gtk_text_iter_get_line (&iter);

				if (*(text + 1) != '\0')
					offset_line = MAX (atoi (text + 1), 0);

				line = MAX (cur_line - offset_line, 0);
			}
			else if (*entry_text == '+')
			{
				gint cur_line = gtk_text_iter_get_line (&iter);

				if (*(text + 1) != '\0')
					offset_line = MAX (atoi (text + 1), 0);

				line = cur_line + offset_line;
			}
			else
			{
				line = MAX (atoi (text) - 1, 0);
			}

			if (split_text[1] != NULL)
			{
				line_offset = atoi (split_text[1]);
			}

			g_strfreev (split_text);

			moved = gedit_document_goto_line (doc, line);
			moved_offset = gedit_document_goto_line_offset (doc, line,
			                                                line_offset);

			gedit_view_scroll_to_cursor (GEDIT_VIEW (frame->priv->view));

			if (!moved || !moved_offset)
			{
				set_entry_background (frame, frame->priv->search_entry,
				                      GEDIT_SEARCH_ENTRY_NOT_FOUND);
			}
			else
			{
				set_entry_background (frame, frame->priv->search_entry,
				                      GEDIT_SEARCH_ENTRY_NORMAL);
			}
		}
	}
}