view 3rdparty/packages/ed/catsub.c @ 3295:6b7a7b233925 default tip

makefile: Allow PORTS with level1/2 mix https://sourceforge.net/p/nitros9/feature-requests/10/
author Tormod Volden <debian.tormod@gmail.com>
date Tue, 19 Apr 2022 18:12:17 +0200
parents bef1844de0dc
children
line wrap: on
line source

/*      catsub.c        */
#include <stdio.h>
#include "tools.h"
#include "ed.h"

extern char *paropen[9], *parclose[9];

char *catsub(from, to, sub, new, newend)
char *from, *to, *sub, *new, *newend;
{
  char *cp, *cp2;

  for (cp = new; *sub != EOS && cp < newend;) {
        if (*sub == DITTO) for (cp2 = from; cp2 < to;) {
                        *cp++ = *cp2++;
                        if (cp >= newend) break;
                }
        else if (*sub == ESCAPE) {
                sub++;
                if ('1' <= *sub && *sub <= '9') {
                        char *parcl = parclose[*sub - '1'];

                        for (cp2 = paropen[*sub - '1']; cp2 < parcl;) {
                                *cp++ = *cp2++;
                                if (cp >= newend) break;
                        }
                } else
                        *cp++ = *sub;
        } else
                *cp++ = *sub;

        sub++;
  }

  return(cp);
}