📄 xpix.shar
字号:
# This is a shell archive. Remove anything before this line, then# unpack it by saving it in a file and typing "sh file". (Files# unpacked will be owned by you and have default permissions.)## This archive contains:# check.bitmap makefile xpix.cecho x - check.bitmapsed -e 's/^X//' > "check.bitmap" << '//E*O*F check.bitmap//'X#define check_width 8X#define check_height 8Xstatic char check_bits[] = {X 0x40, 0x20, 0x20, 0x10, 0x10, 0x09, 0x0a, 0x04};//E*O*F check.bitmap//echo x - makefilesed -e 's/^X//' > "makefile" << '//E*O*F makefile//'X#X CFLAGS = -O4 -DSUN -dalign -I/msrc/apps/X11R5/includeX XLIBS = -L/msrc/apps/X11R5/lib -lXaw -lXmu -lXt -lX11 -lXau -lXdmcp -lXextXX#SUN R4X# XLIBS = -lXaw -lXmu -lXt -lX11 -lXau -lXdmcp -lXext -lXinputXXxpix: xpix.oX cc $(CFLAGS) -o xpix xpix.o $(XLIBS) -lm//E*O*F makefile//echo x - xpix.csed -e 's/^X//' > "xpix.c" << '//E*O*F xpix.c//'X#include <sys/types.h>X#include <netinet/in.h>X#include <stdio.h>X#include <string.h>XX#include "check.bitmap"XX#include <X11/Xlib.h>X#include <X11/Xutil.h>X#include <X11/StringDefs.h>X#include <X11/Intrinsic.h>X#include <X11/IntrinsicP.h>X#include <X11/Shell.h>X#include <X11/ShellP.h>X#include <X11/Xaw/Scrollbar.h>X#include <X11/Xaw/Form.h>X#include <X11/Xaw/Command.h>X#include <X11/Xaw/Label.h>X#include <X11/Xaw/MenuButton.h>X#include <X11/Xaw/SimpleMenu.h>X#include <X11/Xaw/Sme.h>X#include <X11/Xaw/SmeBSB.h>XXextern char *malloc();XX/* Globals needed for display etc. */XXstatic Widget top_level_widget, box_widget, file_menu_button, start_button,X canvas_widget, title_widget, grid_data_widget,X scroll_widget, interval_widget, file_menu;X#define n_file_menu_entries 3Xstatic String file_menu_entries[] = {"Tail ","Cycle ","Quit"};Xstatic Widget file_menu_widgets[n_file_menu_entries];Xstatic Pixmap check_mark;Xstatic Arg arg[25]; Xstatic Display *display;Xstatic Window window;Xstatic int screen, depth;Xstatic Visual *visual;Xstatic XtIntervalId timer;Xstatic XImage *image;Xstatic u_char *pict;Xstatic GC gc;Xstatic char title[80];Xstatic char grid_data[80];Xstatic char interval_string[10];XXstatic long first_time = True; /* Used to set scroll bar on first expose */Xstatic long interval_max = 2000;Xstatic long interval = 500; /* 0.5s between exposures by default */XXstatic int tail_mode = False; /* By default cycle thru framesX instead of tailing a file */XX#define MAX(a,b) (((a)>(b)) ? (a) : (b))X#define MIN(a,b) (((a)<(b)) ? (a) : (b))XX#define MAX_COL 64Xstatic u_char cmap[MAX_COL];XXXstatic int n_grid = 0; /* The number of the current grid */Xstatic int grid_size; /* The size of the current grid */Xstatic int max_grid_size=-1; /* Size of the largest grid */XX#define PICT_SIZE max_grid_sizeXXstatic u_char *grid;Xstatic int working = False;XXvoid Error(string, integer)X char *string;X int integer;X{X (void) fflush(stdout);X (void) fprintf(stderr,"\n\nError was called.\n");X (void) fprintf(stderr,string);X (void) fprintf(stderr," %d (%#x).\n",integer,integer);X exit(1);X}XX/*ARGSUSED*/Xvoid FileMenuCallback(w, pane_num, data)X Widget w;X int pane_num;X caddr_t data;X{X switch (pane_num) {X case 0: /* Tail mode */X tail_mode = True;X XtSetArg(arg[0], XtNrightBitmap, check_mark); /* Check tail */X XtSetValues(file_menu_widgets[0], arg, 1);X XtSetArg(arg[0], XtNrightBitmap, NULL); /* Un-check cycle */X XtSetValues(file_menu_widgets[1], arg, 1);X break;XX case 1: /* Cycle mode */X tail_mode = False;X XtSetArg(arg[0], XtNrightBitmap, check_mark); /* Check cycle */X XtSetValues(file_menu_widgets[1], arg, 1);X XtSetArg(arg[0], XtNrightBitmap, NULL); /* Un-check tail */X XtSetValues(file_menu_widgets[0], arg, 1);X break;XX case 2: /* Quit */X exit(0);X break;XX default:X Error("Unknown menu item", pane_num);X }X}XXint GetNextGrid(grid)X u_char *grid;X{X int n, junk, nread;X u_char *temp;XX if (fread(&grid_size, sizeof(int), 1, stdin) != 1) {X clearerr(stdin);XX if (tail_mode) {X /* In this mode just wait for next time out and try again then */X return False;X }X else {X /* Cycling ... retry at the front of the file */X n_grid = 0;X fseek(stdin, 0, 0);X (void) fread(&junk, sizeof(int), 1, stdin); /* Ignore first word */X X if (fread(&grid_size, sizeof(int), 1, stdin) != 1) {X (void) fprintf(stderr, X "GetNextGrid: Failed to read first grid size\n");X return False;X }X }X }XX grid_size = ntohl(grid_size); /* Convert to machine format */XX /* Have read the grid size so there must be a grid on the way */XX n = grid_size*grid_size;X temp = grid;XX while(n) {X nread = fread(temp, 1, n, stdin);X if (!nread) {X clearerr(stdin);X sleep(1); /* Don't be too agressive */X }X temp += nread;X n -= nread;X }X n_grid++;X return True;X}XXvoid DrawGrid(grid)X u_char *grid;X{X register int scale = max_grid_size/grid_size;X register int i,j,k,l,npix,index;X register u_char *from, *to, *tempk, *tempkl, value;XX from = grid; to = pict; /* For clarity and convenience */X X if (scale > 1) {X for (i=0; i<grid_size; i++)X for (j=0; j<grid_size; j++) {X to = pict + (i*max_grid_size + j)*scale;XX index = *from++;X value = cmap[MIN(index,MAX_COL)];X X for (k=0, tempk=to; k<scale; k++, tempk+=max_grid_size)X for (l=0, tempkl=tempk; l<scale; l++, tempkl++)X *tempkl = value;X }X }X else {X npix = grid_size * grid_size;X while (npix--) {X index = *from++;X *to++ = cmap[MIN(index,MAX_COL)];X }X }XX XPutImage(display, window, gc, image, 0, 0, 0, 0, X image->width, image->height);X (void) sprintf(grid_data, "Grid %d (%d x %d)",X n_grid, grid_size, grid_size);X X XtSetArg(arg[0], XtNlabel, grid_data); /* Reset the grid data */X XtSetValues(grid_data_widget,arg,1);X XFlush(display);X}XXvoid DisplayIntervalValue()X{X (void) sprintf(interval_string, "%4d ms", interval);X XtSetArg(arg[0], XtNlabel, interval_string);X XtSetValues(interval_widget,arg,1);X}XX/*ARGSUSED*/Xvoid ScrollProc(scrollbar, data, position)X Widget scrollbar;X caddr_t data;X caddr_t position;X/*X Called when the left or right buttons are used to step theX scrollbar left or right. We have the responsibility ofX moving the scrollbar.X*/X{X Dimension length;X float fraction, shown;XX /* Get the scrollbar length and move the scroll bar */XX XtSetArg(arg[0], XtNlength, &length);X XtGetValues(scrollbar, arg, 1);X fraction = ((int) position)/ (double) length;XX interval -= fraction*0.05*interval_max; X interval = MIN(interval, interval_max);X interval = MAX(interval, 1);XX fraction = (float) interval/ (float) interval_max;X shown = -1.0;XX DisplayIntervalValue();X XawScrollbarSetThumb(scrollbar, fraction, shown);X}XX/*ARGSUSED*/Xvoid JumpProc(scrollbar, data, fraction_ptr)X Widget scrollbar;X caddr_t data;X caddr_t fraction_ptr;X/*X Called when the middle button is used to drag to X the scrollbar. The scrollbar is moved for us.X*/X{X float fraction = *(float *) fraction_ptr;XX interval = fraction*interval_max;X interval = MIN(interval, interval_max);X interval = MAX(interval, 1);XX DisplayIntervalValue();X}XX/*ARGSUSED*/Xvoid Exposed(widget, data, event)X Widget widget;X caddr_t data;X XEvent *event;X{X /* Now we are exposed we can draw ... only if we have a grid! */XX if (first_time) {X /* Cannot seem to set this before now ? */X ScrollProc(scroll_widget, NULL, 0);X first_time = False;X }XX if (n_grid)X DrawGrid(grid);X}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -