TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

#SUBSTITUTE fails on color matches

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
nya



Joined: 25 Jun 2012
Posts: 39

PostPosted: Sat Mar 22, 2014 4:00 am    Post subject: #SUBSTITUTE fails on color matches Reply with quote

Hi!

The following:

Code:
#sub {foo} {bar}
#showme f<faa>oo


Outputs foo rather than bar, due to the color in the middle of the word "foo," even though the substitution isn't a color substitute. This seems a bit counter intuitive.

I've written up something that might resolve the issue. It involved adding the following function somewhere to act as strstr() but to also skip escape codes in the target string (I put it in vt102.c personally, when I went to test it out, but I suppose the location and its name might both be up for dispute), and then changing check_all_substitutions() to use the new function.

I've tested the code lightly, but probably not as much as it should be tested.

New function:

Code:
char *strstr_strip_vt102_codes(char *str, char *substr, int *length) {
        char *pti, *ptm;

        pti = str;
        ptm = substr;

        if (*ptm == 0) {
                return pti;
        }

        while (*str != 0) {
                while (*ptm != 0) {
                        while (skip_vt102_codes(pti))
                        {
                                pti += skip_vt102_codes(pti);
                        }

                        if (*pti != *ptm) {
                                break;
                        }

                        pti++;
                        ptm++;
                }

                if (*ptm == 0) {
                        if (length != 0) {
                                *length = pti - str;
                        }
                        return str;
                }

                pti = ++str;
                ptm = substr;
        }

        return NULL;
}


Modified check_all_substitutions()

Code:
void check_all_substitutions(struct session *ses, char *original, char *line)
{
        char match[BUFFER_SIZE], subst[BUFFER_SIZE], output[BUFFER_SIZE], *ptl, *ptm, *pto;
        struct listroot *root = ses->list[LIST_SUBSTITUTE];
        struct listnode *node;
        int l;

        for (root->update = 0 ; root->update < root->used ; root->update++)
        {
                if (check_one_regexp(ses, root->list[root->update], line, original, 0))
                {
                        node = root->list[root->update];

                        pto = original;
                        ptl = line;

                        *output = 0;

                        do
                        {
                                if (*gtd->vars[0] == 0)
                                {
                                        break;
                                }

                                strcpy(match, gtd->vars[0]);

                                substitute(ses, node->right, subst, SUB_ARG);


                                if (HAS_BIT(node->flags, NODE_FLAG_META))
                                {
                                        ptm = strstr(pto, match);

                                        l = strlen(match);
                                }
                                else {
                                        ptm = strstr_strip_vt102_codes(pto, match, &l);

                                        ptl = strstr(ptl, match) + strlen(match);
                                }

                                *ptm = 0;

                                cat_sprintf(output, "%s%s", pto, subst);

                                pto = ptm + l;

                                show_debug(ses, LIST_SUBSTITUTE, "#DEBUG SUBSTITUTE {%s} {%s}", node->left, match);
                        }
                        while (check_one_regexp(ses, node, ptl, pto, 0));

                        strcat(output, pto);

                        substitute(ses, output, original, SUB_VAR|SUB_FUN|SUB_COL|SUB_ESC);

//                      strcpy(original, output);
                }
        }
}
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sun Mar 23, 2014 6:16 pm    Post subject: Reply with quote

I've got this bookmarked in my todo list to include. Thanks. : )
Back to top
View user's profile Send private message Send e-mail
nya



Joined: 25 Jun 2012
Posts: 39

PostPosted: Sun Mar 23, 2014 10:41 pm    Post subject: Reply with quote

No problem~

It'd been bugging me that #SUBSTITUTE was failing whenever the MUD I play decided it'd be 'helpful' by coloring people's names, so I finally caved in and found out why!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group