home *** CD-ROM | disk | FTP | other *** search
- /*
- Fmerge
- Greg Lee, Oct '84.
- */
-
- #include <bdscio.h>
-
-
- #define FF 0x0c /* formfeed character, or zero if not supported */
- #define ESC 0x1B
- #define FTSIZE 24000
-
-
- /* masks for mode bits */
- #define ELITE 0x01
- #define PRPTNL 0x02
- #define CMPRSSD 0x04
- #define EMPHSZD 0x08
- #define DBLSTRK 0x10
- #define EXPNDD 0x20
- #define UNDRLN 0x40
- #define ITALIC 0x80
- /* So that's b0-b7; b8,b9,b10 are used for the
- current graphics font, which is 'fo'-1. */
- #define SUPSCRPT 0x0800
- #define SUBSCRPT 0x1000
- #define BENT 0x2000
- #define TALL 0x4000
- #define IGNORE 0x8000
- /* All bits are committed */
-
-
- #define TOPROW 0
- #define BOTROW 23
- #define LEFTCOL 0
- #define RIGHTCOL 79
-
-
-
- char cmd, currch, edfnum, cch, cbyte, cbyteo, screen, mxflag;
- int col, row, currlen, currfont;
-
- char ckeep[6][80], gxoff, gyoff, ib;
-
- int colno;
-
- int i, fd;
- char ftname[30], ftname2[30], *fname;
-
-
- char duplflag, ovlflag;
- int fix[128];
- char ft[FTSIZE];
-
- int fix2[128];
- char ft2[FTSIZE];
-
-
- main(argc,argv)
- char **argv;
- {
-
- ovlflag = FALSE;
- currlen = 0;
- currfont = FALSE;
-
- if (argc-1)
- {
- fname = *++argv;
- argc--;
- strcpy(ftname, fname);
- strcat(ftname,".FN2");
- } else usage();
- if (argc-1)
- {
- fname = *++argv;
- argc--;
- strcpy(ftname2, fname);
- strcat(ftname2,".FN2");
- } else usage();
-
- openwork();
- tokeep();
-
- chkdupl();
- currch = duplflag? ' ' : 1;
-
-
- for ( ; ; currch++)
- { currfont = TRUE;
- tokeep();
- currfont = FALSE;
- if (currlen) fromkeep();
- if (ovlflag) abort("out of memory");
- if (duplflag && currch > '_') break;
- if (currch > '~') break;
- }
-
-
- savefnt();
-
-
- } /* End main */
-
-
- usage()
- { puts("need 2 font names\n");
- exit(0);
- }
-
- abort(s)
- char *s;
- { puts(s);
- exit(0);
- }
-
- openwork()
- { int fdft, i, ftrecs;
-
- setmem(ft, FTSIZE, 0);
- setmem(fix, 128, 0);
- setmem(ft2, FTSIZE, 0);
- setmem(fix2, 128, 0);
-
- if ((fdft = open(ftname,0)) == ERROR) abort("no font"); else
- {
- if (read(fdft, fix, 2) != 2)
- abort("bad font");
-
- /* only read enough of the font to get info for char's
- up to ascii nul (which is not used) */
- ftrecs = (fix[127]+127)/128;
-
- if (read(fdft, ft, ftrecs) != ftrecs)
- {puts("bad font"); exit(ERROR);}
- fabort(fdft);
- if (ftrecs > FTSIZE/128) ovlflag = TRUE;
- }
-
- if (ovlflag) abort("no room");
-
- if ((fdft = open(ftname2,0)) == ERROR) abort("no font"); else
- {
- if (read(fdft, fix2, 2) != 2)
- abort("bad font");
-
- /* only read enough of the font to get info for char's
- up to ascii nul (which is not used) */
- ftrecs = (fix2[127]+127)/128;
-
- if (read(fdft, ft2, ftrecs) != ftrecs)
- abort("bad font");
- fabort(fdft);
- }
-
- chkdupl();
- }
-
- savefnt()
- { int fdft, i, ftrecs;
-
- if (currfont)
- {
- if ((fdft = creat(ftname2)) == ERROR)
- {abort("can't save"); return;}
- if (write(fdft, fix2, 2) != 2)
- {abort("save error"); return;}
-
- /* only write enough of the font to get info for char's
- up to ascii nul (which is not used) */
- ftrecs = (fix2[127]+127)/128;
-
- if (write(fdft, ft2, ftrecs) != ftrecs)
- {abort("save error"); return;}
- if (close(fdft) == ERROR)
- abort("can't close");
- }
- else
- {
- if ((fdft = creat(ftname)) == ERROR)
- {abort("can't save"); return;}
- if (write(fdft, fix, 2) != 2)
- {abort("save error"); return;}
-
- /* only write enough of the font to get info for char's
- up to ascii nul (which is not used) */
- ftrecs = (fix[127]+127)/128;
-
- if (write(fdft, ft, ftrecs) != ftrecs)
- {abort("save error"); return;}
- if (close(fdft) == ERROR)
- abort("can't close");
- }
-
-
- }
-
-
-
- tokeep()
- {
- tokepp(0, currch);
- if (duplflag) tokepp(3, dtrans(currch, FALSE));
- }
-
- tokepp(ib, currch)
- char ib, currch;
- { int i, j, cbase;
-
- if (currfont)
- {
- cbase = fix2[currch];
- currlen = (fix2[currch+1] - cbase) / 3;
- }
- else
- {
- cbase = fix[currch];
- currlen = (fix[currch+1] - cbase) / 3;
- }
-
- if (currlen > 80) currlen = 80;
- for (i = 0; i < 3; i++)
- for (j = 0; j < 80; j++)
- if (j >= currlen) ckeep[ib+i][j] = 0;
- else if (currfont) ckeep[ib+i][j] = ft2[cbase + j + i*currlen];
- else ckeep[ib+i][j] = ft[cbase + j + i*currlen];
- }
-
-
- fromkeep()
- {
- frommkeep(0,currch);
- if (duplflag) frommkeep(3, dtrans(currch, FALSE));
- }
-
- frommkeep(ib, currch)
- char ib, currch;
- { int i, j, cend, cbase, cnext, mlen;
-
- if (currfont)
- {
- cbase = fix2[currch];
- cnext = fix2[currch+1];
- }
- else
- {
- cbase = fix[currch];
- cnext = fix[currch+1];
- }
-
- cend = cbase + currlen * 3;
- mlen = (cend-cnext) ? (ovlflag?
- (2*FTSIZE):FTSIZE)
- - 1 - max(cnext,cend)
- : 0;
-
- if (mlen)
- if (currfont)
- { movmem(ft2+cnext, ft2+cend, mlen);
- for (i = currch+1; i < 128; i++)
- fix2[i] = fix2[i] + cend - cnext;
- }
- else
- { movmem(ft+cnext, ft+cend, mlen);
- for (i = currch+1; i < 128; i++)
- fix[i] = fix[i] + cend - cnext;
- if (fix[127] >= FTSIZE) ovlflag = TRUE;
- }
-
- if (currlen)
- for (i = 0; i < 3; i++)
- for (j = 0; j < currlen; j++)
- if (currfont)
- ft2[cbase + j + i*currlen] = ckeep[ib+i][j];
- else ft[cbase + j + i*currlen] = ckeep[ib+i][j];
- }
-
- dtrans(c, upper)
- char c, upper;
- { if (c == 0x20 || c == 0x5F) return(c);
-
- if (c >= 0x60) c -= 0x20;
- else if (c < 0x20) c += 0x20;
-
- if (upper) return(c);
-
- if (c < 0x40) c -= 0x20;
- else c += 0x20;
-
- return(c);
- }
-
-
- chkdupl()
- {
- duplflag = (currfont ? fix2[0] : fix[0]) & PRPTNL;
- }