Example #1
0
static int
_cmd_complete(int all)
{
	char **argv = NULL;
	int argc = 0;
	int rc = 1;
	char *line = malloc(strlen(rl_line_buffer) + 2);
	if (!line) return -1;
	strcpy(line, rl_line_buffer);
	line[rl_point]   = 2;	/* empty character, will force a word */
	line[rl_point+1] = 0;

	if (tokenize_line(line, &argc, &argv) != 0)
		goto end;

	char *compl = commands_complete(root, argc, (const char **)argv, all);
	if (compl && strlen(argv[argc-1]) < strlen(compl)) {
		if (rl_insert_text(compl + strlen(argv[argc-1])) < 0) {
			free(compl);
			goto end;
		}
		free(compl);
		rc = 0;
		goto end;
	}
	/* No completion or several completion available. */
	fprintf(stderr, "\n");
	rl_forced_update_display();
	rc = 0;
end:
	free(line);
	tokenize_free(argc, argv);
	return rc;
}
Example #2
0
void _log(uint8 lvl, Color color, bool to_stdout, const char *format, va_list ap)
{
	char msg[MAX_MSG_LENGTH];
	
    if(loglevel < lvl)
        return;

	vsnprintf(msg, sizeof(msg), format, ap);
	
	_log_setcolor(to_stdout,color);	
	if(logtime)
        printf("%s\r%s %s\n", DELETE_LINE, GetTimeString().c_str(), msg);
	else
		printf("%s\r%s\n", DELETE_LINE, msg);
	_log_resetcolor(true);
	
    fflush(stdout);

	rl_forced_update_display();
    
    if(logfile)
    {
        fprintf(logfile, "%s", getDateString().c_str());
        fprintf(logfile, "%s\n", msg);
        fflush(logfile);
    }
}
Example #3
0
void __fmtstring(1, 0) cli_display(const char *fmt, va_list ap)
{
	int point, end;
	char *buf;

	point = rl_point;
	end   = rl_end;
	rl_point = rl_end = 0;

	rl_save_prompt();
	rl_clear_message();

	if (vasprintf(&buf, fmt, ap) < 0)
		fprintf(rl_outstream, "cli_display: out of memory\n");
	else {
		fprintf(rl_outstream, "%s\n", buf);
		xfree(buf);
	}

	rl_restore_prompt();

	rl_point = point;
	rl_end   = end;
	rl_forced_update_display();
}
Example #4
0
static char *
on_display(char **text, int len, int max)
{
	char *result = NULL;
	PyObject *list = NULL;
	PyObject *str  = NULL;
	PyObject *r = NULL;
	int iter;


	if (display_hook != NULL) {
#ifdef WITH_THREAD
		PyGILState_STATE gilstate = PyGILState_Ensure();
#endif

		/* create list of matches */
		list = PyList_New(0);
		/*
		 * iterate from 1 to len
		 * 0        -- coincidental string
		 * 1 .. len -- completion variants
		 */
		for (iter = 1; iter <= len; iter++)
		{
			/* create new string object */
			if (text[iter] != NULL)
			{
				str = PyString_FromString(text[iter]);
				/* and attach it to the list */
				PyList_Append(list,str);
			}
		}

		r = PyObject_CallFunction(display_hook, "Os", list, text[0]);
		rl_forced_update_display();

		if (r == NULL)
			goto error;
		if (r == Py_None) {
			result = NULL;
		}
		else {
			char *s = PyString_AsString(r);
			if (s == NULL)
				goto error;
			result = strdup(s);
		}
		Py_DECREF(r);
		goto done;
	  error:
		PyErr_Clear();
		Py_XDECREF(r);
	  done:
#ifdef WITH_THREAD
		PyGILState_Release(gilstate);
#endif
		return result;
	}
	return result;
}
Example #5
0
void
async_printf (const char *fmt, va_list ap)
{
        int tmp_rl_point = rl_point;
        int n = rl_end;
        unsigned int i;

        if (rl_end >= 0 ) {
                rl_kill_text (0, rl_end);
                rl_redisplay ();
        }
        printf ("\r");
        for (i=0 ; i<=strlen (state.prompt) ; i++)
                printf (" ");
        printf ("\r");
        vprintf (fmt, ap);
        printf ("\n");
        fflush(stdout);
        if (n) {
                rl_do_undo ();
                rl_point = tmp_rl_point;
                rl_reset_line_state ();
        }
        rl_forced_update_display ();
}
Example #6
0
static void DaoSignalHandler( int sig )
{
#ifdef DAO_WITH_THREAD
	if( ! DThread_IsMain() ) return;
#endif

	DaoVmSpace_Stop( vmSpace, 1);
	if( count ++ ) exit(1);
	count += 1;

	if( readingline ){
		printf( "\n" );
#ifdef DAO_USE_READLINE
		if( rl_end ==0 ) printf( "type \"q\" to quit.\n" );
#ifndef MACOSX
		rl_replace_line( "", 0 );
		rl_forced_update_display();
#else
		rl_reset_terminal( "" );
#endif
#endif
	}else{
		printf( "keyboard interrupt...\n" );
	}
}
Example #7
0
/* Redisplay the line buffer and completions */
static PyObject *
update(PyObject *self, PyObject *noarg)
{
	rl_forced_update_display();
	Py_INCREF(Py_None);
	return Py_None;
}
static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
{
	uint8_t opdu[ATT_MAX_MTU];
	uint16_t handle, i, olen;

	handle = att_get_u16(&pdu[1]);

	printf("\n");
	switch (pdu[0]) {
	case ATT_OP_HANDLE_NOTIFY:
		printf("Notification handle = 0x%04x value: ", handle);
		break;
	case ATT_OP_HANDLE_IND:
		printf("Indication   handle = 0x%04x value: ", handle);
		break;
	default:
		printf("Invalid opcode\n");
		return;
	}

	for (i = 3; i < len; i++)
		printf("%02x ", pdu[i]);

	printf("\n");
	rl_forced_update_display();

	if (pdu[0] == ATT_OP_HANDLE_NOTIFY)
		return;

	olen = enc_confirmation(opdu, sizeof(opdu));

	if (olen > 0)
		g_attrib_send(attrib, 0, opdu[0], opdu, olen, NULL, NULL, NULL);
}
Example #9
0
// Get new messages
void read_data(const int sockfd) {
    char messages[1000][255]; // TODO - clear message log occasionally to avoid segfault
    int messages_recorded = 0;


    while (1) {
        int count;
        char buffer[256];
        ioctl(sockfd, FIONREAD, &count);

        // If there's new data, read it
        if (count != 0) {
            bzero(buffer,256);
            read(sockfd, buffer, 255);
            strcpy(messages[messages_recorded], buffer);
            messages_recorded++;

            // Print list of messages again
            system("clear");
            int i;
            for(i = 0; i < messages_recorded; i++)
            {
               printf("%s", messages[i]);
            }

            // Redisplay composed message
            rl_forced_update_display();
        }
    }
}
Example #10
0
void rl_printf(const char *fmt, ...)
{
	va_list args;
	bool save_input;
	char *saved_line;
	int saved_point;

	save_input = !RL_ISSTATE(RL_STATE_DONE);

	if (save_input) {
		saved_point = rl_point;
		saved_line = rl_copy_text(0, rl_end);
		rl_save_prompt();
		rl_replace_line("", 0);
		rl_redisplay();
	}

	va_start(args, fmt);
	vprintf(fmt, args);
	va_end(args);

	if (save_input) {
		rl_restore_prompt();
		rl_replace_line(saved_line, 0);
		rl_point = saved_point;
		rl_forced_update_display();
		free(saved_line);
	}
}
Example #11
0
static void gnu_rl_sigint_handler (int sig) /*{{{*/
{
   (void) sig;
   rl_delete_text (0, rl_end);
   rl_point = rl_end = 0;
   fprintf (stdout, "\n");
   rl_forced_update_display ();
}
Example #12
0
int complete_method_table()
{
    if (rl_point < 2 || rl_line_buffer[rl_point-1] != '(') return 0;

    // extract the token preceding the (
    int tokenstart = rl_point-2;

    // check for special operators
    if (strchr("\\><=|&+-*/%^~", rl_line_buffer[tokenstart])){
        while (tokenstart>0 && strchr("<>=!", rl_line_buffer[tokenstart-1])){
            tokenstart--;
        }
    }
    else{
        // check for functions that might contain ! but not start with !
        while (tokenstart>=0 && (jl_word_char(rl_line_buffer[tokenstart]) ||
              rl_line_buffer[tokenstart] == '!')) {
            tokenstart--;
        }
        tokenstart++;
        // ! can't be the first character of a function, unless it's the only character
        if (tokenstart != rl_point-2 && rl_line_buffer[tokenstart] == '!'){
            tokenstart ++;
        }
    }

    jl_value_t* result = call_jl_function_with_string("repl_methods",
                                                      &rl_line_buffer[tokenstart],
                                                      rl_point-tokenstart-1);

    if (!jl_is_byte_string(result)) return 0;
    char *completions = jl_string_data(result);

    int nallocmethods = 0;
    size_t nchars = strlen(completions);
    for (size_t i=0; i<nchars; i++) nallocmethods += completions[i] == '\n';

    char **methods = malloc(sizeof(char *)*(nallocmethods+1));
    methods[0] = NULL;
    methods[1] = strtok_r(completions, "\n", &strtok_saveptr);
    if (methods[1] == NULL) return 0;
    int maxlen = strlen(methods[1]);
    int nmethods = 1;

    char *method;
    while (nmethods < nallocmethods &&
           (method = strtok_r(NULL, "\n", &strtok_saveptr))) {
        int len = strlen(method);
        if (len > maxlen) maxlen = len;
        methods[nmethods+1] = method;
        nmethods++;
    }

    rl_display_match_list(methods, nmethods, maxlen);
    free(methods);
    rl_forced_update_display();
    return 1;
}
Example #13
0
/* Completion display, get readline to still do most of the work for us */
void completion_display(char **matches, int num, int max)
{
	int temp = rl_filename_completion_desired;

	rl_filename_completion_desired = 1;
	rl_display_match_list(matches, num, max);
	rl_forced_update_display ();
	rl_filename_completion_desired = temp;
}
Example #14
0
static int ncl_trace(FILE *fp, const char *fmt, va_list ap)
{
	int dummy;

	dummy = write(1, "\r           \r", 13);
	vfprintf(fp, fmt, ap);
	rl_forced_update_display();
	return 0;
}
Example #15
0
File: rline.cpp Project: cgdb/cgdb
int rline_rl_forced_update_display(struct rline *rline)
{
    if (!rline)
        return -1;

    rl_forced_update_display();

    return 0;
}
Example #16
0
/* SIGINT handler.  This function care user's ^Z input.  */
void
sigint (int sig)
{
  /* Check this process is not child process. */
  if (! execute_flag)
    {
      rl_initialize ();
      printf ("\n");
      rl_forced_update_display ();
    }
}
Example #17
0
File: client.c Project: jpmuga/bird
static void
input_reveal(void)
{
  /* need this, otherwise some lib seems to eat pending output when
     the prompt is displayed */
  fflush(stdout);
  tcdrain(fileno(stdout));

  rl_end = input_hidden_end;
  rl_expand_prompt("bird> ");
  rl_forced_update_display();
}
static void ctrl_c(int signal)
{
#ifdef USE_READLINE
	
	rl_replace_line("", '\0');
	rl_crlf();
	rl_forced_update_display();

#else

	LOG(stdout, "\n%s", PROMPT);
	fflush(stdout);

#endif
}
Example #19
0
void
cli_display_match_list (char **matches, int len, int max)
{
  struct match_list_displayer displayer;

  rl_get_screen_size (&displayer.height, &displayer.width);
  displayer.crlf = cli_mld_crlf;
  displayer.putch = cli_mld_putch;
  displayer.puts = cli_mld_puts;
  displayer.flush = cli_mld_flush;
  displayer.erase_entire_line = cli_mld_erase_entire_line;
  displayer.beep = cli_mld_beep;
  displayer.read_key = cli_mld_read_key;

  gdb_display_match_list (matches, len, max, &displayer);
  rl_forced_update_display ();
}
Example #20
0
/************************************************************************
  Print the prompt if it is not the last thing printed.
************************************************************************/
static void con_update_prompt(void)
{
  if (console_prompt_is_showing || !console_show_prompt)
    return;

#ifdef HAVE_LIBREADLINE
  if (readline_received_enter) {
    readline_received_enter = FALSE;
  } else {
    rl_forced_update_display();
  }
#else
  con_dump(C_READY,"> ");
  con_flush();
#endif

  console_prompt_is_showing = TRUE;
}
Example #21
0
static void primary_all_cb(GSList *services, guint8 status, gpointer user_data)
{
	GSList *l;

	if (status) {
		printf("Discover all primary services failed: %s\n",
							att_ecode2str(status));
		return;
	}

	printf("\n");
	for (l = services; l; l = l->next) {
		struct gatt_primary *prim = l->data;
		printf("attr handle: 0x%04x, end grp handle: 0x%04x "
			"uuid: %s\n", prim->range.start, prim->range.end, prim->uuid);
	}

	rl_forced_update_display();
}
Example #22
0
static void primary_by_uuid_cb(GSList *ranges, guint8 status,
							gpointer user_data)
{
	GSList *l;

	if (status) {
		printf("Discover primary services by UUID failed: %s\n",
							att_ecode2str(status));
		return;
	}

	printf("\n");
	for (l = ranges; l; l = l->next) {
		struct att_range *range = l->data;
		g_print("Starting handle: 0x%04x Ending handle: 0x%04x\n",
						range->start, range->end);
	}

	rl_forced_update_display();
}
Example #23
0
static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
					guint16 plen, gpointer user_data)
{
	struct characteristic_data *char_data = user_data;
	struct att_data_list *list;
	int i;

	if (status == ATT_ECODE_ATTR_NOT_FOUND &&
				char_data->start != char_data->orig_start)
		goto done;

	if (status != 0) {
		printf("Read characteristics by UUID failed: %s\n",
							att_ecode2str(status));
		goto done;
	}

	list = dec_read_by_type_resp(pdu, plen);
	if (list == NULL)
		goto done;

	for (i = 0; i < list->num; i++) {
		uint8_t *value = list->data[i];
		int j;

		char_data->start = att_get_u16(value) + 1;

		printf("\nhandle: 0x%04x \t value: ", att_get_u16(value));
		value += 2;
		for (j = 0; j < list->len - 2; j++, value++)
			printf("%02x ", *value);
		printf("\n");
	}

	att_data_list_free(list);

	rl_forced_update_display();

done:
	g_free(char_data);
}
Example #24
0
File: macro.c Project: bminor/bash
int
rl_print_last_kbd_macro (int count, int ignore)
{
  char *m;

  if (current_macro == 0)
    {
      rl_ding ();
      return 0;
    }
  m = _rl_untranslate_macro_value (current_macro, 1);
  rl_crlf ();
  printf ("%s", m);
  fflush (stdout);
  rl_crlf ();
  FREE (m);
  rl_forced_update_display ();
  rl_display_fixed = 1;

  return 0;
}
static void
char_pipe(int ch)
{
   switch (pipe_state)
   {
   case P_Norm:
      if (ch == '\n')
	 pipe_state = P_Nl;
      fputc(ch, pipe_tmp);
      break;
   case P_Nl:
      if (ch == '.')
	 pipe_state = P_NlDot;
      else
      {
	 if (ch != '\n')
	    pipe_state = P_Norm;
	 fputc(ch, pipe_tmp);
      }
      break;
   case P_NlDot:
      pipe_state = P_Norm;
      if (ch == '\n')
      {
	 fclose(pipe_tmp);
	 system(pipe_command);
	 remove(pipe_name);
	 pipe_flag = 0;
	 write(1, "\n", 1);
	 rl_forced_update_display();
      }
      else
      {
	 fputc('.', pipe_tmp);
	 fputc(ch, pipe_tmp);
      }
      break;
   }

}
Example #26
0
static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
							gpointer user_data)
{
	struct att_data_list *list;
	guint8 format;
	int i;

	if (status != 0) {
		printf("Discover all characteristic descriptors failed: "
						"%s\n", att_ecode2str(status));
		return;
	}

	list = dec_find_info_resp(pdu, plen, &format);
	if (list == NULL)
		return;

	printf("\n");
	for (i = 0; i < list->num; i++) {
		char uuidstr[MAX_LEN_UUID_STR];
		uint16_t handle;
		uint8_t *value;
		bt_uuid_t uuid;

		value = list->data[i];
		handle = att_get_u16(value);

		if (format == 0x01)
			uuid = att_get_uuid16(&value[2]);
		else
			uuid = att_get_uuid128(&value[2]);

		bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
		printf("handle: 0x%04x, uuid: %s\n", handle, uuidstr);
	}

	att_data_list_free(list);

	rl_forced_update_display();
}
Example #27
0
static void char_cb(GSList *characteristics, guint8 status, gpointer user_data)
{
	GSList *l;

	if (status) {
		printf("Discover all characteristics failed: %s\n",
							att_ecode2str(status));
		return;
	}

	printf("\n");
	for (l = characteristics; l; l = l->next) {
		struct gatt_char *chars = l->data;

		printf("handle: 0x%04x, char properties: 0x%02x, char value "
				"handle: 0x%04x, uuid: %s\n", chars->handle,
				chars->properties, chars->value_handle,
				chars->uuid);
	}

	rl_forced_update_display();
}
Example #28
0
File: loop.c Project: tkosgrabar/tg
void net_loop (int flags, int (*is_end)(void)) {
  while (!is_end ()) {
    struct pollfd fds[101];
    int cc = 0;
    if (flags & 1) {
      fds[0].fd = 0;
      fds[0].events = POLLIN;
      cc ++;
    }

    int x = connections_make_poll_array (fds + cc, 101 - cc) + cc;
    double timer = next_timer_in ();
    if (timer > 1000) { timer = 1000; }
    if (poll (fds, x, timer) < 0) {
      /* resuming from interrupt, so not an error situation,
         this generally happens when you suspend your
         messenger with "C-z" and then "fg". This is allowed "
       */
      if (flags & 1) {
        rl_reset_line_state ();
        rl_forced_update_display ();
      }
      work_timers ();
      continue;
    }
    work_timers ();
    if ((flags & 1) && (fds[0].revents & POLLIN)) {
      unread_messages = 0;
      rl_callback_read_char ();
    }
    connections_poll_result (fds + cc, x - cc);
    if (unknown_user_list_pos) {
      do_get_user_list_info_silent (unknown_user_list_pos, unknown_user_list);
      unknown_user_list_pos = 0;
    }
  }
}
Example #29
0
static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
							gpointer user_data)
{
	uint8_t value[ATT_MAX_MTU];
	int i, vlen;

	if (status != 0) {
		printf("Characteristic value/descriptor read failed: %s\n",
							att_ecode2str(status));
		return;
	}

	if (!dec_read_resp(pdu, plen, value, &vlen)) {
		printf("Protocol error\n");
		return;
	}

	printf("\nCharacteristic value/descriptor: ");
	for (i = 0; i < vlen; i++)
		printf("%02x ", value[i]);
	printf("\n");

	rl_forced_update_display();
}
Example #30
0
DLLEXPORT void jl_clear_input(void)
{
    //todo: how to do this better / the correct way / ???
    //move the cursor to a clean line:
    char *p = rl_line_buffer;
    int i;
    for (i = 0; *p != '\0'; p++, i++) {
        if (i >= rl_point && *p == '\n') {
            jl_putc('\n', jl_uv_stdout);
        }
    }
    jl_putc('\n', jl_uv_stdout);
    jl_putc('\n', jl_uv_stdout);
    //reset state:
    rl_reset_line_state();
    reset_indent();
    rl_initialize();
    //and redisplay prompt:
    rl_forced_update_display();
    rl_on_new_line_with_prompt();
#ifdef __WIN32__
    jl_write(jl_uv_stdout, "\e[4C", 4); //hack: try to fix cursor location
#endif
}