/* write a line of text to the scratch file and add a line node to the editor buffer; return a pointer to the end of the text */ const char * put_sbuf_line( const char * const buf, const int size, const int addr ) { line_t * const lp = dup_line_node( 0 ); const char * const p = (const char *) memchr( buf, '\n', size ); int len; if( !lp ) return 0; if( !p ) { set_error_msg( "Line too long" ); return 0; } len = p - buf; /* out of position */ if( seek_write ) { if( fseek( sfp, 0L, SEEK_END ) != 0 ) { show_strerror( 0, errno ); set_error_msg( "Cannot seek temp file" ); return 0; } sfpos = ftell( sfp ); seek_write = false; } if( (int)fwrite( buf, 1, len, sfp ) != len ) /* assert: interrupts disabled */ { sfpos = -1; show_strerror( 0, errno ); set_error_msg( "Cannot write temp file" ); return 0; } lp->pos = sfpos; lp->len = len; add_line_node( lp, addr ); ++current_addr_; sfpos += len; /* update file position */ return p + 1; }
/* copy a range of lines; return false if error */ bool copy_lines( const int first_addr, const int second_addr, const int addr ) { line_t *lp, *np = search_line_node( first_addr ); undo_t * up = 0; int n = second_addr - first_addr + 1; int m = 0; current_addr_ = addr; if( addr >= first_addr && addr < second_addr ) { n = addr - first_addr + 1; m = second_addr - addr; } for( ; n > 0; n = m, m = 0, np = search_line_node( current_addr_ + 1 ) ) for( ; n-- > 0; np = np->q_forw ) { disable_interrupts(); lp = dup_line_node( np ); if( !lp ) { enable_interrupts(); return false; } add_line_node( lp, current_addr_++ ); if( up ) up->tail = lp; else { up = push_undo_atom( UADD, current_addr_, current_addr_ ); if( !up ) { enable_interrupts(); return false; } } modified_ = true; enable_interrupts(); } return true; }
/* append lines from the yank buffer */ bool put_lines( const int addr ) { undo_t * up = 0; line_t *p, *lp = yank_buffer_head.q_forw; if( lp == &yank_buffer_head ) { set_error_msg( "Nothing to put" ); return false; } current_addr_ = addr; while( lp != &yank_buffer_head ) { disable_interrupts(); p = dup_line_node( lp ); if( !p ) { enable_interrupts(); return false; } add_line_node( p, current_addr_++ ); if( up ) up->tail = p; else { up = push_undo_atom( UADD, current_addr_, current_addr_ ); if( !up ) { enable_interrupts(); return false; } } modified_ = true; lp = lp->q_forw; enable_interrupts(); } return true; }
void emit_raw (const char *line) { const char *p = line; while (isspace ((unsigned char) *p)) p++; if (*p) { genLine.lineElement.isComment = (*p == ';'); add_line_node (line); } }