home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / TextEditors&Viewers / Texteditors / FFRED10.LHA / fpl / MacroIO.FPL < prev    next >
Encoding:
Text File  |  1994-09-25  |  1.8 KB  |  75 lines

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