home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-27 | 48.3 KB | 2,195 lines |
- Newsgroups: comp.sources.misc
- From: gershon%gr@cs.utah.edu (Elber Gershon)
- Subject: v24i034: gnuplot3 - interactive function plotting utility, Part12/26
- Message-ID: <1991Oct28.002205.12201@sparky.imd.sterling.com>
- X-Md4-Signature: 3f999071314b466d682c87a1be3fbcac
- Date: Mon, 28 Oct 1991 00:22:05 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: gershon%gr@cs.utah.edu (Elber Gershon)
- Posting-number: Volume 24, Issue 34
- Archive-name: gnuplot3/part12
- Environment: UNIX, MS-DOS, VMS
- Supersedes: gnuplot2: Volume 11, Issue 65-79
-
- #!/bin/sh
- # this is Part.12 (part 12 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file gnuplot/readline.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 12; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping gnuplot/readline.c'
- else
- echo 'x - continuing file gnuplot/readline.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'gnuplot/readline.c' &&
- X while((cur_pos > 0) &&
- X (cur_line[cur_pos-1] == SPACE)) {
- X cur_pos -= 1;
- X putc(BACKSPACE, stderr);
- X }
- X while((cur_pos > 0) &&
- X (cur_line[cur_pos-1] != SPACE)) {
- X cur_pos -= 1;
- X putc(BACKSPACE, stderr);
- X }
- X clear_eoline();
- X max_pos = cur_pos;
- X break;
- X break;
- X case '\n': /* ^J */
- X case '\r': /* ^M */
- X cur_line[max_pos+1] = '\0';
- X putc('\n', stderr);
- X new_line = malloc(strlen(cur_line)+1);
- X strcpy(new_line,cur_line);
- X reset_termio();
- X return(new_line);
- X default:
- X break;
- X }
- X }
- X }
- }
- X
- /* fix up the line from cur_pos to max_pos */
- /* do not need any terminal capabilities except backspace,
- /* and space overwrites a character */
- static void
- fix_line()
- {
- X int i;
- X
- X /* write tail of string */
- X for(i=cur_pos; i<max_pos; i++)
- X putc(cur_line[i], stderr);
- X
- X /* write a space at the end of the line in case we deleted one */
- X putc(SPACE, stderr);
- X
- X /* backup to original position */
- X for(i=max_pos+1; i>cur_pos; i--)
- X putc(BACKSPACE, stderr);
- X
- }
- X
- /* redraw the entire line, putting the cursor where it belongs */
- static void
- redraw_line(prompt)
- char *prompt;
- {
- X int i;
- X
- X fputs(prompt, stderr);
- X fputs(cur_line, stderr);
- X
- X /* put the cursor where it belongs */
- X for(i=max_pos; i>cur_pos; i--)
- X putc(BACKSPACE, stderr);
- }
- X
- /* clear cur_line and the screen line */
- static void
- clear_line(prompt)
- char *prompt;
- {
- X int i;
- X for(i=0; i<max_pos; i++)
- X cur_line[i] = '\0';
- X
- X for(i=cur_pos; i>0; i--)
- X putc(BACKSPACE, stderr);
- X
- X for(i=0; i<max_pos; i++)
- X putc(SPACE, stderr);
- X
- X putc('\r', stderr);
- X fputs(prompt, stderr);
- X
- X cur_pos = 0;
- X max_pos = 0;
- }
- X
- /* clear to end of line and the screen end of line */
- static void
- clear_eoline(prompt)
- char *prompt;
- {
- X int i;
- X for(i=cur_pos; i<max_pos; i++)
- X cur_line[i] = '\0';
- X
- X for(i=cur_pos; i<max_pos; i++)
- X putc(SPACE, stderr);
- X for(i=cur_pos; i<max_pos; i++)
- X putc(BACKSPACE, stderr);
- }
- X
- /* copy line to cur_line, draw it and set cur_pos and max_pos */
- static void
- copy_line(line)
- char *line;
- {
- X strcpy(cur_line, line);
- X fputs(cur_line, stderr);
- X cur_pos = max_pos = strlen(cur_line);
- }
- X
- /* add line to the history */
- void
- add_history(line)
- char *line;
- {
- X struct hist *entry;
- X entry = (struct hist *)malloc(sizeof(struct hist));
- X entry->line = malloc((unsigned int)strlen(line)+1);
- X strcpy(entry->line, line);
- X
- X entry->prev = history;
- X entry->next = NULL;
- X if(history != NULL) {
- X history->next = entry;
- X }
- X history = entry;
- }
- X
- #ifdef MSDOS
- X
- /* Convert Arrow keystrokes to Control characters: */
- static char
- msdos_getch()
- {
- X char c = getch();
- X
- X if (c == 0) {
- X c = getch(); /* Get the extended code. */
- X switch (c) {
- X case 75: /* Left Arrow. */
- X c = 002;
- X break;
- X case 77: /* Right Arrow. */
- X c = 006;
- X break;
- X case 72: /* Up Arrow. */
- X c = 020;
- X break;
- X case 80: /* Down Arrow. */
- X c = 016;
- X break;
- X case 115: /* Ctl Left Arrow. */
- X case 71: /* Home */
- X c = 001;
- X break;
- X case 116: /* Ctl Right Arrow. */
- X case 79: /* End */
- X c = 005;
- X break;
- X case 83: /* Delete */
- X c = 004;
- X break;
- X default:
- X c = 0;
- X break;
- X }
- X }
- X else if (c == 033) { /* ESC */
- X c = 025;
- X }
- X
- X
- X return c;
- }
- X
- #endif /* MSDOS */
- X
- /* set termio so we can do our own input processing */
- static void
- set_termio()
- {
- #ifndef MSDOS
- X if(term_set == 0) {
- #ifdef TERMIOS
- #ifdef TCGETS
- X ioctl(0, TCGETS, &orig_termio);
- #else
- X tcgetattr(0, &orig_termio);
- #endif /* TCGETS */
- #else
- X ioctl(0, TCGETA, &orig_termio);
- #endif /* TERMIOS */
- X rl_termio = orig_termio;
- X
- X rl_termio.c_iflag &= ~(BRKINT|PARMRK|INPCK|IUCLC|IXON|IXOFF);
- X rl_termio.c_iflag |= (IGNBRK|IGNPAR);
- X
- X rl_termio.c_oflag &= ~(ONOCR);
- X
- X rl_termio.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|NOFLSH);
- X rl_termio.c_lflag |= (ISIG);
- X
- X rl_termio.c_cc[VMIN] = 1;
- X rl_termio.c_cc[VTIME] = 0;
- X
- #ifdef VSUSP
- X /* disable suspending process on ^Z */
- X rl_termio.c_cc[VSUSP] = 0;
- #endif /* VSUSP */
- X
- #ifdef TERMIOS
- #ifdef TCSETSW
- X ioctl(0, TCSETSW, &rl_termio);
- #else
- X tcsetattr(0, TCSADRAIN, &rl_termio);
- #endif /* TCSETSW */
- #else
- X ioctl(0, TCSETAW, &rl_termio);
- #endif /* TERMIOS */
- X term_set = 1;
- X }
- #endif /* MSDOS */
- }
- X
- static void
- reset_termio()
- {
- #ifndef MSDOS
- X if(term_set == 1) {
- #ifdef TERMIOS
- #ifdef TCSETSW
- X ioctl(0, TCSETSW, &orig_termio);
- #else
- X tcsetattr(0, TCSADRAIN, &orig_termio);
- #endif /* TCSETSW */
- #else
- X ioctl(0, TCSETAW, &orig_termio);
- #endif /* TERMIOS */
- X term_set = 0;
- X }
- #endif /* MSDOS */
- }
- #endif /* READLINE */
- SHAR_EOF
- echo 'File gnuplot/readline.c is complete' &&
- chmod 0644 gnuplot/readline.c ||
- echo 'restore of gnuplot/readline.c failed'
- Wc_c="`wc -c < 'gnuplot/readline.c'`"
- test 12274 -eq "$Wc_c" ||
- echo 'gnuplot/readline.c: original size 12274, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/help.h ==============
- if test -f 'gnuplot/help.h' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/help.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/help.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/help.h' &&
- /* GNUPLOT - help.h */
- /*
- X * Copyright (C) 1986, 1987, 1990, 1991 Thomas Williams, Colin Kelley
- X *
- X * Permission to use, copy, and distribute this software and its
- X * documentation for any purpose with or without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and
- X * that both that copyright notice and this permission notice appear
- X * in supporting documentation.
- X *
- X * Permission to modify the software is granted, but not the right to
- X * distribute the modified code. Modifications are to be distributed
- X * as patches to released version.
- X *
- X * This software is provided "as is" without express or implied warranty.
- X *
- X *
- X * AUTHORS
- X *
- X * Original Software:
- X * Thomas Williams, Colin Kelley.
- X *
- X * Gnuplot 2.0 additions:
- X * Russell Lang, Dave Kotz, John Campbell.
- X *
- X * Gnuplot 3.0 additions:
- X * Gershon Elber and many others.
- X *
- X * Send your comments or suggestions to
- X * pixar!info-gnuplot@sun.com.
- X * This is a mailing list; to join it send a note to
- X * pixar!info-gnuplot-request@sun.com.
- X * Send bug reports to
- X * pixar!bug-gnuplot@sun.com.
- X */
- X
- /* Exit status returned by help() */
- #define H_FOUND 0 /* found the keyword */
- #define H_NOTFOUND 1 /* didn't find the keyword */
- #define H_ERROR (-1) /* didn't find the help file */
- X
- extern void FreeHelp(); /* use this if you need memory */
- SHAR_EOF
- chmod 0666 gnuplot/help.h ||
- echo 'restore of gnuplot/help.h failed'
- Wc_c="`wc -c < 'gnuplot/help.h'`"
- test 1383 -eq "$Wc_c" ||
- echo 'gnuplot/help.h: original size 1383, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/hrcgraph.asm ==============
- if test -f 'gnuplot/hrcgraph.asm' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/hrcgraph.asm (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/hrcgraph.asm (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/hrcgraph.asm' &&
- TITLE Hercules graphics module
- X
- ; Michael Gordon - 8-Dec-86
- ;
- ; Certain routines were taken from the Hercules BIOS of Dave Tutelman - 8/86
- ; Others came from pcgraph.asm included in GNUPLOT by Colin Kelley
- ;
- ; modified slightly by Colin Kelley - 22-Dec-86
- ; added header.mac, parameterized declarations
- ; added dgroup: in HVmodem to reach HCh_Parms and HGr_Parms - 30-Jan-87
- ; modified by Russell Lang 3 Jun 1988
- ; added H_init
- X
- include header.mac
- X
- if1
- include lineproc.mac
- endif
- X
- X
- GPg1_Base equ 0B800h ; Graphics page 1 base address
- X
- _text segment
- X
- X public _H_line, _H_color, _H_mask, _HVmode, _H_puts
- X public _H_init
- X
- HCfg_Switch equ 03BFH ; Configuration Switch - software switch
- X ; to select graphics card memory map
- X
- beginproc _H_init
- X mov al, 03H ; allow graphics in b8000:bffff
- X mov dx, HCfg_Switch
- X out dx, al
- X ret
- _H_init endp
- X
- hpixel proc near
- X ror word ptr bmask,1
- X jc cont
- X ret
- cont:
- X push ax
- X push bx
- X push cx
- X push dx
- X push si
- X mov cx,ax ; x
- X mov dx,bx ; y
- ;
- ; [couldn't this be done faster with a lookup table? -cdk]
- ;
- X ; first compute the address of byte to be modified
- X ; = 90*[row/4] + [col/8] + 2^D*[row/4] + 2^F*page
- X mov bh,cl ; col (low order) in BH
- X mov bl,dl ; row (low order) in BL
- X and bx,0703H ; mask the col & row remainders
- IFDEF iAPX286
- X shr cx,3 ; col / 8
- X shr dx,2 ; row / 4
- X mov al,90
- X mul dx ; AX = 90*[ row/4 ]
- X add ax,cx ; ... + col/8
- X shl bl,5 ; align row remainder
- ELSE ; same as above, obscure but fast for 8086
- X shr cx,1 ; divide col by 8
- X shr cx,1
- X shr cx,1
- X shr dx,1 ; divide row by 4
- X shr dx,1
- X shl dx,1 ; begin fast multiply by 90 (1011010 B)
- X mov ax,dx
- X shl dx,1
- X shl dx,1
- X add ax,dx
- X shl dx,1
- X add ax,dx
- X shl dx,1
- X shl dx,1
- X add ax,dx ; end fast multiply by 90
- X add ax,cx ; add on the col/8
- X shl bl,1 ; align row remainder
- X shl bl,1
- X shl bl,1
- X shl bl,1
- X shl bl,1
- ENDIF
- X add ah,bl ; use aligned row remainder
- end_adr_calc: ; address of byte is now in AX
- X mov dx,GPg1_Base ; base of pixel display to DX
- X mov es,dx ; ...and thence to segment reg
- X mov si,ax ; address of byte w/ pixel to index reg
- X mov cl,bh ; bit addr in byte
- X mov al,80H ; '1000 0000' in AL
- X shr al,cl ; shift mask to line up with bit to read/write
- set_pix: ; set the pixel
- X or es:[si],al ; or the mask with the right byte
- X pop si
- X pop dx
- X pop cx
- X pop bx
- X pop ax
- X ret
- hpixel endp
- X
- lineproc _H_line, hpixel
- X
- ;
- ; clear - clear page 1 of the screen buffer to zero (effectively, blank
- ; the screen)
- ;
- clear proc near
- X push es
- X push ax
- X push cx
- X push di
- X mov ax, GPg1_Base
- X mov es, ax
- X xor di, di
- X mov cx, 4000h
- X xor ax, ax
- X cld
- X rep stosw ; zero out screen page
- X pop di
- X pop cx
- X pop ax
- X pop es
- X ret
- clear endp
- X
- beginproc _H_color
- X push bp
- X mov bp,sp
- X mov al,[bp+X] ; color
- X mov byte ptr color,al
- X pop bp
- X ret
- _H_color endp
- X
- beginproc _H_mask
- X push bp
- X mov bp,sp
- X mov ax,[bp+X] ; mask
- X mov word ptr bmask,ax
- X pop bp
- X ret
- _H_mask endp
- X
- HCtrl_Port equ 03B8H ; Hercules 6845 control port IO addr
- HIndx_Port equ 03B4H ; Hercules 6845 index port IO addr
- HScrn_Enable equ 008h ; Control port bit to enable video
- HCh_Mode equ 020h ; Character output mode
- HGr_Mode equ 082h ; Graphics output mode page 1
- X
- parm_count equ 12
- X
- beginproc _HVmode
- X push bp
- X mov bp, sp
- X push si
- X mov ax, [bp+X]
- X or ah, al
- X mov al, HCh_Mode ; Assume character mode is wanted
- X mov si, offset dgroup:HCh_Parms
- X cmp ah, 0 ; nonzero means switch to graphics
- X jz vmode_ok
- X call near ptr clear ; clear the graphics page
- X mov al, HGr_Mode
- X mov si, offset dgroup:HGr_Parms
- vmode_ok:
- X mov dx, HCtrl_Port
- X out dx, al ; Set Hercules board to proper mode
- X call near ptr setParms ; Set the 6845 parameters
- X or al, HScrn_Enable ; Enable the video output
- X out dx, al
- X pop si
- X pop bp
- X ret
- _HVmode endp
- X
- setParms proc near ; Send 6845 parms to Hercules board
- X push ax
- X push dx
- X push si
- X mov dx, HIndx_Port ; Index port addr -> DX
- X mov ah, 0 ; 0 -> parameter counter
- sp_loop:
- X mov al, ah
- X out dx, al ; output to 6845 addr register
- X inc dx ; next output to data register
- X mov al, [si] ; next control byte -> al
- X inc si
- X out dx, al ; output control byte
- X dec dx ; 6845 index addr -> dx
- X inc ah ; bump addr
- X cmp ah, parm_count
- X jnz sp_loop
- X pop si
- X pop dx
- X pop ax
- X ret
- setParms endp
- X
- ; H_puts - print text in graphics mode
- ;
- ; cx = row
- ; bx = column
- ; si = address of string (null terminated) to print
- X
- beginproc _H_puts
- X push bp
- X mov bp, sp
- X push si
- X push ds
- X mov si, [bp+X] ; string offset
- X
- ifdef LARGE_DATA
- X mov ds, [bp+X+2] ; string segment
- X mov cx, [bp+X+4] ; row
- X mov bx, [bp+X+6] ; col
- else
- X mov cx, [bp+X+2] ; row
- X mov bx, [bp+X+4] ; col
- endif
- X
- ploop: lodsb ; get next char
- X or al, al ; end of display?
- X je pdone
- X call near ptr display
- X inc bx ; bump to next column
- X jmp ploop
- pdone: pop ds
- X pop si
- X pop bp
- X ret
- _H_puts endp
- X
- ;
- ; display - output an 8x8 character from the IBM ROM to the Herc board
- ;
- ; AX = char, BX = column (0-89), CX = row(0-42) ** all preserved **
- ;
- CON8 db 8
- CON180 db 180
- IBMROM equ 0F000h
- CHARTAB equ 0FA6Eh
- X
- display proc near
- X push ds ; save the lot
- X push es
- X push ax
- X push bx
- X push cx
- X push dx
- X push si
- X push di
- X
- ; setup ds -> IBM ROM, and si -> index into IBM ROM character table located
- ; at 0fa6eh in the ROM
- X
- X and ax, 07fh
- X mul cs:CON8 ; mult by 8 bytes of table per char
- X mov si, ax
- X mov ax, IBMROM
- X mov ds, ax
- X assume ds:nothing
- X add si, CHARTAB ; add offset of character table
- X
- ; compute index into Hercules screen memory for scan line 0. The remaining
- ; seven scan lines are all at fixed offsets from the first.
- ;
- ; Since graphics mode treats the screen as sets of 16x4 "characters",
- ; we need to map an 8x8 real character onto the front or back of
- ; a pair of graphics "characters". The first four scan lines of our
- ; 8x8 character will map to the top graphics "character", and the second
- ; four scan lines map to the graphics character on the "line" (4 scan
- ; lines high) below it.
- ;
- ; For some exotic hardware reason (probably speed), all scan line 0
- ; bits (i.e. every fourth scan line) are stored in memory locations
- ; 0-2000h in the screen buffer. All scan line 1 bits are stored
- ; 2000h-4000h. Within these banks, they are stored by rows. The first
- ; scan line on the screen (scan line 0 of graphics character row 0)
- ; is the first 45 words of memory in the screen buffer. The next 45
- ; words are the first scan line graphics row 1, and since graphics
- ; "characters" are 4 bits high, this second scan line is physically
- ; the fifth scan line displayed on the screen.
- ;
- ; SO, to display an 8x8 character, the 1st and 5th rows of dots are
- ; both scan line 0 of the graphics "character", the 2nd and 6th are
- ; scan line 1, and so on.
- ;
- ; The column (0-89) tells which byte in a scan line we need to load.
- ; Since it takes two rows of graphics characters to hold one row of
- ; our characters, column+90 is a index to scan line 4 rows of pixels
- ; higher (n+4). Thus 180 bytes of screen memory in any bank (0h, 2000h,
- ; 4000h, 6000h) represent a row of 8x8 characters.
- ;
- ; The starting location in screen memory for the first scan line of
- ; a character to be displayed will be: (row*180)+column
- ; The 5th scan line will be at: (row*180)+column+90
- ;
- ; The second and 6th scan lines will be at the above offsets plus
- ; the bank offset of 2000h. The third and 7th, add 4000h and finally
- ; the 4th and 8th, add 6000h.
- ;
- X mov ax, GPg1_Base
- X mov es, ax ; es = hercules page 0
- X mov ax, cx ; get row
- X mul cs:CON180 ; mult by 180(10)
- X mov di, ax ; di = index reg
- X cld ; insure right direction
- X
- ;output 8 segments of character to video ram
- X
- X lodsb ; line 0
- X mov es:[di+bx], al
- X lodsb
- X mov es:[di+bx+2000h], al ; line 1
- X lodsb
- X mov es:[di+bx+4000h], al ; line 2
- X lodsb
- X mov es:[di+bx+6000h], al ; line 3
- X lodsb
- X mov es:[di+bx+90], al ; line 4
- X lodsb
- X mov es:[di+bx+2000h+90], al ; line 5
- X lodsb
- X mov es:[di+bx+4000h+90], al ; line 6
- X lodsb
- X mov es:[di+bx+6000h+90], al ; line 7
- X
- X pop di
- X pop si
- X pop dx
- X pop cx
- X pop bx
- X pop ax
- X pop es
- X pop ds
- X ret
- display endp
- X
- _text ends
- X
- _data segment
- bmask dw -1
- color db 1
- _data ends
- X
- const segment
- HCh_Parms db 61H, 50H, 52H, 0FH, 19H, 06H, 19H, 19H, 02H, 0DH, 0BH, 0CH
- HGr_Parms db 35H, 2DH, 2EH, 07H, 5BH, 02H, 57H, 57H, 02H, 03H, 00H, 00H
- const ends
- X
- X end
- X
- X
- SHAR_EOF
- chmod 0666 gnuplot/hrcgraph.asm ||
- echo 'restore of gnuplot/hrcgraph.asm failed'
- Wc_c="`wc -c < 'gnuplot/hrcgraph.asm'`"
- test 8192 -eq "$Wc_c" ||
- echo 'gnuplot/hrcgraph.asm: original size 8192, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/internal.c ==============
- if test -f 'gnuplot/internal.c' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/internal.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/internal.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/internal.c' &&
- /* GNUPLOT - internal.c */
- /*
- X * Copyright (C) 1986, 1987, 1990, 1991 Thomas Williams, Colin Kelley
- X *
- X * Permission to use, copy, and distribute this software and its
- X * documentation for any purpose with or without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and
- X * that both that copyright notice and this permission notice appear
- X * in supporting documentation.
- X *
- X * Permission to modify the software is granted, but not the right to
- X * distribute the modified code. Modifications are to be distributed
- X * as patches to released version.
- X *
- X * This software is provided "as is" without express or implied warranty.
- X *
- X *
- X * AUTHORS
- X *
- X * Original Software:
- X * Thomas Williams, Colin Kelley.
- X *
- X * Gnuplot 2.0 additions:
- X * Russell Lang, Dave Kotz, John Campbell.
- X *
- X * Gnuplot 3.0 additions:
- X * Gershon Elber and many others.
- X *
- X * Send your comments or suggestions to
- X * pixar!info-gnuplot@sun.com.
- X * This is a mailing list; to join it send a note to
- X * pixar!info-gnuplot-request@sun.com.
- X * Send bug reports to
- X * pixar!bug-gnuplot@sun.com.
- X */
- X
- #include <math.h>
- #include <stdio.h>
- #include "plot.h"
- X
- BOOLEAN undefined;
- X
- char *strcpy();
- X
- struct value *pop(), *complex(), *integer();
- double magnitude(), angle(), real();
- X
- struct value stack[STACK_DEPTH];
- X
- int s_p = -1; /* stack pointer */
- X
- X
- /*
- X * System V and MSC 4.0 call this when they wants to print an error message.
- X * Don't!
- X */
- #ifdef MSDOS
- #ifdef __TURBOC__
- int matherr() /* Turbo C */
- #else
- int matherr(x) /* MSC 5.1 */
- struct exception *x;
- #endif /* TURBOC */
- #else /* not MSDOS */
- #ifdef apollo
- int matherr(struct exception *x) /* apollo */
- #else /* apollo */
- #ifdef AMIGA_LC_5_1
- int matherr(x) /* AMIGA_LC_5_1 */
- struct exception *x;
- #else /* Most everyone else (not apollo). */
- int matherr()
- #endif /* AMIGA_LC_5_1 */
- #endif /* apollo */
- #endif /* MSDOS */
- {
- X return (undefined = TRUE); /* don't print error message */
- }
- X
- X
- reset_stack()
- {
- X s_p = -1;
- }
- X
- X
- check_stack() /* make sure stack's empty */
- {
- X if (s_p != -1)
- X fprintf(stderr,"\nwarning: internal error--stack not empty!\n");
- }
- X
- X
- struct value *pop(x)
- struct value *x;
- {
- X if (s_p < 0 )
- X int_error("stack underflow",NO_CARET);
- X *x = stack[s_p--];
- X return(x);
- }
- X
- X
- push(x)
- struct value *x;
- {
- X if (s_p == STACK_DEPTH - 1)
- X int_error("stack overflow",NO_CARET);
- X stack[++s_p] = *x;
- }
- X
- X
- #define ERR_VAR "undefined variable: "
- X
- f_push(x)
- union argument *x; /* contains pointer to value to push; */
- {
- static char err_str[sizeof(ERR_VAR) + MAX_ID_LEN] = ERR_VAR;
- struct udvt_entry *udv;
- X
- X udv = x->udv_arg;
- X if (udv->udv_undef) { /* undefined */
- X (void) strcpy(&err_str[sizeof(ERR_VAR) - 1], udv->udv_name);
- X int_error(err_str,NO_CARET);
- X }
- X push(&(udv->udv_value));
- }
- X
- X
- f_pushc(x)
- union argument *x;
- {
- X push(&(x->v_arg));
- }
- X
- X
- f_pushd1(x)
- union argument *x;
- {
- X push(&(x->udf_arg->dummy_values[0]));
- }
- X
- X
- f_pushd2(x)
- union argument *x;
- {
- X push(&(x->udf_arg->dummy_values[1]));
- }
- X
- X
- #define ERR_FUN "undefined function: "
- X
- f_call(x) /* execute a udf */
- union argument *x;
- {
- static char err_str[sizeof(ERR_FUN) + MAX_ID_LEN] = ERR_FUN;
- register struct udft_entry *udf;
- struct value save_dummy;
- X
- X udf = x->udf_arg;
- X if (!udf->at) { /* undefined */
- X (void) strcpy(&err_str[sizeof(ERR_FUN) - 1],
- X udf->udf_name);
- X int_error(err_str,NO_CARET);
- X }
- X save_dummy = udf->dummy_values[0];
- X (void) pop(&(udf->dummy_values[0]));
- X
- X execute_at(udf->at);
- X udf->dummy_values[0] = save_dummy;
- }
- X
- f_call2(x) /* execute a udf of two variables */
- union argument *x;
- {
- static char err_str[sizeof(ERR_FUN) + MAX_ID_LEN] = ERR_FUN;
- register struct udft_entry *udf;
- struct value save_dummy0, save_dummy1;
- X
- X udf = x->udf_arg;
- X if (!udf->at) { /* undefined */
- X (void) strcpy(&err_str[sizeof(ERR_FUN) - 1],
- X udf->udf_name);
- X int_error(err_str,NO_CARET);
- X }
- X save_dummy1 = udf->dummy_values[1];
- X save_dummy0 = udf->dummy_values[0];
- X (void) pop(&(udf->dummy_values[1]));
- X (void) pop(&(udf->dummy_values[0]));
- X
- X execute_at(udf->at);
- X udf->dummy_values[1] = save_dummy1;
- X udf->dummy_values[0] = save_dummy0;
- }
- X
- X
- static int_check(v)
- struct value *v;
- {
- X if (v->type != INT)
- X int_error("non-integer passed to boolean operator",NO_CARET);
- }
- X
- X
- f_lnot()
- {
- struct value a;
- X int_check(pop(&a));
- X push(integer(&a,!a.v.int_val) );
- }
- X
- X
- f_bnot()
- {
- struct value a;
- X int_check(pop(&a));
- X push( integer(&a,~a.v.int_val) );
- }
- X
- X
- f_bool()
- { /* converts top-of-stack to boolean */
- X int_check(&top_of_stack);
- X top_of_stack.v.int_val = !!top_of_stack.v.int_val;
- }
- X
- X
- f_lor()
- {
- struct value a,b;
- X int_check(pop(&b));
- X int_check(pop(&a));
- X push( integer(&a,a.v.int_val || b.v.int_val) );
- }
- X
- f_land()
- {
- struct value a,b;
- X int_check(pop(&b));
- X int_check(pop(&a));
- X push( integer(&a,a.v.int_val && b.v.int_val) );
- }
- X
- X
- f_bor()
- {
- struct value a,b;
- X int_check(pop(&b));
- X int_check(pop(&a));
- X push( integer(&a,a.v.int_val | b.v.int_val) );
- }
- X
- X
- f_xor()
- {
- struct value a,b;
- X int_check(pop(&b));
- X int_check(pop(&a));
- X push( integer(&a,a.v.int_val ^ b.v.int_val) );
- }
- X
- X
- f_band()
- {
- struct value a,b;
- X int_check(pop(&b));
- X int_check(pop(&a));
- X push( integer(&a,a.v.int_val & b.v.int_val) );
- }
- X
- X
- f_uminus()
- {
- struct value a;
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X a.v.int_val = -a.v.int_val;
- X break;
- X case CMPLX:
- X a.v.cmplx_val.real =
- X -a.v.cmplx_val.real;
- X a.v.cmplx_val.imag =
- X -a.v.cmplx_val.imag;
- X }
- X push(&a);
- }
- X
- X
- f_eq() /* note: floating point equality is rare because of roundoff error! */
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val ==
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val ==
- X b.v.cmplx_val.real &&
- X b.v.cmplx_val.imag == 0.0);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (b.v.int_val == a.v.cmplx_val.real &&
- X a.v.cmplx_val.imag == 0.0);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real==
- X b.v.cmplx_val.real &&
- X a.v.cmplx_val.imag==
- X b.v.cmplx_val.imag);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_ne()
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val !=
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val !=
- X b.v.cmplx_val.real ||
- X b.v.cmplx_val.imag != 0.0);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (b.v.int_val !=
- X a.v.cmplx_val.real ||
- X a.v.cmplx_val.imag != 0.0);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real !=
- X b.v.cmplx_val.real ||
- X a.v.cmplx_val.imag !=
- X b.v.cmplx_val.imag);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_gt()
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val >
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val >
- X b.v.cmplx_val.real);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (a.v.cmplx_val.real >
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real >
- X b.v.cmplx_val.real);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_lt()
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val <
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val <
- X b.v.cmplx_val.real);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (a.v.cmplx_val.real <
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real <
- X b.v.cmplx_val.real);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_ge()
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val >=
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val >=
- X b.v.cmplx_val.real);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (a.v.cmplx_val.real >=
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real >=
- X b.v.cmplx_val.real);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_le()
- {
- struct value a, b;
- X register int result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X result = (a.v.int_val <=
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.int_val <=
- X b.v.cmplx_val.real);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X result = (a.v.cmplx_val.real <=
- X b.v.int_val);
- X break;
- X case CMPLX:
- X result = (a.v.cmplx_val.real <=
- X b.v.cmplx_val.real);
- X }
- X }
- X push(integer(&a,result));
- }
- X
- X
- f_plus()
- {
- struct value a, b, result;
- X (void) pop(&b);
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X (void) integer(&result,a.v.int_val +
- X b.v.int_val);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.int_val +
- X b.v.cmplx_val.real,
- X b.v.cmplx_val.imag);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X (void) complex(&result,b.v.int_val +
- X a.v.cmplx_val.real,
- X a.v.cmplx_val.imag);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.cmplx_val.real+
- X b.v.cmplx_val.real,
- X a.v.cmplx_val.imag+
- X b.v.cmplx_val.imag);
- X }
- X }
- X push(&result);
- }
- X
- X
- f_minus()
- {
- struct value a, b, result;
- X (void) pop(&b);
- X (void) pop(&a); /* now do a - b */
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X (void) integer(&result,a.v.int_val -
- X b.v.int_val);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.int_val -
- X b.v.cmplx_val.real,
- X -b.v.cmplx_val.imag);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X (void) complex(&result,a.v.cmplx_val.real -
- X b.v.int_val,
- X a.v.cmplx_val.imag);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.cmplx_val.real-
- X b.v.cmplx_val.real,
- X a.v.cmplx_val.imag-
- X b.v.cmplx_val.imag);
- X }
- X }
- X push(&result);
- }
- X
- X
- f_mult()
- {
- struct value a, b, result;
- X (void) pop(&b);
- X (void) pop(&a); /* now do a*b */
- X
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X (void) integer(&result,a.v.int_val *
- X b.v.int_val);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.int_val *
- X b.v.cmplx_val.real,
- X a.v.int_val *
- X b.v.cmplx_val.imag);
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X (void) complex(&result,b.v.int_val *
- X a.v.cmplx_val.real,
- X b.v.int_val *
- X a.v.cmplx_val.imag);
- X break;
- X case CMPLX:
- X (void) complex(&result,a.v.cmplx_val.real*
- X b.v.cmplx_val.real-
- X a.v.cmplx_val.imag*
- X b.v.cmplx_val.imag,
- X a.v.cmplx_val.real*
- X b.v.cmplx_val.imag+
- X a.v.cmplx_val.imag*
- X b.v.cmplx_val.real);
- X }
- X }
- X push(&result);
- }
- X
- X
- f_div()
- {
- struct value a, b, result;
- register double square;
- X (void) pop(&b);
- X (void) pop(&a); /* now do a/b */
- X
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X if (b.v.int_val)
- X (void) integer(&result,a.v.int_val /
- X b.v.int_val);
- X else {
- X (void) integer(&result,0);
- X undefined = TRUE;
- X }
- X break;
- X case CMPLX:
- X square = b.v.cmplx_val.real*
- X b.v.cmplx_val.real +
- X b.v.cmplx_val.imag*
- X b.v.cmplx_val.imag;
- X if (square)
- X (void) complex(&result,a.v.int_val*
- X b.v.cmplx_val.real/square,
- X -a.v.int_val*
- X b.v.cmplx_val.imag/square);
- X else {
- X (void) complex(&result,0.0,0.0);
- X undefined = TRUE;
- X }
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X if (b.v.int_val)
- X
- X (void) complex(&result,a.v.cmplx_val.real/
- X b.v.int_val,
- X a.v.cmplx_val.imag/
- X b.v.int_val);
- X else {
- X (void) complex(&result,0.0,0.0);
- X undefined = TRUE;
- X }
- X break;
- X case CMPLX:
- X square = b.v.cmplx_val.real*
- X b.v.cmplx_val.real +
- X b.v.cmplx_val.imag*
- X b.v.cmplx_val.imag;
- X if (square)
- X (void) complex(&result,(a.v.cmplx_val.real*
- X b.v.cmplx_val.real+
- X a.v.cmplx_val.imag*
- X b.v.cmplx_val.imag)/square,
- X (a.v.cmplx_val.imag*
- X b.v.cmplx_val.real-
- X a.v.cmplx_val.real*
- X b.v.cmplx_val.imag)/
- X square);
- X else {
- X (void) complex(&result,0.0,0.0);
- X undefined = TRUE;
- X }
- X }
- X }
- X push(&result);
- }
- X
- X
- f_mod()
- {
- struct value a, b;
- X (void) pop(&b);
- X (void) pop(&a); /* now do a%b */
- X
- X if (a.type != INT || b.type != INT)
- X int_error("can only mod ints",NO_CARET);
- X if (b.v.int_val)
- X push(integer(&a,a.v.int_val % b.v.int_val));
- X else {
- X push(integer(&a,0));
- X undefined = TRUE;
- X }
- }
- X
- X
- f_power()
- {
- struct value a, b, result;
- register int i, t, count;
- register double mag, ang;
- X (void) pop(&b);
- X (void) pop(&a); /* now find a**b */
- X
- X switch(a.type) {
- X case INT:
- X switch (b.type) {
- X case INT:
- X count = abs(b.v.int_val);
- X t = 1;
- X for(i = 0; i < count; i++)
- X t *= a.v.int_val;
- X if (b.v.int_val >= 0)
- X (void) integer(&result,t);
- X else
- X if (t != 0)
- X (void) complex(&result,1.0/t,0.0);
- X else {
- X undefined = TRUE;
- X (void) complex(&result, 0.0, 0.0);
- X }
- X break;
- X case CMPLX:
- X mag =
- X pow(magnitude(&a),fabs(b.v.cmplx_val.real));
- X if (b.v.cmplx_val.real < 0.0)
- X if (mag != 0.0)
- X mag = 1.0/mag;
- X else
- X undefined = TRUE;
- X mag *= exp(-b.v.cmplx_val.imag*angle(&a));
- X ang = b.v.cmplx_val.real*angle(&a) +
- X b.v.cmplx_val.imag*log(magnitude(&a));
- X (void) complex(&result,mag*cos(ang),
- X mag*sin(ang));
- X }
- X break;
- X case CMPLX:
- X switch (b.type) {
- X case INT:
- X if (a.v.cmplx_val.imag == 0.0) {
- X mag = pow(a.v.cmplx_val.real,(double)abs(b.v.int_val));
- X if (b.v.int_val < 0)
- X if (mag != 0.0)
- X mag = 1.0/mag;
- X else
- X undefined = TRUE;
- X (void) complex(&result,mag,0.0);
- X }
- X else {
- X /* not so good, but...! */
- X mag = pow(magnitude(&a),(double)abs(b.v.int_val));
- X if (b.v.int_val < 0)
- X if (mag != 0.0)
- X mag = 1.0/mag;
- X else
- X undefined = TRUE;
- X ang = angle(&a)*b.v.int_val;
- X (void) complex(&result,mag*cos(ang),
- X mag*sin(ang));
- X }
- X break;
- X case CMPLX:
- X mag = pow(magnitude(&a),fabs(b.v.cmplx_val.real));
- X if (b.v.cmplx_val.real < 0.0)
- X if (mag != 0.0)
- X mag = 1.0/mag;
- X else
- X undefined = TRUE;
- X mag *= exp(-b.v.cmplx_val.imag*angle(&a));
- X ang = b.v.cmplx_val.real*angle(&a) +
- X b.v.cmplx_val.imag*log(magnitude(&a));
- X (void) complex(&result,mag*cos(ang),
- X mag*sin(ang));
- X }
- X }
- X push(&result);
- }
- X
- X
- f_factorial()
- {
- struct value a;
- register int i;
- register double val;
- X
- X (void) pop(&a); /* find a! (factorial) */
- X
- X switch (a.type) {
- X case INT:
- X val = 1.0;
- X for (i = a.v.int_val; i > 1; i--) /*fpe's should catch overflows*/
- X val *= i;
- X break;
- X default:
- X int_error("factorial (!) argument must be an integer",
- X NO_CARET);
- X }
- X
- X push(complex(&a,val,0.0));
- X
- }
- X
- X
- int
- f_jump(x)
- union argument *x;
- {
- X return(x->j_arg);
- }
- X
- X
- int
- f_jumpz(x)
- union argument *x;
- {
- struct value a;
- X int_check(&top_of_stack);
- X if (top_of_stack.v.int_val) { /* non-zero */
- X (void) pop(&a);
- X return 1; /* no jump */
- X }
- X else
- X return(x->j_arg); /* leave the argument on TOS */
- }
- X
- X
- int
- f_jumpnz(x)
- union argument *x;
- {
- struct value a;
- X int_check(&top_of_stack);
- X if (top_of_stack.v.int_val) /* non-zero */
- X return(x->j_arg); /* leave the argument on TOS */
- X else {
- X (void) pop(&a);
- X return 1; /* no jump */
- X }
- }
- X
- X
- int
- f_jtern(x)
- union argument *x;
- {
- struct value a;
- X
- X int_check(pop(&a));
- X if (a.v.int_val)
- X return(1); /* no jump; fall through to TRUE code */
- X else
- X return(x->j_arg); /* go jump to FALSE code */
- }
- SHAR_EOF
- chmod 0644 gnuplot/internal.c ||
- echo 'restore of gnuplot/internal.c failed'
- Wc_c="`wc -c < 'gnuplot/internal.c'`"
- test 16092 -eq "$Wc_c" ||
- echo 'gnuplot/internal.c: original size 16092, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/command.c ==============
- if test -f 'gnuplot/command.c' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/command.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/command.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/command.c' &&
- /* GNUPLOT - command.c */
- /*
- X * Copyright (C) 1986, 1987, 1990, 1991 Thomas Williams, Colin Kelley
- X *
- X * Permission to use, copy, and distribute this software and its
- X * documentation for any purpose with or without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and
- X * that both that copyright notice and this permission notice appear
- X * in supporting documentation.
- X *
- X * Permission to modify the software is granted, but not the right to
- X * distribute the modified code. Modifications are to be distributed
- X * as patches to released version.
- X *
- X * This software is provided "as is" without express or implied warranty.
- X *
- X *
- X * AUTHORS
- X *
- X * Original Software:
- X * Thomas Williams, Colin Kelley.
- X *
- X * Gnuplot 2.0 additions:
- X * Russell Lang, Dave Kotz, John Campbell.
- X *
- X * Gnuplot 3.0 additions:
- X * Gershon Elber and many others.
- X *
- X * Send your comments or suggestions to
- X * pixar!info-gnuplot@sun.com.
- X * This is a mailing list; to join it send a note to
- X * pixar!info-gnuplot-request@sun.com.
- X * Send bug reports to
- X * pixar!bug-gnuplot@sun.com.
- X */
- X
- #include <stdio.h>
- #include <math.h>
- X
- #ifdef AMIGA_AC_5
- #include <time.h>
- void sleep(); /* defined later */
- #endif
- X
- #ifdef MSDOS
- #include <process.h>
- X
- #ifdef __ZTC__
- #define P_WAIT 0
- #include <time.h> /* usleep() */
- #else
- X
- #ifdef __TURBOC__
- #include <dos.h> /* sleep() */
- #include <conio.h>
- extern unsigned _stklen = 16394; /* increase stack size */
- X
- #else /* must be MSC */
- #include <time.h> /* kludge to provide sleep() */
- void sleep(); /* defined later */
- #endif /* TURBOC */
- #endif /* ZTC */
- X
- #endif /* MSDOS */
- X
- #ifdef AMIGA_LC_5_1
- #include <proto/dos.h>
- void sleep();
- #endif /* AMIGA_LC_5_1 */
- X
- #include "plot.h"
- #include "setshow.h"
- #include "help.h"
- X
- #ifndef STDOUT
- #define STDOUT 1
- #endif
- X
- #ifndef HELPFILE
- #ifdef AMIGA_LC_5_1
- #define HELPFILE "S:gnuplot.gih"
- #else
- #define HELPFILE "docs/gnuplot.gih" /* changed by makefile */
- #endif
- #endif
- X
- #define inrange(z,min,max) ((min<max) ? ((z>=min)&&(z<=max)) : ((z>=max)&&(z<=min)) )
- X
- /*
- X * instead of <strings.h>
- X */
- X
- extern char *gets(),*getenv();
- extern char *strcpy(),*strncpy(),*strcat();
- extern int strlen(), strcmp();
- X
- /*
- X * Only reference to contours library.
- X */
- extern struct gnuplot_contours *contour();
- X
- #if defined(unix) && !defined(hpux)
- #ifdef GETCWD
- extern char *getcwd(); /* some Unix's use getcwd */
- #else
- extern char *getwd(); /* most Unix's use getwd */
- #endif
- #else
- extern char *getcwd(); /* Turbo C, MSC and VMS use getcwd */
- #endif
- X
- #ifdef vms
- int vms_vkid; /* Virtual keyboard id */
- #endif
- X
- extern int chdir();
- X
- extern double magnitude(),angle(),real(),imag();
- extern struct value *const_express(), *pop(), *complex();
- extern struct at_type *temp_at(), *perm_at();
- extern struct udft_entry *add_udf();
- extern struct udvt_entry *add_udv();
- extern void squash_spaces();
- extern void lower_case();
- X
- /* local functions */
- static enum coord_type adjustlog();
- X
- extern BOOLEAN interactive; /* from plot.c */
- X
- /* input data, parsing variables */
- struct lexical_unit token[MAX_TOKENS];
- char input_line[MAX_LINE_LEN+1] = "";
- int num_tokens, c_token;
- int inline_num = 0; /* input line number */
- X
- char c_dummy_var[MAX_NUM_VAR][MAX_ID_LEN+1]; /* current dummy vars */
- X
- /* the curves/surfaces of the plot */
- struct curve_points *first_plot = NULL;
- struct surface_points *first_3dplot = NULL;
- static struct udft_entry plot_func;
- struct udft_entry *dummy_func;
- X
- /* support for replot command */
- char replot_line[MAX_LINE_LEN+1] = "";
- static int plot_token; /* start of 'plot' command */
- X
- /* If last plot was a 3d one. */
- BOOLEAN is_3d_plot = FALSE;
- X
- com_line()
- {
- X read_line(PROMPT);
- X
- X /* So we can flag any new output: if false at time of error, */
- X /* we reprint the command line before printing caret. */
- X /* TRUE for interactive terminals, since the command line is typed. */
- X /* FALSE for non-terminal stdin, so command line is printed anyway. */
- X /* (DFK 11/89) */
- X screen_ok = interactive;
- X
- X do_line();
- }
- X
- X
- do_line() /* also used in load_file */
- {
- X if (is_system(input_line[0])) {
- X do_system();
- X (void) fputs("!\n",stderr);
- X return;
- X }
- X num_tokens = scanner(input_line);
- X c_token = 0;
- X while(c_token < num_tokens) {
- X command();
- X if (c_token < num_tokens) /* something after command */
- X if (equals(c_token,";"))
- X c_token++;
- X else
- X int_error("';' expected",c_token);
- X }
- }
- X
- X
- X
- command()
- {
- X int i;
- X char sv_file[MAX_LINE_LEN+1];
- X /* string holding name of save or load file */
- X
- X for (i = 0; i < MAX_NUM_VAR; i++)
- X c_dummy_var[i][0] = '\0'; /* no dummy variables */
- X
- X if (is_definition(c_token))
- X define();
- X else if (almost_equals(c_token,"h$elp") || equals(c_token,"?")) {
- X c_token++;
- X do_help();
- X }
- X else if (almost_equals(c_token,"test")) {
- X c_token++;
- X test_term();
- X }
- X else if (almost_equals(c_token,"pa$use")) {
- X struct value a;
- X int stime, text=0;
- X char buf[MAX_LINE_LEN+1];
- X
- X c_token++;
- X stime = (int )real(const_express(&a));
- X if (!(END_OF_COMMAND)) {
- X if (!isstring(c_token))
- X int_error("expecting string",c_token);
- X else {
- X quotel_str(buf,c_token);
- X (void) fprintf (stderr, "%s",buf);
- X text = 1;
- X }
- X }
- X if (stime < 0) (void) fgets (buf,MAX_LINE_LEN,stdin);
- X /* Hold until CR hit. */
- #ifdef __ZTC__
- X if (stime > 0) usleep((unsigned long) stime);
- #else
- X if (stime > 0) sleep((unsigned int) stime);
- #endif
- X if (text != 0 && stime >= 0) (void) fprintf (stderr,"\n");
- X c_token++;
- X screen_ok = FALSE;
- X }
- X else if (almost_equals(c_token,"pr$int")) {
- X struct value a;
- X
- X c_token++;
- X (void) const_express(&a);
- X (void) putc('\t',stderr);
- X disp_value(stderr,&a);
- X (void) putc('\n',stderr);
- X screen_ok = FALSE;
- X }
- X else if (almost_equals(c_token,"p$lot")) {
- X plot_token = c_token++;
- X plotrequest();
- X }
- X else if (almost_equals(c_token,"sp$lot")) {
- X plot_token = c_token++;
- X plot3drequest();
- X }
- X else if (almost_equals(c_token,"rep$lot")) {
- X if (replot_line[0] == '\0')
- X int_error("no previous plot",c_token);
- X c_token++;
- X replotrequest();
- X }
- X else if (almost_equals(c_token,"se$t"))
- X set_command();
- X else if (almost_equals(c_token,"sh$ow"))
- X show_command();
- X else if (almost_equals(c_token,"cl$ear")) {
- X if (!term_init) {
- X (*term_tbl[term].init)();
- X term_init = TRUE;
- X }
- X (*term_tbl[term].graphics)();
- X (*term_tbl[term].text)();
- X (void) fflush(outfile);
- X screen_ok = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"she$ll")) {
- X do_shell();
- X screen_ok = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"sa$ve")) {
- X if (almost_equals(++c_token,"f$unctions")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_functions(fopen(sv_file,"w"));
- X }
- X }
- X else if (almost_equals(c_token,"v$ariables")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_variables(fopen(sv_file,"w"));
- X }
- X }
- X else if (almost_equals(c_token,"s$et")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_set(fopen(sv_file,"w"));
- X }
- X }
- X else if (isstring(c_token)) {
- X quote_str(sv_file,c_token);
- X save_all(fopen(sv_file,"w"));
- X }
- X else {
- X int_error(
- X "filename or keyword 'functions', 'variables', or 'set' expected",
- X c_token);
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"l$oad")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X load_file(fopen(sv_file,"r"), sv_file);
- X /* input_line[] and token[] now destroyed! */
- X c_token = num_tokens = 0;
- X }
- X }
- X else if (almost_equals(c_token,"cd")) {
- X if (!isstring(++c_token))
- X int_error("expecting directory name",c_token);
- X else {
- X quotel_str(sv_file,c_token);
- X if (chdir(sv_file)) {
- X int_error("Can't change to this directory",c_token);
- X }
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"pwd")) {
- #if defined(unix) && !defined(hpux)
- #ifdef GETCWD
- X (void) getcwd(sv_file,MAX_ID_LEN); /* some Unix's use getcwd */
- #else
- X (void) getwd(sv_file); /* most Unix's use getwd */
- #endif
- #else
- /* Turbo C and VMS have getcwd() */
- X (void) getcwd(sv_file,MAX_ID_LEN);
- #endif
- X fprintf(stderr,"%s\n", sv_file);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"ex$it") ||
- X almost_equals(c_token,"q$uit")) {
- X done(IO_SUCCESS);
- X }
- X else if (!equals(c_token,";")) { /* null statement */
- X int_error("invalid command",c_token);
- X }
- }
- X
- replotrequest()
- {
- char str[MAX_LINE_LEN+1];
- X if(equals(c_token,"["))
- X int_error("cannot set range with replot",c_token);
- X if (!END_OF_COMMAND) {
- X capture(str,c_token,num_tokens-1);
- X if ( (strlen(str) + strlen(replot_line)) <= MAX_LINE_LEN-1) {
- X (void) strcat(replot_line,",");
- X (void) strcat(replot_line,str);
- X } else {
- X int_error("plot line too long with replot arguments",c_token);
- X }
- X }
- X (void) strcpy(input_line,replot_line);
- X screen_ok = FALSE;
- X num_tokens = scanner(input_line);
- X c_token = 1; /* skip the 'plot' part */
- X is_3d_plot ? plot3drequest() : plotrequest();
- }
- X
- X
- plotrequest()
- /*
- X In the parametric case we can say
- X plot [a= -4:4] [-2:2] [-1:1] sin(a),a**2
- X while in the non-parametric case we would say only
- X plot [b= -2:2] [-1:1] sin(b)
- */
- {
- X BOOLEAN changed;
- X int dummy_token = -1;
- X
- X is_3d_plot = FALSE;
- X
- X if (parametric && strcmp(dummy_var[0], "u") == 0)
- X strcpy (dummy_var[0], "t");
- X
- X autoscale_lt = autoscale_t;
- X autoscale_lx = autoscale_x;
- X autoscale_ly = autoscale_y;
- X
- X if (!term) /* unknown */
- X int_error("use 'set term' to set terminal type first",c_token);
- X
- X if (equals(c_token,"[")) {
- X c_token++;
- X if (isletter(c_token)) {
- X if (equals(c_token+1,"=")) {
- X dummy_token = c_token;
- X c_token += 2;
- X } else {
- X /* oops; probably an expression with a variable. */
- X /* Parse it as an xmin expression. */
- X /* used to be: int_error("'=' expected",c_token); */
- X }
- X }
- X changed = parametric ? load_range(&tmin,&tmax):load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed) {
- X if (parametric)
- X autoscale_lt = FALSE;
- X else
- X autoscale_lx = FALSE;
- X }
- X }
- X
- X if (parametric && equals(c_token,"[")) { /* set optional x ranges */
- X c_token++;
- X changed = load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_lx = FALSE;
- X }
- X
- X if (equals(c_token,"[")) { /* set optional y ranges */
- X c_token++;
- X changed = load_range(&ymin,&ymax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_ly = FALSE;
- X }
- X
- X /* use the default dummy variable unless changed */
- X if (dummy_token >= 0)
- X copy_str(c_dummy_var[0],dummy_token);
- X else
- X (void) strcpy(c_dummy_var[0],dummy_var[0]);
- X
- X eval_plots();
- }
- X
- plot3drequest()
- /*
- X in the parametric case we would say
- X splot [u= -Pi:Pi] [v= 0:2*Pi] [-1:1] [-1:1] [-1:1] sin(v)*cos(u),sin(v)*cos(u),sin(u)
- X in the non-parametric case we would say only
- X splot [x= -2:2] [y= -5:5] sin(x)*cos(y)
- X
- */
- {
- X BOOLEAN changed;
- X int dummy_token0 = -1,
- X dummy_token1 = -1;
- X
- X is_3d_plot = TRUE;
- X
- X if (parametric && strcmp(dummy_var[0], "t") == 0) {
- X strcpy (dummy_var[0], "u");
- X strcpy (dummy_var[1], "v");
- X }
- X
- X autoscale_lx = autoscale_x;
- X autoscale_ly = autoscale_y;
- X autoscale_lz = autoscale_z;
- X
- X if (!term) /* unknown */
- X int_error("use 'set term' to set terminal type first",c_token);
- X
- X if (equals(c_token,"[")) {
- X c_token++;
- X if (isletter(c_token)) {
- X if (equals(c_token+1,"=")) {
- X dummy_token0 = c_token;
- X c_token += 2;
- X } else {
- X /* oops; probably an expression with a variable. */
- X /* Parse it as an xmin expression. */
- X /* used to be: int_error("'=' expected",c_token); */
- X }
- X }
- X changed = parametric ? load_range(&umin,&umax):load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed && !parametric) {
- X autoscale_lx = FALSE;
- X }
- X }
- X
- X if (equals(c_token,"[")) {
- X c_token++;
- X if (isletter(c_token)) {
- X if (equals(c_token+1,"=")) {
- X dummy_token1 = c_token;
- X c_token += 2;
- X } else {
- X /* oops; probably an expression with a variable. */
- X /* Parse it as an xmin expression. */
- X /* used to be: int_error("'=' expected",c_token); */
- X }
- X }
- X changed = parametric ? load_range(&vmin,&vmax):load_range(&ymin,&ymax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed && !parametric) {
- X autoscale_ly = FALSE;
- X }
- X }
- X
- X if (equals(c_token,"[")) { /* set optional x ranges */
- X c_token++;
- X changed = load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_lx = FALSE;
- X }
- X
- X if (equals(c_token,"[")) { /* set optional y ranges */
- X c_token++;
- X changed = load_range(&ymin,&ymax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_ly = FALSE;
- X }
- X
- X if (equals(c_token,"[")) { /* set optional z ranges */
- X c_token++;
- X changed = load_range(&zmin,&zmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_lz = FALSE;
- X }
- X
- X /* use the default dummy variable unless changed */
- X if (dummy_token0 >= 0)
- X copy_str(c_dummy_var[0],dummy_token0);
- X else
- X (void) strcpy(c_dummy_var[0],dummy_var[0]);
- X
- X if (dummy_token1 >= 0)
- X copy_str(c_dummy_var[1],dummy_token1);
- X else
- X (void) strcpy(c_dummy_var[1],dummy_var[1]);
- X
- X eval_3dplots();
- }
- X
- X
- define()
- {
- register int start_token; /* the 1st token in the function definition */
- register struct udvt_entry *udv;
- register struct udft_entry *udf;
- X
- X if (equals(c_token+1,"(")) {
- SHAR_EOF
- true || echo 'restore of gnuplot/command.c failed'
- fi
- echo 'End of part 12'
- echo 'File gnuplot/command.c is continued in part 13'
- echo 13 > _shar_seq_.tmp
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-