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 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 
00040   if ((bp == -1) || (bp == BUFSIZE)){
00041     bp=0;
00042     GC_REGION(read(fd, &buf[0], BUFSIZE););
00043   }
00044   c=buf[bp];
00045   bp++;
00046   return(c);
00047 }
00048 
00049 static int COMPARE_STRING(str)
00050 char *str;
00051 {
00052   int mode=0;
00053 
00054   if ((str[0] == 't') && (str[1] == 't'))
00055     mode=1;
00056   if ((str[0] == 'e') && (str[1] == 'm'))
00057     mode=2;
00058   if ((str[0] == 'i') && (str[1] == 't'))
00059     mode=2;
00060   if ((str[0] == 'b') && (str[1] == 'f'))
00061     mode=3;
00062   return(mode);
00063 }
00064 
00065 /* (read-tex fp) */
00066 static pointer READ_TEX(ctx, n,argv)
00067 context *ctx;
00068 int n;
00069 pointer argv[];
00070 { register int i,j, fd;
00071   int brace=1, bslash=0, brace2=0, emphasis=0, kanji=0, mode;
00072   off_t  offset;
00073   pointer fp, s;
00074   char *sp, c, *ch;
00075   static char str[CHAR_SIZE], cmd[10];
00076 
00077   ckarg(2);
00078   fp=argv[0];
00079   offset=(off_t)ckintval(argv[1]);
00080   fd=intval(fp->c.fstream.fd);
00081   if (offset >= 0){
00082     bp=-1;
00083     lseek( fd, offset, 0);
00084   }
00085 
00086   for(;(c=READ_CHAR(fd)) != '{';);
00087   for(sp=&str[0],j=0;brace != 0;){
00088     c=READ_CHAR(fd);
00089     if (kanji != 0){
00090       *sp++=c;
00091       if ( c == 27 ){
00092         for(i=0;i<2;i++){ c=READ_CHAR(fd); *sp++=c;}
00093         kanji=0;
00094       }
00095     }
00096     else if (bslash != 0){
00097       switch(c){
00098           case '>' : for(i=0; i<3; i++) *sp++=' ';
00099           case '=' : bslash=0; break;
00100           case '^' : ;
00101           case '~' : ;
00102           case '_' : ;
00103           case '%' : ;
00104           case '&' : ;
00105           case '#' : *sp++=c; bslash=0; break;
00106           case '\\': *sp++=0x0a; bslash=0; break;
00107           case ' ' : if ((mode=COMPARE_STRING(cmd)) != 0){
00108                         switch(mode){
00109                           case 1 : ch=us; break;
00110                           case 2 : ch=so; break;
00111                           case 3 : ch=md; break;
00112                           }
00113                         for(i=0;i<4;i++)
00114                           *sp++=ch[i];
00115                         emphasis=1;
00116                       }
00117                      bslash=0; break;
00118           case '$' : ;
00119           case '}' : if (j == 0) *sp++=c;
00120                      bslash=0; break;
00121           case '[' : j=0; break;
00122           case '{' : if (j == 0) {*sp++='{'; bslash=0; break;}
00123                      j=0; break;
00124           case ']' : for(i=0;i<4;i++) *sp++=' ';
00125                      for(i=0;i<j;i++) *sp++=cmd[i];
00126                      bslash=0;
00127                      brace2=1;
00128                      break;
00129           default  : cmd[j++]=c; break;
00130           }
00131         }
00132     else {
00133       switch(c){
00134           case '$' : break;
00135           case '\\': bslash=1; j=0; break;
00136           case '{' : brace++; break;
00137           case '}' : if (emphasis != 0){
00138                        for(i=0;i<3;i++) *sp++=ue[i];
00139                        emphasis=0;
00140                      }
00141                      brace--; break;
00142           case '%' : while ((c=READ_CHAR(fd)) != 10); break;
00143           case 10  : if (brace2 == 1) *sp++=10; else *sp++=' ';
00144                      brace2=0; break;
00145           case 27  : kanji=1; *sp++=27; break;
00146           default  : *sp++=c; break;
00147           }
00148         }
00149   }
00150   *sp=NULL;
00151   j=strlen(str);
00152   s=makestring(&str[0],j);
00153   return(s);
00154 }
00155 
00156 /*****************************************************************/
00157 /* eusmain routine                                               */
00158 /*****************************************************************/
00159 
00160 pointer helpsub(ctx,n,argv)
00161 context *ctx;
00162 int n;
00163 pointer argv[];
00164 { pointer mod=argv[0];
00165   defun(ctx, "READ-TEX", mod, READ_TEX);
00166  }


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Sep 3 2015 10:36:19