Ejemplo n.º 1
0
void
str_fmt(char *p, int size, int fmt)
{
    int n, m, len;

    len = strlen (p);
    switch (fmt) {
    case FMT_RJUST:
        for (n = size - len; n > 0; n--)
            strichr (p, ' ');
        break;
    case FMT_LJUST:
        for (m = size - len; m > 0; m--)
            strcat (p, " ");
        break;
    case FMT_RJUST0:
        for (n = size - len; n > 0; n--)
            strichr (p, '0');
        break;
    case FMT_CENTER:
        m = (size - len) / 2;
        n = size - (len + m);
        for (; m > 0; m--)
            strcat (p, " ");
        for (; n > 0; n--)
            strichr (p, ' ');
        break;
    }
}
Ejemplo n.º 2
0
 char *
stristr(register const char * s1, register const char * s2)
{
	while(s1 && *s1) {
		if(strnicmp(s1, s2, strlen(s2)) == 0)
			return ( char *)s1;
		s1 = strichr(s1+1, *s2);
	}
	return NULL;
}
Ejemplo n.º 3
0
static int lcsi (char *x, char *y)
{
    char *first;                /* first occurence of *x in y */
    int res, res2;
    if ((x == NULL) || (y == NULL) || (*x == 0) || (*y == 0))
      return (0);
    first = strichr (y, *x);
    res = lcsi (x + 1, y);      /* is the first letter of x useless? */
    if ((first != NULL) && (strlen (first) > res)) {
        /* well, may be another solution, starting with *x. */
        res2 = lcsi (x + 1, first + 1) + 1;
        if (res2 > res)
          res = res2;
    }
    return (res);
}
Ejemplo n.º 4
0
static int lcsi (char *x, char *y)
{
    static char *savex[MAXSAVE];
    static char *savey[MAXSAVE];
    static int saveres[MAXSAVE];
    char **savexp = savex;
    char **saveyp = savey;
    int   *saveresp = saveres;
    int bestres = 0;
    int res;
    char *newy;
    *savexp++ = x;
    *saveyp++ = y;
    *saveresp++ = 0;
    while (savexp != savex) {
        x = *--savexp;
        y = *--saveyp;
        res = *--saveresp;
        while ((*x) && y && (*y)) {
            while ((*x) && (*y)) {
                int c1, c2;
                c1 = isupper (*x) ? tolower (*x) : *x;
                c2 = isupper (*y) ? tolower (*y) : *y;
                if (c1 != c2)
                  break;
                x++; y++; res++;
            }
            if ((! *x) || (! *y))
              continue;
            newy = strichr (y, *x);
            if (newy != NULL) {
                *savexp++ = x;
                *saveyp++ = newy;
                *saveresp++ = res;
            }
            x++;
        }
        if (res > bestres)
          bestres = res;
    }
    return (bestres);
}