const char *DDFField::GetInstanceData( int nInstance, int *pnInstanceSize ) { int nRepeatCount = GetRepeatCount(); const char *pachWrkData; if( nInstance < 0 || nInstance >= nRepeatCount ) return NULL; /* -------------------------------------------------------------------- */ /* Special case for fields without subfields (like "0001"). We */ /* don't currently handle repeating simple fields. */ /* -------------------------------------------------------------------- */ if( poDefn->GetSubfieldCount() == 0 ) { pachWrkData = GetData(); if( pnInstanceSize != 0 ) *pnInstanceSize = GetDataSize(); return pachWrkData; } /* -------------------------------------------------------------------- */ /* Get a pointer to the start of the existing data for this */ /* iteration of the field. */ /* -------------------------------------------------------------------- */ int nBytesRemaining1 = 0, nBytesRemaining2 = 0; DDFSubfieldDefn *poFirstSubfield; poFirstSubfield = poDefn->GetSubfield(0); pachWrkData = GetSubfieldData(poFirstSubfield, &nBytesRemaining1, nInstance); /* -------------------------------------------------------------------- */ /* Figure out the size of the entire field instance, including */ /* unit terminators, but not any trailing field terminator. */ /* -------------------------------------------------------------------- */ if( pnInstanceSize != NULL ) { DDFSubfieldDefn *poLastSubfield; int nLastSubfieldWidth; const char *pachLastData; poLastSubfield = poDefn->GetSubfield(poDefn->GetSubfieldCount()-1); pachLastData = GetSubfieldData( poLastSubfield, &nBytesRemaining2, nInstance ); poLastSubfield->GetDataLength( pachLastData, nBytesRemaining2, &nLastSubfieldWidth ); if((pachLastData[nLastSubfieldWidth-1] == 0) && (pachLastData[nLastSubfieldWidth - 2] == DDF_FIELD_TERMINATOR)) nLastSubfieldWidth -= 2; *pnInstanceSize = nBytesRemaining1 - (nBytesRemaining2 - nLastSubfieldWidth); } return pachWrkData; }
/* * DoKeyMap - process a key mapping */ vi_rc DoKeyMap( vi_key key ) { vi_rc rc; long total; int i; bool was_base = FALSE; KeyMaps[key].inuse = TRUE; if( KeyMaps[key].is_base ) { was_base = TRUE; for( i = 0; i < MAX_EVENTS; i++ ) { KeyMaps[i].was_inuse = KeyMaps[i].inuse; KeyMaps[i].inuse = TRUE; } } total = GetRepeatCount(); rc = RunKeyMap( &KeyMaps[key], total ); if( was_base ) { for( i = 0; i < MAX_EVENTS; i++ ) { KeyMaps[i].inuse = KeyMaps[i].was_inuse; } } KeyMaps[key].inuse = FALSE; return( rc ); } /* DoKeyMap */
vi_rc DeleteLines( void ) { range r; GetLineRange( &r, GetRepeatCount(), CurrentPos.line ); return( Delete( &r ) ); } /* DeleteLines */
vi_rc YankLines( void ) { range r; GetLineRange( &r, GetRepeatCount(), CurrentPos.line ); return( Yank( &r ) ); } /* YankLines */
/* * DoMove - handle a movement command */ vi_rc DoMove( event *ev ) { range range; vi_rc rc; int curcol; int type; defaultRange( &range ); if( EditFlags.Modeless ) { rc = ev->alt_rtn.move( &range, GetRepeatCount() ); type = ev->alt_b.type; } else { rc = ev->rtn.move( &range, GetRepeatCount() ); type = ev->b.type; } if( rc == ERR_NO_ERR ) { curcol = CurrentPos.column; if( range.start.line != CurrentPos.line ) { if( type == EVENT_REL_MOVE ) { GoToLineRelCurs( range.start.line ); } else { curcol = -1; MemorizeCurrentContext(); GoToLineNoRelCurs( range.start.line ); } } if( curcol != range.start.column ) { GoToColumnOK( range.start.column ); } #ifndef __WIN__ if( range.highlight ) { // don't handle multi-line highlights yet assert( range.hi_start.line == range.hi_end.line ); EditFlags.ResetDisplayLine = true; DCUpdate(); HiliteAColumnRange( range.hi_start.line, range.hi_start.column, range.hi_end.column ); } #endif } return( rc ); }
void ossimDDFField::Dump( FILE * fp ) { int nMaxRepeat = 8; if( getenv("DDF_MAXDUMP") != NULL ) nMaxRepeat = atoi(getenv("DDF_MAXDUMP")); fprintf( fp, " DDFField:\n" ); fprintf( fp, " Tag = `%s'\n", poDefn->GetName() ); fprintf( fp, " DataSize = %d\n", nDataSize ); fprintf( fp, " Data = `" ); for( int i = 0; i < std::min(nDataSize,40); i++ ) { if( pachData[i] < 32 || pachData[i] > 126 ) fprintf( fp, "\\%02X", ((unsigned char *) pachData)[i] ); else fprintf( fp, "%c", pachData[i] ); } if( nDataSize > 40 ) fprintf( fp, "..." ); fprintf( fp, "'\n" ); /* -------------------------------------------------------------------- */ /* dump the data of the subfields. */ /* -------------------------------------------------------------------- */ int iOffset = 0, nLoopCount; for( nLoopCount = 0; nLoopCount < GetRepeatCount(); nLoopCount++ ) { if( nLoopCount > nMaxRepeat ) { fprintf( fp, " ...\n" ); break; } for( int i = 0; i < poDefn->GetSubfieldCount(); i++ ) { int nBytesConsumed; poDefn->GetSubfield(i)->DumpData( pachData + iOffset, nDataSize - iOffset, fp ); poDefn->GetSubfield(i)->GetDataLength( pachData + iOffset, nDataSize - iOffset, &nBytesConsumed ); iOffset += nBytesConsumed; } } }
/* * MovePosition - move to a screen position */ vi_rc MovePosition( void ) { linenum lne, lines; vi_key key; vi_rc rc; if( RepeatDigits == 0 ) { lne = CurrentPos.line; } else { lne = GetRepeatCount(); if( IsPastLastLine( lne ) ) { return( ERR_INVALID_REDRAW ); } } lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ); key = GetNextEvent( false ); switch( key ) { case '.': LeftTopPos.line = lne - lines / 2; break; case VI_KEY( ENTER ): LeftTopPos.line = lne; break; case '-': LeftTopPos.line = lne - lines + 1; break; default: return( ERR_INVALID_REDRAW ); } if( LeftTopPos.line < 1 ) { LeftTopPos.line = 1; } SetCurrentLineNumber( lne ); rc = CGimmeLinePtr( CurrentPos.line, &CurrentFcb, &CurrentLine ); CurrentPos.column = 1; DCInvalidateAllLines(); DCDisplayAllLines(); if( rc == ERR_NO_ERR ) { rc = GoToColumnOnCurrentLine( FindStartOfCurrentLine() ); } return( rc ); } /* MovePosition */
/* * JoinCurrentLineToNext */ vi_rc JoinCurrentLineToNext( void ) { int i, j; vi_rc rc; rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } i = (int) GetRepeatCount(); StartUndoGroup( UndoStack ); for( j = 0; j < i; j++ ) { rc = GenericJoinCurrentLineToNext( true ); if( rc != ERR_NO_ERR ) { break; } } EndUndoGroup( UndoStack ); return( rc ); } /* JoinCurrentLineToNext */
/* * moveHalfPage - display half a page */ static vi_rc moveHalfPage( int dir ) { int ople; vi_rc rc; long repcnt; int ln; ople = EditVars.PageLinesExposed; repcnt = GetRepeatCount(); if( repcnt > 1 ) { ln = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ) - repcnt; if( ln < 1 ) { ln = 1; } HalfPageLines = ln; } EditVars.PageLinesExposed = HalfPageLines; rc = MovePage( dir, 1, false ); EditVars.PageLinesExposed = ople; return( rc ); } /* moveHalfPage */
/* * MoveScreenUp - expose top line */ vi_rc MoveScreenUp( void ) { linenum lne, cnt, lines, top, nlne; lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ); CFindLastLine( &lne ); cnt = GetRepeatCount(); top = LeftTopPos.line - cnt; if( top < 1 ) { top = 1; } LeftTopPos.line = top; if( CurrentPos.line >= top + lines ) { nlne = top + lines - 1; if( nlne > lne ) { nlne = lne; } GoToLineNoRelCurs( nlne ); } DCDisplayAllLines(); SetWindowCursor(); return( ERR_NO_ERR ); } /* MoveScreenUp */
/* * MoveScreenDown - expose bottom line */ vi_rc MoveScreenDown( void ) { linenum lne, cnt, lines, top, x; CFindLastLine( &lne ); lines = WindowAuxInfo( CurrentWindow, WIND_INFO_TEXT_LINES ); x = lne - lines + 1; if( x <= 0 ) { return( ERR_NO_ERR ); } cnt = GetRepeatCount(); top = LeftTopPos.line + cnt; if( top > x ) { top = x; } LeftTopPos.line = top; if( top >= CurrentPos.line ) { GoToLineNoRelCurs( top ); } DCDisplayAllLines(); SetWindowCursor(); return( ERR_NO_ERR ); } /* MoveScreenDown */
/* * doOperator - process an operator event */ static vi_rc doOperator( event *ev ) { event *next; vi_rc rc; long count; range range; int next_type; bool is_op_alias; rc = ERR_INVALID_OP; defaultRange( &range ); count = GetRepeatCount(); is_op_alias = ev->b.is_op_alias; if( is_op_alias ) { ev->rtn.alias( &ev, &next ); } else { next = nextEvent(); // a count is the only thing allowed to interfere between an op and // its argument so we just keep chewing... if( next != &EventList['0'] ) { while( next->b.is_number ) { if( EditFlags.Modeless ) { next->alt_rtn.old(); } else { next->rtn.old(); } next = nextEvent(); } } count *= GetRepeatCount(); } KillRepeatWindow(); if( EditFlags.Modeless ) { range.fix_range = next->alt_b.fix_range; next_type = next->alt_b.type; } else { range.fix_range = next->b.fix_range; next_type = next->b.type; } EditFlags.OperatorWantsMove = true; // was: if( count==1 ) if( next_type == EVENT_OP ) { // op/op only valid when ops are equal if( next == ev ) { rc = GetLineRange( &range, count, CurrentPos.line ); } } else { // it had better be a move operation if( next_type == EVENT_REL_MOVE || next_type == EVENT_ABS_MOVE ) { /* * Kluge! want 'ce' instead of 'cw' - this sucks. * * - even better kludge: if we are currently on white * space, then treat 'cw' as 'cw'. arrrrr. cge. */ if( ( ev == &EventList['c'] || ev == &EventList[VI_KEY( ALT_F1 )] ) && LastEvent == 'w' ) { EditFlags.IsChangeWord = true; if( CurrentLine != NULL ) { if( !isspace( CurrentLine->data[CurrentPos.column - 1] ) ) { next = &EventList['e']; range.fix_range = false; } } } if( EditFlags.Modeless ) { rc = next->alt_rtn.move( &range, count ); } else { rc = next->rtn.move( &range, count ); } EditFlags.IsChangeWord = false; } else { /* * Kluge! treat 'r' as a movement command. */ if( LastEvent == 'r' ) { rc = GetSelectedRegion( &range ); } else if( LastEvent == '0' ) { rc = MoveLineBegin( &range, 1 ); } else if( LastEvent == VI_KEY( ESC ) ) { rc = RANGE_REQUEST_CANCELLED; } } } EditFlags.OperatorWantsMove = false; if( rc == ERR_NO_ERR ) { if( ev->b.modifies ) { rc = ModificationTest(); } if( rc == ERR_NO_ERR ) { NormalizeRange( &range ); if( EditFlags.Modeless ) { rc = ev->alt_rtn.op( &range ); } else { rc = ev->rtn.op( &range ); } } } return( rc ); } /* doOperator */
vi_rc MovePageUp( void ) { return( MovePage( -1, GetRepeatCount(), false ) ); }
vi_rc MovePageDown( void ) { return( MovePage( 1, GetRepeatCount(), false ) ); }