doc/help.eus/helpsub.c
Go to the documentation of this file.
1 /* eus_help.c
2  EusLisp interface to Eushelp
3  1994/Jul/24
4  (c) 1994 Nakagaki, H., KEPCO
5 */
6 
7 #include "eus.h"
8 #include <sys/types.h>
9 #include <unistd.h>
10 
11 #define CHAR_SIZE 2048
12 
13 static int bp=0;
14 static char buf[CHAR_SIZE];
15 static char us[4]={0x1b, 0x5b, 0x34, 0x6d}, /* underline start */
16  ue[3]={0x1b, 0x5b, 0x6d}, /* underline end */
17  so[4]={0x1b, 0x5b, 0x37, 0x6d}, /* highlight mode start */
18  se[3]={0x1b, 0x5b, 0x6d}, /* highlight mode end */
19  md[4]={0x1b, 0x5b, 0x31, 0x6d}, /* bold mode start */
20  me[3]={0x1b, 0x5b, 0x6d}; /* bold mode end */
21 
22 /*****************************************************************/
23 /* READ_TEX( fp ) : read latex file and convert to eushelp */
24 /*****************************************************************/
25 
26 static char READ_CHAR(fd)
27 int fd;
28 {
29  char c;
30 
31  if ((bp == -1) || (bp == CHAR_SIZE)){
32  bp=0;
33  read(fd, &buf[0], CHAR_SIZE);
34  }
35  c=buf[bp];
36  bp++;
37  return(c);
38 }
39 
40 static int COMPARE_STRING(str)
41 char *str;
42 {
43  int mode=0;
44 
45  if ((str[0] == 't') && (str[1] == 't'))
46  mode=1;
47  if ((str[0] == 'e') && (str[1] == 'm'))
48  mode=2;
49  if ((str[0] == 'i') && (str[1] == 't'))
50  mode=2;
51  if ((str[0] == 'b') && (str[1] == 'f'))
52  mode=3;
53  return(mode);
54 }
55 
56 /* (read-tex fp) */
57 static pointer READ_TEX(ctx, n,argv)
58 context *ctx;
59 int n;
60 pointer argv[];
61 { register int i,j, fd;
62  int brace=1, bslash=0, brace2=0, emphasis=0, kanji=0, mode;
63  off_t offset;
64  pointer fp, s;
65  char *sp, c, *ch;
66  static char str[CHAR_SIZE], cmd[10];
67 
68  ckarg(2);
69  fp=argv[0];
70  offset=(off_t)ckintval(argv[1]);
71  fd=intval(fp->c.fstream.fd);
72  if (offset >= 0){
73  bp=-1;
74  lseek( fd, offset, 0);
75  }
76 
77  for(;(c=READ_CHAR(fd)) != '{';);
78  for(sp=&str[0],j=0;brace != 0;){
79  c=READ_CHAR(fd);
80  if (kanji != 0){
81  *sp++=c;
82  if ( c == 27 ){
83  for(i=0;i<2;i++){ c=READ_CHAR(fd); *sp++=c;}
84  kanji=0;
85  }
86  }
87  else if (bslash != 0){
88  switch(c){
89  case '>' : for(i=0; i<3; i++) *sp++=' ';
90  case '=' : bslash=0; break;
91  case '&' : ;
92  case '#' : *sp++=c; bslash=0; break;
93  case '\\': *sp++=0x0a; bslash=0; break;
94  case ' ' : if ((mode=COMPARE_STRING(cmd)) != 0){
95  switch(mode){
96  case 1 : ch=us; break;
97  case 2 : ch=so; break;
98  case 3 : ch=md; break;
99  }
100  for(i=0;i<4;i++)
101  *sp++=ch[i];
102  emphasis=1;
103  }
104  bslash=0; break;
105  case '$' : bslash=0; break;
106  case '}' : if (j == 0) *sp++='}';
107  bslash=0; break;
108  case '[' : j=0; break;
109  case '{' : if (j == 0) {*sp++='{'; bslash=0; break;}
110  j=0; break;
111  case ']' : for(i=0;i<4;i++) *sp++=' ';
112  for(i=0;i<j;i++) *sp++=cmd[i];
113  bslash=0;
114  brace2=1;
115  break;
116  default : cmd[j++]=c; break;
117  }
118  }
119  else {
120  switch(c){
121  case '$' : break;
122  case '\\': bslash=1; j=0; break;
123  case '{' : brace++; break;
124  case '}' : if (emphasis != 0){
125  for(i=0;i<3;i++) *sp++=ue[i];
126  emphasis=0;
127  }
128  brace--; break;
129  case 10 : if (brace2 == 1) *sp++=10; else *sp++=' ';
130  brace2=0; break;
131  case 27 : kanji=1; *sp++=27; break;
132  default : *sp++=c; break;
133  }
134  }
135  }
136  *sp=NULL;
137  j=strlen(str);
138  s=makestring(&str[0],j);
139  return(s);
140 }
141 
142 /*****************************************************************/
143 /* eusmain routine */
144 /*****************************************************************/
145 
146 helpsub(ctx,n,argv)
147 context *ctx;
148 int n;
149 pointer argv[];
150 { pointer mod=argv[0];
151  defun(ctx, "READ-TEX", mod, READ_TEX);
152  }
static char buf[CHAR_SIZE]
static int bp
Definition: eus.h:522
struct filestream fstream
Definition: eus.h:404
int ch[MAXTHREAD]
Definition: eusstream.c:23
GLfloat n[6][3]
Definition: cube.c:15
static int COMPARE_STRING(char *str)
#define intval(p)
Definition: sfttest.c:1
defun("ADR_TO_STRING", mod, ADR_TO_STRING)
static char so[4]
ckarg(2)
static char se[3]
union cell::cellunion c
Definition: eus.h:379
static char me[3]
short s
Definition: structsize.c:2
static pointer READ_TEX(context *ctx, int n, argv)
helpsub(context *ctx, int n, argv)
static char us[4]
static char md[4]
pointer makestring(char *, int)
Definition: makes.c:147
#define NULL
Definition: transargv.c:8
static char READ_CHAR(int fd)
pointer fd
Definition: eus.h:284
static char ue[3]
#define CHAR_SIZE


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 20:00:44