📄 range.c
字号:
/* * * ENTROPIC PROCESSING, INC. * * This material contains proprietary software of Entropic * Processing, Inc. Any reproduction, distribution, or * publication without the the prior written permission of * Entropic Processing, Inc. is strictly prohibited. Any * public distribution of copies of this work authorized in * writing by Entropic Processing, Inc. must bear the notice * * "Copyright 1986 Entropic Processing, Inc." * * mouse_plot - Program to select a range using the mouse on a * MASSCOMP Workstation. * * Written by: Ajaipal S. Virdy on 9/2/86 * * */#ifdef SCCS static char *sccs_id = "@(#)range.c 1.2 9/29/86 EPI";#endif#include <stdio.h>#include <sps/param.h>#define TRUE 1#define FALSE 0#define ESC '\033'#define CLEAR {putchar(ESC);putchar('['); \ putchar('2');putchar('K');}#define HOMECLR {putchar(ESC);putchar('['); \ putchar('2');putchar('J');}#define HOME {putchar(ESC);putchar('[');putchar('H');}#define RIGHT 1#define MIDDLE 2#define LEFT 4#define FOREVER for(;;)#define THISPROG "range"int beginplot; /* read from SPS Common file */int endplot; /* read from SPS Common file */int points;int new_start; /* new start point selected */int new_nan; /* new nan point selected */int fflush();static int standard_x = 1;static int standard_y = 1; static short standard_cursor[16] = /* looks like an arrow */ { 0x0000, 0x4000, 0x6000, 0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00, 0x7f80, 0x7c00, 0x6c00, 0x4600, 0x0600, 0x0000, 0x0000, 0x0000 };main(){ int x, /* x coordinate of current mouse position */ y; /* y coordinate of current mouse position */ int button, /* button state */ handle, /* handle of window */ w, /* width of window */ h; /* height or window */ int x_start, /* start point on abscissa */ y_start; /* start point on ordinate */ int old_x = 0, /* previous x location */ old_y = 0; /* previous y location */ int i = 1; int button1_up = TRUE; /* LEFT button position */ int button2_up = TRUE; /* MIDDLE button position */ int location; /* location on abscisa */ int click = 0; /* number of times mouse has been clicked */ int x0, /* origin of graph x-coordinate */ y0; /* origin of graph y-coordinate */ int x_final, /* endpoint of graph x-coordinate */ y_final; /* endpoint of graph y-coordinate */ /* Start a loop to get button input and to * print coordinates. */ (void) read_params (NULL,SC_CHECK_FILE,NULL); if(symtype("beginplot")==ST_UNDEF || symtype("endplot")==ST_UNDEF) { fprintf(stderr,"range: no beginplot or endplot in Common file\n"); exit(1); } beginplot = getsym_i ("beginplot"); endplot = getsym_i ("endplot"); points = endplot - beginplot + 1; winloadcur16( standard_x, standard_y, standard_cursor ); wincurlife( 1 ); HOME while ( button1_up ) { CLEAR if (click == 0) printf ("Click on the origin with the left mouse button."); else printf ("Now click on the endpoint with the left mouse button."); fflush (stdout); wincurgetwait( &x, &y, &button ); if ( button == 4 ) { if ( click == 0 ) { /* first mouse click */ x0 = x; y0 = y; click = 1; } else { /* second mouse click */ x_final = x; y_final = y; button1_up = FALSE; } } } fflush (stdout);RESTART: HOME CLEAR printf ("Now click start point with left button.\n"); printf ("(middle button to save range and exit, right button to reselect range)\n"); fflush (stdout); button1_up = TRUE; while (button1_up) { wincurgetwait( &x, &y, &button ); if ( button == 4 ) { x_start = x; y_start = y; button1_up = FALSE; } } new_start = beginplot + (points * (x_start - x0) / (x_final - x0)); while (button2_up) { /* Print coordinates at button signal. */ wincurget( &x, &y, &button ); if ( (x != old_x) || (y != old_y) ) { CLEAR if ( (x < x_start) || (x > x_final) ) printf ("OUT OF RANGE"); else { new_nan = beginplot + (points * (x - x0) / (x_final - x0)); printf ("Range selected is from %d to %d", new_start, new_nan); } fflush (stdout); old_x = x; old_y = y; } switch (button) { case RIGHT: CLEAR goto RESTART; break; case MIDDLE: { if (putsym_i("start", new_start) == -1) (void) fprintf (stderr, "%s: could not write into SPS Common file.\n", THISPROG); if (putsym_i("nan", new_nan - new_start + 1) == -1) (void) fprintf (stderr, "%s: could not write into SPS Common file.\n", THISPROG); button2_up = FALSE; } break; case LEFT: break; default: break; } } printf ("\n"); exit( 0 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -