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.9 by greg, Thu Nov 14 02:05:09 2013 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 <stdio.h>
13 + #include <string.h>
14  
15 < editline(buf, c_get, s_put, c_erase, c_kill)    /* edit input line */
16 < char  *buf;
17 < int  (*c_get)(), (*s_put)();
18 < int  c_erase, c_kill;
15 > #include "color.h"
16 >
17 > #include "driver.h"
18 >
19 > #define iscntrl(c)      ((c) < ' ')
20 > #define isblank(c)      ((c) == ' ')
21 > #define iserase(c)      ((c) == '\b' || (c) == 127)
22 > #define iswerase(c)     ((c) == 'W'-'@')
23 > #define iskill(c)       ((c) == 'U'-'@' || (c) == 'X'-'@')
24 >
25 >
26 > void
27 > editline(       /* edit input line */
28 >        char  *buf,
29 >        dr_getchf_t *c_get,
30 >        dr_comoutf_t *s_put
31 > )
32   {
33          static char  erases[] = "\b \b";
34          static char  obuf[4];
35 <        register int  i;
36 <        register int  c;
35 >        int  i;
36 >        int  c;
37          
38          i = 0;
39          while ((c = (*c_get)()&0177) != '\n' && c != '\r')
40 <                if (c == c_erase) {             /* single char erase */
40 >                if (iserase(c)) {               /* single char erase */
41                          if (i > 0) {
42                                  (*s_put)(erases);
43                                  --i;
44                          }
45 <                } else if (c == c_kill) {       /* kill line */
45 >                } else if (iswerase(c)) {       /* word erase */
46 >                        while (i > 0 && isblank(buf[i-1])) {
47 >                                (*s_put)(erases);
48 >                                --i;
49 >                        }
50 >                        while (i > 0 && !isblank(buf[i-1])) {
51 >                                (*s_put)(erases);
52 >                                --i;
53 >                        }
54 >                } else if (iskill(c)) {         /* kill line */
55                          while (i > 0) {
56                                  (*s_put)(erases);
57                                  --i;
# Line 48 | Line 69 | int  c_erase, c_kill;
69                  }
70          buf[i] = '\0';
71          (*s_put)("\n");
72 + }
73 +
74 +
75 + static char  mybuf[512];
76 +
77 +
78 + void
79 + tocombuf(                               /* add command(s) to my buffer */
80 +        char  *b,
81 +        struct driver  *d
82 + )
83 + {
84 +        char  *cp;
85 +        char  *comstart;
86 +
87 +        for (cp = mybuf; *cp; cp++)
88 +                ;
89 +        comstart = cp;
90 +        while ( (*cp++ = *b) )
91 +                if (cp >= mybuf+sizeof(mybuf)) {
92 +                        *comstart = '\0';
93 +                        return;         /* what should I do about this? */
94 +                } else if (*b++ == '\n') {
95 +                        d->inpready++;
96 +                        comstart = cp;
97 +                }
98 + }
99 +
100 +
101 + int
102 + fromcombuf(                             /* get command from my buffer */
103 +        char  *b,
104 +        struct driver  *d
105 + )
106 + {
107 +        char    *cp, *cp1;
108 +                                                /* get next command */
109 +        for (cp = mybuf; *cp != '\n'; cp++)
110 +                if (!*cp)
111 +                        return(0);
112 +        *cp++ = '\0';
113 + #ifdef DEBUG
114 +        (*d->comout)(mybuf);                    /* echo my command */
115 +        (*d->comout)("\n");
116 + #endif
117 +                                                /* send it as reply */
118 +        strcpy(b, mybuf);
119 +        d->inpready--;
120 +                                                /* advance commands */
121 +        cp1 = mybuf;
122 +        while ((*cp1++ = *cp++))
123 +                ;
124 +        return(1);
125   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines