예제 #1
0
/*
 * Initialize pointer 'vue' for the current viewport
 */
static void
init_view(void)
{
    vue = &viewlist[curview];
    vue->gbl->curfile = vue->curfile;
    (void) to_file(vue->gbl);
}
예제 #2
0
파일: b19.cpp 프로젝트: avjgit/notes3
int* position_string_to_array(string answer)
{
    int* position = new int[2];
    position[0] = to_file(answer[0]);
    position[1] = to_rank(answer[1]);
    return position;
}
예제 #3
0
/*
 * Move the workspace marker.  If we are in split-screen mode, also adjust the
 * length of the current viewport.  Finally, re-display the screen.
 */
void
markset(RING * gbl, unsigned num)
{
    unsigned lo = (vue->base_row + MINLIST * (maxview - curview));
    unsigned hi = (unsigned) (LINES - MINWORK);

    if (num < lo)
	num = lo;

    if (curview < (maxview - 1)) {	/* not the last viewport */
	unsigned next_W = viewlist[curview + 1].base_row;
	if (num > hi) {		/* multiple-adjust */
	    mark_W = (int) hi;
	    next_W += (num - hi);
	    if (curview < (maxview - 2))
		hi = viewlist[curview + 2].base_row;
	    hi -= MINLIST;
	    if (next_W > hi)
		next_W = hi;
	} else if (vue->base_row + MINLIST
		   <= (hi = next_W + (num - (unsigned) mark_W))) {
	    next_W = hi;
	    mark_W = (int) num;
	}
	viewlist[curview + 1].base_row = next_W;
    } else {			/* in the last viewport */
	if (num > hi)
	    num = hi;
	mark_W = (int) num;
    }

    (void) to_file(gbl);
    showFILES(gbl, FALSE);
}
예제 #4
0
void
scroll_to_file(RING * gbl, unsigned inx)
{
    if (gbl->curfile != inx) {
	gbl->curfile = inx;
	if (to_file(gbl))
	    showFILES(gbl, FALSE);
	else
	    showC(gbl);
    }
}
예제 #5
0
파일: Zobrist.cpp 프로젝트: Kikirrus/DON
    // Hash key of the FEN
    Key Zob::compute_fen_key (const string &fen, bool c960) const
    {
        if (fen.empty ()) return U64 (0);
        Key fen_key = U64 (0);
        File king[CLR_NO] = {F_NO};

        istringstream sfen (fen);
        uint8_t ch;

        sfen >> noskipws;

        uint32_t idx;
        Square s = SQ_A8;
        while ((sfen >> ch) && !isspace (ch))
        {
            if (isdigit (ch))
            {
                s += Delta (ch - '0'); // Advance the given number of files
            }
            else if (isalpha (ch) && (idx = CharPiece.find (ch)) != string::npos)
            {
                Piece p = Piece (idx);
                fen_key ^= _.psq_k[_color (p)][_ptype (p)][s];
                ++s;
            }
            else if (ch == '/')
            {
                s += DEL_SS;
            }
        }

        sfen >> ch;
        if ('w' == ch) fen_key ^= _.mover_side;

        sfen >> ch;
        if (c960)
        {
            while ((sfen >> ch) && !isspace (ch))
            {
                Color c = isupper (ch) ? WHITE : BLACK;
                uint8_t sym = tolower (ch);
                if ('a' <= sym && sym <= 'h')
                {
                    fen_key ^= _.castle_right[c][(king[c] < to_file (sym)) ? CS_K : CS_Q];
                }
                else
                {
                    return U64 (0);
                }
            }
        }
        else
        {
            while ((sfen >> ch) && !isspace (ch))
예제 #6
0
void test_help(void)
{
	char	tmp[PATH_MAX];
        struct stat st;
        int     i,r;

	for(i=0;pre_mcmd[i].name;i++)
	{
		sprintf(tmp,"../help/%s",pre_mcmd[i].name);
		r = stat(tmp,&st);

		if (r == -1 && errno == ENOENT)
			to_file(1,"help for %s is missing\n",pre_mcmd[i].name);
	}
	exit(0);
}
예제 #7
0
void make_usercombo(void)
{
	usercombo combo;
	int	fd;

	unlink("usercombo.h");
	fd = open("usercombo.h",O_WRONLY|O_CREAT|O_TRUNC,0644);

	to_file(fd,"/""* This file is automatically generated from gencmd.c *""/\n");

#ifdef BOTNET
	combo.comboflags = 0; combo.x.noshare = 1;
	to_file(fd,"#define COMBO_NOSHARE\t0x%x\n",combo.comboflags);
	combo.comboflags = 0; combo.x.readonly = 1;
	to_file(fd,"#define COMBO_READONLY\t0x%x\n",combo.comboflags);
#endif /* BOTNET */

#ifdef GREET
	combo.comboflags = 0; combo.x.greetfile = 1;
	to_file(fd,"#define COMBO_GREETFILE\t0x%x\n",combo.comboflags);
	combo.comboflags = 0; combo.x.randline = 1;
	to_file(fd,"#define COMBO_RANDLINE\t0x%x\n",combo.comboflags);
#endif /* GREET */

#ifdef BOUNCE
	combo.comboflags = 0; combo.x.bounce = 1;
	to_file(fd,"#define COMBO_BOUNCE\t0x%x\n",combo.comboflags);
#endif /* BOUNCE */

	combo.comboflags = 0; combo.x.echo = 1;
	to_file(fd,"#define COMBO_ECHO\t0x%x\n",combo.comboflags);
	combo.comboflags = 0; combo.x.aop = 1;
	to_file(fd,"#define COMBO_AOP\t0x%x\n",combo.comboflags);
	combo.comboflags = 0; combo.x.avoice = 1;
	to_file(fd,"#define COMBO_AVOICE\t0x%x\n",combo.comboflags);

	close(fd);
	exit(0);
}
예제 #8
0
/**
 * Initialise a modified tuple of sampler elements.
 *
 * @param init_size the size the sampler is initialised with
 * @param max_round_interval maximum time a round takes
 * @return a handle to a sampler that consists of sampler elements.
 */
struct RPS_Sampler *
RPS_sampler_mod_init (size_t init_size,
                      struct GNUNET_TIME_Relative max_round_interval)
{
  struct RPS_Sampler *sampler;

  sampler = RPS_sampler_init (init_size, max_round_interval);
  sampler->get_peers = sampler_mod_get_rand_peer;

  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Initialised modified sampler %s\n",
       sampler->file_name);
  to_file (sampler->file_name,
           "This is a modified sampler");

  return sampler;
}
예제 #9
0
/**
 * A fuction to update every sampler in the given list
 *
 * @param sampler the sampler to update.
 * @param id the PeerID that is put in the sampler
 */
  void
RPS_sampler_update (struct RPS_Sampler *sampler,
                    const struct GNUNET_PeerIdentity *id)
{
  uint32_t i;

  to_file (sampler->file_name,
           "Got %s",
           GNUNET_i2s_full (id));

  for (i = 0 ; i < sampler->sampler_size ; i++)
  {
    RPS_sampler_elem_next (sampler->sampler_elements[i],
                           id);
  }

}
예제 #10
0
/**
 * Reinitialise all previously initialised sampler elements with the given value.
 *
 * Used to get rid of a PeerID.
 *
 * @param sampler the sampler to reinitialise a sampler element in.
 * @param id the id of the sampler elements to update.
 */
  void
RPS_sampler_reinitialise_by_value (struct RPS_Sampler *sampler,
                                   const struct GNUNET_PeerIdentity *id)
{
  uint32_t i;
  struct RPS_SamplerElement *trash_entry;

  for ( i = 0 ; i < sampler->sampler_size ; i++ )
  {
    if ( 0 == GNUNET_CRYPTO_cmp_peer_identity(id, &(sampler->sampler_elements[i]->peer_id)) )
    {
      LOG (GNUNET_ERROR_TYPE_DEBUG, "Reinitialising sampler\n");
      trash_entry = GNUNET_new (struct RPS_SamplerElement);
      *trash_entry = *(sampler->sampler_elements[i]);
      to_file (trash_entry->file_name,
               "--- non-active");
      RPS_sampler_elem_reinit (sampler->sampler_elements[i]);
    }
  }
예제 #11
0
int write_seenlist(void)
{
	Seen	*seen;
	int	f;
#ifdef DEBUG
	int	dodeb;
#endif /* DEBUG */

	if (!seenfile)
		return(FALSE);
	if ((f = open(seenfile,O_WRONLY|O_CREAT|O_TRUNC,NEWFILEMODE)) < 0)
		return(FALSE);

#ifdef DEBUG
	dodeb = dodebug;
	dodebug = FALSE;
#endif /* DEBUG */

	for(seen=seenlist;seen;seen=seen->next)
	{
		if ((seen->when - now) > (86400 * SEEN_TIME))
			continue;
		else
		{
			if (seen->t != 0)
			{
				to_file(f,"%s %s %lu %i %s %s\n",
					seen->nick,seen->userhost,
					seen->when,seen->t,
					(seen->pa) ? seen->pa : "",
					(seen->pb) ? seen->pb : "");
			}
		}
	}
	close(f);

#ifdef DEBUG
	dodebug = dodeb;
#endif /* DEBUG */
	return(TRUE);
}
예제 #12
0
bool
FileSystem::rename( string from, string to )
{
    win32::Utf8ToFilename from_file(from);
    win32::Utf8ToFilename to_file(to);

    if (!from_file.IsUTF16Valid() || !to_file.IsUTF16Valid())
    {
        return true;
    }

    if (!::MoveFileExW( from_file, to_file,
                        MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ) )
    {
        log.errorf("%s: MoveFileExW(%s,%s) failed (%d)",__FUNCTION__,from_file.utf8.c_str(),to_file.utf8.c_str(),
                   GetLastError());
        return true;
    }

    return false;
}
예제 #13
0
void run_copy(apr_pool_t *pool,
              const char *from_file_path, const char *to_file_path)
{
    volatile double start_time;
    volatile double end_time;
    apr_mmap_t *from_file_map;
    const char *from_file_data;
    apr_size_t write_size;
    apr_size_t remain_size;

    show_test_name("copy");

    File from_file(pool, from_file_path);
    from_file.open(APR_READ|APR_BINARY);
    from_file_map = from_file.mmap();

    File to_file(pool, to_file_path);
    to_file.open(APR_CREATE|APR_TRUNCATE|APR_READ|APR_WRITE|APR_BINARY);
    MmapFileWriter to_file_writer(pool, to_file.get_handle());

    remain_size = static_cast<apr_size_t>(from_file.get_size()); // 4G の壁
    from_file_data = AS_CONST_CHAR(from_file_map->mm);
    start_time = get_usage_sec();
    while (remain_size > 0) {
        write_size = (remain_size > BUFFER_SIZE) ? BUFFER_SIZE : remain_size;

        to_file_writer.write(from_file_data, write_size);

        from_file_data += write_size;
        remain_size -= write_size;
    }
    to_file_writer.close();
    end_time = get_usage_sec();

    if (diff(pool, from_file_path, to_file_path) != 0) {
        THROW(MESSAGE_FILE_DIFFER);
    }

    show_item("copy", (end_time - start_time)*1000, " msec");
}
예제 #14
0
void datestamp(void)
{
	char	str[100],*th;
	struct tm *t;
	time_t	now;

	time(&now);
	t = localtime(&now);

	switch(t->tm_mday)
	{
	case 31:
	case 21:
	case 1:th="st";break;
	case 22:
	case 2:th="nd";break;
	case 23:
	case 3:th="rd";break;
	default:th="th";
	}
	to_file(1,"\"%s %i%s, %i at %i:%02i%s\"",month[t->tm_mon],t->tm_mday,th,
		t->tm_year + 1900,hourampm[t->tm_hour],t->tm_min,(t->tm_hour <= 11) ? "am" : "pm");
}
예제 #15
0
파일: b19.cpp 프로젝트: avjgit/notes3
int* request_position()
{
    int* position = new int[2];

    position[0] = -1; // filling with incorrect data to start loop
    position[1] = -1;

    string answer;

    while (!is_on_board(position))
    {
        print("Enter knight's position, from a1 to h8: ");
        cin >> answer;
        position[0] = to_file(answer[0]);
        position[1] = to_rank(answer[1]);

        if (!is_on_board(position))
        {
            print("You have entered incorrect data.");
        }
    }
    return position;
}
예제 #16
0
void Base::create_backup(const char* file_name)
{
	ifstream from_file;

	from_file.open(file_name, ios::in);
	const char* suffix =".bak";
	char file_bak[130] ="";
	strcat(file_bak, file_name);
	strcat(file_bak, suffix);
	ofstream to_file(file_bak, ios::out | ios::trunc);

	string temp;

	cout << "Creating backup file" << endl;
	while(!from_file.eof())
	{
		getline(from_file, temp);
		to_file << temp << endl;
	}
	to_file.flush();
	to_file.close();
	from_file.close();
	cout << "BackUp file Created." << endl;
}
예제 #17
0
void stats_loghour(Chan *chan, char *filename, int hour)
{
	ChanStats *stats;
	time_t	when;
	int	fd;

	if (!(stats = chan->stats))
		return;

	when = (now - (now % 3600));

	if ((fd = open(filename,O_WRONLY|O_APPEND|O_CREAT,NEWFILEMODE)) >= 0)
	{
		stats->userseconds += stats->users * (when - stats->lastuser);
		to_file(fd,"H %s %i %i %i %i\n",chan->name,hour,
			(stats->flags & CSTAT_PARTIAL) ? -stats->userseconds : stats->userseconds,
			stats->userpeak,stats->userlow);
		close(fd);
	}
	stats->LHuserseconds = stats->userseconds;
	stats->userseconds = 0;
	stats->lastuser = when;
	stats->flags = 0;
}
예제 #18
0
Word File::read(Uint8* dst, Word bytes) {
  auto result = ::fread(dst, 1, bytes, to_file(m_handle));
  return result;
}
    /** Runs the precision/recall test.
     * May log errors and even end the application in case of severe error.
     * @param params The program options.
     */
    void eval_precision_recall( const program_options& params) {

        LOG(info) << "Loading class membership mappings...";
        Vec1UInt membership_mappings;
        Vec1str cluster_files;
    
        exit_if_false( from_file( params.membership_mappings_file, membership_mappings), RETURN_CODE::IO_ERROR);
        exit_if_false( from_file( params.cluster_file_paths_file,  cluster_files),       RETURN_CODE::IO_ERROR);

        const uint n_features = static_cast<uint>(membership_mappings.size());
        const uint n_clusters = static_cast<uint>(cluster_files.size());

        LOG(info) << "# features: " << n_features;
        LOG(info) << "# clusters: " << n_clusters;


        LOG( info) << "calculating precision / recall ...";

        // find best class for each cluster
        vector<cluster_info_t> class_mapping;

        for( uint i=0; i<n_clusters; ++i) {

            Vec1str current_cluster_image_paths;
            Vec1str current_cluster_real_image_classes;
            std::map<string, uint> class_votes;
            from_file( cluster_files[i], current_cluster_image_paths);
        

            for( auto it=current_cluster_image_paths.begin(); it!=current_cluster_image_paths.end(); ++it) {
            
                const string class_name = bfs::path(*it).parent_path().filename().string();

                current_cluster_real_image_classes.push_back( class_name); 

                const auto map_it = class_votes.find( class_name);
                if( map_it == class_votes.end())
                    class_votes[class_name] = 1;
                else
                    map_it->second += 1;
            }
            
            const auto max_it = std::max_element( class_votes.begin(), 
                                                  class_votes.end(), 
                                                  []( const std::pair<string, int>& p, const std::pair<string, int>& q) { 
                                                      return p.second < q.second; 
                                                  });
            
            if( max_it == class_votes.end()) {
                // ***cluster empty *** (yes, that can happen!)
                continue;
            }

            const string assigned_class( max_it->first);

            const uint n_retrieved_images( static_cast<uint>(current_cluster_image_paths.size()));
            uint false_positives(0);
            uint true_positives(0);
            uint false_negatives(0);

            // find true positives, false positives
            for( auto it=current_cluster_real_image_classes.begin(); it!=current_cluster_real_image_classes.end(); ++it) {
                const string& real_class = *it;
                if( assigned_class.compare( real_class) == 0) {
                    ++true_positives;
                } else {
                    ++false_positives;
                }
            }
            // false negatives
            std::stringstream folder_name;
            folder_name << params.image_db_directory << '/' << assigned_class;
            bfs::path folder_path( folder_name.str());
            assert( bfs::exists( folder_path) && "the directory must exist.");

        
            uint n_relevant_images(0);
            for( bfs::directory_iterator it(folder_path); it!=bfs::directory_iterator(); ++it) {
                bfs::path p(*it);
                p.make_preferred();
                
                if( !p.has_extension() || !is_image_filetype_supported( p.extension().string()))
                    continue;

                ++n_relevant_images;
            
                Vec1str::iterator pos = std::find( current_cluster_image_paths.begin(), current_cluster_image_paths.end(), p.string());
                if( pos == current_cluster_image_paths.end())
                    ++false_negatives;
            }
            assert( true_positives + false_negatives == n_relevant_images && "number of relevant images must be identical to the number of true positivies and false positives");

            // *** found true positivies, false positives, false negatives for cluster i ***
            // calc precision/recall for each class
            const real precision = static_cast<real>(true_positives) / n_retrieved_images;
            const real recall    = static_cast<real>(true_positives) / n_relevant_images;

            class_mapping.push_back( cluster_info_t( assigned_class, true_positives, false_positives, false_negatives, precision, recall));
        }

        real avg_true_positives(0);
        real avg_false_positives(0);
        real avg_false_negatives(0);
        real avg_precision(0);
        real avg_recall(0);

        LOG( info) << "<class name> <true positives> <false positives> <false negatives> <precision> <recall>";
        for( uint i=0; i<class_mapping.size(); ++i) {
            const cluster_info_t& ci = class_mapping[i];
            const string& cluster_name   = std::get<0>(ci);
            const uint true_positives    = std::get<1>(ci);
            const uint false_positives   = std::get<2>(ci);
            const uint false_negatives   = std::get<3>(ci);
            const real precision         = std::get<4>(ci);
            const real recall            = std::get<5>(ci);

            avg_true_positives  += true_positives;
            avg_false_positives += false_positives;
            avg_false_negatives += false_negatives;
            avg_precision       += precision;
            avg_recall          += recall;

            LOG(info) << cluster_name << " " << true_positives << " " << false_positives << " " << false_negatives << " " << precision << " " << recall;
        }

        avg_true_positives  /= class_mapping.size();
        avg_false_positives /= class_mapping.size();
        avg_false_negatives /= class_mapping.size();
        avg_precision       /= class_mapping.size();
        avg_recall          /= class_mapping.size();

        LOG(info) << "Average: <true positives> <false positives> <false negatives> <precision> <recall>";
        LOG(info) << avg_true_positives << " " << avg_false_positives << " " << avg_false_negatives << " " << avg_precision << " " << avg_recall;


        LOG(info) << "Writing stats to file \"" << params.precision_recall_file << "\"...";
        to_file( params.precision_recall_file, class_mapping);

    }
int main ()
{
   int file_size , padding = 0;
   HEADER bmp_header;
   INFO_HEADER bmp_info_header;
   COLOR_PALLET *bgr_pallete = malloc (sizeof( COLOR_PALLET ) * CHAR_RANGE);
   unsigned char *data_buffer , *out_buffer ;
   char *file_name ;
   FILE *in_file = NULL;

   file_name = get_file_name ();
   in_file =  fopen ( file_name , "rb" );
   if (in_file == NULL)
   {
      printf("file opening failed\n");
      return 1;
   }

   if ( fread ( &bmp_header , sizeof ( HEADER ) , 1 , in_file) < 1 )
   {
      printf("Some issue in reading file\n");
      return 0;
   }

   if ( fread ( &bmp_info_header , sizeof ( INFO_HEADER ) , 1 , in_file) < 1 )
   {
      printf("Some issue in reading file\n");
      return 1;
   }
   print_header( bmp_header , bmp_info_header );
   //checking if the image is bmp or not
   if ( bmp_header.signature != BMP_SIGNATURE )
   {
      printf("no a bmp\n");
      return 1;
   }

   if ( bmp_info_header.bits_per_pixel != RGB_SIZE )
   {
      printf("already in greysacle\n");
      return 1;
   }

   if ( fseek ( in_file , bmp_header.offset , SEEK_SET ) == -1 )
   {
      printf("file operation failed\n");
      return 1;
   }

   file_size = bmp_info_header.image_data_size ;
   //based on file_size allocate memory
   data_buffer = malloc (sizeof (char) * file_size + 1 );
   if (data_buffer == NULL)
   {
     printf("malloc Failed\n");
     return 1;
   }
   *(data_buffer  + file_size) = CHAR_NULL;
   //read the data into buffer
   if ( fread ( data_buffer , sizeof(char) , file_size , in_file ) < file_size )
   {
     printf("Some issue in reading file\n");
     fclose (in_file);
     free (data_buffer);
     return 1;
   }

   if ( fclose ( in_file ) == 0  )
   {
      printf("File not closing\n" );
   }

   out_buffer = covert_to_mono ( data_buffer , file_size , bmp_info_header);

   if ( ( bmp_info_header.image_width * 3 ) % 4 != 0)
   padding = 4 - ( ( bmp_info_header.image_width * 3 ) % 4 );

   //change the header details
   bmp_header.offset = COLOR_PALLET_SIZE + HEADER_SIZE;
   bmp_header.bmp_file_size = HEADER_SIZE + ( bmp_info_header.image_width * bmp_info_header.image_height ) + ( padding * bmp_info_header.image_height ) + COLOR_PALLET_SIZE;
   bmp_info_header.bits_per_pixel = 8;
   bmp_info_header.image_data_size =( bmp_info_header.image_width * bmp_info_header.image_height ) + ( padding * bmp_info_header.image_height );

   print_header( bmp_header , bmp_info_header );

   //get bgr pallete
   get_color_pallet ( bgr_pallete );

   to_file (out_buffer, bmp_header , bmp_info_header , bgr_pallete , bmp_info_header.image_data_size) ;


   free (data_buffer);
   data_buffer = NULL;
   free ( out_buffer );
   out_buffer = NULL;
   free (bgr_pallete);
   bgr_pallete = NULL;

   return 0;
}
예제 #21
0
void make_mcmd(void)
{
	const char *pt;
	char	tmp[100],*tabs;
	int	i,j,wh,pass,ct,sl,fd;
	OnMsg	v;

	unlink("mcmd.h");
	fd = open("mcmd.h",O_WRONLY|O_CREAT|O_TRUNC,0644);

	pass = __define_strng;
	ct = 0;

	to_file(fd,"/""* This file is automatically generated from gencmd.c *""/\n");
	to_file(fd,"#ifndef TEST\n#ifndef MCMD_H\n#define MCMD_H 1\n\n");

	while(pass)
	{
		if (pass == __struct_print)
		{
			to_file(fd,"LS const OnMsg mcmd[] =\n{\n");
		}
		if (pass == __struct_acces)
		{
			to_file(fd,"LS OnMsg_access acmd[] =\n{\n");
		}
		for(i=0;pre_mcmd[i].name;i++)
		{
			pt = 0;
			wh = 0;
			for(j=0;pre_mcmd[j].name;j++)
			{
				if (pre_mcmd[j].pass != pass)
				{
					pt = pre_mcmd[j].name;
					wh = j;
					break;
				}
			}
			for(j=0;pre_mcmd[j].name;j++)
			{
				if ((pre_mcmd[j].pass != pass) && (strcmp(pt,pre_mcmd[j].name) > 0))
				{
					pt = pre_mcmd[j].name;
					wh = j;
				}
			}
			if (pass == __define_strng)
			{
				//to_file(fd,"#define S_%s%s\t\"%s\"\n",pt,((strlen(pt) + 2) < 8) ? "\t" : "",pt);
			}
			if (pass == __define_print)
			{
				//to_file(fd,"#define C_%s%s\tmcmd[%i].name\n",pt,((strlen(pt) + 2) < 8) ? "\t" : "",ct);
				to_file(fd,"BEG const char C_%s[]%s\tMDEF(\"%s\");\n",pt,((strlen(pt) + 3) < 8) ? "\t" : "",pt);
				ct++;
			}
			if (pass == __struct_acces)
			{
				to_file(fd,"\t%i,\t/""* %s *""/\n",
					pre_mcmd[wh].flags & CLEVEL,
					pt);
			}
			if (pass == __struct_print)
			{
				memset(&v,0,sizeof(v));

				v.defaultaccess = pre_mcmd[wh].flags & CLEVEL;
				/* + defaultaccess */
				v.dcc    = (pre_mcmd[wh].flags & DCC)    ? 1 : 0;
				v.cc     = (pre_mcmd[wh].flags & CC)     ? 1 : 0;
				v.pass   = (pre_mcmd[wh].flags & PASS)   ? 1 : 0;
				v.args   = (pre_mcmd[wh].flags & CARGS)  ? 1 : 0;
				v.nopub  = (pre_mcmd[wh].flags & NOPUB)  ? 1 : 0;
				v.nocmd  = (pre_mcmd[wh].flags & NOCMD)  ? 1 : 0;
				v.gaxs   = (pre_mcmd[wh].flags & GAXS)   ? 1 : 0;
				v.caxs   = (pre_mcmd[wh].flags & CAXS)   ? 1 : 0;
				v.redir  = (pre_mcmd[wh].flags & REDIR)  ? 1 : 0;
				v.lbuf   = (pre_mcmd[wh].flags & LBUF)   ? 1 : 0;
				v.cbang  = (pre_mcmd[wh].flags & CBANG)  ? 1 : 0;
				v.acchan = (pre_mcmd[wh].flags & ACCHAN) ? 1 : 0;
				v.supres = (pre_mcmd[wh].flags & SUPRES) ? 1 : 0;

				sprintf(tmp,"%3i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i,%2i",
					v.defaultaccess,
					v.dcc,
					v.cc,
					v.pass,
					v.args,
					v.nopub,
					v.nocmd,
					v.gaxs,
					v.caxs,
					v.redir,
					v.lbuf,
					v.cbang,
					v.acchan,
					v.supres
					);

				sl = strlen(pre_mcmd[wh].func) + 1;
				tabs = "\t\t\t";

				sl = (sl & ~7) / 8;
				tabs += sl;

				to_file(fd,(pre_mcmd[wh].cmdarg) ? "{ C_%s,%s\t%s,%s%s\t, \"%s\"\t},\n" : "{ C_%s,%s\t%s,%s%s\t},\n",
					pt,
					((strlen(pt) + 5) < 8) ? "\t" : "",
					pre_mcmd[wh].func,
					tabs,
					tmp,
					pre_mcmd[wh].cmdarg
				);
			}
			pre_mcmd[wh].pass = pass;
		}
		if (pass == __define_strng)
		{
			/* nothing */
		}
		if (pass == __define_print)
		{
			to_file(fd,"\n#ifdef MAIN_C\n\n");
		}
		if (pass == __struct_print)
		{
			to_file(fd,"{ NULL, }};\n\n");
		}
		if (pass == __struct_acces)
		{
			to_file(fd,"};\n\n");
		}
		pass--;
	}
	to_file(fd,"#define LOCALHOST_ULONG %lu\n",inet_addr("127.1"));
	to_file(fd,"#else /""* MAIN_C *""/\n\n");
	to_file(fd,"extern OnMsg mcmd[];\n");
	to_file(fd,"extern OnMsg_access acmd[];\n\n");
	to_file(fd,"#endif /""* MAIN_C *""/\n\n");
	to_file(fd,"#endif /""* MCMD_H *""/\n\n");
	to_file(fd,"#endif /""* TEST *""/\n\n");
	close(fd);
	exit(0);
}
예제 #22
0
파일: Zobrist.cpp 프로젝트: Kikirrus/DON
    // Hash key of the FEN
    Key Zob::compute_fen_key (const   char *fen, bool c960) const
    {
        if (!fen)   return U64 (0);

        Key fen_key = U64 (0);
        File king[CLR_NO] = {F_NO};

#undef skip_whitespace
#undef get_next

#define skip_whitespace()  while (isspace (unsigned char (*fen))) ++fen
#define get_next()         ch = unsigned char (*fen++)

        unsigned char ch;
        for (Rank r = R_8; r >= R_1; --r)
        {
            File f = F_A;
            while (f <= F_H)
            {
                ch = *fen++;
                if (!ch) return U64 (0);

                if      (isdigit (ch))
                {
                    // empty square(s)
                    if ('1' > ch || ch > '8') return U64 (0);

                    uint8_t empty = (ch - '0');
                    f += empty;

                    if (f > F_NO) return U64 (0);
                }
                else if (isalpha (ch))
                {
                    uint32_t idx = CharPiece.find (ch);
                    if (idx != string::npos)
                    {
                        Piece p = Piece (idx);
                        if (EMPTY == p) return U64 (0);
                        if (KING == _ptype (p))  king[_color (p)] = f;

                        fen_key ^= _.psq_k[_color (p)][_ptype (p)][(f | r)];
                    }
                    ++f;
                }
                else
                {
                    return U64 (0);
                }
            }
            if (r > R_1)
            {
                ch = *fen++;
                if ('/' != ch) return U64 (0);
            }
        }
        skip_whitespace ();
        char active = get_next ();
        if ('w' == active) fen_key ^= _.mover_side;

        skip_whitespace ();
        // 3. Castling availability
        // Compatible with 3 standards:
        // * Normal FEN standard,
        // * Shredder-FEN that uses the letters of the columns on which the rooks began the game instead of KQkq
        // * X-FEN standard that, in case of Chess960, if an inner rook is associated with the castling right, the castling
        // tag is replaced by the file letter of the involved rook, as for the Shredder-FEN.
        get_next ();
        if ('-' != ch)
        {
            if (c960)
            {
                do
                {
                    Color c = isupper (ch) ? WHITE : BLACK;
                    char sym = tolower (ch);
                    if ('a' <= sym && sym <= 'h')
                    {
                        fen_key ^= _.castle_right[c][(king[c] < to_file (sym)) ? CS_K : CS_Q];
                    }
                    else
                    {
                        return U64 (0);
                    }

                    get_next ();
                }
                while (ch && !isspace (ch));
            }
            else
            {
                do
                {
                    //switch (ch)
                    //{
                    //case 'K': fen_key ^= _.castle_right[WHITE][CS_K]; break;
                    //case 'Q': fen_key ^= _.castle_right[WHITE][CS_Q]; break;
                    //case 'k': fen_key ^= _.castle_right[BLACK][CS_K]; break;
                    //case 'q': fen_key ^= _.castle_right[BLACK][CS_Q]; break;
                    //default:  return U64(0); break;
                    //}

                    Color c = isupper (ch) ? WHITE : BLACK;
                    switch (toupper (ch))
                    {
                    case 'K': fen_key ^= _.castle_right[c][CS_K]; break;
                    case 'Q': fen_key ^= _.castle_right[c][CS_Q]; break;
                    default:  return U64 (0); break;
                    }

                    get_next ();
                }
                while (ch && !isspace (ch));
            }
        }

        skip_whitespace ();
        get_next ();
        if ('-' != ch)
        {
            unsigned char ep_f = tolower (ch);
            if (!isalpha (ep_f)) return U64 (0);
            if ('a' > ep_f || ep_f > 'h') return U64 (0);

            unsigned char ep_r = get_next ();
            if (!isdigit (ep_r)) return U64 (0);
            if (('w' == active && '6' != ep_r) ||
                ('b' == active && '3' != ep_r)) return U64 (0);

            fen_key ^= _.en_passant[to_file (ep_f)];
        }

#undef skip_whitespace
#undef get_next

        return fen_key;
    }
예제 #23
0
파일: spy.c 프로젝트: MadCamel/energymech
void send_spy(const char *src, const char *format, ...)
{
	Chan	*chan;
	Mech	*backup;
	Spy	*spy;
	va_list	msg;
	const char *tempsrc;
	char	tempdata[MAXLEN];
	int	fd;
	int	printed = FALSE;

	tempsrc = (src == SPYSTR_STATUS) ? time2medium(now) : src;

#ifdef DEBUG
	debug("(send_spy) src %s format = '%s'\n",src,format);
#endif /* DEBUG */

	for(spy=current->spylist;spy;spy=spy->next)
	{
		if ((*src == '#' || *src == '*') && spy->t_src == SPY_CHANNEL)
		{
			if ((*src != '*') && stringcasecmp(spy->src,src))
				continue;
			if ((chan = find_channel_ac(spy->src)) == NULL)
				continue;
			if (find_chanuser(chan,CurrentNick) == NULL)
				continue;
			tempsrc = spy->src;
		}
		else
		/*
		 *  by using string constants we can compare addresses
		 */
		if (spy->src != src)
			continue;

		if (!printed)
		{
			printed = TRUE;
			va_start(msg,format);
			vsprintf(tempdata,format,msg);
			va_end(msg);
		}

		switch(spy->t_dest)
		{
		case SPY_DCC:
			to_file(spy->dcc->sock,"[%s] %s\n",tempsrc,tempdata);
			break;
		case SPY_CHANNEL:
			if (spy->destbot >= 0)
			{
				backup = current;
				for(current=botlist;current;current=current->next)
				{
					if (current->guid == spy->destbot)
					{
						to_server("PRIVMSG %s :[%s] %s\n",spy->dest,tempsrc,tempdata);
						break;
					}
				}
				current = backup;
			}
			else
			{
				to_user(spy->dest,"[%s] %s",tempsrc,tempdata);
			}
			break;
		case SPY_FILE:
			if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0)
			{
				to_file(fd,"[%s] %s\n",logtime(now),tempdata);
				close(fd);
			}
		}
	}
}
예제 #24
0
/**
 * Grow or shrink the size of the sampler.
 *
 * @param sampler the sampler to resize.
 * @param new_size the new size of the sampler
 */
static void
sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
{
  unsigned int old_size;
  uint32_t i;

  // TODO check min and max size

  old_size = sampler->sampler_size;

  if (old_size > new_size)
  { /* Shrinking */

    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Shrinking sampler %d -> %d\n",
         old_size,
         new_size);

    to_file (sampler->file_name,
         "Shrinking sampler %d -> %d",
         old_size,
         new_size);

    for (i = new_size ; i < old_size ; i++)
    {
      to_file (sampler->file_name,
               "-%" PRIu32 ": %s",
               i,
               sampler->sampler_elements[i]->file_name);
    }

    GNUNET_array_grow (sampler->sampler_elements,
                       sampler->sampler_size,
                       new_size);
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "sampler->sampler_elements now points to %p\n",
         sampler->sampler_elements);

  }
  else if (old_size < new_size)
  { /* Growing */
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Growing sampler %d -> %d\n",
         old_size,
         new_size);

    to_file (sampler->file_name,
         "Growing sampler %d -> %d",
         old_size,
         new_size);

    GNUNET_array_grow (sampler->sampler_elements,
        sampler->sampler_size,
        new_size);

    for (i = old_size ; i < new_size ; i++)
    { /* Add new sampler elements */
      sampler->sampler_elements[i] = RPS_sampler_elem_create ();

      to_file (sampler->file_name,
               "+%" PRIu32 ": %s",
               i,
               sampler->sampler_elements[i]->file_name);
    }
  }
  else
  {
    LOG (GNUNET_ERROR_TYPE_DEBUG, "Size remains the same -- nothing to do\n");
    return;
  }

  GNUNET_assert (sampler->sampler_size == new_size);
}