X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Ffish.c;h=3ab09b5ce63579f34fef8f7e270fce84d9aa099f;hb=d710f768161fc9f78ed8243f2de948b65425c06e;hp=9215f4e8a34288f13ffce7cf1ae70beab9ab0120;hpb=acbcbfaf39592b0b9c1864740ff0b3baad053b2e;p=libguestfs.git diff --git a/fish/fish.c b/fish/fish.c index 9215f4e..3ab09b5 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,7 @@ #include #include "fish.h" +#include "c-ctype.h" #include "closeout.h" #include "progname.h" @@ -81,8 +81,6 @@ launch (guestfs_h *_g) if (guestfs_is_config (g)) { if (guestfs_launch (g) == -1) return -1; - if (guestfs_wait_ready (g) == -1) - return -1; } return 0; } @@ -581,7 +579,7 @@ script (int prompt) /* Skip any initial whitespace before the command. */ again: - while (*buf && isspace (*buf)) + while (*buf && c_isspace (*buf)) buf++; if (!*buf) continue; @@ -876,6 +874,8 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) r = do_more (cmd, argc, argv); else if (strcasecmp (cmd, "reopen") == 0) r = do_reopen (cmd, argc, argv); + else if (strcasecmp (cmd, "sparse") == 0) + r = do_sparse (cmd, argc, argv); else if (strcasecmp (cmd, "time") == 0) r = do_time (cmd, argc, argv); else @@ -929,6 +929,8 @@ list_builtin_commands (void) printf ("%-20s %s\n", "reopen", _("close and reopen libguestfs handle")); printf ("%-20s %s\n", + "sparse", _("allocate a sparse image file")); + printf ("%-20s %s\n", "time", _("measure time taken to run command")); /* actions are printed after this (see list_commands) */ @@ -955,6 +957,9 @@ display_builtin_command (const char *cmd) " K or KB number of kilobytes\n" " M or MB number of megabytes\n" " G or GB number of gigabytes\n" + " T or TB number of terabytes\n" + " P or PB number of petabytes\n" + " E or EB number of exabytes\n" " sects number of 512 byte sectors\n")); else if (strcasecmp (cmd, "echo") == 0) printf (_("echo - display a line of text\n" @@ -1022,6 +1027,33 @@ display_builtin_command (const char *cmd) "Close and reopen the libguestfs handle. It is not necessary to use\n" "this normally, because the handle is closed properly when guestfish\n" "exits. However this is occasionally useful for testing.\n")); + else if (strcasecmp (cmd, "sparse") == 0) + printf (_("sparse - allocate a sparse image file\n" + " sparse \n" + "\n" + " This creates an empty sparse file of the given size,\n" + " and then adds so it can be further examined.\n" + "\n" + " In all respects it works the same as the 'alloc'\n" + " command, except that the image file is allocated\n" + " sparsely, which means that disk blocks are not assigned\n" + " to the file until they are needed. Sparse disk files\n" + " only use space when written to, but they are slower\n" + " and there is a danger you could run out of real disk\n" + " space during a write operation.\n" + "\n" + " For more advanced image creation, see qemu-img utility.\n" + "\n" + " Size can be specified (where means a number):\n" + " number of kilobytes\n" + " eg: 1440 standard 3.5\" floppy\n" + " K or KB number of kilobytes\n" + " M or MB number of megabytes\n" + " G or GB number of gigabytes\n" + " T or TB number of terabytes\n" + " P or PB number of petabytes\n" + " E or EB number of exabytes\n" + " sects number of 512 byte sectors\n")); else if (strcasecmp (cmd, "time") == 0) printf (_("time - measure time taken to run command\n" " time [ ...]\n" @@ -1129,7 +1161,7 @@ parse_string_list (const char *str) * as separate fragments because we can't just copy it: we have to remove * the \. */ - while (*p && (!isblank (*p) || in_quote)) { + while (*p && (!c_isblank (*p) || in_quote)) { const char *end = p; /* Check if the fragment starts with a quote */ @@ -1297,3 +1329,51 @@ xwrite (int fd, const void *v_buf, size_t len) return 0; } + +/* Resolve the special "win:..." form for Windows-specific paths. + * This always returns a newly allocated string which is freed by the + * caller function in "cmds.c". + */ +char * +resolve_win_path (const char *path) +{ + char *ret; + size_t i; + + if (strncasecmp (path, "win:", 4) != 0) { + ret = strdup (path); + if (ret == NULL) + perror ("strdup"); + return ret; + } + + path += 4; + + /* Drop drive letter, if it's "C:". */ + if (strncasecmp (path, "c:", 2) == 0) + path += 2; + + if (!*path) { + ret = strdup ("/"); + if (ret == NULL) + perror ("strdup"); + return ret; + } + + ret = strdup (path); + if (ret == NULL) { + perror ("strdup"); + return NULL; + } + + /* Blindly convert any backslashes into forward slashes. Is this good? */ + for (i = 0; i < strlen (ret); ++i) + if (ret[i] == '\\') + ret[i] = '/'; + + char *t = guestfs_case_sensitive_path (g, ret); + free (ret); + ret = t; + + return ret; +}