示例#1
0
HitResponse
BonusBlock::collision(GameObject& other, const CollisionHit& hit_){

  Player* player = dynamic_cast<Player*> (&other);
  if (player) {
    if (player->does_buttjump)
      try_drop(player);
  }

  BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
  if(badguy) {
    // hit contains no information for collisions with blocks.
    // Badguy's bottom has to be below the top of the block
    // SHIFT_DELTA is required to slide over one tile gaps.
    if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > bbox.get_top() + SHIFT_DELTA ) ){
      try_open(player);
    }
  }
  Portable* portable = dynamic_cast<Portable*> (&other);
  if(portable) {
    MovingObject* moving = dynamic_cast<MovingObject*> (&other);
    if(moving->get_bbox().get_top() > bbox.get_bottom() - SHIFT_DELTA) {
      try_open(player);
    }
  }
  return Block::collision(other, hit_);
}
示例#2
0
文件: tl_cue.c 项目: CrimsonVoid/mpv
static bool open_source(struct MPContext *mpctx, struct bstr filename)
{
    void *ctx = talloc_new(NULL);
    bool res = false;

    struct bstr dirname = mp_dirname(mpctx->demuxer->filename);

    struct bstr base_filename = bstr0(mp_basename(bstrdup0(ctx, filename)));
    if (!base_filename.len) {
        mp_msg(MSGT_CPLAYER, MSGL_WARN,
               "CUE: Invalid audio filename in .cue file!\n");
    } else {
        char *fullname = mp_path_join(ctx, dirname, base_filename);
        if (try_open(mpctx, fullname)) {
            res = true;
            goto out;
        }
    }

    // Try an audio file with the same name as the .cue file (but different
    // extension).
    // Rationale: this situation happens easily if the audio file or both files
    // are renamed.

    struct bstr cuefile =
        bstr_strip_ext(bstr0(mp_basename(mpctx->demuxer->filename)));

    DIR *d = opendir(bstrdup0(ctx, dirname));
    if (!d)
        goto out;
    struct dirent *de;
    while ((de = readdir(d))) {
        char *dename0 = de->d_name;
        struct bstr dename = bstr0(dename0);
        if (bstr_case_startswith(dename, cuefile)) {
            mp_msg(MSGT_CPLAYER, MSGL_WARN, "CUE: No useful audio filename "
                    "in .cue file found, trying with '%s' instead!\n",
                    dename0);
            if (try_open(mpctx, mp_path_join(ctx, dirname, dename))) {
                res = true;
                break;
            }
        }
    }
    closedir(d);

out:
    talloc_free(ctx);
    if (!res)
        mp_msg(MSGT_CPLAYER, MSGL_ERR, "CUE: Could not open audio file!\n");
    return res;
}
示例#3
0
static FILE *
ldfile_find_command_file (const char *name,
			  bfd_boolean default_only,
			  bfd_boolean *sysrooted)
{
  search_dirs_type *search;
  FILE *result = NULL;
  char *path;
  static search_dirs_type *script_search;

  if (!default_only)
    {
      /* First try raw name.  */
      result = try_open (name, sysrooted);
      if (result != NULL)
	return result;
    }

  if (!script_search)
    {
      char *script_dir = find_scripts_dir ();
      if (script_dir)
	{
	  search_dirs_type **save_tail_ptr = search_tail_ptr;
	  search_tail_ptr = &script_search;
	  ldfile_add_library_path (script_dir, TRUE);
	  search_tail_ptr = save_tail_ptr;
	}
    }

  /* Temporarily append script_search to the path list so that the
     paths specified with -L will be searched first.  */
  *search_tail_ptr = script_search;

  /* Try now prefixes.  */
  for (search = default_only ? script_search : search_head;
       search != NULL;
       search = search->next)
    {
      path = concat (search->name, slash, name, (const char *) NULL);
      result = try_open (path, sysrooted);
      free (path);
      if (result)
	break;
    }

  /* Restore the original path list.  */
  *search_tail_ptr = NULL;

  return result;
}
示例#4
0
文件: usb.c 项目: h0nzZik/libiqrf
int usb_get_device_list(usb_addr devices[], int n_devices, bool count_only)
{
	int i, j;
	int cnt;
	struct libusb_device **list;

	/* clear list? */
	if (count_only == false)
		memset(devices, 0, n_devices * sizeof(usb_addr));

	cnt = libusb_get_device_list(usb_ctx, &list);
	if (cnt < 0)
		return cnt;

	j = 0;
	for (i=0; i < cnt && j < n_devices; i++) {
		if (device_supported(list[i]) && try_open(list[i])) {
			/* add to list? */
			if (count_only == false) {
				usb_device_get_addr(list[i], &devices[j]);
			}
			j++;
		}
	}
	libusb_free_device_list(list, 1);

	return j;
}
示例#5
0
FILE* fcFileOpener::OpenFile(const std::string& include_path)
{
	if ( include_path.empty() ) {
		return NULL;
	}

	std::string mod_path ( include_path );
	static std::string trimString("\"<> \t");

	mod_path.erase(0, mod_path.find_first_not_of(trimString));
	mod_path.erase(mod_path.find_last_not_of    (trimString)+1);

	if ( _scannedfiles.find(mod_path) != _scannedfiles.end() ) {
		// we already scanned this file
		return NULL;
	}

	// try to open the file as is
	FILE *fp (NULL);

	// try to prepend the search paths
	for (size_t i=0; i<_searchPath.size(); i++) {
		fp = try_open(_searchPath.at(i), mod_path);
		if ( fp ) return fp;
	}
	_scannedfiles.insert( mod_path );
	return NULL;
}
示例#6
0
FILEWrapper::FILEWrapper(const std::string& path, const char* mode) : _fp(nullptr)
{
	if (!try_open(path, mode)) {
		const auto errno_text = loguru::errno_as_text();
		throw_exception(loguru::strprintf("Failed to open file '%s' with mode '%s': %s",
		                                  path.c_str(), mode, errno_text.c_str()));
	}
}
示例#7
0
/* Wait until a suitable serial device exists, then open it */
void find_serial() {
	int wd;
	glob_t g;
	int nread, i;
	struct pollfd pollfd;
	struct inotify_event *e;
	char buf[sizeof(struct inotify_event) + FILENAME_MAX + 1],
		path[FILENAME_MAX + 1];

	wd = inotify_add_watch(inotifyfd,"/dev",IN_CREATE);
	e = (struct inotify_event *) buf;

	syslog(LOG_NOTICE,"looking for serial device");

	glob("/dev/"XBEEDEVBASE"*",0,NULL,&g);

	for(i = 0; i < g.gl_pathc; i++) {
		serialfd = try_open(g.gl_pathv[i],O_RDONLY | O_NOCTTY);
		if(serialfd >= 0) return;
	}

	globfree(&g);

	syslog(LOG_INFO,"nothing there, using inotify");

	pollfd.fd = inotifyfd;
	pollfd.events = POLLIN;

	while(serialfd < 0) {
		poll(&pollfd,1,-1);

		nread = read(inotifyfd,e,sizeof(struct inotify_event)
			+ FILENAME_MAX);

		if(nread < 0) syslog(LOG_WARNING,"read error (%m)");
		else if(strncmp(e->name,XBEEDEVBASE,strlen(XBEEDEVBASE)) == 0
				&& !(e->mask & IN_ISDIR)) {
			strcpy(path,"/dev/");
			strcat(path,e->name);
			serialfd = try_open(path,O_RDONLY | O_NOCTTY);
		}
	}

	inotify_rm_watch(inotifyfd,wd);
}
示例#8
0
static int try_open_fuse_device(char **devp)
{
	int fd;
	int err;

	drop_privs();
	fd = try_open(FUSE_DEV_NEW, devp, 0);
	restore_privs();
	if (fd >= 0)
		return fd;

	err = fd;
	fd = try_open(FUSE_DEV_OLD, devp, 1);
	if (fd >= 0)
		return fd;

	return err;
}
示例#9
0
static char *fopen_any_on_path(const char *fname, FILE **fp)
{
	const char *cur_dir = NULL;
	struct search_path *node;
	char *fullname;

	/*                             */
	assert(fp);
	if (current_srcfile)
		cur_dir = current_srcfile->dir;
	fullname = try_open(cur_dir, fname, fp);

	/*                                            */
	for (node = search_path_head; !*fp && node; node = node->next)
		fullname = try_open(node->dirname, fname, fp);

	return fullname;
}
示例#10
0
void init_putcomplex32(BlinkParams *params, BufContextBlock *blk, HeapContextBlock *hblk, size_t unit_size)
{
	blk->size_out = 64;
	blk->total_out = 0;

	write_time_stamp(params);

	if (params->outType == TY_DUMMY || params->outType == TY_FILE)
	{
		blk->num_output_buffer = (int32 *)malloc(2 * params->outBufSize * sizeof(int32));
		blk->num_output_entries = params->outBufSize * 2;
		if (params->outType == TY_FILE)
		{
			if (params->outFileMode == MODE_BIN)
			{
				blk->num_output_file = try_open(params->outFileName, "wb");
			}
			else
			{
				blk->num_output_file = try_open(params->outFileName, "w");
			}
		}
	}

	if (params->outType == TY_MEM)
	{
		if (blk->mem_output_buf == NULL || blk->mem_output_buf_size == 0)
		{
			fprintf(stderr, "Error: output memory buffer not initialized\n");
			exit(1);
		}
		else
		{
			blk->num_output_buffer = (int32*)blk->mem_output_buf;
			blk->num_output_entries = blk->mem_output_buf_size / (2 * blk->size_out / 8);
		}
	}

	if (params->outType == TY_SDR)
	{
		fprintf(stderr, "Error: Sora TX does not support Complex32\n");
		exit(1);
	}
}
示例#11
0
文件: brp.c 项目: AirSage/bashreduce
int main(int argc, char * argv[])
{
  line_t line;
  int i, j, col_index;
  int first_line = 1;

  if (argc < 5)
    showusage();
  if (strcmp(argv[1], "-") != 0)
    line.pin = try_open(argv[1], "rb");
  else
    line.pin = stdin;
  col_index = atoi(argv[2]);
  int pouts_len = atoi(argv[3]);
  const char* output_format = argv[4];

  FILE ** pouts = (FILE **) malloc( pouts_len * sizeof(FILE *) );
  char out_path[256];
  for (i = 0; i != pouts_len; ++i)
  {
    sprintf(out_path, output_format, i);
    pouts[i] = try_open(out_path, "wb");
  }

  while (fgets(line.buf, sizeof(line.buf), line.pin)) {
    if (first_line) {
      for (j = 0; j != pouts_len; ++j)
      {
        fputs(line.buf, pouts[j]); // write header to all the files
        first_line = 0;
      }
    }
    else if ( find_col(col_index, &line) ) // if this string has the requisite number of columns
      fputs(line.buf, pouts[fnv_hash(line.col_beg, line.col_end) % pouts_len]); // write it to the correct file
  }

  if (line.pin != stdin)
    fclose(line.pin);

  for (i = 0; i != pouts_len; ++i)
    fclose(pouts[i]);

  return 0;
}
示例#12
0
HitResponse
BonusBlock::collision(GameObject& other, const CollisionHit& hit){
    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
    if(badguy) {
      // hit contains no information for collisions with blocks.
      // Badguy's bottom has to be below the top of the bonusblock
      // +7 is required to slide over one tile gaps.
      if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + 7.0) ){
        try_open();
      }
    }
    Portable* portable = dynamic_cast<Portable*> (&other);
    if(portable) {
      MovingObject* moving = dynamic_cast<MovingObject*> (&other);
      if(moving->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
        try_open();
      }
    }
    return Block::collision(other, hit);
}
示例#13
0
static int detect(void)
{
    int fd;

    /* FIXME: do we need to set this? */
    /* setenv("ESD_NO_SPAWN", "1", 0); */
    fd = try_open();
    if (fd < 0)
	return 0;
    close(fd);
    return 1; /* found */
}
示例#14
0
文件: acquire.c 项目: nasa/QuIP
int set_continuous_output_file(QSP_ARG_DECL  const char *fname)
{
	polh_output_file = try_open(fname, "w");

	if( !polh_output_file ) {
		sprintf(ERROR_STRING, "Unable to open file for continuous output: %s", fname);
		warn(ERROR_STRING);
		return(-1);
	}

	return(0);
}
示例#15
0
static int open_fuse_device(char **devp)
{
    int fd;

    fd = try_open(FUSE_DEV_NEW, devp);
    if (fd >= -1)
        return fd;

    fprintf(stderr, "%s: fuse device is missing, try 'modprobe fuse' as root\n",
            progname);

    return -1;
}
示例#16
0
FILE* fcFileOpener::OpenFile(const wxString& include_path, wxString &filepath)
{
    filepath.Clear();
    if ( include_path.empty() ) {
        return NULL;
    }

    wxString mod_path ( include_path );

    static wxString trimString("\"<> \t");

    mod_path.erase(0, mod_path.find_first_not_of(trimString));
    mod_path.erase(mod_path.find_last_not_of    (trimString)+1);

    if ( _scannedfiles.find(mod_path) != _scannedfiles.end() ) {
        // we already scanned this file
        filepath.Clear();
        return NULL;
    }

    FILE *fp (NULL);
    
    // first try to cwd
    fp = try_open(_cwd, mod_path, filepath);
    if ( fp ) {
        return fp;
    }
    
    // Now try the search directories
    for (size_t i=0; i<_searchPath.size(); ++i) {
        fp = try_open(_searchPath.at(i), mod_path, filepath);
        if ( fp ) return fp;
    }
    
    _scannedfiles.insert( mod_path );
    filepath.Clear();
    return NULL;
}
示例#17
0
static int open_output(void)
{
    int fd;

    fd = try_open();

    if(fd < 0)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		  dpm.name, strerror(errno));
	return -1;
    }


    dpm.fd = fd;

    return 0;
}
示例#18
0
static void open_files(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
		       char *nfs[NSERVERS],
		       int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES])
{
	int server, fstype, conn, f; 

	for (server=0;server<NSERVERS;server++)
	for (fstype=0;fstype<NUMFSTYPES;fstype++)
	for (conn=0;conn<NCONNECTIONS;conn++)
	for (f=0;f<NFILES;f++) {
		fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME,
							 O_RDWR|O_CREAT);
		if (fnum[server][fstype][conn][f] == -1) {
			fprintf(stderr,"Failed to open fnum[%u][%u][%u][%u]\n",
				server, fstype, conn, f);
			exit(1);
		}
	}
}
示例#19
0
bool tcp_client::send(const void* data, unsigned int len, string* out /* = NULL */)
{
	bool have_retried = false, reuse_conn;

	while (true)
	{
		if (try_open(&reuse_conn) == false)
		{
			logger_error("connect server error");
			return false;
		}

		if (sender_->send(data, len) == false)
		{
			if (have_retried || !reuse_conn)
			{
				logger_error("send head error");
				return false;
			}

			have_retried = true;
			continue;
		}

		if (out == NULL)
			return true;

		if (reader_ == NULL)
			reader_ = new tcp_reader(*conn_);
		if (reader_->read(*out))
			return true;
		if (have_retried || !reuse_conn)
		{
			logger_error("read data error");
			return false;
		}

		have_retried = true;
	}
}
示例#20
0
void firewire_source::doGetNextFrame()
{
    if (!handle_.get() && !try_open())
    {
	handleClosure(this);
	return;
    }

    fFrameSize = std::min<unsigned int>(overspill_.size(), fMaxSize);
    fNumTruncatedBytes = fFrameSize - overspill_.size();

    if (fFrameSize)
    {
	memcpy(fTo, overspill_.data(), fFrameSize);
	overspill_.clear();
	FramedSource::afterGetting(this);
	return;
    }

    envir().taskScheduler().turnOnBackgroundReadHandling(
	raw1394_get_fd(handle_.get()), raw_poll, this);
}
示例#21
0
文件: lookmenu.c 项目: nasa/QuIP
static COMMAND_FUNC( do_read_data )	/** read a data file */
{
	FILE *fp;
	const char *filename;
	char num_str[16];

	filename=nameof("data file");
	fp=try_open( filename, "r" );
	if( !fp ) return;

	/* We used to clear the data tables here,
	 * but now they are dynamically allocated
	 * and cleared at that time...
	 */

	/* clear old classes */
	do_delete_all_classes(SINGLE_QSP_ARG);
	//curr_tcp=NULL;
	n_have_classes=0;
	if( read_exp_data(QSP_ARG  fp) != 0 ){
		fclose(fp);
		sprintf(ERROR_STRING,"do_read_data:  error return from read_exp_data, file %s",filename);
		WARN(ERROR_STRING);
		return;
	}
	fclose(fp);
	n_have_classes = eltcount(class_list());

	sprintf(num_str,"%d",n_have_classes);	// BUG?  buffer overflow
						// if n_have_classes too big???
	assign_reserved_var( "n_classes" , num_str );
	
	if( verbose ){
		sprintf(ERROR_STRING,"File %s read, %d classes, %d x-values",
			filename,n_have_classes,_nvals);
		advise(ERROR_STRING);
	}
}
示例#22
0
文件: log.cpp 项目: ailyasov/nfstrace
Log::Global::Global(const std::string& path)
    : log_file_path{path}
{
    if(own_file)
    {
        throw std::runtime_error{"Global Logger already have been created."};
    }

    if(!log_file_path.empty())
    {
        struct stat st;

        bool exists = (stat(log_file_path.c_str(), &st) == 0);

        if(!exists && log_file_path.back() == '/')
        {
            throw std::system_error{errno, std::system_category(), {"Error accessing directory: " + log_file_path}};
        }

        if(exists && S_ISDIR(st.st_mode))
        {
            throw std::system_error{errno, std::system_category(), {"Incorrect log file path: " + log_file_path + " - it is a directory! Please set correct path to log."}};
        }
    }
    else
    {
        log_file_path = "nfstrace.log";
    }

    log_file = try_open(log_file_path);
    own_file = true;

    if(utils::Out message{})
    {
        message << "Log file: " << log_file_path;
    }
}
示例#23
0
文件: main.c 项目: georgeee/OS_4sem
int main(int argc, char ** argv){
    int uid, flags;
    char filename[PATH_MAX + 5];
    int ret;
    uid_t ruid, euid, suid;
    char buffer[STDIN_BUFFER_SIZE];
    char * caret = buffer;
    int read_params_ret;
    while(!(read_params_ret = read_params(&uid, &flags, filename, buffer, &caret))){
        if((ret = change_uids(&ruid, &euid, &suid, uid)) != EXIT_SUCCESS_STATUS)
            return ret; 
        if((ret = try_open(filename, flags)) != EXIT_SUCCESS_STATUS)
            return ret;
        if((ret = restore_uids(ruid, euid, suid)) != EXIT_SUCCESS_STATUS)
            return ret;
    }
    if(read_params_ret & READ_PARAMS_INVALID_ARGS){
        return EXIT_INVALID_ARGS_STATUS;
    }
    if(read_params_ret & READ_PARAMS_OTHER){
        return EXIT_OTHER_ERROR_STATUS;
    }
    return EXIT_SUCCESS_STATUS;
}
示例#24
0
static BOOL test_one(struct smbcli_state *cli[NSERVERS][NCONNECTIONS], 
		     char *nfs[NSERVERS],
		     int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES],
		     struct record *rec)
{
	uint_t conn = rec->conn;
	uint_t f = rec->f;
	uint_t fstype = rec->fstype;
	uint_t start = rec->start;
	uint_t len = rec->len;
	uint_t r1 = rec->r1;
	uint_t r2 = rec->r2;
	enum brl_type op;
	int server;
	BOOL ret[NSERVERS];

	if (r1 < READ_PCT) {
		op = READ_LOCK; 
	} else {
		op = WRITE_LOCK; 
	}

	if (r2 < LOCK_PCT) {
		/* set a lock */
		for (server=0;server<NSERVERS;server++) {
			ret[server] = try_lock(cli[server][conn], fstype,
					       fnum[server][fstype][conn][f],
					       start, len, op);
		}
		if (showall || ret[0] != ret[1]) {
			printf("lock   conn=%u fstype=%u f=%u range=%u:%u(%u) op=%s -> %u:%u\n",
			       conn, fstype, f, 
			       start, start+len-1, len,
			       op==READ_LOCK?"READ_LOCK":"WRITE_LOCK",
			       ret[0], ret[1]);
		}
		if (ret[0] != ret[1]) return False;
	} else if (r2 < LOCK_PCT+UNLOCK_PCT) {
		/* unset a lock */
		for (server=0;server<NSERVERS;server++) {
			ret[server] = try_unlock(cli[server][conn], fstype,
						 fnum[server][fstype][conn][f],
						 start, len);
		}
		if (showall || (!hide_unlock_fails && (ret[0] != ret[1]))) {
			printf("unlock conn=%u fstype=%u f=%u range=%u:%u(%u)       -> %u:%u\n",
			       conn, fstype, f, 
			       start, start+len-1, len,
			       ret[0], ret[1]);
		}
		if (!hide_unlock_fails && ret[0] != ret[1]) return False;
	} else {
		/* reopen the file */
		for (server=0;server<NSERVERS;server++) {
			try_close(cli[server][conn], fstype, fnum[server][fstype][conn][f]);
			fnum[server][fstype][conn][f] = try_open(cli[server][conn], nfs[server], fstype, FILENAME,
								 O_RDWR|O_CREAT);
			if (fnum[server][fstype][conn][f] == -1) {
				printf("failed to reopen on share1\n");
				return False;
			}
		}
		if (showall) {
			printf("reopen conn=%u fstype=%u f=%u\n",
			       conn, fstype, f);
		}
	}
	return True;
}
示例#25
0
void
BonusBlock::hit(Player& )
{
  try_open();
}
示例#26
0
void
BonusBlock::try_drop(Player *player)
{
  if(sprite->get_action() == "empty") {
    SoundManager::current()->play("sounds/brick.wav");
    return;
  }

  Sector* sector = Sector::current();
  assert(sector);

  // First what's below the bonus block, if solid send it up anyway (excepting doll)
  Rectf dest_;
  dest_.p1.x = bbox.get_left() + 1;
  dest_.p1.y = bbox.get_bottom() + 1;
  dest_.p2.x = bbox.get_right() - 1;
  dest_.p2.y = dest_.p1.y + 30;
  if (!Sector::current()->is_free_of_statics(dest_, this, true) && !(contents == CONTENT_1UP)) {
    try_open(player);
    return;
  }

  if (player == NULL)
    player = sector->player;

  if (player == NULL)
    return;

  Direction direction = (player->get_bbox().get_middle().x > bbox.get_middle().x) ? LEFT : RIGHT;

  bool countdown = false;

  switch(contents) {
    case CONTENT_COIN:
    {
      try_open(player);
      break;
    }

    case CONTENT_FIREGROW:
    {
      drop_growup_bonus("images/powerups/fireflower/fireflower.sprite", countdown);
      break;
    }

    case CONTENT_ICEGROW:
    {
      drop_growup_bonus("images/powerups/iceflower/iceflower.sprite", countdown);
      break;
    }

    case CONTENT_AIRGROW:
    {
      drop_growup_bonus("images/powerups/airflower/airflower.sprite", countdown);
      break;
    }

    case CONTENT_EARTHGROW:
    {
      drop_growup_bonus("images/powerups/earthflower/earthflower.sprite", countdown);
      break;
    }

    case CONTENT_STAR:
    {
      sector->add_object(std::make_shared<Star>(get_pos() + Vector(0, 32), direction));
      SoundManager::current()->play("sounds/upgrade.wav");
      countdown = true;
      break;
    }

    case CONTENT_1UP:
    {
      sector->add_object(std::make_shared<OneUp>(get_pos(), DOWN));
      SoundManager::current()->play("sounds/upgrade.wav");
      countdown = true;
      break;
    }

    case CONTENT_CUSTOM:
    {
      //NOTE: non-portable trampolines could be moved to CONTENT_CUSTOM, but they should not drop
      object->set_pos(get_pos() +  Vector(0, 32));
      sector->add_object(object);
      object = 0;
      SoundManager::current()->play("sounds/upgrade.wav");
      countdown = true;
      break;
    }

    case CONTENT_SCRIPT:
    {
      countdown = true;
      break;
    } // because scripts always run, this prevents default contents from being assumed

    case CONTENT_LIGHT:
    {
      try_open(player);
      break;
    }
    case CONTENT_TRAMPOLINE:
    {
      try_open(player);
      break;
    }
    case CONTENT_RAIN:
    {
      try_open(player);
      break;
    }
    case CONTENT_EXPLODE:
    {
      hit_counter = 1; // multiple hits of coin explode is not allowed
      Sector::current()->add_object(std::make_shared<CoinExplode>(get_pos() + Vector (0, 40)));
      SoundManager::current()->play("sounds/upgrade.wav");
      countdown = true;
      break;
    }
  }

  if(!script.empty()) { // scripts always run if defined
    std::istringstream stream(script);
    Sector::current()->run_script(stream, "powerup-script");
  }

  if(countdown){ // only decrease hit counter if try_open was not called
    if(hit_counter == 1){
      sprite->set_action("empty");
    }else{
      hit_counter--;
    }
  }
}
示例#27
0
void
BonusBlock::hit(Player & player)
{
  try_open(&player);
}
static int
find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name,
			const char *debuglink_file, GElf_Word debuglink_crc,
			char **debuginfo_file_name)
{
  bool cancheck = debuglink_crc != (GElf_Word) 0;

  const char *file_basename = file_name == NULL ? NULL : basename (file_name);
  char *localname = NULL;
  if (debuglink_file == NULL)
    {
      /* For a alt debug multi file we need a name, for a separate debug
	 name we may be able to fall back on file_basename.debug.  */
      if (file_basename == NULL || mod->dw != NULL)
	{
	  errno = 0;
	  return -1;
	}

      size_t len = strlen (file_basename);
      localname = malloc (len + sizeof ".debug");
      if (unlikely (localname == NULL))
	return -1;
      memcpy (localname, file_basename, len);
      memcpy (&localname[len], ".debug", sizeof ".debug");
      debuglink_file = localname;
      cancheck = false;
    }

  /* Look for a file named DEBUGLINK_FILE in the directories
     indicated by the debug directory path setting.  */

  const Dwfl_Callbacks *const cb = mod->dwfl->callbacks;
  char *localpath = strdup ((cb->debuginfo_path ? *cb->debuginfo_path : NULL)
			    ?: DEFAULT_DEBUGINFO_PATH);
  if (unlikely (localpath == NULL))
    {
      free (localname);
      return -1;
    }

  /* A leading - or + in the whole path sets whether to check file CRCs.  */
  bool defcheck = true;
  char *path = localpath;
  if (path[0] == '-' || path[0] == '+')
    {
      defcheck = path[0] == '+';
      ++path;
    }

  /* XXX dev/ino should be cached in struct dwfl_file.  */
  struct stat64 main_stat;
  if (unlikely ((mod->main.fd != -1 ? fstat64 (mod->main.fd, &main_stat)
		 : file_name != NULL ? stat64 (file_name, &main_stat)
		 : -1) < 0))
    {
      main_stat.st_dev = 0;
      main_stat.st_ino = 0;
    }

  char *file_dirname = (file_basename == file_name ? NULL
			: strndup (file_name, file_basename - 1 - file_name));
  if (file_basename != file_name && file_dirname == NULL)
    {
      free (localpath);
      free (localname);
      return -1;
    }
  char *p;
  while ((p = strsep (&path, ":")) != NULL)
    {
      /* A leading - or + says whether to check file CRCs for this element.  */
      bool check = defcheck;
      if (*p == '+' || *p == '-')
	check = *p++ == '+';
      check = check && cancheck;

      const char *dir, *subdir, *file;
      switch (p[0])
	{
	case '\0':
	  /* An empty entry says to try the main file's directory.  */
	  dir = file_dirname;
	  subdir = NULL;
	  file = debuglink_file;
	  break;
	case '/':
	  /* An absolute path says to look there for a subdirectory
	     named by the main file's absolute directory.  This cannot
	     be applied to a relative file name.  For alt debug files
	     it means to look for the basename file in that dir or the
	     .dwz subdir (see below).  */
	  if (mod->dw == NULL
	      && (file_dirname == NULL || file_dirname[0] != '/'))
	    continue;
	  dir = p;
	  if (mod->dw == NULL)
	    {
	      subdir = file_dirname;
	      /* We want to explore all sub-subdirs.  Chop off one slash
		 at a time.  */
	    explore_dir:
	      subdir = strchr (subdir, '/');
	      if (subdir != NULL)
		subdir = subdir + 1;
	      if (subdir && *subdir == 0)
		continue;
	      file = debuglink_file;
	    }
	  else
	    {
	      subdir = NULL;
	      file = basename (debuglink_file);
	    }
	  break;
	default:
	  /* A relative path says to try a subdirectory of that name
	     in the main file's directory.  */
	  dir = file_dirname;
	  subdir = p;
	  file = debuglink_file;
	  break;
	}

      char *fname = NULL;
      int fd = try_open (&main_stat, dir, subdir, file, &fname);
      if (fd < 0)
	switch (errno)
	  {
	  case ENOENT:
	  case ENOTDIR:
	    /* If we are looking for the alt file also try the .dwz subdir.
	       But only if this is the empty or absolute path.  */
	    if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/'))
	      {
		fd = try_open (&main_stat, dir, ".dwz",
			       basename (file), &fname);
		if (fd < 0)
		  {
		    if (errno != ENOENT && errno != ENOTDIR)
		      goto fail_free;
		    else
		      continue;
		  }
		break;
	      }
	    /* If possible try again with a sub-subdir.  */
	    if (mod->dw == NULL && subdir)
	      goto explore_dir;
	    continue;
	  default:
	    goto fail_free;
	  }
      if (validate (mod, fd, check, debuglink_crc))
	{
	  free (localpath);
	  free (localname);
	  free (file_dirname);
	  *debuginfo_file_name = fname;
	  return fd;
	}
      free (fname);
      close (fd);
    }

  /* No dice.  */
  errno = 0;
fail_free:
  free (localpath);
  free (localname);
  free (file_dirname);
  return -1;
}
示例#29
0
文件: fbmouse.c 项目: CiaranG/ZXdroid
int
fbmouse_init(void)
{
  int i;
#ifdef HAVE_GPM_H
  static Gpm_Connect conn = { ~0/*GPM_MOVE | GPM_DOWN | GPM_UP*/, 0, 0, ~0 };

  libgpm = dlopen( "libgpm.so", RTLD_LAZY );

  if( libgpm ) {
    typeof (Gpm_Open) *gpm_open = dlsym( libgpm, "Gpm_Open" );
    i = 1;
    if( gpm_open( &conn, 0 ) != -1 ) {
      gpmfd = *( typeof( &gpm_fd ) ) dlsym( libgpm, "gpm_fd" );
      gpmflag = ( typeof( &gpm_flag ) ) dlsym( libgpm, "gpm_flag" );
      gpm_getevent = dlsym( libgpm, "Gpm_GetEvent" );
      ui_mouse_present = 1;
      return 0;
    }
  } else
    fprintf( stderr, "%s: couldn't init libgpm: %s\n", fuse_progname,
	     dlerror() );
#endif

  /* No libgpm support, no libgpm or gpm is not running - use our own code */
  if( try_open ("/dev/input/mice") &&
      try_open ("/dev/mouse") &&
      try_open ("/dev/psaux") ) {
    if( errno == ENOENT || errno == ENODEV || errno == EACCES ) {
      fprintf( stderr, "%s: warning: no mouse, or not accessible\n",
	       fuse_progname );
      return 0;
    }
    fprintf( stderr, "%s: couldn't open mouse device: %s\n",
	     fuse_progname, strerror( errno ) );
    return 1;
  }

  /* Try to select plain PS/2 (just in case it's not already selected).
   * Ignore any error.
   */
  i = -1; /* account for big-endian */
  write( mouse_fd, &i, 1 );

  /* Try to set the mouse mode. We prefer ExPS/2 but will accept ImPS/2.
   * The main reason is so that the side buttons don't appear as duplicate
   * buttons 2 and 3, and so that the wheel is available should it be wanted
   * somewhere.
   */
  if( !try_mouse_mode( 100, 3 ) ) {
    packet_size = 4;
    mouse_mode = try_mouse_mode( 200, 4 ) ? ImPS2 : ExPS2;
  }

  /* *Now* we want non-blocking I/O... */
  i = 1;
  if( ioctl( mouse_fd, FIONBIO, &i ) )
    return fbmouse_end(); /* couldn't get it */

  ui_mouse_present = 1;
  return 0;
}
示例#30
0
FileReader::FileReader(const std::string& path, size_t blockSize):
    File(try_open(path)), Cur(new char[blockSize]), Next(new char[blockSize])
{
  std::setbuf(File, 0); // unbuffered, bitte
}