Ejemplo n.º 1
0
void indri::file::Path::remove( const std::string& path ) {
  std::stack<indri::file::DirectoryIterator*> iterators;
  indri::utility::StackDeleter<indri::file::DirectoryIterator> sd( iterators );
  iterators.push( new indri::file::DirectoryIterator( path ) );

  while( iterators.size() ) {
    indri::file::DirectoryIterator* top = iterators.top();
    
    // all done, so go up a level
    if( (*top) == indri::file::DirectoryIterator::end() ) {
      // release any search handles that may point
      // to this directory
      top->close();

      int result = rmdir( top->base().c_str() );
      if( result != 0 )
        LEMUR_THROW( LEMUR_IO_ERROR, "indri::file::Path::remove couldn't remove directory '" + top->base() + "'." );

      delete top;
      iterators.pop();
      continue;
    }

    std::string path = **top;
    (*top)++;

    if( indri::file::Path::isFile( path ) ) {
      int result = lemur_compat::remove( path.c_str() );
      if( result != 0 )
        LEMUR_THROW( LEMUR_IO_ERROR, "indri::file::Path::remove couldn't remove file '" + path + "'." );
    } else {
      iterators.push( new indri::file::DirectoryIterator( path ) );
    }
  }
}
Ejemplo n.º 2
0
void STATS::short_print(            //print stats table
                        FILE *,     //Now uses tprintf instead
                        BOOL8 dump  //dump full table
                       ) {
  inT32 index;                   //table index
  inT32 min = min_bucket ();
  inT32 max = max_bucket ();

  if (buckets == NULL) {
    /*     err.log(RESULT_LOGICAL_ERROR,E_LOC,ERR_PRIMITIVES,
       ERR_SCROLLING,ERR_CONTINUE,ERR_ERROR,
       "Empty stats"); */
    return;
  }
  if (dump) {
    for (index = min; index <= max; index++) {
      tprintf ("%4d:%-3d ", rangemin + index, buckets[index]);
      if ((index - min) % 8 == 7)
        tprintf ("\n");
    }
    tprintf ("\n");
  }

  tprintf ("Total count=%d\n", total_count);
  tprintf ("Min=%d Really=%d\n", (inT32) (ile ((float) 0.0)), min);
  tprintf ("Max=%d Really=%d\n", (inT32) (ile ((float) 1.1)), max);
  tprintf ("Range=%d\n", max + 1 - min);
  tprintf ("Lower quartile=%.2f\n", ile ((float) 0.25));
  tprintf ("Median=%.2f\n", ile ((float) 0.5));
  tprintf ("Upper quartile=%.2f\n", ile ((float) 0.75));
  tprintf ("Mean= %.2f\n", mean ());
  tprintf ("SD= %.2f\n", sd ());
}
ServiceDescription ServiceDiscovery::getServiceDescription(const std::string& name)
{
        bool found = false;
        ServiceDescription sd("");
        {
            boost::unique_lock<boost::mutex> lock(mServicesMutex);

            std::vector<ServiceDiscovery*>::iterator it;
            for(it = msServiceDiscoveries.begin(); it != msServiceDiscoveries.end(); it++)
            {
                try {
                    ServiceConfiguration conf = (*it)->getConfiguration();
                    if(conf.getName() == name)
                    {
                        sd = conf;
                        found = true;
                        break;
                    }
                } catch(...)
                {
                    // ignore errors
                }
            }
        }

        if(!found)
        {
            char buffer[512];
            snprintf(buffer, 512, "Could not find service: %s\n", name.c_str());
            throw std::runtime_error(std::string(buffer));
        }

        return sd;
}
Ejemplo n.º 4
0
void ListaCursor::newCursor(int valor)
{
    int temp = sd();
    disponibles[temp] = disponibles[0];
    bdd[disponibles[0]].numero = valor;
    disponibles[0] = bdd[disponibles[0]].next;
    bdd[disponibles[temp]].next = -1;
}
Ejemplo n.º 5
0
void DisassemblerView::showSegments()
{
    SegmentsDialog sd(this->_listing, this);
    int res = sd.exec();

    if(res == SegmentsDialog::Accepted && sd.selectedSegment())
        ui->disassemblerWidget->jumpTo(sd.selectedSegment());
}
Ejemplo n.º 6
0
TEST(JsonTest, LoadInvalidKey)
{
    ScopedDevice sd(sample_invalid_key);

    ASSERT_EQ(sd.device, nullptr);
    ASSERT_EQ(sd.error.type, MB_DEVICE_JSON_UNKNOWN_KEY);
    ASSERT_STREQ(sd.error.context, ".foo");
}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
     QApplication app( argc, argv);
     app.setFont( QFont( "helvetica", 18));
     KDMShutdown sd( 0, 0,"Hej", "echo shutdown", "echo restart");
     app.setMainWidget( &sd);
     return sd.exec();
}
Ejemplo n.º 8
0
void Background::draw() {
	ci::gl::clear(mSettings.mBackgroundColor);
	if (mTexture) {
		ci::gl::color(1, 1, 1, 1);
		ci::gl::ScopedTextureBind	ts(mTexture);
		ci::gl::ScopedDepth			sd(false);
		mBatch->draw();
	}
}
Ejemplo n.º 9
0
// o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o
void
BRTKernelDef::print(std::ostream& out, int) const
{
   char name[1024];

   if (Project::gDebug) {
      out << "/* BRTKernelDef:" ;
      location.printLocation(out) ;
      out << " */" << std::endl;
   }

   assert(FunctionName());
   assert(FunctionName()->entry);
   assert(FunctionName()->entry->scope);

   /* If the symbol for the generated assembly code already 
   ** exists, don't generate the assembly.  This allows the user
   ** to hand generate the code.
   */
   
#define PRINT_CODE(a,b) \
   sprintf (name, "__%s_%s", FunctionName()->name.c_str(), #b);      \
   if (!FunctionName()->entry->scope->Lookup(name)) {                \
      if (globals.target & TARGET_##a) {                             \
         BRTKernelCode *var;                                         \
            var = decl->isReduce() ? new BRT##a##ReduceCode(*this) : \
                                  new BRT##a##KernelCode(*this);     \
         out << *var << std::endl;                                   \
         delete var;                                                 \
      } else {                                                       \
         out << "static const char *__"                              \
             << *FunctionName() << "_" << #b << "= NULL;\n";         \
      }                                                              \
   }
 
   PRINT_CODE(PS20, ps20);
   PRINT_CODE(FP30, fp30);
   PRINT_CODE(ARB,  arb);
   PRINT_CODE(CPU,  cpu);
#undef PRINT_CODE

   /*
    * XXX I have no idea why this is here instead of in
    * BRTCPUKernel::print().  It's CPU only and needs to be suppressed when
    * the CPU target is suppressed.  --Jeremy.
    * The scatter functions need to be there whether or not the CPU target is repressed
    * For the fallback requirement --Daniel
    */
   if (decl->isReduce()) {
     BRTCPUReduceCode crc(*this);
     BRTScatterDef sd(*crc.fDef);
     sd.print(out,0); 
     // this is needed for CPU fallback for scatter whether or not CPU is enabled
   }

   printStub(out);
}
Ejemplo n.º 10
0
int main() {
	int t;long long int n;
	sd(t);
	while(t--) {
		scanf("%lld\n",&n);
		printf("%lld\n",(long long)((n * (( 3 * n) + 1)) / 2) % 1000007);
	}
	return 0;
}	
Ejemplo n.º 11
0
SaveStateDescriptor AdlMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
	Common::String fileName = Common::String::format("%s.s%02d", target, slot);
	Common::InSaveFile *inFile = g_system->getSavefileManager()->openForLoading(fileName);

	if (!inFile)
		return SaveStateDescriptor();

	if (inFile->readUint32BE() != MKTAG('A', 'D', 'L', ':')) {
		delete inFile;
		return SaveStateDescriptor();
	}

	byte saveVersion = inFile->readByte();
	if (saveVersion != SAVEGAME_VERSION) {
		delete inFile;
		return SaveStateDescriptor();
	}

	char name[SAVEGAME_NAME_LEN] = { };
	inFile->read(name, sizeof(name) - 1);
	inFile->readByte();

	if (inFile->eos() || inFile->err()) {
		delete inFile;
		return SaveStateDescriptor();
	}

	SaveStateDescriptor sd(slot, name);

	int year = inFile->readUint16BE();
	int month = inFile->readByte();
	int day = inFile->readByte();
	sd.setSaveDate(year + 1900, month + 1, day);

	int hour = inFile->readByte();
	int minutes = inFile->readByte();
	sd.setSaveTime(hour, minutes);

	uint32 playTime = inFile->readUint32BE();
	sd.setPlayTime(playTime);

	if (inFile->eos() || inFile->err()) {
		delete inFile;
		return SaveStateDescriptor();
	}

	Graphics::Surface *thumbnail;
	if (!Graphics::loadThumbnail(*inFile, thumbnail)) {
		delete inFile;
		return SaveStateDescriptor();
	}
	sd.setThumbnail(thumbnail);

	delete inFile;
	return sd;
}
Ejemplo n.º 12
0
QString SupportDialog::getHost( QWidget *parent )
{
	SupportDialog sd( parent );
	if( sd.exec() == Accepted )
	{
		return sd.ui->hostEdit->text();
	}

	return QString();
}
Ejemplo n.º 13
0
void MainApp::OnFatalException()
{
#ifndef __APPLE__
#ifndef _DEBUG
	SLADEStackTrace st;
	st.WalkFromException();
	SLADECrashDialog sd(st);
	sd.ShowModal();
#endif
#endif
}
Ejemplo n.º 14
0
str::seq LexicalAnnotation::lines(size_t i, size_t f) const {
  if (!this->bfptr) {
    return str::seq();
  } else if (this->bfptr->first) {
    std::ifstream fd(this->bfptr->second);
    return slurpLines(fd, i, f);
  } else {
    std::istringstream sd(this->bfptr->second);
    return slurpLines(sd, i, f);
  }
}
Ejemplo n.º 15
0
integer_t ScalarDialog::getScalar(QWidget *parent, const QString &title, const QString &description)
{
    ScalarDialog sd(parent);
    sd.setWindowTitle(title);
    sd.setDescription(description);

    if(sd.exec() == ScalarDialog::Accepted)
        return sd.value();

    return UINT64_MAX;
}
		void CreateServer()
		{
			if (m_Peer == NULL)
				Initialize();

			RakNet::SocketDescriptor sd(SERVER_PORT, 0);
			m_Peer->Startup(MAX_CLIENTS, &sd, 1);
			m_IsServer = true;

			m_Peer->SetMaximumIncomingConnections(MAX_CLIENTS);
		}
Ejemplo n.º 17
0
void RepoQuery::getStaticString(int iCol, StringData*& s) {
  if (isNull(iCol)) {
    s = nullptr;
  } else {
    const char* text;
    size_t size;
    getText(iCol, text, size);
    StackStringData sd(text, size, AttachLiteral);
    s = StringData::GetStaticString(&sd);
  }
}
Ejemplo n.º 18
0
 GaussianBartModel::GaussianBartModel(int number_of_trees,
                                      const Vector &y,
                                      const Matrix &x)
     : ParamPolicy(new UnivParams(sd(y))),
       BartModelBase(number_of_trees, mean(y))
 {
   for (int i = 0; i < y.size(); ++i) {
     NEW(RegressionData, dp)(y[i], x.row(i));
     add_data(dp);
   }
 }
Ejemplo n.º 19
0
int ThreadSharedVariant::getIndex(litstr key) {
  ASSERT(is(KindOfArray));
  if (getIsVector()) return -1;
  StringData sd(key);
  if (RuntimeOption::ApcUseGnuMap) {
    StringDataToIntMap::const_iterator it = m_data.gnuMap->strMap->find(&sd);
    if (it == m_data.gnuMap->strMap->end()) return -1;
    return it->second;
  }
  return m_data.map->indexOf(&sd);
}
Ejemplo n.º 20
0
void sd_thread(void const *argument) {
#if defined(TARGET_KL25Z)
    SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
#else
    SDFileSystem sd(p11, p12, p13, p14, "sd");
#endif
    FILE *f = fopen("/sd/out.txt", "w");

    // allocate buffers
    uint8_t data_written[SIZE];
    uint8_t data_read[SIZE];

    // fill data_written buffer with random data
    // write these data into the file
    printf("written: [");
    for (int i = 0; i < SIZE; i++) {
        data_written[i] = rand() % 0xff;
        fprintf(f, "%c", data_written[i]);
        printf("%d ", data_written[i]);
    }
    printf("]\r\nclosing\r\n");
    fclose(f);

    // read back the data from the file and store them in data_read
    f = fopen("/sd/out.txt", "r");
    printf("read: [");
    for (int i=0; i<SIZE; i++) {
        data_read[i] = fgetc(f);
        printf("%d ", data_read[i]);
    }
    printf("]\r\nclosing\r\n");
    fclose(f);

    // check that the data written == data read
    for (int i = 0; i < SIZE; i++) {
        if (data_written[i] != data_read[i]) {
            notify_completion(false);
        }
    }
    notify_completion(true);
}
Ejemplo n.º 21
0
int main(){
  int c, d, u, n;
  n = recebe();
  c = sc(n);
  d = sd(n);
  u = su(n);

  print(c);
  print(d);
  print(u);

}
Ejemplo n.º 22
0
gpointer
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
{
    va_list ap;

    va_start(ap, msg_format);
    SimpleDialog sd(wsApp->mainWindow(), type, btn_mask, msg_format, ap);
    va_end(ap);

    sd.exec();
    return NULL;
}
Ejemplo n.º 23
0
	/*
	 * Returns a scrambled string.
	 */
	STR scramble( STR str ) {
		std::seed_seq sd( str.begin(), str.end() );
		std::default_random_engine gen;

		for ( int i = str.size() - 1; i > 0; --i ) {
			gen.seed( sd );
			std::uniform_int_distribution<int> dist( 0, i );
			std::swap( str[i], str[dist( gen )] );
		}

		return str;
	}
intrusive_ref_ptr<DevFs> //return value is a pointer to DevFs
#else //WITH_DEVFS
void                     //return value is void
#endif //WITH_DEVFS
basicFilesystemSetup(intrusive_ref_ptr<Device> dev)
{
    bootlog("Mounting MountpointFs as / ... ");
    FilesystemManager& fsm=FilesystemManager::instance();
    intrusive_ref_ptr<FilesystemBase> rootFs(new MountpointFs);
    bootlog(fsm.kmount("/",rootFs)==0 ? "Ok\n" : "Failed\n");
    
    #ifdef WITH_DEVFS
    bootlog("Mounting DevFs as /dev ... ");
    StringPart sp("dev");
    int r1=rootFs->mkdir(sp,0755); 
    intrusive_ref_ptr<DevFs> devfs(new DevFs);
    int r2=fsm.kmount("/dev",devfs);
    bool devFsOk=(r1==0 && r2==0);
    bootlog(devFsOk ? "Ok\n" : "Failed\n");
    if(!devFsOk) return devfs;
    fsm.setDevFs(devfs);
    #endif //WITH_DEVFS
    
    bootlog("Mounting Fat32Fs as /sd ... ");
    bool fat32failed=false;
    intrusive_ref_ptr<FileBase> disk;
    #ifdef WITH_DEVFS
    if(dev) devfs->addDevice("sda",dev);
    StringPart sda("sda");
    if(devfs->open(disk,sda,O_RDWR,0)<0) fat32failed=true;
    #else //WITH_DEVFS
    if(dev && dev->open(disk,intrusive_ref_ptr<FilesystemBase>(0),O_RDWR,0)<0)
        fat32failed=true;
    #endif //WITH_DEVFS
    
    intrusive_ref_ptr<Fat32Fs> fat32;
    if(fat32failed==false)
    {
        fat32=new Fat32Fs(disk);
        if(fat32->mountFailed()) fat32failed=true;
    }
    if(fat32failed==false)
    {
        StringPart sd("sd");
        fat32failed=rootFs->mkdir(sd,0755)!=0;
        fat32failed=fsm.kmount("/sd",fat32)!=0;
    }
    bootlog(fat32failed==0 ? "Ok\n" : "Failed\n");
    
    #ifdef WITH_DEVFS
    return devfs;
    #endif //WITH_DEVFS
}
Ejemplo n.º 25
0
		bool FallenController::anyCollisionsWithRemainingLines(const ShapeCubes& cubes)
		{
			Shape shape(getTimingManager());		// TODO Strange usage of Shape class. Maybe it should be simplified
			shape.setCubes(cubes);
			ShapeDynamics sd(shape);

			lines.addAllRemainingToShapeDynamics(sd);

			sd.addObstacle(fallen);

			return sd.anyCollisions();
		}
Ejemplo n.º 26
0
mysocket* init_instance::get_outgoing_socket(int from , int to, int type) {

  sock_dscr sd(from, to, type);

  map<sock_dscr, mysocket*>::iterator i = out_sockets.find(sd);

  if (i == out_sockets.end()) {
    return NULL;
  } else {
    return (*i).second;
  }
}
Ejemplo n.º 27
0
void insert_tiles(char *filename)
{
  bFILE *fp=open_file(filename,"rb");
  if (!fp->open_failure())
  {
    int ft=0,bt=0;
    spec_directory sd(fp);
    delete fp;
    int i=0;
    for (; i<sd.total; i++)
    {
      spec_entry *se=sd.entries[i];
      if (se->type==SPEC_FORETILE)
        ft++;
      else if (se->type==SPEC_BACKTILE)
        bt++;
    }
    if (bt)
      printf("%s : adding %d background tiles (range %d-%d)\n",
         filename,bt,nbacktiles,nbacktiles+bt-1);
    if (ft)
      printf("%s : adding %d foreground tiles (range %d-%d)\n",
         filename,ft,nforetiles,nforetiles+bt-1);
    if (!ft && !bt)
      printf("Warning : file %s has no background or foreground tiles\n",filename);
    else
    {
      int fon=nforetiles,bon=nbacktiles;
      if (ft)
        foretiles=(int *)realloc(foretiles,sizeof(int)*(nforetiles+ft));
      if (bt)
        backtiles=(int *)realloc(backtiles,sizeof(int)*(nbacktiles+bt));

      for (i=0; i<sd.total; i++)
      {
    if (sd.entries[i]->type==SPEC_FORETILE)
    {
      foretiles[fon]=cache.reg(filename,sd.entries[i]->name);
      fon++;
      nforetiles++;
    }
    if (sd.entries[i]->type==SPEC_BACKTILE)
    {
      backtiles[bon]=cache.reg(filename,sd.entries[i]->name);
      bon++;
      nbacktiles++;
    }
      }
    }
  } else
    printf("Warning : insert_tiles -> file %s could not be read from\n",filename);
}
Ejemplo n.º 28
0
/*
 * Warning alert box, taking a format and a va_list argument.
 */
void
vsimple_warning_message_box(const char *msg_format, va_list ap)
{
#ifdef HAVE_LIBPCAP
    // We want to quit after reading the capture file, hence
    // we don't actually open the error dialog.
    if (global_commandline_info.quit_after_cap)
        exit(0);
#endif

    SimpleDialog sd(wsApp->mainWindow(), ESD_TYPE_WARN, ESD_BTN_OK, msg_format, ap);
    sd.exec();
}
Ejemplo n.º 29
0
void generate_cpp(
        const std::string&      filename,
        std::ostream&           os,
        Dependency&             dependency,
        const typeset_type&     types,
        const atomset_type&     atoms,
        const Value&            v,
        T                       pointer_maker )
{
        std::string headername = filename;
        for( std::string::iterator i = headername.begin() ; i != headername.end() ; ++i ) {
                if( !isalpha( *i ) ) { *i = '_'; } else { *i = toupper( *i ); }
        }
        os << "#ifndef " << headername << "\n";
        os << "#define " << headername << "\n\n";

        Context context;
        context.types = types;
        context.atoms = atoms;

        InheritanceCollector ic( context );
        boost::apply_visitor( ic, v.data );

        os << "#include <vector>\n\n";

        os << context.module_header;

        os << "////////////////////////////////////////////////////////////////\n"
           << "// forward declarations\n";
        ForwardDeclarator fd( os, context.basename );
        boost::apply_visitor( fd, v.data );
        os << std::endl;

        os << "////////////////////////////////////////////////////////////////\n"
           << "// tag declarations\n";
        os << "enum Tag {\n";
        context.tagid = 1;
        TagDeclarator td( os, context );
        boost::apply_visitor( td, v.data );
        os << "};\n\n";

        os << "////////////////////////////////////////////////////////////////\n"
           << "// struct declarations\n";
        context.tagid = 1;
        StructDeclarator<T> sd( os, context, pointer_maker );
        boost::apply_visitor( sd, v.data );

        os << context.module_footer;

        os << "#endif // " << headername << "\n";
}
Ejemplo n.º 30
0
bool KMLpdManager::createPrinttoolEntry(KMPrinter *printer, PrintcapEntry *entry)
{
	KURL	dev(printer->device());
	QString	prot = dev.protocol(), sd(entry->arg("sd"));
	entry->m_comment = QString::fromLatin1("##PRINTTOOL3## %1").arg(ptPrinterType(printer));
	if (prot == "smb" || prot == "ncp" || prot == "socket")
	{
		entry->m_args["af"] = sd+QString::fromLatin1("/acct");
		QFile	f(sd+QString::fromLatin1("/.config"));
		if (f.open(IO_WriteOnly))
		{
			QTextStream	t(&f);
			if (prot == "socket")
			{
				t << "printer_ip=" << dev.host() << endl;
				t << "port=" << dev.port() << endl;
				entry->m_args["if"] = driverDirectory()+QString::fromLatin1("/directprint");
			}
			else if (prot == "smb")
			{
				QStringList	l = QStringList::split('/',dev.path(),false);
				if (l.count() == 2)
				{
					t << "share='\\\\" << l[0] << '\\' << l[1] << '\'' << endl;
				}
				else if (l.count() == 1)
				{
					t << "share='\\\\" << dev.host() << '\\' << l[0] << '\'' << endl;
				}
				t << "hostip=" << endl;
				t << "user='******'\'' << endl;
				t << "password='******'\'' << endl;
				t << "workgroup='" << (l.count() == 2 ? dev.host() : QString::fromLatin1("")) << '\'' << endl;
				entry->m_args["if"] = driverDirectory()+QString::fromLatin1("/smbprint");
			}
			else if (prot == "ncp")
			{
				t << "server=" << dev.host() << endl;
				t << "queue=" << dev.path().replace("/",QString::fromLatin1("")) << endl;
				t << "user="******"password="******"if"] = driverDirectory()+QString::fromLatin1("/ncpprint");
			}
		}
		else return false;
		entry->m_args["lp"] = QString::fromLatin1("/dev/null");
	}
	else if (prot != "lpd")
		entry->m_args["lp"] = dev.path();
	return true;
}