Annotation of freem/src/cmd_zedit.c, revision 1.1

1.1     ! snw         1: 
        !             2: /*
        !             3:  *
        !             4:  *   $Id$
        !             5:  *    Implementation of the ZEDIT command
        !             6:  *
        !             7:  *  
        !             8:  *   Author: Serena Willis <snw@coherent-logic.com>
        !             9:  *    Copyright (C) 1998 MUG Deutschland
        !            10:  *    Copyright (C) 2025 Coherent Logic Development LLC
        !            11:  *
        !            12:  *
        !            13:  *   This file is part of FreeM.
        !            14:  *
        !            15:  *   FreeM is free software: you can redistribute it and/or modify
        !            16:  *   it under the terms of the GNU Affero Public License as published by
        !            17:  *   the Free Software Foundation, either version 3 of the License, or
        !            18:  *   (at your option) any later version.
        !            19:  *
        !            20:  *   FreeM is distributed in the hope that it will be useful,
        !            21:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            22:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            23:  *   GNU Affero Public License for more details.
        !            24:  *
        !            25:  *   You should have received a copy of the GNU Affero Public License
        !            26:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
        !            27:  *
        !            28:  *   $Log$
        !            29:  *
        !            30:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
        !            31:  * SPDX-License-Identifier: AGPL-3.0-or-later
        !            32:  **/
        !            33: 
        !            34: #include <string.h>
        !            35: #include <stdlib.h>
        !            36: #include <ctype.h>
        !            37: #include "mpsdef.h"
        !            38: #include "mcommand.h"
        !            39: 
        !            40: MRESULT cmd_zedit(MACTION *ra)
        !            41: {    
        !            42:     MRESULT retval;
        !            43:     char pth[PATHLEN];
        !            44:     char tgt_routine[PATHLEN];    
        !            45:     char editor_command[PATHLEN];
        !            46:     char *tgt_editor;
        !            47:     short free_editor = FALSE;
        !            48: 
        !            49:     if (restricted_mode) {
        !            50:         retval = NOSTAND;
        !            51:         goto done;
        !            52:     }
        !            53: 
        !            54:     if (rou_name[0] == EOL) {
        !            55:         retval = NOPGM;
        !            56:         goto done;
        !            57:     }        
        !            58:     
        !            59:     if ((tgt_editor = getenv ("EDITOR")) == NULL) {
        !            60:         tgt_editor = (char *) malloc (STRLEN * sizeof (char));
        !            61:         NULLPTRCHK(tgt_editor,"cmd_zedit");
        !            62:         
        !            63:         snprintf (tgt_editor, STRLEN - 1, "/usr/bin/vi");
        !            64:         free_editor = TRUE;
        !            65:     }
        !            66:     
        !            67:     if (*codptr == SP || *codptr == EOL) {
        !            68:         stcpy (tgt_routine, rou_name);
        !            69:     }
        !            70:     else {
        !            71:         expr (NAME);
        !            72:         
        !            73:         if (varnam[0] == '^') {
        !            74:             retval = GLOBER;
        !            75:             goto done;
        !            76:         }
        !            77: 
        !            78:         if (varnam[0] == '$') {
        !            79:             retval = INVREF;
        !            80:             goto done;
        !            81:         }
        !            82: 
        !            83:         if (merr ()) {
        !            84:             retval = merr ();
        !            85:             goto done;
        !            86:         }
        !            87:         
        !            88:         stcpy (tgt_routine, varnam);
        !            89:     }
        !            90: 
        !            91:     stcnv_m2c (tgt_routine);
        !            92:     
        !            93:     if ((rtn_get_path (tgt_routine, pth)) == FALSE) {
        !            94:         retval = NOPGM;
        !            95:         goto done;
        !            96:     }
        !            97:     
        !            98:     snprintf (editor_command, sizeof (editor_command) - 1, "%s %s", tgt_editor, pth);
        !            99:     
        !           100:     sig_attach (SIGUSR1, SIG_IGN);
        !           101:     set_io (UNIX);
        !           102: 
        !           103:     system (editor_command);
        !           104: 
        !           105:     set_io (MUMPS);
        !           106:     sig_attach (SIGUSR1, &oncld);
        !           107: 
        !           108:     retval = OK;
        !           109:     
        !           110: done:
        !           111:     if (free_editor) free (tgt_editor);
        !           112:     *ra = RA_CONTINUE;
        !           113:     return retval;        
        !           114: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>