Keywordize EXT:MAKE-TEMP-FILE for temp file name patterns

EXT:MAKE-TEMP-FILE &key (PREFIX "abcl") (SUFFIX ".tmp")
parent 46c93e2c
......@@ -20,6 +20,10 @@ FIXME: currently borks CFFI-TESTS
* Implemented "time of time" semantics {encode,decode}-universal time.
FIXME: breaking a number of ANSI tests. Need to conditionalize runtime behavior.
* EXTENSIONS:MAKE-TEMP-FILE now takes keyword arguments to specify
values of the prefix and suffix strings to the underlying JVM
implementation of java.io.File.createTempFile().
Fixes
-----
......
......@@ -264,31 +264,77 @@ public final class Extensions
}
public static final Primitive MAKE_TEMP_FILE = new make_temp_file();
@DocString(name="make_temp_file",
doc="Create and return the pathname of a previously non-existent file.")
@DocString(name="make-temp-file",
doc="Create and return the pathname of a previously non-existent file.",
args="&key prefix suffix")
private static class make_temp_file extends Primitive {
make_temp_file() {
super("make-temp-file", PACKAGE_EXT, true, "");
super("make-temp-file", PACKAGE_EXT, true, "&key prefix suffix");
}
@Override
public LispObject execute()
public LispObject execute(LispObject ... args)
{
try
{
File file = File.createTempFile("abcl", "", null);
if (file != null)
return new Pathname(file.getPath());
}
catch (IOException e)
{
Debug.trace(e);
String prefix = "abcl";
String suffix = null;
if ( args.length % 2 != 0) {
error(new WrongNumberOfArgumentsException("Expecting an even number of arguments including keywords."));
}
for (int i = 0; i < args.length; i++ ) {
if (args[i].SYMBOLP() != NIL) {
if (args[i].equals(Keyword.PREFIX)) {
String specifiedPrefix = args[i + 1].getStringValue();
if (specifiedPrefix != null) {
if (specifiedPrefix.equals(NIL.getStringValue())) {
error (new TypeError("Cannot create temporary file with NIL prefix."));
}
prefix = specifiedPrefix;
i += 1;
}
} else if (args[i].equals(Keyword.SUFFIX)) {
String specifiedSuffix = args[i + 1].getStringValue();
if (specifiedSuffix != null) {
if (specifiedSuffix.equals(NIL.getStringValue())) {
suffix =null;
} else {
suffix = specifiedSuffix;
}
i += 1;
}
}
} else {
error(new TypeError("Expected matching keyword argument.", args[i], Keyword.PREFIX.classOf()));
}
}
return createTempFile(prefix, suffix);
}
@Override
public LispObject execute() {
return createTempFile("abcl", null);
}
private LispObject createTempFile(String prefix, String suffix) {
try {
File file = File.createTempFile(prefix, suffix, null);
if (file != null)
return new Pathname(file.getPath());
} catch (IllegalArgumentException e) {
// "Failed to create temporary file due to argument problems."
error(new JavaException(e));
} catch (SecurityException e) {
//"Failed to create problem due to problems with JVM SecurityManager."
error(new JavaException(e));
} catch (IOException e) {
// "Failed to create temporary file."
error(new JavaException(e));
}
return NIL;
}
}
public static final Primitive MAKE_TEMP_DIRECTORY = new make_temp_directory();
@DocString(name="make_temp_directory",
@DocString(name="make-temp-directory",
doc="Create and return the pathname of a previously non-existent directory.")
private static class make_temp_directory extends Primitive {
make_temp_directory() {
......@@ -371,5 +417,4 @@ public final class Extensions
return result;
}
}
}
......@@ -122,6 +122,7 @@ public final class Keyword
PACKAGE = internKeyword("PACKAGE"),
PATHNAME = internKeyword("PATHNAME"),
PROBE = internKeyword("PROBE"),
PREFIX = internKeyword("PREFIX"), // EXT:MAKE-TEMP-FILE
PUBLIC = internKeyword("PUBLIC"),
PRESERVE = internKeyword("PRESERVE"),
REF = internKeyword("REF"),
......@@ -134,6 +135,7 @@ public final class Keyword
STATUS = internKeyword("STATUS"),
STREAM = internKeyword("STREAM"),
SUNOS = internKeyword("SUNOS"),
SUFFIX = internKeyword("SUFFIX"), // EXT:MAKE-TEMP-FILE
SUPERSEDE = internKeyword("SUPERSEDE"),
TEST = internKeyword("TEST"),
TEST_NOT = internKeyword("TEST-NOT"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment