本文整理汇总了C++中raw函数的典型用法代码示例。如果您正苦于以下问题:C++ raw函数的具体用法?C++ raw怎么用?C++ raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了raw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xyzsh_readline_interface_on_curses
void xyzsh_readline_interface_on_curses(char* cmdline, int cursor_point, char** argv, int argc, BOOL exit_in_spite_ofjob_exist, BOOL welcome_msg)
{
gSigChld = FALSE;
gSigWinch = FALSE;
signal(SIGCHLD, handler);
signal(SIGWINCH, handler);
const int maxx = mgetmaxx();
const int maxy = mgetmaxy();
int temulator_y = 0;
int temulator_x = 0;
int temulator_height = maxy;
int temulator_width = maxx;
sTEmulator* temulator = temulator_init(temulator_height, temulator_width);
struct sTEmulatorFunArg arg;
arg.cmdline = cmdline;
arg.cursor_point = cursor_point;
arg.argv = argv;
arg.argc = argc;
arg.exit_in_spite_ofjob_exist = exit_in_spite_ofjob_exist;
arg.welcome_msg = welcome_msg;
temulator_open(temulator, temulator_fun, &arg);
initscr();
start_color();
noecho();
raw();
nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
curs_set(0);
ESCDELAY=50;
temulator_init_colors();
WINDOW* term_win = newwin(temulator_height, temulator_width, temulator_y, temulator_x);
int pty = temulator->mFD;
fd_set mask, read_ok;
FD_ZERO(&mask);
FD_SET(0, &mask);
FD_SET(pty, &mask);
int dirty = 0;
struct timeval next;
gettimeofday(&next, NULL);
while(1) {
struct timeval tv = { 0, 1000 * 1000 / 100 };
read_ok = mask;
if(select(pty+1, &read_ok, NULL, NULL, &tv) > 0) {
if(FD_ISSET(pty, &read_ok)) {
temulator_read(temulator);
dirty = 1;
}
}
int key;
while((key = getch()) != ERR) {
temulator_write(temulator, key);
dirty = 1;
}
gettimeofday(&tv, NULL);
if(dirty && is_expired(tv, next)) {
temulator_draw_on_curses(temulator, term_win, temulator_y, temulator_x);
wrefresh(term_win);
dirty = 0;
next = timeval_add(tv, slice);
}
if(gSigChld) {
gSigChld = FALSE;
break;
}
if(gSigWinch) {
gSigWinch = 0;
temulator_height = mgetmaxy();
temulator_width = mgetmaxx();
if(temulator_width >= 10 && temulator_height >= 10) {
resizeterm(temulator_height, temulator_width);
wresize(term_win, temulator_height, temulator_width);
temulator_resize(temulator, temulator_height, temulator_width);
dirty = 1;
}
}
}
//.........这里部分代码省略.........
示例2: init_curses
void init_curses() {
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
}
示例3: modify_display
void modify_display ( void )
{
int i;
int focus = 0;
int c;
int x,y;
int maxx;
int maxy __attribute((unused));
int ll_focus_y = 0;
int ll_focus_x = 0;
WINDOW *mod_win;
getmaxyx ( win, maxy, maxx );
mod_win = newwin ( 8, maxx, 0, 0 );
cbreak();
raw();
nonl();
keypad ( mod_win, TRUE );
while ( 1 )
{
werase( mod_win );
wrefresh( mod_win );
mvwprintw ( mod_win, 0, 0, "Use arrow keys (or vim cursor keys) to navigate;" );
mvwprintw ( mod_win, 1, 0, "Set sort field (highlighted) with 's', order %s (change with 'r')", parametres.reversesort ? "ascending" : "descending" );
mvwprintw ( mod_win, 2, 0, "go down or press enter to change a field, select with space key");
mvwprintw ( mod_win, 3, 0, "'i' to insert a field, 'a' to append it, 'd' to delete");
wmove ( mod_win, 6, 0 );
for ( i = 0; i < MAX_DISPLAY_FIELDS; i++ )
{
wattron ( mod_win, A_REVERSE );
if ( display_fields[i] == NULL )
{
break;
}
if ( display_fields[i]->identifier == parametres.sortby )
{
wattroff ( mod_win, A_REVERSE );
}
wprintw ( mod_win, display_fields[i]->header_format, display_fields[i]->fieldname );
if ( i == focus )
{
wattroff ( mod_win, A_REVERSE );
/* find out where to print the menu in case we need one */
getyx ( mod_win, y, x );
ll_focus_y = y + 1;
ll_focus_x = x - display_fields[i]->field_length;
/*
keep menu inside the current window - in case it would "fall
off" off the edge, move it inwards by the width of the menu
*/
if ( maxx < ( x + MENU_WIDTH ) )
{
ll_focus_x = maxx - MENU_WIDTH;
}
mvwaddch( mod_win, y - 1, x - display_fields[i]->field_length - 1 , ACS_ULCORNER);
mvwaddch( mod_win, y + 1, x - display_fields[i]->field_length - 1 , ACS_LLCORNER);
mvwaddch( mod_win, y + 1, x -1, ACS_LRCORNER);
mvwaddch( mod_win, y - 1, x - 1 , ACS_URCORNER);
mvwvline( mod_win, y , x - display_fields[i]->field_length - 1 , ACS_VLINE, 1 );
mvwvline( mod_win, y , x - 1 , ACS_VLINE, 1 );
mvwhline( mod_win, y - 1, x - display_fields[i]->field_length, ACS_HLINE, display_fields[i]->field_length - 1 );
mvwhline( mod_win, y + 1, x - display_fields[i]->field_length, ACS_HLINE, display_fields[i]->field_length - 1 );
wmove ( mod_win, y, x );
}
}
wrefresh( mod_win );
c = getch();
switch ( c )
{
case 'h':
case KEY_LEFT:
if ( focus > 0 )
{
focus--;
}
break;
case 'l':
case KEY_RIGHT:
if ( display_fields[focus + 1] != NULL )
{
focus++;
}
break;
case 's':
case 'S':
if ( display_fields[focus]->sortable == 1 )
{
parametres.sortby = display_fields[focus]->identifier;
goto end;
}
else
{
printf ( "\a" );
mvwprintw ( mod_win, 5, 0, "%-79s", "Sorry, can't sort by this field");
wrefresh ( mod_win );
sleep ( 1 );
}
break;
case 'r':
//.........这里部分代码省略.........
示例4: main
int main()
{
// Allocate a BCH codec Galois order 8 (w/ 2^8-1 == 255 bit codeword size), and 2 bits of
// correction capacity. This results in a BCH( 255, 239, 2) codec: 255-bit codeword, 239-bit
// data payload capacity, hence 255-239 == 16 bits of parity. Define EZPWD_BCH_CLASSIC to use
// classic Djelic Linux Kernel API. Otherwise, uses <ezpwd/bch> 'bch<..>' or 'BCH<...>' classes.
ezpwd::asserter assert;
try {
#if defined( EZPWD_BCH_CLASSIC )
ezpwd::bch_control *bch = ezpwd::init_bch( 8, 2, 0 );
if ( ! bch )
throw std::logic_error( "Failed to allocate valid BCH codec" );
ezpwd::bch_control &bch_codec( *bch ); // By Galois order, Correction capacity
#else
//ezpwd::bch_base bch_codec( 8, 2 ); // By Galois order, Correction capacity, flexibly
ezpwd::BCH<255,239,2> bch_codec; // By Codeword, Payload and Correction capacities, exactly
#endif
#if defined( EZPWD_BCH_FIXED )
typedef std::array<uint8_t,10> codeword_t; // Fixed (parity initialized to 0)
#else
typedef std::vector<uint8_t> codeword_t; // Variable (parity added by encode)
#endif
codeword_t codeword= {
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF // 8 data
}; // 2 ECC parity
#if defined( EZPWD_BCH_CLASSIC )
// A BCH codeword's ECC must be zero-initialized for classic Djelic API, and
// must be added to variable containers
# if ! defined( EZPWD_BCH_FIXED )
codeword.resize( 10 );
# endif
codeword[8] = 0;
codeword[9] = 0;
ezpwd::encode_bch( &bch_codec, &codeword[0], 8, &codeword[8] );
#else
// A codeword in a fixed container will not be resized by API; assumes ECC on end. Will
// initialize to 0. A variable container will have parity appended by the API.
bch_codec.encode( codeword );
#endif
// Place random errors in the codeword and correct, up to the capacity of the BCH codec.
for ( size_t t = 0; t < 5; ++t ) {
for ( size_t e = 0
#if defined( EZPWD_BCH_CLASSIC )
; e < bch_codec.t
#else
; e < bch_codec.t()
#endif
; ++e ) {
codeword_t corrupted( codeword );
// Randomly corrupt from 0 to bch->t bits
for ( size_t be = 0; be < e; ++be ) {
unsigned int bl = random_80( randomizer );
corrupted[bl/8] ^= uint8_t( 1 ) << ( bl % 8 );
}
codeword_t corrected( corrupted );
#if defined( EZPWD_BCH_CLASSIC )
int corrections = correct_bch( &bch_codec, &corrected[0], 8, &corrected[8] );
#else
int corrections = bch_codec.decode( corrected );
#endif
if ( assert.ISEQUAL( corrections, int( e ),
std::string( "Failed decode of " ) << bch_codec
<< " codeword w/ " << e << " bit errrors"
)) {
std::cout << assert << std::endl;
continue;
}
// Success; If differences were found, they better be in the parity data!
for ( size_t i = 0; i < 8; ++i )
if ( assert.ISEQUAL( corrected[i], codeword[i],
std::string( "Failed recovery of " ) << bch_codec
<< " codeword w/ " << e << " bit errors" ))
std::cout << assert << std::endl;
}
#if ! defined( EZPWD_BCH_CLASSIC )
// Try the inline versions (only available in C++ API)
std::string raw( "abc" );
std::string enc = bch_codec.encoded( raw );
std::string err = enc;
err[0] ^= 0x40;
err[2] ^= 0x08;
std::string dec = bch_codec.decoded( err );
if ( assert.ISEQUAL( dec.substr( 0, 3 ), raw,
std::string( "decoded/encoded of " ) << bch_codec
<< " codeword failed, encoded '0x" << ezpwd::hexstr( raw )
<< "' to '0x" << ezpwd::hexstr( enc )
<< "', decoded '0x" << ezpwd::hexstr( err )
<< "' to '0x" << ezpwd::hexstr( dec )
<< "'" ))
std::cout << assert << std::endl;
#endif
}
std::cout
<< bch_codec << ": ";
//.........这里部分代码省略.........
示例5: mousemask
bool Display::Open()
{
// Open curses
screen=initscr();
if (screen==NULL) {
std::cerr << "Cannot initialize curses" << std::endl;
return false;
}
#ifdef NCURSES_MOUSE_VERSION
mousemask(BUTTON1_PRESSED|
BUTTON1_RELEASED/*|
BUTTON1_CLICKED|
BUTTON1_DOUBLE_CLICKED|
BUTTON1_TRIPLE_CLICKED*/,NULL);
#endif
// Check availibility of colors
colorDepth=1;
colorMode=colorModeMonochrome;
if (has_colors() && start_color()!=ERR && COLORS>=8) {
colorMode=colorModeColor;
colorDepth=4;
}
// Basic curses initialisation
curs_set(0);
noecho();
cbreak();
nonl();
raw();
//Images::Factory::Set(OS::Factory::factory->CreateImageFactory(this));
screenWidth=COLS;
screenHeight=LINES;
workAreaWidth=screenWidth;
workAreaHeight=screenHeight;
type=typeTextual;
EvaluateDisplaySize();
for (int c=1; c<COLOR_PAIRS; c++) {
if (init_pair(c,c%COLORS,c/COLORS)==ERR) {
std::cerr << c << " " << c%COLORS << " " << c/COLORS << std::endl;
std::cerr << "Cannot initialize terminal color pairs" << std::endl;
colorDepth=1;
colorMode=colorModeMonochrome;
break;
}
}
propFont=driver->CreateFont();
propFont=propFont->Load();
propFontSize=1;
fixedFont=driver->CreateFont();
fixedFont=fixedFont->Load();
fixedFontSize=1;
theme=new Theme(this);
for (size_t i=0; i<colorCount; i++) {
color[i]=theme->GetColor((ColorIndex)i);
}
multiClickTime=200;
eventLoop=new UnixEventLoop();
eventLoop->AddSource(new CursesEventSource(this));
return true;
}
示例6: raw64
inline /*-*/ uint64_t* raw64(word_t a) /*-*/ { assert(a==last_addr); return (uint64_t*) raw(a); }
示例7: main
int main(int argc, char* argv[]) {
char * enclave_path = argv[1];
int vm_id = atoi(argv[2]);
int ctrl_fd;
int cons_fd;
use_curses = 1;
if (argc < 3) {
printf("usage: v3_cons_sc <enclave_device> <vm_id>\n");
return -1;
}
/* Check for minimum Terminal size at start */
if (check_terminal_size() != 0) {
printf ("Error: terminal too small!\n");
return -1;
}
ctrl_fd = pet_ioctl_path(enclave_path, PISCES_ENCLAVE_CTRL_CONNECT, NULL);
if (ctrl_fd < 0) {
printf("Error opening enclave control channel\n");
return -1;
}
cons_fd = pet_ioctl_fd(ctrl_fd, PISCES_CMD_VM_CONS_CONNECT, (void *)(uint64_t)vm_id);
close(ctrl_fd);
if (cons_fd < 0) {
printf("Error opening VM console\n");
close(cons_fd);
return -1;
}
tcgetattr(STDIN_FILENO, &console.termios_old);
atexit(handle_exit);
console.x = 0;
console.y = 0;
if (use_curses) {
gettmode();
console.win = initscr();
if (console.win == NULL) {
fprintf(stderr, "Error initialization curses screen\n");
exit(-1);
}
scrollok(console.win, 1);
erase();
}
/*
termios = console.termios_old;
termios.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | IGNPAR);
termios.c_iflag &= ~(INLCR | INPCK | ISTRIP | IXOFF | IXON | PARMRK);
//termios.c_iflag &= ~(ICRNL | INLCR );
// termios.c_iflag |= SCANCODES;
// termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
//termios.c_lflag &= ~(ICANON | IEXTEN | ISIG | NOFLSH);
termios.c_lflag &= ~(ICANON | ECHO);
termios.c_cc[VMIN] = 1;
termios.c_cc[VTIME] = 0;
tcflush(STDIN_FILENO, TCIFLUSH);
tcsetattr(STDIN_FILENO, TCSANOW, &termios);
*/
raw();
cbreak();
noecho();
keypad(console.win, TRUE);
//ioctl(STDIN_FILENO, KDSKBMODE, K_RAW);
while (1) {
int ret;
fd_set rset;
FD_ZERO(&rset);
FD_SET(cons_fd, &rset);
FD_SET(STDIN_FILENO, &rset);
ret = select(cons_fd + 1, &rset, NULL, NULL, NULL);
// printf("Returned from select...\n");
if (ret == 0) {
continue;
//.........这里部分代码省略.........
示例8: main
int main(int argc, char *argv[])
{
if (argc != 10 || !strncmp(argv[1],"-h",2))
{
puts("DrawLineSegment: Prints a line through two given points");
puts("USAGE: ./DrawLineSegment x");
return 0;
}
initscr(); /* Start curses mode */
raw(); /* Line buffering disabled */
noecho(); /* Don't echo() while we do getch */
start_color(); /* Start color */
init_pair(1, COLOR_RED, COLOR_RED);
init_pair(2, COLOR_BLUE, COLOR_BLUE);
attron(COLOR_PAIR(1));
curs_set(0);
double x1 = atof(argv[1]);
double y1 = atof(argv[2]);
double x2 = atof(argv[3]);
double y2 = atof(argv[4]);
double x3 = atof(argv[5]);
double y3 = atof(argv[6]);
double x4 = atof(argv[7]);
double y4 = atof(argv[8]);
Pair mid1 = midPoint(x1,y1,x2,y2);
Pair mid2 = midPoint(x3,y3,x4,y4);
Pair mid = midPoint(mid1.x,mid1.y,mid2.x,mid2.y);
Pair rpoint1;
Pair rpoint2;
Pair rpoint3;
Pair rpoint4;
for (int i = 0; i < 1080; i++)
{
rpoint1 = rotateDPoint(mid.x,mid.y,x1,y1,i);
rpoint2 = rotateDPoint(mid.x,mid.y,x2,y2,i);
rpoint3 = rotateDPoint(mid.x,mid.y,x3,y3,i);
rpoint4 = rotateDPoint(mid.x,mid.y,x4,y4,i);
//draw the starting line
//draw the midpoint
attron(COLOR_PAIR(2));
drawPair(mid);
//draw rotated about the middle point
attron(COLOR_PAIR(1));
drawQuadrilateral(rpoint1.x,rpoint1.y,
rpoint2.x,rpoint2.y,
rpoint3.x,rpoint3.y,
rpoint4.x,rpoint4.y); //draw the shape
refresh(); /* Print it on to the real screen */
//sleep() wasn't working too well for me
for (int j = 0; j <= atol(argv[5])*10000; j++);
clear();
}
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
示例9: main
int main(int argc, char *argv[])
{
void (*old_hook)(const char *, long, const char *, va_list);
int use_menu = 1, k_errno;
char buf[BUFSIZ];
if ((whoami = strrchr(argv[0], '/')) == NULL)
whoami = argv[0];
else
whoami++;
if (!(current_li = malloc(sizeof(List_info))))
{
sprintf(buf, ": allocating list info");
goto punt;
}
else
{
current_li->acl_type = NULL;
current_li->acl_name = NULL;
current_li->desc = NULL;
current_li->modtime = NULL;
current_li->modby = NULL;
current_li->modwith = NULL;
}
username = mrcl_krb_user();
if (!username)
exit(1);
if (mrcl_connect(NULL, "mailmaint", 2, 1))
exit(2);
initscr();
if ((LINES < 24) || (COLS < 60))
{
display_buff("Display window too small.\n\n");
sprintf(buf, "Current window parameters are (%d lines, %d columns)\n",
LINES, COLS);
display_buff(buf);
display_buff("Please resize your window\n");
display_buff("to at least 24 lines and 60 columns.\n");
exit(0);
}
raw();
noecho();
old_hook = set_com_err_hook(menu_err_hook);
position[0] = oldpos[0] = 1;
level = 0;
pack_main_menu();
pack_help_menu();
display_menu(main_menu);
get_main_input();
cls();
endwin();
set_com_err_hook(old_hook);
free_menu(main_menu);
free_menu(help_menu);
if (current_li->acl_type)
free(current_li->acl_type);
if (current_li->acl_name)
free(current_li->acl_name);
if (current_li->desc)
free(current_li->desc);
if (current_li->modtime)
free(current_li->modtime);
if (current_li->modby)
free(current_li->modby);
if (current_li->modwith)
free(current_li->modwith);
free(current_li);
mr_disconnect();
exit(0);
punt:
com_err(whoami, status, "%s", buf);
exit(1);
}
示例10: main
//.........这里部分代码省略.........
/*
* Now that we have the logfile and the ACU open
* return to the real uid and gid. These things will
* be closed on exit. The saved-setuid uid and gid
* allows us to get the original setuid permissions back
* for removing the uucp lock.
*/
userperm();
/*
* Kludge, there's no easy way to get the initialization
* in the right order, so force it here.
* Do the open here, before we change back to real uid.
* We will check whether the open succeeded later, when
* (and if) we actually go to use the file.
*/
if ((PH = getenv("PHONES")) == NOSTR) {
myperm();
PH = "/etc/phones";
}
phfd = fopen(PH, "r");
userperm();
vinit(); /* init variables */
setparity("none"); /* set the parity table */
if ((i = speed(number(value(BAUDRATE)))) == NULL) {
(void) printf("tip: bad baud rate %d\n",
number(value(BAUDRATE)));
myperm();
delock(uucplock);
return (3);
}
/*
* Hardwired connections require the
* line speed set before they make any transmissions
* (this is particularly true of things like a DF03-AC)
*/
if (HW)
ttysetup(i);
if (p = connect()) {
(void) printf("\07%s\n[EOT]\n", p);
myperm();
delock(uucplock);
return (1);
}
/*
* Always setup the tty again here in case hardware flow
* control was selected, which can only be set after the
* connection is made, or in case this is not a hardwired
* modem (rare these days) that likewise can only be setup
* after the connection is made.
*/
ttysetup(i);
cucommon:
/*
* From here down the code is shared with
* the "cu" version of tip.
*/
(void) ioctl(0, TCGETS, (char *)&defarg);
arg = defarg;
/* turn off input processing */
arg.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
arg.c_cc[VMIN] = 1;
arg.c_cc[VTIME] = 0;
arg.c_iflag &= ~(INPCK|IXON|IXOFF|ICRNL);
arg.c_oflag = 0; /* turn off all output processing */
/* handle tandem mode in case was set in remote file */
if (boolean(value(TAND)))
tandem("on");
else
tandem("off");
raw();
(void) pipe(fildes); (void) pipe(repdes);
(void) signal(SIGALRM, (sig_handler_t)timeout);
/*
* Everything's set up now:
* connection established (hardwired or dialup)
* line conditioned (baud rate, mode, etc.)
* internal data structures (variables)
* so, fork one process for local side and one for remote.
*/
if (CM != NOSTR) {
(void) sleep(2); /* let line settle */
parwrite(FD, (unsigned char *)CM, strlen(CM));
}
(void) printf(cumode ? "Connected\r\n" : "\07connected\r\n");
(void) signal(SIGCHLD, (sig_handler_t)deadkid);
if (pid = fork())
tipin();
else
tipout();
/*NOTREACHED*/
}
示例11: main
int main(int argc, char *argv[])
{
RedditUserLogged *user = NULL;
char *subreddit = NULL;
char *password = NULL, *username = NULL;
optParser parser;
DEBUG_START(DEBUG_FILE, DEBUG_FILENAME);
memset(&parser, 0, sizeof(optParser));
parser.argc = argc;
parser.argv = argv;
optAddOptions (&parser, mainOptions, MOPT_ARG_COUNT);
handleArguments(&parser);
if (mainOptions[MOPT_HELP].isSet) {
displayHelp(&parser);
return 0;
}
optClearParser(&parser);
setlocale(LC_CTYPE, "");
initscr();
raw();//We want character for character input
keypad(stdscr,1);//Enable extra keys like arrowkeys
noecho();
start_color();
use_default_colors();
init_pair(1, -1, -1);
init_pair(2, COLOR_BLACK, COLOR_WHITE);
DEBUG_PRINT(L"Starting...\n");
/* Start libreddit */
redditGlobalInit();
globalState = redditStateNew();
globalState->userAgent = redditCopyString("cReddit/0.0.1");
redditStateSet(globalState);
if (mainOptions[MOPT_USERNAME].isSet) {
username = mainOptions[MOPT_USERNAME].svalue;
if (!mainOptions[MOPT_PASSWORD].isSet)
password = getPassword();
else
password = mainOptions[MOPT_PASSWORD].svalue;
user = redditUserLoggedNew();
redditUserLoggedLogin(user, username, password);
/* Don't want to leave that important Reddit password in memory */
memset(password, 0, strlen(password));
if (!mainOptions[MOPT_PASSWORD].isSet)
free(password);
}
if (mainOptions[MOPT_SUBREDDIT].isSet) {
subreddit = mainOptions[MOPT_SUBREDDIT].svalue;
if (!startsWith("/r/", subreddit) && strcmp("/", subreddit) != 0)
prepend("/r/", subreddit);
} else {
subreddit = "/";
}
showSubreddit(subreddit);
redditUserLoggedFree(user);
redditStateFree(globalState);
redditGlobalCleanup();
endwin();
DEBUG_END(DEBUG_FILE);
return 0;
}
示例12: ncurses_init_graphics
static int ncurses_init_graphics(caca_display_t *dp)
{
static int curses_colors[] =
{
/* Standard curses colours */
COLOR_BLACK,
COLOR_BLUE,
COLOR_GREEN,
COLOR_CYAN,
COLOR_RED,
COLOR_MAGENTA,
COLOR_YELLOW,
COLOR_WHITE,
/* Extra values for xterm-16color */
COLOR_BLACK + 8,
COLOR_BLUE + 8,
COLOR_GREEN + 8,
COLOR_CYAN + 8,
COLOR_RED + 8,
COLOR_MAGENTA + 8,
COLOR_YELLOW + 8,
COLOR_WHITE + 8
};
mmask_t newmask;
int fg, bg, max;
dp->drv.p = malloc(sizeof(struct driver_private));
#if defined HAVE_GETENV && defined HAVE_PUTENV
ncurses_install_terminal(dp);
#endif
#if defined HAVE_SIGNAL
sigwinch_d = dp;
signal(SIGWINCH, sigwinch_handler);
#endif
#if defined HAVE_LOCALE_H
setlocale(LC_ALL, "");
#endif
_caca_set_term_title("caca for ncurses");
initscr();
keypad(stdscr, TRUE);
nonl();
raw();
noecho();
nodelay(stdscr, TRUE);
curs_set(0);
/* Activate mouse */
newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
mousemask(newmask, &dp->drv.p->oldmask);
mouseinterval(-1); /* No click emulation */
/* Set the escape delay to a ridiculously low value */
ESCDELAY = 10;
/* Activate colour */
start_color();
/* If COLORS == 16, it means the terminal supports full bright colours
* using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8),
* we can build 16*16 colour pairs.
* If COLORS == 8, it means the terminal does not know about bright
* colours and we need to get them through A_BOLD and A_BLINK (\e[1m
* and \e[5m). We can only build 8*8 colour pairs. */
max = COLORS >= 16 ? 16 : 8;
for(bg = 0; bg < max; bg++)
for(fg = 0; fg < max; fg++)
{
/* Use ((max + 7 - fg) % max) instead of fg so that colour 0
* is light gray on black. Some terminals don't like this
* colour pair to be redefined. */
int col = ((max + 7 - fg) % max) + max * bg;
init_pair(col, curses_colors[fg], curses_colors[bg]);
dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
if(max == 8)
{
/* Bright fg on simple bg */
dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
/* Simple fg on bright bg */
dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
| COLOR_PAIR(col);
/* Bright fg on bright bg */
dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
| COLOR_PAIR(col);
}
}
caca_add_dirty_rect(dp->cv, 0, 0, dp->cv->width, dp->cv->height);
dp->resize.allow = 1;
caca_set_canvas_size(dp->cv, COLS, LINES);
dp->resize.allow = 0;
return 0;
//.........这里部分代码省略.........
示例13: raw
char *Buffer::current() const {
return raw(_cur);
}
示例14: grow
char *Buffer::alloc(size_t sz) {
grow(sz);
char *p = raw(_end);
_end += sz;
return p;
}
示例15: avatar
//.........这里部分代码省略.........
AddWall(Avatars[b].pos.y, Avatars[b].pos.x, Avatars[b].last_move, 0);
}
break;
case M_SOUTH:
if (maze->maze[Avatars[b].pos.y][Avatars[b].pos.x].south_wall != 2) {
AddWall(Avatars[b].pos.y, Avatars[b].pos.x, Avatars[b].last_move, 0);
}
break;
case M_EAST:
if (maze->maze[Avatars[b].pos.y][Avatars[b].pos.x].east_wall != 2) {
AddWall(Avatars[b].pos.y, Avatars[b].pos.x, Avatars[b].last_move, 0);
}
break;
case M_WEST:
if (maze->maze[Avatars[b].pos.y][Avatars[b].pos.x].west_wall != 2) {
AddWall(Avatars[b].pos.y, Avatars[b].pos.x, Avatars[b].last_move, 0);
}
break;
default:
AddWall(Avatars[b].pos.y, Avatars[b].pos.x, Avatars[b].last_move, 0);
break;
}
Avatars[b].pos = pos;
Avatars[b].direction = Avatars[b].last_move;
Avatars[b].last_move = M_NULL_MOVE;
}
}
}
////////////////graphics////////////////
//initscr();
clear();
raw();
//start_color();
create_border(maze->num_col, maze->num_row);
draw_inside(maze);
//draw_fakes(maze);
int f;
for (f = 0; f<a.nAvatars; f++) {
draw_avatar(2*Avatars[f].pos.y+1, 2*Avatars[f].pos.x+1);
}
//unsigned int microseconds;
//microseconds = 200;
//usleep(microseconds);
refresh();
/* Determine the direction of the move for the current Avatar */
/* Avatar 0 has a fixed location - it never moves */
if (a.avID == 0) {
if(!final_destination) {
final_destination = (XYPos *) calloc(1, sizeof(XYPos));
final_destination->x = Avatars[a.avID].pos.x;
final_destination->y = Avatars[a.avID].pos.y;
}
move = M_NULL_MOVE;
}
// if(!final_destination){
// for(int i = 0; i < a.nAvatars; i++){
// if (i == a.avID) continue;
// //if the Avatar is in the same place as another Avatar, save position as final_destination
// if((Avatars[i].pos.x == Avatars[a.avID].pos.x) && (Avatars[i].pos.y == Avatars[a.avID].pos.y)){
// final_destination = (XYPos *) calloc(1, sizeof(XYPos));
// final_destination->x = Avatars[a.avID].pos.x;
// final_destination->y = Avatars[a.avID].pos.y;