--- freem/src/cmd_zedit.c 2025/05/19 02:03:31 1.2
+++ freem/src/cmd_zedit.c 2025/05/19 17:57:20 1.3
@@ -1,7 +1,7 @@
/*
*
- * $Id: cmd_zedit.c,v 1.2 2025/05/19 02:03:31 snw Exp $
+ * $Id: cmd_zedit.c,v 1.3 2025/05/19 17:57:20 snw Exp $
* Implementation of the ZEDIT command
*
*
@@ -26,6 +26,9 @@
* along with FreeM. If not, see .
*
* $Log: cmd_zedit.c,v $
+ * Revision 1.3 2025/05/19 17:57:20 snw
+ * Extend ZEDIT to create the specified routine if it does not yet exist
+ *
* Revision 1.2 2025/05/19 02:03:31 snw
* Reverse-engineer and document argumented ZPRINT (thanks to D. Wicksell)
*
@@ -38,6 +41,7 @@
**/
#include
+#include
#include
#include
#include "mpsdef.h"
@@ -51,7 +55,8 @@ MRESULT cmd_zedit(MACTION *ra)
char editor_command[PATHLEN];
char *tgt_editor;
short free_editor = FALSE;
-
+ FILE *fp;
+
if (restricted_mode) {
/* we never shell out in restricted mode */
retval = NOSTAND;
@@ -105,8 +110,13 @@ MRESULT cmd_zedit(MACTION *ra)
if ((rtn_get_path (tgt_routine, pth)) == FALSE) {
/* the routine could not be found */
- retval = NOPGM;
- goto done;
+ if ((fp = fopen (pth, "w")) == NULL) {
+ retval = PROTECT;
+ goto done;
+ }
+
+ fprintf (fp, "%s ; Created by FreeM Administrator\n QUIT\n", tgt_routine);
+ fclose (fp);
}
snprintf (editor_command, sizeof (editor_command) - 1, "%s %s", tgt_editor, pth);
@@ -122,6 +132,7 @@ MRESULT cmd_zedit(MACTION *ra)
sig_attach (SIGUSR1, &oncld);
retval = OK;
+ codptr++;
done:
if (free_editor) free (tgt_editor);