home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / fed / part01 < prev    next >
Encoding:
Text File  |  1993-09-07  |  53.4 KB  |  1,502 lines

  1. Newsgroups: comp.sources.misc
  2. From: masrich@ubvmsb.cc.buffalo.edu (Richard Wicks)
  3. Subject: v39i075:  fed - Font Editor for use with VT320 and VT220 terminals, v2.0, Part01/02
  4. Message-ID: <csm-v39i075=fed.084751@sparky.Sterling.COM>
  5. X-Md4-Signature: 1bdf04748cf862657b18b238126d8982
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: University at Buffalo
  8. Date: Tue, 7 Sep 1993 13:48:47 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: masrich@ubvmsb.cc.buffalo.edu (Richard Wicks)
  12. Posting-number: Volume 39, Issue 75
  13. Archive-name: fed/part01
  14. Environment: vt320/220, VMS, UNIX
  15.  
  16. This program is a font editor for use with VT320 and VT220 Digital
  17. terminals (or compatibles).  About a year ago, I posted a similar program
  18. called fed, not surprisingly, this is called fed2.  The files this program
  19. produces can be viewed on a VT320 (in VT320 mode) or a VT220 (in VT220 mode)
  20. by typing the output file to the screen.  If you are interested, there are
  21. several example fonts included.  Fonts for 220 terminals are *_200.fnt and
  22. fonts for 320 terms are *_300.fnt.
  23.  
  24. NOTE:  fonts built for 320 terminals cannot be views on 220's!
  25.  
  26. I originally wrote this program on a VAX/VMS system, and I used conventions 
  27. from that operating system.  The one convention that unix users will probably 
  28. not be familiar with is that FED backs up files by saving every keystroke you 
  29. make to a journal file.  If the system crashes, you can recover the program 
  30. with fed -r {filename}.  Journal files are deleted if you successfully save 
  31. a file, or if you quit from editing a file. 
  32.  
  33. The default extension for font files (with fed) is .fnt.  Another nice 
  34. feature (I think) for FED2.0 is that it can read (to a limited extent) 
  35. pre-existing files created with other programs (or *gasp* by hand).  
  36. Read for_programmers.txt before attempting to alter a pre-existing font 
  37. NOT created with fed.
  38.  
  39. If you have a mind to, Fed2.0 will compile nicely on a VMS system.
  40. It needs to be setup as a symbol, or it will not function.
  41.  
  42. Also, there is another utility included called convert.c, it will
  43. do CRUDE conversions from VT320 to VT220 terminals and vice-versa.
  44. Understandably, the conversion from 220 to 320 is much better.  There is
  45. not a makefile included for this since it is very easy to compile
  46.  
  47. Once you have compiled fed, do fed -h for a list of switches.  The
  48. program has ample online help I will not waste time repeating it here.
  49.  
  50.                                                         Thanks,
  51.                                                         Rich
  52. - ------------------------------ cut here ------------------------------
  53. #! /bin/sh
  54. # This is a shell archive.  Remove anything before this line, then feed it
  55. # into a shell via "sh file" or similar.  To overwrite existing files,
  56. # type "sh file -c".
  57. # Contents:  convert.c escape.h fed2.c shift.c
  58. # Wrapped by kent@sparky on Tue Sep  7 08:40:03 1993
  59. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  60. echo If this archive is complete, you will see the following message:
  61. echo '          "shar: End of archive 1 (of 2)."'
  62. if test -f 'convert.c' -a "${1}" != "-c" ; then 
  63.   echo shar: Will not clobber existing file \"'convert.c'\"
  64. else
  65.   echo shar: Extracting \"'convert.c'\" \(6034 characters\)
  66.   sed "s/^X//" >'convert.c' <<'END_OF_FILE'
  67. X/*****************************************************************************/
  68. X/* this program does a VERY basic conversion from VT220 fonts to VT320 fonts */
  69. X/* and vice-versa.  On the VMS systems, this program has to be setup as a    */
  70. X/* symbol for use.  It will compile on Unix, and use is self explainitory    */
  71. X/* once you run it.                                 -Rich                    */
  72. X/*****************************************************************************/
  73. X#include <stdio.h>
  74. X
  75. X#define VT320_SS "\033P1;0;1;15;1;2;12;0;{.A" /* first line of vt320 file  */
  76. X#define VT220_SS "\033P1;0;1;4;1;1;{.A"       /* first line of vt220 file  */
  77. X#define WIDTH 15
  78. X
  79. X/*****************************************************************************/
  80. X/* This routine reads a character and puts into a binary format              */
  81. X/* If the end of file is reached or the escape character if found, this      */
  82. X/* function returns 0 and the program is exited.                             */
  83. X/* a = address where binary sequence is to be stored                         */
  84. X/* fp = file from which sixel bit character is obtained                      */
  85. X/* width = width of character                                                */
  86. X/*****************************************************************************/
  87. Xint read_character (a,fp,width)
  88. X    char *a;
  89. X    FILE *fp;
  90. X    int width;
  91. X{
  92. X  char in_char;
  93. X  int i;
  94. X
  95. X  for (i=0;i<(2*width);i++)
  96. X  { a[i] = 0;
  97. X  }
  98. X
  99. X  i = 0;
  100. X  while ((in_char=fgetc(fp)) != ';')
  101. X  { switch (in_char)
  102. X    { case 033  : return 0;
  103. X      case '/'  : i = width;
  104. X      case '\n' : break; 
  105. X      default   : a[i++] = in_char-'?';
  106. X                  break;
  107. X    }
  108. X  }
  109. X  return 1;
  110. X}
  111. X
  112. X/*****************************************************************************/
  113. X/* This routine pushes a character up by 1 bit, used for conversion from 320 */
  114. X/* to 220 fonts.                                                             */
  115. X/* a = character sequence used to store character in binary form             */
  116. X/*****************************************************************************/
  117. Xvoid push_up (a)
  118. X     char *a;
  119. X{
  120. X  char *b;                 /* point used to point to lower half of character */
  121. X  int i;
  122. X  char c;
  123. X
  124. X  b = (char *)((int)a + 15);
  125. X  for (i=0;i<15;i++)
  126. X  { c = (*b & 1);
  127. X    *a /= 2;
  128. X    *b /= 2;
  129. X    c *= 32;
  130. X    *a = (*a | c);
  131. X    *a = (*a & 63);           /* this keeps only bits 1-6 */
  132. X    *b = (*b & 15);           /* this keeps only bits 1-4 */
  133. X    a++;b++;
  134. X  }
  135. X}
  136. X
  137. X/*****************************************************************************/
  138. X/* This routine outputs the sixel set that is stored in a binary sequence    */
  139. X/* a = binary sequence storing the character                                 */
  140. X/* fp = file to write sixel sequence to                                      */
  141. X/* width = width of new character                                            */
  142. X/*****************************************************************************/
  143. Xvoid write_character (a,fp,width)
  144. X     char *a;
  145. X     FILE *fp;
  146. X     int width;
  147. X{
  148. X  int i;
  149. X
  150. X  putc (';',fp);
  151. X  for (i=0;i<width;i++)
  152. X  { putc (*a+'?',fp);
  153. X    a++;
  154. X  }
  155. X  putc ('/',fp);
  156. X  for (i=0;i<width;i++)
  157. X  { putc (*a+'?',fp);
  158. X    a++;
  159. X  }
  160. X  putc ('\n',fp);
  161. X}
  162. X
  163. X/*****************************************************************************/
  164. X/* This converts a 320 sequence to a 220 sequence                            */
  165. X/* a = 320 sequence                                                          */
  166. X/*****************************************************************************/
  167. Xchar *f322 (a)
  168. X      char *a;
  169. X{
  170. X  int i;
  171. X  char b[15];
  172. X
  173. X  for (i=0;i<8;i++)
  174. X  { b[i] = *a++;
  175. X    a++;
  176. X  }
  177. X  a--;
  178. X  for (i=8;i<16;i++)
  179. X  { b[i] = *a++;
  180. X    a++;
  181. X  }
  182. X  return b;
  183. X}
  184. X
  185. Xvoid push_down (a)
  186. X     char *a;
  187. X{
  188. X  char *b;               /* pointer used to point to lower half of character */
  189. X  int i;
  190. X  char c;
  191. X
  192. X  b = (char *)((int)a + 8);
  193. X  for (i=0;i<8;i++)
  194. X  { c = (*a & 32);
  195. X    *a *= 2;
  196. X    *b *= 2;
  197. X    c /= 32;
  198. X    *b = (*b | c);
  199. X    *a = (*a & 63);           /* this keeps only bits 1-6 */
  200. X    *b = (*b & 63);           /* this keeps only bits 1-6 */
  201. X    a++;b++;
  202. X  }
  203. X}
  204. X
  205. Xchar *f223 (a)
  206. X     char *a;
  207. X{
  208. X  int i;
  209. X  char b[30];
  210. X
  211. X  for (i=0;i<15;i += 2)
  212. X  { b[i] = *a++;
  213. X    b[i+1] = b[i];
  214. X  }
  215. X  for (i=15;i<30;i += 2)
  216. X  { b[i] = *a++;
  217. X    b[i+1] = b[i];
  218. X  }
  219. X  return b;
  220. X}
  221. X
  222. Xmain (argc,argv)
  223. X      int argc;
  224. X      char *argv[];
  225. X{
  226. X  FILE *f_in;
  227. X  FILE *f_out;
  228. X  char character[2*WIDTH];
  229. X  char in_char;
  230. X  char error=0;
  231. X  char *ss;
  232. X  char *converted;
  233. X
  234. X  if (argc !=3 && argc !=4)
  235. X  { printf ("\nUsage is convert (dest) infile {outfile}\n");
  236. X    printf ("  (dest) = 2 or 3.  2 converts from 320 to 220, 3 from 220 to 320\n");
  237. X    printf ("  infile (required) = input file\n");
  238. X    printf ("  outfile (optional) = output file, defaults to stdout\n\n");
  239. X    exit (1);
  240. X  }
  241. X
  242. X  if (*argv[1] != '2' && *argv[1] != '3')
  243. X  { printf ("you must suply a destination type of 2 or 3\n");
  244. X    exit (1);
  245. X  }
  246. X
  247. X  if ((f_in = fopen (argv[2],"r")) == NULL)
  248. X  { printf ("Could not open input file\n");
  249. X    exit (1);
  250. X  }
  251. X  if (argc == 4)
  252. X  { if ((f_out = fopen (argv[3],"w")) == NULL)
  253. X    { printf ("Could not open output file\n");
  254. X      exit (1);
  255. X    }
  256. X  } else
  257. X  { f_out = stdout;
  258. X  }
  259. X
  260. X  if (*argv[1] == '2') ss = VT320_SS;
  261. X  else ss = VT220_SS;
  262. X  while ((in_char = fgetc(f_in)) != '{')
  263. X  { if ((in_char != *ss) && (!(error)))
  264. X    { printf ("Warning: Expected escape sequence at top of file not found!\n");
  265. X      error = 1;
  266. X    }
  267. X    ss++;
  268. X  }
  269. X  while (fgetc(f_in) != ';');
  270. X
  271. X  if (*argv[1] == '2')
  272. X  { fprintf (f_out,"%s\n",VT220_SS);
  273. X    while (read_character (character,f_in,15))
  274. X    { push_up (character);
  275. X      converted = f322 (character);
  276. X      write_character (converted,f_out,8);
  277. X    }
  278. X  } else
  279. X  { fprintf (f_out,"%s\n",VT320_SS);
  280. X    while (read_character (character,f_in,8))
  281. X    { push_down (character);
  282. X      converted = f223 (character);
  283. X      write_character (converted,f_out,15);
  284. X    }
  285. X  }
  286. X  fprintf (f_out,"\033\\\033).A\016\n");
  287. X  fclose (f_out);
  288. X  fclose (f_in);
  289. X}
  290. END_OF_FILE
  291.   if test 6034 -ne `wc -c <'convert.c'`; then
  292.     echo shar: \"'convert.c'\" unpacked with wrong size!
  293.   fi
  294.   # end of 'convert.c'
  295. fi
  296. if test -f 'escape.h' -a "${1}" != "-c" ; then 
  297.   echo shar: Will not clobber existing file \"'escape.h'\"
  298. else
  299.   echo shar: Extracting \"'escape.h'\" \(796 characters\)
  300.   sed "s/^X//" >'escape.h' <<'END_OF_FILE'
  301. X#define UND "\033[4m"    /* underline mode                                 */
  302. X#define REV "\033[7m"    /* reverse video mode                             */
  303. X#define OFF "\033[0m"    /* turns off attributes to character sets         */
  304. X#define VT320_SS "\033P1;0;1;15;1;2;12;0;{.A" /* first line of vt320 file  */
  305. X#define VT220_SS "\033P1;0;1;4;1;1;{.A"    /* first line of vt220 file     */
  306. X
  307. X#define CLEAR             "\033[2J\033[;H"
  308. X#define CURS_2_END        "\033[0J"
  309. X#define SINGLE_WIDTH      "\033#5"
  310. X#define DOUBLE_WIDTH      "\033#6"
  311. X#define DOUBLE_HEIGHT_1   "\033#3"
  312. X#define DOUBLE_HEIGHT_2   "\033#4"
  313. X#define CUST_OFF          "\033(B\017"
  314. X#define CUST_ON           "\033).A\016"
  315. X#define BACK              "\033[D"
  316. X#define BACK_2            "\033[2D"
  317. X#define BACK_7            "\033[7D"
  318. END_OF_FILE
  319.   if test 796 -ne `wc -c <'escape.h'`; then
  320.     echo shar: \"'escape.h'\" unpacked with wrong size!
  321.   fi
  322.   # end of 'escape.h'
  323. fi
  324. if test -f 'fed2.c' -a "${1}" != "-c" ; then 
  325.   echo shar: Will not clobber existing file \"'fed2.c'\"
  326. else
  327.   echo shar: Extracting \"'fed2.c'\" \(35324 characters\)
  328.   sed "s/^X//" >'fed2.c' <<'END_OF_FILE'
  329. X/*****************************************************************************/
  330. X/* FED Version 2.0: Created at the University of Buffalo in NY, USA,  The    */
  331. X/*                  The best of the cheapest engineering schools!            */
  332. X/*                                                                           */
  333. X/* Author:           MASRICH@ubvms.cc.buffalo.edu  (Richard Wicks)           */
  334. X/*                                                                           */
  335. X/*                   you may reach me at:                                    */
  336. X/*                                                                           */
  337. X/*                   V128LL9e@ubvms.cc.buffalo.edu                           */
  338. X/*             -or-  wicks@acsu.buffalo.edu                                  */
  339. X/*             -or-  wicks@eng.buffalo.edu                                   */
  340. X/*             -or-  wicks@cs.buffalo.edu                                    */
  341. X/*                                                                           */
  342. X/*     depending on which account they deactivate last when I graduate.      */
  343. X/*                                                                           */
  344. X/* Modification History:                                                     */
  345. X/*                                                                           */
  346. X/*   September 1993    : wrote program                                       */
  347. X/*                                                                           */
  348. X/*****************************************************************************/
  349. X#include "fed2.h"
  350. X#include "shift.h"
  351. X#include "escape.h"
  352. X
  353. Xchar character[N_CHAR][N_COL];  /* 97 characters, 30 bytes for each one    */
  354. Xint WIDTH=0;             /* Width of character, differs for 220, 320..etc  */
  355. Xint HEIGHT=0;            /* Height of character, differs for 220, 320..etc */
  356. Xint CORNER_X;            /* Position where display of character starts (X) */
  357. Xint CORNER_Y;            /* Position where display of character starts (Y) */
  358. Xchar *SS;                /* Starting string (changes according to term)    */
  359. Xchar *TT;                /* Terminal type (320,220,240,420,etc...)         */
  360. Xchar *JOURNAL_NAME;      /* name of journal file                           */
  361. Xchar RECOVER=0;          /* indicates if a file must be recovered          */
  362. XFILE *JOURNAL_P=NULL;    /* file pointer for recovering/saving .fjl files  */
  363. X
  364. X#ifdef VAX
  365. X/*****************************************************************************/
  366. X/* This is to patch a bug with VAX curses.  Vax Curses will not allow        */
  367. X/* cursor movement unless wmove() is used.  This screws up printf ().        */
  368. X/* Usage of the curses library is very limited since it cannot support the   */
  369. X/* soft fonts.                                                               */
  370. X/*****************************************************************************/
  371. Xchar get_char ()
  372. X{
  373. X  static int a;
  374. X
  375. X  if (RECOVER)
  376. X  { static char character;
  377. X    if ((character = fgetc (JOURNAL_P)) != EOF)
  378. X    { return character;
  379. X    } else
  380. X    { fclose (JOURNAL_P);
  381. X      JOURNAL_P = fopen (JOURNAL_NAME,"a");
  382. X      RECOVER = 0;
  383. X      return 0;
  384. X    }
  385. X  } else
  386. X  { smg$read_keystroke (stdkb,&a);
  387. X    if (JOURNAL_P != NULL) putc (a,JOURNAL_P);
  388. X    return (char)a;
  389. X  }
  390. X}
  391. X#else
  392. X/*****************************************************************************/
  393. X/* for UNIX use, DO NOT USE THIS PROCEDURE WITH VAX.  VAX CURSES SUCKS EVEN  */
  394. X/* _MORE_ THAN UNIX CURSES DOES!!!                                           */
  395. X/*****************************************************************************/
  396. Xchar get_char ()
  397. X{
  398. X  static char character;
  399. X
  400. X  if (RECOVER)
  401. X  { static char character;
  402. X    if ((character = fgetc (JOURNAL_P)) != EOF)
  403. X    { return character;
  404. X    } else
  405. X    { close (JOURNAL_P);
  406. X      JOURNAL_P = fopen (JOURNAL_NAME,"a");
  407. X      RECOVER = 0;
  408. X      return 0;
  409. X    }
  410. X  } else
  411. X  { character = wgetch(stdscr);
  412. X    if (JOURNAL_P != NULL)
  413. X    { putc (character,JOURNAL_P);
  414. X      fflush (JOURNAL_P);
  415. X    }
  416. X    return character;
  417. X  }
  418. X}
  419. X#endif
  420. X
  421. X/*****************************************************************************/
  422. X/* if the Character Viewer is turned off, this routine is used to reset the  */
  423. X/* character sets to XXX.                                                    */
  424. X/* a = a boolean that controlls the sending of the termintion escape sequence*/
  425. X/*****************************************************************************/
  426. Xvoid read_char_viewer (a)
  427. X     char a;
  428. X{
  429. X  if (WIDTH == VT220_WIDTH)
  430. X  { printf ("%s\n",VT220_SS);
  431. X    printf (";iiSSii/AADDAA;Fesw[MF/FB@?@BF;[KDBFM[/FMKGCEF;FM[wseF/FB@?@BF"); 
  432. X    printf (";FM[{saF/FB@?@BF;[GDFFM[/FMKGCEF;Fesw[MF/FB@?@BF");
  433. X  } else
  434. X  { printf ("%s\n",VT320_SS);
  435. X    printf (";?iiiiSSSSiiii/?IIIIDDDDIIII;_OGcQHDACHQcGO_/@ACHQcGOgcQHCA@");
  436. X    printf (";@ACHQcGOgcQHCA@/_OGcQHDACHQcGO_;_OGcQHDACHQcGO_/@ACHQcGOgcQHCA@");
  437. X    printf (";_OGcQHDACHQcGO_/@ACHQcGOgcQHCA@;@ACHQcGOgcQHCA@/_OGcQHDACHQcGO_");
  438. X    printf (";_OGcQHDACHQcGO_/@ACHQcGOgcQHCA@");
  439. X  }
  440. X  if (!(a)) printf ("\033\\");
  441. X}
  442. X
  443. X/*****************************************************************************/
  444. X/* This defines the custom character set for VT220                           */
  445. X/*****************************************************************************/
  446. Xvoid read_220_char ()
  447. X{
  448. X  read_char_viewer(1);
  449. X  printf (";;;;;;;;;;;;;;;;;;;;;;;;;;/???MAAAI;/IIIIIIII;/IIIAAAM");
  450. X  printf (";~~~???~/NNN???N;DDDCCCF/;DDDDDDDD/;???FCCCD/;???~???~/???N???N");
  451. X  printf (";/IIIIIMC;DDDDDFA?/;???AFDDD/;/???CMIII;T??@??@/D");
  452. X  printf (";T?i~}}~}/D?INNNNN;DDDDDDDD/IIIIIIII;DDDCCCF/IIIAAAM");
  453. X  printf (";???FCCCD/???MAAAI;DDDDDDDD/IIIAAAM;DDDDDDDD/???MAAAI");
  454. X  printf (";Ti?Ti?T/DA?DA?D\033\\");
  455. X}
  456. X
  457. X/*****************************************************************************/
  458. X/* This defines the custom character set for VT320                           */
  459. X/*****************************************************************************/
  460. Xvoid read_320_char ()
  461. X{
  462. X  read_char_viewer (1);
  463. X  printf (";;;;;;;;;;;;;;;;;;;;;;;;;");
  464. X  printf (";/????????wwGGGgg;/ggggggggggggggg;/ggGGGww;~~???~~/~~???~~;DDCCCFF/");
  465. X  printf (";DDDDDDDDDDDDDDD/;????????FFCCCDD/;????????~~???~~/????????~~???~~");
  466. X  printf (";/gggwO;DDDFA/;??????????AFDDD/;/??????????Owggg");
  467. X  printf (";Ti@?@?@?@?@?@iT/Ti?_?_?_?_?_?iT;Ti~}~}~}~}~}~iT/Ti^~^~^~^~^~^iT");
  468. X  printf (";DDDDDDDDDDDDDDD/ggggggggggggggg;DDCCCFF/ggGGGww");
  469. X  printf (";????????FFCCCDD/????????wwGGGgg;DDDDDDDDDDDDDDD/ggGGGww");
  470. X  printf (";DDDDDDDDDDDDDDD/????????wwGGGgg;??SiSiSiSiSiS/??TITITITITIT\033\\");
  471. X}
  472. X
  473. X/*****************************************************************************/
  474. X/* This positions the cursor.                                                */
  475. X/* a = Y position                                                            */
  476. X/* b = X position                                                            */
  477. X/*****************************************************************************/
  478. Xchar *position (a,b)
  479. X     int a;
  480. X     int b;
  481. X{
  482. X  static char ret_line[9];
  483. X
  484. X  sprintf (ret_line,"\033[%d;%dH",a,b);
  485. X  return ret_line;
  486. X}
  487. X
  488. X/*****************************************************************************/
  489. X/* This routine draws the pixel representation of a character                */
  490. X/* a = string containing binary sequence for number                          */
  491. X/*****************************************************************************/
  492. Xvoid draw (a)
  493. X     char *a;
  494. X{
  495. X  int x;
  496. X  int y;
  497. X  int bitno=1;
  498. X
  499. X  for (y=1;y<HEIGHT+1;y++)
  500. X  { printf ("%s",position(CORNER_Y+y,CORNER_X+1));
  501. X    for (x=0;x<WIDTH;x++)
  502. X    { if (a[x] & bitno)
  503. X        putc ('N',stdout);
  504. X      else
  505. X        putc ('M',stdout);
  506. X    }
  507. X    bitno *= 2;
  508. X    if (bitno > 32)
  509. X    { a = (char *)((int)a + WIDTH);
  510. X      bitno=1;
  511. X    }
  512. X  }  
  513. X}
  514. X
  515. X/*****************************************************************************/
  516. X/* This routine turns an array of characters into the most effecient string  */
  517. X/* the be used to program a character                                        */
  518. X/* a = incomming array to be converted                                       */
  519. X/* b = boolean, if set this function will optimize the string                */
  520. X/*****************************************************************************/
  521. Xchar *array_2_string(a,b)
  522. X     char *a;
  523. X     char b;
  524. X{
  525. X  static char ret_string[N_COL+3];
  526. X  static int i;
  527. X  static int width;
  528. X  static char *stroll;
  529. X
  530. X  width = -1;
  531. X  stroll = ret_string;
  532. X  *stroll++ = ';';
  533. X  if (b)
  534. X  { for (i=0;i<WIDTH;i++) if (a[i]) width=i;
  535. X  } else
  536. X  { width = WIDTH-1;
  537. X  }
  538. X  for (i=0;i<width+1;i++) *stroll++=a[i]+'?';
  539. X  *stroll++='/';
  540. X  width = -1;
  541. X  if (b)
  542. X  { for (i=WIDTH;i<(2*WIDTH);i++) if (a[i]) width=i;
  543. X  } else
  544. X  { width = (2*WIDTH)-1;
  545. X  }
  546. X  for (i=WIDTH;i<width+1;i++) *stroll++=a[i]+'?';
  547. X  *stroll = 0;
  548. X  if (ret_string[2] == 0) ret_string[1] = 0;  /* character is blank */
  549. X  return ret_string;
  550. X}
  551. X
  552. X/*****************************************************************************/
  553. X/* This routine prints out the escape sequence so that you can view the      */
  554. X/* altered character (s)                                                     */
  555. X/* first = character that is currently being edited                          */
  556. X/* viewer = byte (either 1 or 0) determines if viewer should be updated      */
  557. X/* viewer_string = character string that indicates what is in the viewer     */
  558. X/*****************************************************************************/
  559. Xvoid preview (first,viewer,view_string)
  560. X     char first;
  561. X     char viewer;
  562. X     char *view_string;
  563. X{
  564. X  static last_view;
  565. X
  566. X  printf ("%s%s",SS,array_2_string(character[first-'!']),1);
  567. X  if (viewer)
  568. X  { int j;
  569. X    if ((j = (int)strrchr(view_string,first)) || (!(last_view)))
  570. X    { j -= (int)view_string - 1;
  571. X      if (!(last_view)) j = 6;
  572. X      for (viewer=0;viewer<j;viewer++)
  573. X      { if (*view_string == ' ') putc (';',stdout);
  574. X        else printf ("%s",array_2_string(character[*view_string-'!']),1);
  575. X        view_string++;
  576. X      }
  577. X    }
  578. X  }
  579. X  printf ("\033\\");
  580. X  last_view = viewer;
  581. X}
  582. X
  583. X/*****************************************************************************/
  584. X/* Load character set into memory (if specified file exists).  Initializes   */
  585. X/* character set to blanks as well.                                          */
  586. X/* fn = file name to be retrieved (or created)                               */
  587. X/* ss = starting string expected to be found in file                         */
  588. X/*****************************************************************************/
  589. Xchar load_character_set (fn,ss)
  590. X     char *fn;
  591. X     char *ss;
  592. X{
  593. X  FILE *fp;
  594. X  int char_number;
  595. X  int element_number;
  596. X  char element;
  597. X  char quit=0;
  598. X  char start_string[80];
  599. X  char second_half=0;
  600. X
  601. X  for (char_number = 0;char_number < N_CHAR;char_number++)
  602. X  { for (element_number = 0;element_number< N_COL;element_number++)
  603. X    { character[char_number][element_number] = 0;
  604. X    }
  605. X  }
  606. X
  607. X  if ((fp = fopen (fn,"r")) == NULL)
  608. X  { if (errno == ENOENT)
  609. X    { printf ("%s: Filename %s%s%s not found, creating a new file.\n",
  610. X               NAME,UND,fn,OFF);
  611. X    } else
  612. X    { perror (fn);
  613. X      exit (1);
  614. X    }
  615. X    sleep (2);
  616. X    return 0;
  617. X  } else                /* do file conversion from characters to bits       */
  618. X  { char_number = 0;
  619. X
  620. X    while ((element = fgetc(fp)) != EOF && element != '{')
  621. X    { if (SS[char_number] != element)
  622. X      { if (!(char_number))
  623. X        { printf ("%s: This is NOT a font file.\n",NAME);
  624. X          exit (1);
  625. X        }
  626. X        printf ("WARNING: The escape sequence on line 1 does not match\n");
  627. X        printf ("         expected type!\n");
  628. X        sleep (2);
  629. X        while ((element = fgetc(fp)) != EOF && element != '{');
  630. X        ungetc (element,fp);
  631. X      }
  632. X      char_number++;
  633. X    }
  634. X    if (element != '{')
  635. X    { printf ("%s: This is NOT a font file.\n",NAME);
  636. X      exit (1);
  637. X    }
  638. X    while (fgetc(fp) != ';');            /* read Dscs, but ignore it        */
  639. X    ungetc (';',fp);                     /* backup one character            */
  640. X
  641. X    element_number = 0;
  642. X    char_number = -1;   /* the first character is space, this prog skips it */
  643. X    while ((element = fgetc(fp)) != EOF && char_number < N_CHAR)
  644. X    { switch (element)
  645. X      { case '/' : if (element_number > WIDTH)
  646. X               { printf ("Buffer overflow!\n");
  647. X                     printf ("The width of the character exceedes expected\n");
  648. X                     printf ("parameters for character %c (char number %d)\n\n",
  649. X                              char_number+'!',char_number+1);
  650. X                     quit = 1;
  651. X           }
  652. X                   second_half = 1;
  653. X                   element_number = WIDTH;
  654. X                   break;
  655. X        case ';' : element_number = 0;
  656. X                   second_half = 0;
  657. X                   char_number++;
  658. X        case '\n': break;
  659. X        default  : if (element == 033) goto escape;
  660. X                   if (!(element < '?' || element > '~'))
  661. X                   { if (element_number != 2*WIDTH)
  662. X                       character[char_number][element_number]=element-'?';
  663. X                   } else if (element_number < (2*WIDTH))
  664. X           { printf ("Illegal element \"%c\" found for character \"%c\"\n",
  665. X                              element,char_number+'!');
  666. X                     printf ("(char number %d)\n\n",char_number+1);
  667. X                     quit = 1;
  668. X           }
  669. X                   if (!(second_half))
  670. X                   { character[char_number][element_number++] &= 63;
  671. X                   } else
  672. X                   { if (WIDTH == VT220_WIDTH)
  673. X                     { character[char_number][element_number++] &= 15;
  674. X                     } else
  675. X                     { character[char_number][element_number++] &= 63;
  676. X                     }
  677. X                   }
  678. X      }
  679. X    }
  680. X  }
  681. X  escape:;
  682. X  fclose (fp);
  683. X  if (quit) exit (1);
  684. X  return 1;
  685. X}
  686. X
  687. X/*****************************************************************************/
  688. X/* This routine saves the character set to a file or to the screen           */
  689. X/* fn = filename to save character set to (if NULL it saves it to stdout)    */
  690. X/* comment = boolean, if set, it will put a comment in the font file, will   */
  691. X/*           not effect the character set, except make it slower to type to  */
  692. X/*           the screen.                                                     */
  693. X/*****************************************************************************/
  694. Xvoid save_characters (fn,comment)
  695. X     char *fn;
  696. X     char comment;
  697. X{
  698. X  int i;
  699. X  int column;
  700. X  FILE *fp;
  701. X
  702. X  if (fn == NULL) fp = stdout;
  703. X  else fp = fopen (fn,"w");
  704. X  if (fp == NULL)
  705. X  { perror (fn);
  706. X    if (JOURNAL_P == NULL)
  707. X    { printf ("Keeping journal file %s intact.\n",JOURNAL_NAME);
  708. X    } else
  709. X    { printf ("EEK! File lost, use a journal file next time!\n");
  710. X    }
  711. X    fclose (JOURNAL_P);
  712. X    exit (1);
  713. X  }
  714. X  fprintf (fp,"%s\n",SS);
  715. X  for (i=0;i<N_CHAR;i++)
  716. X  { fprintf (fp,"%s",array_2_string(character[i]),(!(comment)));
  717. X    if (comment)
  718. X    { putc (' ',fp);
  719. X      if ((i+'!') == ';') fprintf (fp,"semicolin");
  720. X      else if ((i+'!') == '/') fprintf (fp,"slash");
  721. X      else putc (i+'!',fp);
  722. X    }
  723. X    putc ('\n',fp);
  724. X  }
  725. X  fprintf (fp,"\033\\%s\n",CUST_ON);
  726. X}
  727. X
  728. X/*****************************************************************************/
  729. X/* This routine allows the user to select what is to be viewed in the Viewer */
  730. X/* a = boolean, if set it will just print the viewer, else it will program it*/
  731. X/* draw = string that will contain what is in the viewer                     */
  732. X/*****************************************************************************/
  733. Xint set_viewer (a,draw)
  734. X    char a;
  735. X    char *draw;
  736. X{
  737. X  if (!(a))
  738. X  { char mode;
  739. X    char *line;
  740. X    int x,y;
  741. X
  742. X    line = draw;
  743. X    printf ("%s%s",position(19,1),CURS_2_END);
  744. X    printf ("%sABBBBBBBBBBBBBBBBBBBBBBBBBBBBC\n",position(20,25));
  745. X    printf ("%sH %sMODE? (%sN%sormal,%sW%side,%sT%sall)   %sD\n",
  746. X             position(21,25),CUST_OFF,UND,OFF,UND,OFF,UND,OFF,CUST_ON);
  747. X    printf ("%sGFFFFFFFFFFFFFFFFFFFFFFFFFFFFE\n",position(22,25));
  748. X    printf ("%s%s",position(21,52),CUST_OFF);
  749. X    while ((mode = get_char()) != 'N' && mode != 'W' && mode != 'T' &&
  750. X           mode != 'n' && mode != 'w' && mode != 't');
  751. X    mode = toupper (mode);
  752. X    putc (mode,stdout);
  753. X    switch (mode)
  754. X    { case 'N' : a = 1;
  755. X                 break;
  756. X      case 'W' : a = 2;
  757. X                 break;
  758. X      case 'T' : a = 3;
  759. X                 break;
  760. X    }
  761. X    printf ("%s%s%s",position(19,1),CURS_2_END,CUST_ON);
  762. X    printf ("%sABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBC ABBBBBC\n",position(20,13));
  763. X    printf ("%sH %sType in the viewer characters in the Box    %sD H%s %3.3s %sD\n",position(21,13),CUST_OFF,CUST_ON,CUST_OFF,draw,CUST_ON);
  764. X    printf ("%sH %sReturn to END, Tab to SKIP, Space for Blank %sD H%s %3.3s %sD\n",position(22,13),CUST_OFF,CUST_ON,CUST_OFF,draw+3,CUST_ON);
  765. X    printf ("%sGFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE GFFFFFE%s\n",position(23,13),CUST_OFF);
  766. X    x = 63;
  767. X    y = 21;
  768. X    while (y < 23)
  769. X    { printf ("%s",position(y,x));
  770. X      mode = get_char();
  771. X      if (mode >= ' ' && mode <= '~')
  772. X      { putc (mode,stdout);
  773. X        *line = mode;
  774. X        line++; x++;
  775. X      } else
  776. X      { switch (mode)
  777. X        { case NEWLINE : y = 23;
  778. X                         break;
  779. X          case 9       : x++;
  780. X        }
  781. X      }
  782. X      if (x > 65)
  783. X      { y++;
  784. X        x = 63;
  785. X      }
  786. X    }
  787. X  }
  788. X  if (a)
  789. X  { printf ("%s%s%sLBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBI\n",position (19,1),CURS_2_END,CUST_ON);
  790. X    switch (a)
  791. X    { case 1 : printf ("%s   %s%3.3s  %s\"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$\n",SINGLE_WIDTH,CUST_OFF,draw,CUST_ON);
  792. X               printf ("%s   %s%3.3s  %s%%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'\n",SINGLE_WIDTH,CUST_OFF,draw+3,CUST_ON);
  793. X               break;
  794. X      case 2 : printf ("%s %s%3.3s  %s\"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$\n",DOUBLE_WIDTH,CUST_OFF,draw,CUST_ON);
  795. X               printf ("%s %s%3.3s  %s%%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'\n",DOUBLE_WIDTH,CUST_OFF,draw+3,CUST_ON);
  796. X               break;
  797. X      case 3 : printf ("%s %s%3.3s  %s\"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$\n",DOUBLE_HEIGHT_1,CUST_OFF,draw,CUST_ON);
  798. X               printf ("%s %s%3.3s  %s\"#$  \"#$  \"#$  \"#$  \"#$  \"#$  \"#$\n",DOUBLE_HEIGHT_2,CUST_OFF,draw,CUST_ON);
  799. X               printf ("%s %s%3.3s  %s%%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'\n",DOUBLE_HEIGHT_1,CUST_OFF,draw+3,CUST_ON);
  800. X               printf ("%s %s%3.3s  %s%%&'  %%&'  %%&'  %%&'  %%&'  %%&'  %%&'\n",DOUBLE_HEIGHT_2,CUST_OFF,draw+3,CUST_ON);
  801. X               break;
  802. X    }
  803. X    printf ("%sKFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFJ",SINGLE_WIDTH);
  804. X  }
  805. X  return a;
  806. X}
  807. X
  808. X/*****************************************************************************/
  809. X/* The routine draws the work screen                                         */
  810. X/* fn = name of file being edited                                            */
  811. X/* view = controlls how the viewer is displayed                              */
  812. X/* view_string = string of what is to be viewed                              */
  813. X/*****************************************************************************/
  814. Xvoid setup_display (fn,view,view_string)
  815. X     char *fn;
  816. X     char view;
  817. X     char *view_string;
  818. X{
  819. X  printf ("%s",CLEAR);
  820. X  if (WIDTH == VT220_WIDTH) read_220_char ();
  821. X  else read_320_char ();
  822. X  /* #5 = single width, single height */
  823. X  printf ("%sABBBBBBBBBBBBBBBC  ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBC\n",CUST_ON);
  824. X  printf ("H%sD  H %sh: move cursor left             E: edit previewer        %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTTTTTTTTTTTT",CUST_OFF,CUST_ON);
  825. X  printf ("H%sD  H %sj: move cursor down             R: toggle all bits       %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  826. X  printf ("H%sD  H %sk: move cursor up               X: flip on X axis        %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  827. X  printf ("H%sD  H %sl: move cursor right            Y: flip on Y axis        %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  828. X  printf ("H%sD  H %sH: shift object left           ^E: erase work area       %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  829. X  printf ("H%sD  H %sJ: shift object down           ^P: preview characters    %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  830. X  printf ("H%sD  H %sK: shift object up             ^I: import letter         %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  831. X  printf ("H%sD  H %sL: shift object right          ^D: save and exit         %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  832. X  printf ("H%sD  H %sQ: Quit/No save                ^V: toggle viewer         %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  833. X  printf ("H%sD  H %s<RETURN>  Save letter           <SPACE>  toggle bit      %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT",CUST_OFF,CUST_ON);
  834. X  printf ("H%sD  QOOOOOOOOOOOOOOOOOOOOOOORSOOOOORSOOOOOOOOOOOOOOOOOOOOOOOOOOP\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTMMMMMMMMTTT");
  835. X  printf ("H%sD  H                       DH %s%3.3s %sDH %sFilename: %-14.14s %sD\n",(WIDTH == VT320_WIDTH)?"MMMMMMMMMMMMMMM":"TTTTTTTTTTTTTTT",CUST_OFF,TT,CUST_ON,CUST_OFF,fn,CUST_ON);
  836. X  printf ("GFFFFFFFFFFFFFFFE  GFFFFFFFFFFFFFFFFFFFFFFFEGFFFFFEGFFFFFFFFFFFFFFFFFFFFFFFFFFE\n");
  837. X  printf ("      %sstandard width & height:          %s!!!!    !         !        !\n",CUST_OFF,CUST_ON);
  838. X  printf ("   %s%sdouble width:    %s!!  !      !\n",CUST_OFF,DOUBLE_WIDTH,CUST_ON);
  839. X  printf ("   %s%sdouble height:   %s!!  !    !   !\n",CUST_OFF,DOUBLE_HEIGHT_1,CUST_ON);
  840. X  printf ("   %s%sdouble height:   %s!!  !    !   !\n",CUST_OFF,DOUBLE_HEIGHT_2,CUST_ON);
  841. X  (void) set_viewer (view,view_string);
  842. X}
  843. X
  844. X/*****************************************************************************/
  845. X/* This gets the character to edit                                           */
  846. X/*****************************************************************************/
  847. Xchar get_char_to_edit()
  848. X{
  849. X  char char_to_edit;
  850. X
  851. X  printf ("%s%sCharacter to Edit:  %s",CUST_OFF,position(13,22),BACK);
  852. X  while ((char_to_edit = get_char() ) < '!' || char_to_edit > '~');
  853. X  printf ("%c%s",char_to_edit,CUST_ON);
  854. X  return char_to_edit;
  855. X}
  856. X
  857. X/*****************************************************************************/
  858. X/* This routine types out the character set that the user created            */
  859. X/*****************************************************************************/
  860. Xvoid preview_char_set ()
  861. X{
  862. X  char normal;
  863. X  char custom;
  864. X  int last;
  865. X
  866. X  printf ("%s%sWait... loading character set to terminal...\n",CLEAR,CUST_OFF);
  867. X  save_characters (NULL,0);
  868. X  printf ("%s",CUST_OFF);
  869. X  last = '!';
  870. X  while (last < 127)
  871. X  { for (normal = (char)last;normal<(last+20) && normal<127;normal++)
  872. X    { printf ("%c   ",normal);
  873. X    } printf ("%s\n",CUST_ON);
  874. X    for (custom = (char)last;custom<(last+20) && custom<127;custom++)  /* reg  */
  875. X    { printf ("%c   ",custom);
  876. X    } printf ("\n%s",DOUBLE_WIDTH);
  877. X    for (custom = (char)last;custom<(last+20) && custom<127;custom++)  /* wide */
  878. X    { printf ("%c ",custom);
  879. X    } printf ("\n%s",DOUBLE_HEIGHT_1);
  880. X    for (custom = (char)last;custom<(last+20) && custom<127;custom++)  /* tall */
  881. X    { printf ("%c ",custom);
  882. X    } printf ("\n%s",DOUBLE_HEIGHT_2);
  883. X    for (custom = (char)last;custom<(last+20) && custom<127;custom++)  /* tall */
  884. X    { printf ("%c ",custom);
  885. X    } printf ("\n\n");
  886. X    printf ("%sPress any key to continue...\n",CUST_OFF);
  887. X    (void) get_char();
  888. X    last = (int)normal;
  889. X  }
  890. X}
  891. X
  892. X/*****************************************************************************/
  893. X/* This edits an individual character                                        */
  894. X/* a = character to be edited                                                */
  895. X/* fn = filename being edited                                                */
  896. X/*****************************************************************************/
  897. Xchar edit_char(a,fn)
  898. X     char a;
  899. X     char *fn;
  900. X{
  901. X  char key;
  902. X  int x=1;
  903. X  int y=1;
  904. X  char bitno=1;
  905. X  static viewer_size=1;
  906. X  static char viewer_string[7]="123456";
  907. X  static viewer_on=0;
  908. X
  909. X  printf ("%s",CUST_OFF);
  910. X  if (viewer_on)
  911. X  { preview (a,1,viewer_string);
  912. X  } else
  913. X  { printf ("%son ",position(10,71));
  914. X    read_char_viewer (0);
  915. X  }
  916. X  printf ("%s",CUST_ON);
  917. X  draw (character[a-'!']);
  918. X  preview (a,viewer_on,viewer_string);
  919. X  printf ("%s",position(CORNER_Y+y,CORNER_X+x));
  920. X  while ((key = get_char()) != NEWLINE && key != 4)
  921. X  {
  922. X    switch (key)
  923. X    { case 'h' : x--;
  924. X                 if (x < 1) x = WIDTH;
  925. X                 break;
  926. X      case 'j' : y++;
  927. X                 bitno *= 2;
  928. X                 if (y > HEIGHT)
  929. X                 { y = 1;
  930. X                   bitno=1;
  931. X                 }
  932. X                 if (bitno > 32) bitno=1;
  933. X                 break;
  934. X      case 'k' : y--;
  935. X                 bitno /= 2;
  936. X                 if (bitno < 1) bitno = 32;
  937. X                 if (y < 1)
  938. X                 { y = HEIGHT;
  939. X                   if (HEIGHT == VT220_HEIGHT)
  940. X                   { bitno = 8;
  941. X                   } else
  942. X                   { bitno = 32;
  943. X                   }
  944. X                 }
  945. X                 break;
  946. X      case 'l' : x++;
  947. X                 if (x > WIDTH) x = 1;
  948. X                 break;
  949. X      case ' ' : if (y < 7)
  950. X                 { character[a-'!'][x-1] ^= bitno;
  951. X                   if (character[a-'!'][x-1] & bitno)
  952. X                     putc ('N',stdout);
  953. X                   else
  954. X                     putc ('M',stdout);
  955. X                 } else
  956. X                 { character[a-'!'][x+(WIDTH-1)] ^= bitno;
  957. X                   if (character[a-'!'][x+(WIDTH-1)] & bitno)
  958. X                     putc ('N',stdout);
  959. X                   else
  960. X                     putc ('M',stdout);
  961. X                 }
  962. X                 printf ("%s",position(CORNER_Y+y,CORNER_X+x));
  963. X                 preview (a,viewer_on,viewer_string);
  964. X                 break;
  965. X      case 'H' : shift_left (character[a-'!']);
  966. X                 draw (character[a-'!']);
  967. X                 preview (a,viewer_on,viewer_string);
  968. X                 break;
  969. X      case 'L' : shift_right (character[a-'!']);
  970. X                 draw (character[a-'!']);
  971. X                 preview (a,viewer_on,viewer_string);
  972. X                 break;
  973. X      case 'K' : shift_up (character[a-'!']);
  974. X                 draw (character[a-'!']);
  975. X                 preview (a,viewer_on,viewer_string);
  976. X                 break;
  977. X      case 'J' : shift_down (character[a-'!']);
  978. X                 draw (character[a-'!']);
  979. X                 preview (a,viewer_on,viewer_string);
  980. X                 break;
  981. X      case 'R' : toggle_bits (character[a-'!']);
  982. X                 draw (character[a-'!']);
  983. X                 preview (a,viewer_on,viewer_string);
  984. X                 break;
  985. X      case 'Y' : flip_y (character[a-'!']);
  986. X                 draw (character[a-'!']);
  987. X                 preview (a,viewer_on,viewer_string);
  988. X                 break;
  989. X      case 'X' : flip_x (character[a-'!']);
  990. X                 draw (character[a-'!']);
  991. X                 preview (a,viewer_on,viewer_string);
  992. X                 break;
  993. X      case 9   : import_char(a);
  994. X                 draw (character[a-'!']);
  995. X                 preview (a,viewer_on,viewer_string);
  996. X                 break;
  997. X      case 5   : erase_char (character[a-'!']);
  998. X                 draw (character[a-'!']);
  999. X                 preview (a,viewer_on,viewer_string);
  1000. X                 break;
  1001. X      case 'E' : viewer_size = set_viewer (0,viewer_string);
  1002. X                 if (viewer_on)
  1003. X                 { preview (a,0,viewer_string);
  1004. X                   preview (a,1,viewer_string);
  1005. X                 }
  1006. X                 break;
  1007. X      case 16  : preview_char_set ();
  1008. X      case 12  : setup_display(fn,viewer_size,viewer_string);
  1009. X                 printf ("%s",CUST_OFF);
  1010. X                 if (viewer_on)
  1011. X                 { printf ("%soff",position(10,71));
  1012. X                   preview (a,0,viewer_string);
  1013. X                 } else
  1014. X                 { printf ("%son ",position(10,71));
  1015. X                   read_char_viewer (0);
  1016. X                 }
  1017. X                 preview (a,viewer_on,viewer_string);
  1018. X                 printf ("%s",CUST_ON);
  1019. X                 preview (a,viewer_on,viewer_string);
  1020. X                 draw (character[a-'!']);
  1021. X                 printf ("%s%sCharacter to Edit: %c%s",CUST_OFF,position(13,22),a,CUST_ON);
  1022. X                 break;
  1023. X      case 22  : viewer_on = !(viewer_on);
  1024. X                 printf ("%s",CUST_OFF);
  1025. X                 if (viewer_on)
  1026. X                 { printf ("%soff",position(10,71));
  1027. X                   preview (a,0,viewer_string);
  1028. X                 } else
  1029. X                 { printf ("%son ",position(10,71));
  1030. X                   read_char_viewer (0);
  1031. X                 }
  1032. X                 preview (a,viewer_on,viewer_string);
  1033. X                 printf ("%s",CUST_ON);
  1034. X                 break;
  1035. X      case 'Q' : printf ("%s%sTo Quit hit 'Y' :   %s",CUST_OFF,position(13,22),BACK_2);
  1036. X                 if (get_char() == 'Y')
  1037. X                 { printf ("Yes");
  1038. X                   printf ("%s\n",position (24,1));
  1039. X                   fclose (JOURNAL_P);
  1040. X                   remove (JOURNAL_NAME);
  1041. X                   exit (1);
  1042. X                 } else
  1043. X                 { printf ("%s%sCharacter to Edit: %c%s",CUST_OFF,position(13,22),a,CUST_ON);
  1044. X                 }
  1045. X                 break;
  1046. X    }
  1047. X    printf ("%s",position(CORNER_Y+y,CORNER_X+x));
  1048. X  }
  1049. X  if (key == NEWLINE) return 1;
  1050. X  return 0;
  1051. X}
  1052. X
  1053. X/*****************************************************************************/
  1054. X/* This function adds the extension (defined by EXTENSION) to the filename   */
  1055. X/* if one does not already exist.  It also creates a jounal file for         */
  1056. X/* recovery from system interruptions.                                       */
  1057. X/* fn = filename given                                                       */
  1058. X/* jou = journal file                                                        */
  1059. X/*****************************************************************************/
  1060. Xvoid add_extension (fn,jou)
  1061. X     char **fn;
  1062. X     char **jou;
  1063. X{
  1064. X#ifdef VAX
  1065. X
  1066. X  int i;
  1067. X  for (i=0;(*fn)[i] && ((*fn)[i] != '.');i++)
  1068. X  { if ((*fn)[i]=='<' || (*fn)[i]=='[' ) while ((*fn)[i]!='>' && (*fn)[i]!=']') i++;
  1069. X  }
  1070. X  *jou = (char *) malloc (i+strlen(JOURNAL)+1);
  1071. X  strncpy (*jou,*fn,i); (*jou)[i] = 0;
  1072. X  strcat (*jou,JOURNAL);
  1073. X  if ((*fn)[i] != '.')
  1074. X  { char *nf;
  1075. X    nf = (char *) malloc (strlen(*fn)+strlen(EXTENSION)+1);
  1076. X    strcpy (nf,*fn);
  1077. X    strcat (nf,EXTENSION);
  1078. X    *fn=nf;
  1079. X  }
  1080. X#else
  1081. X  char *period;
  1082. X
  1083. X  period = strrchr (*fn,'.');
  1084. X  if (period == NULL)
  1085. X  { char *nf;
  1086. X    nf = (char *) malloc (strlen(*fn)+strlen(EXTENSION)+1);
  1087. X    strcpy (nf,*fn);
  1088. X    strcat (nf,EXTENSION);
  1089. X    *fn=nf;
  1090. X    period = strrchr (*fn,'.');
  1091. X  }
  1092. X  *jou = (char *) malloc ((int)(period)-(int)(*fn)+strlen(JOURNAL)+1);
  1093. X  strcpy (*jou,*fn);
  1094. X  sprintf (strrchr(*jou,'.'),"%s",JOURNAL);
  1095. X#endif
  1096. X}
  1097. X
  1098. X#ifndef VAX
  1099. X/*****************************************************************************/
  1100. X/* If the fed program has been compiled on a unix machine, this routine is   */
  1101. X/* used.  Given a path name, it returns the filename for the older version   */
  1102. X/* Format returned is {path}.#{file}.~, as in emacs                          */
  1103. X/* a = filename to be converted.                                             */
  1104. X/*****************************************************************************/
  1105. Xchar *unix_bkp (a)
  1106. X     char *a;
  1107. X{
  1108. X  char *point;
  1109. X  char *ret_string;
  1110. X
  1111. X  ret_string = (char *)malloc (strlen(a)+5);
  1112. X  point = strchr (a,'.');   /* get near end of path (fed forces a period) */
  1113. X  while (*point != '/' && point != a) point--;
  1114. X  if (a == point)           /* no path preceedes the file name            */
  1115. X  { sprintf (ret_string,".#%s.~",a);
  1116. X  } else
  1117. X  { int b;
  1118. X    point++;
  1119. X    b = (int)point-(int)a;
  1120. X    strncpy (ret_string,a,b);
  1121. X    ret_string[b]=0;
  1122. X    sprintf ((char *)((int)ret_string+b),".#%s.~",point);
  1123. X  }
  1124. X  return ret_string;
  1125. X}
  1126. X#endif
  1127. X
  1128. Xmain (argc,argv)
  1129. X      int argc;
  1130. X      char **argv;
  1131. X{
  1132. X  char *file_name=NULL;
  1133. X  char comment=0;
  1134. X  char journal=1;
  1135. X  char quit=0;
  1136. X  char file_exists=0;
  1137. X
  1138. X  while (--argc)
  1139. X  { if (*(argv[argc]) != '-')
  1140. X    { if (file_name != NULL)     /* parse for file name */
  1141. X      { printf ("%s: illegal number of parameters.\n",NAME);
  1142. X        exit (1);
  1143. X      }
  1144. X      file_name = argv[argc];
  1145. X    } else                       /* parse switches       */
  1146. X    { while (*(++(argv[argc])))
  1147. X      { switch (*argv[argc])
  1148. X        { case '2' : WIDTH = VT220_WIDTH;
  1149. X                     HEIGHT = VT220_HEIGHT;
  1150. X                     CORNER_X = 5;
  1151. X                     CORNER_Y = 2;
  1152. X                     SS = VT220_SS;
  1153. X                     TT = "220";
  1154. X                     break;
  1155. X          case '3' : WIDTH = VT320_WIDTH;
  1156. X                     HEIGHT = VT320_HEIGHT;
  1157. X                     CORNER_X = 1;
  1158. X                     CORNER_Y = 1;
  1159. X                     SS = VT320_SS;
  1160. X                     TT = "320";
  1161. X                     break;
  1162. X          case 'r' : RECOVER = 1;
  1163. X                     break;
  1164. X          case 'n' : journal = 0;
  1165. X                     break;
  1166. X          case 'f' : comment = 1;
  1167. X                     break;
  1168. X          case 'h' : printf ("%s Version %s: VT 220/320 Graphic Font Editor\n\n",NAME,VERSION);
  1169. X                     printf ("  -2 : Edit 220 character set on a 220\n");
  1170. X                     printf ("  -3 : Edit 320 character set on a 320\n");
  1171. X                     printf ("  -r : recover an interrupted file\n");
  1172. X                     printf ("  -n : do not keep a journal file\n");
  1173. X                     printf ("  -f : comment font file\n\n");
  1174. X                     exit (1);
  1175. X          default  : printf ("%s: switch -%c unknown and ignored\n",NAME,*argv[argc]);
  1176. X                     quit = 1;
  1177. X                     break;
  1178. X        }
  1179. X      }
  1180. X    }
  1181. X  }
  1182. X  if (!(journal) && RECOVER)
  1183. X  { printf ("%s: switch conflict -r -n\n",NAME);
  1184. X    quit = 1;
  1185. X  }
  1186. X  if (file_name == NULL)
  1187. X  { printf ("%s: you MUST supply a filename to edit\n",NAME);
  1188. X    quit = 1;
  1189. X  }
  1190. X  if (HEIGHT == 0)
  1191. X  { printf ("%s: you must specify 220 or 320\n",NAME);
  1192. X    quit = 1;
  1193. X  }
  1194. X
  1195. X  if (quit)
  1196. X  { printf ("\n%s: use the -h switch for help\n",NAME);
  1197. X    exit (1);
  1198. X  }
  1199. X  initscr ();       /* start curses (used only for keyboard input)  */
  1200. X  noecho ();        /* don't echo characters to screen              */
  1201. X  crmode ();        /* don't wait for carriage returns in getc()    */
  1202. X  add_extension (&file_name,&JOURNAL_NAME);
  1203. X
  1204. X  file_exists = load_character_set (file_name,SS);
  1205. X  if (journal)
  1206. X  { if (!(RECOVER)) JOURNAL_P = fopen (JOURNAL_NAME,"w");
  1207. X    else JOURNAL_P = fopen(JOURNAL_NAME,"r");
  1208. X    if (JOURNAL_P == NULL)
  1209. X    { printf ("%s: FATAL could not open journal file: %s!\n",NAME,JOURNAL_NAME);
  1210. X      exit (1);
  1211. X    }
  1212. X  }
  1213. X  setup_display(file_name,1,"123456");
  1214. X  while (edit_char(get_char_to_edit(),file_name));
  1215. X#ifndef VAX
  1216. X  if (file_exists) rename (file_name,unix_bkp(file_name));
  1217. X#endif
  1218. X  save_characters(file_name,comment);
  1219. X  fclose (JOURNAL_P);
  1220. X  remove (JOURNAL_NAME);
  1221. X  printf ("%s%s\n",position (24,1),CUST_OFF);
  1222. X}
  1223. END_OF_FILE
  1224.   if test 35324 -ne `wc -c <'fed2.c'`; then
  1225.     echo shar: \"'fed2.c'\" unpacked with wrong size!
  1226.   fi
  1227.   # end of 'fed2.c'
  1228. fi
  1229. if test -f 'shift.c' -a "${1}" != "-c" ; then 
  1230.   echo shar: Will not clobber existing file \"'shift.c'\"
  1231. else
  1232.   echo shar: Extracting \"'shift.c'\" \(6267 characters\)
  1233.   sed "s/^X//" >'shift.c' <<'END_OF_FILE'
  1234. X#include "fed2.h"
  1235. X#include "escape.h"
  1236. X#include "shift.h"
  1237. X
  1238. Xextern char character[N_CHAR][N_COL];
  1239. Xextern int WIDTH;
  1240. Xextern int HEIGHT;
  1241. Xextern int CORNER_X;
  1242. Xextern int CORNER_Y;
  1243. Xextern char *SS;
  1244. Xextern char *TT;
  1245. Xextern char *JOURNAL_NAME;
  1246. Xextern char RECOVER;
  1247. Xextern FILE *JOURNAL_P;
  1248. X
  1249. X/*****************************************************************************/
  1250. X/* this routine shifts the character being edited left                       */
  1251. X/* a = string that stores character definition                               */
  1252. X/*****************************************************************************/
  1253. Xvoid shift_left (a)
  1254. X     char *a;
  1255. X{
  1256. X  char b;
  1257. X  int i;
  1258. X
  1259. X  b = *a;
  1260. X  for (i=1;i<WIDTH;i++)
  1261. X  { *a = *(a+1);
  1262. X    a++;
  1263. X  }
  1264. X  *a = b;
  1265. X
  1266. X  b = *(++a);
  1267. X  for (i=1;i<WIDTH;i++)
  1268. X  { *a = *(a+1);
  1269. X    a++;
  1270. X  }
  1271. X  *a = b;
  1272. X}
  1273. X
  1274. X/*****************************************************************************/
  1275. X/* this routine shifts the character being edited right                      */
  1276. X/* a = string that stores character definition                               */
  1277. X/*****************************************************************************/
  1278. Xvoid shift_right (a)
  1279. X     char *a;
  1280. X{
  1281. X  char b;
  1282. X  int i;
  1283. X
  1284. X  a = (char *)((int)a+(2*WIDTH)-1);
  1285. X  b = *a;
  1286. X  for (i=1;i<WIDTH;i++)
  1287. X  { *a = *(a-1);
  1288. X    a--;
  1289. X  }
  1290. X  *a = b;
  1291. X
  1292. X  b = *(--a);
  1293. X  for (i=1;i<WIDTH;i++)
  1294. X  { *a = *(a-1);
  1295. X    a--;
  1296. X  }
  1297. X  *a = b;
  1298. X}
  1299. X
  1300. X/*****************************************************************************/
  1301. X/* this routine shifts the character being edited up                         */
  1302. X/* a = string that stores character definition                               */
  1303. X/*****************************************************************************/
  1304. Xvoid shift_up (a)
  1305. X     char *a;
  1306. X{
  1307. X  int i;
  1308. X  char *b;
  1309. X  char c;
  1310. X  char d;
  1311. X
  1312. X  b = (char *)((int)a+WIDTH);
  1313. X  for (i=0;i<WIDTH;i++)
  1314. X  {
  1315. X    c = (*a & 1);
  1316. X    d = (*b & 1);
  1317. X    *a = *a >> 1;
  1318. X    *b = *b >> 1;
  1319. X    if (HEIGHT == VT220_HEIGHT) *b |= (c*8);
  1320. X    else *b |= (c*32);
  1321. X    *a |= (d*32);
  1322. X    a++; b++;
  1323. X  }
  1324. X}
  1325. X
  1326. X/*****************************************************************************/
  1327. X/* this routine shifts the character being edited down                       */
  1328. X/* a = string that stores character definition                               */
  1329. X/*****************************************************************************/
  1330. Xvoid shift_down (a)
  1331. X     char *a;
  1332. X{
  1333. X  int i;
  1334. X  char *b;
  1335. X  char c;
  1336. X  char d;
  1337. X
  1338. X  b = (char *)((int)a+WIDTH);
  1339. X  for (i=0;i<WIDTH;i++)
  1340. X  {
  1341. X    c = (*a & 32);
  1342. X    *a &= 31;
  1343. X    if (HEIGHT == VT220_HEIGHT)
  1344. X    { d = (*b & 8);
  1345. X      *b &= 7;
  1346. X    }
  1347. X    else
  1348. X    { d = (*b & 32);
  1349. X      *b &= 31;
  1350. X    }
  1351. X    *a = *a << 1;
  1352. X    *b = *b << 1;
  1353. X    if (c) *b |= 1;
  1354. X    if (d) *a |= 1;
  1355. X    a++; b++;
  1356. X  }
  1357. X}
  1358. X
  1359. X/*****************************************************************************/
  1360. X/* this routine erases the current character being edited                    */
  1361. X/* a = string that stores character definition                               */
  1362. X/*****************************************************************************/
  1363. Xvoid erase_char (a)
  1364. X     char *a;
  1365. X{
  1366. X  int i;
  1367. X
  1368. X  for (i=0;i<2*WIDTH;i++) *a++ = 0;
  1369. X}
  1370. X
  1371. X/*****************************************************************************/
  1372. X/* this routine toggles all pixels from off to on and vice-versa             */
  1373. X/* a = string that stores character definition                               */
  1374. X/*****************************************************************************/
  1375. Xvoid toggle_bits (a)
  1376. X     char *a;
  1377. X{
  1378. X  int i;
  1379. X
  1380. X  for (i=0;i<WIDTH;i++) *a++ ^= 63;
  1381. X  if (WIDTH == VT220_WIDTH)
  1382. X    for (i=0;i<WIDTH;i++) *a++ ^= 15;
  1383. X  else
  1384. X    for (i=0;i<WIDTH;i++) *a++ ^= 63;
  1385. X}
  1386. X
  1387. X/*****************************************************************************/
  1388. X/* this routine copies a character from one location to another              */
  1389. X/* a = character to be changed                                               */
  1390. X/*****************************************************************************/
  1391. Xvoid import_char (a)
  1392. X     char a;
  1393. X{
  1394. X  char b;
  1395. X  int i;
  1396. X
  1397. X  printf ("%s%sImport from:        %s",position(13,22),CUST_OFF,BACK_7);
  1398. X  b = get_char();
  1399. X  if (b < '!' || b > '~')
  1400. X  { printf (" ABORT");
  1401. X    sleep (1);
  1402. X    printf ("%s%sCharacter to Edit: %c%s",CUST_OFF,position(13,22),a,CUST_ON);
  1403. X  } else
  1404. X  { printf (" %c to %c%s",b,a,CUST_ON);
  1405. X    for (i=0;i<2*WIDTH;i++)
  1406. X    { character[a-'!'][i] = character[b-'!'][i];
  1407. X    }
  1408. X  }
  1409. X}
  1410. X
  1411. X/*****************************************************************************/
  1412. X/* this routine flips the character over the Y axis                          */
  1413. X/* a = string that stores character definition                               */
  1414. X/*****************************************************************************/
  1415. Xvoid flip_y (a)
  1416. X     char *a;
  1417. X{
  1418. X  int i;
  1419. X  char *b;
  1420. X  char c;
  1421. X
  1422. X  b = (char *)((int)a+WIDTH-1);
  1423. X  for (i=0;i<(WIDTH/2);i++)
  1424. X  { c = *a;
  1425. X    *a++ = *b;
  1426. X    *b-- = c;
  1427. X  }
  1428. X  a = (char *)((int)a+WIDTH-(WIDTH/2));
  1429. X  b = (char *)((int)a+WIDTH-1);
  1430. X  for (i=0;i<(WIDTH/2);i++)
  1431. X  { c = *a;
  1432. X    *a++ = *b;
  1433. X    *b-- = c;
  1434. X  }
  1435. X}
  1436. X
  1437. X/*****************************************************************************/
  1438. X/* This function flips the character being drawn over the X axis.   The code */
  1439. X/* is a little long since all characters are essentially stored in binary    */
  1440. X/* form.  If you can get a better routine than this:  MAIL ME! Thanx.        */
  1441. X/* a = string representation of character                                    */
  1442. X/*****************************************************************************/
  1443. Xvoid flip_x (a)
  1444. X     char *a;
  1445. X{
  1446. X  char *b;
  1447. X  char bit1;
  1448. X  char bit2;
  1449. X  int walk;
  1450. X  char bitno1=1;
  1451. X  char bitno2=32;
  1452. X  char *top;
  1453. X
  1454. X  top = a;
  1455. X  b = (char *)((int)a+WIDTH);
  1456. X  for (walk=0;walk<WIDTH;walk++)
  1457. X  { for (bitno1=1;bitno1<33;bitno1 *=2)
  1458. X    { if (!bitno2) bitno2 = 32;
  1459. X      bit1 = (bitno1 & *a);
  1460. X      bit2 = (bitno2 & *b);
  1461. X      if (bit1) *b |= bitno2; else *b &= (~bitno2);
  1462. X      if (bit2) *a |= bitno1; else *a &= (~bitno1);
  1463. X      bitno2 /= 2;
  1464. X    }
  1465. X    a++; b++;
  1466. X  }
  1467. X  if (WIDTH == VT220_WIDTH)   /* in 220 mode, bits must shift right by 2 */
  1468. X  { a = top;
  1469. X    b = (char *)((int)a+WIDTH);
  1470. X    for (walk=0;walk<WIDTH;walk++)
  1471. X    { bitno1 = (*b & 3);
  1472. X      *a = *a >> 2;
  1473. X      *a |= (bitno1 << 4);
  1474. X      *b = *b >> 2;
  1475. X      a++; b++;
  1476. X    }
  1477. X  }
  1478. X}
  1479. END_OF_FILE
  1480.   if test 6267 -ne `wc -c <'shift.c'`; then
  1481.     echo shar: \"'shift.c'\" unpacked with wrong size!
  1482.   fi
  1483.   # end of 'shift.c'
  1484. fi
  1485. echo shar: End of archive 1 \(of 2\).
  1486. cp /dev/null ark1isdone
  1487. MISSING=""
  1488. for I in 1 2 ; do
  1489.     if test ! -f ark${I}isdone ; then
  1490.     MISSING="${MISSING} ${I}"
  1491.     fi
  1492. done
  1493. if test "${MISSING}" = "" ; then
  1494.     echo You have unpacked both archives.
  1495.     rm -f ark[1-9]isdone
  1496. else
  1497.     echo You still must unpack the following archives:
  1498.     echo "        " ${MISSING}
  1499. fi
  1500. exit 0
  1501. exit 0 # Just in case...
  1502.