Cleanup: consolidate swrite
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
source = parse.cpp parserstate.cpp parser.cpp templates.cpp terminal.cpp termemu.cpp parseraction.cpp terminalcsi.cpp
|
source = parse.cpp parserstate.cpp parser.cpp templates.cpp terminal.cpp termemu.cpp parseraction.cpp terminalcsi.cpp swrite.cpp
|
||||||
objects = parserstate.o parser.o templates.o terminal.o parseraction.o terminalcsi.o
|
objects = parserstate.o parser.o templates.o terminal.o parseraction.o terminalcsi.o swrite.o
|
||||||
|
repos = templates.rpo
|
||||||
executables = parse termemu
|
executables = parse termemu
|
||||||
|
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
|||||||
@@ -15,10 +15,7 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
#include "swrite.hpp"
|
||||||
#ifndef __STDC_ISO_10646__
|
|
||||||
#error "Must have __STDC_ISO_10646__"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const size_t buf_size = 1024;
|
const size_t buf_size = 1024;
|
||||||
|
|
||||||
@@ -64,11 +61,6 @@ int main( int argc __attribute__((unused)),
|
|||||||
|
|
||||||
if ( child == 0 ) {
|
if ( child == 0 ) {
|
||||||
/* child */
|
/* child */
|
||||||
if ( chdir( "/" ) < 0 ) {
|
|
||||||
perror( "chdir" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
char *my_argv[ 2 ];
|
char *my_argv[ 2 ];
|
||||||
my_argv[ 0 ] = strdup( "/bin/bash" );
|
my_argv[ 0 ] = strdup( "/bin/bash" );
|
||||||
assert( my_argv[ 0 ] );
|
assert( my_argv[ 0 ] );
|
||||||
@@ -147,21 +139,9 @@ int copy( int src, int dest )
|
|||||||
} else if ( bytes_read < 0 ) {
|
} else if ( bytes_read < 0 ) {
|
||||||
perror( "read" );
|
perror( "read" );
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
ssize_t total_bytes_written = 0;
|
|
||||||
while ( total_bytes_written < bytes_read ) {
|
|
||||||
ssize_t bytes_written = write( dest, buf + total_bytes_written,
|
|
||||||
bytes_read - total_bytes_written );
|
|
||||||
if ( bytes_written <= 0 ) {
|
|
||||||
perror( "write" );
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
total_bytes_written += bytes_written;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return swrite( dest, buf, bytes_read );
|
||||||
}
|
}
|
||||||
|
|
||||||
int vt_parser( int fd, Parser::UTF8Parser *parser )
|
int vt_parser( int fd, Parser::UTF8Parser *parser )
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include "parserstate.hpp"
|
#include "parserstate.hpp"
|
||||||
#include "parserstatefamily.hpp"
|
#include "parserstatefamily.hpp"
|
||||||
|
|
||||||
|
#ifndef __STDC_ISO_10646__
|
||||||
|
#error "Must have __STDC_ISO_10646__"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Parser {
|
namespace Parser {
|
||||||
class Parser {
|
class Parser {
|
||||||
private:
|
private:
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "swrite.hpp"
|
||||||
|
|
||||||
|
int swrite( int fd, const char *str, ssize_t len )
|
||||||
|
{
|
||||||
|
ssize_t total_bytes_written = 0;
|
||||||
|
ssize_t bytes_to_write = ( len >= 0 ) ? len : strlen( str );
|
||||||
|
while ( total_bytes_written < bytes_to_write ) {
|
||||||
|
ssize_t bytes_written = write( fd, str + total_bytes_written,
|
||||||
|
bytes_to_write - total_bytes_written );
|
||||||
|
if ( bytes_written <= 0 ) {
|
||||||
|
perror( "write" );
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
total_bytes_written += bytes_written;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SWRITE_HPP
|
||||||
|
#define SWRITE_HPP
|
||||||
|
|
||||||
|
int swrite( int fd, const char *str, ssize_t len = -1 );
|
||||||
|
|
||||||
|
#endif
|
||||||
+3
-30
@@ -17,10 +17,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "terminal.hpp"
|
#include "terminal.hpp"
|
||||||
|
#include "swrite.hpp"
|
||||||
#ifndef __STDC_ISO_10646__
|
|
||||||
#error "Must have __STDC_ISO_10646__"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const size_t buf_size = 1024;
|
const size_t buf_size = 1024;
|
||||||
|
|
||||||
@@ -158,21 +155,9 @@ int copy( int src, int dest )
|
|||||||
} else if ( bytes_read < 0 ) {
|
} else if ( bytes_read < 0 ) {
|
||||||
perror( "read" );
|
perror( "read" );
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
ssize_t total_bytes_written = 0;
|
|
||||||
while ( total_bytes_written < bytes_read ) {
|
|
||||||
ssize_t bytes_written = write( dest, buf + total_bytes_written,
|
|
||||||
bytes_read - total_bytes_written );
|
|
||||||
if ( bytes_written <= 0 ) {
|
|
||||||
perror( "write" );
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
total_bytes_written += bytes_written;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return swrite( dest, buf, bytes_read );
|
||||||
}
|
}
|
||||||
|
|
||||||
int termemu( int fd, Terminal::Emulator *terminal, int debug_fd )
|
int termemu( int fd, Terminal::Emulator *terminal, int debug_fd )
|
||||||
@@ -198,19 +183,7 @@ int termemu( int fd, Terminal::Emulator *terminal, int debug_fd )
|
|||||||
terminal->debug_printout( STDOUT_FILENO );
|
terminal->debug_printout( STDOUT_FILENO );
|
||||||
|
|
||||||
/* write writeback */
|
/* write writeback */
|
||||||
ssize_t total_bytes_written = 0;
|
return swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() );
|
||||||
ssize_t bytes_to_write = terminal_to_host.length();
|
|
||||||
const char *str = terminal_to_host.c_str();
|
|
||||||
while ( total_bytes_written < bytes_to_write ) {
|
|
||||||
ssize_t bytes_written = write( fd, str + total_bytes_written,
|
|
||||||
bytes_to_write - total_bytes_written );
|
|
||||||
if ( bytes_written <= 0 ) {
|
|
||||||
perror( "write" );
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
total_bytes_written += bytes_written;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-17
@@ -5,11 +5,10 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "terminal.hpp"
|
#include "terminal.hpp"
|
||||||
|
#include "swrite.hpp"
|
||||||
|
|
||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
|
|
||||||
static void swrite( int fd, const char *str );
|
|
||||||
|
|
||||||
Cell::Cell()
|
Cell::Cell()
|
||||||
: overlapping_cell( NULL ),
|
: overlapping_cell( NULL ),
|
||||||
contents(),
|
contents(),
|
||||||
@@ -192,21 +191,6 @@ void Emulator::print( Parser::Print *act )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swrite( int fd, const char *str )
|
|
||||||
{
|
|
||||||
ssize_t total_bytes_written = 0;
|
|
||||||
ssize_t bytes_to_write = strlen( str );
|
|
||||||
while ( total_bytes_written < bytes_to_write ) {
|
|
||||||
ssize_t bytes_written = write( fd, str + total_bytes_written,
|
|
||||||
bytes_to_write - total_bytes_written );
|
|
||||||
if ( bytes_written <= 0 ) {
|
|
||||||
perror( "write" );
|
|
||||||
} else {
|
|
||||||
total_bytes_written += bytes_written;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Emulator::debug_printout( int fd )
|
void Emulator::debug_printout( int fd )
|
||||||
{
|
{
|
||||||
std::string screen;
|
std::string screen;
|
||||||
|
|||||||
Reference in New Issue
Block a user