/* dectoch.e */
/* by D.A.Bauman on  Nov-27-1989 */
/* Modified for Epsilon V5 on Aug-16-1990 */

/* Usage: ALT(CTRL('Q')): insert graphics chars from decimal value 
    251 = û   ,   135 = ‡   ,   48 = 0   ,  etc */

/* Usage: CTRL('U') ALT(CTRL('G')): insert graphics borders from numpad:
    ÚÂ¿  7 8 9
    ÃÅ´  4 5 6
    ÀÁÙ  1 2 3
    ³Ä   0 .  */
/* Usage: CTRL('U') ALT(CTRL('T')): insert double graphics border from numpad:
    ÉË»  7 8 9
    ÌÎ¹  4 5 6
    ÈÊ¼  1 2 3
    ºÍ   0 .  */

#include "eel.h"

command dec_to_char() on reg_tab[ALT(CTRL('q'))]
{char str[80];
 int i;
 get_string(str,"Enter decimal value to insert as a char: ");
 if (*str)
  {i=strtoi(str,10);
   if (i)
    {
     bprintf("%c",i);
    }
  }
}

command select_graphics_single() on reg_tab[ALT(CTRL('g'))]
{
 select_graphics_char(1);
}

command select_graphics_double() on reg_tab[ALT(CTRL('t'))]
{
 select_graphics_char(2);
}

int _sgc_first=1;
short sp[11]= {0x5200,0x4f00,0x5000,0x5100,0x4b00,0x4c00,
               0x4d00,0x4700,0x4800,0x4900,0x5300};
 
int select_graphics_char(type) int type;
{int c,i,j,k=0;
 char *ptr;
 char *ptr1="³ÀÁÙÃÅ´ÚÂ¿Ä";
 char *ptr2="ºÈÊ¼ÌÎ¹ÉË»Í";
 if (iter>1) k=1;
 iter=1;
 if (type==1) ptr=ptr1; else ptr=ptr2;
 if (_sgc_first == 1) {_sgc_first=0; set_show_graphic();}
 refresh();
 say("Select cooresponding NUM Keypad representing outline graphics char: ");
 do
  {i=getkey();
   j=0;
   for(c=0; c<11; c++) if (sp[c]==key_code) {j=ptr[c]; break;}
   if (!j)
    {if ((i==8) || (i==127)) {backward_delete_character(); refresh();}
     else if ((i==10) || (i==13)) j=10;
     else if ((i>=' ') && (i<=254)) j=i;
/*     else if ((i>=292) && (i<=302)) j=ptr[i-292]; */ /* < EEL V5.0 */
     else if (!key_code && i==309) j=ptr[5];
     else k=0;
    }
   if (j) {bprintf("%c",j); refresh();}
   iter=1;
  }
 while(k);
 say("");
}
