Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate code in tool-interface #1539

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sources/app/tool-invoke/tool-invoke.dylan
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Module: tool-invoke
Synopsis: A standalone program to invoke Functional Developer tools on
Synopsis: A standalone program to invoke Functional Developer tools on
specification files.
Author: 7/98 Seth LaForge
Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc.
Expand All @@ -15,7 +15,7 @@ define method main () => ()
exit-application(2);
end if;
end method;
local method yn-handler (c :: <tool-yes-no-question>, next :: <function>)
local method yn-handler (c :: <tool-yes-no-question>, next :: <function>)
=> (answer :: <boolean>)
format-out("%s (y/n) ", c);
force-output(*standard-output*);
Expand All @@ -30,7 +30,7 @@ define method main () => ()

let args = application-arguments();
if (size(args) < 1 | size(args) > 2)
format-out("Usage: %s <specification-file-name> [<project-file-name>]\n",
format-out("Usage: %s <specification-file-name> [<project-file-name>]\n",
application-name());
exit-application(1);
end if;
Expand All @@ -39,7 +39,7 @@ define method main () => ()
if (project-file)
project-file := as(<file-locator>, project-file);
end if;

let tool-name = tool-name-from-specification(spec-file);
let tool = tool-find(tool-name);
if (tool)
Expand Down
1 change: 1 addition & 0 deletions sources/corba/scepter/tool/tool-scepter-library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define library tool-scepter
use dylan;
use common-dylan;
use collections;
use file-source-records;
use system;
use io;
use tools-interface;
Expand Down
1 change: 1 addition & 0 deletions sources/corba/scepter/tool/tool-scepter-module.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Warranty: Distributed WITHOUT WARRANTY OF ANY KIND

define module tool-scepter
use common-dylan;
use file-source-records;
use format;
use streams;
use table-extensions;
Expand Down
2 changes: 1 addition & 1 deletion sources/corba/scepter/tool/tool-scepter.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ end method;

define inline-only function read-spec-file (file :: <file-locator>)
=> (specification)
read-keyword-pair-file(file);
read-file-header(file);
end function;

define function date-as-string (date :: false-or(<date>)) => (r :: <string>)
Expand Down
2 changes: 1 addition & 1 deletion sources/lib/motley/tool-iface.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ define function motley-invoke
debug-message("Motley invoked. Spec: %=, project: %=, last: %=, clean: %=\n",
spec-file, project-file, last-run & date-as-string(last-run),
clean-build?);
let spec-keys = read-keyword-pair-file(spec-file);
let spec-keys = read-file-header(spec-file);
motley-process-spec(spec-keys, spec-file, project-file, last-run,
clean-build?: clean-build?);
end function motley-invoke;
Expand Down
1 change: 1 addition & 0 deletions sources/lib/parser-generator/tool/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
define library tool-parser-generator
use dylan;
use common-dylan;
use file-source-records;
use io;
use system;
use tools-interface;
Expand Down
1 change: 1 addition & 0 deletions sources/lib/parser-generator/tool/module.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define module tool-parser-generator
use common-dylan;
use simple-debugging, import: { debug-out };
use date;
use file-source-records;
use file-system;
use format;
use streams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define method parser-generator-invoke

let keyval = keyword-file-element-value;
let keyline = keyword-file-element-line;
let spec = read-keyword-pair-file(spec-file);
let spec = read-file-header(spec-file);
local method key (sym :: <symbol>) element(spec, sym, default: #()) end;
local method single (sym :: <symbol>, #key default = $unsupplied)
if (sym.key.size = 1)
Expand Down
26 changes: 14 additions & 12 deletions sources/lib/source-records/header-reader.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define class <bad-header> (<simple-error>)
end;

define method read-file-header (file :: <locator>)
=> (keys :: <table>, lines :: <integer>, chars :: <integer>)
=> (keys :: <table>, nlines :: <integer>, nchars :: <integer>)
block ()
with-open-file (stream = file)
read-header-from-stream(stream)
Expand All @@ -27,6 +27,12 @@ end method;

define constant $unique-header-keywords = #(#"module", #"language");

// Read 'key: val' pairs up through the empty line that separates the header
// from the main source code. Returns
// * a table mapping key (interned as a symbol) to values which are either a
// single string or, if there were continuation lines, a sequence of strings.
// * the number of lines read
// * the number of characters read
define method read-header-from-stream (stream :: <stream>)
=> (keys :: <table>, lines :: <integer>, chars :: <integer>)
let keys = make(<table>);
Expand All @@ -49,6 +55,7 @@ define method read-header-from-stream (stream :: <stream>)
end
end method;

// Read one 'key: val' pair, with val possibly having continuation lines.
define method read-file-header-component (stream :: <stream>)
=> (key, strings, nlines, end-of-header?)
let (key-line, nl?) = read-line(stream, on-end-of-stream: "");
Expand All @@ -65,8 +72,9 @@ define method read-file-header-component (stream :: <stream>)
if (header-end-marker-line?(continuation-line))
values(key, reverse!(text-strings), nlines, #t)
else
let text = parse-header-continuation-line(continuation-line);
loop(pair(text, text-strings), nlines)
loop(pair(strip(continuation-line, test: header-whitespace?),
text-strings),
nlines)
end
else
char & unread-element(stream, char);
Expand All @@ -77,11 +85,9 @@ define method read-file-header-component (stream :: <stream>)
end method;

define method parse-header-keyword-line (line :: <string>)
let colon = position(line, ':');
if (~colon)
signal(make(<bad-header>,
message: format-to-string("Syntax error on line: %=", line)))
end;
let colon = position(line, ':')
| signal(make(<bad-header>,
message: format-to-string("Syntax error on line: %=", line)));
values(as(<symbol>, copy-sequence(line, end: colon)),
strip(line, start: colon + 1, test: header-whitespace?))
end method;
Expand All @@ -91,10 +97,6 @@ define inline function header-whitespace? (c :: <character>) => (white? :: <bool
c == ' ' | c == '\t'
end;

define method parse-header-continuation-line (line :: <string>)
strip(line, test: header-whitespace?)
end method;

define function header-end-marker-line? (line :: <string>)
every?(header-whitespace?, line)
end function;
5 changes: 3 additions & 2 deletions sources/project-manager/tools-interface/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
define library tools-interface
use dylan;
use common-dylan;
use system;
use file-source-records;
use io;
use system;

export tools-interface;
end library tools-interface;
Expand All @@ -21,6 +22,7 @@ define module tools-interface
use dylan;
use common-extensions;
use machine-words;
use file-source-records;
use format;
use format-out;
use locators;
Expand Down Expand Up @@ -59,7 +61,6 @@ define module tools-interface
project-information-base-address-setter,
project-information-remaining-keys-setter;

export read-keyword-pair-file, read-keyword-pair-stream;
export write-keyword-pair-file, write-keyword-pair-stream;
export <keyword-file-element>,
keyword-file-element-value, keyword-file-element-value-setter,
Expand Down
Loading