Ejemplo n.º 1
0
void draw_car(char yes) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    // reset the colors
    reset_color();

    // if we are drawing a car make it cyan
    if (yes) set_color_bold(BG_CYAN);

    // draw car 0
    goto_line(street_loc[1]+car_loc[0][1]-1, street_loc[1]+car_loc[0][0]-1);
    printf(" ");

    // draw car 1
    goto_line(street_loc[1]+car_loc[1][1]-1, street_loc[1]+car_loc[1][0]-1);
    printf(" ");

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 2
0
static void
cmd_G(key_info_t key_info, keys_info_t *keys_info)
{
	if(key_info.count == NO_COUNT_GIVEN)
		goto_line(bottom);
	else
		goto_line(key_info.count);
}
Ejemplo n.º 3
0
static void
cmd_gg(key_info_t key_info, keys_info_t *keys_info)
{
	if(key_info.count == NO_COUNT_GIVEN)
		goto_line(top);
	else
		goto_line(key_info.count + top - 1);
}
Ejemplo n.º 4
0
void draw_keymap(void) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    // figure out which x y to draw it at
    int x = keymap_loc[1];
    int y = keymap_loc[0];

    // draw the keymapping
    set_color(FG_BLACK);
    set_color_bold(BG_WHITE);
    goto_line(x, y+0); printf("[c] - Car in turn lane");
    goto_line(x, y+1); printf("[w] - Press walk button");
    goto_line(x, y+2); printf("[b] - Toggle broken");
    goto_line(x, y+3); printf("[e] - Emergency for %d seconds", emergency_duration);
    goto_line(x, y+4); printf("    [-/+] - Inc/Dec");
    goto_line(x, y+5); printf("[m] - Toggle manual");
    goto_line(x, y+6); printf("    [j/k] - Next/Prev light");
    goto_line(x, y+7); printf("    [1/2/3] - Red/Yellow/Green");
    goto_line(x, y+8); printf("[r] - Redraw");

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 5
0
void draw_frame(void) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    clear_screen();
    goto_line(0,0);

    set_color_bold(FG_BLACK);
    set_color_bold(BG_WHITE);

    int x, y;
    for (y = 0; y < FRAME_HEIGHT; y++) 
    {
        for (x = 0; x < FRAME_WIDTH; x++) 
        {
            switch (frame[y][x]) 
            {
                case '-': printf("\u2500"); break;
                case '|': printf("\u2502"); break;
                case ' ': printf(" "); break;

                default: printf("%s", pipes[frame[y][x]-'0']);
            }
        }
        printf("\n");
    }

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 6
0
Archivo: misc.c Proyecto: 8l/ted
void Goto_line()
{
	extern char * return_item();
	char *s;
	int row=atoi(return_item(0))-1;
	goto_line(row);
	save_win_context(active_win);
}
Ejemplo n.º 7
0
void goto_line_activate(GtkEntry *entry,gpointer user_data)
{
    gchar *current_text;
    if (document_manager_get_current_document(main_window.docmg)) {
        current_text = (gchar *)gtk_entry_get_text(entry);
        goto_line(current_text);
    }
}
Ejemplo n.º 8
0
Archivo: cmds.c Proyecto: hankem/jed
/* the page up/down commands set cursor_motion to -1 because we do not
 want to use any goal column information */
int pagedown_cmd()
{
   int col, this_line, this_point;
   int n;

   Cursor_Motion = -1;
   if (IN_MINI_WINDOW)
     {
	scroll_completion (1);
	return 1;
     }

   if (eobp())
     {
	eob_bob_error (3);
	return 1;
     }

   n = JWindow->rows;
   if ((CBuf != JWindow->buffer) || (n == 1))
     {
	return next_visible_lines (n);
     }

   if (JWindow->trashed)
     {
	update (NULL, 0, 0, 1);
	if (JWindow->trashed) return next_visible_lines (n);
     }

   /* This is ugly. */

   this_line = LineNum;
   this_point = Point;

   col = calculate_column ();
   if (goto_bottom_of_window ())
     {
	recenter (&Number_One);
     }

   goto_column1 (&col);

   if ((Last_Key_Function == (FVOID_STAR) pageup_cmd)
       && (Jed_This_Key_Function == (FVOID_STAR) pagedown_cmd))
     {
	goto_line (&Last_Page_Line);
	if (Last_Page_Point < CLine->len)
	  Point = Last_Page_Point;
     }
   else if (CLine->next == NULL) eol();
   else bol ();

   Last_Page_Line = this_line;
   Last_Page_Point = this_point;

   return(1);
}
Ejemplo n.º 9
0
Archivo: misc.c Proyecto: 8l/ted
K_GotoGrep(int replace)
{
char *ss=edbf[cursor_row].cstr;
int len=edbf[cursor_row].len;
char *p,*q,*fn,*t;
int row,i;
char s[2048];

if (!ss||!len) return;
memcpy(s,ss,len);
if (!(p=strchr(s,':'))) return;
t=p-1;
while (*t==' ') t--;
t++;
*t=0;
p++;
fn=s;
if (!(q=strchr(p,':'))) return;
*q=0;
while(*p==' ') p++;
#if	0
printf("--%s---%s---\n",fn,p);
#endif
row=atoi(p);
row--;

for(i=0;i<file_no;i++) {
	if (!strcmp(edstate[i].fname,fn)) break;
}
if (i<file_no) {
	goto_file(i);
	goto_line(row);
	return;
}
if (replace) {
	nosave=1;
	close_file_noexit();
}
save_edstate();
#if	0
strcpy(fname,fn);
#endif
edit_file(fn);
goto_line(row);
}
Ejemplo n.º 10
0
Archivo: prefs.c Proyecto: vigna/ne
static char *virtual_extension(buffer * const b) {
	if (virt_ext == NULL) return NULL;
	/* If the buffer filename has an extension, check that it's in extra_ext. */
	const char * const filename_ext = extension(b->filename);
	if (filename_ext != NULL) {
		int i;
		for(i = 0; i < num_extra_exts; i++)
			if (fnmatch(extra_ext[i], filename_ext, 0) == 0) break;
		if (i == num_extra_exts) return NULL;
	}

	/* Reduce the maximum number of lines to scan so that no more
	than REGEX_SCAN_LIMIT characters are regex'd. */
	int64_t line_limit = 0, pos_limit = -1, len = 0;
	for(line_desc *ld = (line_desc *)b->line_desc_list.head; ld->ld_node.next && line_limit < max_max_line;
		ld = (line_desc *)ld->ld_node.next, line_limit++)
		if ((len += ld->line_len + 1) > REGEX_SCAN_LIMIT) {
			line_limit++;
			pos_limit = REGEX_SCAN_LIMIT - (len - ld->line_len - 1);
			break;
		}

	int64_t earliest_found_line = INT64_MAX;
	char *ext = NULL;

	const int64_t b_cur_line    = b->cur_line;
	const int64_t b_cur_pos     = b->cur_pos;
	const int     b_search_back = b->opt.search_back;
	const int     b_case_search = b->opt.case_search;
	const int     b_last_was_regexp = b->last_was_regexp;
	char * const find_string    = b->find_string;

	b->opt.search_back = true;

	for(int i = 0; earliest_found_line > 0 && i < num_virt_ext && !stop; i++) {
		int64_t min_line = -1; /* max_line is 1-based, but internal line numbers (min_line) are 0-based. */
		/* Search backwards in b from max_line for the first occurance of regex. */
		b->opt.case_search = virt_ext[i].case_sensitive;
		const int64_t max_line = min(virt_ext[i].max_line, line_limit);
		goto_line(b, max_line - 1);
		goto_pos(b, max_line == line_limit && pos_limit != -1 ? pos_limit : b->cur_line_desc->line_len);
		b->find_string = virt_ext[i].regex;
		b->find_string_changed = 1;
		while (find_regexp(b, NULL, true, false) == OK) {
			min_line = b->cur_line;
			D(fprintf(stderr, "[%d] --- found match for '%s' on line <%d>\n", __LINE__, ext, min_line);)
			if (min_line == 0) break;
		}
		if (min_line > -1) {
			if (min_line < earliest_found_line) {
				earliest_found_line = min_line;
				ext = virt_ext[i].ext;
			}
		}
	}
Ejemplo n.º 11
0
void draw_status(int y, const char *msg) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    set_color(FG_BLACK);
    set_color_bold(BG_WHITE);

    goto_line(status_loc[1], status_loc[0]+y);
    printf("                                               "); 

    goto_line(status_loc[1], status_loc[0]+y);
    printf(msg);

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 12
0
void
cmd_delete()
{
  int m, n;
  get_int_opt(&m);
  next_arg();
  get_int_opt(&n);
  if (m > n) notif_error("First argument cannot be greater than the second");
  copy_lines(m - 1);
  if (m < ln) notif_error("Invalid line number");
  goto_line(n + 1);
}
Ejemplo n.º 13
0
Archivo: cmds.c Proyecto: hankem/jed
int pageup_cmd (void)
{
   int col, this_line, this_point;
   int n;

   Cursor_Motion = -1;

   if (IN_MINI_WINDOW)
     {
	scroll_completion (-1);
	return 1;
     }

   if (bobp())
     {
	eob_bob_error (-3);
	return 1;
     }

   n = JWindow->rows;
   if ((CBuf != JWindow->buffer) || (n == 1))
     {
	return prev_visible_lines (n);
     }

   if (JWindow->trashed)
     {
	update (NULL, 0, 0, 1);
	if (JWindow->trashed) return prev_visible_lines (n);
     }

   this_line = LineNum;
   this_point = Point;
   col = calculate_column ();
   goto_top_of_window ();
   (void) goto_column1(&col);
   recenter(&JWindow->rows);

   if ((Last_Key_Function == (FVOID_STAR) pagedown_cmd)
       && (Jed_This_Key_Function == (FVOID_STAR) pageup_cmd))
     {
	goto_line (&Last_Page_Line);
	if (Last_Page_Point < CLine->len)
	  Point = Last_Page_Point;
     }
   else
     bol (); /* something like: Point = point_column(JWindow->column) better? */
   Last_Page_Line = this_line;
   Last_Page_Point = this_point;
   return(1);
}
Ejemplo n.º 14
0
void
cmd_replace()
{
  int m, n;
  get_int_opt(&m);
  next_arg();
  get_int_opt(&n);
  if (m > n) notif_error("First argument cannot be greater than the second");
  next_arg();
  copy_lines(m - 1);
  if (m < ln) return;
  goto_line(n + 1);
  write_text();
}
Ejemplo n.º 15
0
void clear_instruction_area(){
	goto_line(INSTRUCTION_LINE);
	clear_line();
	goto_line(INSTRUCTION_LINE+1);
	clear_line();
	goto_line(INSTRUCTION_LINE+2);
	clear_line();
	goto_line(INSTRUCTION_LINE+3);
	clear_line();
	goto_line(INSTRUCTION_LINE+4);
	clear_line();
	goto_line(INSTRUCTION_LINE+5);
	clear_line();
	goto_line(INSTRUCTION_LINE+6);
	clear_line();
	goto_line(INSTRUCTION_LINE);
}
Ejemplo n.º 16
0
// prints out a line in this format:
//
// [print_count] [Eater: num] [Bites: bites] ...
//
void print(int type, Eater eater) {

    // if we are skipping debug lines don't do anything
    if (type == DEBUG && !print_debug) return;

    // obtain the lock so no other thread can interrupt us
    OSSemPend(print_lock, 0, NULL);

    // if we are printing each line in place go to a unique Y coordinate
    // depending on which eater we are, then clear the line
    if (print_inplace) {
        goto_line(1, eater.num+1);
        clear_line();
    }

    // display the print count in gray
    set_color_bold(30);
    printf("[%4d] ", print_count);

    // print which eater we are and how many bites we've taken
    set_color_bold(31+eater.num);
    printf("[Eater: %d] [Bites: %d] ", eater.num, eater.bites);

    // if we are eating we want to see it in bold
    if (eater.state == EATING)
        set_color_bold(31+eater.num);
    else
        set_color(31+eater.num);

    // if this is a debug message we want it to be bold
    if (type == DEBUG) set_color_bold(30);

    // print out the status message for this state
    switch (eater.state) {
        case THINKING:      printf("Thinking for %ds\n", eater.time); break;
        case WAITING_LEFT:  printf("Waiting to pick up left fork (%d)...\n", eater.left_fork); break;
        case WAITING_RIGHT: printf("Waiting to pick up right fork (%d)...\n", eater.right_fork); break;
        case EATING:        printf("Eating for %ds\n", eater.time); break;
        case PUTTING_RIGHT: printf("Putting down right fork (%d)...\n", eater.right_fork); break;
        case PUTTING_LEFT:  printf("Putting down left fork (%d)...\n", eater.left_fork); break;
    }
        
    // we just printed a line, increment the count
    print_count++;

    // we're done, release the lock
    OSSemPost(print_lock);
}
Ejemplo n.º 17
0
void syntax_add_lines(gchar *output)
{
	GtkTreeIter   iter;
	gchar *copy;
	gchar *token;
	gchar *line_number;
	gchar *first_error = NULL;
	gint line_start;
	gint line_end;
	gint indent;

	first_error = 0;
	copy = output;

	while ((token = strtok(copy, "\n"))) {
		if ((strncmp(token, "PHP Warning:  ", MIN(strlen(token), 14))!=0) && (strncmp(token, "Content-type", MIN(strlen(token), 12))!=0)) { 
			gtk_list_store_append (main_window.lint_store, &iter);
			gtk_list_store_set (main_window.lint_store, &iter, 0, token, -1);
	
			line_number = strrchr(token, ' ');
			line_number++;
	
			if (atoi(line_number)>0) {
				if (!first_error) {
					first_error = line_number;
				}
				indent = gtk_scintilla_get_line_indentation(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
	
				line_start = gtk_scintilla_position_from_line(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
				line_start += (indent/preferences.indentation_size);
	
				line_end = gtk_scintilla_get_line_end_position(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
			
				gtk_scintilla_start_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_start, 128);
				gtk_scintilla_set_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_end-line_start, INDIC2_MASK);
			}
			else {
				g_print("Line number is 0\n");
			}
		}
		copy = NULL;
	}

	if (first_error) {
		goto_line(first_error);
	}
}
Ejemplo n.º 18
0
void draw_street(void) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    set_color_bold(FG_WHITE);

    int x, y;
    for (y = 0; y < HEIGHT; y++)
    {
        goto_line(street_loc[1], street_loc[0]+y);

        for (x = 0; x < WIDTH; x++)
        {
 
            switch (diagram[y][x])
            {
                // http://www.utf8-chartable.de/unicode-utf8-table.pl

                // lane markers
                case '=': set_color_dim(FG_YELLOW); printf("\u2550"); break;
                case ',': set_color_dim(FG_YELLOW); printf("\u2551"); break;
                case '-': set_color_bold(FG_WHITE); printf("\u2500"); break;
                case '|': set_color_bold(FG_WHITE); printf("\u2502"); break;
                case 'v': set_color_bold(FG_WHITE); printf("\u2518"); break;
                case 'r': set_color_bold(FG_WHITE); printf("\u250C"); break;
                case 'n': set_color_bold(FG_WHITE); printf("\u2510"); break;
                case 'l': set_color_bold(FG_WHITE); printf("\u2514"); break;

                // cross walks
                case 'h': printf(" "); break;
                case 'c': printf("C"); break;

                default: printf("%c", diagram[y][x]);
            }
        }
    }

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 19
0
void lint_row_activated (GtkTreeSelection *selection, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  gchar *line;
  gchar *space;

  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
    gtk_tree_model_get (model, &iter, 0, &line, -1);

    // Get the line
    space = strrchr(line, ' ');
    space++;
    // Go to that line
      goto_line(space);

    g_free (line);
  }
}
Ejemplo n.º 20
0
bool ScriptTextEditor::goto_method(const String& p_method) {


	Vector<String> functions = get_functions();

	String method_search = p_method + ":";

	for (int i=0;i<functions.size();i++) {
		String function=functions[i];

		if (function.begins_with(method_search)) {

			int line=function.get_slice(":",1).to_int();
			goto_line(line-1);
			return true;
		}
	}

	return false;
}
Ejemplo n.º 21
0
void draw_walk(int state) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);

    int i;
    for (i = 0; i < 4; i++) 
    {
        goto_line(street_loc[1] + walk_loc[i][1] - 1, 
                  street_loc[0] + walk_loc[i][0] - 1); 
        set_light_color(state);
        printf("C");
    }

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 22
0
void draw_lights(void) 
{
    // obtain the lock so no other thread can interrupt us
    pend(draw_lock);
   
    char light_arrows[6][6] = {
        "\u2193", // down
        "\u2191", // up
        "\u2192", // right
        "\u2191", // up
        "\u2193", // down
        "\u2190"  // left
    };

    int i = 0;
    for (i = 0; i < 6; i++) 
    {
        // goto light x,y
        goto_line(street_loc[1]+light_loc[i][1]-1, street_loc[0]+light_loc[i][0]-1); 
        
        if (manual_mode && i == selected_light) set_color_bold(BG_BLUE);

        // set it to proper color
        set_light_color(lights[i]); 

        // draw the arrow for this light
        printf(light_arrows[i]);

        reset_color();
    }

    reset_color();
    hide_cursor();

    // we're done, release the lock
    post(draw_lock);
}
Ejemplo n.º 23
0
// main() has a brief setup and starts one background thread.
// then it enters one big while loop for testing multiple capes.
int main(){
	int ret;
	float volt;
	imu_data_t data; // not really used, just necessary to test imu
	// use defaults for now, except also enable magnetometer.
	imu_config_t conf = get_default_imu_config();
	conf.enable_magnetometer=1;

	// counters for how many pass and fail
	num_passes = 0;
	num_fails = 0;

	// initialize_cape, this should never fail unless software is not set up
	// in which case a useful error message should be printed out.
	if(initialize_cape()<0){
		printf("initialize_cape() failed, this is a software issue,\n");
		printf("not a hardware issue. Try running install.sh and restart\n");
		return -1;
	}

	// set up the button handlers once
	set_pause_pressed_func(&on_pause_pressed);
	set_pause_released_func(&on_pause_released);
	set_mode_pressed_func(&on_mode_pressed);
	set_mode_released_func(&on_mode_released);

	// start blinking thread for 6V test
	pthread_create(&blinking_thread, NULL, blinking_function, (void*) NULL);

	// print welcome
	clear_screen();
	goto_line(0);
	printf("Welcome to the Robotics Cape tester!\n\n");
	printf("this will walk you through testing multiple capes and keep\n");
	printf("track of how many pass and fail.\n");
	printf("Closing the program erases the pass/fail count.\n\n");
	printf("Press enter to begin, anything else to quit.\n");
	if(continue_or_quit()<1){
		goto END;
	}

	/***************************************************************************
	* Begin main while loop
	***************************************************************************/
	while(get_state()!=EXITING){
		line = 0; // reset current printing line to top of terminal
		set_led(RED,OFF);
		set_led(GREEN,OFF);
		
		// clear screen and print pass/fail header
		clear_screen();
		goto_line(line);
		printf("passes: %d  fails: %d\n", num_passes, num_fails);
		line+=2;
		
		
		goto_line(INSTRUCTION_LINE-1);
		printf("*******************************************************************\n");
		printf("Place a new cape in the test jig but don't connect anything else.\n");
		printf("Press any key to start test.\n");
		
		// wait to start test
		if(continue_or_quit()<0){
			goto END;
		}

		/***********************************************************************
		* begin list of tests
		***********************************************************************/
		// make sure 12V DC supply is disconnected
CHECK_DC_DISCONNECT:
		volt = get_dc_jack_voltage();
		if(volt>2.0){
			clear_instruction_area();
			printf("Voltage detected on the DC jack input. This is supposed to be\n");
			printf("disconnected for this part of the test.\n");
			printf("Disconnect and hit ENTER to continue\n");
			printf("If the DC supply was disconnected, there may be a problem with resistors\n");
			printf("R1 or R14, press any key other than ENTER to FAIL this test.\n");
			ret = continue_or_quit();
			if(ret==1) goto CHECK_DC_DISCONNECT;
			else if(ret<0) goto END;
			else{
				goto_line(line);
				printf("FAILED	DC JACK VOLTAGE TEST\n");
				line++;
				fail_test();
				continue;
			}
		}

		// test imu
		ret = initialize_imu(&data, conf);
		power_off_imu();
		goto_line(line);
		line++;
		if(ret<0){
			printf("FAILED	MPU9250 IMU\n");
			fail_test();
			continue; // go to beginning to test next cape
		}
		printf("PASSED	MPU9250 IMU\n");

		// test barometer
		ret = initialize_barometer(BMP_OVERSAMPLE_16,BMP_FILTER_OFF);
		power_off_barometer();
		goto_line(line);
		line++;
		if(ret<0){
			printf("FAILED	BMP280 BAROMETER\n");
			fail_test();
			continue; // go to beginning to test next cape
		}
		printf("PASSED	BMP280 BAROMETER\n");

		// test buttons/LEDS
		clear_instruction_area();
		printf("Press the PAUSE button on cape, the RED led should light up.\n");
		printf("Press the MODE button on cape, the GREEN led should light up.\n");
		printf("Press ENTER to indicate the buttons/leds work\n");
		printf("Press any other key to indicate a failure\n");
		ret = continue_or_quit();
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	BUTTON/LED\n");
			fail_test();
			continue;
		}
		else if(ret<0) goto END;
		printf("PASSED	BUTTON/LED\n");

		// DC power jack ADC check
		clear_instruction_area();
		printf("Plug in the 12V power supply, GREEN CHG LED should turn on.\n");
		printf("Press ENTER if the GREEN CHG LED turns on\n");
		printf("Press any other key if not\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	CHARGER\n");
			printf("CHG_IC may be bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	CHARGER\n");
		volt = get_dc_jack_voltage();
		if(volt<11.0 || volt>13.0){
			printf("FAILED	12V DC VOLTAGE\n");
			printf("measuring %0.2fV at DC jack, should be roughly 12V\n", volt);
			printf("Resistors R1 or R14 may be bad, shorted, or missing.\n");
			fail_test();
			continue;
		}
		line++;
		printf("PASSED	12V DC VOLTAGE\n");

		// 5V regulator test
		clear_instruction_area();
		printf("Plug in the 4-pin dongle to PWR socket\n");
		printf("Press ENTER if the dongle LED lights up, any other key if not.\n");
		ret = continue_or_quit();
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	5V REGULATOR\n");
			printf("Diode D3 or IC 5VREG may be bad\n");
			fail_test();
			continue;
		}
		else if(ret<0) goto END;
		printf("PASSED	5V REGULATOR\n");

		// battery ADC check
		clear_instruction_area();
		printf("Plug in 2-cell battery and press any key to continue\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		volt = get_battery_voltage();
		goto_line(line);
		line++;
		if(volt<5.0 || volt>9.0){
			printf("FAILED	BATTERY VOLTAGE\n");
			printf("measuring %0.2fV at battery, should be between 6 and 8.4\n", volt);
			printf("Resistors R19 or R25 may be bad, shorted, or missing.\n");
			fail_test();
			continue;
		}
		printf("PASSED	BATTERY VOLTAGE\n");

		// battery discharge check
		clear_instruction_area();
		printf("Disconnect the 12V DC power supply.\n");
		printf("If 4-pin dongle LED is still lit, press ENTER\n");
		printf("Otherwise press any other key.\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	BATTERY DISCHARGE\n");
			printf("Diode D2, or mosfet Q3 are bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	BATTERY DISCHARGE\n");

		// 6V regulator check
		clear_instruction_area();
		printf("Plug in the 3-pin dongle into any of the 8 servo channels.\n");
		printf("If the dongle LED is blinking press ENTER.\n");
		printf("Otherwise press any other key.\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	6VREG\n");
			printf("AOZ1284PI 6VREG or supporting components are bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	6VREG CHECK\n");

		// END OF TESTING THIS CAPE, PASSED!!!
		num_passes++;
		printf("COMPLETE TEST PASSED\n");
		goto_line(0);
		printf("passes: %d  fails: %d\n", num_passes, num_fails);
		clear_instruction_area();
		printf("Press any key to continue with next cape\n");
		continue_or_quit();
		if(ret<0) goto END;
		// now loop back to test next cape

	} // end while(get_state()!= EXITING)

		
	// if we got here there was a critical error or user hit ctrl+c
END:
	pthread_join(blinking_thread, NULL);
	disable_servo_power_rail();
	cleanup_cape();
	clear_screen();
	return 0;
}
Ejemplo n.º 24
0
static void
gnome_goto_line (GtkWidget *widget, WView *view)
{
	goto_line (view);
}
Ejemplo n.º 25
0
/**
 * Edit a stream
 * @param console_in   stream to read console from
 * @param console_out  stream to write console to
 * @param stream  stream to read/write file to
 */
void muon_edit(handle_t console_in, handle_t console_out, const char *title, handle_t stream)
  {
  int rc;
  int i;

  editor_t *ed = (editor_t *) neutron_malloc(sizeof(editor_t));
  memset(ed, 0, sizeof(editor_t));
  ed->console_in = console_in;
  ed->console_out = console_out;
  ed->title = title;
  ed->anchor = -1;

  rc = load_file(ed, stream);

  get_console_size(ed);

  bool done = false;
  int key;

  ed->refresh = 1;
  while (!done)
    {
    if (ed->refresh)
      {
      draw_screen(ed);
      draw_full_statusline(ed);
      ed->refresh = 0;
      ed->lineupdate = 0;
      }
    else if (ed->lineupdate)
      {
      update_line(ed);
      ed->lineupdate = 0;
      draw_statusline(ed);
      }
    else
      {
      draw_statusline(ed);
      }

    position_cursor(ed);

    key = getkey(ed);

    if (key >= ' ' && key <= 0x7F)
      {
      insert_char(ed, (char) key);
      }
    else
      {
      switch (key)
        {
        case KEY_F1:
          help(ed);
          break;
        case KEY_F5:
          redraw_screen(ed);
          break;
       case KEY_UP:
         up(ed, 0);
          break;
        case KEY_DOWN:
          down(ed, 0);
          break;
        case KEY_LEFT:
          left(ed, 0);
          break;
        case KEY_RIGHT:
          right(ed, 0);
          break;
        case KEY_HOME:
          home(ed, 0);
          break;
        case KEY_END:
          end(ed, 0);
          break;
        case KEY_PGUP:
          pageup(ed, 0);
          break;
        case KEY_PGDN:
          pagedown(ed, 0);
          break;
        case KEY_CTRL_RIGHT:
          wordright(ed, 0);
          break;
        case KEY_CTRL_LEFT:
          wordleft(ed, 0);
          break;
        case KEY_CTRL_HOME:
          top(ed, 0);
          break;
        case KEY_CTRL_END:
          bottom(ed, 0);
          break;
        case KEY_SHIFT_UP:
          up(ed, 1);
          break;
        case KEY_SHIFT_DOWN:
          down(ed, 1);
          break;
        case KEY_SHIFT_LEFT:
          left(ed, 1);
          break;
        case KEY_SHIFT_RIGHT:
          right(ed, 1);
          break;
        case KEY_SHIFT_PGUP:
          pageup(ed, 1);
          break;
        case KEY_SHIFT_PGDN:
          pagedown(ed, 1);
          break;
        case KEY_SHIFT_HOME:
          home(ed, 1);
          break;
        case KEY_SHIFT_END:
          end(ed, 1);
          break;
        case KEY_SHIFT_CTRL_RIGHT:
          wordright(ed, 1);
          break;
        case KEY_SHIFT_CTRL_LEFT:
          wordleft(ed, 1);
          break;
        case KEY_SHIFT_CTRL_HOME:
          top(ed, 1);
          break;
        case KEY_SHIFT_CTRL_END:
          bottom(ed, 1);
          break;
        case ctrl('a'):
          select_all(ed);
          break;
        case ctrl('c'):
          copy_selection(ed);
          break;
        case ctrl('f'):
          find_text(ed, 0);
          break;
        case ctrl('l'):
          goto_line(ed);
          break;
        case ctrl('g'):
          find_text(ed, 1);
          break;
        case KEY_TAB:
          indent(ed, INDENT);
          break;
        case KEY_SHIFT_TAB:
          unindent(ed, INDENT);
          break;
        case KEY_ENTER:
          newline(ed);
          break;
        case KEY_BACKSPACE:
          backspace(ed);
          break;
        case KEY_DEL:
          del(ed);
          break;
        case ctrl('x'):
          cut_selection(ed);
          break;
        case ctrl('z'):
          undo(ed);
          break;
        case ctrl('r'):
          redo(ed);
          break;
        case ctrl('v'):
          paste_selection(ed);
          break;
        case ctrl('s'):
          save_editor(ed);
          break;
        case ctrl('q'):
          done = close_editor(ed);
          break;
        }
      }
    }

  gotoxy(ed, 0, ed->lines + 1);

  outstr(ed, RESET_COLOR CLREOL);

  if (ed->clipboard)
    neutron_free(ed->clipboard);

  if (ed->search)
    neutron_free(ed->search);

  if (ed->linebuf)
    neutron_free(ed->linebuf);

  clear_undo(ed);
  neutron_free(ed);
  }
Ejemplo n.º 26
0
void hide_cursor(void)
{
    goto_line(1, FRAME_HEIGHT);
}
Ejemplo n.º 27
0
Archivo: search.c Proyecto: dmt4/ne
int find(buffer * const b, const char *pattern, const bool skip_first) {

	bool recompile_string;

	if (!pattern) {
		pattern = b->find_string;
		recompile_string = b->find_string_changed || b->last_was_regexp;
	}
	else recompile_string = true;

	const int m = strlen(pattern);
	if (!pattern || !m) return ERROR;

	if (recompile_string) for(int i = 0; i < sizeof d / sizeof *d; i++) d[i] = m;

	const unsigned char * const up_case = b->encoding == ENC_UTF8 ? ascii_up_case : localised_up_case;
	const bool sense_case = (b->opt.case_search != 0);
	line_desc *ld = b->cur_line_desc;
	int64_t y = b->cur_line;
	stop = false;

	if (! b->opt.search_back) {

		if (recompile_string) {
			for(int i = 0; i < m - 1; i++) d[CONV((unsigned char)pattern[i])] = m - i-1;
			b->find_string_changed = 0;
		}

		char * p = ld->line + b->cur_pos + m - 1 + (skip_first ? 1 : 0);
		const unsigned char first_char = CONV((unsigned char)pattern[m - 1]);

		while(y < b->num_lines && !stop) {

			assert(ld->ld_node.next != NULL);

			if (ld->line_len >= m) {

				while((p - ld->line) < ld->line_len) {
					const unsigned char c = CONV((unsigned char)*p);
					if (c != first_char) p += d[c];
					else {
						int i;
						for (i = 1; i < m; i++)
							if (CONV((unsigned char)*(p - i)) != CONV((unsigned char)pattern[m - i-1])) {
								p += d[c];
								break;
							}
						if (i == m) {
							goto_line(b, y);
							goto_pos(b, (p - ld->line) - m + 1);
							return OK;
						}
					}
				}
			}

			ld = (line_desc *)ld->ld_node.next;
			if (ld->ld_node.next) p = ld->line + m-1;
			y++;
		}
	}
	else {

		if (recompile_string) {
			for(int i = m - 1; i > 0; i--) d[CONV((unsigned char)pattern[i])] = i;
			b->find_string_changed = 0;
		}

		char * p = ld->line + (b->cur_pos > ld->line_len - m ? ld->line_len - m : b->cur_pos + (skip_first ? -1 : 0));
		const unsigned char first_char = CONV((unsigned char)pattern[0]);

		while(y >= 0 && !stop) {

			assert(ld->ld_node.prev != NULL);

			if (ld->line_len >= m) {

				while((p - ld->line) >= 0) {

					const unsigned char c = CONV((unsigned char)*p);
					if (c != first_char) p -= d[c];
					else {
						int i;
						for (i = 1; i < m; i++)
							if (CONV((unsigned char)*(p + i)) != CONV((unsigned char)pattern[i])) {
								p -= d[c];
								break;
							}
						if (i == m) {
							goto_line(b, y);
							goto_pos(b, p - ld->line);
							return OK;
						}
					}
				}
			}

			ld = (line_desc *)ld->ld_node.prev;
			if (ld->ld_node.prev) p = ld->line + ld->line_len - m;
			y--;
		}
	}

	return stop ? STOPPED : NOT_FOUND;
}
Ejemplo n.º 28
0
Archivo: search.c Proyecto: dmt4/ne
int find_regexp(buffer * const b, const char *regex, const bool skip_first) {

	const unsigned char * const up_case = b->encoding == ENC_UTF8 ? ascii_up_case : localised_up_case;
	bool recompile_string;

	if (!regex) {
		regex = b->find_string;
		recompile_string = b->find_string_changed || !b->last_was_regexp;
	}
	else recompile_string = true;

	if (!regex || !strlen(regex)) return ERROR;

	if (re_pb.buffer == NULL) {
		if (re_pb.buffer = malloc(START_BUFFER_SIZE)) re_pb.allocated = START_BUFFER_SIZE;
		else return OUT_OF_MEMORY;
	}

	re_pb.fastmap = (void *)d;

	/* We have to be careful: even if the search string has not changed, it
	is possible that case sensitivity has. In this case, we force recompilation. */

	if (b->opt.case_search) {
		if (re_pb.translate != 0) recompile_string = true;
		re_pb.translate = 0;
	}
	else {
		if (re_pb.translate != up_case) recompile_string = true;
		re_pb.translate = (unsigned char *)up_case;
	}

	if (recompile_string) {
		const char *actual_regex = regex;

		/* If the buffer encoding is UTF-8, we need to replace dots with UTF8DOT,
			non-word-constituents (\W) with UTF8NONWORD, and embed complemented
			character classes in UTF8COMP, so that they do not match UTF-8
			subsequences. Moreover, we must compute the remapping from the virtual
			to the actual groups caused by the new groups thus introduced. */

		if (b->encoding == ENC_UTF8) {
			const char *s;
			char *q;
			bool escape = false;
			int virtual_group = 0, real_group = 0, dots = 0, comps = 0, nonwords = 0;

			s = regex;

			/* We first scan regex to compute the exact number of characters of
				the actual (i.e., after substitutions) regex. */

			do {
				if (!escape) {
					if (*s == '.') dots++;
					else if (*s == '[') {
						if (*(s+1) == '^') {
							comps++;
							s++;
						}

						if (*(s+1) == ']') s++; /* A literal ]. */

						/* We scan the list up to ] and check that no non-US-ASCII characters appear. */
						do if (utf8len(*(++s)) != 1) return UTF8_REGEXP_CHARACTER_CLASS_NOT_SUPPORTED; while(*s && *s != ']');
					}
					else if (*s == '\\') {
						escape = true;
						continue;
					}
				}
				else if (*s == 'W') nonwords++;
				escape = false;
			} while(*(++s));

			actual_regex = q = malloc(strlen(regex) + 1 + (strlen(UTF8DOT) - 1) * dots + (strlen(UTF8NONWORD) - 2) * nonwords + (strlen(UTF8COMP) - 1) * comps);
			if (!actual_regex) return OUT_OF_MEMORY;
			s = regex;
			escape = false;

			do {
				if (escape || *s != '.' && *s != '(' && *s != '[' && *s != '\\') {
					if (escape && *s == 'W') {
						q--;
						strcpy(q, UTF8NONWORD);
						q += strlen(UTF8NONWORD);
						real_group++;
					}
					else *(q++) = *s;
				}
				else {
					if (*s == '\\') {
						escape = true;
						*(q++) = '\\';
						continue;
					}

					if (*s == '.') {
						strcpy(q, UTF8DOT);
						q += strlen(UTF8DOT);
						real_group++;
					}
					else if (*s == '(') {
						*(q++) = '(';
						if (virtual_group < RE_NREGS - 1) map_group[++virtual_group] = ++real_group;
					}
					else if (*s == '[') {
						if (*(s+1) == '^') {
							strcpy(q, UTF8COMP);
							q += strlen(UTF8COMP);
							s++;
							if (*(s+1) == ']') *(q++) = *(++s); /* A literal ]. */
							do	*(q++) = *(++s); while (*s && *s != ']');
							if (*s) *(q++) = ')';
							real_group++;
						}
						else {
							*(q++) = '[';
							if (*(s+1) == ']') *(q++) = *(++s); /* A literal ]. */
							do	*(q++) = *(++s); while (*s && *s != ']');
						}
					}
				}

				escape = false;
			} while(*(s++));

			/* This assert may be false if a [ is not closed. */
			assert(strlen(actual_regex) == strlen(regex) + (strlen(UTF8DOT) - 1) * dots + (strlen(UTF8NONWORD) - 2) * nonwords + (strlen(UTF8COMP) - 1) * comps);
		}

		const char * p = re_compile_pattern(actual_regex, strlen(actual_regex), &re_pb);

		if (b->encoding == ENC_UTF8) free((void*)actual_regex);

		if (p) {
			/* Here we have a very dirty hack: since we cannot return the error of
				regex, we print it here. Which means that we access term.c's
				functions. 8^( */
			print_message(p);
			alert();
			return ERROR;
		}

	}

	b->find_string_changed = 0;

	line_desc *ld = b->cur_line_desc;
	int64_t y = b->cur_line;
	stop = false;

	if (! b->opt.search_back) {

		int64_t start_pos = b->cur_pos + (skip_first ? 1 : 0);

		while(y < b->num_lines && !stop) {
			assert(ld->ld_node.next != NULL);

			int64_t pos;
			if (start_pos <= ld->line_len &&
				 (pos = re_search(&re_pb, ld->line ? ld->line : "", ld->line_len, start_pos, ld->line_len - start_pos, &re_reg)) >= 0) {
				goto_line(b, y);
				goto_pos(b, pos);
				return OK;
			}

			ld = (line_desc *)ld->ld_node.next;
			start_pos = 0;
			y++;
		}
	}
	else {

		int64_t start_pos = b->cur_pos + (skip_first ? -1 : 0);

		while(y >= 0 && !stop) {

			assert(ld->ld_node.prev != NULL);

			int64_t pos;
			if (start_pos >= 0 &&
				 (pos = re_search(&re_pb, ld->line ? ld->line : "", ld->line_len, start_pos, -start_pos - 1, &re_reg)) >= 0) {
				goto_line(b, y);
				goto_pos(b, pos);
				return OK;
			}

			ld = (line_desc *)ld->ld_node.prev;
			if (ld->ld_node.prev) start_pos = ld->line_len;
			y--;
		}
	}

	return stop ? STOPPED : NOT_FOUND;
}
Ejemplo n.º 29
0
Archivo: main.cpp Proyecto: CCJY/coliru
std::istream& get_line( std::istream& stm, std::string& line, unsigned int n ) {

    goto_line( stm, n ) ;
    return std::getline( stm, line ) ;
}
Ejemplo n.º 30
0
Archivo: undo.c Proyecto: hankem/jed
int undo (void) /*{{{*/
{
   int line;
   CHECK_READ_ONLY
   if (!(CBuf->flags & UNDO_ENABLED))
     {
	msg_error("Undo not enabled for this buffer.");
	return(0);
     }
   else if ((CBuf->undo == NULL)
#ifdef UNDO_HAS_REDO
	    || (0 == MORE_UNDO_INFO)
#else
	    || (LAST_UNDO->type == 0)
#endif
	    )
     {
	msg_error("No more undo information.");
	return(0);
     }
   Undo_In_Progress = 1;

   do
     {
	int undo_type;
#ifdef UNDO_HAS_REDO
	line = (int) CURRENT_UNDO->linenum;
	undo_type = CURRENT_UNDO->type & 0xFF;
#else
	line = (int) LAST_UNDO->linenum;
	undo_type = LAST_UNDO->type & 0xFF;
#endif
	if ((line <= (int) CBuf->nup)
	    || ((unsigned int) line >= CBuf->nup + Max_LineNum))
	  {
	     if (((unsigned int) line != CBuf->nup + Max_LineNum)
		 || (undo_type == NLINSERT))
	       {
		  msg_error("Next undo lies outside visible buffer.");
		  break;
	       }
	  }
	line -= CBuf->nup;
	goto_line(&line);
#ifdef UNDO_HAS_REDO
	Point = CURRENT_UNDO->point;
#else
	Point = LAST_UNDO->point;
#endif
	if (Point > CLine->len)
	  {
	     Point = 0;
	     msg_error ("Internal Error in undo: Point > CLine->len");
	     break;
	  }

	switch (undo_type)
	  {
#ifdef UNDO_HAS_REDO
	   case CDELETE: (void) jed_insert_nbytes (CURRENT_UNDO->buf, CURRENT_UNDO->misc);
	     /* Point = CURRENT_UNDO->point; */
#else
	   case CDELETE: (void) jed_insert_nbytes (LAST_UNDO->buf, LAST_UNDO->misc);
	     /* Point = LAST_UNDO->point; */
#endif
	     break;

#ifdef UNDO_HAS_REDO
	   case CINSERT: (void) jed_del_nbytes (CURRENT_UNDO->misc);
#else
	   case CINSERT: (void) jed_del_nbytes (LAST_UNDO->misc);
#endif
	     break;

	   case UNDO_POSITION:
	     break;

	   case NLINSERT: jed_del_wchar (); break;

	   default: return(1);
	  }

#ifdef UNDO_HAS_REDO
	if (CURRENT_UNDO == NULL) break;
	/*  no more undo info after overflow */

	/*  above calls to ins_chars/deln/del may overflow the undo-ring */
	if (CURRENT_UNDO->type & UNDO_UNCHANGED_FLAG)
	  {
	     mark_buffer_modified (CBuf, 0, 1);
	  }

	if (CURRENT_UNDO == FIRST_UNDO)
	  {
	     CURRENT_UNDO = NULL ;
	     break ;			/*  no more undo info  */
	  }

	CURRENT_UNDO--;
	if (CURRENT_UNDO < UNDO_RING) CURRENT_UNDO = UNDO_RING + MAX_UNDOS - 1;
#else
	if (LAST_UNDO->type & UNDO_UNCHANGED_FLAG)
	  {
	     mark_buffer_modified (CBuf, 0, 1);
	  }

	if (LAST_UNDO == FIRST_UNDO) LAST_UNDO->type = 0;
	else
	  {
	     LAST_UNDO--;
	     if (LAST_UNDO < UNDO_RING) LAST_UNDO = UNDO_RING + MAX_UNDOS - 1;
	  }
#endif
     }
#ifdef UNDO_HAS_REDO
   while ((!IS_UNDO_BD) && (CURRENT_UNDO->type));
#else
   while ((!IS_UNDO_BD) && (LAST_UNDO->type));
#endif

   message("Undo!");
   Undo_In_Progress = 0;
   return(1);
}