Пример #1
0
        /***************************************************************************
         * Function: TakeSection
         * Purpose:
         * Add a section to the composite list. Called from make_composites
         * to copy a section, add it to the composite list and set the state,
         * leftbase and rightbase.	 Note that the state could be STATE.SAME
         * with a null section on the left.	 May NOT call with STATE.SAME and
         * a null right section! */
        public static void TakeSection(ListAnchor compo, Section left, Section right, STATE state)
        {
            Section sec = null;

            /* select which section is being output, and change the state to indicate it has been output */
            switch( state ){
                case STATE.SAME:
                    /* both the same. we mark both as output, and
                     * take the right one.	It is possible that the
                     * left one could be null (an ignorable blank section) */
                    if( left != null ) left.state = STATE.MARKED;
                    right.state = STATE.MARKED;
                    sec = right;
                    break;

                case STATE.LEFTONLY:
                case STATE.MOVEDLEFT:
                    sec = left;
                    left.state = STATE.MARKED;
                    break;

                case STATE.RIGHTONLY:
                case STATE.MOVEDRIGHT:
                    sec = right;
                    right.state = STATE.MARKED;
                    break;
            }

            /* create a new section on the list */
            Section newsec = new Section( sec.first, sec.last );
            compo.AddTail( newsec );

            newsec.state = state;

            if (left != null)	newsec.leftbase = left.first.linenr;
            else				newsec.leftbase = 0;

            if (right != null)	newsec.rightbase = right.first.linenr;
            else				newsec.rightbase = 0;
        }
Пример #2
0
 /***************************************************************************
 * Function: section_makelist
 * Purpose:
 * Make a list of sections by traversing a list of lines. Consecutive
 * linked lines that are linked to consecutive lines are put in a single
 * section. Blocks of unlinked lines are placed in a section.
 * If isIgnoreBlanks is set then we first try to link them as normal.
 * but if they won't link then we just skip over them and keep them
 * in the same section.
 * Left must be set true iff the list of lines is a left hand section.
 * Returns a handle to a list of sections */
 public static void MakeList(ListAnchor sections, ListAnchor linelist, bool left,bool isIgnoreBlanks)
 {
     /* for each line in the list */
     for( Line line1 = (Line)linelist.GetHead(); line1 != null; line1 = (Line)line1.GetNext() ){
         /* is it linked ? */
         bool matched;
         Line line2;
         if( line1.link != null || ( isIgnoreBlanks && line1.IsBlank() ) ){
             line2 = FindEndOfMatched(line1,isIgnoreBlanks);
             matched = true;
         } else {
             line2 = FindEndOfUnmatched(line1);
             matched = false;
         }
         Section sect = new Section(line1, line2);	/* create the section and add to list */
         sections.AddTail( sect );
         sect.state = (
               matched ? STATE.SAME
             : left	  ? STATE.LEFTONLY
             :			STATE.RIGHTONLY
             );
         line1 = line2;	/* advance to end of section (no-op if 1 line section) */
     }
 }