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

#CONFIG {TAB SPLIT}

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



Joined: 25 Jun 2012
Posts: 39

PostPosted: Mon Jun 30, 2014 2:41 am    Post subject: #CONFIG {TAB SPLIT} Reply with quote

I think I remember that when the functionality for stripping certain characters from auto-tab was first implemented, people asked if it could be customized. I kind of agreed, and thought it would be nice if autotabbing could ignore any set of characters I want, since often I only care about letters or numbers.

The functionality is limited to ASCII characters (codes 33 to 127, inclusive), and things are still automatically split on spaces. It uses a bit array, so the added data to each session is 24 bytes, and look-up times should not be particularly slow - at least, it's not doing anything more complex than it already was (processing-wise, anyway - bit arrays are probably more complex of a concept than simple if statements).

I was unsure why it needed nesting capabilities, given that it would be reading from the buffer, which even if it has curly braces they should presumably not be read as tintin++ code. Likewise it does not automatically break at the command separator anymore (nor does it treat it as escapable), although the default settings stick with breaking at commas, periods, and semi-colons, so it still will under the default settings.

Code:
diff -rup tt/src/config.c tt-split/src/config.c
--- tt/src/config.c   2013-12-29 17:37:10.000000000 -0600
+++ tt-split/src/config.c   2014-06-30 02:30:59.609375000 -0500
@@ -570,3 +570,74 @@ DO_CONFIG(config_256color)
 
    return ses;
 }
+
+DO_CONFIG(config_tabstrip)
+{
+   char buf[BUFFER_SIZE], error[BUFFER_SIZE];
+   char *ptr, *erp;
+   int config[sizeof(ses->tab_strip) / sizeof(int*)] = {0};
+   int i, offset, sz;
+
+   ptr = buf;
+   erp = error;
+
+   sz = 32;
+
+   if (*arg == '\0')
+   {
+      for (i = 0; i < (sizeof(ses->tab_strip) / sizeof(*(ses->tab_strip))); i++)
+      {
+         config[i] = ses->tab_strip[i];
+
+         while ((offset = FFS_BIT(config[i])) >= 0) {
+            *ptr++ = (i * sz) + offset + 32;
+
+            DEL_BIT(config[i], 1 << offset);
+         }
+      }
+
+      *ptr = '\0';
+
+      tintin_printf(ses, "#CONFIG {TAB SPLIT}: Currently splits on the following characters: %s", buf);
+
+      return NULL;
+   }
+
+   do
+   {
+      if (*arg < 32 || *arg > 127)
+      {
+         *erp++ = *arg;
+      }
+      else
+      {
+         BITMAP_SET(config, (*arg)-32);
+      }
+   } while (*(++arg));
+
+   *erp = '\0';
+
+   if (error[0])
+   {
+      tintin_printf(ses, "#ERROR: #CONFIG {TAB SPLIT}: INVALID BREAKING CHARACTERS: %s.", error);
+
+      return NULL;
+   }
+
+   for (i = 0; i < (sizeof(ses->tab_strip) / sizeof(*(ses->tab_strip))); i++)
+   {
+      ses->tab_strip[i] = config[i];
+
+      while ((offset = FFS_BIT(config[i])) >= 0) {
+         *ptr++ = (i * sz) + offset + 32;
+
+         DEL_BIT(config[i], 1 << offset);
+      }
+   }
+
+   *ptr = '\0';
+
+   update_node_list(ses->list[LIST_CONFIG], config_table[index].name, buf, "");
+
+   return ses;
+}
diff -rup tt/src/cursor.c tt-split/src/cursor.c
--- tt/src/cursor.c   2013-12-29 17:37:10.000000000 -0600
+++ tt-split/src/cursor.c   2014-06-30 01:51:44.187500000 -0500
@@ -1162,7 +1162,7 @@ int cursor_tab_add(int input_now, int st
 int cursor_auto_tab_add(int input_now, int stop_after_first)
 {
    char tab[BUFFER_SIZE], buf[BUFFER_SIZE];
-   int scroll_cnt, line_cnt, tab_len;
+   int scroll_cnt, line_cnt;
    char *arg;
 
    line_cnt = 0;
@@ -1201,19 +1201,10 @@ int cursor_auto_tab_add(int input_now, i
 
       while (*arg)
       {
-         arg = get_arg_stop_spaces(gtd->ses, arg, tab, 0);
+         arg = get_arg_stop_split(gtd->ses, arg, tab);
 
          if (!strncmp(tab, &gtd->input_buf[input_now], strlen(&gtd->input_buf[input_now])))
          {
-            tab_len = strlen(tab) -1;
-
-            if (tab_len > 0)
-            {
-               if (tab[tab_len] == '.' || tab[tab_len] == ',' || tab[tab_len] == ';')
-               {
-                  tab[tab_len] = 0;
-               }
-            }
 
             if (search_node_list(gtd->ses->list[LIST_TABCYCLE], tab))
             {
diff -rup tt/src/main.c tt-split/src/main.c
--- tt/src/main.c   2013-12-29 17:37:10.000000000 -0600
+++ tt-split/src/main.c   2014-06-30 00:58:25.250000000 -0500
@@ -382,6 +382,7 @@ void init_tintin(int greeting)
    do_configure(gts, "{VERBOSE}           {OFF}");
    do_configure(gts, "{WORDWRAP}           {ON}");
    do_configure(gts, "{256 COLORS}       {AUTO}");
+   do_configure(gts, "{TAB STRIP}         {.,;}");
 
    gts->input_level--;
 
diff -rup tt/src/parse.c tt-split/src/parse.c
--- tt/src/parse.c   2014-06-30 01:53:24.703125000 -0500
+++ tt-split/src/parse.c   2014-06-30 01:55:53.609375000 -0500
@@ -494,6 +494,45 @@ char *get_arg_stop_spaces(struct session
 
    return pti;
 }
+/*
+   get one arg, stop at spaces or split characters
+*/
+
+char *get_arg_stop_split(struct session *ses, char *string, char *result)
+{
+   char *pto, *pti;
+
+   pti = space_out(string);
+   pto = result;
+
+   while (*pti)
+   {
+      if (HAS_BIT(ses->flags, SES_FLAG_BIG5) && *pti & 128 && pti[1] != 0)
+      {
+         *pto++ = *pti++;
+         *pto++ = *pti++;
+         continue;
+      }
+
+      else if (isspace((int) *pti))
+      {
+         pti++;
+         break;
+      }
+      else if (*pti > 32 && *pti < 128)
+      {
+         if (BITMAP_GET(ses->tab_strip, *pti - 32))
+         {
+            pti++;
+            break;
+         }
+      }
+      *pto++ = *pti++;
+   }
+   *pto = '\0';
+
+   return pti;
+}
 
 /*
    advance ptr to next none-space
diff -rup tt/src/session.c tt-split/src/session.c
--- tt/src/session.c   2013-12-29 17:37:10.000000000 -0600
+++ tt-split/src/session.c   2014-06-30 00:50:52.765625000 -0500
@@ -224,6 +224,11 @@ struct session *new_session(struct sessi
    newsession->telopts       = gts->telopts;
    newsession->auto_tab      = gts->auto_tab;
 
+   for (cnt = 0 ; cnt < (sizeof(gts->tab_strip) / sizeof(*(gts->tab_strip))) ; cnt++)
+   {
+      newsession->tab_strip[cnt] = gts->tab_strip[cnt];
+   }
+
    newsession->cmd_color     = strdup(gts->cmd_color);
 
    newsession->read_max      = gts->read_max;
diff -rup tt/src/tables.c tt-split/src/tables.c
--- tt/src/tables.c   2013-12-29 17:37:10.000000000 -0600
+++ tt-split/src/tables.c   2014-06-30 00:57:58.515625000 -0500
@@ -333,6 +333,13 @@ struct config_type config_table[] =
    },
 
    {
+      "TAB STRIP",
+      "",
+      "Set of characters to strip when using auto tabs",
+      config_tabstrip
+   },
+
+   {
       "",
       "",
       0,
diff -rup tt/src/tintin.h tt-split/src/tintin.h
--- tt/src/tintin.h   2014-06-30 01:52:46.750000000 -0500
+++ tt-split/src/tintin.h   2014-06-30 01:53:44.968750000 -0500
@@ -522,6 +522,20 @@ enum operators
 #define FFS_BIT(bitvector)        ((ffs(bitvector) - 1))
 
 /*
+   Bit array operations
+*/
+
+#define BITMAP_IND(bit, sz)       ((bit) >> ((sz)+1))
+#define BITMAP_MAX(sz)            ((1 << ((sz)+1)) - 1)
+#define BITMAP_BIT(bit, sz)       (1 << ((bit) & BITMAP_MAX(sz)))
+#define BITMAP_SZ(bm)             (sizeof(*(bm)))
+#define BITMAP_GEL(bm, bit, sz)       ((bm)[BITMAP_IND((bit), (sz))])
+#define BITMAP_DO(bm, bit, op, sz) \
+   (BITMAP_GEL((bm), (bit), (sz)) op BITMAP_BIT((bit), (sz)))
+#define BITMAP_GET(bm, bit)       (BITMAP_DO((bm), (bit), &, BITMAP_SZ(bm)))
+#define BITMAP_SET(bm, bit)       (BITMAP_DO((bm), (bit), |=, BITMAP_SZ(bm)))
+
+/*
    Generic
 */
 
@@ -620,6 +634,7 @@ struct session
    int                     telopts;
    int                     telopt_flag[8];
    int                     flags;
+   int                     tab_strip[3];
    char                  * host;
    char                  * ip;
    char                  * port;
@@ -1327,6 +1342,7 @@ extern DO_CONFIG(config_mccp);
 extern DO_CONFIG(config_autotab);
 extern DO_CONFIG(config_charset);
 extern DO_CONFIG(config_256color);
+extern DO_CONFIG(config_tabstrip);
 
 #endif
 
@@ -1693,6 +1709,7 @@ extern char *get_arg_in_braces(struct se
 extern char *sub_arg_in_braces(struct session *ses, char *string, char *result, int flag, int sub);
 extern char *get_arg_with_spaces(struct session *ses, char *string, char *result, int flag);
 extern char *get_arg_stop_spaces(struct session *ses, char *string, char *result, int flag);
+extern char *get_arg_stop_split(struct session *ses, char *string, char *result);
 extern char *space_out(char *string);
 extern char *get_arg_to_brackets(struct session *ses, char *string, char *result);
 extern char *get_arg_at_brackets(struct session *ses, char *string, char *result);
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Mon Jun 30, 2014 7:05 am    Post subject: Reply with quote

Will have to give this some thought. Trying to avoid adding features that nobody will use.
Back to top
View user's profile Send private message Send e-mail
nya



Joined: 25 Jun 2012
Posts: 39

PostPosted: Mon Jun 30, 2014 8:35 pm    Post subject: Reply with quote

Fair enough.

That said, after I posted that, I realized that what I really wanted wasn't a way to specify which characters to stop autotab on, but a way to specify which characters to include in autotab. That might be a more intuitive configuration option.

(Actually, if you want to go with that, just say so and I can rewrite the patch to work like that, probably with ranges too when you're configuring it, so you can say #CONFIG {AUTOTAB} {-a-zA-Z0-9} to mean to include hyphen, letters (capital or not), and numbers.)
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 -> Development 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