2 * Copyright (c) 2007 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
39 void ddb_readfile(char *file);
40 void ddb_main(int argc, char *argv[]);
46 fprintf(stderr, "usage: ddb capture [-M core] [-N system] print\n");
47 fprintf(stderr, " ddb capture [-M core] [-N system] status\n");
48 fprintf(stderr, " ddb script scriptname\n");
49 fprintf(stderr, " ddb script scriptname=script\n");
50 fprintf(stderr, " ddb scripts\n");
51 fprintf(stderr, " ddb unscript scriptname\n");
52 fprintf(stderr, " ddb pathname\n");
57 ddb_readfile(char *filename)
62 if ((f = fopen(filename, "r")) == NULL)
63 err(EX_UNAVAILABLE, "fopen: %s", filename);
67 while (fgets(buf, BUFSIZ, f)) {
73 if (buf[spn-1] == '\n')
76 spn = strspn(buf, WHITESP);
78 if (*argv[0] == '#' || *argv[0] == '\0')
82 spn = strcspn(argv[0], WHITESP);
83 argv[1] = argv[0] + spn + strspn(argv[0] + spn, WHITESP);
91 printf("argc = %d\n", argc);
92 for (i = 0; i < argc; i++) {
93 printf("arg[%d] = %s\n", i, argv[i]);
103 ddb_main(int argc, char *argv[])
109 if (strcmp(argv[0], "capture") == 0)
110 ddb_capture(argc, argv);
111 else if (strcmp(argv[0], "script") == 0)
112 ddb_script(argc, argv);
113 else if (strcmp(argv[0], "scripts") == 0)
114 ddb_scripts(argc, argv);
115 else if (strcmp(argv[0], "unscript") == 0)
116 ddb_unscript(argc, argv);
122 main(int argc, char *argv[])
126 * If we've only got one argument and it's an absolute path to a file,
127 * interpret as a file to be read in.
129 if (argc == 2 && argv[1][0] == '/' && access(argv[1], R_OK) == 0)
130 ddb_readfile(argv[1]);
132 ddb_main(argc-1, argv+1);