Skip to content

Commit

Permalink
Support globbing for vm
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jul 5, 2024
1 parent aad539a commit eb030d2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/cmdlets/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Output } from '../io/output.js';
import { Format } from '../misc/format.js';
import { Token } from '../io/token.js';
import { Var } from '../vars/var.js';
import { Regex } from '../misc/regex.js';

const USAGE: string = `Usage: vm
Expand All @@ -24,6 +25,9 @@ export class VmCmdLet extends CmdLet {
const retWithAddress = this.runWithAddress(tokens);
if (retWithAddress !== null) return retWithAddress;

const retWithWildCard = this.runWithWildcard(tokens);
if (retWithWildCard !== null) return retWithWildCard;

const retWithName = this.runWithName(tokens);
if (retWithName !== null) return retWithName;

Expand Down Expand Up @@ -96,6 +100,31 @@ export class VmCmdLet extends CmdLet {
Output.writeln();
}

private runWithWildcard(tokens: Token[]): Var | null {
if (tokens.length !== 1) return null;

const t0 = tokens[0] as Token;
const name = t0.getLiteral();
if (!Regex.isGlob(name)) return null;

const regex = Regex.globToRegex(name);
if (regex === null) return this.usage();

const modules = Process.enumerateModules().filter(m => m.name.match(regex));
modules.sort();
modules.forEach(m => {
m.enumerateRanges('---').forEach(r => {
this.printMapping(r);
});
});
if (modules.length === 1) {
const module = modules[0] as Module;
return new Var(module.base.toString());
} else {
return Var.ZERO;
}
}

private runWithName(tokens: Token[]): Var | null {
if (tokens.length !== 1) return null;

Expand Down

0 comments on commit eb030d2

Please sign in to comment.