コード例 #1
2
ファイル: shapefile.cpp プロジェクト: apprisi/stasm4
static void ImgDirs(
    char*       dirs,       // out
    const char* shapepath,  // in: shape file path
    FILE*       file)       // in
{
    char s[SLEN];
    Fgets(s, SLEN-1, file); // will skip blank lines and comments, if any

    static const char* const whitespace = " \t\n\r";
    char* token = strtok(s, whitespace);
    if (!token || 0 != strcmp(token, "Directories"))
        Err("Expected \"Directories\" in line %d of %s",
            LineNbr(file), shapepath);

    token = strtok(NULL, whitespace);
    if (!token)
        Err("Cannot read image directories in line %d of %s",
            LineNbr(file), shapepath);

    strncpy_(dirs, token, SLEN);
    ConvertBackslashesToForwardAndStripFinalSlash(dirs);
}
コード例 #2
0
ファイル: shapefile.cpp プロジェクト: tbian/aov
static void
GetImageDirsFromShapeFile (char sImageDirs[],       // out
                           const char sShapeFile[], // in
                           FILE *pShapeFile)        // in
{
char s[SLEN];
Fgets(s, SLEN-1, pShapeFile);   // this skips blank lines and comments, if any

const char *sWhiteSpace = " \t\n\r";
char *sToken = strtok(s, sWhiteSpace);
if (!sToken || 0 != strcmp(sToken, "Directories"))
    Err("expected \"Directories\" in line %d of %s",
        nGetLineNbr(pShapeFile), sShapeFile);

sToken = strtok(NULL, sWhiteSpace);
if (!sToken)
    Err("can't read image directories in line %d of %s",
        nGetLineNbr(pShapeFile), sShapeFile);

strcpy(sImageDirs, sToken);
}
コード例 #3
0
ファイル: Shader.cpp プロジェクト: ChrisJansson/Graphics
void Shader::SetParameter(const std::string& name, CurrentTextureType)
{
    if (myShaderProgram)
    {
        EnsureGlContext();

        // Find the location of the variable in the shader
        myCurrentTexture = glGetUniformLocationARB(myShaderProgram, name.c_str());
        if (myCurrentTexture == -1)
            Err() << "Texture \"" << name << "\" not found in shader" << std::endl;
    }
}
コード例 #4
0
ファイル: String.cpp プロジェクト: 3dik/bkoder
char GetChar (DynChar Char)
{
  switch (Char)
  {
    case SPACE: return ' ';
    case DASH: return '-';
    case DOT: return '.';
    case SLASH: return '/';
    case BACKSLASH: return '\\';
    default: throw Err ("Unknown DynChar");
  }
}//GetChar
コード例 #5
0
ファイル: Shader.cpp プロジェクト: ChrisJansson/Graphics
bool Shader::LoadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename)
{
    // Read the vertex shader file
    std::vector<char> vertexShader;
    if (!GetFileContents(vertexShaderFilename, vertexShader))
    {
        Err() << "Failed to open vertex shader file \"" << vertexShaderFilename << "\"" << std::endl;
        return false;
    }

    // Read the fragment shader file
    std::vector<char> fragmentShader;
    if (!GetFileContents(fragmentShaderFilename, fragmentShader))
    {
        Err() << "Failed to open fragment shader file \"" << fragmentShaderFilename << "\"" << std::endl;
        return false;
    }

    // Compile the shader program
    return Compile(&vertexShader[0], &fragmentShader[0]);
}
コード例 #6
0
ファイル: Shader.cpp プロジェクト: ChrisJansson/Graphics
bool Shader::LoadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream)
{
    // Read the vertex shader code from the stream
    std::vector<char> vertexShader;
    if (!GetStreamContents(vertexShaderStream, vertexShader))
    {
        Err() << "Failed to read vertex shader from stream" << std::endl;
        return false;
    }

    // Read the fragment shader code from the stream
    std::vector<char> fragmentShader;
    if (!GetStreamContents(fragmentShaderStream, fragmentShader))
    {
        Err() << "Failed to read fragment shader from stream" << std::endl;
        return false;
    }

    // Compile the shader program
    return Compile(&vertexShader[0], &fragmentShader[0]);
}
コード例 #7
0
ファイル: a_all.cpp プロジェクト: BigEd/Cores
	void Assembler::macro()
	{
		char *sptr, *eptr;
		char nbuf[NAME_MAX+1];
		int idlen, xx;
		Macro *fmac;

		gNargs = 0;
		macrobuf = "";
		idlen = ibuf->getIdentifier(&sptr, &eptr);
		if (idlen == 0)
		{
			//printf("aaa:%.20s|\r\n", sptr);
			Err(E_MACRONAME);
			return;
		}
		if (pass < 2)
		{
			memset(nbuf, '\0', sizeof(nbuf));
			memcpy(nbuf, sptr, min(idlen, NAME_MAX));
			gMacro.setName(nbuf);
			fmac = (Macro *)macroTbl->find(&gMacro);
			if (fmac)
			{
				Err(E_DEFINED, nbuf);
				return;
			}
		}
		// Free parameter list (if not already freed)
		for (xx = 0; xx < MAX_MACRO_PARMS; xx++)
			if (parmlist[xx]) {
				delete parmlist[xx];
				parmlist[xx] = NULL;
			}

		xx = gNargs = ibuf->getParmList(parmlist);
		gMacro.setArgCount(xx);
		gMacro.setFileLine(CurFileNum, File[CurFileNum].LastLine);
		CollectingMacro = true;
	}
コード例 #8
0
static void WriteShapeMod(  // write a shape model to a .mh file as C++ code
    const char*  modname,   // in
    const Shape& meanshape, // in: n x 2
    const VEC&   eigvals,   // in: 2n x 1
    const MAT&   eigvecs,   // in: 2n x 2n, inverse of eigs of cov mat
    const char*  outdir,    // in: output directory
    const char*  comment)   // in
{
    char path[SLEN];
    sprintf(path, "%s/mh/%s_shapemodel.mh", outdir, modname);
    lprintf("Generating %s\n", path);
    FILE *file = fopen(path, "wb");
    if (!file)
        Err("Cannot open %s", path);
    char s[SLEN];
    Fprintf(file, "// %s.mh: machine generated shape model\n", path);
    Fprintf(file, "//\n");
    Fprintf(file, "// Command: %s\n//\n\n", comment);
    char path1[SLEN]; sprintf(path1, "stasm_%s_shapemodel_mh", modname);
    ToUpper(path1);
    Fprintf(file, "#ifndef %s\n", path1);
    Fprintf(file, "#define %s\n\n", path1);
    Fprintf(file, "namespace stasm {\n\n");

    sprintf(s, "%s_meanshapedata", modname);
    WriteMatAsArray(meanshape, s, "mean shape", file);

    Fprintf(file,
        "\nstatic const cv::Mat %s_meanshape(%d, %d, CV_64FC1, "
        "(double *)%s_meanshapedata);\n\n",
        modname, meanshape.rows, meanshape.cols, modname);

    sprintf(s, "%s_eigvalsdata", modname);
    WriteMatAsArray(eigvals, s, "eigen values", file);

    Fprintf(file,
        "\nstatic const cv::Mat %s_eigvals(%d, %d, CV_64FC1, "
        "(double *)%s_eigvalsdata);\n\n",
        modname, eigvals.rows, eigvals.cols, modname);

    sprintf(s, "%s_eigvecsdata", modname);
    WriteMatAsArray(eigvecs, s, "eigen vectors", file);

    Fprintf(file,
        "\nstatic const cv::Mat %s_eigvecs(%d, %d, CV_64FC1, "
        "(double *)%s_eigvecsdata);\n\n",
        modname, eigvecs.rows, eigvecs.cols, modname);

    Fprintf(file, "} // namespace stasm\n", path1);
    Fprintf(file, "#endif // %s\n", path1);
    fclose(file);
}
コード例 #9
0
ファイル: macros.cpp プロジェクト: hoangt/cryptoleq
void Macros::instance_process_args(const string & name, int idx)
{
    Pnode pval = macdef_instance->argvals[idx];

    const Nodes & usage = macdef_instance->iduse[name];
    for (auto i : usage)
    {
        // i is id
        Node * parent = i->parent;
        //find in parent references to this id
        for (auto & j : parent->children)
        {
            if (j.get() != i.get())
                continue;

            // this is our reference - j is Pnode in the parent's list
            j = pval;
            j->parent = parent;

            if (Item * itm = dynamic_cast<Item *>(parent))
            {
                if (itm->typ != Item::eId) throw Err(LNFUN);
                throw Err("Parameter names in array definitions, use [(...)]", i->tok());
            }

            // now change parents type
            Term * term = dynamic_cast<Term *>(parent);
            if (!term) throw Err(LNFUN);
            // pval is either Idn or Expr
            Idn * idn = get<Idn>(NOTHR, pval);

            if (idn)
                continue; // all good term should be eId

            // otherwise pval is expr
            term->typ = Term::eExpr;
        }
    }
}
コード例 #10
0
ファイル: SinfParser.cpp プロジェクト: fitzgen/gecko-dev
Result<Ok, nsresult>
SinfParser::ParseSchm(Box& aBox)
{
  BoxReader reader(aBox);

  if (reader->Remaining() < 8) {
    return Err(NS_ERROR_FAILURE);
  }

  MOZ_TRY(reader->ReadU32()); // flags -- ignore
  MOZ_TRY_VAR(mSinf.mDefaultEncryptionType, reader->ReadU32());
  return Ok();
}
コード例 #11
0
ファイル: opts.cpp プロジェクト: ushakov/mapsoft
// input/output operators for options
std::ostream & operator<< (std::ostream & s, const Opts & o){
  json_error_t e;
  json_t *J = json_object();
  for (auto i: o){
    json_object_set(J, i.first.c_str(), json_string(i.second.c_str()));
  }
  char *ret = json_dumps(J, JSON_SORT_KEYS);
  json_decref(J);
  if (!ret) throw Err() << "can't write Opts";
  s<<ret;
  free(ret);
  return s;
}
コード例 #12
0
ファイル: MainSession.cpp プロジェクト: DrJukka/Symbian_Codes
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_ServerSession::KillProcessL(const RMessage2& aMessage)
{        
	TInt Err(KErrNone);

	TBuf8<255> Hjelpper;
	
//	TRAP(Err,
	aMessage.ReadL(0,Hjelpper,0);
	
	Server().KillProcess(Hjelpper);
	
    aMessage.Complete(Err);		
}
コード例 #13
0
ファイル: money.cpp プロジェクト: cmdc0de/WolfshadeMud
//////////////////////////////
//	FromString
//	check the string ...Is it cash we are talking about?
//	if so exchange.  Take from this monehy add add to other
//	The remove functions through a CError if not enough cash.
//	written by: Demetrius Comes
void sMoney::FromString(CString & strMoney, sMoney & ToAdd, int nCoins)
{
	if(strMoney.Compare(m_strPlat.Left(strMoney.GetLength())))
	{
		ToAdd.AddPlat(RemovePlat(nCoins));
		throw "platinum";
	}
	else if(strMoney.Compare(m_strGold.Left(strMoney.GetLength())))
	{
		ToAdd.AddGold(RemoveGold(nCoins));
		throw "gold";
	}
	else if(strMoney.Compare(m_strSilver.Left(strMoney.GetLength())))
	{
		ToAdd.AddSilver(RemoveSilver(nCoins));
		throw "silver";
	}
	else if(strMoney.Compare(m_strCopper.Left(strMoney.GetLength())))
	{
		ToAdd.AddCopper(RemoveCopper(nCoins));
		throw "copper";
	}
	else if(strMoney.Compare("coins"))
	{
		if(nCoins!=-1 && nCoins!=1)
		{
			CError Err(MESSAGE_ONLY,"You can't specify coins without type!\r\n");
			throw &Err;
		}
		if(IsEmpty())
		{
			CError Err(MESSAGE_ONLY,"You can't find any coins.\r\n");
			throw &Err;
		}
		ToAdd+=*this;
		*this=0;
		throw "coins";
	}
}
コード例 #14
0
ファイル: MemMapSnapshot.cpp プロジェクト: Noctem/gecko-dev
Result<Ok, nsresult> MemMapSnapshot::Freeze(AutoMemMap& aMem) {
  auto orig = mFile.ref().ClonePlatformHandle();
  mFile.reset();

  HANDLE handle;
  if (!::DuplicateHandle(
          GetCurrentProcess(), orig.release(), GetCurrentProcess(), &handle,
          GENERIC_READ | FILE_MAP_READ, false, DUPLICATE_CLOSE_SOURCE)) {
    return Err(NS_ERROR_FAILURE);
  }

  return aMem.initWithHandle(FileDescriptor(handle), mMem.size());
}
コード例 #15
0
ファイル: lsh.cpp プロジェクト: snap-stanford/curis-2012
void LSH::WordHashing(TQuoteBase* QuoteBase, THashSet<TMd5Sig>& Shingles) {
  Err("Hashing shingles using words...\n");
  TIntV QuoteIds;
  QuoteBase->GetAllQuoteIds(QuoteIds);
  for (int qt = 0; qt < QuoteIds.Len(); qt++) {
    if (qt % 1000 == 0) {
      Err("%d out of %d completed\n", qt, QuoteIds.Len());
    }
    TQuote Q;
    QuoteBase->GetQuote(QuoteIds[qt], Q);

    TStrV Content;
    Q.GetParsedContent(Content);

    int ContentLen = Content.Len();
    for (int i = 0; i < ContentLen; i++) {
      const TMd5Sig ShingleMd5(Content[i]);
      Shingles.AddKey(ShingleMd5);
    }
  }
  Err("Done with word hashing! Number of shingles: %d\n", Shingles.Len());
}
コード例 #16
0
ファイル: wpatch.c プロジェクト: Ukusbobra/open-watcom-v2
void FilePatchError( int format, ... )
{
    va_list     args;
    int         err;

    va_start( args, format );
    err = errno;
    Err( format, args );
    printf( ": %s\n", strerror( err ) );
    va_end( args );
    MsgFini();
    exit( EXIT_FAILURE );
}
コード例 #17
0
ファイル: Application.c プロジェクト: dansog56/mcuoneclipse
static void LogToFile(int16_t x, int16_t y, int16_t z) {
  uint8_t write_buf[48];
  UINT bw;
  TIMEREC time;

  /* open file */
  if (FAT1_open(&fp, "./log.txt", FA_OPEN_ALWAYS|FA_WRITE)!=FR_OK) {
    Err();
  }
  /* move to the end of the file */
  if (FAT1_lseek(&fp, fp.fsize) != FR_OK || fp.fptr != fp.fsize) {
    Err();
  }
  /* get time */
  if (TmDt1_GetTime(&time)!=ERR_OK) {
    Err();
  }
  /* write data */
  write_buf[0] = '\0';
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Hour);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Min);
  UTIL1_chcat(write_buf, sizeof(write_buf), ':');
  UTIL1_strcatNum8u(write_buf, sizeof(write_buf), time.Sec);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');

  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), x);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), y);
  UTIL1_chcat(write_buf, sizeof(write_buf), '\t');
  UTIL1_strcatNum16s(write_buf, sizeof(write_buf), z);
  UTIL1_strcat(write_buf, sizeof(write_buf), (unsigned char*)"\r\n");
  if (FAT1_write(&fp, write_buf, UTIL1_strlen((char*)write_buf), &bw)!=FR_OK) {
    (void)FAT1_close(&fp);
    Err();
  }
  /* closing file */
  (void)FAT1_close(&fp);
}
コード例 #18
0
ファイル: funky_env.c プロジェクト: gregghz/funky
int establish_root_environment(void) {
    spawn_env(NULL, Primordial_Grid(GC_SKIPREG));
    rootEnvironment=Car(env);
    rootBacros=Grid();
    unknownSymbolError=Err(Cons(String("Unknown symbol"), NULL));
    Set(rootEnvironment, "nil", NULL);
    Set(rootEnvironment, "true", Atom("true"));
    Set(rootEnvironment, "add", Routine(&dirty_sum));
    Set(rootEnvironment, "+", Get(rootEnvironment, "add"));
    Set(rootEnvironment, "subtract", Routine(&dirty_sub));
    Set(rootEnvironment, "-", Get(rootEnvironment, "subtract"));
    Set(rootEnvironment, "if", Method(&funky_if));
    Set(rootEnvironment, "&ver", String("Funky Lisp Draft 3"));
    Set(rootEnvironment, "set!", Routine(&funky_set));
    Set(rootEnvironment, "print_", Routine(&funky_print));
    Set(rootEnvironment, "list", Routine(&funky_list));
    Set(rootEnvironment, "pair", Routine(&funky_pair));
    Set(rootEnvironment, "grid", Routine(&funky_grid));
    Set(rootEnvironment, "get", Routine(&funky_grid_get));
    Set(rootEnvironment, "quote", Method(&funky_quote));
    Set(rootEnvironment, "apply", Routine(&apply));
    Set(rootEnvironment, "mac", Method(&funky_macro));
    Set(rootEnvironment, "def", Method(&funky_def));
    Set(rootEnvironment, "head", Routine(&funky_head));
    Set(rootEnvironment, "rest_", Routine(&funky_rest));
    Set(rootEnvironment, "last", Routine(&funky_last));
    Set(rootEnvironment, "err", Routine(&funky_err));
    Set(rootEnvironment, "dump", Routine(&funky_dump));
    Set(rootEnvironment, "&bacros", rootBacros);
    Set(rootEnvironment, ">", Routine(&funky_greater_than));
    Set(rootEnvironment, "<", Routine(&funky_less_than));
    Set(rootEnvironment, "=", Routine(&funky_equivalent));
    Set(rootEnvironment, "not", Routine(&funky_not_operator));
    Set(rootEnvironment, "eval", Method(&funky_evaluator));
    Set(rootEnvironment, "true?", Routine(&funky_truthy));
    Set(rootEnvironment, "false?", Routine(&funky_nilly));
    Set(rootEnvironment, "lambda?", Routine(&funky_callable));
    Set(rootEnvironment, "atom?", Routine(&funky_is_atom));
    Set(rootEnvironment, "gen?", Routine(&funky_is_gen));
    Set(rootEnvironment, "len", Routine(&funky_length));
    Set(rootEnvironment, "gen", Routine(&funky_gen));
    Set(rootEnvironment, "cons", Routine(&funky_cons));
    Set(rootEnvironment, "append", Routine(&funky_append));
    Set(rootEnvironment, "error?", Routine(&funky_is_error));
    Set(rootEnvironment, "grid?", Routine(&funky_is_grid));
    Set(rootEnvironment, "txt-concatenate_", Routine(&funky_make_txt));
    Set(rootEnvironment, "type", Routine(&funky_type_symbol));
    Set(rootEnvironment, UNKNOWN_HANDLER, Atom(UNKNOWN_LIT));
    establish_bacros(rootBacros);
    return new_env();
}
コード例 #19
0
ファイル: opts.cpp プロジェクト: ushakov/mapsoft
void
Opts::check_unknown (std::list<std::string> known) const {
  std::string unknown;
  int n=0;
  for (auto i : *this){
    if (std::find(known.begin(), known.end(), i.first) == known.end())
      unknown += (n++ ? ", ": " ") + i.first;
  }
  if (n){
    throw Err() << "unknown "
                << (n==1? "option:":"options:")
                << unknown;
  }
}
コード例 #20
0
ファイル: server.c プロジェクト: anandsoft/odatalite
static void _GetConfFileOptions()
{
    char path[MAX_PATH_SIZE];
    char err[256];

    MakePath(ID_PHITD_CONF, path);

    if (access(path, R_OK) == 0 &&
        ConfFileLoad(
            path, "=", _ConfFileCallback, &g_options, err, sizeof(err)) != 0)
    {
        Err("%s", err);
    }
}
コード例 #21
0
ファイル: MainSession.cpp プロジェクト: DrJukka/Symbian_Codes
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_ServerSession::KillTaskL(const RMessage2& aMessage)
{        
	TInt Err(KErrNone);

	TPckgBuf<TUid> ItemData;
	
//	TRAP(Err,
	aMessage.ReadL(0,ItemData,0);
	
	Err = Server().KillTasks(ItemData());
	
	aMessage.WriteL(0,ItemData);
    aMessage.Complete(Err);		
}
コード例 #22
0
static int FirstShapeWithAllPoints(
    const ShapeFile& sh)
{
    for (int ishape = 0; ishape < sh.nshapes_; ishape++)
        if (NbrUsedPoints(sh.shapes_[ishape]) == sh.shapes_[ishape].rows)
        {
            lprintf("Reference shape %s is at index %d and has %d landmarks\n",
                    sh.bases_[ishape].c_str(), ishape, sh.shapes_[ishape].rows);
            return ishape; // note: return
        }

    Err("%s: all shapes have unused points", sh.shapepath_);
    return 0; // never get here
}
コード例 #23
0
ファイル: MainSession.cpp プロジェクト: DrJukka/Symbian_Codes
/* 
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
void CExPolicy_ServerSession::SetFileMappingL(const RMessage2& aMessage)
{        
	TInt Err(KErrNone);

	TPckgBuf<TFileMappingItem> ItemData;
	
//	TRAP(Err,
	aMessage.ReadL(0,ItemData,0);
	
	Err = Server().SetFileMapping(ItemData());

	aMessage.WriteL(0,ItemData);
    aMessage.Complete(Err);		
}
コード例 #24
0
ファイル: shader.cpp プロジェクト: MEC402/cruft
unsigned int
ShaderProgram::linkProgram()
{
  if (!checkBuilt()) {
    // this ShaderProgram has already been built.
    return 0;
  }

  if (m_stages.empty()) {
    Err() << "When linking program, there were no shaders to link! Cannot "
      "create shader program.";
    return 0;
  }

  if (m_programId != 0) {
    Dbg() << "Relinking shader program id=" << m_programId;
  } else {
    // have GL make a program and bail out if no success.
    createNewProgram();

    if (m_programId == 0)
      return 0;

    Dbg() << "Linking shader program id=" <<  m_programId;
  }

  gl_check(glLinkProgram(m_programId));

  // Check the program
  int InfoLogLength{ 0 };
  GLint result{ GL_FALSE };

  gl_check(glGetProgramiv(m_programId, GL_LINK_STATUS, &result));
  gl_check(glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &InfoLogLength));
  Dbg() << "GL Link Status for shader program "
        << m_programId << ": "
        << (result == GL_FALSE ? "GL_FALSE" : "GL_TRUE")
        << ".";

  if (InfoLogLength > 1) {
    std::vector<char> programErrorMessage(InfoLogLength + 1);
    gl_check(glGetProgramInfoLog(m_programId,
      InfoLogLength,
      nullptr,
      &programErrorMessage[0]));
    Dbg() << &programErrorMessage[0];
  }

  return m_programId;
}
コード例 #25
0
unsigned int RageFileSink::Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
{
	if (!m_file.IsOpen())
		throw Err("FileSink: output stream not opened");
	
	if( m_file.Write((const char *)inString, length) == -1 )
		throw WriteErr( m_file );
	
	if (messageEnd)
		if( m_file.Flush() == -1 )
			throw WriteErr( m_file );
	
	return 0;
}
コード例 #26
0
ファイル: jsink.cpp プロジェクト: bduc/ruby-cryptopp
size_t RubyIOSink::Put2(const byte* inString, size_t length, int messageEnd, bool blocking)
{
  if (!m_stream) {
    throw Err("RubyIOSink: output stream not opened");
  }

  rb_funcall(*m_stream, rb_intern("write"), 1, rb_str_new((const char*) inString, length));

  if (messageEnd) {
    rb_funcall(*m_stream, rb_intern("flush"), 0);
  }

  return 0;
}
コード例 #27
0
ファイル: Font.cpp プロジェクト: vidjogamer/SFML
bool Font::LoadFromFile(const std::string& filename)
{
    // Cleanup the previous resources
    Cleanup();
    myRefCount = new int(1);

    // Initialize FreeType
    // Note: we initialize FreeType for every font instance in order to avoid having a single
    // global manager that would create a lot of issues regarding creation and destruction order.
    FT_Library library;
    if (FT_Init_FreeType(&library) != 0)
    {
        Err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl;
        return false;
    }
    myLibrary = library;

    // Load the new font face from the specified file
    FT_Face face;
    if (FT_New_Face(static_cast<FT_Library>(myLibrary), filename.c_str(), 0, &face) != 0)
    {
        Err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl;
        return false;
    }

    // Select the unicode character map
    if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0)
    {
        Err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl;
        return false;
    }

    // Store the loaded font in our ugly void* :)
    myFace = face;

    return true;
}
コード例 #28
0
ファイル: Application.c プロジェクト: dansog56/mcuoneclipse
void APP_Run(void) {
  int16_t x,y,z;
  uint8_t res;
  #define ACCEL_VAL  2000

  res = FX1_Enable(); /* enable accelerometer (just in case) */
  if (res!=ERR_OK) {
    Err();
  }
  if (FAT1_Init()!=ERR_OK) {
    Err();
  }
  if (FAT1_mount(0, &fileSystemObject) != FR_OK) { /* mount file system */
    Err();
  }
  for(;;) {
    //LED1_Neg();
    x = FX1_GetX();
    y = FX1_GetY();
    z = FX1_GetZ();
    if (x>ACCEL_VAL || x<-ACCEL_VAL) {
      LED1_On();
      LED2_Off();
      LED3_Off();
    } else if (y>ACCEL_VAL || y<-ACCEL_VAL) {
      LED1_Off();
      LED2_On();
      LED3_Off();
    } else if (z>ACCEL_VAL || z<-ACCEL_VAL) {
      LED1_Off();
      LED2_Off();
      LED3_On();
    }
    LogToFile(x, y, z);
    WAIT1_Waitms(1000);
  }
}
コード例 #29
0
ファイル: camera.cpp プロジェクト: shivam11/stasmjs
bool fInitCamera (HWND hMainWnd, int iDeviceIndex)
{
// Create a capture window to capture the output from the camera
// The capture window is not actually displayed (in this application)

hgCapWnd = capCreateCaptureWindow(NULL,
                                  WS_CHILD,         // window style
                                  0, 0, 0, 0,       // position and size
                                  hMainWnd, ID_CAP);
if (!hgCapWnd)
    {
    Err("Can't open the camera display window");
    return 0;
    }
if (!capDriverConnect(hgCapWnd, iDeviceIndex))
    {
    Err("Can't connect to the camera");
    return false;
    }
if (!capDriverGetCaps(hgCapWnd, &gDriverCaps, sizeof(CAPDRIVERCAPS)))
    {
    Err("Can't get capabilities of the camera");
    return false;
    }
if (!capPreview(hgCapWnd, FALSE))   // turn off preview
    {
    Err("capPreview FALSE failed");
    return false;
    }
if (!capGetStatus(hgCapWnd, &gCapStatus, sizeof(CAPSTATUS)))
    {
    Err("Can't get status of the camera");
    return false;
    }
PrintCapStatus();
return true;    // success
}
コード例 #30
0
ファイル: tasmdescmod.cpp プロジェクト: avtomaton/stasm
static void WriteTrainDescs(
    const TRAIN_DISTS& train_dists, // in: [ipoint] [idesc] distances from true landmark
    const TRAIN_DESCS& train_descs, // in: [ipoint] [idesc] training descriptors
    int                ilev,        // in:
    const char*        outdir)      // in: output directory (-d flag)
{
    clock_t start_time = clock();
    const int npoints = NSIZE(train_descs);
    Pacifier pacifier(npoints);
    for (int ipoint = 0; ipoint < npoints; ipoint++)
    {
        // filename
        const int ndigits = NumDigits(npoints);
        char format[SLEN]; // e.g. tasmout/log/lev1_p23_classic.desc
        sprintf(format, "%%s/log/lev%%d_p%%%d.%dd_%%s.desc", ndigits, ndigits);
        char path[SLEN];
        sprintf(path, format, outdir, ilev, ipoint,
                IsTasmHatDesc(ilev, ipoint)? "hat": "classic");
        static int printed;
        PrintOnce(printed, "    generating %s (tasm -w flag)...\n", path);
        FILE* file = fopen(path, "wb");
        if (!file)
            Err("Cannot open %s", path);
        // header
        const vec_VEC descs = train_descs[ipoint]; // descriptors for this point
        const vec_double dists = train_dists[ipoint];
        Fprintf(file, "ilev ipoint       dist ");
        for (int i = 0; i < NSIZE(descs[0]); i++)
        {
            char s[SLEN];  sprintf(s, "x%d ", i);
            Fprintf(file, " %10.10s", s);
        }
        Fprintf(file, "\n");
        // contents
        for (int idesc = 0; idesc < NSIZE(descs); idesc++)
        {
            Fprintf(file, "%4d %6d %10g", ilev, ipoint, dists[idesc]);
            for (int i = 0; i < NSIZE(descs[idesc]); i++)
                Fprintf(file, " %10g", descs[idesc](i));
            Fprintf(file, "\n");
        }
        fclose(file);
        if (print_g)
            pacifier.Print_(ipoint);
    }
    if (print_g)
        pacifier.End_();
    lprintf(" [%.1f secs]\n", double(clock() - start_time) / CLOCKS_PER_SEC);
}