Article View: comp.sources.atari.st
Article #43v02i045: modedit -- Hardwire an editor into German Modula-2
From: Steven Grimm
Date: Sun, 25 Jun 1989 16:15
Date: Sun, 25 Jun 1989 16:15
80 lines
3012 bytes
3012 bytes
Submitted-by: piet@cs.ruu.nl (Piet van Oostrum)
Posting-number: Volume 2, Issue 45
Archive-name: modedit
This program can be used to glue your favorite editor into the German
Modula-2 system. The program starts the editor named in the environment
variable EDITOR, with the cursor enabled. The environment of the parent is
passed on as the modula system forgets about it. If more than 1 parameter
is given, the first one is the error file, and that file is updated to get
the line/char numbers in normal ASCII code.
All this wouldn't be necessary if the Modula2 compiler did it right.
I compiled this with sozobon. [Note: the backslashes in the filename near
the top may have to be doubled (like \\) or C may treat them as escapes for
the next character in the filename. Dunno what Sozobon does about that. -sg]
------------------------------------------------------------------------
#!/bin/sh
# shar: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# modify.c
#
sed 's/^X//' << 'SHAR_EOF' > modify.c &&
X#include <basepage.h>
X#include <stdio.h>
X#include <osbind.h>
X#include <string.h>
X#define DEF_EDIT "c:\bin\xmg.ttp"
Xextern char *getenv();
Xextern char *_envp;
Xmain(argc, argv)
Xint argc; char **argv;
X{
X char *program, buf[80], command[128];
X int status;
X BASEPAGE *bp = _base;
X printf ("\033e"); /* cursor on */
X /* search for environment */
X /* modula-2 does not pass the environment, */
X /* so we also look in parents' environment */
X while (bp) {
X _envp = bp->p_env;
X bp = bp->p_parent;
X program = getenv("EDITOR");
X if (program && *program) break;
X }
X if (!program || !*program)
X program = DEF_EDIT;
X command[1] = 0;
X if (argc > 2 ) {
X register int c;
X char *tempname = strdup (argv[1]);
X FILE *errfile = fopen (argv[1], "r"), *copfile;
X strcpy (tempname + strlen(tempname) -3, "tmp");
X copfile = fopen (tempname, "w");
X while ((c = getc (errfile)) != EOF)
X putc ((c>=0x10 && c<=0x19) ? c+0x20 : c, copfile);
X fclose (errfile);
X fclose (copfile);
X remove (argv[1]);
X rename (tempname, argv[1]);
X }
X while (--argc > 0) {
X strcat (&command[1], (++argv)[0]);
X strcat (&command[1], " ");
X }
X command[0] = strlen(&command[1]);
X status = (int) Pexec (0, program, command, _envp);
X if (status) {
X fprintf (stderr, "Can't execute %s - error %d\n",
X program, status);
X }
X printf ("\033f"); /* cursor off */
X return status;
X}
X
SHAR_EOF
chmod 0600 modify.c || echo "restore of modify.c fails"
exit 0
Technical Details
Message-ID:
<8127@saturn.ucsc.edu>Path:
arc1-ca.pugleaf.net!wuarchive!wugate!uunet!dino!uxc.cso.uiuc.edu!csd4.milw.wisc.edu!bionet!agate!saturn!koreth@ssyx.ucsc.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wuarchive!wugate!uunet!dino!uxc.cso.uiuc.edu!csd4.milw.wisc.edu!bionet!agate!saturn!koreth@ssyx.ucsc.edu From: koreth@ssyx.ucsc.edu (Steven Grimm) Newsgroups: comp.sources.atari.st Subject: v02i045: modedit -- Hardwire an editor into German Modula-2 Keywords: shar, C Message-ID: <8127@saturn.ucsc.edu> Date: 25 Jun 89 16:15:06 GMT Sender: usenet@saturn.ucsc.edu Lines: 80 Approved: koreth@ssyx.ucsc.edu