1 /* $NetBSD: test.c,v 1.1.1.1 2009/02/18 11:17:38 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of LVM2. 8 * 9 * This copyrighted material is made available to anyone wishing to use, 10 * modify, copy, or redistribute it subject to the terms and conditions 11 * of the GNU Lesser General Public License v.2.1. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software Foundation, 15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 #include <stdio.h> 18 #include <string.h> 19 #include <stdlib.h> 20 #include <readline/readline.h> 21 #include "lvm2.h" 22 23 #define MAX_ARGS 64 24 25 static int lvm_split(char *str, int *argc, char **argv, int max) 26 { 27 char *b = str, *e; 28 *argc = 0; 29 30 while (*b) { 31 while (*b && isspace(*b)) 32 b++; 33 34 if ((!*b) || (*b == '#')) 35 break; 36 37 e = b; 38 while (*e && !isspace(*e)) 39 e++; 40 41 argv[(*argc)++] = b; 42 if (!*e) 43 break; 44 *e++ = '\0'; 45 b = e; 46 if (*argc == max) 47 break; 48 } 49 50 return *argc; 51 } 52 53 static int lvmapi_test_shell(void *h) 54 { 55 int argc, i; 56 char *input = NULL, *args[MAX_ARGS], **argv; 57 58 while (1) { 59 free(input); 60 input = readline("lvm> "); 61 62 /* EOF */ 63 if (!input) { 64 printf("\n"); 65 break; 66 } 67 68 /* empty line */ 69 if (!*input) 70 continue; 71 72 argv = args; 73 74 if (lvm_split(input, &argc, argv, MAX_ARGS) == MAX_ARGS) { 75 printf("Too many arguments, sorry."); 76 continue; 77 } 78 79 if (!strcmp(argv[0], "lvm")) { 80 argv++; 81 argc--; 82 } 83 84 if (!argc) 85 continue; 86 87 if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit")) { 88 printf("Exiting.\n"); 89 break; 90 } else if (!strcmp(argv[0], "?") || !strcmp(argv[0], "help")) { 91 printf("No commands defined\n"); 92 } else if (!strcmp(argv[0], "scan")) { 93 for (i=1; i < argc; i++) 94 printf("Scan a path!\n"); 95 } 96 } 97 98 free(input); 99 return 0; 100 } 101 102 int main (int argc, char *argv[]) 103 { 104 void *h; 105 106 h = lvm2_create(); 107 if (!h) { 108 printf("Unable to open lvm library instance\n"); 109 return 1; 110 } 111 112 lvmapi_test_shell(h); 113 114 if (h) 115 lvm2_destroy(h); 116 return 0; 117 } 118 119