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


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