Esempio n. 1
0
int main(void)
{
	entry* entry_head = calloc(sizeof(entry), 1);
	snapshot* snapshot_head = calloc(sizeof(snapshot), 1);

	int latest_snapshotID = 1;

	char buffer[MAX_LINE_LENGTH];

	printf("> ");

	while(fgets(buffer, sizeof(buffer), stdin))
	{
		struct command_struct *command = get_command_struct(buffer);
		if(!command) continue;


		if(strcmp(command->args_malloc_ptr[0], "bye") == 0)
		{
			bye_command(snapshot_head, entry_head);
			free_command(command);
			printf("bye");
			return 0;
		}
		else if(strcmp(command->args_malloc_ptr[0], "help") == 0)
		{
			print_help_string();
		}
		else if(strcmp(command->args_malloc_ptr[0], "list") == 0)
		{
			list_command(command, entry_head, snapshot_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "get") == 0)
		{
			get_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "del") == 0)
		{
			del_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "purge") == 0)
		{
			purge_command(command, entry_head, snapshot_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "set") == 0)
		{
			set_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "push") == 0)
		{
			push_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "append") == 0)
		{
			append_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "pick") == 0)
		{
			pick_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "pluck") == 0)
		{
			pluck_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "pop") == 0)
		{
			pop_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "drop") == 0)
		{
			drop_command(command, snapshot_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "rollback") == 0)
		{
			rollback_command(command, snapshot_head, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "checkout") == 0)
		{
			checkout_command(command, snapshot_head, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "snapshot") == 0)
		{
			snapshot_command(snapshot_head, entry_head, &latest_snapshotID);
		}
		else if(strcmp(command->args_malloc_ptr[0], "min") == 0)
		{
			min_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "max") == 0)
		{
			max_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "sum") == 0)
		{
			sum_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "len") == 0)
		{
			len_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "rev") == 0)
		{
			rev_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "uniq") == 0)
		{
			uniq_command(command, entry_head);
		}
		else if(strcmp(command->args_malloc_ptr[0], "sort") == 0)
		{
			sort_command(command, entry_head);
		}
		printf("\n> ");
		free_command(command);
	}
		bye_command(snapshot_head, entry_head);
	return 0;
}
Esempio n. 2
0
static void execute_user_command(client_t *c, int narg, char **args)
{
    const char *cmd;

    cmd = args[0];
    narg--;
    args++;

    switch (narg) {
    case 0:
        if      (!strcmp(cmd, "register"))   register_client(c);
        else if (!strcmp(cmd, "unregister")) unregister_client(c);
        else if (!strcmp(cmd, "exit"))       quit_mainloop(c, 0);
        else if (!strcmp(cmd, "quit"))       quit_mainloop(c, 0);
        else if (!strcmp(cmd, "help")) {
            print(c, "Available commands:");
            print(c, "  register                     - register to server");
            print(c, "  unregister                   - unregister from server");
            print(c, "  focus none|shared|exclusive  - request voice focus");
            print(c, "  add command <command>        - add new command");
            print(c, "  del command <command>        - delete a command");
            print(c, "  render tts '<msg>' \\        - request TTS of <msg>");
            print(c, "    [-voice:<voice>] \\");
            print(c, "    [-timeout:<timeout>]\\");
            print(c, "    [-events]");
            print(c, "  cancel tts '<id>'            - cancel given TTS "
                  "request");
            print(c, "  list commands                - list commands set");
            print(c, "  list voices                  - list available voices");
            print(c, "  help                         - show this help");
            print(c, "  exit                         - exit from client");
        }
        else
            print(c, "Unknown command '%s'.", cmd);
        break;

    case 1:
        if (!strcmp(cmd, "focus")) {
            if (strcmp(args[0], "none") &&
                strcmp(args[0], "shared") &&
                strcmp(args[0], "exclusive")) {
                print(c, "Invalid focus '%s', valid foci are: "
                      "none, shared, and exclusive.", args[0]);
            }
            else
                request_focus(c, args[0]);
        }
        else if (!strcmp(cmd, "reset") && !strcmp(args[0], "commands"))
            reset_commands(c);
        else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "commands"))
            list_commands(c);
        else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices"))
            query_voices(c, NULL);
        else if (!strcmp(cmd, "cancel" ) && !strcmp(args[0], "tts"))
            cancel_tts(c, 0, NULL);
        else
            print(c, "Invalid command.");
        break;

    case 2:
        if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices"))
            query_voices(c, args[1]);
        else if (!strcmp(cmd, "cancel"))
            cancel_tts(c, narg-1, args+1);
        else
            print(c, "Invalid command.");
        break;

    default:
        if (!strcmp(args[0], "command")) {
            if (!strcmp(cmd, "add" ))
                add_command(c, narg-1, args+1);
            else if (!strcmp(cmd, "del" ) || !strcmp(cmd, "delete"))
                del_command(c, narg-1, args+1);
            else
                print(c, "Invalid command.");
        }
        else if (!strcmp(args[0], "tts")) {
            if (!strcmp(cmd, "render"))
                request_tts(c, narg-1, args+1);
            else
                print(c, "Invalid TTS command.");
        }
        else
            print(c, "Invalid command.");
        break;
    }
}