Beispiel #1
0
static char* csel_list_strategies (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
	int i = 0;
	char strategy[128],
		 desc[128],
		 params[128];

	switch (cmd) {
	case CLI_INIT:
		e->command = "csel list strategies";
		e->usage = "Usage: csel list strategies\n";
		return NULL;

	case CLI_GENERATE:
		return NULL;
	}


	term_color(strategy, "Strategy", COLOR_YELLOW, 0, sizeof(strategy));
	term_color(desc, "Description", COLOR_BRWHITE, 0, sizeof(desc));
	term_color(params, "Parameters", COLOR_BRWHITE, 0, sizeof(params));

	for (; i < (sizeof(strategies) / sizeof(struct strategy)); ++i)
		ast_cli(a->fd, "%s: %s\n%s: %s\n%s: %s\n%s", strategy, strategies[i].name,
				desc, strategies[i].desc, params, strategies[i].desc_params ? strategies[i].desc_params : "(none)",
				(i + 1) < (sizeof(strategies) / sizeof(struct strategy)) ? "\n" : "");

	return CLI_SUCCESS;
}
Beispiel #2
0
Datei: test.c Projekt: clibs/term
int
main(int argc, char **argv){
  term_bold();
  term_underline();
  printf("bold and underlined\n");

  term_reset();
  printf("reset\n");

  term_color("green");
  printf("ok\n");

  term_bold();
  term_color("red");
  term_background("red");
  printf("fail");
  term_reset();

  term_move_to(50, 10);
  printf("hey");
  term_move_by(1, 1);
  printf("there");
  term_move_to(0, 15);

  int w = 0, h = 0;
  term_size(&w, &h);
  printf("%dx%d\n", w, h);

  return 0;
}
Beispiel #3
0
/* If flag = 0 (default): check if s existed in 1.39.15 and print verbosely
 * the answer.
 * If flag > 0: silently return n+1 if function changed, 0 otherwise.
 *   (where n is the index of s in whatnowlist).
 * If flag < 0: -flag-1 is the index in whatnowlist
 */
int
whatnow(char *s, int flag)
{
  int n;
  char *def;
  whatnow_t wp;
  entree *ep;

  if (flag < 0) { n = -flag; flag = 0; }
  else
  {
    if (flag && strlen(s)==1) return 0; /* special case "i" and "o" */
    if (!is_identifier(s) || !is_entry_intern(s,funct_old_hash,NULL))
    {
      if (flag) return 0;
      pari_err(talker,"as far as I can recall, this function never existed");
    }
    n = 0;
    do
      def = (oldfonctions[n++]).name;
    while (def && strcmp(def,s));
    if (!def)
    {
      int m=0;
      do
        def = (functions_oldgp[m++]).name;
      while (def && strcmp(def,s));
      n += m - 1;
    }
  }

  wp=whatnowlist[n-1]; def=wp.name;
  if (def == SAME)
  {
    if (flag) return 0;
    pari_err(talker,"this function did not change");
  }
  if (flag) return n;

  if (def == REMOV)
    pari_err(talker,"this function was suppressed");
  if (!strcmp(def,"x*y"))
  {
    pariprintf("  %s is now called *.\n\n",s);
    pariprintf("    %s%s ===> %s%s\n\n",s,wp.oldarg,wp.name,wp.newarg);
    return 1;
  }
  ep = is_entry(wp.name);
  if (!ep) pari_err(bugparier,"whatnow");
  pariputs("New syntax: "); term_color(c_ERR);
  pariprintf("%s%s ===> %s%s\n\n",s,wp.oldarg,wp.name,wp.newarg);
  term_color(c_HELP);
  print_text(ep->help); pariputc('\n');
  term_color(c_NONE); return 1;
}
Beispiel #4
0
void
gp_help(const char *s, long flag)
{
  pari_sp av = avma;
  if ((flag & h_RL) == 0)
  {
    if (*s == '?') { flag |= h_LONG; s++; }
    if (*s == '?') { flag |= h_APROPOS; s++; }
  }
  term_color(c_HELP); help(s,flag); term_color(c_NONE);
  if ((flag & h_RL) == 0) pari_putc('\n');
  avma = av;
}
Beispiel #5
0
void
logger_info (char *message) {
	term_color("cyan");
  printf("  info: ");
  term_reset();
  puts(message);
}
Beispiel #6
0
void
logger_error (char *message) {
	term_color("red");
  printf("  error: ");
  term_reset();
  puts(message);
}
Beispiel #7
0
void
logger_warn (char *message) {
	term_color("yellow");
  printf("  warn: ");
  term_reset();
  puts(message);
}
Beispiel #8
0
void
logger_debug (char *message) {
	term_color("yellow");
  printf("  debug: ");
  term_reset();
  puts(message);
}
Beispiel #9
0
Datei: disp.c Projekt: erukiti/ne
void	dsp_regview(dspreg_t *drp)
{
	dspfmt_t	*dfp, *dfp_b;
	char		*p;
	int 		n,m,a,b,i;

	char		spc_buf[LN_dspbuf+1];

	for (i=0;i<drp->sizey;++i)
		{
//fprintf(stderr,"**\n");

		 dfp=drp->func(drp->vp, i, drp->sizex, drp->sizey);
		 if (dfp==NULL)
		 	continue;

		 dfp_b = dfp;
		 p=dfp->str;
		 n=drp->sizex;
		 m=0;

		 memset(spc_buf, ' ', n);
		 spc_buf[n]='\0';

		 for (;;)
		 	{
		 	 if (*p=='\0')
		 	 	{
//fprintf(stderr," *%p\n", dfp->next);
		 	 	 if (dfp->next==NULL)
		 	 	 	p=spc_buf; else
		 	 	 	{
		 	 	 	 dfp=dfp->next;
		 	 	 	 p=dfp->str;
		 	 	 	}
		 	 	}
//fprintf(stderr,"*>[%s]\n",p);

		 	 a= min(strlen(p),n-m);

		 	 term_color(dfp->col);
		 	 term_locate(drp->y+i, drp->x +m);
		 	 widthputs(p,a);

		 	 m+=a;
		 	 p+=a;

//fprintf(stderr,"---\n");

		 	 if (m>=drp->sizex)
		 	 	break;
		 	}

		 dsp_fmtsfin(dfp_b);
		}
//fprintf(stderr,"-\n");
}
Beispiel #10
0
void term_clear()
{
#ifdef CURSES
    clear();
#else
    clr_scr();
#endif
    term_color(COL_WHITE);
}
Beispiel #11
0
void kern_main(multiboot_info_t *boot_info) {
  term_clear();
  term_color(TERM_GREEN, TERM_BLACK);
  term_print("Booting\n");
  term_print("Initializing memory manager\n");
  if (mm_init(boot_info)) {
    term_print("Failed to initialize memory manager\n");
    return;
  }

  com_init();
  com_print(COM1, "Hello COM1!\n");
  log_info("This is a logging test!");
  return;
}
Beispiel #12
0
/*!
 * \brief [lua_CFunction] This function is part of the 'application' metatable
 * and is used to execute applications similar to pbx_exec() (for access from
 * lua, don't call directly)
 *
 * \param L the lua_State to use
 * \return nothing
 *
 * This funciton is executed as the '()' operator for apps accessed through the
 * 'app' table.
 *
 * \code
 * app.playback('demo-congrats')
 * \endcode
 */
static int lua_pbx_exec(lua_State *L)
{
	int res, nargs = lua_gettop(L);
	const char *data = "";
	char *app_name, *context, *exten;
	char tmp[80], tmp2[80], tmp3[LUA_EXT_DATA_SIZE];
	int priority, autoservice;
	struct ast_app *app;
	struct ast_channel *chan;

	lua_getfield(L, 1, "name");
	app_name = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	if (!(app = pbx_findapp(app_name))) {
		lua_pushstring(L, "application '");
		lua_pushstring(L, app_name);
		lua_pushstring(L, "' not found");
		lua_concat(L, 3);
		return lua_error(L);
	}
	

	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
	chan = lua_touserdata(L, -1);
	lua_pop(L, 1);
	
	context = ast_strdupa(ast_channel_context(chan));
	exten = ast_strdupa(ast_channel_exten(chan));
	priority = ast_channel_priority(chan);
	
	lua_concat_args(L, 2, nargs);
	data = lua_tostring(L, -1);

	ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
			exten, context, priority,
			term_color(tmp, app_name, COLOR_BRCYAN, 0, sizeof(tmp)),
			term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
			term_color(tmp3, data, COLOR_BRMAGENTA, 0, sizeof(tmp3)));

	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
	autoservice = lua_toboolean(L, -1);
	lua_pop(L, 1);

	if (autoservice)
		ast_autoservice_stop(chan);

	res = pbx_exec(chan, app, data);

	lua_pop(L, 1); /* pop data */
	data = "";

	if (autoservice)
		ast_autoservice_start(chan);

	/* error executing an application, report it */
	if (res) {
		lua_pushinteger(L, res);
		return lua_error(L);
	}

	if (strcmp(context, ast_channel_context(chan))) {
		lua_pushstring(L, context);
		lua_pushstring(L, ast_channel_context(chan));
		lua_pushliteral(L, "context");
	} else if (strcmp(exten, ast_channel_exten(chan))) {
		lua_pushstring(L, exten);
		lua_pushstring(L, ast_channel_exten(chan));
		lua_pushliteral(L, "exten");
	} else if (priority != ast_channel_priority(chan)) {
		lua_pushinteger(L, priority);
		lua_pushinteger(L, ast_channel_priority(chan));
		lua_pushliteral(L, "priority");
	} else {
		/* no goto - restore the original position back
		 * to lua state, in case this was a recursive dialplan
		 * call (a dialplan application re-entering dialplan) */
		lua_update_registry(L, context, exten, priority);
		return 0;
	}

	/* goto detected - construct error message */
	lua_insert(L, -3);
													
	lua_pushliteral(L, " changed from ");							    
	lua_insert(L, -3);									       
													 
	lua_pushliteral(L, " to ");								      
	lua_insert(L, -2);									       
													 
	lua_concat(L, 5);										
													 
	ast_debug(2, "Goto detected: %s\n", lua_tostring(L, -1));					
	lua_pop(L, 1);										   
													 
	/* let the lua engine know it needs to return control to the pbx */			      
	lua_pushinteger(L, LUA_GOTO_DETECTED);							   
	lua_error(L);

	return 0;
}
/*! \brief unregister codec translator */
int ast_unregister_translator(struct ast_translator *t)
{
	char tmp[80];
	struct ast_translator *u, *ul = NULL;
	ast_mutex_lock(&list_lock);
	u = list;
	while(u) {
		if (u == t) {
			if (ul)
				ul->next = u->next;
			else
				list = u->next;
			if (option_verbose > 1)
				ast_verbose(VERBOSE_PREFIX_2 "Unregistered translator '%s' from format %s to %s\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt));
			break;
		}
		ul = u;
		u = u->next;
	}
	rebuild_matrix(0);
	ast_mutex_unlock(&list_lock);
	return (u ? 0 : -1);
}
int ast_register_translator(struct ast_translator *t)
{
	char tmp[80];
	t->srcfmt = powerof(t->srcfmt);
	t->dstfmt = powerof(t->dstfmt);
	if (t->srcfmt >= MAX_FORMAT) {
		ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
		return -1;
	}
	if (t->dstfmt >= MAX_FORMAT) {
		ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
		return -1;
	}
	calc_cost(t,1);
	if (option_verbose > 1)
		ast_verbose(VERBOSE_PREFIX_2 "Registered translator '%s' from format %s to %s, cost %d\n", term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)), ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
	ast_mutex_lock(&list_lock);
	if (!added_cli) {
		ast_cli_register(&show_trans);
		added_cli++;
	}
	t->next = list;
	list = t;
	rebuild_matrix(0);
	ast_mutex_unlock(&list_lock);
	return 0;
}
Beispiel #15
0
/*!
 * \brief [lua_CFunction] This function is part of the 'application' metatable
 * and is used to execute applications similar to pbx_exec() (for access from
 * lua, don't call directly)
 *
 * \param L the lua_State to use
 * \return nothing
 *
 * This funciton is executed as the '()' operator for apps accessed through the
 * 'app' table.
 *
 * \code
 * app.playback('demo-congrats')
 * \endcode
 */
static int lua_pbx_exec(lua_State *L)
{
	int res, nargs = lua_gettop(L);
	const char *data = "";
	char *app_name, *context, *exten;
	char tmp[80], tmp2[80], tmp3[LUA_EXT_DATA_SIZE];
	int priority, autoservice;
	struct ast_app *app;
	struct ast_channel *chan;

	lua_getfield(L, 1, "name");
	app_name = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	if (!(app = pbx_findapp(app_name))) {
		lua_pushstring(L, "application '");
		lua_pushstring(L, app_name);
		lua_pushstring(L, "' not found");
		lua_concat(L, 3);
		return lua_error(L);
	}
	

	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
	chan = lua_touserdata(L, -1);
	lua_pop(L, 1);
	
	
	lua_getfield(L, LUA_REGISTRYINDEX, "context");
	context = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "exten");
	exten = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "priority");
	priority = lua_tointeger(L, -1);
	lua_pop(L, 1);

	lua_concat_args(L, 2, nargs);
	data = lua_tostring(L, -1);

	ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
			exten, context, priority,
			term_color(tmp, app_name, COLOR_BRCYAN, 0, sizeof(tmp)),
			term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
			term_color(tmp3, data, COLOR_BRMAGENTA, 0, sizeof(tmp3)));

	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
	autoservice = lua_toboolean(L, -1);
	lua_pop(L, 1);

	if (autoservice)
		ast_autoservice_stop(chan);

	res = pbx_exec(chan, app, data);

	lua_pop(L, 1); /* pop data */
	data = "";

	if (autoservice)
		ast_autoservice_start(chan);

	/* error executing an application, report it */
	if (res) {
		lua_pushinteger(L, res);
		return lua_error(L);
	}

	lua_detect_goto(L);

	return 0;
}
Beispiel #16
0
/*!
 * \brief [lua_CFunction] This function is part of the 'application' metatable
 * and is used to execute applications similar to pbx_exec() (for access from
 * lua, don't call directly)
 *
 * \param L the lua_State to use
 * \return nothing
 *
 * This funciton is executed as the '()' operator for apps accessed through the
 * 'app' table.
 *
 * \code
 * app.playback('demo-congrats')
 * \endcode
 */
static int lua_pbx_exec(lua_State *L)
{
	int res, nargs = lua_gettop(L);
	char data[LUA_EXT_DATA_SIZE] = "";
	char *data_next = data, *app_name;
	char *context, *exten;
	char tmp[80], tmp2[80], tmp3[LUA_EXT_DATA_SIZE];
	int priority, autoservice;
	size_t data_left = sizeof(data);
	struct ast_app *app;
	struct ast_channel *chan;
	
	lua_getfield(L, 1, "name");
	app_name = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	if (!(app = pbx_findapp(app_name))) {
		lua_pushstring(L, "application '");
		lua_pushstring(L, app_name);
		lua_pushstring(L, "' not found");
		lua_concat(L, 3);
		return lua_error(L);
	}
	

	lua_getfield(L, LUA_REGISTRYINDEX, "channel");
	chan = lua_touserdata(L, -1);
	lua_pop(L, 1);
	
	
	lua_getfield(L, LUA_REGISTRYINDEX, "context");
	context = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "exten");
	exten = ast_strdupa(lua_tostring(L, -1));
	lua_pop(L, 1);
	
	lua_getfield(L, LUA_REGISTRYINDEX, "priority");
	priority = lua_tointeger(L, -1);
	lua_pop(L, 1);


	if (nargs > 1) {
		int i;

		if (!lua_isnil(L, 2))
			ast_build_string(&data_next, &data_left, "%s", luaL_checkstring(L, 2));

		for (i = 3; i <= nargs; i++) {
			if (lua_isnil(L, i))
				ast_build_string(&data_next, &data_left, ",");
			else
				ast_build_string(&data_next, &data_left, ",%s", luaL_checkstring(L, i));
		}
	}
	
	ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\")\n",
			exten, context, priority,
			term_color(tmp, app_name, COLOR_BRCYAN, 0, sizeof(tmp)),
			term_color(tmp2, chan->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
			term_color(tmp3, data, COLOR_BRMAGENTA, 0, sizeof(tmp3)));

	lua_getfield(L, LUA_REGISTRYINDEX, "autoservice");
	autoservice = lua_toboolean(L, -1);
	lua_pop(L, 1);

	if (autoservice)
		ast_autoservice_stop(chan);

	res = pbx_exec(chan, app, data);
	
	if (autoservice)
		ast_autoservice_start(chan);

	/* error executing an application, report it */
	if (res) {
		lua_pushinteger(L, res);
		return lua_error(L);
	}
	return 0;
}
Beispiel #17
0
int view(int laddr) {
	int n, c;
	char c1;

	if(laddr < 0)
		return(ERROR5);

	if(laddr)
		curln = laddr;

	switch(c1 = *lp++) {

	case 'a':
		if((c  = getint() - 1) < STATUS_AREA   ||  c  > TEXT_AREA)
			return(ERROR5);
		if(*lp++ != ' ')
			return(ERROR5);

/*
		n = ((n = getint()) > 7) ? (n << 8) | 0x02 : n << 8;
		attributes[c] = (attributes[c] & 0x00fd) | n | 0x8000;
*/
/*	n = ((n = getint()) > 7 && dev_type < 3) ? (n << 8) | 0x02 : n << 8;	@@@	*/
		n = ((n = getint()) > 7) ? (n << 8) | 0x02 : n << 8;
		if(*lp++ != ' ')
			return(ERROR5);
		n = (n & 0x0fff) | ((getint() & 0x7) << 12);
		attributes[c] = (attributes[c] & 0x00fd) | n | 0x8000;
		if(c == 2) {
			term_fill(attributes[2]);
			term_color(attributes[2]);
			term_clear(TERM_CLS_SCR);
			}
		mark_line(0);
		clr_flag = 1;
		return(OK);

	case 'c':
		if((n = getint()) < 0  ||  n > screen_height-SCREEN_OFFSET)
			return(ERROR5);

		if(n)
			center_line = n - 1;
		else {
			screen_row = imax(1, imin(lastln - center_line, curln + 1));
			clear_screen1(1);
			clr_flag = 1;
			mark_line(0);
			update_screen();
			}

		return(OK);

	case 'f':
	case 'q':
		view_quick = !view_quick;
		return(OK);

	case 'l':
		n = left_margin;
		goto marg;
	case 'r':
		n = right_margin;
marg:
		if((c = *lp++) == '+')
			n += getint();
		else if(c == '-')
			n -= getint();
		else if(c == '.')
			n = curcol;
		else {
			--lp;
			n = getint();
			}

		if(c1 == 'l') {
			left_margin = imin(right_margin-1, imax(1, n));
			cc_reg = (n == left_margin);
			}
		else {
			right_margin = imax(left_margin+1, imin(LINE_LENGTH, n));
			cc_reg = (n == right_margin);
			}

		firstp->lflags |= DIRTY_FLAG;
		if(nmarks)
			mark_line(marker1);

		return(OK);

/*
	case 'm':
		menu = !menu;
		return(OK);
*/

	case 's':
		if(*lp == '-') {
			++lp;
			n = -getint();
			}
		else
			n = getint();

		screen_row = imax(1, imin(lastln - center_line, screen_row + n));
		curln = imax(1, imin(lastln, curln + n));

		clear_screen1(1);
		clr_flag = 1;
		mark_line(0);
		update_screen();
		return(OK);

	case 't':
		if((n = getint()) == 2  ||  n == 4  ||  n == 8) {
			tab_len = n - 1;
			mark_line(0);
			update_screen();
			}
		return(OK);

	case 'z':
/*
		if(zoom > NSCREEN_SIZES  ||  screen_sizes[zoom] == 0)
			zoom = 1;
		set_video_size(zoom);
*/
		clear_screen1(1);
		clr_flag = 1;
		mark_line(0);
		update_screen();
		return(OK);
		}

	return(ERROR2);
	}