Ejemplo n.º 1
0
void create_object(void)
{
    ::create_object();
    set_name("guard");
    add_id("dungeon guard");
    set_short("a darkling dungeon guard");
    set_long("One of the guards responsible for guarding the dungeons. " +
             "His skin is pale and his small, black eyes lack pupils. Two " +
             "long teeth protrude from his lower jaw. He stands there in " +
             "silence, observing your every move.\n");
    set_level(16);
    set_unarmed(0);
    set_db(3);
    set_hp(240);
    set_skill("combat",90);
    set_skill("longblade",90);
    set_skill("resist",90);
    set_skill("perception",90);
    set_wc(1);
    set_new_ac(1);
    add_money(random(400));

    make(ARMOUR + "dark_plate");
    make(WEAPON + "dark_bastsword");
    make(ARMOUR + "dark_lshield");
    make(ARMOUR + "dark_phelmet");
    make(ARMOUR + "dark_cloak");
    make(ARMOUR + "dark_glove");
    make(ARMOUR + "dark_boot");
    make(ARMOUR + "dark_amulet");
    init_command("wear all");
    init_command("wield sword");

    load_a_chat(15,({ "The dungeon guard tries to bite you!\n" }));
Ejemplo n.º 2
0
void create_object(void)
{
    ::create_object();
    set_name("keeper");
    add_id("dungeon keeper");
    set_short("a dungeon keeper");
    set_long("One of the darklings serving in the dungeons of the castle. " +
             "He looks human, but has pale skin and long, black hair. Long, " +
             "He has two long, protruding teeth in his lower jaw. He " +
             "observes you coldy with his small, black, pupilless eyes.\n");
    set_level(14);
    set_unarmed(0);
    set_db(3);
    set_hp(210);
    set_skill("combat",85);
    set_skill("longblade",85);
    set_skill("resist",85);
    set_skill("perception",85);
    set_aggressive(1);
    set_walking();
    set_wc(25);
    set_new_ac(25);
    add_money(random(200));
    make(ARMOUR + "dark_plate");
    make(WEAPON + "dark_lsword");
    make(ARMOUR + "dark_lshield");
    make(ARMOUR + "dark_helmet");
    make(ARMOUR + "dark_glove");
    make(ARMOUR + "dark_boot");
    make(ARMOUR + "dark_amulet");
    init_command("wear all");
    init_command("wield sword");
    make(OBJECT + "cell_key");

    load_a_chat(15,({ "The darkling tries to bite you!\n" }));
Ejemplo n.º 3
0
void create_object(void)
{
    set_short("Captain Hilary Rosen",1);
    set_long("Hilary is the captain of the Riaa. She rules it with an " +
             "iron hand. She has made it her mission in life to end piracy " +
             "and protect the bards who trust the Riaa to distribute " +
             "their goods around the world. She's not doing very well " +
             "at this particular moment.\n");
    set_name("hilary");
    add_id("captain"); //Added by Angelwings
    add_id("captain hilary");
    add_id("captain hilary rosen");
    add_id("hilary rosen");

    set_level(2);
    set_race("human");
    set_hp(80 + random(25));
    set_al(0);
    add_money(100 + random(20));
    set_gender(2);
    set_skill("combat",20 + random(10));

    make(PCWEAPON + "sword");
    make(PCARMOUR + "leather_armour");
    init_command("wield sword");
    init_command("wear armour");

    load_chat(10,({
        "Hilary says: Sign on to my crew and I'll make you rich and famous.\n",
        "Hilary says: All I do, I do for the bards.\n",
    }));
Ejemplo n.º 4
0
int		main()
{
  t_mysh	mysh;

  my_printf(GREEN "\t\t\t\t\tWelcome to mysh v_1\n\n" DEFAULT_COLOR);
  if (signal(SIGINT, SIG_IGN) == SIG_ERR)
    exit(0);
  recup_env(&mysh);
  if (my_getenv("PWD", &mysh) != 0)
    {
      if ((mysh.previous = my_strdup(mysh.recup_getenv)) == NULL)
	return (0);
    }
  else
    mysh.previous = NULL;
  while (42)
    {
      prompt(&mysh);
      if ((mysh.command = get_next_line(0, &mysh)) == NULL)
	{
	  my_putchar('\n');
	  my_exit(&mysh);
	}
      else
	init_command(&mysh);
    }
  return (0);
}
Ejemplo n.º 5
0
char* get_command_proposal(char* name) {
	static char ans[100];
	command* c;

	if(strcmp(name, "MCA") == 0) {
		c = init_command(name, "PWMD", "PWMI");
	} else if(strcmp(name, "MCA") == 0) {
		c = init_command(name, "PWMF", "PWMB");
	} else {
		c = init_command(name, "", "");
	}
	
	strcpy(ans, command_string(c));
	destroy_command(c);

	return ans;
}
Ejemplo n.º 6
0
int main()
{
	char input[CMD_MAX_LENGTH];
	Command cmd;
	int exit_code = 0;
	char prompt[1024];
	char hostname[256];
	char cwd[256];
	char *fgetsret = NULL;

	signal(SIGCHLD, sigchld_handler);

	gethostname(hostname, 256);
	getcwd(cwd, 256);
	setup_prompt(prompt, hostname, cwd);

	while(1)
	{
		printf("%s", prompt);
		fgetsret = fgets(input, CMD_MAX_LENGTH, stdin);
		if(fgetsret == NULL)
			return 0;

		delete_ending_newline(input);

		if(strlen(input) != 0)
		{
			if(cmd_exit(input, &exit_code))
				return exit_code;

			init_command(&cmd);
			if(parse_members(input, &cmd) == 0 && parse_args(&cmd) == 0)
			{
				/*
				   aff_members(&cmd);
				   aff_args(&cmd);
				   aff_redirect(&cmd);

				   printf("----------\n");
				   */

				exec_command(&cmd);
			}

			destroy_command(&cmd);
		}

		*input = '\0';
	}

	return 0;
}
Ejemplo n.º 7
0
void init_shell()
{
	int i;

	// init all commands to unused
	for (i = 0; i < MAX_COMMANDS + 1; i++)
	{
		cmd[i].name = NULL;
		cmd[i].func = NULL;
	}

	i = 0;
	// init used commands
	init_command("print_process", print_process_func, i++);
	init_command("sleep", sleep_func, i++);
	init_command("clear", clear_func, i++);
	init_command("echo", echo_func, i++);
	init_command("pacman", pacman_func, i++);

	// print_commands();

	create_process (shell_process, 3, 0, "Shell process");
}
Ejemplo n.º 8
0
void create_object(void)
{
    ::create_object();
    set_short("a woman");
    set_long("Nanicia Cirdal is a beautiful woman with long, dark hair. " +
             "She is at the well getting water. She peers suspiciously " +
             "at you.\n");
    set_name("nanicia");

    make(ARMOUR + "band");
    init_command("wear band");

    load_chat(4,({ "Nanicia says: The well is nearly dry. I bet Nirach " +
                   "is responsible for that too.\n",
                   "The woman looks down into the well.\n" }));
Ejemplo n.º 9
0
void create_object(void)
{
    ::create_object();
    set_short("a woman");
    set_long("Ylena Tiralam has long, red hair and brown eyes. She is " +
             "taking care of her newborn baby.\n");
    set_name("ylena");

    make(ARMOUR + "dress");
    init_command("wear dress");

    load_chat(4,({ "Ylena frowns as she examines her baby's diaper.\n",
                   "The woman whispers to herself: Will Nirach ever let you " +
                   "grow up, little one...\n"
                 }));
Ejemplo n.º 10
0
Archivo: app.cpp Proyecto: jj4jj/dcpots
int App::init(int argc, const char * argv[]){
    int ret = on_create(argc, argv);
    if (ret){
        GLOG_ERR("app check start error:%d !", ret);
        return -1;
    }
    ret = init_arguments(argc, argv, impl_, *this);
    if (ret){
        GLOG_ERR("init argumets error :%d !", ret);
        return -1;
    }
    _app_reload_env(impl_);
    //////////////////////////////////////////////////////////////
    const char * pidfile = cmdopt().getoptstr("pid-file");
    //1.control command
    ret = init_command(*this, pidfile);
    if (ret){
        if (ret < 0){
            GLOG_ERR("control command init error:%d !", ret);
            return -1;
        }
        else {
            exit(0);
        }
    }
    //"start:n:S:start process normal mode;"
    if (!cmdopt().hasopt("start")){
        exit(-1);
    }
    //2.daemonlization and pid running checking
    if (cmdopt().hasopt("daemon")){
        daemonlize(1, 0, pidfile);
    }
    if (pidfile && getpid() != dcs::lockpidfile(pidfile)){
        fprintf(stderr, "process should be unique running ...");
        return -2;
    }
    init_signal();
    //////////////////////////////////////////////////////////////
    ret = init_facilities(*this, impl_);
    if (ret){
        GLOG_ERR("init facilities error:%d !", ret);
        return -1;
    }
    GLOG_IFO("app framework init success !");
    //////////////////////////////////////////////////////////////////////////////////
    return on_init();
}
Ejemplo n.º 11
0
void create_object(void)
{
    ::create_object();
    set_short("a pondering man");
    set_long("Marmon Sylifin is a fisherman. There isn't much fish in the " +
             "river anymore, so he spends most of his time on the bridge " +
             "watching the river rush by.\n");
    set_name("marmon");

    make(WEAPON + "knife");
    init_command("wield knife");
    make(OBJECT + "wood");

    load_chat(4,({ "The man says: Don't go up there. To the castle I " +
                   "mean...\n",
                   "The man sighs and looks up at the castle.\n" }));
Ejemplo n.º 12
0
//Process commands pointed by input pointer (STDIN or CMD ARGS) -> Parse, Execute
void processCommand(FILE *input_ptr)
{
char input_line[MAX_LINE];
struct commands_struct *command_line = NULL;
get_cwd();
	while(fgets(input_line, MAX_LINE, input_ptr) != NULL) {
	command_line = init_command();
	if (parse(input_line, command_line) == 0) 
	{
	        execute(command_line);
	}
	get_cwd();
	free(command_line);
	fflush(input_ptr);
	}
}
Ejemplo n.º 13
0
/**
 * Process the buffer
 * Return TRUE to exit program
 */
int process_buf(char **bufargs) {
    struct Command *cmd;
    int argc = 0;

    /*  cd command*/
    if (!strcmp(bufargs[0], "cd") && bufargs[0][2] == '\0') {
        set_cwd(bufargs[1]);
        return FALSE;
    }

    /* exit command */
    if (!strcmp(bufargs[0], "exit") && bufargs[0][4] == '\0') {
        return TRUE;
    }

    /* Get argc */
    while (bufargs[argc++] != ARR_END);

    /* Set up command and first process */
    cmd = init_command();
    cmd->procHead = init_process(argc * sizeof(char *));
    cmd->runningProcs++;

    /* Allocate arguments to their processes within the command */
    if (allocate_args(argc, bufargs, cmd) == TRUE) {
        /* Invalid command */
        free_command(NULL, cmd);
        return FALSE;
    }

    /* Add the command to the global commands */
    add_global(cmd);

    /* For each process in the command, fork it and set it up as running */
    fork_command(cmd);

    /* If foreground command, then wait on processes */
    if (cmd->type == FG) {
        wait_running(cmd);

        /* set the foreground command to null and clean it */
        globalCmd[FG] = NULL;
        free_command(NULL, cmd);
    }

    return FALSE;
}
Ejemplo n.º 14
0
void create_object(void)
{
    ::create_object();
    set_short("a wierdo");
    set_long("A man who's been locked in because people thought he was a " +
             "wierdo. Well, even if he wasn't one when they locked him " +
             "up, the years spent in this dark room has turned him into " +
             "one.\n");
    set_name("wierdo");

    make(ARMOUR + "straight_jacket");
    init_command("wear armour");

    load_chat(15,({ "Wierdo says: Whisper words into my brain, assuring " +
                    "me that I'm insane...\n",
                    "Wierdo says: Sleep my friend and you will see, the " +
                    "dream is my reality...\n"}));
Ejemplo n.º 15
0
//-------------------------------------------------
// ctor
//-------------------------------------------------
datfile_manager::datfile_manager(running_machine &machine) : m_machine(machine)
{
	if (machine.options().enabled_dats() && first_run)
	{
		first_run = false;
		if (parseopen("mameinfo.dat"))
		{
			init_mameinfo();
			parseclose();
		}

		if (parseopen("command.dat"))
		{
			init_command();
			parseclose();
		}

		if (parseopen("story.dat"))
		{
			init_storyinfo();
			parseclose();
		}

		if (parseopen("messinfo.dat"))
		{
			init_messinfo();
			parseclose();
		}

		if (parseopen("sysinfo.dat"))
		{
			init_sysinfo();
			parseclose();
		}

		if (parseopen("history.dat"))
		{
			init_history();
			parseclose();
		}
	}
}
Ejemplo n.º 16
0
static void init_loop(void)
{
    topsym ->next=(symblst) NULL;
    stop_loop=NULL;
    stop_fun=NULL;
    parsing=true;

    tree_pt=0;
    label_pt=0;
    block_depth=0;
    fun_name=0;
    label=label_null;
    if (gc_set)	gc();
    initpar();
    if (cur_out != stdout) cur_out=stdout;
    strcpy(promptlabel,PROMPT);
    fflush(cur_out);
    init_command(); /* this also prompts and calls |inputline| */
    registrate_cpu();
}
Ejemplo n.º 17
0
void* command_classification(void* thread_id) {
	char* command_input;
	scanf("%s", command_input);

	command* c = init_command(command_input, "FLAG", "");

	int priority = get_priority(c);

	if(priority == HIGH_PRIORITY)
		enqueue(q1, 1);

	else if(priority == MEDIUM_PRIORITY)
		enqueue(q2, 2);

	else if(priority == LOW_PRIORITY)
		enqueue(q3, 2);

	return (void*) NULL;

}
Ejemplo n.º 18
0
void set2416(char display_num) {
	TP_OFF;
    DEBUG_DELAY
	TP_ON;
	//sys en
	init_command(0b100000000010,display_num);
	//led on
	init_command(0b100000000110,display_num);
	//blink on
	//   init_command(0b100000010010);
	//master mode
	init_command(0b100000101110,display_num);
	//RC
	init_command(0b100000110110,display_num);
	//commons option
	init_command(0b100001011110,display_num);
	//pwm duty
	init_command(0b100101111110,display_num);
    DEBUG_DELAY
	TP_OFF;
}
Ejemplo n.º 19
0
int main(int argc,char* argv[]) {

    char* response;
    char* token;

    gtk_init(&argc,&argv);

    process_args(argc,argv);

    while(receiver==-1) {
        GtkDialog* dialog=(GtkDialog*)configure(TRUE);
        gtk_dialog_run(dialog);
        frequency=configure_get_frequency();
        configure_destroy();
    }

/*
    sprintf(property_path,".ghpsdr.rx%d.properties",receiver);
    properties_load(property_path);

    token=property_get("window.x");
    if(token) window_x=atoi(token);
    token=property_get("window.y");
    if(token) window_y=atoi(token);
    token=property_get("fps");
    if(token) fps=atoi(token);
    token=property_get("frequency");
    if(token) frequency=atol(token);
    token=property_get("waterfall.high");
    if(token) waterfall_high=atof(token);
    token=property_get("waterfall.low");
    if(token) waterfall_low=atof(token);
*/

    init_command(server);

    init_monitor();

    sprintf(command,"attach %d",receiver);
    response=send_command(command);
    token=strtok(response," ");
    if(token==NULL) {
        fprintf(stderr,"null response to attach command!\n");
        exit(1);
    }
    if(strcmp(token,"OK")==0) {
        token=strtok(NULL," ");
        if(token==NULL) {
            fprintf(stderr,"expected sample rate in response to attach command!\n");
            exit(1);
        } else {
            sample_rate=atoi(token);
        }
    } else {
        fprintf(stderr,"Error: %s!\n",response);
        exit(1);
    }

    sprintf(command,"frequency %ld",frequency);
    send_command(command);

    build_ui();

    init_iq_thread(receiver);
    start_iq_thread((void*)process_iq_samples);
    sprintf(command,"start iq %d",get_iq_port());
    send_command(command);
    
    timer_id=gtk_timeout_add(1000/fps,process_samples,NULL);

    gtk_main();

    close_command();

    return 0;
}
Ejemplo n.º 20
0
/*{{{ main() */
int
main (int argc, char *argv[])
{
  int i;
  char *val, **cmd_argv = NULL;
  /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */
  static char windowid_string[20], *display_string;

  for (i = 0; i < argc; i++)
    {
      if (!strcmp (argv[i], "-e"))
	{
	  argc = i;
	  argv[argc] = NULL;
	  if (argv[argc + 1] != NULL)
	    {
	      cmd_argv = (argv + argc + 1);
	      if (cmd_argv[0] != NULL)
		rs_iconName = rs_title = my_basename (cmd_argv[0]);
	    }
	  break;
	}
    }

  rs_name = my_basename (argv[0]);

  /*
   * Open display, get options/resources and create the window
   */
  if ((display_name = getenv ("DISPLAY")) == NULL)
    display_name = ":0";

  get_options (argc, argv);

  Xdisplay = XOpenDisplay (display_name);
  if (!Xdisplay)
    {
      print_error ("can't open display %s", display_name);
      exit (EXIT_FAILURE);
    }
  extract_resources (Xdisplay, rs_name);

  /*
   * set any defaults not already set
   */
  if (!rs_title)
    rs_title = rs_name;
  if (!rs_iconName)
    rs_iconName = rs_name;
  if (!rs_saveLines || (TermWin.saveLines = atoi (rs_saveLines)) < 0)
    TermWin.saveLines = SAVELINES;

  /* no point having a scrollbar without having any scrollback! */
  if (!TermWin.saveLines)
    Options &= ~Opt_scrollBar;

#ifdef PRINTPIPE
  if (!rs_print_pipe)
    rs_print_pipe = PRINTPIPE;
#endif
  if (!rs_cutchars)
    rs_cutchars = CUTCHARS;

#ifndef NO_BOLDFONT
  if (rs_font[0] == NULL && rs_boldFont != NULL)
    {
      rs_font[0] = rs_boldFont;
      rs_boldFont = NULL;
    }
#endif
  for (i = 0; i < NFONTS; i++)
    {
      if (!rs_font[i])
	rs_font[i] = def_fontName[i];
#ifdef KANJI
      if (!rs_kfont[i])
	rs_kfont[i] = def_kfontName[i];
#endif
    }

#ifdef XTERM_REVERSE_VIDEO
  /* this is how xterm implements reverseVideo */
  if (Options & Opt_reverseVideo)
    {
      if (!rs_color[fgColor])
	rs_color[fgColor] = def_colorName[bgColor];
      if (!rs_color[bgColor])
	rs_color[bgColor] = def_colorName[fgColor];
    }
#endif

  for (i = 0; i < NRS_COLORS; i++)
    if (!rs_color[i])
      rs_color[i] = def_colorName[i];

#ifndef XTERM_REVERSE_VIDEO
  /* this is how we implement reverseVideo */
  if (Options & Opt_reverseVideo)
    {
      const char *name;
      /* swap foreground/background colors */

      name = rs_color[fgColor];
      rs_color[fgColor] = rs_color[bgColor];
      rs_color[bgColor] = name;

      name = def_colorName[fgColor];
      def_colorName[fgColor] = def_colorName[bgColor];
      def_colorName[bgColor] = name;
    }
#endif

  /* convenient aliases for setting fg/bg to colors */
  color_aliases (fgColor);
  color_aliases (bgColor);
#ifndef NO_CURSORCOLOR
  color_aliases (cursorColor);
  color_aliases (cursorColor2);
#endif /* NO_CURSORCOLOR */
#ifndef NO_BOLDUNDERLINE
  color_aliases (colorBD);
  color_aliases (colorUL);
#endif /* NO_BOLDUNDERLINE */

  Create_Windows (argc, argv);
  scr_reset ();			/* initialize screen */
  Gr_reset ();			/* reset graphics */

  /* add scrollBar, do it directly to avoid resize() */
  scrollbar_mapping (Options & Opt_scrollBar);

#ifdef DEBUG_X
  XSynchronize (Xdisplay, True);
  XSetErrorHandler ((XErrorHandler) abort);
#else
  XSetErrorHandler ((XErrorHandler) xerror_handler);
#endif

#ifdef DISPLAY_IS_IP
  /* Fixup display_name for export over pty to any interested terminal
   * clients via "ESC[7n" (e.g. shells).  Note we use the pure IP number
   * (for the first non-loopback interface) that we get from
   * network_display().  This is more "name-resolution-portable", if you
   * will, and probably allows for faster x-client startup if your name
   * server is beyond a slow link or overloaded at client startup.  Of
   * course that only helps the shell's child processes, not us.
   *
   * Giving out the display_name also affords a potential security hole
   */
  val = display_name = network_display (display_name);
  if (val == NULL)
#endif /* DISPLAY_IS_IP */
    val = XDisplayString (Xdisplay);
  if (display_name == NULL)
    display_name = val;		/* use broken `:0' value */

  i = strlen (val);
  display_string = MALLOC ((i + 9) * sizeof (char), "display_string");

  sprintf (display_string, "DISPLAY=%s", val);
  sprintf (windowid_string, "WINDOWID=%u", (unsigned int) TermWin.parent);

  /* add entries to the environment:
   * @ DISPLAY:   in case we started with -display
   * @ WINDOWID:  X window id number of the window
   * @ COLORTERM: terminal sub-name and also indicates its color
   * @ TERM:      terminal name
   */
  putenv (display_string);
  putenv (windowid_string);
  if (Xdepth <= 2)
    {
      putenv ("COLORTERM=" COLORTERMENV "-mono");
      putenv ("TERM=" TERMENV);
    }
  else
    {
#ifdef XPM_BACKGROUND
      putenv ("COLORTERM=" COLORTERMENV "-xpm");
#else
      putenv ("COLORTERM=" COLORTERMENV);
#endif
#ifdef DEFINE_XTERM_COLOR
      putenv ("TERM=" TERMENV "-color");
#else
      putenv ("TERM=" TERMENV);
#endif
    }

  init_command (cmd_argv);
  main_loop ();			/* main processing loop */
  return EXIT_SUCCESS;
}
Ejemplo n.º 21
0
int
main(int argc, char *argv[])
{
	KeySym key;
	XEvent event;
	int hidden = 1;
	int fullscreen = 0;
	int i, tmp;
	int old_height = 0;
	Window tmpwin, last_focused, current_focused;
	XWindowAttributes wa;

	/* strip the path from argv[0] if there is one */
	progname = strrchr(argv[0], '/');
	if (!progname)
		progname = argv[0];
	else
		progname++;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-h")) {
			printf("%s:\n"
				   "-e: program to execute\n"
				   "you can configure me via xresources:\n"
				   "%s*foo:value\n"
				   "foo can be any standard xterm/urxvt/st xresource or:\n"
				   "resource               default value\n\n"
				   "term:                  xterm\n"
				   "restart:               0\n"
				   "xOffset:               0\n"
				   "yOffset:               0\n"
				   "xrandrSupport:         0\n"
				   "screenWidth:           Display width\n"
				   "consoleHeight:         10\n"
				   "aniDelay:              40\n"
				   "stepSize;              1\n"
				   "toggleKey:             ControlAlt+y\n"
				   "keySmaller:            Control+KP_Subtract\n"
				   "keyBigger:             Control+KP_Add\n" "keyFull:               Alt+F11\n", progname, progname);
			exit(0);
		}
	}

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, " can not open dpy %s", XDisplayName(NULL));
	}
	screen = DefaultScreen(dpy);
	root = RootWindow(dpy, screen);
	XSetErrorHandler(handle_xerror);
	cursor = XCreateFontCursor(dpy, XC_double_arrow);
	get_defaults();
	init_win();
	init_command(argc, argv);
	init_xterm(1);
	while (1) {
		XNextEvent(dpy, &event);
		switch (event.type) {
		case FocusOut:
			/* Always keep input focus when visible */
			if (!hidden)
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			break;
		case EnterNotify:
			XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
			XSync(dpy, False);
			break;
		case LeaveNotify:
			if (last_focused && event.xcrossing.detail != NotifyInferior) {
				XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case KeyPress:
			key = XKeycodeToKeysym(dpy, event.xkey.keycode, 0);
			if (key == opt_key) {
				if (!hidden) {
					XGetInputFocus(dpy, &current_focused, &revert_to);
					if (last_focused && current_focused == termwin)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					/* else
					   XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); */
					if (opt_step && !fullscreen)
						roll(UP);
					XUnmapWindow(dpy, win);
					hidden = 1;
					XSync(dpy, False);
				}
				else {
					XGetInputFocus(dpy, &last_focused, &revert_to);
					last_focused = get_toplevel_parent(last_focused);

					if (opt_step && !fullscreen) {
						XGrabServer(dpy);
						roll(DOWN);
						XUngrabServer(dpy);
					}
					else if (opt_xrandr)
						update_geom(last_focused);
					XMoveWindow(dpy, win, opt_x, opt_y);
					XMapWindow(dpy, win);
					XRaiseWindow(dpy, win);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					hidden = 0;
					XSync(dpy, False);
					XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
				}
				break;
			}
			if (!hidden) {
				if (key == opt_key_full) {
					if (!fullscreen) {
						old_height = height;
						height = get_optimal_height(get_display_height());
						fullscreen = 1;
					}
					else {
						height = old_height;
						fullscreen = 0;
					}
				}

				/* update height inc just in case something changed for the
				 * terminal, i.e. font size */
				resize_inc = get_height_inc();
				if (key == opt_key_bigger)
					height += resize_inc;
				if (key == opt_key_smaller)
					height -= resize_inc;
				if (height < resize_inc)
					height = resize_inc;
				height = get_optimal_height(height);
				resize_term(opt_width, height);
				XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				XSync(dpy, False);
			}
			break;
		case ButtonPress:
			resize();
			XSync(dpy, False);
			break;
		case UnmapNotify:
			if (event.xunmap.window == termwin) {
				if (opt_restart) {
					if (opt_restart_hidden) {
						roll(UP);
						hidden = 1;
					}
					init_xterm(0);
					XSync(dpy, False);
					if (opt_restart_hidden && last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					else
						XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
				}
				else {
					if (last_focused)
						XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime);
					XSync(dpy, False);
					exit(0);
				}
			}
			break;
		}
	}
	return 0;
}
Ejemplo n.º 22
0
int main (int argc, char** argv)
{
  output_file = stdout;

  program_name = basename (argv[0]);
  init_command (argc-1, argv+1);

  source_path = getenv ("COVERAGE_PATH");
  if (source_path == NULL) {
    source_path = "."; }
  augment_source_path (source_path);


  while (TRUE) {
   get_command ();
   switch ((int)command) {
      case QUIT: {
        exit (0);
        break; }
      case DUMMY: {
        break; }
      case EXEC_FILE: {
        FILE *f = fopen (*arg_v, "r");
        if (f == NULL) {
          sprintf (error_message, "cannot open command file %s",
                      *arg_v);
          error (); }
        command_file_stack [++nb_command_files] = f;
        command_source = FROM_FILE;
        break; }      
      case READ_DATABASE: {
        while (arg_c-- > 0) {
          read_coverage_data (*arg_v++); }
        break; }
      case WRITE_DATABASE: {
        ensure_that_database_is_loaded ();
        while (arg_c-- > 0) {
          write_coverage_data (*arg_v++); }
        break; }
      case SHOW_LINES: {
        ensure_that_database_is_loaded ();
        while (arg_c-- > 0) {
          show_lines (basename (*arg_v++)); }
        break; }
      case SHOW_LINES_ALL: {
        collection c;
        ensure_that_database_is_loaded ();
        for (c = collections; c != NULL; c = c->next) {
          show_lines (c->file_name); }
        break; }
      case SHOW_PROCS: {
        ensure_that_database_is_loaded ();
        while (arg_c-- > 0) {
          show_procs (basename (*arg_v++)); }
        break; }
      case SHOW_PROCS_ALL: {
        collection c;
        ensure_that_database_is_loaded ();
        for (c = collections; c != NULL; c = c->next) {
          show_procs (c->file_name); }
        break; }
      case AUGMENT_SOURCE_PATH: {
        while (arg_c-- > 0) {
          augment_source_path (*arg_v++); }
        break; }
      case SELECT_OUTPUT: {
        FILE* f = fopen (*arg_v, "w"); 
        if (f == NULL) {
          sprintf (error_message,
                   "cannot open %s for output - %s", *arg_v,
                   "redirection ignored\n");
          warning (); }
        else {
          if (output_file != stdout) {
            fclose (output_file); }
          if (verbose_mode) {
            fprintf (stderr, "output file is now %s\n", *arg_v); }
          output_file = f; }
        break; }
      case VERBOSE_ON: {
        verbose_mode = TRUE;
        break; }}}

  /* exit (0); */
}
Ejemplo n.º 23
0
/*
This function is called from erlang:port_call/3. It works a lot like the control call-back,
but uses the external term format for input and output.
- command is an integer, obtained from the call from erlang (the second argument to erlang:port_call/3).
- buf and len provide the arguments to the call (the third argument to erlang:port_call/3). They're decoded using ei.
- rbuf points to a return buffer, rlen bytes long.

The return data (written to *rbuf) should be a valid erlang term in the external term format. This is converted to an
erlang term and returned by erlang:port_call/3 to the caller. If more space than rlen bytes is needed to return data,
*rbuf can be set to memory allocated with driver_alloc. This memory will be freed automatically after call has returned.
The return value (of this callback function) is the number of bytes returned in *rbuf. If ERL_DRV_ERROR_GENERAL is returned
(or in fact, anything < 0), erlang:port_call/3 will throw a BAD_ARG.

THIS IMPLEMENTATION of the callback handles two kinds of commands, INIT_COMMAND and ENGINE_COMMAND. An INIT_COMMAND should
only be issued once during the lifecycle of the driver, *before* any data is sent to the port using port_command/port_control.
The INIT_COMMAND causes the driver to load the specified shared library and call a predefined entry point (see the
erlxsl_driver header file for details) to initialize an XslEngine structure.

TODO: document ENGINE_COMMAND.
TODO: locking during ENGINE_COMMAND calls
TODO: support the transform command here as well - small binaries (which we can't/won't share/refcount) can be passed and copied...
*/
static int
call(ErlDrvData drv_data, unsigned int command, char *buf,
    int len, char **rbuf, int rlen, unsigned int *flags) {

    int i;
    int type;
    int size;
    int index = 0;
    int rindex = 0;
    /*int arity;
     *
    char cmd[MAXATOMLEN];*/
    char *data;
    DriverState state;
    DriverHandle *d = (DriverHandle*)drv_data;

    ei_decode_version(buf, &index, &i);
    if (command == INIT_COMMAND) {
        ei_get_type(buf, &index, &type, &size);
        INFO("ei_get_type %s of size = %i\n", ((char*)&type), size);
        // TODO: pull options tuple instead
        data = ALLOC(size + 1);
        ei_decode_string(buf, &index, data);
        INFO("Driver received data %s\n", data);
        state = init_provider(d, data);
    } else if (command == ENGINE_COMMAND) {
        DriverContext *ctx = ALLOC(sizeof(DriverContext));
        // ErlDrvPort port = (ErlDrvPort)d->port;
        // XslEngine *engine = (XslEngine*)d->engine;
        // ErlDrvTermData callee_pid = driver_caller(port);
        Command *cmd = init_command(NULL, ctx, NULL, init_iov(Text, 0, NULL));

        state = decode_ei_cmd(cmd, buf, &index);
        if (state == Success) {
            XslEngine *engine = (XslEngine*)d->engine;
            if (engine->command != NULL) {
                EngineState enstate = engine->command(cmd);
                if (enstate == Ok) {
                    state = Success;
                }
            }
        }
        /*ei_get_type(buf, &index, &type, &size);
        INFO("ei_get_type %s of size = %i\n", ((char*)&type), size);
        data = ALLOC(size + 1);
        ei_decode_string(buf, &index, data);*/
    } else {
        state = UnknownCommand;
    }

    ei_encode_version(*rbuf, &rindex);
    if (state == InitOk) {
        INFO("Provider configured with library %s\n", d->loader->name);
#ifdef _DRV_SASL_LOGGING
        // TODO: pull the logging_port and install it....
#endif
        ei_encode_atom(*rbuf, &rindex, "configured");
    } else if (state == Success) {
        ei_encode_tuple_header(*rbuf, &rindex, 2);
        ei_encode_atom(*rbuf, &rindex, "ok");
        if (state == OutOfMemory) {
            ei_encode_string(*rbuf, &rindex, heap_space_exhausted);
        } else if (state == UnknownCommand) {
            ei_encode_string(*rbuf, &rindex, unknown_command);
        } else {
            const char *err = (d->loader)->error_message;
            ei_encode_string_len(*rbuf, &rindex, err, strlen(err));
        }
    } else {
        ei_encode_tuple_header(*rbuf, &rindex, 2);
        ei_encode_atom(*rbuf, &rindex, "error");
        if (state == OutOfMemory) {
            ei_encode_string(*rbuf, &rindex, heap_space_exhausted);
        } else if (state == UnknownCommand) {
            ei_encode_string(*rbuf, &rindex, unknown_command);
        } else {
            const char *err = (d->loader)->error_message;
            ei_encode_string_len(*rbuf, &rindex, err, strlen(err));
        }
    }
    DRV_FREE(data);
    return(rindex);
};
Ejemplo n.º 24
0
/*
This function is called whenever the port is written to. The port should be in binary mode, see open_port/2.
The ErlIOVec contains both a SysIOVec, suitable for writev, and one or more binaries. If these binaries should be retained,
when the driver returns from outputv, they can be queued (using driver_enq_bin for instance), or if they are kept in a
static or global variable, the reference counter can be incremented.

THIS IMPLEMENTATION of the callback unpacks a set of headers from the input binary and constructs a Command object
which is then submitted to the XslEngine. When the emulator is running in SMP mode, the actual processing is done on
an async thread (using the driver_async submission mechanism) and the apply_transform function is used to wrap the
XslEngine callback functions. The results of processing are handled on a main emulator thread in the ready_async driver callback.
*/
static void
outputv(ErlDrvData drv_data, ErlIOVec *ev) {

    // char *error_msg;
    char *xml;
    char *xsl;
    char *data;

    DriverHandle *d = (DriverHandle*)drv_data;
    ErlDrvPort port = (ErlDrvPort)d->port;
    InputSpec *hspec;
    PayloadSize *hsize;

    XslTask *job;
    DriverContext *ctx;
    AsyncState *asd;
    DriverState state;
    ErlDrvTermData callee_pid = driver_caller(port);
    UInt8 *type1;
    UInt64 *size;

    if ((hspec = ALLOC(sizeof(InputSpec))) == NULL) {
        FAIL(port, "system_limit");
        return;
    }
    if ((hsize = (PayloadSize*)try_driver_alloc(port,
        sizeof(PayloadSize), hspec)) == NULL) return;

    DBG("sizeof(uint64_t): %lu \n", sizeof(UInt64));
    DBG("ev->vsize: %i \n", ev->vsize);

    // the first 8bit chunk holds the number of parameters
    type1 = ((UInt8*)ev->binv[1]->orig_bytes);
    hspec->param_grp_arity = *type1;

    // next two 8bit chunks hold the type specs
    type1++;
    hspec->input_kind = *type1;

    type1++;
    hspec->xsl_kind = *type1;

    // next two 64bit chunks hold the type specs
    type1++;
    size = ((UInt64*)type1);
    hsize->input_size = *size;

    size++;
    hsize->xsl_size = *size;

    // next comes the xml and xslt binaries, which may be in one of three places:
    // 1. if the XML binary is heap allocated, it'll be in the binv entry
    // 2. if the XML binary is not heap allocated, it'll be in the next binv entry
    // 3. if the XSL binary is not heap allocated, it'll be in the next binv entry
    //        otherwise it'll bin in the (following) SysIOVec

    // if there is enough space remaining in a binv entry for the input document,
    // we pull it from there. Otherwise, it'll be collapsed into the first binary.
    size_t pos = ((sizeof(UInt8) * NUM_TYPE_HEADERS) +
                                (sizeof(UInt64) * NUM_SIZE_HEADERS));
    // INFO("pos = %lu \n", pos);
    UInt8 bin_idx = FIRST_BINV_ENTRY;    // first entry is reserved

    if ((pos + hsize->input_size) <= ev->binv[bin_idx]->orig_size) {
        data = (char*)(&ev->binv[bin_idx]->orig_bytes[pos]);
    } else {
        data = ev->binv[++bin_idx]->orig_bytes;
    }
    // FIXME: find a way around NULL terminated strings and we can share the binary!
    xml = ALLOC(hsize->input_size + 1);
    xml[hsize->input_size] = '\0';
    strncpy(xml, data, hsize->input_size);

    if (hsize->xsl_size < 64) {
        data = &ev->iov[++bin_idx].iov_base[0];
    } else {
        data = ev->binv[++bin_idx]->orig_bytes;
    }
    xsl = ALLOC(hsize->xsl_size + 1);
    xsl[hsize->xsl_size] = '\0';
    strncpy(xsl, data, hsize->xsl_size);

    if ((job = (XslTask*)try_driver_alloc(port,
        sizeof(XslTask), xml, xsl, hsize, hspec)) == NULL) return;
    if ((ctx = (DriverContext*)try_driver_alloc(port,
        sizeof(DriverContext), xml, xsl, hsize, hspec, job)) == NULL) return;
    if ((asd = (AsyncState*)try_driver_alloc(port,
        sizeof(AsyncState), xml, xsl, hsize, hspec, job, ctx)) == NULL) return;

    ctx->port = port;
    ctx->caller_pid = callee_pid;
    asd->driver = d;
    if ((asd->command = init_command(transform_command, ctx, job, NULL)) == NULL) {
        free_async_state(asd);
        FAIL(port, "system_limit");
        return;
    }

    fprintf(stderr, "xml[spec: %lu, len:%lu]\n", (long unsigned int)hsize->input_size, strlen(xml));
    fprintf(stderr, "xsl[spec: %lu, len:%lu]\n", (long unsigned int)hsize->xsl_size, strlen(xsl));

    state = init_task(job, hsize, hspec, xml, xsl);
    switch (state) {
    case OutOfMemoryError:
        free_async_state(asd);
        FAIL(port, "system_limit");
        return;
    case Success:
        /*
        driver_async will call engine->transform passing command, then
        call ready_async followed by cleanup_task. The synchronous code
        works something like this:

        (*a->async_invoke)(a->async_data);
        if (async_ready(prt, a->async_data)) {
            if (a->async_free != NULL)
                (*a->async_free)(a->async_data);
        }
        */
        INFO("provider handoff: transform\n");
        driver_async(port, NULL, apply_transform, asd, NULL); //cleanup_task);
        break;
    default:    // TODO: it would be better if we didn't do "everthing else is an error" here
        // TODO: error!?
        break;
    }
};
Ejemplo n.º 25
0
int main(int argc, char *argv[])
{
	int cmdfd = -1;
	bdaddr_t local_addr, remote_addr;
	struct avc_frame frame;
	int size;
	char *addrstr;

	if(argc != 2) {
		fprintf(stderr, "use: avsnd <dest>\n");
		exit(1);
	}

	addrstr = argv[1];
	fprintf(stderr, "Using address: %s\n", addrstr);
	str2ba(addrstr, &remote_addr);
	bacpy(&local_addr, BDADDR_ANY);

	cmdfd = do_connect(&local_addr, &remote_addr, L2CAP_PSM_AVCTP, NULL);

	if(cmdfd < 0) {
		fprintf(stderr, "can't connect to %s\n", addrstr);
		exit(1);
	}

	while(!terminate) {

		//printf("command? [u]p [d]own [q]uit > ");

		sleep(1); 
		printf("sending volume-up\n");				
		frame.operand0 = VOLUP_OP;

		size = sizeof(frame);
		init_command(&frame.header);
		frame.ctype = CMD_PASSTHROUGH;
		frame.opcode = OP_PASS;
		frame.operand1 = 0;
		frame.zeroes = 0;
		frame.subunit_id = 0;
		frame.subunit_type = SUBUNIT_PANEL;

		printf("sending command\n");
		dump_packet(&frame, size);
		write(cmdfd, &frame, size);

		printf("waiting for reply...\n");

		size = read(cmdfd, &frame, sizeof(frame));
		if(size > 0) {
			if(frame.ctype == CMD_ACCEPTED) {
				printf("(ack)\n");
			} else if(frame.ctype == CMD_PASSTHROUGH) {
				switch (frame.operand0) {
				case PLAY_OP:
					printf("[play]\n");
					break;
				case PAUSE_OP:
					printf("[pause]\n");
					break;
				case NEXT_OP:
					printf("[next]\n");
					break;
				case PREV_OP:
					printf("[previous]\n");
					break;
				default:
					printf("received passthrough %d bytes:\n", size);
					dump_packet(&frame, size);
				}

				init_response(&frame.header);
				frame.ctype = CMD_ACCEPTED;
				write(cmdfd, &frame, size);
			} else {
				printf("unrecognized frame\n");
				dump_packet(&frame, size);
			}
		} else {
			printf("no response\n");
			terminate = 1;
		}

	}

	close(cmdfd);

	return 0;
}