--- xmessage.c.old Fri Oct 8 05:47:42 1999 +++ xmessage.c Fri Oct 8 05:47:16 1999 @@ -29,6 +29,7 @@ */ +#include #include #include #include @@ -163,6 +164,60 @@ exit(default_exitstatus); } +/* Convert tabs to spaces in *messagep,*lengthp, copying to a new block of + memory. */ +void +detab (char **messagep, int *lengthp) +{ + int i, n, col, psize; + char *p; + + /* count how many tabs there are */ + n = 0; + for (i = 0; i < *lengthp; i++) + if ((*messagep)[i] == '\t') + n++; + + /* length increases by at most seven extra spaces for each tab */ + psize = *lengthp + n*7 + 1; + p = XtMalloc (psize); + + /* convert tabs to spaces, copying into p */ + n = 0; + col = 0; + for (i = 0; i < *lengthp; i++) + { + switch ((*messagep)[i]) { + case '\n': + p[n++] = '\n'; + col = 0; + break; + case '\t': + do + { + p[n++] = ' '; + col++; + } + while ((col % 8) != 0); + break; + default: + p[n++] = (*messagep)[i]; + col++; + break; + } + } + + assert (n < psize); + + /* null-terminator needed by Label widget */ + p[n] = '\0'; + + free (*messagep); + + *messagep = p; + *lengthp = n; +} + static XtActionsRec actions_list[] = { {"exit", exit_action}, {"default-exit", default_exit_action}, @@ -240,6 +295,8 @@ XtAppAddActions(app_con, actions_list, XtNumber(actions_list)); XtOverrideTranslations(top, XtParseTranslationTable(top_trans)); + + detab (&message_str, &message_len); /* * create the query form; this is where most of the real work is done