Back to index

radiance  4R0+20100331
Defines | Functions | Variables
editline.c File Reference
#include "copyright.h"
#include <stdio.h>
#include <string.h>
#include "color.h"
#include "driver.h"

Go to the source code of this file.

Defines

#define iscntrl(c)   ((c) < ' ')
#define isblank(c)   ((c) == ' ')
#define iserase(c)   ((c) == '\b' || (c) == 127)
#define iswerase(c)   ((c) == 'W'-'@')
#define iskill(c)   ((c) == 'U'-'@' || (c) == 'X'-'@')

Functions

void editline (char *buf, dr_getchf_t *c_get, dr_comoutf_t *s_put)
void tocombuf (char *b, struct driver *d)
int fromcombuf (char *b, struct driver *d)

Variables

static const char RCSid [] = "$Id: editline.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $"
static char mybuf [512]

Define Documentation

#define isblank (   c)    ((c) == ' ')

Definition at line 20 of file editline.c.

#define iscntrl (   c)    ((c) < ' ')

Definition at line 19 of file editline.c.

#define iserase (   c)    ((c) == '\b' || (c) == 127)

Definition at line 21 of file editline.c.

#define iskill (   c)    ((c) == 'U'-'@' || (c) == 'X'-'@')

Definition at line 23 of file editline.c.

#define iswerase (   c)    ((c) == 'W'-'@')

Definition at line 22 of file editline.c.


Function Documentation

void editline ( char *  buf,
dr_getchf_t c_get,
dr_comoutf_t s_put 
)

Definition at line 27 of file editline.c.

{
       static char  erases[] = "\b \b";
       static char  obuf[4];
       register int  i;
       register int  c;
       
       i = 0;
       while ((c = (*c_get)()&0177) != '\n' && c != '\r')
              if (iserase(c)) {           /* single char erase */
                     if (i > 0) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iswerase(c)) {   /* word erase */
                     while (i > 0 && isblank(buf[i-1])) {
                            (*s_put)(erases);
                            --i;
                     }
                     while (i > 0 && !isblank(buf[i-1])) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iskill(c)) {            /* kill line */
                     while (i > 0) {
                            (*s_put)(erases);
                            --i;
                     }
              } else if (iscntrl(c)) {           /* control char */
                     i = 0;
                     buf[i++] = c;
                     obuf[0] = '^'; obuf[1] = c|0100; obuf[2] = '\0';
                     (*s_put)(obuf);
                     break;
              } else {                           /* regular char */
                     buf[i++] = c;
                     obuf[0] = c; obuf[1] = '\0';
                     (*s_put)(obuf);
              }
       buf[i] = '\0';
       (*s_put)("\n");
}

Here is the caller graph for this function:

int fromcombuf ( char *  b,
struct driver d 
)

Definition at line 101 of file editline.c.

{
       register char *cp;
                                          /* get next command */
       for (cp = mybuf; *cp != '\n'; cp++)
              if (!*cp)
                     return(0);
       *cp++ = '\0';
#ifdef DEBUG
       (*d->comout)(mybuf);               /* echo my command */
       (*d->comout)("\n");
#endif
                                          /* send it as reply */
       strcpy(b, mybuf);
       d->inpready--;
                                          /* advance commands */
       strcpy(mybuf, cp);
       return(1);
}

Here is the caller graph for this function:

void tocombuf ( char *  b,
struct driver d 
)

Definition at line 79 of file editline.c.

{
       register char  *cp;
       char  *comstart;

       for (cp = mybuf; *cp; cp++)
              ;
       comstart = cp;
       while ( (*cp++ = *b) )
              if (cp >= mybuf+sizeof(mybuf)) {
                     *comstart = '\0';
                     return;              /* what should I do about this? */
              } else if (*b++ == '\n') {
                     d->inpready++;
                     comstart = cp;
              }
}

Here is the caller graph for this function:


Variable Documentation

char mybuf[512] [static]

Definition at line 75 of file editline.c.

const char RCSid[] = "$Id: editline.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $" [static]

Definition at line 2 of file editline.c.