Exemple #1
0
Announce::Announce(string _areamask, string _msgbase, string _msg_from, 
           string _aka, string _msg_to, string _msg_subject, 
           string _templ, string _origin) : areamask(), msgbase(), msg_from(_msg_from), 
           aka(_aka), msg_to(_msg_to), msg_subject(_msg_subject), templ(_templ), 
           origin(_origin), local(false) { 
  vector<string> v;
  SplitLine(_areamask, (*this).areamask, ',');
  SplitLine(_msgbase, v, ':');
  (*this).msgbase.first = StringToInt(v[0]);
  (*this).msgbase.second = StringToInt(v[1]);
    
  if((*this).aka.isEmpty()) {
    (*this).local = true;
  }
}
hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) {
    Entity *e = SK.GetEntity(he);
    int entityType = e->type;

    hEntity ret;
    if(e->IsCircle()) {
        ret = SplitCircle(he, pinter);
    } else if(e->type == Entity::LINE_SEGMENT) {
        ret = SplitLine(he, pinter);
    } else if(e->type == Entity::CUBIC || e->type == Entity::CUBIC_PERIODIC) {
        ret = SplitCubic(he, pinter);
    } else {
        Error("Couldn't split this entity; lines, circles, or cubics only.");
        return Entity::NO_ENTITY;
    }

    // Finally, delete the request that generated the original entity.
    int reqType = EntReqTable::GetRequestForEntity(entityType);
    SK.request.ClearTags();
    for(int i = 0; i < SK.request.n; i++) {
        Request *r = &(SK.request.elem[i]);
        if(r->group.v != activeGroup.v) continue;
        if(r->type != reqType) continue;
    
        // If the user wants to keep the old entities around, they can just
        // mark them construction first.
        if(he.v == r->h.entity(0).v && !r->construction) {
            r->tag = 1;
            break;
        }
    }
    DeleteTaggedRequests();

    return ret;
}
Exemple #3
0
int EBuffer::LineNew() {
    if (SplitLine(VToR(CP.Row), CP.Col) == 0)
        return 0;

    if (!MoveDown())
        return 0;

    if (CP.Col > 0) {

        if (!MoveLineStart())
            return 0;

        //int Indent = LineIndented(VToR(CP.Row));

        if (!LineIndent())
            return 0;

        //if (Indent > 0)
        //  if (InsText(Row, C, Indent, 0) == 0)
        //    return 0;

        if (BFI(this, BFI_Trim))
            if (TrimLine(VToR(CP.Row - 1)) == 0)
                return 0;
    }
    return 1;
}
Exemple #4
0
void DFSpells::SaveSchool(std::ofstream &fout, School *school)
{
	char buffer[256];
	std::vector <std::string> lines;

	fout << "\n\n#---------------------------------------------\n";

	sprintf(buffer, "S:%s,%s,%s,%s,%s,%s,%s,%s", school->name.c_str(),school->deity.c_str(),school->skill.c_str(),school->resistSkill.c_str(),
			school->r.c_str(),school->g.c_str(),school->b.c_str(),school->symbol.c_str());
	fout << buffer;

	SplitLine( school->deityDescription, lines);
	for ( unsigned int i = 0; i < lines.size(); i++ )
		fout << "\nG:" << lines[i];

	// donations
	for ( unsigned int i = 0; i < school->lowDonation.size(); i++ )
		fout << "\nL:" << school->lowDonation[i];
	for ( unsigned int i = 0; i < school->neutralDonation.size(); i++ )
		fout << "\nN:" << school->neutralDonation[i];
	for ( unsigned int i = 0; i < school->highDonation.size(); i++ )
		fout << "\nH:" << school->highDonation[i];

	fout << "\n#---------------------------------------------\n\n";

	std::vector<Spell*>::iterator itr;
	for ( itr = school->spells.begin(); itr != school->spells.end(); itr++ )
	{
		SaveSpell(fout, *itr);
	}
}
Exemple #5
0
std::vector<std::string> Log::GetLines(int quantity, int width, int skipLines) {
	std::vector<std::string> lines;

	if(quantity <= 0 || width <= 0)
		return lines;

	std::vector<std::string> buffer;

	if((int) list.size() - quantity - skipLines <= 0) {
		if((int) list.size() > quantity)
			skipLines = list.size() - quantity;
		else
			skipLines = 0;
	}

	int firstLine = list.size() - 1 - skipLines;
	int lastLine = list.size() - skipLines - quantity;
	if(lastLine < 0)
		lastLine = 0;

	for(int line = firstLine; line >= lastLine; --line) {
		buffer = SplitLine(line, width);
		lines.reserve(lines.size() + buffer.size());
		lines.insert(lines.end(), buffer.begin(), buffer.end());
	}

	while((int) lines.size() > quantity)
		lines.erase(lines.end());

	return lines;
}
Exemple #6
0
bool Plane::Split(const vector<Vector3F>& vIn, vector<Vector3F>& vFront, vector<Vector3F>& vBack) const
{
	if(vIn.empty())
	{
		return false;
	}

	unsigned int NumOfInVectors = vIn.size();
	if(NumOfInVectors <= 2)
	{
		return false;
	}

	vFront.clear();
	vBack.clear();

	int iThisIndex = NumOfInVectors - 1;
	int iNextIndex = 0;

	RelativeLocation plThis = TestPoint(vIn[iThisIndex]);
	RelativeLocation plNext;

	for(iNextIndex = 0; iNextIndex < NumOfInVectors; ++iNextIndex)
	{
		plNext = TestPoint(vIn[iNextIndex]);

		if(plThis == RL_FRONT)
		{
			vFront.push_back(vIn[iThisIndex]);
		}
		else if(plThis == RL_BACK)
		{
			vBack.push_back(vIn[iThisIndex]);
		}
		else
		{
			vFront.push_back(vIn[iThisIndex]);
			vBack.push_back(vIn[iThisIndex]);
		}

		if((plThis == RL_FRONT && plNext == RL_BACK) || (plThis == RL_BACK && plNext == RL_FRONT))
		{
			Vector3F vSplit = SplitLine(vIn[iThisIndex], vIn[iNextIndex]);
			vFront.push_back(vSplit);
			vBack.push_back(vSplit);
		}

		iThisIndex = iNextIndex;
		plThis = plNext;
	}

	if(vFront.size() >= 3 && vBack.size() >= 3)
	{
		return true;
	}
	return false;
}
Exemple #7
0
void SimRender::ConstructSquareOnGround(const CSimContext& context, float x, float z, float w, float h, float a,
		SOverlayLine& overlay, bool floating)
{
	overlay.m_Coords.clear();

	CmpPtr<ICmpTerrain> cmpTerrain(context, SYSTEM_ENTITY);
	if (cmpTerrain.null())
		return;

	float water = 0.f;
	if (floating)
	{
		CmpPtr<ICmpWaterManager> cmpWaterMan(context, SYSTEM_ENTITY);
		if (!cmpWaterMan.null())
			water = cmpWaterMan->GetExactWaterLevel(x, z);
	}

	float c = cos(a);
	float s = sin(a);

	std::vector<std::pair<float, float> > coords;

	// Add the first vertex, since SplitLine will be adding only the second end-point of the each line to
	// the coordinates list. We don't have to worry about the other lines, since the end-point of one line
	// will be the starting point of the next
	coords.push_back(std::make_pair(x - w/2*c + h/2*s, z + w/2*s + h/2*c));

	SplitLine(coords, x - w/2*c + h/2*s, z + w/2*s + h/2*c, x - w/2*c - h/2*s, z + w/2*s - h/2*c);
	SplitLine(coords, x - w/2*c - h/2*s, z + w/2*s - h/2*c, x + w/2*c - h/2*s, z - w/2*s - h/2*c);
	SplitLine(coords, x + w/2*c - h/2*s, z - w/2*s - h/2*c, x + w/2*c + h/2*s, z - w/2*s + h/2*c);
	SplitLine(coords, x + w/2*c + h/2*s, z - w/2*s + h/2*c, x - w/2*c + h/2*s, z + w/2*s + h/2*c);

	overlay.m_Coords.reserve(coords.size() * 3);

	for (size_t i = 0; i < coords.size(); ++i)
	{
		float px = coords[i].first;
		float pz = coords[i].second;
		float py = std::max(water, cmpTerrain->GetExactGroundLevel(px, pz)) + RENDER_HEIGHT_DELTA;
		overlay.m_Coords.push_back(px);
		overlay.m_Coords.push_back(py);
		overlay.m_Coords.push_back(pz);
	}
}
Exemple #8
0
int EBuffer::InsertString(const char *aStr, int aCount) {
    int P;
    int C, L;
    int Y = VToR(CP.Row);

    if (BFI(this, BFI_InsertKillBlock) == 1)
        if (CheckBlock() == 1)
            if (BlockKill() == 0)
                return 0;

    if (BFI(this, BFI_Insert) == 0)
        if (CP.Col < LineLen())
            if (KillChar() == 0)
                return 0;
    if (InsText(Y, CP.Col, aCount, aStr) == 0)
        return 0;
    C = CP.Col;
    L = VToR(CP.Row);
    P = CharOffset(RLine(L), C);
    P += aCount;
    C = ScreenPos(RLine(L), P);
    if (SetPos(C, CP.Row) == 0)
        return 0;
    if (BFI(this, BFI_Trim) && *aStr != '\t')
        if (TrimLine(L) == 0)
            return 0;
    if (BFI(this, BFI_WordWrap) == 2) {
        if (DoWrap(0) == 0) return 0;
    } else if (BFI(this, BFI_WordWrap) == 1) {
        int P, C = CP.Col;
        PELine LP;
        int L;

        if (C > BFI(this, BFI_RightMargin)) {
            L = CP.Row;

            C = BFI(this, BFI_RightMargin);
            P = CharOffset(LP = RLine(L), C);
            while ((C > BFI(this, BFI_LeftMargin)) &&
                    ((LP->Chars[P] != ' ') &&
                     (LP->Chars[P] != 9)))
                C = ScreenPos(LP, --P);

            if (P <= BFI(this, BFI_LeftMargin)) {
                C = BFI(this, BFI_RightMargin);
            } else
                C = ScreenPos(LP, P);
            if (SplitLine(L, C) == 0) return 0;
            IndentLine(L + 1, BFI(this, BFI_LeftMargin));
            if (SetPos(CP.Col - C - 1 + BFI(this, BFI_LeftMargin), CP.Row + 1) == 0) return 0;
        }
    }
    return 1;
}
Exemple #9
0
static void LoadGimpPalette(FILE* fp, Palette& pal)
{
    int idx=0;

    char line[256];
    int linenum=0;
    bool gotcookie=false;
    while( fgets( line, sizeof(line), fp ) )
    {
        ++linenum;
        std::vector< std::string > args;
        SplitLine(line, args);
        if( args.empty() )
            continue;

        if( !gotcookie )
        {
            if(args.size()==2 && args[0] == "GIMP" && args[1] == "Palette")
                gotcookie = true;
            else
                throw Exception("not a GIMP palette");
        }

        if( args[0] == "Name:" )
        {
            continue;
        }
        if( args[0] == "Column:" )
        {
            continue;
        }


        if( args.size() >= 3 && idx <=255 )
        {
            RGBx c;
            c.r = atoi( args[0].c_str() );
            c.g = atoi( args[1].c_str() );
            c.b = atoi( args[2].c_str() );
            // ignore name, if there is one

            pal.SetColour(idx,c);
            ++idx;
        }
    }

    if( !feof(fp ) )
    {
        throw Exception( "read error" );
    }

    pal.SetNumColours(idx);
}
Exemple #10
0
void CRemoteConsole :: ProcessPacket( const QByteArray &data, const QHostAddress &sender, const quint16 &senderPort )
{
	QString message( data );
	message = message.trimmed();
	
	if (!message.isEmpty())
	{
		QString cmd;
		QString payload;
		QString target;
		SplitLine( message, cmd, payload, target );
		
		CRemoteConsoleClient *client = NULL;
		for( QList<CRemoteConsoleClient *> :: iterator i = m_KnownClients.begin( ); i != m_KnownClients.end( ); i++ )
		{
			if( (*i)->GetAddress( ) == sender && (*i)->GetPort() == senderPort )
			{
				client = *i;
				// update LastReceived time
				//client->Pong( );
				break;
			}
		}
	}
	
	for( QList<CRemoteConsoleClient *> :: iterator i = m_KnownClients.begin( ); i != m_KnownClients.end( ); )
	{
		//(*i)->AutoBroadcast( m_GHost->m_CurrentGame, m_GHost->m_AdminGame );
		
		/*if( GetTime( ) > (*i)->GetLastReceived( ) + m_KeepAliveTime + m_Timeout && (*i)->IsAuthed( ) )
		{
			// user has not responded in time, de-auth him
			(*i)->SetAuthed( false );
			(*i)->Send( "[RCON] Your session timed out" );
			CONSOLE_Print("[RCON] User [" + (*i)->GetIPString( ) + "] timed out");
		}
		else if( GetTime( ) > (*i)->GetLastReceived( ) + m_KeepAliveTime
				&& GetTime( ) > (*i)->GetLastPinged( ) + m_KeepAliveInterval )
		{
			// user has not sent an command in quite some time, send him a keep-alive packet (containing the word "PING")
			(*i)->Ping( );
		}
		
		if ( !(*i)->IsAuthed( ) && !(*i)->IsBanned( ) )
		{
			delete *i;
			i = m_KnownClients.erase( i );
		}
		else
			i++;*/
	}
}
Exemple #11
0
std::vector<std::string> SplitToLines(const std::string &crStr, ulong nMaxLen)
{
    std::vector<std::string> atResult;
    std::vector<std::string> atInitialLines = SplitString('\n', crStr);

    for (auto strLine: atInitialLines)
    {
        std::vector<std::string> atLines = SplitLine(strLine, nMaxLen);
        atResult.insert(atResult.end(), atLines.begin(), atLines.end());
    }

    return std::move(atResult);
}
Exemple #12
0
bool Plane::Split(const Polygon<Vector3F>& mpIn, Polygon<Vector3F>* pmpFront, Polygon<Vector3F>* pmpBack) const
{
	if(!pmpFront || !pmpBack || mpIn.m_iCurrentNumVectors <= 2)
	{
		return false;
	}

	pmpFront->m_iCurrentNumVectors = 0;
	pmpBack->m_iCurrentNumVectors = 0;

	int iThisIndex = mpIn.m_iCurrentNumVectors - 1;
	int iNextIndex = 0;

	RelativeLocation plThis = TestPoint(mpIn.m_vList[iThisIndex]);
	RelativeLocation plNext;

	for(; iNextIndex < mpIn.m_iCurrentNumVectors; ++iNextIndex)
	{
		plNext = TestPoint(mpIn.m_vList[iNextIndex]);

		if(plThis == RL_FRONT)
		{
			pmpFront->m_vList[pmpFront->m_iCurrentNumVectors++] = mpIn.m_vList[iThisIndex];
		}
		else if(plThis == RL_BACK)
		{
			pmpBack->m_vList[pmpBack->m_iCurrentNumVectors++] = mpIn.m_vList[iThisIndex];
		}
		else
		{
			pmpFront->m_vList[pmpFront->m_iCurrentNumVectors++] = mpIn.m_vList[iThisIndex];
			pmpBack->m_vList[pmpBack->m_iCurrentNumVectors++] = mpIn.m_vList[iThisIndex];
		}

		if((plThis == RL_FRONT && plNext == RL_BACK) || (plThis == RL_BACK && plNext == RL_FRONT))
		{
			Vector3F mvSplit = SplitLine(mpIn.m_vList[iThisIndex], mpIn.m_vList[iNextIndex]);
			pmpFront->m_vList[pmpFront->m_iCurrentNumVectors++] = mvSplit;
			pmpBack->m_vList[pmpBack->m_iCurrentNumVectors++] = mvSplit;
		}

		iThisIndex = iNextIndex;
		plThis = plNext;
	}

	if(pmpFront->m_iCurrentNumVectors >= 3 && pmpBack->m_iCurrentNumVectors >= 3)
	{
		return true;
	}
	return false;
}
Exemple #13
0
void __fastcall TPrnMaterialForm::DetailBand1BeforePrint(
      TQRCustomBand *Sender, bool &PrintBand)
{
  	AnsiString szRem=cp_name->DataSet->FieldByName("mn_rem")->AsString;
  CStringArray lstLine;
  int i;
  QRMemo1->Lines->Clear();

  SplitLine(szRem.c_str(),lstLine);
  for(i=0;i<lstLine.GetSize();i++)
  {
  	QRMemo1->Lines->Add((LPCSTR)lstLine[i]);
  }
   //	QRMemo1->Text=cp_name->DataSet->FieldByName("mn_rem")->AsString;
}
Exemple #14
0
void DFSkills::Save()
{
	std::ofstream fout( GetDataPath("%s/world/skillsTEST"), std::ios::binary);

	/**
	  * Possible improvement: set out skills in class sections as already done in skills.txt
	  * To do this class data will probably need to be saved, or comments read to determine what
	  * section a skill belongs in
	  * (Probably the latter)
	  */
	fout << "# Special skills\n"
		 << "# Key:\n"
		 << "# S:name,squirrel name,type[,event],icon_x,icon_y\n"
		 << "# where:\n"
		 << "# squirrel name is the postfix part of a two Squirrel functions:\n"
		 << "# prereq<squirrel name> is called for the prerequisite it should return a true/false value\n"
		 << "# action<squirrel name> is called to performt the action,when activating the skill\n"
		 << "# icon tile x,y are from spells.bmp\n"
		 << "# D:Description of skill (multiple lines)\n"
		 << "#\n"
		 << "# type is: (M-manual,A-automatic)\n"
		 << "# event is: (A-armor)\n"
		 << "#\n"
		 << "# The prereq function can be slow-ish, but the action should execute\n"
		 << "# fast.\n"
		 << "#\n"
		 << "# TODO: add prereq special skills here to create a rough tree of what\n"
		 << "# sages show. This also helps with not running too many prereq functions.\n\n";

	std::vector <std::string> lines;
	for ( std::vector<SpecialSkill*>::iterator itr = data.begin(); itr != data.end(); itr++ )
	{
		fout << "S:" << (*itr)->name << ',' << (*itr)->squirrelName << ','
			 << (*itr)->type << ',';
		if ( (*itr)->type == "A" )
			fout << (*itr)->event << ',';
		fout << (*itr)->icon_x << ',' << (*itr)->icon_y;

		SplitLine((*itr)->description,lines);
		for ( unsigned int i = 0; i < lines.size(); i++ )
			fout << "\nD:" << lines[i];

		fout << "\n\n";
	}

	fout.close();
}
Exemple #15
0
bool MipsAssembleOpcode(const char* line, DebugInterface* cpu, u32 address, u32& dest)
{
	char name[64],args[256];
	SplitLine(line,name,args);

	CMipsInstruction Opcode(cpu);
	if (cpu == NULL || Opcode.Load(name,args,(int)address) == false)
	{
		return false;
	}
	if (Opcode.Validate() == false)
	{
		return false;
	}

	Opcode.Encode();
	dest = Opcode.getEncoding();

	return true;
}
Exemple #16
0
void DFSpells::SaveSpell(std::ofstream &fout, Spell *spell)
{
	char buffer[256];
	std::vector <std::string> lines;

	sprintf(buffer, "P:%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
			spell->name.c_str(), spell->symbol.c_str(), spell->level.c_str(), spell->mana.c_str(), spell->exp.c_str(),
			spell->failureRate.c_str(), spell->action.c_str(), spell->distance.c_str(), spell->area.c_str(),
			spell->speed.c_str(), spell->effect.c_str(), spell->target.c_str(), spell->icon_x.c_str(), spell->icon_y.c_str(),
			spell->disposition.c_str(), spell->prerequisite.c_str());
	fout << buffer;

	fout << "\nW:" << spell->sound;

	SplitLine(spell->notes, lines);
	for ( unsigned int i = 0; i < lines.size(); i++ )
		fout << "\nD:" << lines[i];

	fout << "\n\n";
}
void ImageSegmenter::SplitLinesIntoWords(const Mat& img)
{
	
	// Scan the line boundaries array and for each entry
	// split the line into words
	//cout << "Lines size=" << m_lineBoundaries.size() << endl;
	for(unsigned int i = 0 ; i < m_lineBoundaries.size() ; i++) {
		pair<unsigned int,unsigned int> currLineBoundaries = m_lineBoundaries.at(i);
		unsigned int currLineTop = currLineBoundaries.first;
		unsigned int currLineBottom = currLineBoundaries.second;
		//cout << "Line: " << currLineTop << " " << currLineBottom << endl;
		//cout << "Rect [0," << currLineTop << "," << m_docImage.cols << "," << currLineBottom-currLineTop+1 << "]" << endl; 
		Mat lineImg(m_docImage,cv::Rect(0,currLineTop,m_docImage.cols,currLineBottom-currLineTop+1));

		vector< pair<unsigned int,unsigned int> > wordBoundaries;
		SplitLine(lineImg,wordBoundaries);	
		m_wordBoundaries.push_back(wordBoundaries);
	}
		
}
Exemple #18
0
static void ParseLine(gus_config_t *config, char *line)
{
    char *fields[6];
    unsigned int num_fields;
    unsigned int instr_id, mapped_id;

    num_fields = SplitLine(line, fields, 6);

    if (num_fields < 6)
    {
        return;
    }

    instr_id = atoi(fields[0]);
    mapped_id = atoi(fields[MappingIndex()]);

    free(config->patch_names[instr_id]);
    config->patch_names[instr_id] = M_StringDuplicate(fields[5]);
    config->mapping[instr_id] = mapped_id;
}
Exemple #19
0
// ac and av are commandline options passed along from main()
// Commandline options override config file options.
void ZigConfig::Init( int ac, char* av[] )
{
	// try to read in opts from file
	{
		std::string inname = JoinPath( ZigUserDir(), "options" );
		std::ifstream in( inname.c_str() );
		int linenum = 0;
		while( in.good() )
		{
			std::string line;
			std::getline( in, line );
			++linenum;

			std::vector< std::string > opts;
			SplitLine( line, opts );

			if( opts.empty() )		// ignore blank lines
				continue;

			ApplyOption( *this, opts );
		}
	}

	// now apply commandline opts on top.
	int i=1;
	while( i<ac )
	{
		std::vector< std::string > opt;
		if( av[i][0] != '-' )
			throw Wobbly( "Syntax error: '%s'", av[i] );
		opt.push_back( &av[i][1] );
		++i;
		// collect args for this option
		while( i<ac && av[i][0] != '-' )
		{
			opt.push_back( av[i] );
			++i;
		}
		ApplyOption( *this, opt );
	}
}
void FreeNavProcedureReader::ReadStarFile(std::string Filename, std::vector<Procedure>& procedures) {
  std::ifstream filehandle(Filename.c_str());
  std::string line;
    
  if(filehandle.is_open()) {
    while(getline(filehandle, line)) {
      std::vector<std::string> elements;
      SplitLine(line, elements, ',');
      
      if(elements.size() > 1) {
        
        Procedure procedure = this->ReadProcedureLine(elements, true);
        
        for(size_t i=4; i < elements.size(); i = i+15) {
          this->ReadStarWaypoint(elements, procedure, i);
        }
        
        procedures.push_back(procedure);
      }
    }
  }
}
Exemple #21
0
bool Plane::Clip(const Polygon<Vector3F>& mpIn, Polygon<Vector3F>* pmpOut) const
{
	if(!pmpOut || mpIn.m_iCurrentNumVectors <= 2)
	{
		return false;
	}

	int iThisIndex = mpIn.m_iCurrentNumVectors - 1;
	int iNextIndex = 0;

	RelativeLocation plThis = TestPoint(mpIn.m_vList[iThisIndex]);
	RelativeLocation plNext;

	pmpOut->m_iCurrentNumVectors = 0;

	for(iNextIndex = 0; iNextIndex < mpIn.m_iCurrentNumVectors; ++iNextIndex)
	{
		plNext = TestPoint(mpIn.m_vList[iNextIndex]);

		if(plThis == RL_FRONT || plThis == RL_COPLANAR)
		{
			pmpOut->m_vList[pmpOut->m_iCurrentNumVectors++] = mpIn.m_vList[iThisIndex];
		}

		if((plThis == RL_BACK && plNext == RL_FRONT) || (plThis == RL_FRONT && plNext == RL_BACK))
		{
			pmpOut->m_vList[pmpOut->m_iCurrentNumVectors++] = SplitLine(mpIn.m_vList[iThisIndex], mpIn.m_vList[iNextIndex]);
		}

		iThisIndex = iNextIndex;
		plThis = plNext;
	}

	if(pmpOut->m_iCurrentNumVectors >= 3)
	{
		return true;
	}
	return false;
}
Exemple #22
0
static void PartitionLineList(plane_t plane, bspline_t *list, bspline_t **sides)
{
	sides[0] = NULL;
	sides[1] = NULL;
	
	for (; list; list = list->next)
	{
		bspline_t *split[2];
		int i;

		SplitLine(plane, list, globalepsilon, &split[0], &split[1]);

		// process the front (0) and back (1) splits
		for (i = 0; i < 2; i++)
		{
			if (split[i])
			{
				split[i]->next = sides[i];
				sides[i] = split[i];
			}
		}
	}
}
Exemple #23
0
bool Plane::Split(const LineSeg& mlsIn, LineSeg* pmlsFront, LineSeg* pmlsBack) const
{
	Vector3F temp = SplitLine(mlsIn.v0, mlsIn.v1);

	if(TestPoint(mlsIn.v0) == RL_FRONT)
	{
		pmlsFront->v0 = mlsIn.v0;
		pmlsFront->v1 = temp;
		pmlsBack->v0 = temp;
		pmlsBack->v1 = mlsIn.v1;
		return true;
	}
	else
	{
		pmlsFront->v0 = temp;
		pmlsFront->v1 = mlsIn.v1;
		pmlsBack->v0 = mlsIn.v0;
		pmlsBack->v1 = temp;
		return true;
	}

	return false;
}
Exemple #24
0
bool MipsAssembleOpcode(const char* line, DebugInterface* cpu, u32 address, u32& dest, std::string& errorText)
{
	char name[64],args[256];
	SplitLine(line,name,args);

	CMipsInstruction opcode(cpu);
	if (cpu == NULL || opcode.Load(name,args,(int)address) == false)
	{
		errorText = opcode.getErrorMessage();
		return false;
	}

	if (opcode.Validate() == false)
	{
		errorText = "Parameter failure.";
		return false;
	}

	opcode.Encode();
	dest = opcode.getEncoding();

	return true;
}
Exemple #25
0
/*----------------------*
 * Paste from Clipboard *
 *----------------------*/
BOOL PasteClip (LONG x, struct line_node *actline, struct InstData *data)
{
  struct line_node *line = NULL;
  struct line_node *startline = NULL;
  struct line_node *previous = NULL;
  UWORD   *styles = NULL;
  UWORD   *colors = NULL;
  STRPTR  textline;
  BOOL newline = TRUE;
  BOOL res = FALSE;

  ENTER();

  if(InitClipboard(data, IFFF_READ))
  {
    if(StopChunk(data->iff, ID_FTXT, ID_CHRS) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_FLOW) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_HIGH) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_SBAR) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_COLS) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_STYL) == 0 &&
       StopChunk(data->iff, ID_FTXT, ID_CSET) == 0)
    {
      LONG error, codeset = 0;
      UWORD flow = MUIV_TextEditor_Flow_Left;
      UWORD color = FALSE;
      UWORD separator = 0;
      BOOL ownclip = FALSE;
      LONG updatefrom;

      while(TRUE)
      {
        struct ContextNode *cn;

        error = ParseIFF(data->iff, IFFPARSE_SCAN);
        SHOWVALUE(DBF_CLIPBOARD, error);
        if(error == IFFERR_EOC)
          continue;
        else if(error)
          break;

        if((cn = CurrentChunk(data->iff)) != NULL)
        {
          switch (cn->cn_ID)
          {
            case ID_CSET:
              D(DBF_CLIPBOARD, "reading FLOW");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(cn->cn_Size >= 4)
              {
                /* Only the first four bytes are interesting */
                if(ReadChunkBytes(data->iff, &codeset, 4) != 4)
                {
                  codeset = 0;
                }
                SHOWVALUE(DBF_CLIPBOARD, codeset);
              }
              break;

            case ID_FLOW:
              D(DBF_CLIPBOARD, "reading FLOW");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(cn->cn_Size == 2)
              {
                if(ReadChunkBytes(data->iff, &flow, 2) == 2)
                  if(flow > MUIV_TextEditor_Flow_Right)
                    flow = MUIV_TextEditor_Flow_Left;
                SHOWVALUE(DBF_CLIPBOARD, flow);
              }
              break;

            case ID_HIGH:
              D(DBF_CLIPBOARD, "reading HIGH");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if (cn->cn_Size == 2)
              {
                error = ReadChunkBytes(data->iff, &color, 2);
                SHOWVALUE(DBF_CLIPBOARD, color);
                SHOWVALUE(DBF_CLIPBOARD, error);
              }
              break;

            case ID_SBAR:
              D(DBF_CLIPBOARD, "reading SBAR");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if (cn->cn_Size == 2)
              {
                error = ReadChunkBytes(data->iff, &separator, 2);
                SHOWVALUE(DBF_CLIPBOARD, separator);
                SHOWVALUE(DBF_CLIPBOARD, error);
              }
              break;

            case ID_COLS:
              D(DBF_CLIPBOARD, "reading COLS");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              if(colors)
              {
                MyFreePooled(data->mypool, colors);
                colors = NULL;
              }
              // allocate one word more than the chunk tell us, because we terminate the array with an additional value
              if(cn->cn_Size > 0 && (colors = (UWORD *)MyAllocPooled(data->mypool, cn->cn_Size + sizeof(UWORD))) != NULL)
              {
                error = ReadChunkBytes(data->iff, colors, cn->cn_Size);
                SHOWVALUE(DBF_CLIPBOARD, error);
                colors[cn->cn_Size / 2] = 0xffff;
              }
              break;

            case ID_STYL:
              D(DBF_CLIPBOARD, "reading STYL");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);
              ownclip = TRUE;
              if(styles)
              {
                MyFreePooled(data->mypool, styles);
                styles = NULL;
              }
              // allocate one word more than the chunk tell us, because we terminate the array with an additional value
              if(cn->cn_Size > 0 && (styles = (UWORD *)MyAllocPooled(data->mypool, cn->cn_Size + sizeof(UWORD))) != NULL)
              {
                error = ReadChunkBytes(data->iff, styles, cn->cn_Size);
                SHOWVALUE(DBF_CLIPBOARD, error);
                styles[cn->cn_Size / 2] = EOS;
              }
              break;

            case ID_CHRS:
            {
              D(DBF_CLIPBOARD, "reading CHRS");
              SHOWVALUE(DBF_CLIPBOARD, cn->cn_Size);

              data->HasChanged = TRUE;

              if(cn->cn_Size > 0 && !ownclip)
              {
                char *contents;
                ULONG length = cn->cn_Size;

                if((contents = (char *)MyAllocPooled(data->mypool, length + 1)) != NULL)
                {
                  error = ReadChunkBytes(data->iff, contents, length);
                  SHOWVALUE(DBF_CLIPBOARD, error);

                  if(contents[length - 1] != '\n')
                  {
                    newline = FALSE;
                  }
                  else
                  {
                    length--;
                  }
                  contents[length] = '\0';

                  #if defined(__MORPHOS__)
                  if (codeset == CODESET_UTF8)
                  {
                    if (IS_MORPHOS2)
                      contents = utf8_to_ansi(data, contents);
                  }
                  #endif

                  if((line = ImportText(contents, data, &ImPlainHook, data->ImportWrap)))
                  {
                    if(!startline)
                      startline = line;
                    if(previous)
                      previous->next  = line;

                    line->previous    = previous;
                    line->visual    = VisualHeight(line, data);
                    data->totallines += line->visual;
                    while(line->next)
                    {
                      line = line->next;
                      line->visual    = VisualHeight(line, data);
                      data->totallines += line->visual;
                    }
                    previous = line;
                  }
                  MyFreePooled(data->mypool, contents);
                }
              }
              else
              {
                ULONG length = cn->cn_Size;

                if(length > 0 && (textline = (char *)MyAllocPooled(data->mypool, length + 2)) != NULL)
                {
                  error = ReadChunkBytes(data->iff, textline, length);
                  SHOWVALUE(DBF_CLIPBOARD, error);

                  if (textline[length - 1] != '\n')
                  {
                    newline = FALSE;
                    textline[length] = '\n';
                    length++;
                  }
                  textline[length] = '\0';

                  if((line = AllocLine(data)))
                  {
                    line->next     = NULL;
                    line->previous   = previous;
                    line->line.Contents   = textline;
                    line->line.Length   = length;
                    line->visual   = VisualHeight(line, data);
                    line->line.Color    = color;
                    line->line.Flow     = flow;
                    line->line.Separator = separator;
                    line->line.Styles   = styles;
                    line->line.Colors   = colors;
                    data->totallines += line->visual;

                    if(!startline)
                      startline = line;
                    if(previous)
                      previous->next  = line;

                    previous = line;
                  }
                  else
                  {
                    if(styles)
                      MyFreePooled(data->mypool, (void *)styles);
                    if(colors)
                      MyFreePooled(data->mypool, (void *)colors);
                  }
                }
                else
                {
                  if(styles)
                    MyFreePooled(data->mypool, styles);
                  if(colors)
                    MyFreePooled(data->mypool, (void *)colors);
                }
                styles    = NULL;
                colors    = NULL;
                flow      = MUIV_TextEditor_Flow_Left;
                color     = FALSE;
                separator = 0;
                ownclip   = FALSE;
              }
            }
            break;
          }
        }
      }

      if(line)
      {
        BOOL oneline = FALSE;

        SplitLine(x, actline, FALSE, NULL, data);
        line->next = actline->next;
        actline->next->previous = line;
        actline->next = startline;
        startline->previous = actline;
        data->CPos_X = line->line.Length-1;
        if(actline->next == line)
        {
          data->CPos_X += actline->line.Length-1;
          oneline = TRUE;
        }
        if(!newline)
          MergeLines(line, data);
        MergeLines(actline, data);
        if(oneline)
          line = actline;
        if(newline)
        {
          line = line->next;
          data->CPos_X = 0;
        }
        data->actualline = line;
      }
      else
      {
        switch(error)
        {
          case IFFERR_MANGLED:
          case IFFERR_SYNTAX:
          case IFFERR_NOTIFF:
            D(DBF_CLIPBOARD, "no FTXT clip!");
            DoMethod(data->object, MUIM_TextEditor_HandleError, Error_ClipboardIsNotFTXT);
            break;
          default:
            D(DBF_CLIPBOARD, "clipboard is empty!");
            DoMethod(data->object, MUIM_TextEditor_HandleError, Error_ClipboardIsEmpty);
            break;
        }
      }
      data->update = TRUE;

      ScrollIntoDisplay(data);
      updatefrom = LineToVisual(actline, data)-1;
      if(updatefrom < 0)
        updatefrom = 0;
      DumpText(data->visual_y+updatefrom, updatefrom, data->maxlines, TRUE, data);

      if(data->update)
        res = TRUE;
      else
        data->update = TRUE;
    }

    EndClipSession(data);
  }

  RETURN(res);
  return res;
}
Exemple #26
0
int EBuffer::DoWrap(int WrapAll) {
    int L, Len, C, P, Ind;
    PELine LP;
    int Left = BFI(this, BFI_LeftMargin), Right = BFI(this, BFI_RightMargin);
    int FirstParaLine;
    int NoChange = 0, NoChangeX = 0;

    if (Left >= Right) return 0;

    L = VToR(CP.Row);

    FirstParaLine = 0;
    if (L > 0)
        if (IsLineBlank(L - 1)) FirstParaLine = L;

    while (L < RCount) {
        NoChange = 1;

        if (VToR(CP.Row) != L || L != FirstParaLine) {
            if (VToR(CP.Row) == L)
                if (CP.Col <= LineIndented(L))
                    if (SetPos(Left, CP.Row) == 0) WFAIL(1);
            Ind = IndentLine(L, Left);
            if (VToR(CP.Row) == L)
                if (SetPos((CP.Col + Ind > 0) ? CP.Col + Ind : 0, CP.Row) == 0) WFAIL(2);
            NoChange = 0;
        }
        Len = LineLen(L);

        if (IsLineBlank(L)) break;

        if (Len < Right) {
            int firstwordbeg = -1;
            int firstwordend = -1;
            int X;
            PELine lp;

            if (L < RCount - 1) {
                IndentLine(L + 1, 0);
                if ((ScreenPos(RLine(L + 1), RLine(L + 1)->Count) == 0) ||
                        (RLine(L + 1)->Chars[0] == '>') || (RLine(L + 1)->Chars[0] == '<')) break;
            } else
                break;
            if (L + 1 >= RCount) break;

            lp = RLine(L + 1);
            for (X = 0; X < lp->Count; X++) {
                if (firstwordbeg == -1 &&
                        ((lp->Chars[X] != ' ') && (lp->Chars[X] != '\t'))) {
                    firstwordbeg = X;
                } else if (firstwordend == -1 &&
                           ((lp->Chars[X] == ' ' || lp->Chars[X] == '\t'))) {
                    firstwordend = X - 1;
                }
            }
            if (firstwordbeg != -1)
                if (firstwordend == -1)
                    firstwordend = lp->Count;

            if (firstwordend == -1) break;
            if (Right - Len > firstwordend - firstwordbeg) {
                if (JoinLine(L, Len + 1) == 0) WFAIL(3);
                NoChange = 0;
                continue;
            } else
                IndentLine(L + 1, Left);
        } else if (Len > Right) {
            C = Right;
            P = CharOffset(LP = RLine(L), C);
            while ((C > Left) &&
                    ((LP->Chars[P] != ' ') &&
                     (LP->Chars[P] != 9)))
                C = ScreenPos(LP, --P);

            if (P <= Left) {
                L++;
                continue;
            }
            C = ScreenPos(LP, P);
            if (SplitLine(L, C) == 0) WFAIL(4);
            IndentLine(L + 1, Left);
            if (L < RCount - 2 && LineLen(L + 1) == Left) {
                if (!IsLineBlank(L + 2)) {
                    if (JoinLine(L + 1, Left) == 0) WFAIL(5);
                }
            }
            if (L == VToR(CP.Row) && CP.Col > C) {
                if (SetPos(Left + CP.Col - C - 1, CP.Row + 1) == 0) WFAIL(6);
            }
            NoChange = 0;
            L++;
            continue;
        }
        if (WrapAll == 0)
            if (NoChangeX) {
                //printf("\n\nBreak OUT = %d\n\x7", L);
                break;
            }
        L++;
        NoChangeX = NoChange;
    }
    if (WrapAll == 1)
        if (SetPosR(Left,
                    (L < RCount - 2) ? (L + 2) :
                    (L < RCount - 1) ? (L + 1) :
                    (RCount - 1)) == 0) WFAIL(7);
    return 1;
}
int
retriever_services(ClientData clientData,
		Tcl_Interp *interp, /* Current interpreter. */
		int argc,           /* Number of arguments. */
		char **argv)        /* Argument strings.    */
{
    Tcl_CmdInfo infoPtr;
    ClientData  wcdata = 0;
    Tcl_CmdProc* wcmd = NULL;
    char *wname;
    char *command, *contents;
    int pargc, i, size, itembuf_size[10], item_size[10];
    char *p, *q, *line_items[10], *pline;
    int result, ret = TCL_OK, fnd = 0;
    int length;

    wname = argv[1];
    if (wname[0])
    {
	if (!Tcl_GetCommandInfo(interp, wname, &infoPtr))
	{
	    Tcl_AppendResult(interp, "wrong # \"",
		wname, "\" does not exist", (char *) NULL);
	    return TCL_ERROR;
	}
	wcdata = infoPtr.clientData;
	wcmd = (Tcl_CmdProc *)infoPtr.proc;
    }
    pargc = 2;
    command   = argv[pargc++];
    contents  = argv[pargc++];

    if (contents[0] == '\0')
    {
	Tcl_SetResult (interp, "", TCL_STATIC);
	return ret;
    }
    Tcl_ResetResult (interp);

    for (i=0;i<10;i++)
    {
	line_items[i] = ckalloc (256);
	itembuf_size[i] = 256;
    }

    /*
     * given a list of found symbols, insert those into the
     * treetable.
     *******************************************************/
    if ((argc == 5 || argc == 4) && *command == 'i' && strcmp (command, "insert") == 0)
    {
	int txtlen = 1024, datalen = 256, newlen, newdlen;
	int rargc = 0, slen;
	char *rargv[13];
	char *text, *data, image[64], *scope;
	int fnd;
	
	text = ckalloc (txtlen);
	data = ckalloc (datalen);
	
	rargc = 0;
	rargv[rargc++] = wname;
	rargv[rargc++] = "insert";
	rargv[rargc++] = "end";
	rargv[rargc++] = "-text";
	rargv[rargc++] = text;
	rargv[rargc++] = "-data";
	rargv[rargc++] = data;
	rargv[rargc++] = "-image";
	rargv[rargc++] = image;
	if (argc == 5)
	{
	    rargv[rargc++] = "-parent";
	    rargv[rargc++] = argv[pargc++];
	}
	
	for (length = strlen(contents), q = contents; 1;)
        {
	    char    *prevlist = q;
	    result = TclFindElement(interp, q, length, &pline, &q, &size, NULL);
	    if (result != TCL_OK || size == 0)
	    {
		break;
	    }
	    length -= q - prevlist;
	
	    /* split line into fields */
	    fnd = SplitLine (pline, size, itembuf_size, line_items, item_size);
	
	    /* use dynamic buffers for data */
	    newdlen = item_size[FIL_POS]
		    + item_size[FRM_POS]
		    + item_size[TO__POS]
		    + 10 /*scope*/ + 4;
	    if (newdlen > datalen)
	    {
		datalen = newdlen + newdlen / 2;
		data = ckrealloc (data, datalen);
		rargv[6] = data;
	    }
	
	    /* we parse files, when number of columns is 1-2 or
	     * the file filed is empty */
	    if (fnd == 2 || fnd == 3 || line_items[FIL_POS][0] == 0)
	    {
		strcpy (image, "file_+_image");
		
		if (line_items[TYP_POS][0] == '1')
		{
		    continue; /* skip directories */
		}
		/* skip first character, if there is a space */
		if (line_items[TYP_POS][0] == ' ')
		{
		    strcpy (line_items[TYP_POS], line_items[TYP_POS]+1);
		}
		
		/* mark the files entries as special entries */
		strcpy (data, "1");
	    }
	    else
	    {
		/* scope name */
		scope = GetScope (line_items[NAM_POS]);
		if (scope[0] == 0)
		{
		    scope = "ud";
		}
		slen = strlen (scope);
		/* skip 'iu' and 'in': there are ref. to includes */
		if (slen == 2 && scope[0] == 'i' && (scope[1] == 'u' || scope[1] == 'n'))
		{
		    continue;
		}
		
		/* only 'fd' 'fu' 'md' 'mi' and 'fr' have parameter list */
		if (! (slen == 2 && (
		    (scope[0] == 'm' && (scope[1] == 'i' || scope[1] == 'd')) ||
		    (scope[0] == 'f' && (scope[1] == 'd' || scope[1] == 'u' || scope[1] == 'r')))))
		{
		    line_items[PRM_POS][0] = 0;
		}
		sprintf (image, "type_%s_image", scope);
		
		sprintf (data, "%s\t%s\t%s\t%s",
			    line_items[FIL_POS],
			    line_items[FRM_POS],
			    line_items[TO__POS],
			    scope);
	    }
	
	    newlen = item_size[NAM_POS]
		    + item_size[CLS_POS]
		    + item_size[TYP_POS]
		    + item_size[PRM_POS]
		    + item_size[FIL_POS]
		    + 5;
	    if (newlen > txtlen)
	    {
		txtlen = newlen + newlen / 2;
		text = ckrealloc (text, txtlen);
		rargv[4] = text;
	    }
	    if (line_items[CLS_POS][0] == '#')
	    {
		line_items[CLS_POS][0] = 0;
	    }
	    sprintf (text, "%s\t%s\t%s\t%s\t%s",
			line_items[NAM_POS],
			line_items[CLS_POS],
			line_items[TYP_POS],
			line_items[PRM_POS],
			line_items[FIL_POS]);
	    (*wcmd)(wcdata, interp, rargc, rargv);
	}
	
	ckfree (data);
	ckfree (text);
    }
    else if (argc == 10 && *command == 'f' && strcmp (command, "filter") == 0)
    {
	char *pattern, *file, *type, *parameter;
	int from, to;
	char *buf;
	int buf_size = 512;
	int length;
	
	pattern   = argv[pargc++];
	file      = argv[pargc++];
	type      = argv[pargc++];
	parameter = argv[pargc++];
	from      = atoi (argv[pargc++]);
	to        = atoi (argv[pargc++]);
	
	buf = (char*)ckalloc (buf_size);
	
	if (*contents) for (length=strlen(contents), q = contents; 1;)
        {
	    char    *prevlist = q;
	    result = TclFindElement(interp, q, length, &pline, &q, &size, NULL);
	    if (result != TCL_OK || size == 0)
	    {
		break;
	    }
	    length -= q - prevlist;
	    SplitLine (pline, size, itembuf_size, line_items, item_size);
	
	    if (*type)
	    {
		if (item_size[TYP_POS] == 0)
		{
		    continue;
		}
		if (strncmp (type, line_items[TYP_POS], item_size[TYP_POS]) != 0)
		{
		    continue;
		}
	    }
	
	    if (*parameter)
	    {
		if (item_size[PRM_POS] == 0)
		{
		    continue;
		}
		/* delete () from parameter list, if parameter doesn't
		 * begin with '(' */
		if (*parameter != '(')
		{
		    for (p=line_items[PRM_POS]; p[1] && p[2]; p++)
		    {
			p[0] = p[1];
		    }
		    p[0] = 0;
		}
		if (strcmp (parameter, line_items[PRM_POS]) != 0)
		{
		    continue;
		}
	    }
	
	    if (*file)
	    {
		if (*file != *line_items[FIL_POS] || strcmp (file, line_items[FIL_POS]) != 0)
		{
		    continue;
		}
	    }
	
	    if (from != -1)
	    {
		if (from < GetNumber (line_items[FRM_POS]))
		{
		    continue;
		}
	    }
	    if (to != -1)
	    {
		if (to > GetNumber (line_items[TO__POS]))
		{
		    continue;
		}
	    }
	
	    if (buf_size < size+1)
	    {
		buf_size += size;
		buf = (char*)ckrealloc (buf, buf_size);
	    }
	    memcpy (buf, pline, size);
	    buf[size] = 0;
	
	    Tcl_AppendElement (interp, buf);
	    fnd = 1;
	}
	
	if (!fnd)
	{
	    Tcl_SetResult (interp, "", TCL_STATIC);
	}
	
	ckfree (buf);
    }
    else
    {
	Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
	     " tree filter contents pattern file type parameter from to |\n"
	     " tree insert contents ?parent?\"",
	     (char *) NULL);
	ret = TCL_ERROR;
    }

    for(i=0;i<10;i++)
    {
	ckfree (line_items[i]);
    }
    return ret;
}
Exemple #28
0
int EBuffer::LineSplit() {
    if (SplitLine(VToR(CP.Row), CP.Col) == 0) return 0;
    if (BFI(this, BFI_Trim))
        if (TrimLine(VToR(CP.Row)) == 0) return 0;
    return 1;
}
Exemple #29
0
long Redo(struct InstData *data)
{
    ENTER();

    D(DBF_UNDO, "undolevel: %ld undocur: %ld undofill: %ld", data->undolevel, data->undocur, data->undofill);

    // check if there something to redo at all
    if(data->undofill > 0 && data->undocur < data->undofill)
    {
        struct UserAction *buffer = (struct UserAction *)data->undopointer;

        if(Enabled(data))
        {
            data->blockinfo.enabled = FALSE;
            MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data);
        }

        // in case undocur is equal zero then we have to
        // set the undoavailable attribute to true to signal
        // others that undo is available
        if(data->undocur == 0)
            set(data->object, MUIA_TextEditor_UndoAvailable, TRUE);

        data->undopointer = (APTR)((char *)data->undopointer + sizeof(struct UserAction));
        data->undocur++;

//    if(data->actualline != LineNode(buffer->y, data) || data->CPos_X != buffer->x)
        SetCursor(data->CPos_X, data->actualline, FALSE, data);
        data->CPos_X = buffer->x;
        data->actualline = LineNode(buffer->y, data);
        ScrollIntoDisplay(data);

        switch(buffer->type)
        {
        case ET_PASTECHAR:
            PasteChars(data->CPos_X++, data->actualline, 1, (char *)&buffer->del.character, buffer, data);
            break;

        case ET_BACKSPACECHAR:
        case ET_DELETECHAR:
            RemoveChars(data->CPos_X, data->actualline, 1, data);
            break;

        case ET_SPLITLINE:
            SplitLine(data->CPos_X, data->actualline, TRUE, NULL, data);
            break;

        case ET_MERGELINES:
        case ET_BACKSPACEMERGE:
            MergeLines(data->actualline, data);
            break;

        case ET_PASTEBLOCK:
        {
            struct Hook *oldhook = data->ImportHook;

            data->ImportHook = &ImPlainHook;
            InsertText(data, (char *)buffer->clip, TRUE);
            data->ImportHook = oldhook;
            MyFreePooled(data->mypool, buffer->clip);

            buffer->blk.x = data->CPos_X;
            buffer->blk.y = LineNr(data->actualline, data);
        }
        break;

        case ET_DELETEBLOCK_NOMOVE:
        case ET_DELETEBLOCK:
        {
            struct marking block =
            {
                TRUE,
                LineNode(buffer->y, data),
                buffer->x,
                LineNode(buffer->blk.y, data),
                buffer->blk.x
            };
            char  *clip = GetBlock(&block, data);

            CutBlock2(data, FALSE, FALSE, &block, TRUE);
            buffer->clip = (unsigned char *)clip;
        }
        break;

        default:
            // nothing to do
            break;
        }

        ScrollIntoDisplay(data);

        if(data->flags & FLG_Active)
            SetCursor(data->CPos_X, data->actualline, TRUE, data);

        // if undocur == undofill this signals that we
        // don't have any things to redo anymore.
        if(data->undocur == data->undofill)
            set(data->object, MUIA_TextEditor_RedoAvailable, FALSE);

        RETURN(TRUE);
        return(TRUE);
    }
    else
    {
        DoMethod(data->object, MUIM_TextEditor_HandleError, Error_NothingToRedo);

        RETURN(FALSE);
        return(FALSE);
    }
}
Exemple #30
0
long Undo(struct InstData *data)
{
    ENTER();

    D(DBF_UNDO, "undolevel: %ld undocur: %ld undofill: %ld", data->undolevel, data->undocur, data->undofill);

    // check if there is something in the undo
    // buffer available
    if(data->undolevel > 0 && data->undocur > 0)
    {
        struct UserAction *buffer;
        BOOL  crsr_move = TRUE;

        if(Enabled(data))
        {
            data->blockinfo.enabled = FALSE;
            MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data);
        }

        // as the redo operation automatically
        // becomes available when undo is used we just
        // check here if we didn't yet set RedoAvailable
        // as we only want to set it once
        if(data->undocur == data->undofill)
            set(data->object, MUIA_TextEditor_RedoAvailable, TRUE);

        data->undopointer = (APTR)((char *)data->undopointer - sizeof(struct UserAction));
        data->undocur--;
        buffer = (struct UserAction *)data->undopointer;

//    if(data->actualline != LineNode(buffer->y, data) || data->CPos_X != buffer->x)
        SetCursor(data->CPos_X, data->actualline, FALSE, data);

        data->CPos_X = buffer->x;
        data->actualline = LineNode(buffer->y, data);
        ScrollIntoDisplay(data);

        switch(buffer->type)
        {
        case ET_PASTECHAR:
        {
            buffer->del.character = *(data->actualline->line.Contents+data->CPos_X);
            buffer->del.style = GetStyle(data->CPos_X, data->actualline);
            buffer->del.flow = data->actualline->line.Flow;
            buffer->del.separator = data->actualline->line.Separator;
            RemoveChars(data->CPos_X, data->actualline, 1, data);
        }
        break;

        case ET_BACKSPACECHAR:
        {
            PasteChars(data->CPos_X++, data->actualline, 1, (char *)&buffer->del.character, buffer, data);
        }
        break;

        case ET_DELETECHAR:
        {
            PasteChars(data->CPos_X, data->actualline, 1, (char *)&buffer->del.character, buffer, data);
        }
        break;

        case ET_SPLITLINE:
        {
            MergeLines(data->actualline, data);
        }
        break;

        case ET_MERGELINES:
        {
            SplitLine(data->CPos_X, data->actualline, FALSE, buffer, data);
        }
        break;

        case ET_BACKSPACEMERGE:
        {
            SplitLine(data->CPos_X, data->actualline, TRUE, buffer, data);
        }
        break;

        case ET_PASTEBLOCK:
        {
            struct marking block =
            {
                TRUE,
                LineNode(buffer->y, data),
                buffer->x,
                LineNode(buffer->blk.y, data),
                buffer->blk.x
            };
            char *clip = GetBlock(&block, data);

            CutBlock2(data, FALSE, FALSE, &block, TRUE);
            buffer->clip = (unsigned char *)clip;
        }
        break;

        case ET_DELETEBLOCK_NOMOVE:
            crsr_move = FALSE;
        // continue

        case ET_DELETEBLOCK:
        {
            struct Hook *oldhook = data->ImportHook;
            char *clip = (char *)buffer->clip;

            data->ImportHook = &ImPlainHook;
            InsertText(data, clip, crsr_move);
            data->ImportHook = oldhook;
            MyFreePooled(data->mypool, clip);

            buffer->blk.x = data->CPos_X;
            buffer->blk.y = LineNr(data->actualline, data);

            if(!crsr_move)
            {
                data->CPos_X = buffer->x;
                data->actualline = LineNode(buffer->y, data);
            }
        }
        break;

        default:
            // nothing to do
            break;
        }

        ScrollIntoDisplay(data);

        if(data->flags & FLG_Active)
            SetCursor(data->CPos_X, data->actualline, TRUE, data);

        // if there are no further undo levels we
        // have to set UndoAvailable to FALSE
        if(data->undocur == 0)
        {
            set(data->object, MUIA_TextEditor_UndoAvailable, FALSE);

            if(!(data->flags & FLG_UndoLost))
                data->HasChanged = FALSE;
        }

        RETURN(TRUE);
        return(TRUE);
    }
    else
    {
        DoMethod(data->object, MUIM_TextEditor_HandleError, Error_NothingToUndo);

        RETURN(FALSE);
        return(FALSE);
    }
}