Exemple #1
0
void save_to_db(int i)
{
	struct itimerval to;
	int res;

	//send search http req and leave everything else (e.g. parsing job) in the callback function of curl_perform

	HtmlContent h;
	h.content = (char*)malloc(1);
	h.size = 0;
	h.processed = 0;
	res = crawl("http://www.google.com.hk/search?q=%E9%99%88%E5%85%89%E8%AF%9A", &h);
/*
	signal(SIGALRM, save_to_db);

	to.it_interval.tv_sec = 0;
	to.it_interval.tv_usec = 0;
	to.it_value.tv_sec = config.interval;
	to.it_value.tv_usec = 0;

	setitimer(ITIMER_REAL, &to, 0);
*/

	printf("time flies\n");
}
void MenuScene::displayWorm()
{
    row_col size = {20, 18};
    FreePlayGround* playGround = FreePlayGround::create();
    playGround->create(size);
    playGround->setScale(1.4f);
    auto contentSize = playGround->getContentSize();
    playGround->setPosition(Vec2(-contentSize.width / 2, -contentSize.height / 2) + VisibleRect::center());
    playGround->setRotation(45);
    
    auto action = ScaleTo::create(4, 1.2);
    auto action2 = ScaleTo::create(4, 1.4);
    playGround->runAction(RepeatForever::create(Sequence::create(action, action2, nullptr)));
    
    this->addChild(playGround);
    
    setPlayGround(playGround);
    
    auto worm = FreeWorm::create();
    start_point start;
    start.info = {0, 9};
    start.direction = 1;
    
    worm->born(playGround, start);
    worm->setOpacity(150);
    worm->crawl();
}
Exemple #3
0
int main(int argc, char *argv[]) {
  pthread_mutex_init(&buffer_mutex, NULL);
  pthread_mutex_init(&bounded_queue_mutex, NULL);
  int rc = crawl("/u/c/s/cs537-1/ta/tests/4a/tests/files/small_buffer/pagea", 1, 1, 1, fetch, edge);
  assert(rc == 0);
  check(buffer_space_error == 0, "Shouldn't be possible to put multiple links inside buffer as buffer has only 1 space\n");
  return compareOutput(buffer, fill, "/u/c/s/cs537-1/ta/tests/4a/tests/files/output/small_buffer.out");
}
Exemple #4
0
int main()
{
	string input_file_name("seed.txt");
	string output_file_name("crawled_links.txt");
	CCrawl crawl(input_file_name.c_str(),output_file_name.c_str());
	
	crawl.DoCrawl();
}
static void
crawl(GumboTag tag, list_t *elements, GumboNode *node) {
  NODE_TYPE_CHECK(node);

  if (tag == node->v.element.tag)
    list_rpush(elements, list_node_new(node));

  GumboVector *children = &node->v.element.children;
  for (unsigned int i = 0; i < children->length; i++) {
    crawl(tag, elements, children->data[i]);
  }
}
 bool GeneticMutation::crawl(GeneticCondition* p_cond,float strength) {
   if(p_cond->getConditionType() == GCT_Compound) {
     bool retval = false;
     GeneticConditionsList conditions = ((GeneticCompoundCondition*)(p_cond))->getChildConditions();
     for(GeneticConditionsListIterator it = conditions.begin(); it != conditions.end(); it++) {
       retval = crawl(*it,strength) && retval;
     };
     return retval;
   } 
   else  {
     return execute(p_cond,strength);
   };
 };
 bool GeneticMutation::crawl(GeneticAction* p_act,float strength) {
   if(p_act->getActionType() == GAT_Compound) {
     bool retval = false;
     GeneticActionsList actions = ((GeneticCompoundAction*)(p_act))->getChildActions();
     for(GeneticActionsListIterator it = actions.begin(); it != actions.end(); it++) {
       retval = crawl(*it,strength) && retval;
     };
     return retval;
   } 
   else  {
     return execute(p_act,strength);
   };
 };
Exemple #8
0
int
main(int argc, cstring argv[])
{
	FILE *logfp;
	if (argc < 2) {
		(void) fprintf(stderr, "[%s] %s (%s)\n",
				"USAGE", *argv, "path/to/crawl *");
		return EXIT_FAILURE;
	}

	/* prepare to record diagnostics */
	if ((logfp = fopen(LOG_FILE, "a+b"))) {
		(void) fprintf(logfp, "[insect] started logging at %s", TIME_STAMP);
	} else {
		(void) fprintf(stderr, "[FATAL] %s (fopen failed)\n", LOG_FILE);
		return EXIT_FAILURE;
	}
	/* TODO don't need this?
	if (create_pipe(DUMP_TARGET, true_output)) {
		(void) fprintf(logfp, "[insect] %s (failed to establish pipe)\n",
				strerror(errno));
		return EXIT_FAILURE;
	}
	*/

	/* initializes a walk down "memory lane" */
	if (reminisce(NULL)) {
		(void) fprintf(stderr, "[FATAL] couldn't start (reminisce failed)\n");
		return EXIT_FAILURE;
	}
	/* crawl specified directories (in a single thread) */
	while (--argc) {
		if (file_exists(argv[argc])) {
			(void) fprintf(stdout, "[INFO] crawled %d entries (for '%s')\n",
					crawl((cstring) argv[argc], &remember), argv[argc]);
		}
	}
	/* dump all the info into a file */
	if (regurgitate(logfp, &record_dump)) {
		(void) fprintf(stderr, "[WARNING] entries remaining (after crawl)\n");
	}

	/* clean up resources */
	(void) fprintf(logfp, "[insect] stopped logging at %s", TIME_STAMP);
	if (fclose(logfp)) {
		(void) fprintf(stderr, "[WARNING] %s (fclose failed)\n", LOG_FILE);
	}
	return EXIT_SUCCESS;
}
list_t *
gumbo_get_elements_by_tag_name(const char *tag_name, GumboNode *root) {
  GumboTag tag;
  list_t *elements = NULL;

  if (!tag_name || GUMBO_TAG_UNKNOWN == (tag = gumbo_tag_enum(tag_name)))
    return NULL;

  if (!(elements = list_new()))
    return NULL;

  crawl(tag, elements, root);

  return elements;
}
Exemple #10
0
int main()
{
    int res;
    int count;
    HtmlContent h;
    char url[100] = "http://www.google.com.hk/search?q=";
    char ex[100];
    int len;

    h.content = (char*)malloc(1);
    h.size = 0;
    res = crawl("http://www.google.com.hk/search?q=chenguangcheng", &h);
//              res = crawl("http://www.google.com.hk/#hl=en&source=hp&q=%E9%99&btnG=Google+Search", &h);
//              res = crawl("http://www.google.com.hk/search?q=%E9%99%88%E5%85%89%E8%AF%9A", &h);
    printf("%s\n", h.content);
}
Exemple #11
0
bool
OverlayImpl::processRequest (beast::http::message const& req,
    Handoff& handoff)
{
    if (req.url() != "/crawl")
        return false;

    beast::http::message resp;
    resp.request(false);
    resp.status(200);
    resp.reason("OK");
    Json::Value v;
    v["overlay"] = crawl();
    handoff.response = HTTP::make_JsonWriter(resp, v);
    return true;
}
Exemple #12
0
void percolate()
{
   int x, y, z;
   
   for (x = 0; x < X; x++) //reset percolation / electrification lattice
         for (y = 0; y < Y; y++)
             for (z = 0; z < Z; z++)
	         perc[x][y][z] = 0;
   electricsegments=0;
   percolation=0;
   
   for (x = 0; x < X; x++) //electrifiy y=Y-1 plane
     for (y = 0; y < Y; y++)
       crawl(x,y,0); //if snake present
   
   fprintf(stderr,"Density: %f Electricsegments: %d Percolation: %d Fraction Electric Snakes: %f\n",DENSITY,electricsegments,percolation,(float)electricsegments/(float)num_segments);
}
Exemple #13
0
int generateoutput(L_Lsystem *system, char *outfile) {
	FILE *fp = fopen(outfile,"w");
	// populate the rule/substitution arrays
	crawl(system);
	//initial rule
	char *tgstring = malloc(2);
	tgstring[0] = system->start;
	tgstring[1] = 0;
	
	int n=1;
	
	//Build the string to be translated into instructions
	int len=1;
	int loc=0;
	char *result = malloc(1);
	while (n < system->limit) {
		
		int i = 0;
		while (tgstring[i] != 0) {
			if (rules[tgstring[i]] == 0) {
				if (loc < len + 1) {
					// insufficient space
					realloc(result,sizeof(result)+1);
					len++;
				}
				result[loc++] = tgstring[i];
			}
			else {
				if (loc + strlen(rules[tgstring[i]]) < len) {
					realloc(result,2*sizeof(result));
					len = 2*len;
				}
				result[loc] = tgstring[i];
				loc = loc + strlen(rules[tgstring[i]]);
			}
		}
		n++;
	}
	
	//Substitutions
	for (n=0;n<len;n++) {
		fprintf(fp,"%s\n",substitutions[result[n]]);
	}
	fclose(fp);
}
Exemple #14
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //for our settings
    QCoreApplication::setOrganizationName("BengalBionics");
    QCoreApplication::setOrganizationDomain("bengalbionics.com");
    QCoreApplication::setApplicationName("Chhobi");
    setWindowIcon(QIcon(":Images/Icons/chhobi-icon.png"));

    setup_ui();
    restore_appearance();
    setup_connections();
    setup_database();
    setup_photo_root();
    load_photo_list();
    crawl();
}
Exemple #15
0
/**
 * Crawls grid recursively for letters starting at grid[x][y].
 * Returns true iff all letters are found.
 */
bool crawl(string letters, int x, int y)
{
    // if out of letters, then we must've found them all!
    if (strlen(letters) == 0)
        return true;

    // don't fall off the grid!
    if (x < 0 || x >= DIMENSION)
        return false;
    if (y < 0 || y >= DIMENSION)
        return false;

    // been here before!
    if (marks[x][y])
        return false;

    // check grid[x][y] for current letter
    if (grid[x][y] != letters[0])
        return false;

    // mark location
    marks[x][y] = true;

    // look left and right for next letter
    for (int i = -1; i <= 1; i++)
    {
        // look down and up for next letter
        for (int j = -1; j <= 1; j++)
        {
            // check grid[x + i][y + j] for next letter
            if (crawl(&letters[1], x + i, y + j))
                return true;
        }
    }

    // unmark location
    marks[x][y] = false;

    // fail
    return false;
}
Exemple #16
0
/**
 * Returns true iff word, s, is found in grid.
 */
bool find(string s)
{
    // word must be at least 2 characters in length
    if (strlen(s) < 2)
        return false;

    // search grid for word
    for (int row = 0; row < DIMENSION; row++)
    {
        for (int col = 0; col < DIMENSION; col++)
        {
            // reset marks
            for (int i = 0; i < DIMENSION; i++)
                for (int j = 0; j < DIMENSION; j++)
                    marks[i][j] = false;

            // search for word starting at grid[i][j]
            if (crawl(s, row, col))
                return true;
        }
    }
    return false;
}
Exemple #17
0
int main(int argc, char *argv[])
{
    arguments arg;
    memset(&arg, 0, sizeof(arguments));

    /* Default values. */
    arg.verbosity = orcm_not_set;
    arg.color = orcc_not_set;
    arg.max_events = DEFAULT_MAX_EVENTS;
    arg.url = 0;
    arg.out_file = DEFAULT_OUT;
    arg.excludes = 0;
    arg.excludes_len = 0;

    /* Parse our arguments; every option seen by parse_opt will
       be reflected in arguments. */
    argp_parse(&argp, argc, argv, 0, 0, &arg);

    if (orcm_not_set == arg.verbosity) {
        arg.verbosity = orcm_normal;
    }

    if (orcc_not_set == arg.color) {
        arg.color = orcc_no_color;
    }

    init_polyorcout(arg.verbosity, arg.color);

    print_splash();
    crawl(&arg);

    free(arg.excludes);

    orcout(orcm_quiet, "Done!\n");
    return EXIT_SUCCESS;
}
Exemple #18
0
void crawl(int x, int y, int z)
{
  if (x<0 || x>=X ||
      y<0 || y>=Y ||
      z<0 || z>=Z ||
      lattice[x][y][z]==-1 || 
      perc[x][y][z]==1) //no snake OR already been here by alternate route...
     return;
   
  perc[x][y][z]=1; 
  electricsegments++;
   
   if (z==0) //crossed lattice
     percolation=1;
   
   crawl(x+1,y,z);
   crawl(x-1,y,z);
   crawl(x,y+1,z);
   crawl(x,y-1,z);
   crawl(x,y,z+1);
   crawl(x,y,z-1);
}
Exemple #19
0
void MainWindow::setup_connections()
{
    //Event filter for drag on mailing label
    ui->mailLabel->installEventFilter(this);

    //Menu
    QObject::connect(ui->actionSet_Root, SIGNAL(triggered()),
            this, SLOT(select_photo_root()));
    QObject::connect(ui->actionCrawl, SIGNAL(triggered()),
                     this, SLOT(crawl()));
    QObject::connect(ui->actionReload, SIGNAL(triggered()),
                     this, SLOT(load_photo_list()));
    QObject::connect(ui->actionAbout, SIGNAL(triggered()),
                     this, SLOT(about()));
    QObject::connect(ui->actionAboutQT, SIGNAL(triggered()),
                     qApp, SLOT(aboutQt()));


    //Ribbon
    QObject::connect(ribbon, SIGNAL(preview_id(PhotoInfo)),
            this, SLOT(set_preview_photo(PhotoInfo)));
    QObject::connect(ribbon, SIGNAL(hold()),
            this, SLOT(send_to_holding()));
    QObject::connect(hold_ribbon, SIGNAL(preview_id(PhotoInfo)),
            this, SLOT(set_preview_photo(PhotoInfo)));
    //Want to do fancy date thingy when user scrolls
    QScrollBar *ribbon_scroll = ui->QGV_timeline->verticalScrollBar();
    QObject::connect(ribbon_scroll, SIGNAL(sliderMoved(int)),
            ribbon, SLOT(slider_value_changed(int)));
    QObject::connect(ribbon_scroll, SIGNAL(sliderReleased()),
            ribbon, SLOT(slider_released()));

    //Database filter controls
    QObject::connect(ui->keywordListWidget, SIGNAL(itemSelectionChanged()),
                     this, SLOT(load_photos_with_active_keyword()));
    QObject::connect(ui->captionSearchLineEdit, SIGNAL(returnPressed()),
                     this, SLOT(load_photos_with_caption()));


    //Editing controls
    QObject::connect(ui->captionEdit, SIGNAL(textEdited(QString)),
            this, SLOT(photo_caption_changed()));
    QObject::connect(ui->captionEdit, SIGNAL(returnPressed()),
            this, SLOT(save_photo_meta_data()));
    QObject::connect(ui->dateTimeEdit, SIGNAL(editingFinished()),
            this, SLOT(save_photo_meta_data()));

    //Holding table connections
    QObject::connect(ui->resizeButton, SIGNAL(clicked()),
            this, SLOT(resize_photos()));
    QObject::connect(ui->folderButton, SIGNAL(clicked()),
            this, SLOT(show_resized_folder()));


    //Database crawler
    QObject::connect(&disk_crawler, SIGNAL(started()),
                     this, SLOT(crawl_started()));
    QObject::connect(&disk_crawler, SIGNAL(finished()),
                     this, SLOT(crawl_ended()));
    QObject::connect(&disk_crawler, SIGNAL(now_searching(const QString &)),
                     this, SLOT(now_crawling(const QString &)));
    QObject::connect(this, SIGNAL(stop_crawl()),
                     &disk_crawler, SLOT(stop()));//needed for window close

}
Exemple #20
0
int main(int argc, char *argv[]) {
  assert(argc == 2);
  int rc = crawl(argv[1], 1, 1, 1, fetch, edge);
  assert(rc == 0);
  return 0;
}
int main(int argc, char *argv[]) {
  pthread_mutex_init(&buffer_mutex, NULL);
  int rc = crawl("/u/c/s/cs537-1/ta/tests/4a/tests/files/complex_parsing/pagea", 5, 4, 15, fetch, edge);
  assert(rc == 0);
  return compareOutput(buffer, fill, "/u/c/s/cs537-1/ta/tests/4a/tests/files/output/complex_parsing.out");
}
 bool GeneticMutation::execute(GeneticClause* clause,float strength) {
   bool a = crawl(clause->act,strength);
   bool b = crawl(clause->cond,strength);
   return a && b;
 };