Index: src/parrot_debugger.c =================================================================== --- src/parrot_debugger.c (revision 37686) +++ src/parrot_debugger.c (working copy) @@ -117,8 +117,34 @@ static void PDB_printwelcome(void); static void PDB_run_code(PARROT_INTERP, int argc, char *argv[]); +static struct longopt_opt_decl options[] = { + { 's', 's', OPTION_optional_FLAG, { "--script" } }, + { 'h', 'h', OPTION_optional_FLAG, { "--help" } }, +}; + + /* +=item C + +Print out the user help info. + +=cut + +*/ + +static void help(Parrot_Interp interp) +{ + fprintf(stderr, "Usage: parrot_debugger programfile [program-options]\n"); + fprintf(stderr, "parrot_debugger - debugger for parrot\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, "parrot_debugger [-s | --script FILE]\n"); + fprintf(stderr, "parrot_debugger [-h | --help ]\n"); + Parrot_exit(interp, 1); +} + +/* + =item C Reads the PASM or PBC file from argv[1], loads it, and then calls @@ -131,11 +157,13 @@ int main(int argc, char *argv[]) { - int nextarg; Parrot_Interp interp; PDB_t *pdb; const char *scriptname = NULL; + int status; + struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; + Parrot_set_config_hash(); interp = Parrot_new(NULL); @@ -153,16 +181,30 @@ Parrot_block_GC_mark(interp); Parrot_block_GC_sweep(interp); - nextarg = 1; - if (argv[nextarg] && strcmp(argv[nextarg], "--script") == 0) - { - scriptname = argv [++nextarg]; - ++nextarg; + while ((status = longopt_get(interp, + argc, argv, options, &opt)) > 0) { + switch (opt.opt_id) { + case 's': + scriptname = opt.opt_arg; + break; + case 'h': + default: + help(interp); + break; + } } + if (status == -1) { + help(interp); + } + argc -= opt.opt_index; + argv += opt.opt_index; - if (argv[nextarg]) { - const char *filename = argv[nextarg]; + + if(argc > 0) { + const char *filename = *argv; const char *ext = strrchr(filename, '.'); + argc --; + argv ++; if (ext && STREQ(ext, ".pbc")) { Parrot_PackFile pf = Parrot_pbc_read(interp, filename, 0); @@ -232,7 +274,7 @@ PDB_printwelcome(); interp->run_core = PARROT_DEBUGGER_CORE; - PDB_run_code(interp, argc - nextarg, argv + nextarg); + PDB_run_code(interp, argc, argv); Parrot_exit(interp, 0); @@ -303,10 +345,10 @@ The debugger now uses it's own interpreter. User code is run in Interp* debugee. We have: - debug_interp->pdb->debugee->debugger - ^ | - | v - +------------- := -----------+ + interp->pdb->debugee->debugger + ^ | + | v + +--------- := ---------+ Debug commands are mostly run inside the C. User code runs of course in the C. Index: CREDITS =================================================================== --- CREDITS (revision 37686) +++ CREDITS (working copy) @@ -795,6 +795,7 @@ N: Saleem Ansari E: tuxdna@gmail.com D: Fixed typos in documentation +D: use longopts in parrot debugger N: Sam Ruby E: rubys@intertwingly.net