~ubuntu-branches/ubuntu/precise/xchat-gnome/precise

« back to all changes in this revision

Viewing changes to src/common/text.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-01-23 10:38:23 UTC
  • mto: (2.1.1 etch) (1.1.19 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20060123103823-qnje8vlt9kpfqsk4
Tags: upstream-0.9
ImportĀ upstreamĀ versionĀ 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
353
353
                                g_free (stamp);
354
354
                        }
355
355
                }
356
 
                temp = strip_color (text, -1, 1, 1);
 
356
                temp = strip_color (text, -1, STRIP_ALL);
357
357
                len = strlen (temp);
358
358
                write (sess->logfd, temp, len);
359
359
                /* lots of scripts/plugins print without a \n at the end */
1235
1235
        pevent_make_pntevts ();
1236
1236
}
1237
1237
 
 
1238
/*
 
1239
        CL: format_event now handles filtering of arguments:
 
1240
        1) if prefs.stripcolor is set, filter all style control codes from arguments
 
1241
        2) always strip \001 (ATTR_HIDDEN) from arguments: it is only for use in the format string itself
 
1242
*/
 
1243
#define ARG_FLAG(argn) (1 << argn)
 
1244
 
1238
1245
void
1239
 
format_event (session *sess, int index, char **args, char *o, int sizeofo)
 
1246
format_event (session *sess, int index, char **args, char *o, int sizeofo, unsigned int stripcolor_args)
1240
1247
{
1241
1248
        int len, oi, ii, numargs;
1242
1249
        char *i, *ar, d, a, done_all = FALSE;
1283
1290
                                printf ("arg[%d] is NULL in print event\n", a + 1);
1284
1291
                        } else
1285
1292
                        {
1286
 
                                len = strlen (ar);
1287
 
                                memcpy (&o[oi], ar, len);
 
1293
                                if (stripcolor_args & ARG_FLAG(a + 1)) len = strip_color2 (ar, -1, &o[oi], STRIP_ALL);
 
1294
                                else len = strip_hidden_attribute (ar, &o[oi]);
1288
1295
                                oi += len;
1289
1296
                        }
1290
1297
                        break;
1316
1323
}
1317
1324
 
1318
1325
static void
1319
 
display_event (session *sess, int event, char **args)
 
1326
display_event (session *sess, int event, char **args, unsigned int stripcolor_args)
1320
1327
{
1321
1328
        char o[4096];
1322
 
        format_event (sess, event, args, o, sizeof (o));
 
1329
        format_event (sess, event, args, o, sizeof (o), stripcolor_args);
1323
1330
        if (o[0])
1324
1331
                PrintText (sess, o);
1325
1332
}
1500
1507
        return 0;
1501
1508
}
1502
1509
 
 
1510
 
 
1511
/* black n white(0/1) are bad colors for nicks, and we'll use color 2 for us */
 
1512
/* also light/dark gray (14/15) */
 
1513
/* 5,7,8 are all shades of yellow which happen to look dman near the same */
 
1514
 
 
1515
static char rcolors[] = { 19, 20, 22, 24, 25, 26, 27, 28, 29 };
 
1516
 
 
1517
static int
 
1518
color_of (char *name)
 
1519
{
 
1520
        int i = 0, sum = 0;
 
1521
 
 
1522
        while (name[i])
 
1523
                sum += name[i++];
 
1524
        sum %= sizeof (rcolors) / sizeof (char);
 
1525
        return rcolors[sum];
 
1526
}
 
1527
 
 
1528
 
1503
1529
/* called by EMIT_SIGNAL macro */
1504
1530
 
1505
1531
void
1507
1533
{
1508
1534
        char *word[PDIWORDS];
1509
1535
        int i;
 
1536
        unsigned int stripcolor_args = (prefs.stripcolor ? 0xFFFFFFFF : 0);
 
1537
        char tbuf[NICKLEN + 4];
1510
1538
 
1511
 
        if (!a)
1512
 
                a = "\000";
1513
 
        if (!b)
1514
 
                b = "\000";
1515
 
        if (!c)
1516
 
                c = "\000";
1517
 
        if (!d)
1518
 
                d = "\000";
 
1539
        if (prefs.colorednicks && (index == XP_TE_CHANACTION || index == XP_TE_CHANMSG))
 
1540
        {
 
1541
                snprintf (tbuf, sizeof (tbuf), "\003%d%s", color_of (a), a);
 
1542
                a = tbuf;
 
1543
                stripcolor_args &= ~ARG_FLAG(1);        /* don't strip color from this argument */
 
1544
        }
1519
1545
 
1520
1546
        word[0] = te[index].name;
1521
 
        word[1] = a;
1522
 
        word[2] = b;
1523
 
        word[3] = c;
1524
 
        word[4] = d;
 
1547
        word[1] = (a ? a : "\000");
 
1548
        word[2] = (b ? b : "\000");
 
1549
        word[3] = (c ? c : "\000");
 
1550
        word[4] = (d ? d : "\000");
1525
1551
        for (i = 5; i < PDIWORDS; i++)
1526
1552
                word[i] = "\000";
1527
1553
 
1532
1558
 
1533
1559
        /* If a plugin's callback executes "/close", 'sess' may be invalid */
1534
1560
        if (is_session (sess))
1535
 
                display_event (sess, index, word);
 
1561
                display_event (sess, index, word, stripcolor_args);
1536
1562
}
1537
1563
 
1538
1564
int