home *** CD-ROM | disk | FTP | other *** search
- /* DPS V1.1
-
- Author: Allen Norskog
-
- Revision history:
- V1.0: 3/28/89 - (unofficial release)
- V1.1: 4/23/89 - First real release
- - bug fixes to V1.0
- - Allow Workbench startup
-
- This program released into the Public Domain.
-
- This program compiled with Manx Aztec C V3.6A using
- 32 bit integers. (cc +L; ln ... -lc32) */
-
- #include <stdio.h>
- #include <exec/memory.h>
- #include <intuition/intuition.h>
- #include <intuition/screens.h>
- #include <graphics/display.h>
- #include <graphics/gfxmacros.h>
- #include <workbench/startup.h>
- #include <workbench/workbench.h>
- #include <workbench/icon.h>
- #include <functions.h>
-
- FILE *fopen(),*ifile=NULL;
-
-
- #define ARG_REQ_NUM 1
- #define ARG_INFILE 1
-
- #define ERR_NUM_ARGS 1
- #define ERR_INFILE 2
- #define ERR_BAD_HEADER 3
- #define ERR_G_LIB 4
- #define ERR_INT_LIB 5
- #define ERR_P_WINDOW 6
- #define ERR_ABORT 7
- #define ERR_NO_IMAGE 8
- #define ERR_SCREEN 9
- #define ERR_S_WINDOW 10
- #define ERR_SHORT_FILE 11
- #define ERR_HEADER_VERSION 12
- #define ERR_HEADER_FLAGS 13
-
-
-
- #define MP_S_WINDOW 0
- #define MP_QUIT 1
-
- /* 8.5 * 72 = 612; 11 * 72 =792 */
- #define DEF_DOTS_WIDE 612
- #define DEF_DOTS_TALL 792
- #define DEF_HALF_DOTS_TALL 396
-
- /* 612 / 16 ~= 39 */
- #define DEF_LINE_WORDS 39
- #define DEF_SMALL_LINE_WORDS 20
- #define DEF_LINE_BYTES 78
- /* For now, things are rather customized to 640 by 400 screen */
- #define DEF_SCREEN_HEIGHT 400
- #define TWO_E16 65536
- #define TWO_E16_MINUS_1 65535
- #define IMAGESIZE DEF_LINE_WORDS*DEF_DOTS_TALL
- #define SMALL_IMAGESIZE DEF_SMALL_LINE_WORDS*DEF_HALF_DOTS_TALL
- #define NORMALFLAGS (WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE|WINDOWDEPTH)
-
- extern struct WBStartup *WBenchMsg;
-
- static char *err_msg[]=
- {
- "Everything ok.\n",
- "Command format: dps infile\n\n\
- Command displays a PrintScript run length encoded file.\n\n",
- "Input file does not exist.\n\n",
- "This is not a proper PrintScript file.\n\n",
- "Graphics library won't open!\n\n",
- "Intuition library won't open!\n\n",
- "Unable to open page display window! Probably low on memory.\n\n",
- "Dps aborted.\n\n",
- "Unable to create image! Probably low on memory.\n\n",
- "Unable to open custom screen! Probably low on memory.\n\n",
- "Unable to open overview window! Probably low on memory.\n\n",
- "File too short for even header.\n\n",
- "Version number in file header must be 1.\n\n",
- "Flags number in file header must be 1 (RLE).\n\n"
- };
-
- int version;
- int flags;
- int xdpi;
- int ydpi;
- int width;
- int height;
-
- int from_wb=FALSE;
- int bytes_per_line;
- int max_bytes_out;
- int bytes_out=0;
- int field_length;
- int field_count=0;
- int repeat_count=0;
- int data_byte=0;
- int nibble=0;
- int blank_line=TRUE;
- int new_line[DEF_LINE_BYTES];
- int page_line_count=0;
- int screen_lines=DEF_SCREEN_HEIGHT;
- char *con_name = "CON:20/20/600/40/ DPS V1.1";
- USHORT *image=NULL;
- USHORT *small_image=NULL;
- USHORT color_map[]={
- 0x0867, /* Gray page background to reduce flicker */
- 0x0000, /* Black text on paper */
- 0x0404, /* Dark purple */
- 0x0640 /* Yellow */
- };
-
- struct Image small_page = {
- 0, 0, /* LeftEdge, TopEdge */
- DEF_LINE_WORDS*8, DEF_HALF_DOTS_TALL, /* Width, Height */
- 1, /* Depth */
- NULL, /* *ImageData */
- 1, 0, /* PlanePick, PlaneOnOff */
- NULL /* *NextImage */
- };
-
- struct Image page = {
- -10, 0, /* LeftEdge, TopEdge */
- DEF_LINE_WORDS*16, DEF_DOTS_TALL, /* Width, Height */
- 1, /* Depth */
- NULL, /* *ImageData */
- 1, 0, /* PlanePick, PlaneOnOff */
- NULL /* *NextImage */
- };
-
- struct Border slide_border1 = {
- 0, 0, /* LeftEdge, TopEdge */
- 1, 2, JAM1, /* FrontPen, BackPen (ignored), DrawMode */
- 0, /* Count */
- NULL, /* *XY */
- NULL /* *NextBorder */
- };
-
- struct Border slide_border2 = {
- 0, 0, /* LeftEdge, TopEdge */
- 1, 2, JAM1, /* FrontPen, BackPen (ignored), DrawMode */
- 0, /* Count */
- NULL, /* *XY */
- NULL /* *NextBorder */
- };
-
- struct PropInfo prop_slider1 = {
- FREEVERT | AUTOKNOB, /* Flags */
- 0, /* HorizPot */
- 0, /* VertPot */
- 0xFFFF, /* HorizBody */
- 0x5555, /* VertBody */
- 0, /* CWidth */
- 0, /* CHeight */
- 0, /* HPotRes */
- 0, /* VPotRes */
- 0, /* LeftBorder */
- 0 /* TopBorder */
- };
-
- struct PropInfo prop_slider2 = {
- FREEVERT | AUTOKNOB, /* Flags */
- 0, /* HorizPot */
- 0, /* VertPot */
- 0xFFFF, /* HorizBody */
- 0x5555, /* VertBody */
- 0, /* CWidth */
- 0, /* CHeight */
- 0, /* HPotRes */
- 0, /* VPotRes */
- 0, /* LeftBorder */
- 0 /* TopBorder */
- };
-
- struct Gadget slider1 = {
- NULL, /* *NextGadget */
- -18, 12, 16, -25, /* LeftEdge, TopEdge,
- Width, Height */
- GADGHCOMP | GRELRIGHT | GRELHEIGHT, /* Flags */
- GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY, /* Activation */
- PROPGADGET | GZZGADGET, /* GadgetType */
- (APTR)&slide_border1, /* GadgetRender */
- NULL, /* SelectRender */
- NULL, /* *GadgetText */
- 0, /* MutualExclude */
- (APTR)&prop_slider1, /* SpecialInfo */
- 1, /* GadgetID */
- NULL /* UserData */
- };
-
- struct Gadget slider2 = {
- NULL, /* *NextGadget */
- -18, 12, 16, -25, /* LeftEdge, TopEdge,
- Width, Height */
- GADGHCOMP | GRELRIGHT | GRELHEIGHT, /* Flags */
- GADGIMMEDIATE|FOLLOWMOUSE|RELVERIFY, /* Activation */
- PROPGADGET | GZZGADGET, /* GadgetType */
- (APTR)&slide_border2, /* GadgetRender */
- NULL, /* SelectRender */
- NULL, /* *GadgetText */
- 0, /* MutualExclude */
- (APTR)&prop_slider2, /* SpecialInfo */
- 1, /* GadgetID */
- NULL /* UserData */
- };
-
- struct IntuiText req_text = {
- 0,1, /* FrontPen, BackPen */
- JAM1, /* DrawMode */
- 5,4, /* LeftEdge, TopEdge */
- NULL, /* TextAttr */
- NULL, /* UBYTE *IText */
- NULL /* NextText */
- };
-
- struct IntuiText cont_text = {
- 0,1, /* FrontPen, BackPen */
- JAM1, /* DrawMode */
- 5,4, /* LeftEdge, TopEdge */
- NULL, /* TextAttr */
- (unsigned char *)"Continue",/* UBYTE *IText */
- NULL /* NextText */
- };
-
- struct IntuiText p_menu_1_text = {
- 0,1, /* FrontPen, BackPen */
- JAM1, /* DrawMode */
- 0,0, /* LeftEdge, TopEdge */
- NULL, /* TextAttr */
- (unsigned char *)"Overview",/* UBYTE *IText */
- NULL /* NextText */
- };
-
- struct IntuiText p_menu_2_text = {
- 0,1, /* FrontPen, BackPen */
- JAM1, /* DrawMode */
- 0,0, /* LeftEdge, TopEdge */
- NULL, /* TextAttr */
- (unsigned char *)"Quit", /* UBYTE *IText */
- NULL /* NextText */
- };
-
- struct MenuItem p_menu_2 = {
- NULL, /* *NextItem */
- 0,12,80,12, /* LeftEdge, TopEdge, Width, Height */
- ITEMTEXT | HIGHCOMP | ITEMENABLED, /* Flags */
- 0, /* MutualExclude */
- (APTR)&p_menu_2_text, /* ItemFill */
- 0, /* Command */
- NULL, /* *SubItem */
- 0 /* NextSelect */
- };
-
- struct MenuItem p_menu_1 = {
- &p_menu_2, /* *NextItem */
- 0,0,80,12, /* LeftEdge, TopEdge, Width, Height */
- ITEMTEXT | HIGHCOMP | ITEMENABLED, /* Flags */
- 0, /* MutualExclude */
- (APTR)&p_menu_1_text, /* ItemFill */
- 0, /* Command */
- NULL, /* *SubItem */
- 0 /* NextSelect */
- };
-
- struct Menu project_menu = {
- NULL, /* *NextMenu */
- 0,0,80,12, /* LeftEdge, TopEdge, Width, Height */
- MENUENABLED, /* Flags */
- (BYTE *)"Project", /* BYTE *MenuName */
- &p_menu_1 /* *FirstItem */
- };
-
- static struct NewScreen myDpsScreen = {
- 0, 0, /* SHORT LeftEdge, TopEdge */
- 640, DEF_SCREEN_HEIGHT, /* Width, Height */
- 2, /* Depth */
- 0, 1, /* UBYTE DetailPen, BlockPen */
- HIRES | INTERLACE, /* USHORT ViewModes */
- CUSTOMSCREEN, /* USHORT Type */
- NULL, /* struct TextAttr *Font */
- (unsigned char *)"DPS Screen", /* UBYTE *DefaultTitle */
- NULL, /* struct Gadget *Gadgets */
- NULL /* struct BitMap *CustomBitMap */
- };
-
- static struct NewWindow myPageWindow = {
- 0, 0, /* SHORT LeftEdge, TopEdge */
- 640, /* Width */
- DEF_SCREEN_HEIGHT, /* Height */
- -1, -1, /* UBYTE DetailPen, BlockPen */
- /* ULONG IDCMPFlags */
- CLOSEWINDOW | NEWSIZE | MENUPICK | GADGETDOWN | GADGETUP | MOUSEMOVE,
- /* ULONG Flags */
- SMART_REFRESH|NOCAREREFRESH|NORMALFLAGS|GIMMEZEROZERO,
- &slider1, /* struct Gadget *FirstGadget */
- NULL, /* struct Image *CheckMark */
- (unsigned char *)"DPS V1.1", /* UBYTE *Title */
- NULL, /* struct Screen *Screen */
- NULL, /* struct BitMap *BitMap */
- 80, 50, 640, 400, /* SHORT MinWidth,MinHeight,
- MaxWidth, MaxHeight*/
- CUSTOMSCREEN /* USHORT Type */
- };
-
- static struct NewWindow mySmallWindow = {
- 0, 0, /* SHORT LeftEdge, TopEdge */
- DEF_LINE_WORDS*8+28, /* Width */
- DEF_SCREEN_HEIGHT, /* Height */
- -1, -1, /* UBYTE DetailPen, BlockPen */
- /* ULONG IDCMPFlags */
- CLOSEWINDOW | NEWSIZE | MENUPICK | GADGETDOWN | GADGETUP | MOUSEMOVE,
- /* ULONG Flags */
- SMART_REFRESH|NOCAREREFRESH|NORMALFLAGS|GIMMEZEROZERO,
- &slider2, /* struct Gadget *FirstGadget */
- NULL, /* struct Image *CheckMark */
- (unsigned char *)"Overview", /* UBYTE *Title */
- NULL, /* struct Screen *Screen */
- NULL, /* struct BitMap *BitMap */
- 80, 50, 640, 400, /* SHORT MinWidth,MinHeight,
- MaxWidth, MaxHeight*/
- CUSTOMSCREEN /* USHORT Type */
- };
-
- struct Screen *dpsScreen=NULL;
- struct Window *pageWindow=NULL;
- struct Menu *pageWindowMenu=NULL;
- struct Window *smallWindow=NULL;
- struct RastPort *Rport1=NULL;
- struct RastPort *Rport2=NULL;
- struct Library *IconBase=NULL;
- struct Library *GfxBase=NULL;
- struct Library *IntuitionBase=NULL;
-
-
- void disp_err(x)
- int x;
- {
- struct FileHandle *con;
-
- if (from_wb) {
- if (pageWindow) {
- req_text.IText = (UBYTE *) err_msg[x];
- x = AutoRequest(pageWindow,&req_text,NULL,&cont_text,
- NULL,NULL,600,60);
- }
- else {
- con = Open(con_name,MODE_OLDFILE);
- if (con) {
- Write(con,err_msg[x],strlen(err_msg[x]));
- Delay(120);
- Close(con);
- }
- }
- }
- else {
- printf(err_msg[x]);
- }
- }
-
- void err_exit(x)
- int x;
- {
- disp_err(x);
- exit(x); /* err_exit is not called when any windows/screens are open */
- }
-
- void redraw_small_image()
- {
- int image_lines;
- int first_line;
- int last_line;
-
-
- image_lines = smallWindow->Height - smallWindow->BorderTop -
- smallWindow->BorderBottom;
- last_line = DEF_HALF_DOTS_TALL - image_lines;
- first_line = (prop_slider2.VertPot * last_line)/ TWO_E16_MINUS_1;
-
- DrawImage(Rport2,&small_page,0,-first_line);
- }
-
- void redraw_image() /* redraws large image */
- {
- int image_lines;
- int first_line;
- int last_line;
-
-
- image_lines = pageWindow->Height - pageWindow->BorderTop -
- pageWindow->BorderBottom;
- last_line = DEF_DOTS_TALL - image_lines;
- first_line = (prop_slider1.VertPot * last_line)/ TWO_E16_MINUS_1;
-
- DrawImage(Rport1,&page,0,-first_line);
- }
-
- void redraw_small_window() /* sets slider and redraws small image */
- {
- int image_lines;
- int body;
- int first_line;
- int last_line;
-
-
- image_lines = smallWindow->Height - smallWindow->BorderTop -
- smallWindow->BorderBottom;
- body = (TWO_E16_MINUS_1 * image_lines) / DEF_HALF_DOTS_TALL;
- last_line = DEF_HALF_DOTS_TALL - image_lines;
- first_line = (prop_slider2.VertPot * last_line)/ TWO_E16_MINUS_1;
-
- DrawImage(Rport2,&small_page,0,-first_line);
- ModifyProp(&slider2,smallWindow,NULL,prop_slider2.Flags,
- prop_slider2.HorizPot,prop_slider2.VertPot,prop_slider2.HorizBody,
- body);
- RefreshGadgets(&slider2,smallWindow,NULL);
- }
-
- void redraw() /* sets slider and redraws large image */
- {
- int image_lines;
- int body;
- int first_line;
- int last_line;
-
-
- image_lines = pageWindow->Height - pageWindow->BorderTop -
- pageWindow->BorderBottom;
- body = (TWO_E16_MINUS_1 * image_lines) / DEF_DOTS_TALL;
- last_line = DEF_DOTS_TALL - image_lines;
- first_line = (prop_slider1.VertPot * last_line)/ TWO_E16_MINUS_1;
-
- DrawImage(Rport1,&page,0,-first_line);
- ModifyProp(&slider1,pageWindow,NULL,prop_slider1.Flags,
- prop_slider1.HorizPot,prop_slider1.VertPot,prop_slider1.HorizBody,
- body);
- RefreshGadgets(&slider1,pageWindow,NULL);
- }
-
- void kill_small_window()
- {
- if (small_image != NULL) {
- FreeMem(small_image, SMALL_IMAGESIZE*sizeof(USHORT));
- small_image = NULL;
- }
- if (smallWindow) {
- CloseWindow(smallWindow);
- smallWindow = NULL;
- }
- Rport2=NULL;
- }
-
- void open_small_window()
- {
- int i,j,k;
- int big_words;
- int small_words;
-
- if (smallWindow == NULL) {
-
- small_image = (USHORT *) AllocMem(SMALL_IMAGESIZE*sizeof(USHORT),
- MEMF_CHIP|MEMF_CLEAR);
- if (small_image == NULL) {
- disp_err(ERR_NO_IMAGE);
- return;
- }
- small_page.ImageData = small_image;
-
- big_words =0; /* Offset to present row in page image */
- small_words=0; /* Offset to present row in small image */
-
- /* The following loop compresses the image 2x in both
- height and width */
-
- for (i = 0; i<DEF_HALF_DOTS_TALL; i++) {
- for (j = 0, k=0; j<DEF_SMALL_LINE_WORDS-1; j++, k += 2) {
- small_image[small_words+j] =
- (shrink_word(image[big_words+k])<<8) +
- shrink_word(image[big_words+k+1]);
- small_image[small_words+j] |=
- (shrink_word(image[big_words+k+DEF_LINE_WORDS])<<8) +
- shrink_word(image[big_words+k+DEF_LINE_WORDS+1]);
- }
- small_image[small_words+j] = (shrink_word(image[big_words+k])
- | shrink_word(image[big_words+k+DEF_LINE_WORDS])) <<8;
- big_words += 2*DEF_LINE_WORDS;
- small_words += DEF_SMALL_LINE_WORDS;
- }
-
- prop_slider2.VertPot = 0; /* This is needed on second opening of
- this window */
- smallWindow = OpenWindow(&mySmallWindow);
- Rport2 = smallWindow->RPort;
- if (smallWindow == NULL) {
- kill_small_window();
- disp_err(ERR_S_WINDOW);
- return;
- }
- redraw_small_window();
- }
- }
-
- void kill_page_window()
- {
- if (image) {
- FreeMem(image, IMAGESIZE*sizeof(USHORT));
- image = NULL;
- }
- if (pageWindow) {
- if (pageWindowMenu) ClearMenuStrip(pageWindow);
- pageWindowMenu = NULL;
- CloseWindow(pageWindow);
- pageWindow = NULL;
- }
- }
-
- void kill_dps_screen()
- {
- kill_small_window();
- kill_page_window();
- if (dpsScreen) {
- CloseScreen(dpsScreen);
- dpsScreen == NULL;
- }
- }
-
- void open_page_window()
- {
- myPageWindow.Screen = dpsScreen;
- mySmallWindow.Screen = dpsScreen;
-
- pageWindow = OpenWindow(&myPageWindow);
- if (pageWindow == NULL) {
- kill_dps_screen();
- CloseLibrary(IntuitionBase);
- CloseLibrary(GfxBase);
- err_exit(ERR_P_WINDOW);
- }
-
- pageWindowMenu = &project_menu;
- SetMenuStrip(pageWindow, pageWindowMenu);
- Rport1 = pageWindow->RPort;
- redraw();
- }
-
- void handle_events()
- {
- int mouse_moved;
- int remove_small_window;
- int make_small_window;
- int get_out;
- struct IntuiMessage *imsg;
- long class;
- USHORT code;
- unsigned long m1, m2, res;
- short menu, item;
-
- m1=1L<<pageWindow->UserPort->mp_SigBit;
- m2=0;
- for (;;) {
- res = Wait(m1|m2);
- if (res & m1) {
- get_out=FALSE;
- mouse_moved=FALSE;
- make_small_window=FALSE;
- while (imsg = (struct IntuiMessage *)GetMsg(pageWindow->UserPort)) {
- class = imsg->Class;
- code = imsg->Code;
- ReplyMsg(imsg);
- switch(class) {
- case CLOSEWINDOW:
- get_out=TRUE;
- break;
- case NEWSIZE:
- redraw();
- break;
- case GADGETDOWN: /* Gadget stuff all the same */
- case GADGETUP:
- case MOUSEMOVE:
- mouse_moved = TRUE;
- break;
- case MENUPICK:
- menu = MENUNUM(code);
- item = ITEMNUM(code);
- if (menu == 0) {
- switch(item) {
- case(MP_S_WINDOW):
- make_small_window=TRUE;
- break;
- case(MP_QUIT):
- get_out=TRUE;
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- if (get_out) return;
- if (mouse_moved) redraw_image();
- if (make_small_window) {
- open_small_window();
- if (smallWindow) m2=1L<<smallWindow->UserPort->mp_SigBit;
- }
- }
- if (res & m2) {
- mouse_moved = FALSE;
- remove_small_window = FALSE;
- while (imsg = (struct IntuiMessage *)GetMsg(smallWindow->UserPort)) {
- class = imsg->Class;
- code = imsg->Code;
- ReplyMsg(imsg);
- switch(class) {
- case CLOSEWINDOW:
- remove_small_window = TRUE;
- break;
- case NEWSIZE:
- redraw_small_window();
- break;
- case GADGETDOWN: /* Gadget stuff all the same */
- case GADGETUP:
- case MOUSEMOVE:
- mouse_moved = TRUE;
- break;
- default:
- break;
- }
- }
- if (remove_small_window) {
- kill_small_window();
- m2 = 0;
- }
- else if (mouse_moved) redraw_small_image();
- }
- }
- }
-
- int shrink_byte(c) /* Compress a byte into a nibble.
- This routine not used at present,
- but might be useful */
- int c;
- {
- int nibble;
-
- nibble = 0;
- if (c & 3) nibble = 1;
- if (c & 12) nibble |= 2;
- if (c & 48) nibble |= 4;
- if (c & 192) nibble |= 8;
- return(nibble);
- }
-
- int shrink_word(c) /* Compress a 16 bit word into 8 bits */
- unsigned int c;
- {
- unsigned int byte;
-
- byte = 0;
- if (c & 0x3) byte = 1;
- if (c & 0xc) byte |= 2;
- if (c & 0x30) byte |= 4;
- if (c & 0xc0) byte |= 8;
- if (c & 0x300) byte |= 0x10;
- if (c & 0xc00) byte |= 0x20;
- if (c & 0x3000) byte |= 0x40;
- if (c & 0xc000) byte |= 0x80;
- return(byte);
- }
-
- void clear_new_line()
- {
- int j;
-
- for (j = 0; j<DEF_LINE_BYTES; j++) {
- new_line[j] = 0;
- }
- }
-
- int flip_byte(c) /* Reverses the bit order */
- int c;
- {
- int b;
-
- b = ((c & 1) <<7) | ((c & 2) <<5) | ((c & 4) <<3) | ((c & 8) <<1);
- b |= ((c & 0x80) >>7) | ((c & 0x40) >>5) | ((c & 0x20) >>3) |
- ((c & 0x10) >>1);
- return(b);
- }
-
- void clear_image() /* Sets up large image. Draws a (8.5 x 11) page
- border into the image. */
- {
- int i;
- int j;
-
- image = (USHORT *) AllocMem(IMAGESIZE*sizeof(USHORT),
- MEMF_CHIP|MEMF_CLEAR);
- if (image == NULL) {
- err_exit(ERR_NO_IMAGE);
- }
- page.ImageData = image;
-
- /* Draw a page border */
- i = (DEF_DOTS_TALL-1) * DEF_LINE_WORDS; /* point to last line */
- for (j = 1; j<DEF_LINE_WORDS; j++) {
- image[j] = 0xFFFF;
- image[i+j] = 0xFFFF;
- }
- image[0] = 0x000F; /* 8.5inches * 72dpi = 612 bits
- = 38.25 (16bit words)
- Therefore, we need 39 words.
- Since the line is flipped, data starts on the
- third nibble */
- image[i] = 0x000F;
- for (j = 1, i=DEF_LINE_WORDS;
- j<DEF_DOTS_TALL-1; j++, i += DEF_LINE_WORDS) {
-
- image[i] = 0x0008; /* Beginning of line */
- image[i+DEF_LINE_WORDS-1] = 0x0001; /* End of line */
- }
- }
-
- void enter_new_line() /* puts a line into the large image */
- {
- int b;
- int i;
- int j;
- int k;
-
- page_line_count++;
- if (page_line_count > DEF_DOTS_TALL) return;
- if (blank_line != TRUE) {
- k = (DEF_DOTS_TALL-page_line_count)*DEF_LINE_WORDS;
- for (b=j= 0; j<DEF_LINE_WORDS; j++, b += 2) {
- i = (new_line[b]<<8) + new_line[b+1];
- image[k+j] ^= i; /* XOR so that writes on page edges are
- visible */
- }
- }
- blank_line = TRUE;
- }
-
- void read_header() /* Reads the header of a PrintScript run-length-encoded
- file. */
- {
- int c;
- int i;
- int done;
-
-
- /* Read header and check if ok */
- done = FALSE;
- i=0;
- while (done != TRUE) {
- c = getc(ifile);
- if (c == EOF) {
- done = TRUE;
- disp_err(ERR_SHORT_FILE);
- err_exit(ERR_BAD_HEADER);
- }
- else {
- i++;
- switch (i) {
- case 1:
- version = c*256;
- break;
- case 2:
- version += c;
- /* This needs to be re-thought if future versions
- come along. */
- if (version != 1) {
- disp_err(ERR_HEADER_VERSION);
- err_exit(ERR_BAD_HEADER);
- }
- break;
- case 3:
- flags = c*256;
- break;
- case 4:
- flags += c;
- if (flags != 1) {
- disp_err(ERR_HEADER_FLAGS);
- err_exit(ERR_BAD_HEADER);
- }
- break;
- case 5:
- xdpi = c*256;
- break;
- case 6:
- xdpi += c;
- break;
- case 7:
- ydpi = c*256;
- break;
- case 8:
- ydpi += c;
- break;
- case 9:
- width = c*256;
- break;
- case 10:
- width += c;
- break;
- case 11:
- height = c*256;
- break;
- case 12:
- height += c;
- done = TRUE;
- break;
- default:
- err_exit(ERR_BAD_HEADER); /* Should never get here */
- break;
- }
- }
- }
-
- }
-
- void build_image() /* This reads the part of the PrintScript
- run-length-encoded file and builds the image.
- Since the PrintScript image is "upside-down",
- we need to put the top line to the bottom, etc.,
- and also reverse each line left-to-right. */
- {
- int c;
- int i;
- int j;
- int done;
-
- clear_new_line();
- blank_line = TRUE;
- done = FALSE;
- i=0;
- while (done != TRUE) {
- c = getc(ifile);
- if (c == EOF) {
- done = TRUE;
- }
- else {
- i++;
- switch (i) {
- case 1:
- field_length = c*256;
- field_count = 0;
- bytes_out = 0;
- break;
- case 2:
- field_length += c;
- if (field_length == 0) {
- i = 0;
- enter_new_line(); /* enter a blank line */
- /* clear_new_line(); */
- }
- else blank_line = FALSE;
- break;
- case 3:
- repeat_count = c + 1;
- field_count++;
- break;
- case 4:
- i = 2;
- data_byte = flip_byte(c); /* Reverse byte left-to-right */
- field_count++;
- if ((repeat_count + bytes_out) > max_bytes_out) {
- repeat_count = max_bytes_out - bytes_out;
- }
- for (j = 0; j<repeat_count; j++) {
- /* Put bytes in "backwards". We want the first
- byte to go way over to the right in
- new_line[77]. */
- bytes_out++;
- new_line[DEF_LINE_BYTES-bytes_out] = data_byte;
- }
- if (field_count >= field_length) {
- i = 0;
- enter_new_line();
- clear_new_line();
- }
- break;
- default:
- err_exit(ERR_BAD_HEADER); /* Should never get here */
- break;
- }
- }
- }
-
- }
-
- void get_wb_args(wb_msg)
- struct WBStartup *wb_msg;
- {
- struct WBArg *wb_arg;
- struct DiskObject *diskobj;
- char **toolarray;
- int i;
- char *s;
-
- wb_arg = wb_msg->sm_ArgList;
- if ((IconBase = OpenLibrary("icon.library",0))) {
- diskobj = (struct DiskObject *) GetDiskObject(wb_arg->wa_Name);
- if (diskobj) {
- toolarray = (char **) diskobj->do_ToolTypes;
- s = (char *) FindToolType(toolarray,"FILE");
- if (s) {
- ifile=fopen(s,"r");
- }
- FreeDiskObject(diskobj);
- }
- CloseLibrary(IconBase);
- }
- if (!ifile) {
- err_exit(ERR_INFILE);
- }
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct ViewPort *vp;
-
- from_wb = (argc == 0);
-
- if (from_wb) {
- get_wb_args(WBenchMsg);
- }
- else {
- if (argc <= ARG_REQ_NUM) {
- err_exit(ERR_NUM_ARGS);
- }
- ifile=fopen(argv[ARG_INFILE],"r");
- if (!ifile) {
- err_exit(ERR_INFILE);
- }
- }
-
- max_bytes_out = DEF_LINE_BYTES;
-
- read_header();
-
- /* Old debug stuff
- printf("version = %d\n", version);
- printf("flags = %d\n", flags);
- printf("xdpi = %d\n", xdpi);
- printf("ydpi = %d\n", ydpi);
- printf("width = %d\n", width);
- printf("height = %d\n", height);
- printf("max_bytes_out = %d\n", max_bytes_out);
- */
-
- clear_image();
- build_image();
- close(ifile);
-
- /* If we haven't aborted by this point, start doing graphics */
-
- GfxBase = OpenLibrary("graphics.library", 0L);
- if (GfxBase == NULL) {
- if (image != NULL) {
- FreeMem(image, IMAGESIZE*sizeof(USHORT));
- image = NULL;
- }
- err_exit(ERR_G_LIB);
- }
- IntuitionBase = OpenLibrary("intuition.library", 0L);
- if (IntuitionBase == NULL) {
- if (image != NULL) {
- FreeMem(image, IMAGESIZE*sizeof(USHORT));
- image = NULL;
- }
- CloseLibrary(GfxBase);
- err_exit(ERR_INT_LIB);
- }
-
- dpsScreen = OpenScreen(&myDpsScreen);
- if (dpsScreen == NULL) {
- kill_dps_screen();
- CloseLibrary(IntuitionBase);
- CloseLibrary(GfxBase);
- err_exit(ERR_SCREEN);
- }
- vp = &dpsScreen->ViewPort;
- LoadRGB4(vp,color_map,4);
-
- open_page_window();
- handle_events();
-
- kill_dps_screen();
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (GfxBase) CloseLibrary(GfxBase);
- return(0);
- }
-
-
- _abort()
- {
- kill_dps_screen();
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (GfxBase) CloseLibrary(GfxBase);
- exit(ERR_ABORT);
- }
-
-
-