Re-name some of the VSH_DOMBYFOO stuff to VSH_BYFOO in order to re-use it for the network stuff. Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx> Index: libvirt-foo/src/virsh.c =================================================================== --- libvirt-foo.orig/src/virsh.c 2007-02-14 14:29:40.000000000 +0000 +++ libvirt-foo.orig/src/virsh.c 2007-02-14 14:29:40.000000000 +0000 @@ -10,7 +10,7 @@ * Daniel P. Berrange <berrange@xxxxxxxxxx> * * - * $Id: virsh.c,v 1.49 2007/02/14 01:40:09 berrange Exp $ + * $Id: virsh.c,v 1.50 2007/02/14 16:04:55 markmc Exp $ */ #define _GNU_SOURCE /* isblank() */ @@ -194,9 +194,9 @@ static char *vshCommandOptString(vshCmd int *found); static int vshCommandOptBool(vshCmd * cmd, const char *name); -#define VSH_DOMBYID (1 << 1) -#define VSH_DOMBYUUID (1 << 2) -#define VSH_DOMBYNAME (1 << 3) +#define VSH_BYID (1 << 1) +#define VSH_BYUUID (1 << 2) +#define VSH_BYNAME (1 << 3) static virDomainPtr vshCommandOptDomainBy(vshControl * ctl, vshCmd * cmd, const char *optname, char **name, int flag); @@ -204,7 +204,7 @@ static virDomainPtr vshCommandOptDomainB /* default is lookup by Id, Name and UUID */ #define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \ vshCommandOptDomainBy(_ctl, _cmd, _optname, _name, \ - VSH_DOMBYID|VSH_DOMBYUUID|VSH_DOMBYNAME) + VSH_BYID|VSH_BYUUID|VSH_BYNAME) static void vshPrintExtra(vshControl * ctl, const char *format, ...); static void vshDebug(vshControl * ctl, int level, const char *format, ...); @@ -226,6 +226,25 @@ static void *_vshCalloc(vshControl * ctl static char *_vshStrdup(vshControl * ctl, const char *s, const char *filename, int line); #define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__) + +static int idsorter(const void *a, const void *b) { + const int *ia = (const int *)a; + const int *ib = (const int *)b; + + if (*ia > *ib) + return 1; + else if (*ia < *ib) + return -1; + return 0; +} +static int namesorter(const void *a, const void *b) { + const char **sa = (const char**)a; + const char **sb = (const char**)b; + + return strcasecmp(*sa, *sb); +} + + /* --------------- * Commands * --------------- @@ -392,22 +411,6 @@ static vshCmdOptDef opts_list[] = { }; -static int domidsorter(const void *a, const void *b) { - const int *ia = (const int *)a; - const int *ib = (const int *)b; - - if (*ia > *ib) - return 1; - else if (*ia < *ib) - return -1; - return 0; -} -static int domnamesorter(const void *a, const void *b) { - const char **sa = (const char**)a; - const char **sb = (const char**)b; - - return strcasecmp(*sa, *sb); -} static int cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED) { @@ -437,7 +440,7 @@ cmdList(vshControl * ctl, vshCmd * cmd A return FALSE; } - qsort(&ids[0], maxid, sizeof(int), domidsorter); + qsort(&ids[0], maxid, sizeof(int), idsorter); } } if (inactive) { @@ -459,7 +462,7 @@ cmdList(vshControl * ctl, vshCmd * cmd A return FALSE; } - qsort(&names[0], maxname, sizeof(char*), domnamesorter); + qsort(&names[0], maxname, sizeof(char*), namesorter); } } vshPrintExtra(ctl, "%3s %-20s %s\n", _("Id"), _("Name"), _("State")); @@ -1544,7 +1547,7 @@ cmdDomname(vshControl * ctl, vshCmd * cm if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) return FALSE; if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, - VSH_DOMBYID|VSH_DOMBYUUID))) + VSH_BYID|VSH_BYUUID))) return FALSE; vshPrint(ctl, "%s\n", virDomainGetName(dom)); @@ -1575,7 +1578,7 @@ cmdDomid(vshControl * ctl, vshCmd * cmd) if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) return FALSE; if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, - VSH_DOMBYNAME|VSH_DOMBYUUID))) + VSH_BYNAME|VSH_BYUUID))) return FALSE; id = virDomainGetID(dom); @@ -1610,7 +1613,7 @@ cmdDomuuid(vshControl * ctl, vshCmd * cm if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) return FALSE; if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, - VSH_DOMBYNAME|VSH_DOMBYID))) + VSH_BYNAME|VSH_BYID))) return FALSE; if (virDomainGetUUIDString(dom, uuid) != -1) @@ -2088,7 +2091,7 @@ vshCommandOptDomainBy(vshControl * ctl, *name = n; /* try it by ID */ - if (flag & VSH_DOMBYID) { + if (flag & VSH_BYID) { id = (int) strtol(n, &end, 10); if (id >= 0 && end && *end == '\0') { vshDebug(ctl, 5, "%s: <%s> seems like domain ID\n", @@ -2097,13 +2100,13 @@ vshCommandOptDomainBy(vshControl * ctl, } } /* try it by UUID */ - if (dom==NULL && (flag & VSH_DOMBYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { + if (dom==NULL && (flag & VSH_BYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n", cmd->def->name, optname); dom = virDomainLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (dom==NULL && (flag & VSH_DOMBYNAME)) { + if (dom==NULL && (flag & VSH_BYNAME)) { vshDebug(ctl, 5, "%s: <%s> tring as domain NAME\n", cmd->def->name, optname); dom = virDomainLookupByName(ctl->conn, n); --