Changeset 14877


Ignore:
Timestamp:
09/29/16 21:38:59 (7 years ago)
Author:
Mark Evenson
Message:

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

EXT:MAKE-TEMP-FILE &key (PREFIX "abcl") (SUFFIX ".tmp")

Location:
trunk/abcl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/CHANGES

    r14876 r14877  
    2525
    2626  FIXME:  breaking a number of ANSI tests.  Need to conditionalize runtime behavior.
     27
     28* EXTENSIONS:MAKE-TEMP-FILE now takes keyword arguments to specify
     29  values of the prefix and suffix strings to the underlying JVM
     30  implementation of java.io.File.createTempFile().
    2731
    2832Fixes
  • trunk/abcl/src/org/armedbear/lisp/Extensions.java

    r14853 r14877  
    265265
    266266  public static final Primitive MAKE_TEMP_FILE = new make_temp_file();
    267   @DocString(name="make_temp_file",
    268              doc="Create and return the pathname of a previously non-existent file.")
     267  @DocString(name="make-temp-file",
     268             doc="Create and return the pathname of a previously non-existent file.",
     269             args="&key prefix suffix")
    269270  private static class make_temp_file extends Primitive {
    270271    make_temp_file() {
    271       super("make-temp-file", PACKAGE_EXT, true, "");
    272     }
    273     @Override
    274     public LispObject execute()
    275     {
    276       try
    277         {
    278           File file = File.createTempFile("abcl", "", null);
    279           if (file != null)
    280             return new Pathname(file.getPath());
    281         }
    282       catch (IOException e)
    283         {
    284           Debug.trace(e);
    285         }
     272      super("make-temp-file", PACKAGE_EXT, true, "&key prefix suffix");
     273    }
     274    @Override
     275    public LispObject execute(LispObject ... args)
     276    {
     277      String prefix = "abcl";
     278      String suffix = null;
     279      if ( args.length % 2 != 0) {
     280        error(new WrongNumberOfArgumentsException("Expecting an even number of arguments including keywords."));
     281      }
     282
     283      for (int i = 0; i < args.length; i++ ) {
     284        if (args[i].SYMBOLP() != NIL) {
     285          if (args[i].equals(Keyword.PREFIX)) {
     286            String specifiedPrefix = args[i + 1].getStringValue();
     287            if (specifiedPrefix != null) {
     288              if (specifiedPrefix.equals(NIL.getStringValue())) {
     289                error (new TypeError("Cannot create temporary file with NIL prefix."));
     290              }
     291              prefix = specifiedPrefix;
     292              i += 1;
     293            }
     294          } else if (args[i].equals(Keyword.SUFFIX)) {
     295            String specifiedSuffix = args[i + 1].getStringValue();
     296            if (specifiedSuffix != null) {
     297              if (specifiedSuffix.equals(NIL.getStringValue())) {
     298                suffix =null;
     299              } else {
     300                suffix = specifiedSuffix;
     301              }
     302              i += 1;
     303            }
     304          }
     305        } else {
     306          error(new TypeError("Expected matching keyword argument.", args[i], Keyword.PREFIX.classOf()));
     307        }
     308      }
     309      return createTempFile(prefix, suffix);
     310    }
     311
     312    @Override
     313    public LispObject execute() {
     314      return createTempFile("abcl", null);
     315    }
     316
     317    private LispObject createTempFile(String prefix, String suffix) {
     318      try {
     319        File file = File.createTempFile(prefix, suffix, null);
     320        if (file != null)
     321          return new Pathname(file.getPath());
     322      } catch (IllegalArgumentException e) {
     323        // "Failed to create temporary file due to argument problems."
     324        error(new JavaException(e));
     325      } catch (SecurityException e) {
     326        //"Failed to create problem due to problems with JVM SecurityManager."
     327        error(new JavaException(e));
     328      } catch (IOException e) {
     329        // "Failed to create temporary file."
     330        error(new JavaException(e));
     331      }
    286332      return NIL;
    287333    }
     
    289335
    290336  public static final Primitive MAKE_TEMP_DIRECTORY = new make_temp_directory();
    291   @DocString(name="make_temp_directory",
     337  @DocString(name="make-temp-directory",
    292338             doc="Create and return the pathname of a previously non-existent directory.")
    293339  private static class make_temp_directory extends Primitive {
     
    372418    }
    373419  }
    374 
    375420}
  • trunk/abcl/src/org/armedbear/lisp/Keyword.java

    r14063 r14877  
    123123        PATHNAME            = internKeyword("PATHNAME"),
    124124        PROBE               = internKeyword("PROBE"),
     125        PREFIX              = internKeyword("PREFIX"), // EXT:MAKE-TEMP-FILE
    125126        PUBLIC              = internKeyword("PUBLIC"),
    126127        PRESERVE            = internKeyword("PRESERVE"),
     
    135136        STREAM              = internKeyword("STREAM"),
    136137        SUNOS               = internKeyword("SUNOS"),
     138        SUFFIX              = internKeyword("SUFFIX"),  // EXT:MAKE-TEMP-FILE
    137139        SUPERSEDE           = internKeyword("SUPERSEDE"),
    138140        TEST                = internKeyword("TEST"),
Note: See TracChangeset for help on using the changeset viewer.