cmdtree

A trie command launcher for X11
git clone git://jb55.com/cmdtree
Log | Files | Refs | README | LICENSE

command.c (825B)


      1 
      2 #include "command.h"
      3 
      4 #include <err.h>
      5 #include <string.h>
      6 #include <unistd.h>
      7 #include <stdio.h>
      8 
      9 #include "util.h"
     10 
     11 int
     12 command_is_prefix(struct command *cmd) {
     13 	return cmd->nchildren > 0;
     14 }
     15 
     16 void
     17 command_exec(struct command *cmd) {
     18 	const char *cmdname = cmd->command == NULL ? cmd->name : cmd->command;
     19 	execlp("/bin/sh", "sh", "-c", cmdname, (char *) 0);
     20 	err(1, "executing command %s", cmd->name);
     21 }
     22 
     23 int
     24 command_num_children(struct command *cmd) {
     25 	return cmd->nchildren;
     26 }
     27 
     28 struct command *
     29 command_lookup(struct command *cmd, int ncmds, const char *binding) {
     30 	for (int i = 0; i < ncmds; ++i) {
     31 		if (strcmp(binding, cmd[i].bind) == 0)
     32 			return &cmd[i];
     33 	}
     34 
     35 	return NULL;
     36 }
     37 
     38 /* static struct command emacs_commands[] = { */
     39 /*   { .bind = "d", .name = "emacs-dev", .nchildren = 0, .children = NULL }, */
     40 /* }; */
     41