Back to index

tetex-bin  3.0
Functions
lib_slkset.c File Reference
#include <curses.priv.h>
#include <ctype.h>

Go to the source code of this file.

Functions

 slk_set (int i, const char *astr, int format)

Function Documentation

slk_set ( int  i,
const char *  astr,
int  format 
)

Definition at line 44 of file lib_slkset.c.

{
    SLK *slk = SP->_slk;
    size_t len;
    int offset;
    const char *str = astr;
    const char *p;

    T((T_CALLED("slk_set(%d, \"%s\", %d)"), i, str, format));

    if (slk == NULL || i < 1 || i > slk->labcnt || format < 0 || format > 2)
       returnCode(ERR);
    if (str == NULL)
       str = "";

    while (isspace(UChar(*str)))
       str++;               /* skip over leading spaces  */
    p = str;
    while (isprint(UChar(*p)))
       p++;                 /* The first non-print stops */

    --i;                    /* Adjust numbering of labels */

    len = (size_t) (p - str);
    if (len > (size_t) slk->maxlen)
       len = slk->maxlen;
    if (len == 0)
       slk->ent[i].ent_text[0] = 0;
    else
       strncpy(slk->ent[i].ent_text, str, len)[len] = 0;
    memset(slk->ent[i].form_text, ' ', (unsigned) slk->maxlen);
    slk->ent[i].ent_text[slk->maxlen] = 0;

    switch (format) {
    default:
    case 0:                 /* left-justified */
       offset = 0;
       break;
    case 1:                 /* centered */
       offset = (slk->maxlen - len) / 2;
       break;
    case 2:                 /* right-justified */
       offset = slk->maxlen - len;
       break;
    }
    memcpy(slk->ent[i].form_text + offset,
          slk->ent[i].ent_text,
          len);
    slk->ent[i].form_text[slk->maxlen] = 0;
    slk->ent[i].dirty = TRUE;
    returnCode(OK);
}

Here is the call graph for this function: