ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/editline.c
(Generate patch)

Comparing ray/src/rt/editline.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:22 1989 UTC vs.
Revision 2.5 by greg, Tue Feb 25 02:47:22 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  editline.c - routine for editing raw input for rview.
6   *
7 < *      10/5/88
7 > *  External symbols declared in driver.h
8   */
9  
10 < #include  <ctype.h>
10 > #include "copyright.h"
11  
12 + #include "color.h"
13  
14 < editline(buf, c_get, s_put, c_erase, c_kill)    /* edit input line */
14 > #include "driver.h"
15 >
16 > #define iscntrl(c)      ((c) < ' ')
17 > #define isblank(c)      ((c) == ' ')
18 > #define iserase(c)      ((c) == '\b' || (c) == 127)
19 > #define iswerase(c)     ((c) == 'W'-'@')
20 > #define iskill(c)       ((c) == 'U'-'@' || (c) == 'X'-'@')
21 >
22 >
23 > void
24 > editline(buf, c_get, s_put)     /* edit input line */
25   char  *buf;
26 < int  (*c_get)(), (*s_put)();
27 < int  c_erase, c_kill;
26 > int  (*c_get)();
27 > void  (*s_put)();
28   {
29          static char  erases[] = "\b \b";
30          static char  obuf[4];
# Line 25 | Line 33 | int  c_erase, c_kill;
33          
34          i = 0;
35          while ((c = (*c_get)()&0177) != '\n' && c != '\r')
36 <                if (c == c_erase) {             /* single char erase */
36 >                if (iserase(c)) {               /* single char erase */
37                          if (i > 0) {
38                                  (*s_put)(erases);
39                                  --i;
40                          }
41 <                } else if (c == c_kill) {       /* kill line */
41 >                } else if (iswerase(c)) {       /* word erase */
42 >                        while (i > 0 && isblank(buf[i-1])) {
43 >                                (*s_put)(erases);
44 >                                --i;
45 >                        }
46 >                        while (i > 0 && !isblank(buf[i-1])) {
47 >                                (*s_put)(erases);
48 >                                --i;
49 >                        }
50 >                } else if (iskill(c)) {         /* kill line */
51                          while (i > 0) {
52                                  (*s_put)(erases);
53                                  --i;
# Line 48 | Line 65 | int  c_erase, c_kill;
65                  }
66          buf[i] = '\0';
67          (*s_put)("\n");
68 + }
69 +
70 +
71 + static char  mybuf[512];
72 +
73 +
74 + void
75 + tocombuf(b, d)                          /* add command(s) to my buffer */
76 + register char  *b;
77 + register struct driver  *d;
78 + {
79 +        register char  *cp;
80 +        char  *comstart;
81 +
82 +        for (cp = mybuf; *cp; cp++)
83 +                ;
84 +        comstart = cp;
85 +        while (*cp++ = *b)
86 +                if (cp >= mybuf+sizeof(mybuf)) {
87 +                        *comstart = '\0';
88 +                        return;         /* what should I do about this? */
89 +                } else if (*b++ == '\n') {
90 +                        d->inpready++;
91 +                        comstart = cp;
92 +                }
93 + }
94 +
95 +
96 + int
97 + fromcombuf(b, d)                        /* get command from my buffer */
98 + char  *b;
99 + struct driver  *d;
100 + {
101 +        register char   *cp;
102 +                                                /* get next command */
103 +        for (cp = mybuf; *cp != '\n'; cp++)
104 +                if (!*cp)
105 +                        return(0);
106 +        *cp++ = '\0';
107 + #ifdef DEBUG
108 +        (*d->comout)(mybuf);                    /* echo my command */
109 +        (*d->comout)("\n");
110 + #endif
111 +                                                /* send it as reply */
112 +        strcpy(b, mybuf);
113 +        d->inpready--;
114 +                                                /* advance commands */
115 +        strcpy(mybuf, cp);
116 +        return(1);
117   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines