Example #1
0
 private int handleClose(int a0) {
   OpenFile file = openfiles.get(a0);
   if (file == null) return -1;
   file.close();
   openfiles.remove(a0);
   available_descriptors.add(a0);
   return 0;
 }
Example #2
0
        public void importFile() {
                Editor editor=getJPE().getEditor();                

                String tempfilename = getFileName(FileDialog.LOAD);
                OpenFile tempfile = new OpenFile(tempfilename);
                String txt = tempfile.getText();

                if (txt != null) {
                        editor.insertText(txt);
                        getJPE().say("Text Import");
                }
        }
Example #3
0
 private void handleClose(String result) {
         // get the text handler 
         Editor editor=(Editor)getJPE().getEditor();        
         if (editor!=null) {
                 // get the selected file from the text handler
                 OpenFile file=editor.getEditFile();
                 if (file!=null) {
                         if (result.equals("y")) file.saveFile();
                         file.clearDirty();
                         closeFile();
                 }
         }
 }
Example #4
0
 /**
 * save selected file to disk
 */
 private void saveFile() {
         // get the text handler 
         Editor editor=(Editor)getJPE().getEditor();        
         if (editor!=null) {
                 // get the selected file from the text handler
                 OpenFile file=editor.getEditFile();
                 if (file!=null) {
                         // signal the use we are saving and save it to disk                
                         getJPE().say("Saving file "+file.getName());
                         file.saveFile();
                         getJPE().say("Saved file "+file.getName());
                 }
         }
 }
Example #5
0
 /**
 * close the selected file, meaning removing it from the Opened
 * list and removing it from the auto reload on startup list
 */
 private void closeFile() {
         OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened");        
         Editor editor=(Editor)getJPE().getEditor();        
         if (editor!=null) {
                 OpenFile file=editor.getEditFile();
                 if (!file.isDirty()) {
                         ofh.removeFile(file);
                         addRecent(file.getName());
                         ofh.switchOpenFile();
                 } else {
                         getJPE().setAskMode(this,"close","File not saved, save first  (y/n) ? ",true);
                 }
         }
 }
Example #6
0
 public void handleRevert(String answer) {
         if("y".equals(answer)) {
                 Editor editor=(Editor)getJPE().getEditor();        
                 if (editor!=null) {
                         // get the selected file from the text handler
                         OpenFile file=editor.getEditFile();
                         if (file!=null) {
                                 // revert the file
                                 file.loadFile();
                                 // tell editor to useFile, without saving
                                 editor.useFile(file,false);
                         }
                 }
         }
 }
Example #7
0
 @Override
 public String getName() {
   String ret = mFile.getName();
   if (ret.endsWith("/")) ret = ret.substring(0, ret.length() - 1);
   ret = ret.substring(ret.lastIndexOf("/") + 1);
   return ret;
 }
Example #8
0
 /* we will try to allocate a free page from the freepages*/
 public static int insertPage(int ppn) {
   int numBits = 0;
   int spn = swapFile.length() / PAGESIZE;
   if (freePages.size() > 0) {
     spn = freePages.remove(0);
   }
   return insertPage(spn, ppn);
 }
Example #9
0
 public static int insertPage(int spn, int ppn) {
   swapLock.acquire();
   int numBits = swapFile.write(spn * PAGESIZE, memory, ppn * PAGESIZE, PAGESIZE);
   // assert that numBits == PAGESIZE
   allocatedPages.add(spn);
   swapLock.release();
   return spn;
 }
Example #10
0
 private void lockFile() {
         OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened");        
         Editor editor=(Editor)getJPE().getEditor();        
         if (editor!=null) {
                 OpenFile file=editor.getEditFile();
                 if (file.isLocked()) {
                         file.clearLocked();
                         getJPE().setLockState(false);
                         getJPE().say("file is now unlocked ( read / write )");
                 } else {
                         file.setLocked();
                         getJPE().setLockState(true);
                         getJPE().say("file is now locked (read only)");
                 }
                 ofh.updateProperties();
         }
 }
Example #11
0
 public static void readPage(int spn, int ppn) {
   if (allocatedPages.contains(spn)) {
     swapLock.acquire();
     swapFile.read(spn * PAGESIZE, memory, ppn * PAGESIZE, PAGESIZE);
     swapLock.release();
   } else {
   }
 }
Example #12
0
        /**
        * create new file, under the name untitled or a followup
        * untitled2, untitled3 etc etc
        */
        public void newFile(boolean template) {
                // get the openfile handler to add the new file
                OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened");        
                if (ofh==null) {
                        // no opened handler started so lets start one and add it the
                        // menu.
                        ofh=(OpenFileHandler)getJPE().addHandler(new OpenFileHandler(getJPE()));
                        ofh.createMenu(getJPE().getMenuBar());
                }


                // find a empty untitled filename
                String prefix="untitled";
                String filename=prefix;
                int i=2;
                // repeat until we found one        
                while (ofh.isLoaded(filename)) {
                        filename=prefix+(i++);        
                }

                // open a file with the found name
                OpenFile file=new OpenFile(filename);
                if(template) {
                        // open a dialog to let the user select the file we need to load        
                        String tempfilename = getFileName(FileDialog.LOAD);
                        OpenFile tempfile = new OpenFile(tempfilename);
                        String txt = tempfile.getText();
                        try {
                                RE re = new RE("<getJPE():date>");
                                txt = re.substitute(txt,""+new Date());
                                file.setText(txt);
                        } catch(REException ree) {
                                ree.printStackTrace();
                        }
                }

                // add the file to the opened file list
                ofh.addFile(file);

                // load this file into the text area
                getJPE().getEditor().useFile(file);
        }
Example #13
0
 public void fetchFrom(OpenFile file) {
   byte buffer[] = new byte[tableSize * DirectoryEntry.sizeOf()];
   // read the file
   file.readAt(buffer, 0, tableSize * DirectoryEntry.sizeOf(), 0);
   // unmarshall
   int pos = 0;
   for (int i = 0; i < tableSize; i++) {
     table[i].internalize(buffer, pos);
     pos += DirectoryEntry.sizeOf();
   }
 }
Example #14
0
  public void writeBack(OpenFile file) {
    byte buffer[] = new byte[tableSize * DirectoryEntry.sizeOf()];
    // marshall
    int pos = 0;
    for (int i = 0; i < tableSize; i++) {
      table[i].externalize(buffer, pos);
      pos += DirectoryEntry.sizeOf();
    }

    // write the file
    file.writeAt(buffer, 0, tableSize * DirectoryEntry.sizeOf(), 0);
  }
Example #15
0
 public OpenLZMA(OpenFile file) {
   mFile = file;
   try {
     mRAF = new MyRandomAccessFile(file.getPath(), "r");
     mLZMA = new Handler();
     mLZMA.Open(mRAF);
     // Logger.LogInfo("LZMA file " + LZMAFile + " has " + length() +
     // " entries");
   } catch (IOException e) {
     Logger.LogError("Couldn't open LZMA file (" + file + ")");
   }
 }
Example #16
0
  private int handleWrite(int a0, int bufaddr, int count) {
    OpenFile file = openfiles.get(a0);
    if (file == null) return -1;
    byte[] transfer_buffer = new byte[Processor.pageSize];
    int total_transfer = 0;
    while (count > 0) {
      int readlen = Math.min(Processor.pageSize, count);

      int actualread = readVirtualMemory(bufaddr, transfer_buffer, 0, readlen);
      if (actualread == -1) return -1;
      if (actualread < readlen) return -1;

      int written_bytes = file.write(transfer_buffer, 0, actualread);
      if (written_bytes != actualread) {
        return -1;
      }
      count -= actualread;
      bufaddr += actualread;
      total_transfer += actualread;
    }
    return total_transfer;
  }
Example #17
0
 /**
 * ask the user for a filename (using a file requester) and save
 * the current file under that name
 */
 private void saveAsFile() {
         // get openfile handlers
         OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened");        
         if (ofh!=null) {
                 // ask the user for the file name
                 String filename=getFileName(FileDialog.SAVE);
                 // get the text handler
                 Editor editor=(Editor)getJPE().getEditor();        
                 // get the selected file                                
                 OpenFile file=editor.getEditFile();
                 // remove the file from the opened list
                 ofh.removeFile(file);
                 if (file!=null) {
                         // set the new name in the file
                         file.setName(filename);
                         getJPE().say("Saving file "+file.getName());
                         // save the file under this new name
                         file.saveFile();
                         // add the file to the opened files again  (now new name)
                         ofh.addFile(file);
                         getJPE().say("Saved file "+file.getName());
                 }
         }
 }
Example #18
0
  /**
   * Sets the properties of a new task, passed as an argument.
   *
   * <p>Creates a new thread list, sets TaskLive status and creation time, creates and opens the
   * task's swap file of the size equal to the size (in bytes) of the addressable virtual memory.
   *
   * @return task or null @OSPProject Tasks
   */
  public static TaskCB do_create() {
    TaskCB new_task = new TaskCB(); // criação da nova task
    HClock new_clock = new HClock(); // instância do relógio do sistema
    String path = SwapDeviceMountPoint + String.valueOf(new_task.getID()); // path do swap file

    new_task.new_thread = new ArrayList<ThreadCB>();
    new_task.new_port = new ArrayList<PortCB>();
    new_task.new_file = new ArrayList<OpenFile>();

    new_task.setPageTable(new PageTable(new_task));

    new_task.setCreationTime(
        new_clock.get()); // usa a instância do relógio, para setar o horário de criação da task

    new_task.setStatus(TaskLive); // seta o estado atual da task (TaskLive)
    new_task.setPriority(1); // como não foi especificado nenhuma prioridade na descrição, usamos 1

    new_task.new_swap.create(
        path,
        (int)
            Math.pow(
                2.0D,
                MMU.getVirtualAddressBits())); // tamanho da página deve ser 2^(número de bits do
    // ambiente)
    OpenFile save_swap = OpenFile.open(path, new_task); // abrimos o swap file

    new_task.setSwapFile(
        save_swap); // dizemos que o swap criado acima deve ser alocado a nossa task

    ThreadCB.create(new_task); // criamos a thread inicial

    if (save_swap == null) { // verificamos se o swap foi criado com sucesso
      new_task
          .new_thread
          .get(0)
          .dispatch(); // caso não tenha, dispachamos a thread criada acima (posição 0 do vetor)
      return null; // e retornamos uma task nula
    }

    return new_task; // se tudo ocorreu como esperado, retornamos a task criada inicialmente
  }
Example #19
0
 @Override
 public OpenPath getParent() {
   return mFile.getParent();
 }
Example #20
0
 @Override
 public String getAbsolutePath() {
   return mFile.getAbsolutePath();
 }
Example #21
0
 @Override
 public long length() {
   return mFile.length();
 }
Example #22
0
 @Override
 public Long lastModified() {
   return mFile.lastModified();
 }
Example #23
0
 @Override
 public String getPath() {
   return mFile.getPath();
 }
Example #24
0
 @Override
 public OutputStream getOutputStream() throws IOException {
   return new LzmaOutputStream(mFile.getOutputStream());
 }
Example #25
0
 @Override
 public Boolean canRead() {
   return mFile.canRead();
 }
Example #26
0
 @Override
 public InputStream getInputStream() throws IOException {
   return new LzmaInputStream(mFile.getInputStream());
 }
Example #27
0
 @Override
 public Boolean mkdir() {
   return mFile.mkdir();
 }
Example #28
0
 @Override
 public Boolean delete() {
   return mFile.delete();
 }
Example #29
0
 @Override
 public Boolean exists() {
   return mFile.exists();
 }
Example #30
0
 @Override
 public Boolean canWrite() {
   return mFile.canWrite();
 }