Exemple #1
0
const TextObjectLineInfo& TextObject::findLineInfoForIndex(int index) const
{
	const TextObjectLineInfo* line_info = getLineInfo(0);
	for (int line = 1; line < getNumLines(); ++line)
	{
		const TextObjectLineInfo* next_line_info = getLineInfo(line);
		if (index < next_line_info->start_index)
			break;
		line_info = next_line_info;
	}
	return *line_info;
}
void KateCodeFoldingTree::expandOne(int realLine, int numLines)
{
  // hl whole file
  m_buffer->line (m_buffer->count()-1);

  KateLineInfo line;
  int blockTrack = 0;
  for (int i = realLine; i >= 0; i--) {
    getLineInfo(&line, i);

    if (line.topLevel)
      // done
      break;

    if (line.startsInVisibleBlock && i != realLine) {
      if (blockTrack == 0)
        toggleRegionVisibility(i);

      blockTrack--;
    }

    if (line.endsBlock)
      blockTrack++;

    if (blockTrack < 0)
      // too shallow
      break;
  }

  blockTrack = 0;
  for (int i = realLine; i < numLines; i++) {
    getLineInfo(&line, i);

    if (line.topLevel)
      // done
      break;

    if (line.startsInVisibleBlock) {
      if (blockTrack == 0)
        toggleRegionVisibility(i);

      blockTrack++;
    }

    if (line.endsBlock)
      blockTrack--;

    if (blockTrack < 0)
      // too shallow
      break;
  }
}
int KateCodeFoldingTree::collapseOne(int realLine)
{
  // hl whole file
  m_buffer->line (m_buffer->count()-1);

  KateLineInfo line;
  int unrelatedBlocks = 0;
  for (int i = realLine; i >= 0; i--) {
    getLineInfo(&line, i);

    if (line.topLevel && !line.endsBlock)
      // optimisation
      break;

    if (line.endsBlock  && ( line.invalidBlockEnd ) && (i != realLine)) {
      unrelatedBlocks++;
    }

    if (line.startsVisibleBlock) {
      unrelatedBlocks--;
      if (unrelatedBlocks == -1) {
        toggleRegionVisibility(i);
        return i;
      }
    }
  }
  return -1;
}
Exemple #4
0
int mainPopulate()
{
    getLineInfo();
    char bigrams[WIDTH*HEIGHT-1][2];
    populate_bigrams(bigrams);
    int bigram_frequency_table[92][92];//only a-z considered
    populate_bigrams_freq_table(bigram_frequency_table, bigrams);
    find_max (bigram_frequency_table);
    return 0;
}
Exemple #5
0
int TextObject::findLineForIndex(int index) const
{
	int line_num = 0;
	for (int line = 1; line < getNumLines(); ++line)
	{
		const TextObjectLineInfo* line_info = getLineInfo(line);
		if (index < line_info->start_index)
			break;
		line_num = line;
	}
	return line_num;
}
void KateCodeFoldingTree::expandToplevelNodes(int numLines)
{
  // hl whole file
  m_buffer->line (m_buffer->count()-1);

  KateLineInfo line;
  for (int i = 0; i < numLines; i++) {
    getLineInfo(&line, i);

    if (line.startsInVisibleBlock)
      toggleRegionVisibility(i);
  }
}
Exemple #7
0
// FIXME actually this is two functions, selected by parameter find_line_only; make two functions or return TextObjectLineInfo reference
int TextObject::calcTextPositionAt(QPointF point, bool find_line_only) const
{
	float click_tolerance = Settings::getInstance().getMapEditorClickTolerancePx();
	
	for (int line = 0; line < getNumLines(); ++line)
	{
		const TextObjectLineInfo* line_info = getLineInfo(line);
		if (line_info->line_y - line_info->ascent > point.y())
			return -1;	// NOTE: Only true as long as every line has a bigger or equal y value than the line before
		
		if (point.x() < line_info->line_x - click_tolerance) continue;
		if (point.y() > line_info->line_y + line_info->descent) continue;
		if (point.x() > line_info->line_x + line_info->width + click_tolerance) continue;
		
		// Position in the line rect.
		if (find_line_only)
			return line;
		else
			return line_info->getIndex(point.x());
	}
	return -1;
}
Exemple #8
0
int syntaxAnalysis(char * fileName)
{
    FILE * sourceFile = fopen(fileName,"r") ;
    if(!sourceFile)
    {
        printf("can not open file '%s'\n",fileName) ;
        return -1 ;
    }
    char  words[NAME_MAX_LEN] = "" ;
    char valOrAddr[VAL_MAX_LEN] = "" ;
    struct Stack
    {
        int data[STACK_DEPTH] ;
        int top ;
    } ; //EA stack
    struct Stack stateS ;
    struct Stack symbolS ;
    /* -----------init-------------- */
    stateS.top = 0 ;
    symbolS.top = 0 ;
    stateS.data[stateS.top++] = 0 ;
    symbolS.data[symbolS.top++] = transName("#") ;
        /** init semanticS */
    initSemanticS() ;
        /* make a global sybolTb */
    struct symbolTb * globalTb = mkTb(NULL) ;
        /* init the offset stack , tbptr stack */
    initTbptrS() ;
    initOffsetS() ;
    initLbptrS() ;
    offsetS.data[offsetS.top++] = 0 ;
    tbptrS.data[tbptrS.top++] = globalTb ;
    //-------------------
    #ifdef FREOPEN
    char * dotPos = strchr(fileName,'.') ;
    char intermediateFileName[30] ; //get the name
    if(dotPos == NULL)
    {
        strcpy(intermediateFileName,fileName) ;
        strcat(intermediateFileName,".ix") ;
    }
    else
    {
        char * dp = fileName ;
        for( ; dp != dotPos ; dp++)
        {
            intermediateFileName[dp - fileName] = *dp ;
        }
        intermediateFileName[dp - fileName] = '\0' ;
        strcat(intermediateFileName,".ix") ;
    }
    printf("%s",intermediateFileName) ;
    freopen(intermediateFileName , "w" , stdout) ; //to create or clear it
    freopen("CON","w",stdout) ;
    #endif
    getLineInfo(sourceFile,words,valOrAddr) ;
    while(1)
    {
        #ifdef OUTPUT_ANALYSIS_STACK
        int j = 0 ;
        for( ; j < stateS.top ; j++)
        {
            printf("%d,",stateS.data[j]) ;
        }
        printf("\n") ;
        for( j = 0 ; j < stateS.top ; j++)
        {
            printf("%s,",getName(symbolS.data[j]) ) ;
        }
        printf("\n") ;
        #endif
        #ifdef OUTPUT_READLINE
        printf("--words:%s\n--valoraddr:%s\n",words,valOrAddr) ;
        #endif
        #ifdef OUTPUT_SEMANTIC_STACK
        int dk = 0 ;
        printf("--semantic_stack--\n") ;
        for( ; dk < semanticS.top ; dk++)
        {
            printf("[%s,%s,%s] | ",semanticS.data[dk].lexType,semanticS.data[dk].lexVal,semanticS.data[dk].tbName) ;
        }
        printf("\n") ;
        #endif
        int symbol = transName(words) ;
        if(symbol != EMPTY)
        {
                // find ACTION
                #ifdef OUTPUT_STATUS
                int cState = stateS.data[stateS.top -1 ] ;
                printf("current state=%d,symbol=%d,%s",cState,symbol,getName(symbol)) ;
                #endif
                int val = analysisTable.table[stateS.data[stateS.top -1 ]][symbol] ;
                if(val == ACC )
                {
                    #ifdef SYNTAX
                    printf("ACC\n") ;
                    #endif
                    return 0 ;
                }
                else if(val == ERROR)
                {
                    #ifdef SYNTAX
                    printf("something error\n") ;
                    #endif
                    return -1 ;
                }
                else if(val >= 0 )
                {
                    /* shift */
                    symbolS.data[symbolS.top++] = symbol ;
                    stateS.data[stateS.top++] = val ;
                    shiftSemanticAct(words,valOrAddr) ;
                    #ifdef SYNTAX
                    printf("shift %s\n",getName(symbol)) ;
                    #endif
                    /* read next */
                    if(getLineInfo(sourceFile,words,valOrAddr) == EOF)
                    {
                        strcpy(words,"#") ;
                    }
                }
                else if(val < 0)
                {
                    /* reduce */
                    val = - val ;
                    /*print */

                    #ifdef SYNTAX
                    char * proS = restoreP(val) ;
                    printf("%s,%d\n",proS,strlen(proS)) ;
                    free(proS) ;
                    #endif
                    #ifdef FREOPEN
                    freopen(intermediateFileName,"a",stdout) ;
                    #endif

                    if(semanticAct(val) == FALSE_ANA)
                    {
                        #ifdef FREOPEN
                        fflush(stdout) ;
                        freopen( "CON", "w", stdout );
                        #endif
                        return FALSE_ANA ;
                    }


                    #ifdef FREOPEN
                    fflush(stdout) ;
                    freopen( "CON", "w", stdout );
                    #endif
                    //free(proS) ;
                    /* stack pop */
                    int len = productions.data[val].len ;
                    stateS.top = stateS.top - len ;
                    symbolS.top  = symbolS.top - len ;
                    /* stack push */
                        /* we should get the production left */
                    int pLeft = productions.data[val].pLeft ;
                    symbolS.data[symbolS.top++] = pLeft ;
                    /* look up goto table*/
                    int gotoState = analysisTable.table[stateS.data[stateS.top -1]][pLeft] ;
                    if(gotoState == ERROR)
                    {
                        printf("GOTO table occured error") ;
                        return -1 ;
                    }
                    stateS.data[stateS.top++] = gotoState ;
                }
        }
        else
        {
            printf("not supported symbol ,%s!\n",words) ;
            return -1 ;
        }
    }
    return 0 ;
}