koreth@ssyx.ucsc.edu (Steven Grimm) (06/25/89)
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