home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / MacroIO.FPL < prev    next >
Encoding:
Text File  |  1995-02-27  |  1.8 KB  |  76 lines

  1.  
  2. export void SaveMacro ()
  3. {
  4.   int id;
  5.   string promptname="";
  6.   string name;
  7.  
  8.   id = PromptBuffer("Macro to save:", 10);
  9.   if (id) {
  10.     if (!strncmp(ReadInfo("file_name"), "Macro", 5))
  11.       promptname="FrexxEd:Macros/";
  12.     else if (!strlen(ReadInfo("file_path")))
  13.       promptname=joinstr("FrexxEd:Macros/", ReadInfo("file_name"));
  14.     if (strlen(promptname))
  15.       name=PromptFile(promptname, "Save macro:", "#?.macro");
  16.     else
  17.       name=ReadInfo("full_file_name");
  18.     if (strlen(name)) {
  19.       int oldid=GetEntryID();
  20.       string insertline;
  21.       string firstline;
  22.       string macrostring;
  23.  
  24.       CurrentBuffer(id);
  25.       firstline=GetLine(1);
  26.  
  27.       if (strncmp(firstline, "/* Macro:", 9))
  28.         insertline=joinstr("/* Macro:", ReadInfo("macro_key"), "*/\n");
  29.  
  30.       CurrentBuffer(oldid);
  31.       macrostring=GetBlock(id);
  32.       if (!GetErrNo()) {
  33.         SaveString(name, joinstr(insertline, macrostring));
  34.       } else
  35.         ReturnStatus("Out of memory!");
  36.     } else
  37.       ReturnStatus("Function cancel!");
  38.   } else
  39.     ReturnStatus("Function cancel!");
  40. }
  41.  
  42.  
  43. export void LoadMacro(string macrofile)
  44. {
  45.  
  46.   string macroname;
  47.  
  48.   if(strlen(macrofile))
  49.     macroname = macrofile;
  50.   else
  51.     macroname=PromptFile("FrexxEd:Macros/", "Load macro:", "#?.macro");
  52.   if (strlen(macroname)) {
  53.     int id;
  54.     int oldid=GetEntryID();
  55.     id=New();
  56.     if (id) {
  57.       string firstline;
  58.       CurrentBuffer(id);
  59.       Load(macroname);
  60.       firstline=GetLine(1);
  61.       if (!strncmp(firstline, "/* Macro:", 9)) {
  62.         int len;
  63.         len=strstr(firstline, "*/\n");
  64.         if (len)
  65.           AssignKey(joinstr("ExecuteBuffer(", ltostr(id), ");"), substr(firstline, 9, len-9));
  66.         SetInfo(id, "macro_key", substr(firstline, 9, len-9));
  67.         SetInfo(id, "type", 12);
  68.       } else {
  69.         ReturnStatus("No macro!");
  70.         Kill(id);
  71.       }
  72.       CurrentBuffer(oldid);
  73.     }
  74.   }
  75. }
  76.