Beispiel #1
0
static
void
block( int el )
{
    int i, idx = 0, row, col;

    rb->yield();

    /* Find first unknown square */
    for( i = 0 ; i < 9 && !IS_EMPTY( idx = idx_block( el, i ) ) ; ++i )
        ;
    if( i < 9 )
    {
        assert( IS_EMPTY( idx ) );
        row = ROW( idx );
        col = COLUMN( idx );
        for( ++i ; i < 9 ; ++i )
        {
            idx = idx_block( el, i );
            if( IS_EMPTY( idx ) )
            {
                if( ROW( idx ) != row )
                    row = -1;
                if( COLUMN( idx ) != col )
                    col = -1;
            }
        }
        if( 0 <= row )
            exblock( el, row, idx_row );
        if( 0 <= col )
            exblock( el, col, idx_column );
    }
}
Beispiel #2
0
void Display::update_arm(uint8_t r)
{
    if (AP_Notify::flags.armed) {
        draw_text(COLUMN(0), ROW(r), ">>>>> ARMED! <<<<<");
    } else {
        draw_text(COLUMN(0), ROW(r), "     disarmed     ");
    }
}
Beispiel #3
0
void Display::update_prearm(uint8_t r)
{
    if (AP_Notify::flags.pre_arm_check) {
        draw_text(COLUMN(0), ROW(r), "Prearm: passed    ");
    } else {
        draw_text(COLUMN(0), ROW(r), "Prearm: failed    ");
    }
}
Beispiel #4
0
void Display::update_ekf(uint8_t r)
{
    if (AP_Notify::flags.ekf_bad) {
        draw_text(COLUMN(0), ROW(r), "EKF:    fail");
    } else {
        draw_text(COLUMN(0), ROW(r), "EKF:    ok  ");
    }
}
Beispiel #5
0
char *ConstructCursorPositionReport() {
	char *s = ".[##;##R";
	s[2] = (COLUMN(TermInfo)/10) + 48;
	s[3] = (COLUMN(TermInfo)%10) + 48;
	s[5] = (ROW(TermInfo)/10) + 48;
	s[6] = (ROW(TermInfo)%10) + 48;
	return s;
}
Beispiel #6
0
static inline int square_distance(int s1, int s2)
{
    int r = abs(RANK(s1) - RANK(s2));
    int c = abs(COLUMN(s1) - COLUMN(s2));
    if (r > c)
        return r;
    else
        return c;
};
/* compute one round of Q (short variants) */
static void RND512Q(uint8_t *x, uint32_t *y, uint32_t r) {
  uint32_t temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp;
  uint32_t* x32 = (uint32_t*)x;
  x32[ 0] = ~x32[ 0];
  x32[ 1] ^= 0xffffffff^r;
  x32[ 2] = ~x32[ 2];
  x32[ 3] ^= 0xefffffff^r;
  x32[ 4] = ~x32[ 4];
  x32[ 5] ^= 0xdfffffff^r;
  x32[ 6] = ~x32[ 6];
  x32[ 7] ^= 0xcfffffff^r;
  x32[ 8] = ~x32[ 8];
  x32[ 9] ^= 0xbfffffff^r;
  x32[10] = ~x32[10];
  x32[11] ^= 0xafffffff^r;
  x32[12] = ~x32[12];
  x32[13] ^= 0x9fffffff^r;
  x32[14] = ~x32[14];
  x32[15] ^= 0x8fffffff^r;
  COLUMN(x,y, 0,  2,  6, 10, 14,  1,  5,  9, 13, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y, 2,  4,  8, 12,  0,  3,  7, 11, 15, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y, 4,  6, 10, 14,  2,  5,  9, 13,  1, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y, 6,  8, 12,  0,  4,  7, 11, 15,  3, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y, 8, 10, 14,  2,  6,  9, 13,  1,  5, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y,10, 12,  0,  4,  8, 11, 15,  3,  7, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y,12, 14,  2,  6, 10, 13,  1,  5,  9, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
  COLUMN(x,y,14,  0,  4,  8, 12, 15,  3,  7, 11, temp_v1, temp_v2, temp_upper_value, temp_lower_value, temp);
}
Beispiel #8
0
static xmlNode *
column_save( Model *model, xmlNode *xnode )
{
	Column *col = COLUMN( model );
	int x = IM_MAX( 0, col->x - column_left_offset );
	int y = IM_MAX( 0, col->y - column_top_offset );

	xmlNode *xthis;

	if( !(xthis = MODEL_CLASS( parent_class )->save( model, xnode )) )
		return( NULL );

	/* Save sform for backwards compat with nip 7.8 ... now a workspace
	 * property.
	 */
	if( !set_iprop( xthis, "x", x ) ||
		!set_iprop( xthis, "y", y ) ||
		!set_sprop( xthis, "open", bool_to_char( col->open ) ) ||
		!set_sprop( xthis, "selected",
			bool_to_char( col->selected ) ) ||
		!set_sprop( xthis, "sform", bool_to_char( FALSE ) ) ||
		!set_iprop( xthis, "next", col->next ) || 
		!set_sprop( xthis, "name", IOBJECT( col )->name ) )
		return( NULL );

	/* Caption can be NULL for untitled columns.
	 */
	if( IOBJECT( col )->caption )
		if( !set_sprop( xthis, "caption", IOBJECT( col )->caption ) ) 
			return( NULL );

	return( xthis );
}
Beispiel #9
0
void Display::update_gps(uint8_t r)
{
    static const char * gpsfixname[] = {"Other", "NoGPS","NoFix","2D","3D","DGPS", "RTK f", "RTK F"};
    char msg [DISPLAY_MESSAGE_SIZE];
    const char * fixname;
    switch  (AP_Notify::flags.gps_status) {
        case AP_GPS::NO_GPS:
            fixname = gpsfixname[1];
            break;
        case AP_GPS::NO_FIX:
            fixname = gpsfixname[2];
            break;
        case AP_GPS::GPS_OK_FIX_2D:
            fixname = gpsfixname[3];
            break;
        case AP_GPS::GPS_OK_FIX_3D:
            fixname = gpsfixname[4];
            break;
        case AP_GPS::GPS_OK_FIX_3D_DGPS:
            fixname = gpsfixname[5];
            break;
        case AP_GPS::GPS_OK_FIX_3D_RTK_FLOAT:
            fixname = gpsfixname[6];
            break;
        case AP_GPS::GPS_OK_FIX_3D_RTK_FIXED:
            fixname = gpsfixname[7];
            break;
        default:
            fixname = gpsfixname[0];
            break;
    }
    snprintf(msg, DISPLAY_MESSAGE_SIZE, "GPS:%-5s Sats:%2u", fixname, (unsigned)AP_Notify::flags.gps_num_sats) ;
    draw_text(COLUMN(0), ROW(r), msg);
}
Beispiel #10
0
void Display::update_text(uint8_t r)
{
    char msg [DISPLAY_MESSAGE_SIZE] = {};
    char txt [NOTIFY_TEXT_BUFFER_SIZE] = {};

    const bool text_is_valid = AP_HAL::millis() - pNotify->_send_text_updated_millis < _send_text_valid_millis;
    if (!text_is_valid) {
        update_text_empty(r);
        return;
    }

    if (_movedelay > 0) {
        _movedelay--;
        return;
    }

    snprintf(txt, sizeof(txt), "%s", pNotify->get_text());

    memset(msg, ' ', sizeof(msg)-1); // leave null termination
    const uint8_t len = strlen(&txt[_mstartpos]);
    const uint8_t to_copy = (len < sizeof(msg)-1) ? len : (sizeof(msg)-1);
    memcpy(msg, &txt[_mstartpos], to_copy);

    if (len <= sizeof(msg)-1) {
        // end-of-message reached; pause scrolling a while
        _movedelay = 4;
        // reset startpos so we start scrolling from the start again:
        _mstartpos = 0;
    } else {
        _mstartpos++;
    }

    draw_text(COLUMN(0), ROW(0), msg);
 }
Beispiel #11
0
Column *
workspace_get_column( Workspace *ws )
{
	if( ICONTAINER( ws )->current )
		return( COLUMN( ICONTAINER( ws )->current ) );

	return( NULL );
}
Beispiel #12
0
void Display::update_mode(uint8_t r)
{
    char msg [DISPLAY_MESSAGE_SIZE];
    if (pNotify->get_flight_mode_str()) {
        snprintf(msg, DISPLAY_MESSAGE_SIZE, "Mode: %s", pNotify->get_flight_mode_str()) ;
        draw_text(COLUMN(0), ROW(r), msg);
    }
}
Beispiel #13
0
void Display::update_text_empty(uint8_t r)
{
    char msg [DISPLAY_MESSAGE_SIZE] = {};
    memset(msg, ' ', sizeof(msg)-1);
    _movedelay = 0;
    _mstartpos = 0;
    draw_text(COLUMN(0), ROW(r), msg);
}
Beispiel #14
0
void EraseFromCursorToEOL() {
	int i;

	for (i = COLUMN(TermInfo); i < MAXCOLS; i++) {
		SCREENCHAR(TermInfo, ROW(TermInfo), i) = ' ';
		FORMATCODE(TermInfo, ROW(TermInfo), i) = CURRENTFORMAT(TermInfo);
	}
}
Beispiel #15
0
void EraseFromSOLToCursor() {
	int i;

	for (i = 0; i < COLUMN(TermInfo); i++) {
		SCREENCHAR(TermInfo, ROW(TermInfo), i) = ' ';
		FORMATCODE(TermInfo, ROW(TermInfo), i) = FORMATCODE(TermInfo, ROW(TermInfo), 0);
	}
}
Beispiel #16
0
static void
column_child_remove( iContainer *parent, iContainer *child )
{
	Column *col = COLUMN( parent );

	workspace_set_modified( col->ws, TRUE );

	ICONTAINER_CLASS( parent_class )->child_remove( parent, child );
}
Beispiel #17
0
void SetFormat(int format, BOOL enable) {
	if (enable) {
		CURRENTFORMAT(TermInfo) = CURRENTFORMAT(TermInfo) | format;
	}
	else {
		CURRENTFORMAT(TermInfo) = CURRENTFORMAT(TermInfo) & (!format);
	}
	FORMATCODE(TermInfo, ROW(TermInfo), COLUMN(TermInfo)) = CURRENTFORMAT(TermInfo);
}
Beispiel #18
0
Datei: db.c Projekt: carnil/nodau
/* open an existing note */
int db_edit(char* search)
{
    char* date;
    char* name;
    char* text;
    char* crypt;
    int r;
    /* get the note by name */
    sql_result *result;
    result = db_get("SELECT * FROM nodau WHERE name = '%s'",search);

    /* nothing there */
    if (result->num_rows == 0) {
        db_result_free(result);
        if (config_read("edit_autocreate","false")) {
            printf("No notes match '%s'\n",search);
        } else {
            return db_new(search);
        }
        return 0;
    }

    /* get the data */
    date = db_gettime(result->data[COLUMN(0,COL_DATE)]);
    name = result->data[COLUMN(0,COL_NAME)];
    text = result->data[COLUMN(0,COL_TEXT)];
    crypt = result->data[COLUMN(0,COL_CRYPT)];

    /* get the passphrase if it's encrypted */
    if (!strcmp(crypt,"true")) {
        crypt = crypt_get_key();
        text = note_decrypt(text,crypt);
        if (!text)
            return 1;
    }

    /* edit the note */
    r = edit(name, date, text);

    /* free the result */
    db_result_free(result);

    return r;
}
Beispiel #19
0
Datei: db.c Projekt: carnil/nodau
/* list notes according to search criteria */
int db_list(char* search)
{
    sql_result *res;
    int i;
    char* pref = "match";

    /* if search is null, list all */
    if (search == NULL) {
        pref = "note";
        res = db_get("SELECT * FROM nodau");

        /* nothing there */
        if (res->num_rows == 0) {
            printf("No notes to list\n");
            db_result_free(res);
            return 0;
        }
    } else {
        /* first try a name search */
        res = db_get("SELECT * FROM nodau WHERE name LIKE '%%%s%%'",search);

        /* if there's nothing then try a time search */
        if (res->num_rows == 0) {
            unsigned int idate;
            db_result_free(res);
            /* at time */
            if (strncmp(search,"t@",2) == 0) {
                idate = db_getstamp(search+2);
                res = db_get("SELECT * FROM nodau WHERE date = %u", idate);
                /* after time */
            } else if (strncmp(search,"t+",2) == 0) {
                idate = db_getstamp(search+2);
                res = db_get("SELECT * FROM nodau WHERE date > %u", idate);
                /* before time */
            } else if (strncmp(search,"t-",2) == 0) {
                idate = db_getstamp(search+2);
                res = db_get("SELECT * FROM nodau WHERE date < %u", idate);
            }
        }
        /* nothing there */
        if (!res || !res->num_rows || !res->num_cols) {
            printf("No notes match '%s'\n",search);
            return 0;
        }
    }

    /* print the list */
    for (i=0; i<res->num_rows; i++) {
        printf("%s %d: %s\n",pref,i+1,res->data[COLUMN(i,COL_NAME)]);
    }

    /* free the result */
    db_result_free(res);

    return 0;
}
Beispiel #20
0
int MoveGen(const BOARD *board, MOVE *poss_moves, char noncaptures)
{
    int nmoves = 0;
    for(SQUARE orig = a1; orig <= h8; orig++){
        PIECE p = board->squares[orig];
        if(board->white_to_move){
            switch(p){
                case W_PAWN:
                    nmoves = WhitePawnMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case W_KNIGHT:
                    nmoves = NonSlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case W_BISHOP:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case W_ROOK:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case W_QUEEN:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case W_KING:
                    nmoves = NonSlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                default: break;
            }
            if(noncaptures) nmoves = GenerateWhiteCastle(board, poss_moves, nmoves);
        }else{
            switch(p){
                case B_PAWN:
                    nmoves = BlackPawnMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case B_KNIGHT:
                    nmoves = NonSlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case B_BISHOP:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case B_ROOK:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case B_QUEEN:
                    nmoves = SlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                case B_KING:
                    nmoves = NonSlidingMoves(board, orig, poss_moves, nmoves, noncaptures);
                    break;
                default: break;
            }
            if(noncaptures) nmoves = GenerateBlackCastle(board, poss_moves, nmoves);
        }
        if(COLUMN(orig) == H_COLUMN) orig += 8;
    }
    return nmoves;
}
Beispiel #21
0
static void
workspaceview_child_size_cb( Columnview *cview, 
	GtkAllocation *allocation, Workspaceview *wview )
{
	Workspace *ws = WORKSPACE( VOBJECT( wview )->iobject );
	Workspacegroup *wsg = workspace_get_workspacegroup( ws );

	int right, bottom;

	g_assert( IS_WORKSPACEVIEW( wview ) );

	/* Compute a new bounding box for our children.
	 */
	wview->bounding.left = 0;
	wview->bounding.top = 0;
	wview->bounding.width = 0;
	wview->bounding.height = 0;

	(void) view_map( VIEW( wview ),
		(view_map_fn) workspaceview_child_size_sub, 
		&wview->bounding, NULL );

	wview->bounding.width += 1000;
	wview->bounding.height += 1000;

#ifdef DEBUG
{
	Column *col = COLUMN( VOBJECT( cview )->iobject );

	printf( "workspaceview_child_size_cb: cview %s "
		"bb left=%d, top=%d, width=%d, height=%d\n",
		IOBJECT( col )->name, 
		wview->bounding.left,
		wview->bounding.top,
		wview->bounding.width,
		wview->bounding.height );
}
#endif /*DEBUG*/

	/* Resize our fixed if necessary.
	 */
	right = IM_RECT_RIGHT( &wview->bounding );
	bottom = IM_RECT_BOTTOM( &wview->bounding );
	if( right != wview->width || bottom != wview->height ) {
		gtk_widget_set_size_request( GTK_WIDGET( wview->fixed ), 
			right, bottom ); 

		/* Update the model hints ... it uses bounding to position
		 * loads and saves.
		 */
		ws->area = wview->bounding;
		filemodel_set_offset( FILEMODEL( wsg ), 
			ws->area.left, ws->area.top );
	}
}
Beispiel #22
0
Datei: db.c Projekt: carnil/nodau
/* encrypt an existing note, or create a new encrypted note */
int db_encrypt(char* search)
{
    /* search by name */
    sql_result *result;
    char* crypt;
    int r;
    result = db_get("SELECT * FROM nodau WHERE name = '%s'",search);

    /* there's already a note with that name */
    if (result->num_rows) {
        char* name;
        char* text;

        /* get the data */
        name = result->data[COLUMN(0,COL_NAME)];
        text = result->data[COLUMN(0,COL_TEXT)];
        crypt = result->data[COLUMN(0,COL_CRYPT)];

        /* encrypt it if it's not already */
        if (!strcmp(crypt,"false")) {
            crypt = crypt_get_key();
            r = db_update(name,text);
        } else {
            printf("Note '%s' is already encrypted\n",search);
        }
        db_result_free(result);
        return r;
    }

    /* free the search result */
    db_result_free(result);

    /* create the new entry */
    db_insert(search,"new entry");

    if (error_msg)
        fprintf(stderr,"%s\n",error_msg);

    crypt = crypt_get_key();
    /* open for editing */
    return db_edit(search);
}
Beispiel #23
0
/* Search for a column by name.
 */
Column *
workspace_column_find( Workspace *ws, const char *name )
{
	Model *model;

	if( !(model = icontainer_map( ICONTAINER( ws ),
		(icontainer_map_fn) iobject_test_name, (void *) name, NULL )) ) 
		return( NULL );

	return( COLUMN( model ) );
}
Beispiel #24
0
static void
workspace_child_add( iContainer *parent, iContainer *child, int pos )
{
	Workspace *ws = WORKSPACE( parent );
	Column *col = COLUMN( child );

	ICONTAINER_CLASS( parent_class )->child_add( parent, child, pos );

	if( col->selected )
		workspace_column_select( ws, col );
}
Beispiel #25
0
static void
column_child_add( iContainer *parent, iContainer *child, int pos )
{
	Column *col = COLUMN( parent );

	ICONTAINER_CLASS( parent_class )->child_add( parent, child, pos );

	/* Update our context.
	 */
	col->scol = column_get_subcolumn( col );
}
Beispiel #26
0
Datei: db.c Projekt: carnil/nodau
/* decrypt an existing note or create a new encrypted note */
int db_decrypt(char* search)
{
    /* search by name */
    sql_result *result;
    int r;
    result = db_get("SELECT * FROM nodau WHERE name = '%s'",search);

    /* found the note */
    if (result->num_rows) {
        char* text;
        char* crypt;

        /* get the data */
        text = result->data[COLUMN(0,COL_TEXT)];
        crypt = result->data[COLUMN(0,COL_CRYPT)];

        /* decrypt it if it is encrypted */
        if (!strcmp(crypt,"true")) {
            char* t;
            crypt = crypt_get_key();
            t = note_decrypt(text,crypt);
            if (!t)
                return 1;
            free(crypt_key);
            crypt_key = NULL;
            r = db_update(search,t);
            db_result_free(result);
            return r;
        } else {
            printf("Note '%s' is not encrypted\n",search);
            db_result_free(result);
        }
        return 0;
    }

    printf("No notes matches '%s'\n",search);
    db_result_free(result);

    return 0;
}
Beispiel #27
0
Datei: db.c Projekt: carnil/nodau
/* show an existing note */
int db_show(char* search)
{
    char* date;
    char* name;
    char* text;
    char* crypt;
    /* get the note by name */
    sql_result *result;
    result = db_get("SELECT * FROM nodau WHERE name = '%s'",search);

    /* nothing there */
    if (result->num_rows == 0) {
        printf("No notes match '%s'\n",search);
        db_result_free(result);
        return 0;
    }

    /* get the data */
    date = db_gettime(result->data[COLUMN(0,COL_DATE)]);
    name = result->data[COLUMN(0,COL_NAME)];
    text = result->data[COLUMN(0,COL_TEXT)];
    crypt = result->data[COLUMN(0,COL_CRYPT)];

    /* get the passphrase if it's encrypted */
    if (!strcmp(crypt,"true")) {
        crypt = crypt_get_key();
        text = note_decrypt(text,crypt);
        if (!text)
            return 1;
    }

    /* display the note */
    printf("%s (%s):\n%s\n",name,date,text);

    /* free the result */
    db_result_free(result);

    return 0;
}
Beispiel #28
0
static void
workspace_current( iContainer *parent, iContainer *child )
{
	Workspace *ws = WORKSPACE( parent );
	Column *col = COLUMN( child );
	Column *current = workspace_get_column( ws );

	if( current )
		current->selected = FALSE;
	if( col )
		col->selected = TRUE;

	ICONTAINER_CLASS( parent_class )->current( parent, child );
}
Beispiel #29
0
static gboolean
column_save_test( Model *model )
{
	Column *col = COLUMN( model );
	Workspace *ws = col->ws;
	Workspacegroup *wsg = workspace_get_workspacegroup( ws );

	if( wsg->save_type == WORKSPACEGROUP_SAVE_SELECTED ) 
		/* Only save columns containing selected rows.
		 */
		return( column_map( col, 
			(row_map_fn) row_is_selected, NULL, NULL ) != NULL );

	return( TRUE );
}
Beispiel #30
0
static
void
common( int el )
{
    int i, idx, row, col, digit, mask;

    rb->yield();

    for( digit = 1 ; digit <= 9 ; ++digit )
    {
        mask = DIGIT_STATE( digit );
        row = col = -1;  /* Value '9' indicates invalid */
        for( i = 0 ; i < 9 ; ++i )
        {
            /* Digit possible? */
            idx = idx_block( el, i );
            if( IS_EMPTY( idx ) && 0 == ( board[ idx ] & mask ) )
            {
                if( row < 0 )
                    row = ROW( idx );
                else
                if( row != ROW( idx ) )
                    row = 9; /* Digit appears in multiple rows */
                if( col < 0 )
                    col = COLUMN( idx );
                else
                if( col != COLUMN( idx ) )
                    col = 9; /* Digit appears in multiple columns */
            }
        }
        if( -1 != row && row < 9 )
            exmask( mask, el, row, idx_row );
        if( -1 != col && col < 9 )
            exmask( mask, el, col, idx_column );
    }
}