home *** CD-ROM | disk | FTP | other *** search
- /* -*-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);
- }
-