Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • text.c

    r47519e1b r3bcf125  
    5050void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)
    5151{
    52   char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
    53   int col, cnt, padding;
    54  
     52  char *ptr1, *ptr2, *tmpbuff, *last;
     53  int len;
     54
    5555  tmpbuff=owl_malloc(strlen(in)+20);
    5656
    5757  strcpy(tmpbuff, "");
    5858  last=in+strlen(in)-1;
    59   ptr_s=in;
    60   while (ptr_s<last) {
    61     ptr_e=strchr(ptr_s, '\n');
    62     if (!ptr_e) {
     59  ptr1=in;
     60  while (ptr1<last) {
     61    ptr2=strchr(ptr1, '\n');
     62    if (!ptr2) {
    6363      /* but this shouldn't happen if we end in a \n */
    6464      break;
    6565    }
    6666   
    67     if (ptr_e==ptr_s) {
     67    if (ptr2==ptr1) {
    6868      strcat(tmpbuff, "\n");
    69       ptr_s++;
    70       continue;
    71     }
    72 
    73     col = 0;
    74     cnt = 0;
    75     padding = 0;
    76     ptr_c = ptr_s;
    77     while(col < bcol && ptr_c < ptr_e) {
    78       gunichar c = g_utf8_get_char(ptr_c);
    79       if (col + mk_wcwidth(c) > bcol) break;
    80       col += mk_wcwidth(c);
    81       ptr_c = g_utf8_next_char(ptr_c);
    82       if (col >= acol) {
    83         if (cnt == 0) {
    84           ptr_s = ptr_c;
    85           padding = col - acol;
    86         }
    87         ++cnt;
    88       }
    89     }
    90     if (cnt) {
    91       while(padding-- > 0) {
    92         strcat(tmpbuff, " ");
    93       }
    94       strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
    95     }
    96     strcat(tmpbuff, "\n");
    97     ptr_s = ptr_e + 1;
    98 #if 0
     69      ptr1++;
     70      continue;
     71    }
     72
    9973    /* we need to check that we won't run over here */
    100     if ( (ptr_e-ptr_s) < (bcol-acol) ) {
    101       len=ptr_e-(ptr_s+acol);
     74    if ( (ptr2-ptr1) < (bcol-acol) ) {
     75      len=ptr2-(ptr1+acol);
    10276    } else {
    10377      len=bcol-acol;
    10478    }
    105     if ((ptr_s+len)>=last) {
    106       len-=last-(ptr_s+len);
    107     }
    108 
    109     strncat(tmpbuff, ptr_s+acol, len);
     79    if ((ptr1+len)>=last) {
     80      len-=last-(ptr1+len);
     81    }
     82
     83    strncat(tmpbuff, ptr1+acol, len);
    11084    strcat(tmpbuff, "\n");
    11185
    112     ptr_s=ptr_e+1;
    113 #endif
     86    ptr1=ptr2+1;
    11487  }
    11588  strcpy(out, tmpbuff);
     
    194167
    195168    /* look for things we know */
    196     if (!strncasecmp(ptr2, "<BODY ", 6) ||
     169    if (!strncasecmp(ptr2, "<BODY", 5) ||
    197170        !strncasecmp(ptr2, "<FONT", 5) ||
    198171        !strncasecmp(ptr2, "<HTML", 5) ||
     
    302275char *stristr(char *a, char *b)
    303276{
    304   char *x, *y;
    305   char *ret = NULL;
    306   if ((x = g_utf8_casefold(a, -1)) != NULL) {
    307     if ((y = g_utf8_casefold(b, -1)) != NULL) {
    308       ret = strstr(x, y);
    309       if (ret != NULL) {
    310         ret = ret - x + a;
    311       }
    312       g_free(y);
    313     }
    314     g_free(x);
    315   }
     277  char *x, *y, *ret;
     278
     279  if ((x=owl_strdup(a))==NULL) return(NULL);
     280  if ((y=owl_strdup(b))==NULL) return(NULL);
     281  downstr(x);
     282  downstr(y);
     283  ret=strstr(x, y);
     284  if (ret==NULL) {
     285    owl_free(x);
     286    owl_free(y);
     287    return(NULL);
     288  }
     289  ret=ret-x+a;
     290  owl_free(x);
     291  owl_free(y);
    316292  return(ret);
    317293}
     
    320296int only_whitespace(char *s)
    321297{
    322   if (g_utf8_validate(s,-1,NULL)) {
    323     char *p;
    324     for(p = s; p[0]; p=g_utf8_next_char(p)) {
    325       if (!g_unichar_isspace(g_utf8_get_char(p))) return 0;
    326     }
    327   }
    328   else {
    329     int i;
    330     for (i=0; s[i]; i++) {
    331       if (!isspace((int) s[i])) return(0);
    332     }
     298  int i;
     299  for (i=0; s[i]; i++) {
     300    if (!isspace((int) s[i])) return(0);
    333301  }
    334302  return(1);
     
    359327  tolen  = strlen(to);
    360328  fromlen  = strlen(from);
    361   out = owl_malloc(outlen);
     329  out = malloc(outlen);
    362330
    363331  while (in[inpos]) {
Note: See TracChangeset for help on using the changeset viewer.