helpsub.c
Go to the documentation of this file.
00001 /* eus_help.c
00002         EusLisp interface to Eushelp
00003         1994/Jul/24
00004         (c) 1994 Nakagaki, H., KEPCO
00005 */
00006 static char *rcsid="@(#)$Id$";
00007 #include "eus.h"
00008 
00009 #pragma init (init_object_module)
00010 extern pointer helpsub();
00011 static void init_object_module()
00012   { add_module_initializer("helpsub", helpsub);}
00013 
00014 
00015 
00016 #include <sys/types.h>
00017 #include <unistd.h>
00018 
00019 #define BUFSIZE 256
00020 #define CHAR_SIZE 16384
00021 
00022 static int  bp=0;
00023 static char buf[CHAR_SIZE];
00024 static char us[4]={0x1b, 0x5b, 0x34, 0x6d},  /* underline start */
00025             ue[3]={0x1b, 0x5b, 0x6d},        /* underline end */
00026             so[4]={0x1b, 0x5b, 0x37, 0x6d},  /* highlight mode start */
00027             se[3]={0x1b, 0x5b, 0x6d},        /* highlight mode end */
00028             md[4]={0x1b, 0x5b, 0x31, 0x6d},  /* bold mode start */
00029             me[3]={0x1b, 0x5b, 0x6d};        /* bold mode end */
00030 
00031 /*****************************************************************/
00032 /* READ_TEX( fp ) : read latex file and convert to eushelp       */
00033 /*****************************************************************/
00034 
00035 static char READ_CHAR(fd)
00036 int fd;
00037 {
00038   char c;
00039   int r;
00040 
00041   if ((bp == -1) || (bp == BUFSIZE)){
00042     bp=0;
00043     GC_REGION(r=read(fd, &buf[0], BUFSIZE););
00044   }
00045   c=buf[bp];
00046   bp++;
00047   return(c);
00048 }
00049 
00050 static int COMPARE_STRING(str)
00051 char *str;
00052 {
00053   int mode=0;
00054 
00055   if ((str[0] == 't') && (str[1] == 't'))
00056     mode=1;
00057   if ((str[0] == 'e') && (str[1] == 'm'))
00058     mode=2;
00059   if ((str[0] == 'i') && (str[1] == 't'))
00060     mode=2;
00061   if ((str[0] == 'b') && (str[1] == 'f'))
00062     mode=3;
00063   return(mode);
00064 }
00065 
00066 /* (read-tex fp) */
00067 static pointer READ_TEX(ctx, n,argv)
00068 context *ctx;
00069 int n;
00070 pointer argv[];
00071 { register int i,j, fd;
00072   int brace=1, bslash=0, brace2=0, emphasis=0, kanji=0, mode;
00073   off_t  offset;
00074   pointer fp, s;
00075   char *sp, c, *ch;
00076   static char str[CHAR_SIZE], cmd[10];
00077 
00078   ckarg(2);
00079   fp=argv[0];
00080   offset=(off_t)ckintval(argv[1]);
00081   fd=intval(fp->c.fstream.fd);
00082   if (offset >= 0){
00083     bp=-1;
00084     lseek( fd, offset, 0);
00085   }
00086 
00087   for(;(c=READ_CHAR(fd)) != '{';);
00088   for(sp=&str[0],j=0;brace != 0;){
00089     c=READ_CHAR(fd);
00090     if (kanji != 0){
00091       *sp++=c;
00092       if ( c == 27 ){
00093         for(i=0;i<2;i++){ c=READ_CHAR(fd); *sp++=c;}
00094         kanji=0;
00095       }
00096     }
00097     else if (bslash != 0){
00098       switch(c){
00099           case '>' : for(i=0; i<3; i++) *sp++=' ';
00100           case '=' : bslash=0; break;
00101           case '^' : ;
00102           case '~' : ;
00103           case '_' : ;
00104           case '%' : ;
00105           case '&' : ;
00106           case '#' : *sp++=c; bslash=0; break;
00107           case '\\': *sp++=0x0a; bslash=0; break;
00108           case ' ' : if ((mode=COMPARE_STRING(cmd)) != 0){
00109                         switch(mode){
00110                           case 1 : ch=us; break;
00111                           case 2 : ch=so; break;
00112                           case 3 : ch=md; break;
00113                           }
00114                         for(i=0;i<4;i++)
00115                           *sp++=ch[i];
00116                         emphasis=1;
00117                       }
00118                      bslash=0; break;
00119           case '$' : ;
00120           case '}' : if (j == 0) *sp++=c;
00121                      bslash=0; break;
00122           case '[' : j=0; break;
00123           case '{' : if (j == 0) {*sp++='{'; bslash=0; break;}
00124                      j=0; break;
00125           case ']' : for(i=0;i<4;i++) *sp++=' ';
00126                      for(i=0;i<j;i++) *sp++=cmd[i];
00127                      bslash=0;
00128                      brace2=1;
00129                      break;
00130           default  : cmd[j++]=c; break;
00131           }
00132         }
00133     else {
00134       switch(c){
00135           case '$' : break;
00136           case '\\': bslash=1; j=0; break;
00137           case '{' : brace++; break;
00138           case '}' : if (emphasis != 0){
00139                        for(i=0;i<3;i++) *sp++=ue[i];
00140                        emphasis=0;
00141                      }
00142                      brace--; break;
00143           case '%' : while ((c=READ_CHAR(fd)) != 10); break;
00144           case 10  : if (brace2 == 1) *sp++=10; else *sp++=' ';
00145                      brace2=0; break;
00146           case 27  : kanji=1; *sp++=27; break;
00147           default  : *sp++=c; break;
00148           }
00149         }
00150   }
00151   *sp=0;
00152   j=strlen(str);
00153   s=makestring(&str[0],j);
00154   return(s);
00155 }
00156 
00157 /*****************************************************************/
00158 /* eusmain routine                                               */
00159 /*****************************************************************/
00160 
00161 pointer helpsub(ctx,n,argv)
00162 context *ctx;
00163 int n;
00164 pointer argv[];
00165 { pointer mod=argv[0];
00166   defun(ctx, "READ-TEX", mod, READ_TEX,NULL);
00167  }


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53