Esempio n. 1
0
void ClassDef::WriteHpp( void )
{

  int i;
  int width = 10;

  cout << hppFile.psz() << endl;

  ofstream hpp( hppFile );
  if( !hpp  )
  {
     cerr << "Could not open hpp file: " << hppFile.psz() << endl;
     openErr = 1;
  }

  // write any #includes
  //
  for( i=0; i < includes.max(); i++ )
  {
    hpp << includes[i]->psz() << endl; 
  }

  // write the class name
  //
  hpp << endl << "class " << className.psz(); 

  char sep = ':'; 

  for( i=0; i < privateParents.max(); i++ )
  {
    hpp << sep << " private " << privateParents[i]->psz();
    if( sep == ':' ) sep = ',';
  }

  for( i=0; i < publicParents.max(); i++ )
  {
    hpp << sep << " public " << publicParents[i]->psz();  
    if( sep == ':' ) sep = ',';
  }

  hpp << endl << "{" << endl;

  // now go through the found variables
  //
  hpp << endl << "private:" << endl << endl;

  for( i=0; i<privateMembers.max(); i++ )
  {
    width = privateMembers[i]->type.max() > width?
	    privateMembers[i]->type.max():
	    width;
    hpp.setf(ios::left,ios::adjustfield);
    hpp << indent << setw(width) << privateMembers[i]->type.psz() << " ";
    hpp << indent << privateMembers[i]->name.lowerS().psz() << ";" << endl;
  }


  // Auto members for the size of pointer variables
  //
  for( i=0; i<sizeMembers.max(); i++ )
  {
    width = sizeMembers[i]->type.max() > width?
	    sizeMembers[i]->type.max():
	    width;
    hpp.setf(ios::left,ios::adjustfield);
    hpp << indent << setw(width) << sizeMembers[i]->type.psz() << " ";
    hpp << indent << sizeMembers[i]->name.lowerS().psz() << ";" << endl;
  }


  // private method output goes here.
  //
  hpp << endl << "protected:" << endl << endl;

  for( i=0; i < privateMethods.max(); i++)
  {
    hString current;
    current = privateMethods[i]->psz();
    current.searchAndReplaceWith( "`", "" );
    hpp << indent << current.psz() << ";" << endl;
  }

  width = 10;

  for( i=0; i<publicMembers.max(); i++ )
  {
    width = publicMembers[i]->type.max() > width?
	    publicMembers[i]->type.max():
	    width;
    hpp.setf(ios::left,ios::adjustfield);
    hpp << indent << setw(width) << publicMembers[i]->type.psz() << " ";
    hpp << indent << publicMembers[i]->name.lowerS().psz() << ";" << endl;
  }

  // size sets go in the protected region
  //
  for( i=0; i<sizeMembers.max(); i++ )
  {

    // only do the set here.
    hpp << indent << sizeMembers[i]->AccessDefs[1]->psz() << endl;
    hpp << endl;

  }

  for( i=0; i<privateMembers.max(); i++ )
  {

    for ( int j = 0; j<2 && j<privateMembers[i]->AccessDefs.max(); j++ )
    {
      hpp << indent << privateMembers[i]->AccessDefs[j]->psz() << endl;
    }
    hpp << endl;

  }

  hpp << endl << "public:" << endl << endl;

  //
  // The universal public stuff goes here
  //

  //
  // Constructor, destructor, assignment and copy constructor
  //

  // allocate for the input line from the class defination file.
  //
  char * GenLine = new char[256];

  // open the needed files:
  //
  ifstream classGen( pszAssignDef );
  if( ! classGen )
  {
     cerr << "Couldn't open assign def. file: " << pszAssignDef << endl;
     openErr = true;
  }

  while ( classGen.getline( GenLine, 255 ) && className.max() )
  {

    hString * newStr = new hString;
    *newStr = GenLine;

    newStr->searchAndReplaceWith( tokClass, className.psz() );
    newStr->trim();
    
    hpp << indent << newStr->psz() << endl;

    delete newStr;

  } // end while

  delete GenLine;

  // accessors go here...
  //


  for( i=0; i<publicMembers.max(); i++ )
  {

    for ( int j = 0; j<2 && j<publicMembers[i]->AccessDefs.max(); j++ )
    {
      hpp << indent << publicMembers[i]->AccessDefs[j]->psz() << endl;
    }
    hpp << endl;

  }

  for( i=0; i<sizeMembers.max(); i++ )
  {

    // only do the get here.
    hpp << indent << sizeMembers[i]->AccessDefs[0]->psz() << endl;
    hpp << endl;

  }


  for( i=0; i < publicMethods.max(); i++)
  {
    hString current;
    current = publicMethods[i]->psz();
    current.searchAndReplaceWith( "`", "" );
    hpp << indent << current.psz() << ";" << endl;
  }

  hpp << endl << "};" << endl;

}
Esempio n. 2
0
void
eavlBitmapFont::DumpToInitFile(const std::string &fn,
                               const std::string &shortname)
{
    // write the cpp and header files
    ofstream cpp((fn + ".cpp").c_str(), ios::out);
    ofstream hpp((fn + ".h").c_str(), ios::out);

    string shortupper(shortname);
    std::transform(shortupper.begin(), shortupper.end(), shortupper.begin(),
                   toupper);
    hpp << "#ifndef EAVL_"<<shortupper<<"_H" << endl;
    hpp << "#define EAVL_"<<shortupper<<"_H" << endl;
    hpp << endl;
    hpp << "eavlBitmapFont *Create"<<shortname<<"Font();" << endl;
    hpp << endl;
    hpp << "#endif" << endl;

    cpp << "#include <eavlBitmapFont.h>" << endl;
    cpp << endl;
    cpp << "static int charmetrics[][8] = {" << endl;
    for (int i=0; i<chars.size(); i++)
    {
        Character &c = chars[i];
        cpp << "    {"
            << int((unsigned char)c.c) << ","
            << c.offx << "," << c.offy << ","
            << c.x << "," << c.y << ","
            << c.w << "," << c.h << ","
            << c.adv << "}";
        if (i < chars.size()) 
            cpp << ",";
        cpp << endl;
    }
    cpp << "};" << endl;
    cpp << "static const char *charids[] = {" << endl;
    for (int i=0; i<chars.size(); i++)
    {
        Character &c = chars[i];
        if (i % 10 == 0)
            cpp << endl << "    ";
        cpp << "\"" << ((c.c == '\"' || c.c == '\\') ? "\\" : "") << c.id << "\"";
        if (i < chars.size()-1)
            cpp << ",";
        else
            cpp << endl;
    }
    cpp << "};" << endl;
    cpp << endl;
    cpp << "static const unsigned char rawimage[] = {";
    for (int i=0; i<rawimagefiledata.size(); ++i)
    {
        if (i % 10 == 0)
            cpp << endl << "    ";
        cpp << "0x"
            << std::hex << std::setfill('0') << std::setw(2)
            << int((unsigned char)(rawimagefiledata[i]));
        if (i < rawimagefiledata.size()-1)
            cpp << ",";
        else
            cpp << endl;
    }
    cpp << std::dec;
    cpp << "};" << endl;
    cpp << endl;
    cpp << "eavlBitmapFont *Create"<<shortname<<"Font()" << endl;
    cpp << "{" << endl;
    cpp << "    eavlBitmapFont *font = new eavlBitmapFont;" << endl;
    cpp << "    font->name      = \"" << name << "\";" << endl;
    cpp << "    font->height    = " << height << ";" << endl;
    cpp << "    font->ascender  = " << ascender << ";" << endl;
    cpp << "    font->descender = " << descender << ";" << endl;
    cpp << "    font->imgw      = " << imgw << ";" << endl;
    cpp << "    font->imgh      = " << imgh << ";" << endl;
    cpp << "    font->padl      = " << padl << ";" << endl;
    cpp << "    font->padr      = " << padr << ";" << endl;
    cpp << "    font->padt      = " << padt << ";" << endl;
    cpp << "    font->padb      = " << padb << ";" << endl;
    cpp << "    font->rawimagefiledata.insert(" << endl
        << "        font->rawimagefiledata.begin()," << endl
        << "        rawimage, rawimage + "<<rawimagefiledata.size() << ");" << endl;
    cpp << "    for (int i=0; i<"<<chars.size()<<"; i++)" << endl;
    cpp << "    {" << endl;
    cpp << "        font->chars.push_back(eavlBitmapFont::Character("
        << "charids[i],charmetrics[i]));" << endl;
    cpp << "        font->shortmap[charmetrics[i][0]] = i;" << endl;
    cpp << "    }" << endl;
    cpp << endl;
    cpp << "    // Any kerning data follows..." << endl;
    cpp << endl;
    for (int i=0; i<chars.size(); i++)
    {
        Character &c = chars[i];
        bool header = false;
        for (int j=0; j<256; j++)
        {
            if (c.kern[j] != 0)
            {
                if (!header)
                    cpp << "    // Character " << c.id << endl;
                header = true;
                cpp << "    font->chars["<<i<<"].kern["<<j<<"] = " << c.kern[j] << ";" << endl;
            }
        }
    }
    cpp << "    return font;" << endl;
    cpp << "}" << endl;

    cpp << endl;

    cpp.close();
    hpp.close();
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
  if (argc != 2) {
    std::cerr << "Usage: dtdbin PATH_TO_DTD_FILES" << std::endl;
    return EXIT_FAILURE;
  }

  std::ofstream cpp("musicxml-dtd.cpp"), hpp("musicxml-dtd.hpp");

  hpp << "#ifndef MUSICXML_DTD_HPP" << std::endl
      << "#define MUSICXML_DTD_HPP" << std::endl
      << "#include <map>" << std::endl
      << "#include <string>" << std::endl
      << "#include <xercesc/util/XercesDefs.hpp>" << std::endl
      << std::endl
      << "namespace musicxml {" << std::endl
      << std::endl
      << "extern "
         "std::map<std::string, std::pair<XMLByte const *, XMLSize_t>> const "
         "dtd;" << std::endl
      << std::endl
      << "}" << std::endl
      << std::endl
      << "#endif" << std::endl;

  cpp << "#include \"musicxml-dtd.hpp\"" << std::endl;
  cpp << std::endl;
  for (auto &&pair: dtds) {
    std::string path(argv[1]);
    path += pair.second;
    std::ifstream dtd(path);
    if (!dtd.good()) {
      std::cerr << "DTD file " << path << " not found." << std::endl;
      return EXIT_FAILURE;
    }
    std::istreambuf_iterator<char> dtd_begin(dtd.rdbuf()), dtd_end;
    std::string dtd_string(dtd_begin, dtd_end);
    cpp << "static XMLByte const " << cpp_identifier(pair.second)
        << "[" << std::dec << dtd_string.length() << "UL] = {";
    for (unsigned i = 0; i < dtd_string.length(); ++i) {
      if ((i % 13) == 0) cpp << std::endl << "  ";
      cpp << "0X";
      cpp.width(2); cpp.fill('0');
      cpp << std::hex << int(static_cast<unsigned char>(dtd_string[i]));
      if (i < dtd_string.length() - 1) cpp << ", ";
    }
    cpp << std::endl << "};" << std::endl << std::endl;
  }

  cpp << "std::map<std::string, std::pair<XMLByte const *, XMLSize_t>> const "
         "musicxml::dtd = {" << std::endl;
  for (auto &&pair: dtds) {
    std::string path(argv[1]);
    path += pair.second;
    cpp << "  { \"" << pair.first << "\"," << std::endl
        << "    std::make_pair(&" << cpp_identifier(pair.second) << "[0], sizeof("
        << cpp_identifier(pair.second) << "))" << std::endl << "  },"
        << std::endl;
  }
  cpp << "};" << std::endl;

  return EXIT_SUCCESS;
}
Esempio n. 4
0
int release(int ldes1, int pid)
{

	register struct	sentry	*sptr;
	struct	pentry	*pptr;
	STATWORD ps;
	//unsigned long ctime;
	int tail,prev,ldes,ver;
#ifdef DEBUGF
		kprintf("\nInside release\n");
#endif

	disable (ps);
	ldes=GET_LOCK(ldes1);
	ver=GET_VER(ldes1);
#ifdef DEBUGF
	kprintf("\nLDES:%04x, VER:%d, LOCK:%d\n",ldes1,ver,ldes);
#endif



	if (isbadlock(ldes) || (sptr= &semaph[ldes])->sstate==SFREE) {
#ifdef DEBUGF
		kprintf("\npid %d has found an error, ldes=%d, sptr->sstate= %d\n",pid,ldes,sptr->sstate);
#endif
			restore(ps);
			return(SYSERR);
		}
	if (ver!=sptr->lversion)
	{
#ifdef DEBUGF
	kprintf("\nVersion error\n");
#endif
			restore(ps);
			return(SYSERR);
		}
	if (fpidinlock(pid,ldes)==0)
	{
		restore(ps);
		return(SYSERR);
	}
#ifdef DEBUGF
		kprintf("\nPast error check sptr->semcnt:%d\n",sptr->semcnt);
#endif
		proctab[pid].lnosheld--;
	if ((sptr->semcnt++) < 0)
	{
#ifdef DEBUGD
		kprintf("\nInside if,sptr->lstate:%d, sptr->nordu:%d \n",sptr->lstate,sptr->nordu);
#endif
		if ( ((sptr->lstate==READ) && (--sptr->nordu==0)) || (sptr->lstate==WRITE))
		{
#ifdef DEBUGC
		kprintf("\nInside second if sptr->hprd:%d sptr->hpwrt:%d\n",sptr->hprd,sptr->hpwrt);
#endif
			if (sptr->hprd>sptr->hpwrt)
			{
				//release all readers with hprd
#ifdef DEBUGC
		kprintf("\nReleasing readers\n");
#endif
				tail=sptr->sqtail;
				prev=q[tail].qprev;

				while (q[prev].qkey==sptr->hprd)
				{
					pptr=&proctab[prev];
					if (pptr->lstate==READ)
					{
						dequeue(prev);
						ready(prev,RESCHNO);
						lreschedyes=1;
					}
					prev=q[prev].qprev;

				}
				sptr->hprd=hpp(ldes,READ);
				//resched();
				restore(ps);
				return (OK);
			}
			if (sptr->hpwrt>sptr->hprd)
			{
#ifdef DEBUGD
		kprintf("\nReleasing writer\n");
#endif
				//release hpwrt
				tail=sptr->sqtail;
				prev=q[tail].qprev;
				while (q[prev].qkey==sptr->hpwrt)
				{
					pptr=&proctab[prev];
					if (pptr->lstate==WRITE)
					{
						dequeue(prev);
						sptr->hpwrt=hpp(ldes,WRITE);
#ifdef DEBUGD
		kprintf("\nReleasing writer pid%d for lock %d, new hpwrt= %d\n",prev,ldes,sptr->hpwrt);
#endif
						ready(prev,RESCHNO);
						lreschedyes=1;
						restore(ps);
						return (OK);
					}
					prev=q[prev].qprev;

				}


			}

			if (sptr->hprd==sptr->hpwrt)
			{

				if (sptr->wtime-sptr->rtime>1000)
				{
#ifdef DEBUGC
		kprintf("\nReleasing readers priority equal\n");
#endif
					//release all readers with hprd
					tail=sptr->sqtail;
					prev=q[tail].qprev;

					while (q[prev].qkey==sptr->hprd)
					{
						pptr=&proctab[prev];
						if (pptr->lstate==READ)
						{
							dequeue(prev);
							ready(prev,RESCHNO);
							lreschedyes=1;
						}
						prev=q[prev].qprev;

					}
					sptr->hprd=hpp(ldes,READ);
					//resched();
					restore(ps);
					return (OK);

				}
				else
				{
					//release hpwrt
					tail=sptr->sqtail;
					prev=q[tail].qprev;
					while (q[prev].qkey==sptr->hprd)
					{
						pptr=&proctab[prev];
						if (pptr->lstate==WRITE)
						{
							dequeue(prev);
							sptr->hpwrt=hpp(ldes,WRITE);
							ready(prev,RESCHNO);
							lreschedyes=1;
							restore(ps);
							return (OK);
						}
						prev=q[prev].qprev;

					}


				}
			}
		}
	}
	restore(ps);
	return OK;

}