home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / FREDV19A.LHA / FrexxEd / fpl / ExtraIO.FPL < prev    next >
Encoding:
Text File  |  1995-07-26  |  5.1 KB  |  239 lines

  1. string xfplf_filename="FrexxEd:FPL/";
  2. export int ExecuteFPLFile(string title)
  3. {
  4.   string newfile;
  5.   newfile=PromptFile(xfplf_filename, title, "#?.FPL");
  6.   if (strlen(newfile)) {
  7.     xfplf_filename=newfile;
  8.     ExecuteFile(newfile);
  9.   } else
  10.     ReturnStatus("Function cancel!");
  11. }
  12.  
  13. export int Open(string file)
  14. {
  15.   string name;
  16.   int inputbuffer=GetEntryID();
  17.   int id=inputbuffer;
  18.   int ret;
  19.  
  20.   if (ReadInfo("changes") || ReadInfo("size"))
  21.     id=New();    /* If the buffer isn't empty or is changed, open a new */
  22.   if (id) {
  23.     CurrentBuffer(id);
  24.     if (id!=inputbuffer || strlen(file))
  25.       ret=Load(file, "Open file:");
  26.     else
  27.       ret=Load("", "Open file:", ReadInfo("full_file_name", id));
  28.     CurrentBuffer(inputbuffer);
  29.     if (ret<0) {
  30.       if (id!=inputbuffer)
  31.         Kill(id);
  32.       id=0;
  33.     } else {
  34.       if (id!=inputbuffer) {
  35.         Activate(id);
  36.         CurrentBuffer(id);
  37.       }
  38.     }
  39.   }
  40.   ReturnStatus(GetReturnMsg(ret));
  41.   return(id);
  42. }
  43.  
  44. export int DeleteFile(string pattern)
  45. {
  46.   int numoffiles, a;
  47.   string files[1];
  48.   string question = "Are you sure you want to delete these?";
  49.  
  50.   if(strlen(pattern)) {
  51.     numoffiles = GetFileList(pattern, &files);
  52.   }
  53.   else {
  54.     numoffiles = PromptFile("", "Select files to delete", "#?", "m", &files);
  55.   }
  56.   if(numoffiles) {
  57.     while(a<numoffiles) {
  58.       question += "\n\"" + files[a] + "\"";
  59.       a++;
  60.     }
  61.     numoffiles *= Request(question, "Delete these?");
  62.     while(numoffiles--) {
  63.       System(sprintf("C:delete FORCE QUIET FILE \"%s\"", files[numoffiles]));
  64.     }
  65.   }
  66.   if(!numoffiles)
  67.     ReturnStatus("No files were deleted!");
  68.  
  69.   return numoffiles;
  70. }
  71.  
  72. export int SaveAs()
  73. {
  74.   string name;
  75.   int ret=1;
  76.  
  77.   name=PromptFile(ReadInfo("full_file_name"), "Save As", "", "s");
  78.  
  79.   if (strlen(name)) {
  80.     if(Check(name))
  81.       ret = Request("File already exists!\nDo you want to replace it?");
  82.     if(ret) {
  83.       Rename(name);
  84.       if(0 > Save()) {
  85.         ReturnStatus(GetReturnMsg(GetErrNo()));
  86.         DisplayBeep();
  87.       }
  88.     }
  89.   }
  90. }
  91.  
  92.  
  93. export int BlockLoad()
  94. {
  95.   string filename=PromptFile("", "Load Block!");
  96.  
  97.   if (strlen(filename)) {
  98.     string file;
  99.     int ret;
  100.     file=LoadString(filename);
  101.     ret=StringToBlock(file);    
  102.     if (ret!=0) {
  103.       ReturnStatus(GetReturnMsg(ret));
  104.       DisplayBeep();
  105.     }
  106.   }
  107. }
  108.  
  109. export int BlockSave()
  110. {
  111.   string filename=PromptFile("", "Save Block!");
  112.  
  113.   if (strlen(filename)) {
  114.     string file;
  115.     int ret;
  116.     file=GetBlock();
  117.     ret=SaveString(filename, file);
  118.     if (ret<0) {
  119.       ReturnStatus(GetReturnMsg(ret));
  120.       DisplayBeep();
  121.     }
  122.   }
  123. }
  124.  
  125. export int SaveChanges()  /* Save only a changed buffer */
  126. {
  127.   if (ReadInfo("changes")) {
  128.     if(0 > Save()) {
  129.       ReturnStatus(GetReturnMsg(GetErrNo()));
  130.       DisplayBeep();
  131.     }
  132.   } else
  133.     ReturnStatus("No changes need to be saved!");
  134. }
  135.  
  136. export int SaveAll()  /* Save all buffers */
  137. {
  138.   int currentid=GetEntryID();
  139.   int firstid=GetBufferID();
  140.   int id=firstid;
  141.  
  142.   do {
  143.     if (ReadInfo("type")&1) {
  144.       if(0 > Save()) {
  145.         ReturnStatus(GetReturnMsg(GetErrNo()));
  146.         DisplayBeep();
  147.       }
  148.     }
  149.     id=NextBuffer(id);
  150.     if (id == firstid)
  151.       id=0;
  152.     else
  153.       CurrentBuffer(id);
  154.   } while (id);
  155.   CurrentBuffer(currentid);
  156. }
  157.  
  158. export int SaveAllChanges()  /* Save all buffers */
  159. {
  160.   int activeentry=GetEntryID();
  161.   int firstid=GetBufferID();
  162.   int id=firstid;
  163.  
  164.   do {
  165.     if (ReadInfo("changes") && (ReadInfo("type")&1)) {
  166.       if(0 > Save()) {
  167.         ReturnStatus(GetReturnMsg(GetErrNo()));
  168.         DisplayBeep();
  169.       }
  170.     }
  171.     id=NextBuffer(id);
  172.     if (id == firstid)
  173.       id=0;
  174.     else
  175.       CurrentBuffer(id);
  176.   } while (id);
  177.   CurrentBuffer(activeentry);
  178. }
  179.  
  180. /* The Print functions will save the print file to t:PrintFile, make
  181.    a script to print it and start a new process that execute the script. */
  182.  
  183. export int Print()
  184. {
  185.   if (0 <= Save("t:PrintFile", "")) {
  186.     if (0 <= SaveString("t:PrintSkript", "type >prt: t:PrintFile \n"
  187.                                          "Delete >NIL: t:PrintFile \n"))
  188.       System("run >NIL: Execute t:PrintSkript");
  189.   }
  190.   else {
  191.     ReturnStatus(GetReturnMsg(GetErrNo()));
  192.     DisplayBeep();
  193.   }
  194. }
  195.  
  196. export int BlockPrint()
  197. {
  198.   if (0 <= SaveString("t:PrintFile", GetBlock())) {
  199.     if (0 <= SaveString("t:PrintSkript", "type >prt: t:PrintFile \n"
  200.                                           "Delete >NIL: t:PrintFile \n"))
  201.       System("run >NIL: Execute t:PrintSkript");
  202.   }
  203.   else {
  204.     ReturnStatus(GetReturnMsg(GetErrNo()));
  205.     DisplayBeep();
  206.   }
  207. }
  208.  
  209. export int RenameQuery()
  210. {
  211.   string name=PromptFile(ReadInfo("full_file_name"));
  212.   if (strlen(name)) {
  213.     int ret=1;
  214.     if(Check(name))
  215.       ret = Request("File " + name + " already exists!\nDo you really want this file name?");
  216.     if(ret)
  217.       Rename(name);
  218.   }
  219. }
  220.  
  221. export int SaveQuery()
  222. {
  223.   return !Request("File \"" + ReadInfo("full_file_name") + "\"\nhas been changed after FrexxEd loaded it.\nSave it anyway?");
  224. }
  225.  
  226. int _SaveCheck;
  227. export int SaveCheck(string file, string packmode)
  228. {
  229.   if(!_SaveCheck && !strlen(file) && !strlen(ReadInfo("file_name"))) {
  230.     _SaveCheck++;
  231.     SaveAs();
  232.     _SaveCheck--;
  233.     return 1; /* already saved by now! */
  234.   }
  235. }
  236.  
  237. Hook("FileChanged", "SaveQuery");
  238. Hook("Save", "SaveCheck");
  239.