cvsuser 03/06/05 02:35:41
Modified: . packfile.c pdump.c
Log:
pdump: use long option; fix a SIGSEGV
Revision Changes Path
1.88 +7 -7 parrot/packfile.c
Index: packfile.c
===================================================================
RCS file: /cvs/public/parrot/packfile.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -w -r1.87 -r1.88
--- packfile.c 1 Jun 2003 00:17:44 -0000 1.87
+++ packfile.c 5 Jun 2003 09:35:41 -0000 1.88
@@ -7,7 +7,7 @@
** This program is free software. It is subject to the same
** license as Parrot itself.
**
-** $Id: packfile.c,v 1.87 2003/06/01 00:17:44 josh Exp $
+** $Id: packfile.c,v 1.88 2003/06/05 09:35:41 leo Exp $
**
** History:
** Rework by Melvin; new bytecode format, make bytecode portable.
@@ -868,17 +868,17 @@
size_t i;
default_dump_header(interpreter, self);
- i = self->file_offset + 4;
+ i = self->data ? 0: self->file_offset + 4;
if (i % 8)
PIO_printf(interpreter, "\n %04x: ", (int) i);
- for ( ; i < (self->size ? self->file_offset+self->size + 4 :
+ for ( ; i < (self->data ? self->size :
self->file_offset + self->op_count); i++) {
if (i % 8 == 0) {
PIO_printf(interpreter, "\n %04x: ", (int) i);
}
PIO_printf(interpreter, "%08lx ", (unsigned long)
- self->data[i]);
+ self->data ? self->data[i] : self->pf->src[i]);
}
PIO_printf(interpreter, "\n]\n");
}
1.22 +39 -49 parrot/pdump.c
Index: pdump.c
===================================================================
RCS file: /cvs/public/parrot/pdump.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -r1.21 -r1.22
--- pdump.c 1 Feb 2003 19:05:51 -0000 1.21
+++ pdump.c 5 Jun 2003 09:35:41 -0000 1.22
@@ -1,7 +1,7 @@
/* pdump.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: pdump.c,v 1.21 2003/02/01 19:05:51 leo Exp $
+ * $Id: pdump.c,v 1.22 2003/06/05 09:35:41 leo Exp $
* Overview:
* A program to dump pack files to human readable form.
* Data Structure and Algorithms:
@@ -72,7 +72,7 @@
{
printf("pdump - dump or convert parrot bytecode (PBC) files\n");
printf("usage:\n");
- printf("pdump [-t] [-d] [-h] file.pbc\n");
+ printf("pdump [-tdh] [--terse|--disassemble|--header-only] file.pbc\n");
printf("pdump -o converted.pbc file.pbc\n\n");
printf("\t-d ... disassemble bytecode segments\n");
printf("\t-h ... dump header only\n");
@@ -83,6 +83,14 @@
exit(0);
}
+static struct longopt_opt_decl options[] = {
+ { 'h', 'h', 0, { "--header-only" } },
+ { '?', '?', 0, { "--help" } },
+ { 't', 't', 0, { "--terse" } },
+ { 'd', 'd', 0, { "--disassemble" } },
+ { 'o', 'o', OPTION_required_FLAG, { "--output" } }
+};
+
int
main(int argc, char **argv)
{
@@ -92,60 +100,42 @@
int disas = 0;
int convert = 0;
int header = 0;
- char *file;
+ const char *file;
+ struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
+ int status;
if (argc < 2) {
help();
}
- argc--;
- argv++;
- while (argc > 1) {
- if (strcmp(*argv, "-t") == 0) {
- argc--;
- argv++;
+ interpreter = make_interpreter(NO_FLAGS);
+ Parrot_init(interpreter, (void *)&terse);
+ while ((status = longopt_get(interpreter,
+ argc, argv, options, &opt)) > 0) {
+ switch (opt.opt_id) {
+ case 'h':
+ header = 1;
+ break;
+ case 't':
terse = 1;
- }
- else if (strcmp(*argv, "-d") == 0) {
- argc--;
- argv++;
+ break;
+ case 'd':
disas = 1;
- }
- else if (memcmp(*argv, "-o", 2) == 0) {
- if ((*argv)[2])
- file = *argv+2;
- else {
- argc--;
- argv++;
- if (argc > 1)
- file = *argv;
- else {
- fprintf(stderr, "Missing file param\n");
- exit(1);
- }
- }
- argc--;
- argv++;
+ break;
+ case 'o':
+ file = opt.opt_arg;
convert = 1;
- }
- else if (strcmp(*argv, "-h") == 0) {
- argc--;
- argv++;
- header = 1;
- }
- else if (strcmp(*argv, "-?") == 0) {
+ break;
+ case '?':
help();
+ break;
}
- else if (**argv == '-') {
- printf("Unknown option '%s' ignored\n", *argv);
- argc--;
- argv++;
}
- else
- break;
+ if (status == -1) {
+ help();
}
+ argc -= opt.opt_index;
+ argv += opt.opt_index;
- interpreter = make_interpreter(NO_FLAGS);
- Parrot_init(interpreter, (void *)&terse);
pf = Parrot_readbc(interpreter, *argv);