home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * SNIP V1.3
- *
- * Freely redistributable, donations not discouraged.
- * Bug reports, suggestions, feedback welcomed.
- *
- * John 07-01-88
- */
-
- /*
- * John Russell
- * 5 Alderdice Place
- * St. John's, Newfoundland
- * Canada A1B 2P8
- * (709) 726-7847
- *
- * john13@garfield.uucp (...utai!garfield!john13)
- *
- */
-
- /* this contains mostly the bitmaps for the characters of the topaz-8 font */
-
- /* assign whatever directory snip is in to snip: */
-
- /* you may need to add extra includes yourself, I use a precompiled */
- /* include file of common intuition/graphics files */
-
- #include "snip:snip.h"
-
- /* these are the defines I use for all modules */
- #include "snip:defs.h"
-
- extern struct Window *WhichWindow(); /* find window under mouse */
- extern struct Screen *WhichScreen(); /* find screen under mouse */
- extern BOOL reactivate;
-
- short save_format = PRINT_STDOUT; /* default if you don't give "-p" or "-c" on command line */
-
- /* these are concerned with storing the text in a rectangular block */
-
- char *scratch = NULL;
- short scratchsize = 0;
- short scratchwidth, scratchheight;
-
- /* these are concerned with making it possible to get text from any window */
-
- short x_offset = 0, y_offset = 0;
-
- struct NewWindow nwindow =
- {
- 50,0,372,10,
- 1,2,
- VANILLAKEY | CLOSEWINDOW | MOUSEBUTTONS | INACTIVEWINDOW,
- REPORTMOUSE | RMBTRAP | SMART_REFRESH | NOCAREREFRESH | WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH,
- NULL, NULL,
- (UBYTE *)"SNIP V1.3 © 1988 John Russell",
- NULL, NULL, -1, -1, -1, -1, WBENCHSCREEN
- };
-
- /* using these snip can be detached from the CLI without run, by linking */
- /* with detach.o32 from Manx 3.6 */
-
- long _stack = 4000;
- long _priority = 0;
- long _BackGroundIO = 1;
- char *_procname = (char *)&(nwindow.Title);
-
- char usage[] = "Usage: snip [options] ('run' not needed)\n\
- Options may be in any order. Possible options are:\n\
- -s : Snipped text is written to standard output (default)\n\
- -p : Snipped text is written to \"pipe:snip\"\n\
- -c : Snipped text is written to the clipboard\n\
- -k : Snipped text is typed into the next window to become active\n\
- -K : Same as -k, except text is written as one line (no carriage returns)\n\
- -a : Use with -k or -K. Snip window re-activates itself after pasting.\n\
- -o <name> : Standard output sent to name, eg PAR: or df0:text.\n\
- -f <name> : Use a different font. Filename should be the name of a font\n\
- definition file created by SNIPGEN; the search path will be\n\
- <name>.fontdef and s:<name>.fontdef.\n\
- on <name> : Open Snip window on screen called <name>. Use \"-null\" as name\n\
- of unnamed screens (ie on -null).\n\
- x y : For non-console windows (eg the VT100 window), you specify an offset\n\
- for SNIP to use in positioning its capture box. If one offset is\n\
- specified then both must be even if the other one is just zero.\n\
- See documentation for help with interactive commands.\n\
- \t\t\tSNIP Copyright 1988 John Russell\n\
- ";
-
- char plea[] = "Please use Kickstart/Workbench V1.2 for latest ";
-
- /* to be able to safely abort, I need to declare these externally */
- /* ^C won't be trapped now, but I keep _abort() out of habit */
-
- struct Window *w = NULL; /* this is the one I open */
- struct Window *window; /* this is an arbitrary window */
- struct FileHandle *fp = NULL; /* for writing captured text to a file */
- BOOL layer_locked = FALSE; /* so I'll always know if I control someone else's window */
- struct FileHandle *outfilehandle = NULL;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct Screen *screen;
- struct MsgPort *port;
- register ULONG class, code;
-
- struct RastPort rp; /* <- Note actual structure, not pointer */
- register struct RastPort *myrp = &rp; /* saves some bytes & is faster */
-
- register struct IntuiMessage *msg;
-
- register struct FileHandle *out = Output();
-
- register short count, x, y; /* I _always_ have variables called x & y. Does anyone else *hate* i & j for subscripts? */
- short x1, y1, x2, y2;
-
- short tx1, tx2, ty1, ty2; /* temps for reversing box corners if need be (unused at the moment) */
-
- register BOOL drawing = FALSE;
- BOOL done = FALSE;
-
- if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",33L)))
- {
- Wrlen(out,plea);
- Wr(out,"Intuition.\n");
- goto breakpoint;
- }
-
- if (!(GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",33L)))
- {
- Wrlen(out,plea);
- Wr(out,"Graphics.\n");
- goto breakpoint;
- }
-
- if (!(LayersBase=(struct LayersBase *) OpenLibrary("layers.library",33L)))
- {
- Wrlen(out,plea);
- Wr(out,"Layers.\n");
- goto breakpoint;
- }
-
- if (!parse_args(argc,argv))
- goto breakpoint; /* error in command line */
-
- if (!initstuff())
- {
- Wr(out,"Error establishing keyboard IO\n");
- goto breakpoint;
- }
-
- if (!(w = OpenWindow(&nwindow)))
- {
- Wr(out,"Can't open window\n");
- goto breakpoint;
- }
-
- while (NOT done)
- {
- WaitPort(w->UserPort);
-
- while (msg = (struct IntuiMessage *)GetMsg(w->UserPort))
- {
- class = msg->Class;
- code = msg->Code;
- x = msg->MouseX;
- y = msg->MouseY;
-
- ReplyMsg(msg);
-
- switch(class)
- {
- case CLOSEWINDOW:
- done = TRUE;
- break;
-
- /*
- * Here is the outline for the outline routine:
- * - clicking right mouse button sets (x1,y1) point (upper left of a
- * character) and outlines that character; it also seizes control
- * of the window layer we are interested in so it won't change yet
- * - moving mouse makes box erase and then redraw; as new characters
- * are covered they will be outlined
- * - releasing the right mouse button erases the box for a final time,
- * and causes the area within the rectangle to be "read" using the
- * character bitmap compare routines
- * - the final location of the rectangle endpoints may be reversed and
- * then tweaked a bit if the rubberbanding was not left->right, top->
- * bottom (not yet)
- *
- */
-
- case MOUSEBUTTONS:
- switch(code)
- {
- case MENUDOWN:
-
- /* what was mouse clicked upon? */
-
- window = WhichWindow();
-
- if (!window)
- {
- Wr(out,"Please select a valid window.\n");
- break;
- }
-
- /* FREEZE, WINDOW! */
-
- #ifndef NOLOCK
- LockLayerRom(window->WLayer);
- #endif
- layer_locked = TRUE;
-
- /* make a copy of the rastport to bang on */
- CopyMem(window->RPort, myrp, sizeof(struct RastPort));
-
- SetDrMd(myrp, COMPLEMENT);
-
- /* figure out the exact pixels for box corners */
- compute_xy1(window, &x1, &y1);
- compute_xy2(window, &x2, &y2);
- drawing = TRUE;
- ModifyIDCMP(w, MOUSEMOVE | CLOSEWINDOW | MOUSEBUTTONS | INACTIVEWINDOW);
- do_box(myrp, x1, y1, x2, y2);
- break;
-
- case MENUUP:
- if (drawing)
- {
- drawing = FALSE;
- ModifyIDCMP(w, CLOSEWINDOW | MOUSEBUTTONS | VANILLAKEY | INACTIVEWINDOW);
- do_box(myrp, x1, y1, x2, y2);
-
- /* for actually reading from the screen, x1,y1 must be above & left x2,y2 */
-
- if ( x1+4 >= x2 ||
- y1+4 >= y2 )
- {
- free_window();
- Wr(out,"Please drag down and to the left\n");
- break;
- }
-
- interpret(myrp, x1, y1, x2, y2);
-
- /* "flash" the region to indicate we are finished */
- for (x=0; x<2; x++)
- {
- RectFill(myrp, x1, y1, x2, y2);
- Delay(10);
- }
-
- /* unlock layers */
- free_window();
-
- /* store the text in optional format */
- /* the stash routine will use all global variables */
-
- stash();
-
- FreeMem(scratch, scratchsize);
- scratch = NULL;
- }
- break;
-
- default:
- break;
- }
- break;
-
- case MOUSEMOVE:
-
- /* I'll ignore the message when I can for max speed */
-
- if ((NOT drawing) || (x != w->MouseX) || (y != w->MouseY))
- break;
-
- /* out with the old... */
- do_box(myrp, x1, y1, x2, y2);
- compute_xy2(window, &x2, &y2);
-
- /* and in with the new */
- do_box(myrp, x1, y1, x2, y2);
- break;
-
- case VANILLAKEY:
-
- switch(code)
- {
- /* Control exact placement of 8x8 square areas */
- /* [u]p, [d]own, [l]eft, [r]ight are key commands */
-
- /* (I considered h,j,k, & l but that would be Unix-snobbish :-) */
-
- case 'l':
- x_offset--;
- break;
-
- case 'r':
- x_offset++;
- break;
-
- case 'u':
- y_offset--;
- break;
-
- case 'd':
- y_offset++;
- break;
-
- /* toggle automatic activation of window after keyboard pasting */
-
- case 'a':
- reactivate = reactivate ? FALSE : TRUE;
- break;
-
- /* Control how data is to be 'pasted' */
- /* [s]tandard output, [c]lipboard, [p]ipe file are key commands */
- /* new additions for V1.2: [k]eyboard and [K]eyboard without CR's */
-
- /* Note that you can add your own save functions and use other letters to switch to them */
-
- case 'p':
- save_format = WRITE_PIPE;
- break;
-
- case 's':
- save_format = PRINT_STDOUT;
- break;
-
- case 'k':
- save_format = TYPE_KEYBOARD;
- break;
-
- case 'K':
- save_format = KEYBOARD_NOCR;
- break;
-
- case 'c':
- save_format = PASTE_CLIPBOARD;
- default:
- break;
- }
- break;
-
- default:
- break;
-
- } /* end switch class */
-
- } /* end while GetMsg */
-
- } /* end while NOT done */
-
- breakpoint:
- _abort();
- }
-
- _abort()
- {
- if (ioReq)
- if (ioReq->io_Device)
- CloseDevice(ioReq);
- DeleteStdIO(ioReq);
- if (ioPort)
- DeletePort(ioPort);
- if (layer_locked) free_window();
- if (w) CloseWindow(w);
- if (fp) Close(fp);
- if (outfilehandle) Close(outfilehandle);
- if (scratch) FreeMem(scratch, scratchsize);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- if (GfxBase) CloseLibrary(GfxBase);
- if (LayersBase) CloseLibrary(LayersBase);
- exit(0);
- }
-
- /* Always trying to save a few bytes... */
-
- free_window()
- {
- #ifndef NOLOCK
- UnlockLayerRom(window->WLayer);
- #endif
- layer_locked = FALSE;
- }
-
-