Changes in / [2febcae:3617286]


Ignore:
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • aim.c

    r34509d5 r9854278  
    948948 
    949949  if (modname) {
    950     if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
     950    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
    951951      /* perror("memrequest: malloc"); */
    952952      return -1;
     
    954954    sprintf(filename, "%s/%s.ocm", priv->aimbinarypath, modname);
    955955  } else {
    956     if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
     956    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
    957957      /* perror("memrequest: malloc"); */
    958958      return -1;
     
    964964    if (!modname) {
    965965      /* perror("memrequest: stat"); */
    966       owl_free(filename);
     966      free(filename);
    967967      return -1;
    968968    }
     
    986986    int i;
    987987   
    988     owl_free(filename); /* not needed */
     988    free(filename); /* not needed */
    989989    owl_function_error("getaimdata memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname);
    990990    i = 8;
     
    993993    }
    994994   
    995     if (!(buf = owl_malloc(i))) {
     995    if (!(buf = malloc(i))) {
    996996      return -1;
    997997    }
     
    10171017    *buflenret = i;
    10181018  } else {
    1019     if (!(buf = owl_malloc(len))) {
    1020       owl_free(filename);
     1019    if (!(buf = malloc(len))) {
     1020      free(filename);
    10211021      return -1;
    10221022    }
     
    10241024    if (!(f = fopen(filename, "r"))) {
    10251025      /* perror("memrequest: fopen"); */
    1026       owl_free(filename);
    1027       owl_free(buf);
     1026      free(filename);
     1027      free(buf);
    10281028      return -1;
    10291029    }
    10301030   
    1031     owl_free(filename);
     1031    free(filename);
    10321032   
    10331033    if (fseek(f, offset, SEEK_SET) == -1) {
    10341034      /* perror("memrequest: fseek"); */
    10351035      fclose(f);
    1036       owl_free(buf);
     1036      free(buf);
    10371037      return -1;
    10381038    }
     
    10411041      /* perror("memrequest: fread"); */
    10421042      fclose(f);
    1043       owl_free(buf);
     1043      free(buf);
    10441044      return -1;
    10451045    }
     
    10761076  if (priv->aimbinarypath && (getaimdata(sess, &buf, &buflen, offset, len, modname) == 0)) {
    10771077    aim_sendmemblock(sess, fr->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
    1078     owl_free(buf);
     1078    free(buf);
    10791079  } else {
    10801080    owl_function_debugmsg("faimtest_memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", priv->aimbinarypath, modname);
     
    13421342      int z;
    13431343     
    1344       newbuf = owl_malloc(i+1);
     1344      newbuf = malloc(i+1);
    13451345      for (z = 0; z < i; z++)
    13461346        newbuf[z] = (z % 10)+0x30;
    13471347      newbuf[i] = '\0';
    13481348      /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_ACK | AIM_IMFLAGS_AWAY, newbuf); */
    1349       owl_free(newbuf);
     1349      free(newbuf);
    13501350    }
    13511351  } else if (strstr(tmpstr, "seticqstatus")) {
  • cmd.c

    r34509d5 r6922edd  
    7474  owl_cmd *cmd;
    7575
    76   tmpbuff=owl_strdup(cmdbuff);
     76  tmpbuff=strdup(cmdbuff);
    7777  argv=owl_parseline(tmpbuff, &argc);
    7878  if (argc < 0) {
  • configure.in

    r762512d r18e28a4  
    1212fi
    1313
    14 m4_include(/usr/share/aclocal/pkg.m4)
    15 dnl m4_include(pkg.m4)
    1614
    1715dnl Check for Athena
     
    111109LDFLAGS=${LDFLAGS}\ ${FOO}
    112110
    113 dnl Add CFLAGS and LDFLAGS for glib-2.0
    114 PKG_CHECK_MODULES(GLIB,glib-2.0)
    115 
    116 echo Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}
    117 CFLAGS=${CFLAGS}\ ${GLIB_CFLAGS}
    118 echo Adding glib-2.0 LDFLAGS ${GLIB_LIBS}
    119 LDFLAGS=${LDFLAGS}\ ${GLIB_LIBS}
    120 
    121 
    122111dnl Checks for typedefs, structures, and compiler characteristics.
    123112
  • fmtext.c

    r5376a95 rfa3290d  
    88void owl_fmtext_init_null(owl_fmtext *f)
    99{
    10   f->textlen = 0;
    11   f->bufflen = 5;
    12   f->textbuff = owl_malloc(5);
    13   f->textbuff[0] = 0;
    14   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    15   f->default_fgcolor = OWL_COLOR_DEFAULT;
    16   f->default_fgcolor = OWL_COLOR_DEFAULT;
     10  f->textlen=0;
     11  f->bufflen=5;
     12  f->textbuff=owl_malloc(5);
     13  f->fmbuff=owl_malloc(5);
     14  f->fgcolorbuff=owl_malloc(5 * sizeof(short));
     15  f->bgcolorbuff=owl_malloc(5 * sizeof(short));
     16  f->textbuff[0]=0;
     17  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     18  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     19  f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
    1720}
    1821
     
    2124void owl_fmtext_clear(owl_fmtext *f)
    2225{
    23   f->textlen = 0;
    24   f->textbuff[0] = 0;
    25   f->default_attrs = OWL_FMTEXT_ATTR_NONE;
    26   f->default_fgcolor = OWL_COLOR_DEFAULT;
    27   f->default_fgcolor = OWL_COLOR_DEFAULT;
     26    f->textlen = 0;
     27    f->textbuff[0] = 0;
     28    f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     29    f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     30    f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
     31}
     32
     33/* Internal function.  Set the attribute 'attr' from index 'first' to
     34 * index 'last'
     35 */
     36void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last)
     37{
     38  int i;
     39  for (i=first; i<=last; i++) {
     40    f->fmbuff[i]=(unsigned char) attr;
     41  }
     42}
     43
     44/* Internal function.  Add the attribute 'attr' to the existing
     45 * attributes from index 'first' to index 'last'
     46 */
     47void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last)
     48{
     49  int i;
     50  for (i=first; i<=last; i++) {
     51    f->fmbuff[i]|=(unsigned char) attr;
     52  }
     53}
     54
     55/* Internal function.  Set the color to be 'color' from index 'first'
     56 * to index 'last
     57 */
     58void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last)
     59{
     60  int i;
     61  for (i=first; i<=last; i++) {
     62    f->fgcolorbuff[i]=(short)color;
     63  }
     64}
     65
     66void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last)
     67{
     68  int i;
     69  for (i=first; i<=last; i++) {
     70    f->bgcolorbuff[i]=(short)color;
     71  }
    2872}
    2973
     
    3175{
    3276    if(newlen + 1 > f->bufflen) {
    33       f->textbuff = owl_realloc(f->textbuff, newlen + 1);
     77      f->textbuff=owl_realloc(f->textbuff, newlen+1);
     78      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short));
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short));
    3481      f->bufflen = newlen+1;
    3582  }
    3683}
    3784
    38 int _owl_fmtext_is_format_char(gunichar c) /*noproto*/
    39 {
    40   if ((c & ~OWL_FMTEXT_UC_ATTR_MASK) == OWL_FMTEXT_UC_ATTR) return 1;
    41   if ((c & ~(OWL_FMTEXT_UC_ALLCOLOR_MASK)) == OWL_FMTEXT_UC_COLOR_BASE) return 1;
    42   return 0;
    43 }
    4485/* append text to the end of 'f' with attribute 'attr' and color
    4586 * 'color'
    4687 */
    47 void owl_fmtext_append_attr(owl_fmtext *f, char *text, char attr, short fgcolor, short bgcolor)
    48 {
    49   char attrbuff[6];
    50   int newlen, a = 0, fg = 0, bg = 0;
    51  
    52   if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
    53   if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
    54   if (bgcolor != OWL_COLOR_DEFAULT) bg=1;
    55 
    56   /* Plane-16 characters in UTF-8 are 4 bytes long. */
    57   newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg));
     88void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor)
     89{
     90  int newlen;
     91  newlen=strlen(f->textbuff)+strlen(text);
    5892  _owl_fmtext_realloc(f, newlen);
    59 
    60   /* Set attributes */
    61   if (a) {
    62     memset(attrbuff,0,6);
    63     g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);
    64     strcat(f->textbuff, attrbuff);     
    65   }
    66   if (fg) {
    67     memset(attrbuff,0,6);
    68     g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);
    69     strcat(f->textbuff, attrbuff);     
    70   }
    71   if (bg) {
    72     memset(attrbuff,0,6);
    73     g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);
    74     strcat(f->textbuff, attrbuff);     
    75   }
    7693 
    7794  strcat(f->textbuff, text);
    78 
    79   /* Reset attributes */
    80   if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
    81   if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
    82   if (a)  strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);
     95  _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
     96  _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen);
     97  _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen);
    8398  f->textlen=newlen;
    8499}
     
    114129}
    115130
    116 /* Add the attribute 'attr' to the default atts for the text in 'f' */
    117 void owl_fmtext_addattr(owl_fmtext *f, char attr)
     131/* Add the attribute 'attr' to all text in 'f' */
     132void owl_fmtext_addattr(owl_fmtext *f, int attr)
    118133{
    119134  /* add the attribute to all text */
    120   f->default_attrs |= attr;
    121 }
    122 
    123 /* Set the default foreground color for this fmtext to 'color'.
    124  * Only affects text that is colored default.
     135  int i, j;
     136
     137  j=f->textlen;
     138  for (i=0; i<j; i++) {
     139    f->fmbuff[i] |= attr;
     140  }
     141}
     142
     143/* Anywhere the color is NOT ALREDY SET, set the color to 'color'.
     144 * Other colors are left unchanged
    125145 */
    126146void owl_fmtext_colorize(owl_fmtext *f, int color)
    127147{
    128   f->default_fgcolor = color;
    129 }
    130 
    131 /* Set the default foreground color for this fmtext to 'color'.
    132  * Only affects text that is colored default.
    133  */
     148  /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
     149  int i, j;
     150
     151  j=f->textlen;
     152  for(i=0; i<j; i++) {
     153    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color;
     154  }
     155}
     156
    134157void owl_fmtext_colorizebg(owl_fmtext *f, int color)
    135158{
    136   f->default_bgcolor = color;
    137 }
    138 
    139 /* Internal function. Parse attrbute character. */
    140 void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor) /*noproto*/
    141 {
    142   if ((c & OWL_FMTEXT_UC_ATTR) == OWL_FMTEXT_UC_ATTR) {
    143     *attr = c & OWL_FMTEXT_UC_ATTR_MASK;
    144   }
    145   else if ((c & OWL_FMTEXT_UC_FGCOLOR) == OWL_FMTEXT_UC_FGCOLOR) {
    146     *fgcolor = (c == OWL_FMTEXT_UC_FGDEFAULT
    147                 ? OWL_COLOR_DEFAULT
    148                 : c & OWL_FMTEXT_UC_COLOR_MASK);
    149   }
    150   else if ((c & OWL_FMTEXT_UC_BGCOLOR) == OWL_FMTEXT_UC_BGCOLOR) {
    151     *bgcolor = (c == OWL_FMTEXT_UC_BGDEFAULT
    152                 ? OWL_COLOR_DEFAULT
    153                 : c & OWL_FMTEXT_UC_COLOR_MASK);
    154   }
    155 }
    156 
    157 /* Internal function. Scan for attribute characters. */
    158 void _owl_fmtext_scan_attributes(owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) /*noproto*/
    159 {
    160   char *p;
    161   p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    162   while (p && p < f->textbuff + start) {
    163     _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor);
    164     p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    165   }
    166 
     159  /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */
     160  int i, j;
     161
     162  j=f->textlen;
     163  for(i=0; i<j; i++) {
     164    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color;
     165  }
     166}
    167167
    168168/* Internal function.  Append text from 'in' between index 'start' and
    169169 * 'stop' to the end of 'f'
    170170 */
    171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/
    172 {
    173   char attrbuff[6];
    174   int newlen, a = 0, fg = 0, bg = 0;
    175   char attr = 0;
    176   short fgcolor = OWL_COLOR_DEFAULT;
    177   short bgcolor = OWL_COLOR_DEFAULT;
    178 
    179   _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor);
    180   if (attr != OWL_FMTEXT_ATTR_NONE) a=1;
    181   if (fgcolor != OWL_COLOR_DEFAULT) fg=1;
    182   if (bgcolor != OWL_COLOR_DEFAULT) bg=1;
    183 
    184   /* We will reset to defaults after appending the text. We may need
    185      to set initial attributes. */
    186   newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12;
     171void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop)
     172{
     173  int newlen, i;
     174
     175  newlen=strlen(f->textbuff)+(stop-start+1);
    187176  _owl_fmtext_realloc(f, newlen);
    188177
    189   if (a) {
    190     memset(attrbuff,0,6);
    191     g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);
    192     strcat(f->textbuff, attrbuff);     
    193   }
    194   if (fg) {
    195     memset(attrbuff,0,6);
    196     g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);
    197     strcat(f->textbuff, attrbuff);     
    198   }
    199   if (bg) {
    200     memset(attrbuff,0,6);
    201     g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);
    202     strcat(f->textbuff, attrbuff);     
    203   }
    204 
    205178  strncat(f->textbuff, in->textbuff+start, stop-start+1);
    206 
    207   /* Reset attributes */
    208   strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);
    209   strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);
    210   strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);
    211 
    212179  f->textbuff[newlen]='\0';
     180  for (i=start; i<=stop; i++) {
     181    f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i];
     182    f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i];
     183    f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i];
     184  }
    213185  f->textlen=newlen;
    214186}
     
    235207char *owl_fmtext_print_plain(owl_fmtext *f)
    236208{
    237   return owl_strip_format_chars(f->textbuff);
    238 }
    239 
    240 void _owl_fmtext_wattrset(WINDOW *w, int attrs) /*noproto*/
    241 {
    242   wattrset(w, A_NORMAL);
    243   if (attrs & OWL_FMTEXT_ATTR_BOLD) wattron(w, A_BOLD);
    244   if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE);
    245   if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE);
    246 }
     209  return(owl_strdup(f->textbuff));
     210}
     211
    247212/* add the formatted text to the curses window 'w'.  The window 'w'
    248213 * must already be initiatlized with curses
    249214 */
    250 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search)
    251 {
    252   /* char *tmpbuff; */
    253   /* int position, trans1, trans2, trans3, len, lastsame; */
    254   char *s, *p;
    255   char attr;
    256   short fg, bg;
    257   int search_results, search_len;
    258  
     215void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
     216{
     217  char *tmpbuff;
     218  int position, trans1, trans2, trans3, len, lastsame;
     219
    259220  if (w==NULL) {
    260221    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
     
    262223  }
    263224
    264   search_results = (do_search
    265                     ? owl_fmtext_search(f, owl_global_get_search_string(&g))
    266                     : NULL);
    267   if (search_results) search_len = strlen(owl_global_get_search_string(&g));
    268   s = f->textbuff;
    269   /* Set default attributes. */
    270   attr = f->default_attrs;
    271   fg = f->default_fgcolor;
    272   bg = f->default_bgcolor;
    273   _owl_fmtext_wattrset(w, attr);
    274   if (owl_global_get_hascolors(&g)) {
    275     short pair;
    276     pair = owl_fmtext_get_colorpair(fg, bg);
    277     if (pair != -1) {
    278       wcolor_set(w,pair,NULL);
    279     }
    280   }
    281 
    282   /* Find next possible format character. */
    283   p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    284   while(p) {
    285     if (_owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    286       /* Deal with all text from last insert to here. */
    287       char tmp;
    288    
    289       tmp = p[0];
    290       p[0] = '\0';
    291       if (search_results) {
    292         /* Search is active, so highlight search results. */
    293         char tmp2, *ss;
    294         ss = stristr(s, owl_global_get_search_string(&g));
    295         while (ss) {
    296           /* Found search string, highlight it. */
    297 
    298           tmp2 = ss[0];
    299           ss[0] = '\0';
    300           waddstr(w, s);
    301           ss[0] = tmp2;
    302 
    303           _owl_fmtext_wattrset(w,attr ^ A_REVERSE);
    304 
    305           tmp2 = ss[search_len];
    306           ss[search_len] = '\0';
    307           waddstr(w, ss);
    308           ss[search_len] = tmp2;
    309 
    310           _owl_fmtext_wattrset(w,attr);
    311 
    312           s = ss + search_len;
    313           ss = stristr(s, owl_global_get_search_string(&g));
    314         }
    315       }
    316       /* Deal with remaining part of string. */
    317       waddstr(w, s);
    318       p[0] = tmp;
    319 
    320       /* Deal with new attributes. Initialize to defaults, then
    321          process all consecutive formatting characters. */
    322       attr = f->default_attrs;
    323       fg = f->default_fgcolor;
    324       bg = f->default_bgcolor;
    325       while (p && _owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    326         _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
    327         p = g_utf8_next_char(p);
    328       }
    329       _owl_fmtext_wattrset(w, attr | f->default_attrs);
    330       if (owl_global_get_hascolors(&g)) {
    331         if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
    332         if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
    333         short pair;
    334         pair = owl_fmtext_get_colorpair(fg, bg);
    335         if (pair != -1) {
    336           wcolor_set(w,pair,NULL);
    337         }
    338       }
    339       /* Advance to next non-formatting character. */
    340       s = p;
    341       p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    342     }
    343     else {
    344       p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    345     }
    346   }
    347   if (s) {
    348     waddstr(w, s);
    349   }
     225  tmpbuff=owl_malloc(f->textlen+10);
     226
     227  position=0;
     228  len=f->textlen;
     229  while (position<=len) {
     230    /* find the last char with the current format and color */
     231    trans1=owl_util_find_trans(f->fmbuff+position, len-position);
     232    trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position);
     233    trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position);
     234
     235    lastsame = (trans1 < trans2) ? trans1 : trans2;
     236    lastsame = (lastsame < trans3) ? lastsame : trans3;
     237    lastsame += position;
     238
     239    /* set the format */
     240    wattrset(w, A_NORMAL);
     241    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_BOLD) {
     242      wattron(w, A_BOLD);
     243    }
     244    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_REVERSE) {
     245      wattron(w, A_REVERSE);
     246    }
     247    if (f->fmbuff[position] & OWL_FMTEXT_ATTR_UNDERLINE) {
     248      wattron(w, A_UNDERLINE);
     249    }
     250
     251    /* set the color */
     252    /* warning, this is sort of a hack */
     253    if (owl_global_get_hascolors(&g)) {
     254      short fg, bg, pair;
     255      fg = f->fgcolorbuff[position];
     256      bg = f->bgcolorbuff[position];
     257
     258      pair = owl_fmtext_get_colorpair(fg, bg);
     259      if (pair != -1) {
     260        wcolor_set(w,pair,NULL);
     261      }
     262    }
     263
     264    /* add the text */
     265    strncpy(tmpbuff, f->textbuff + position, lastsame-position+1);
     266    tmpbuff[lastsame-position+1]='\0';
     267    waddstr(w, tmpbuff);
     268
     269    position=lastsame+1;
     270  }
     271  owl_free(tmpbuff);
    350272}
    351273
     
    360282 
    361283  /* find the starting line */
    362   ptr1 = in->textbuff;
    363   for (i = 0; i < aline; i++) {
    364     ptr1 = strchr(ptr1, '\n');
    365     if (!ptr1) return(-1);
    366     ptr1++;
    367   }
    368  
     284  ptr1=in->textbuff;
     285  if (aline!=0) {
     286    for (i=0; i<aline; i++) {
     287      ptr1=strchr(ptr1, '\n');
     288      if (!ptr1) return(-1);
     289      ptr1++;
     290    }
     291  }
    369292  /* ptr1 now holds the starting point */
    370293
    371294  /* copy in the next 'lines' lines */
    372   if (lines < 1) return(-1);
    373 
    374   for (i = 0; i < lines; i++) {
    375     offset = ptr1 - in->textbuff;
    376     ptr2 = strchr(ptr1, '\n');
     295  if (lines<1) return(-1);
     296
     297  for (i=0; i<lines; i++) {
     298    offset=ptr1-in->textbuff;
     299    ptr2=strchr(ptr1, '\n');
    377300    if (!ptr2) {
    378       _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) - 1);
     301      _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1);
    379302      return(-1);
    380303    }
    381     _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) + offset);
    382     ptr1 = ptr2 + 1;
     304    _owl_fmtext_append_fmtext(out, in, offset, (ptr2-ptr1)+offset);
     305    ptr1=ptr2+1;
    383306  }
    384307  return(0);
     
    392315void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    393316{
    394   char *ptr_s, *ptr_e, *ptr_c, *last;
    395   int col, st, padding, chwidth;
     317  char *ptr1, *ptr2, *last;
     318  int len, offset;
    396319
    397320  last=in->textbuff+in->textlen-1;
    398   ptr_s=in->textbuff;
    399   while (ptr_s <= last) {
    400     ptr_e=strchr(ptr_s, '\n');
    401     if (!ptr_e) {
     321  ptr1=in->textbuff;
     322  while (ptr1<=last) {
     323    ptr2=strchr(ptr1, '\n');
     324    if (!ptr2) {
    402325      /* but this shouldn't happen if we end in a \n */
    403326      break;
    404327    }
    405328   
    406     if (ptr_e == ptr_s) {
     329    if (ptr2==ptr1) {
    407330      owl_fmtext_append_normal(out, "\n");
    408       ++ptr_s;
     331      ptr1++;
    409332      continue;
    410333    }
    411334
    412     col = 0;
    413     st = 0;
    414     padding = 0;
    415     ptr_c = ptr_s;
    416     while(col <= bcol && ptr_c < ptr_e) {
    417       gunichar c = g_utf8_get_char(ptr_c);
    418       if (!_owl_fmtext_is_format_char(c)) {
    419         chwidth = wcwidth(c);
    420      
    421         if (col + chwidth > bcol)
    422           break;
    423         if (col >= acol) {
    424           if (st == 0) {
    425             ptr_s = ptr_c;
    426             padding = col - acol;
    427             ++st;
    428           }
    429         }
    430         col += chwidth;
    431         chwidth = 0;
    432       }
    433       ptr_c = g_utf8_next_char(ptr_c);
    434     }
    435     if (st) {
    436       /* lead padding */
    437       owl_fmtext_append_spaces(out, padding);
    438       if (ptr_c[0] & 0x80) {
    439         if (col + chwidth == bcol)
    440           ptr_c = g_utf8_next_char(ptr_c);
    441         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - 1 - in->textbuff);     
    442         owl_fmtext_append_normal(out, "\n");
    443       }
    444       else {
    445         _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    446       }
    447     }
    448     else {
     335    /* we need to check that we won't run over here */
     336    len=bcol-acol;
     337    if (len > (ptr2-(ptr1+acol))) {
     338      /* the whole line fits with room to spare, don't take a full 'len' */
     339      len=ptr2-(ptr1+acol);
     340    }
     341    if (len>last-ptr1) {
     342      /* the whole rest of the text fits with room to spare, adjust for it */
     343      len-=(last-ptr1);
     344    }
     345    if (len<=0) {
     346      /* saftey check */
    449347      owl_fmtext_append_normal(out, "\n");
    450     }
    451     ptr_s = g_utf8_next_char(ptr_e);
     348      ptr1=ptr2+1;
     349      continue;
     350    }
     351
     352    offset=ptr1-in->textbuff;
     353    _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len);
     354
     355    ptr1=ptr2+1;
    452356  }
    453357}
     
    477381
    478382/* set the charater at 'index' to be 'char'.  If index is out of
    479  * bounds don't do anything. If c or char at index is not ASCII, don't
    480  * do anything because it's not UTF-8 safe. */
    481 void owl_fmtext_set_char(owl_fmtext *f, int index, char ch)
     383 * bounds don't do anything */
     384void owl_fmtext_set_char(owl_fmtext *f, int index, int ch)
    482385{
    483386  if ((index < 0) || (index > f->textlen-1)) return;
    484   /* NOT ASCII*/
    485   if (f->textbuff[index] & 0x80 || ch & 0x80) return;
    486387  f->textbuff[index]=ch;
    487388}
     
    499400  dst->textlen=src->textlen;
    500401  dst->textbuff=owl_malloc(mallocsize);
     402  dst->fmbuff=owl_malloc(mallocsize);
     403  dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));
     404  dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));
    501405  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    502   dst->default_attrs = src->default_attrs;
    503   dst->default_fgcolor = src->default_fgcolor;
    504   dst->default_bgcolor = src->default_bgcolor;
     406  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
     407  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short));
     408  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short));
     409}
     410
     411/* highlight all instances of "string".  Return the number of
     412 * instances found.  This is a case insensitive search.
     413 */
     414int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string)
     415{
     416
     417  int found, len;
     418  char *ptr1, *ptr2;
     419
     420  len=strlen(string);
     421  found=0;
     422  ptr1=f->textbuff;
     423  while (ptr1-f->textbuff <= f->textlen) {
     424    ptr2=stristr(ptr1, string);
     425    if (!ptr2) return(found);
     426
     427    found++;
     428    _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE,
     429                         ptr2 - f->textbuff,
     430                         ptr2 - f->textbuff + len - 1);
     431
     432    ptr1=ptr2+len;
     433  }
     434  return(found);
    505435}
    506436
     
    510440int owl_fmtext_search(owl_fmtext *f, char *string)
    511441{
     442
    512443  if (stristr(f->textbuff, string)) return(1);
    513444  return(0);
     
    750681{
    751682  if (f->textbuff) owl_free(f->textbuff);
     683  if (f->fmbuff) owl_free(f->fmbuff);
     684  if (f->fgcolorbuff) owl_free(f->fgcolorbuff);
     685  if (f->bgcolorbuff) owl_free(f->bgcolorbuff);
    752686}
    753687
  • functions.c

    r3617286 r3617286  
    16061606          sprintf(buff, "  Field %i   : ", i+1);
    16071607         
    1608           ptr=owl_zephyr_get_field_as_utf8(n, i+1);
     1608          ptr=owl_zephyr_get_field(n, i+1);
    16091609          len=strlen(ptr);
    16101610          if (len<30) {
     
    25992599  }
    26002600  /* downcase it */
    2601   {
    2602     char *temp = g_utf8_strdown(filtname, -1);
    2603     if (temp) {
    2604       owl_free(filtname);
    2605       filtname = temp;
    2606     }
    2607   }
     2601  downstr(filtname);
    26082602  /* turn spaces, single quotes, and double quotes into dots */
    26092603  owl_text_tr(filtname, ' ', '.');
     
    30303024  char *quoted;
    30313025
    3032   buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
     3026  buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
    30333027  strcpy(buff, "class");
    30343028  if (!strcmp(class, "*")) {
     
    33343328          if (ret==0) {
    33353329            for (x=0; x<numlocs; x++) {
    3336               line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
     3330              line=malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
    33373331              tmp=short_zuser(user);
    33383332              sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
     
    34403434          _exit(127);
    34413435        }
    3442         parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1));
     3436        parsed=realloc(parsed, sizeof(*parsed) * (myargc+1));
    34433437        parsed[myargc] = NULL;
    34443438       
  • global.c

    r34509d5 rad15610  
    545545    len+=strlen(argv[i])+5;
    546546  }
    547   g->startupargs=owl_malloc(len+5);
     547  g->startupargs=malloc(len+5);
    548548
    549549  strcpy(g->startupargs, "");
  • logging.c

    r28ee32b rd0961fe  
    155155    to = owl_sprintf("jabber:%s", owl_message_get_recipient(m));
    156156  } else if (owl_message_is_type_aim(m)) {
    157     char *temp2;
    158157    temp = owl_aim_normalize_screenname(owl_message_get_recipient(m));
    159     temp2 = g_utf8_strdown(temp,-1);
    160     to = owl_sprintf("aim:%s", temp2);
    161     owl_free(temp2);
     158    downstr(temp);
     159    to = owl_sprintf("aim:%s", temp);
    162160    owl_free(temp);
    163161  } else {
     
    269267  } else if (owl_message_is_type_aim(m)) {
    270268    /* we do not yet handle chat rooms */
    271     char *normalto, *temp;
    272     temp = owl_aim_normalize_screenname(owl_message_get_sender(m));
    273     normalto = g_utf8_strdown(temp, -1);
     269    char *normalto;
     270    normalto=owl_aim_normalize_screenname(owl_message_get_sender(m));
     271    downstr(normalto);
    274272    from=frombuff=owl_sprintf("aim:%s", normalto);
    275273    owl_free(normalto);
    276     owl_free(temp);
    277274  } else if (owl_message_is_type_loopback(m)) {
    278275    from=frombuff=owl_strdup("loopback");
     
    293290
    294291  ch=frombuff[0];
    295   if (!g_ascii_isalnum(ch)) from="weird";
     292  if (!isalnum(ch)) from="weird";
    296293
    297294  for (i=0; i<len; i++) {
     
    302299
    303300  if (!personal) {
    304     if (strcmp(from, "weird")) {
    305       char* temp = g_utf8_strdown(frombuff, -1);
    306       if (temp) {
    307         owl_free(frombuff);
    308         from = frombuff = temp;
    309       }
    310     }
     301    if (strcmp(from, "weird")) downstr(from);
    311302  }
    312303
  • message.c

    r6201646 r6711361  
    7979    owl_list_append_element(&(m->attributes), pair);
    8080  }
    81   owl_pair_set_value(pair, owl_validate_or_convert(attrvalue));
     81  owl_pair_set_value(pair, owl_strdup(attrvalue));
    8282}
    8383
     
    493493{
    494494  if(m->zwriteline) owl_free(m->zwriteline);
    495   m->zwriteline=owl_strdup(line);
     495  m->zwriteline=strdup(line);
    496496}
    497497
     
    537537  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
    538538  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    539   owl_fmtext_colorize(&b, fgcolor);
    540   owl_fmtext_colorizebg(&b, bgcolor);
    541 
    542   owl_fmtext_curs_waddstr(&b, win, owl_global_is_search_active(&g));
     539  if (fgcolor!=OWL_COLOR_DEFAULT) {
     540    owl_fmtext_colorize(&b, fgcolor);
     541  }
     542  if (bgcolor!=OWL_COLOR_DEFAULT) {
     543    owl_fmtext_colorizebg(&b, bgcolor);
     544  }
     545
     546  if (owl_global_is_search_active(&g)) {
     547    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
     548  }
     549     
     550  owl_fmtext_curs_waddstr(&b, win);
    543551
    544552  owl_fmtext_free(&a);
     
    882890  }
    883891
    884   m->zwriteline=owl_strdup("");
     892  m->zwriteline=strdup("");
    885893
    886894  /* save the hostname */
     
    964972  }
    965973
    966   m->zwriteline=owl_strdup("");
     974  m->zwriteline=strdup("");
    967975
    968976  owl_message_set_body(m, "<uninitialized>");
  • owl.c

    r89f5338 r89f5338  
    4848#include <termios.h>
    4949#include <sys/stat.h>
    50 #include <locale.h>
    5150#include "owl.h"
    5251
     
    9392  debug=0;
    9493  initialsubs=1;
    95 
    96   setlocale(LC_ALL, "");
    97  
    9894  if (argc>0) {
    9995    argv++;
  • owl.h

    r9866c3a r18e28a4  
    5252#include <termios.h>
    5353#include <libfaim/aim.h>
    54 #include <wchar.h>
    5554#include "config.h"
    56 #include "glib.h"
    5755#ifdef HAVE_LIBZEPHYR
    5856#include <zephyr/zephyr.h>
     
    10098#define OWL_FMTEXT_ATTR_REVERSE   2
    10199#define OWL_FMTEXT_ATTR_UNDERLINE 4
    102 
    103 #define OWL_FMTEXT_UC_BASE 0x100000 /* Unicode Plane 16 - Supplementary Private Use Area-B*/
    104 #define OWL_FMTEXT_UC_ATTR ( OWL_FMTEXT_UC_BASE | 0x800 )
    105 #define OWL_FMTEXT_UC_ATTR_MASK 0x7
    106 #define OWL_FMTEXT_UC_COLOR_BASE ( OWL_FMTEXT_UC_BASE | 0x400 )
    107 #define OWL_FMTEXT_UC_FGCOLOR OWL_FMTEXT_UC_COLOR_BASE
    108 #define OWL_FMTEXT_UC_BGCOLOR ( OWL_FMTEXT_UC_COLOR_BASE | 0x200 )
    109 #define OWL_FMTEXT_UC_DEFAULT_COLOR 0x100
    110 #define OWL_FMTEXT_UC_FGDEFAULT ( OWL_FMTEXT_UC_FGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
    111 #define OWL_FMTEXT_UC_BGDEFAULT ( OWL_FMTEXT_UC_BGCOLOR | OWL_FMTEXT_UC_DEFAULT_COLOR )
    112 #define OWL_FMTEXT_UC_COLOR_MASK 0xFF
    113 #define OWL_FMTEXT_UC_ALLCOLOR_MASK ( OWL_FMTEXT_UC_COLOR_MASK | OWL_FMTEXT_UC_DEFAULT_COLOR | 0x200)
    114 #define OWL_FMTEXT_UC_STARTBYTE_UTF8 '\xf4'
    115 
    116 #define OWL_FMTEXT_UTF8_ATTR_NONE "\xf4\x80\xa0\x80"
    117 #define OWL_FMTEXT_UTF8_FGDEFAULT "\xf4\x80\x94\x80"
    118 #define OWL_FMTEXT_UTF8_BGDEFAULT "\xf4\x80\x96\x80"
    119 
    120 
    121 
    122100
    123101#define OWL_COLOR_BLACK     0
     
    276254  int bufflen;
    277255  char *textbuff;
    278   char default_attrs;
    279   short default_fgcolor;
    280   short default_bgcolor;
     256  char *fmbuff;
     257  short *fgcolorbuff;
     258  short *bgcolorbuff;
    281259} owl_fmtext;
    282260
  • perlconfig.c

    r5376a95 rad15610  
    5555    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
    5656    for (i=0; i<j; i++) {
    57       ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1);
     57      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1);
    5858      av_push(av_zfields, newSVpvn(ptr, strlen(ptr)));
    5959      owl_free(ptr);
  • text.c

    rdd24b6a r72db971  
    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 + wcwidth(c) > bcol) break;
    80       col += 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);
     
    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]) {
  • util.c

    r7b1d048 r89f5338  
    399399}
    400400
     401/* downcase the string 'foo' */
     402void downstr(char *foo)
     403{
     404  int i;
     405  for (i=0; foo[i]!='\0'; i++) {
     406    foo[i]=tolower(foo[i]);
     407  }
     408}
     409
    401410/* Caller must free response.
    402411 * Takes in strings which are space-separated lists of tokens
     
    437446void *owl_malloc(size_t size)
    438447{
    439   return(g_malloc(size));
     448  return(malloc(size));
    440449}
    441450
    442451void owl_free(void *ptr)
    443452{
    444   g_free(ptr);
     453  free(ptr);
    445454}
    446455
    447456char *owl_strdup(const char *s1)
    448457{
    449   return(g_strdup(s1));
     458  return(strdup(s1));
    450459}
    451460
    452461void *owl_realloc(void *ptr, size_t size)
    453462{
    454   return(g_realloc(ptr, size));
     463  return(realloc(ptr, size));
    455464}
    456465
    457466/* allocates memory and returns the string or null.
    458467 * caller must free the string.
     468 * from Linux sprintf man page.
    459469 */
    460470char *owl_sprintf(const char *fmt, ...)
    461471{
     472  int n, size = 100;
     473  char *p;
    462474  va_list ap;
    463   char *ret = NULL;
    464   va_start(ap, fmt);
    465   ret = g_strdup_vprintf(fmt, ap);
    466   va_end(ap);
    467   return ret;
    468 }
    469 
     475  if ((p = owl_malloc (size)) == NULL) return (NULL);
     476  while (1) {
     477    /* Try to print in the allocated space. */
     478    va_start(ap, fmt);
     479    n = vsnprintf (p, size, fmt, ap);
     480    va_end(ap);
     481    /* If that worked, return the string. */
     482    if (n > -1 && n < size)
     483      return p;
     484    /* Else try again with more space. */
     485    if (n > -1)    /* glibc 2.1 */
     486      size = n+1; /* precisely what is needed */
     487    else           /* glibc 2.0 */
     488      size *= 2;  /* twice the old size */
     489    if ((p = owl_realloc (p, size)) == NULL)
     490      return NULL;
     491  }
     492}
    470493
    471494/* Return the owl color associated with the named color.  Return -1
     
    753776}
    754777
    755 char * owl_get_datadir()
    756 {
    757   char * datadir = getenv("BARNOWL_DATA_DIR");
    758   if(datadir != NULL)
    759     return strchr(datadir, '=') + 1;
    760   return DATADIR;
    761 }
    762 
    763 /* Strips format characters from a valid utf-8 string. Returns the
    764    empty string if 'in' does not validate. */
    765 char * owl_strip_format_chars(char *in)
    766 {
    767   char *r;
    768   if (g_utf8_validate(in, -1, NULL)) {
    769     char *s, *p;
    770     r = owl_malloc(strlen(in)+1);
    771     r[0] = '\0';
    772     s = in;
    773     p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    774     while(p) {
    775       /* If it's a format character, copy up to it, and skip all
    776          immediately following format characters. */
    777       if (_owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    778         strncat(r, s, p-s);
    779         p = g_utf8_next_char(p);
    780         while (p && _owl_fmtext_is_format_char(g_utf8_get_char(p))) {
    781           p = g_utf8_next_char(p);
    782         }
    783         s = p;
    784         p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    785       }
    786       else {
    787         p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    788       }
    789     }
    790     if (s) strcat(r,s);
    791   }
    792   else {
    793     r = owl_strdup("");
    794   }
    795   return r;
    796 }
    797 
    798 /* If in is not UTF-8, convert from ISO-8859-1. We may want to allow
    799  * the caller to specify an alternative in the future. We also strip
    800  * out characters in Unicode Plane 16, as we use that plane internally
    801  * for formatting.
    802  */
    803 char * owl_validate_or_convert(char *in)
    804 {
    805   if (g_utf8_validate(in, -1, NULL)) {
    806     return owl_strip_format_chars(in);
    807   }
    808   else {
    809     return g_convert(in, -1,
    810                      "UTF-8", "ISO-8859-1",
    811                      NULL, NULL, NULL);
    812   }
    813 }
    814 /* Attempts to convert 'in' to ISO-8859-1. Returns that if possible,
    815    else returns UTF-8.
    816  */
    817 char * owl_get_iso_8859_1_if_possible(char *in)
    818 {
    819   char *out;
    820   if (g_utf8_validate(in, -1, NULL)) {
    821     out = g_convert(in, -1,
    822                     "ISO-8859-1", "UTF-8",
    823                     NULL, NULL, NULL);
    824     if (!out) {
    825       out = owl_strdup(in);
    826     }
    827   }
    828   else {
    829     out = owl_strdup("");
    830   }
    831   return out;
     778char * owl_get_datadir() {
     779    char * datadir = getenv("BARNOWL_DATA_DIR");
     780    if(datadir != NULL)
     781        return strchr(datadir, '=') + 1;
     782    return DATADIR;
    832783}
    833784
  • viewwin.c

    r9866c3a r8721756  
    7373  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
    7474
    75   owl_fmtext_curs_waddstr(&fm2, v->curswin, 0);
     75  owl_fmtext_curs_waddstr(&fm2, v->curswin);
    7676
    7777  /* print the message at the bottom */
  • zcrypt.c

    r34509d5 r9ceee9d  
    385385
    386386/* Build a space-separated string from argv from elements between start  *
    387  * and end - 1.  owl_malloc()'s the returned string. */
     387 * and end - 1.  malloc()'s the returned string. */
    388388char *BuildArgString(char **argv, int start, int end) {
    389389  int len = 1;
     
    397397
    398398  /* Allocate memory */
    399   result = (char *)owl_malloc(len);
     399  result = (char *)malloc(len);
    400400  if (result) {
    401401    /* Build the string */
     
    482482      /* Prepare result to be returned */
    483483      char *temp = keyfile;
    484       keyfile = (char *)owl_malloc(strlen(temp) + 1);
     484      keyfile = (char *)malloc(strlen(temp) + 1);
    485485      if (keyfile) {
    486486        strcpy(keyfile, temp);
     
    611611      }
    612612      use_buffer = TRUE;
    613       if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) {
     613      if ((inptr = inbuff = (char *)malloc(MAX_RESULT)) == NULL) {
    614614        printf("Memory allocation error\n");
    615615        return FALSE;
     
    639639      printf("Could not run zwrite\n");
    640640      if (freein && inbuff) {
    641         owl_free(inbuff);
     641        free(inbuff);
    642642      }
    643643      return(FALSE);
     
    685685
    686686  /* Free the input buffer, if necessary */
    687   if (freein && inbuff) owl_free(inbuff);
     687  if (freein && inbuff) free(inbuff);
    688688
    689689  return(!error);
  • zephyr.c

    r6201646 r50e29e3  
    354354  return(owl_strdup(""));
    355355}
    356 
    357 char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j)
    358 {
    359   int i, count, save;
    360 
    361   /* If there's no message here, just run along now */
    362   if (n->z_message_len == 0)
    363     return(owl_strdup(""));
    364 
    365   count=save=0;
    366   for (i = 0; i < n->z_message_len; i++) {
    367     if (n->z_message[i]=='\0') {
    368       count++;
    369       if (count == j) {
    370         /* just found the end of the field we're looking for */
    371         return(owl_validate_or_convert(n->z_message + save));
    372       } else {
    373         save = i + 1;
    374       }
    375     }
    376   }
    377   /* catch the last field, which might not be null terminated */
    378   if (count == j - 1) {
    379     char *tmp, *out;
    380     tmp = owl_malloc(n->z_message_len-save+5);
    381     memcpy(tmp, n->z_message+save, n->z_message_len-save);
    382     tmp[n->z_message_len-save]='\0';
    383     out = owl_validate_or_convert(tmp);
    384     owl_free(tmp);
    385     return out;
    386   }
    387 
     356#else
     357char *owl_zephyr_get_field(void *n, int j)
     358{
    388359  return(owl_strdup(""));
    389 }
    390 #else
    391 char *owl_zephyr_get_field(void *n, int j)
    392 {
    393   return(owl_strdup(""));
    394 }
    395 char *owl_zephyr_get_field_as_utf8(ZNotice_t *n, int j)
    396 {
    397   return owl_zephyr_get_field(n, j);
    398360}
    399361#endif
  • zwrite.c

    r7b1d048 r1fe100c  
    4444        break;
    4545      }
    46       z->class=owl_get_iso_8859_1_if_possible(myargv[1]);
     46      z->class=owl_strdup(myargv[1]);
    4747      myargv+=2;
    4848      myargc-=2;
     
    5252        break;
    5353      }
    54       z->inst=owl_get_iso_8859_1_if_possible(myargv[1]);
     54      z->inst=owl_strdup(myargv[1]);
    5555      myargv+=2;
    5656      myargc-=2;
     
    6060        break;
    6161      }
    62       z->realm=owl_get_iso_8859_1_if_possible(myargv[1]);
     62      z->realm=owl_strdup(myargv[1]);
    6363      myargv+=2;
    6464      myargc-=2;
     
    6868        break;
    6969      }
    70       z->zsig=owl_get_iso_8859_1_if_possible(myargv[1]);
     70      z->zsig=owl_strdup(myargv[1]);
    7171      myargv+=2;
    7272      myargc-=2;
     
    7676        break;
    7777      }
    78       z->opcode=owl_get_iso_8859_1_if_possible(myargv[1]);
     78      z->opcode=owl_strdup(myargv[1]);
    7979      myargv+=2;
    8080      myargc-=2;
     
    9393      myargv++;
    9494      myargc--;
    95       z->message=owl_get_iso_8859_1_if_possible("");
     95      z->message=owl_strdup("");
    9696      while (myargc) {
    97         z->message=owl_realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
     97        z->message=realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
    9898        strcat(z->message, myargv[0]);
    9999        strcat(z->message, " ");
     
    113113    } else {
    114114      /* anything unattached is a recipient */
    115       owl_list_append_element(&(z->recips), owl_get_iso_8859_1_if_possible(myargv[0]));
     115      owl_list_append_element(&(z->recips), strdup(myargv[0]));
    116116      myargv++;
    117117      myargc--;
     
    146146
    147147    if (zsigowlvar && *zsigowlvar) {
    148       z->zsig=owl_get_iso_8859_1_if_possible(zsigowlvar);
     148      z->zsig=owl_strdup(zsigowlvar);
    149149    } else if (zsigproc && *zsigproc) {
    150150      FILE *file;
     
    161161      if (!file) {
    162162        if (zsigzvar && *zsigzvar) {
    163           z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
     163          z->zsig=owl_strdup(zsigzvar);
    164164        }
    165165      } else {
     
    175175      }
    176176    } else if (zsigzvar) {
    177       z->zsig=owl_get_iso_8859_1_if_possible(zsigzvar);
     177      z->zsig=owl_strdup(zsigzvar);
    178178    } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
    179       z->zsig=owl_get_iso_8859_1_if_possible(pw->pw_gecos);
     179      z->zsig=strdup(pw->pw_gecos);
    180180      ptr=strchr(z->zsig, ',');
    181181      if (ptr) {
     
    218218  int i, j;
    219219  char toline[LINE];
    220   char *tmp = NULL;
    221220
    222221  if (z->message) owl_free(z->message);
     
    232231      }
    233232    }
    234     tmp = owl_get_iso_8859_1_if_possible(msg);
    235     z->message=owl_sprintf("%s\n%s", toline, tmp);
     233    z->message=owl_sprintf("%s\n%s", toline, msg);
    236234  } else {
    237     z->message=owl_get_iso_8859_1_if_possible(msg);
    238   }
    239   if (tmp) owl_free(tmp);
     235    z->message=owl_strdup(msg);
     236  }
    240237}
    241238
     
    308305{
    309306  if (z->opcode) owl_free(z->opcode);
    310   z->opcode=owl_get_iso_8859_1_if_possible(opcode);
     307  z->opcode=owl_strdup(opcode);
    311308}
    312309
Note: See TracChangeset for help on using the changeset viewer.