Files
Digital-Research-Source-Code/CPM OPERATING SYSTEMS/CPM 68K/cpm68k_pgms/snobol4/GENPRIM.C
Sepp J Morris 31738079c4 Upload
Digital Research
2020-11-06 18:50:37 +01:00

1 line
1.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* -*-c,save-*- */
/*
* genprim.c - general prims - replace and dupl
* Robert Heller. Created: Sun Mar 9, 1986 15:58:08.74
* Last Mod:
*
* (c) Copyright 1986 by Robert Heller
* All Rights Reserved
*
*
*/
#include <stdio.h>
dupl(instr,count,outbuff)
register char *instr,*outbuff;
register int count;
{
register char *p;
register int len;
p = outbuff; len = strlen(instr);
while (count-- > 0) {
strcpy(p,instr);
p += len;
}
}
char *a_dupl(instr,count)
register char *instr;
register int count;
{
char *malloc();
register int len;
register char *new;
len = strlen(instr) * count;
new = malloc(len+1);
if (new == NULL) {
perror("dupl");
abort(0);
}
dupl(instr,count,new);
return(new);
}
replace(input,olds,news,result)
char *input,*olds,*news,*result;
{
register int indx;
register char *p1,*p2,*p3;
char *index();
p1 = input; p2 = result;
while (*p1 != '\0') {
p3 = index(olds,*p1);
if (p3 == NULL) {
fprintf(stderr,"replace: bad string: %s\n",input);
abort(*p1);
}
indx = (int) (p3 - olds);
*p2 = news[indx];
p1++; p2++;
}
*p2 = '\0';
}
char *a_replace(input,olds,news)
char *input,*olds,*news;
{
char *malloc();
register char *result;
result = malloc(strlen(input)+1);
if (result == NULL) {
perror("replace");
abort(0);
}
replace(input,olds,news,result);
return(result);
}