Ejemplo n.º 1
0
int send_event(int sock, int type, unsigned int value)
{
	struct JoyEvent event;

	if(sock < 0)
	{
		return 0;
	}

	/* Note, should swap endian */
	event.magic = LE32(JOY_MAGIC);
	event.type = LE32(type);
	event.value = LE32(value);

	if(fixed_write(sock, &event, sizeof(event)) != sizeof(event))
	{
		fprintf(stderr, "Could not write out data to socket\n");
		return 0;
	}

	return 1;
}
Ejemplo n.º 2
0
int execute_line(const char *buf)
{
	char args[4096];
	char *argv[16];
	int  argc;
	int len;
	int ret = 0;

	len = strlen(buf);

	if(len > 0)
	{
		char redir[PATH_MAX];
		int  type;
		int binlen = parse_cli(buf, args, &argc, argv, 16, g_context.sargc, g_context.sargv, &type, redir);
		if((binlen > 0) && (args[0] != '#'))
		{
			if(strchr(argv[0], '.') || strchr(argv[0], '/'))
			{
				int ldlen = strlen("ld")+1;
				/* If this looks to be a path then prefix ld and send */
				memmove(args+ldlen, args, binlen);
				memcpy(args, "ld", ldlen);
				binlen += ldlen;
			}
			else
			{
				const struct sh_command *cmd = find_command(argv[0]);
				if((cmd) && (cmd->func))
				{
					if(cmd->min_args > (argc-1))
					{
						help_cmd(argc, argv);
						return 0;
					}
					else
					{
						if(!cmd->func(argc-1, argv+1))
						{
							/* If it returns 0 then dont continue with the output */
							return 0;
						}
					}
				}
			}

			if(!g_context.args.script)
			{
				/* Remove the handler and prompt */
				rl_callback_handler_remove();
				rl_callback_handler_install("", cli_handler);
			}

			if(type != REDIR_TYPE_NONE)
			{
				if(type == REDIR_TYPE_NEW)
				{
					g_context.fredir = fopen(redir, "w");
				}
				else
				{
					g_context.fredir = fopen(redir, "a");
				}

				if(g_context.fredir == NULL)
				{
					fprintf(stderr, "Warning: Could not open file %s\n", redir);
				}
			}

			len = fixed_write(g_context.sock, args, binlen);
			if(len < 0)
			{
				close(g_context.sock);
				g_context.sock = -1;
				return -1;
			}
			strcpy(g_context.currcmd, args);
			ret = 1;
		}
	}

	return ret;
}