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


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Mar 9 2017 04:57:49