Exemplo n.º 1
0
Arquivo: edit.c Projeto: npe9/harvey
String*
getregexp(int delim)
{
	String *buf, *r;
	int i, c;

	buf = allocstring(0);
	for(i=0; ; i++){
		if((c = getch())=='\\'){
			if(nextc()==delim)
				c = getch();
			else if(nextc()=='\\'){
				Straddc(buf, c);
				c = getch();
			}
		}else if(c==delim || c=='\n')
			break;
		if(i >= RBUFSIZE)
			editerror("regular expression too long");
		Straddc(buf, c);
	}
	if(c!=delim && c)
		ungetch();
	if(buf->n > 0){
		patset = TRUE;
		freestring(lastpat);
		lastpat = buf;
	}else
		freestring(buf);
	if(lastpat->n == 0)
		editerror("no regular expression defined");
	r = newstring(lastpat->n);
	runemove(r->r, lastpat->r, lastpat->n);	/* newstring put \0 at end */
	return r;
}
Exemplo n.º 2
0
int substringx (char **ap, char *inx, char *outx, int niter)
/**
 *ap is original string
 all occurrences of inx are substituted with outx
 can loop so be careful !!

 NB.  ap must be on heap.  Fixed allocation not supported
*/
{
    char *a, *pt ;
    char *str ;
    int len, off, x ;

    if (niter>50) fatalx("bad string replacement\n %s\n", *ap) ;

    a = *ap ;
    len = strlen(a) + strlen(inx) + strlen(outx) + 1 ;
    pt = strstr(a, inx) ;
    if (pt == NULL) {
        return 0 ;
    }
    ZALLOC(str, len, char) ;
    off = pt - a ;
    strncpy(str,a,off) ;
    strcpy(str+off, outx) ;
    x = strlen(outx) ;
    pt += strlen(inx) ;
    strcpy(str+off+x, pt) ;

    freestring(&a) ;
    *ap = strdup(str) ;
    free(str) ;
    return (1 + substringx(ap, inx, outx, niter+1)) ;
}
Exemplo n.º 3
0
int oldsplitup(char *strin, char**spt, int maxpt)
/**
 retained in case there are compatibility problems
*/
{
    char *s1, *s2, *sx ;
    char *str ;
    int i, len, num ;

    len = strlen(strin) ;
    if (len==0) return 0 ;
    ZALLOC(str, 2*len, char) ;
    num = 0 ;
    sx = strin ;
    for (i=0; i<maxpt; i++)  {
        s1 = fnwhite(sx) ;
        if (s1==NULL) {
            break ;
        }
        s2 = fwhite(s1) ;
        if (s2==NULL) {
            s2 = s1+strlen(s1) ;
        }
        s2-- ;  /* now points at last character of next word */
        len = s2-s1+1 ;
        strncpy(str,s1,len) ;
        str[len] = '\0' ;
        spt[num] = strdup(str) ;
        ++num ;
        sx = s2+1 ;
    }
    freestring(&str) ;
    return num ;
}
Exemplo n.º 4
0
void freeup (char *strpt[],int numpt)
/** free up array of strings */
{
    int i ;
    for (i=numpt-1; i>=0; i--)  {
        if (strpt[i] != NULL) freestring(&strpt[i]) ;
    }
}
Exemplo n.º 5
0
Arquivo: edit.c Projeto: npe9/harvey
void
freecmd(void)
{
	int i;

	while(cmdlist.nused > 0)
		free(cmdlist.ucharptr[--cmdlist.nused]);
	while(addrlist.nused > 0)
		free(addrlist.ucharptr[--addrlist.nused]);
	while(stringlist.nused>0){
		i = --stringlist.nused;
		freestring(stringlist.stringptr[i]);
	}
}
Exemplo n.º 6
0
char *strstrx(char *s1, char *s2)
// like strstr but case insensitive
// see also strcasestr
{
    char *ss1, *ss2, *spt  ;

    ss1 = strdup(s1) ;
    ss2 = strdup(s2) ;


    mkupper(ss1) ;
    mkupper(ss2) ;

    spt = strstr(ss1, ss2) ;
    if (spt != NULL) {
        spt = s1 + (spt - ss1) ;
    }

    freestring(&ss1) ;
    freestring(&ss2) ;

    return spt ;

}