home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume24 / gnuplot3 / part12 < prev    next >
Text File  |  1991-10-27  |  49KB  |  2,195 lines

  1. Newsgroups: comp.sources.misc
  2. From: gershon%gr@cs.utah.edu (Elber Gershon)
  3. Subject:  v24i034:  gnuplot3 - interactive function plotting utility, Part12/26
  4. Message-ID: <1991Oct28.002205.12201@sparky.imd.sterling.com>
  5. X-Md4-Signature: 3f999071314b466d682c87a1be3fbcac
  6. Date: Mon, 28 Oct 1991 00:22:05 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: gershon%gr@cs.utah.edu (Elber Gershon)
  10. Posting-number: Volume 24, Issue 34
  11. Archive-name: gnuplot3/part12
  12. Environment: UNIX, MS-DOS, VMS
  13. Supersedes: gnuplot2: Volume 11, Issue 65-79
  14.  
  15. #!/bin/sh
  16. # this is Part.12 (part 12 of a multipart archive)
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file gnuplot/readline.c continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 12; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping gnuplot/readline.c'
  34. else
  35. echo 'x - continuing file gnuplot/readline.c'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'gnuplot/readline.c' &&
  37. X                while((cur_pos > 0) &&
  38. X                      (cur_line[cur_pos-1] == SPACE)) {
  39. X                    cur_pos -= 1;
  40. X                    putc(BACKSPACE, stderr);
  41. X                }
  42. X                while((cur_pos > 0) &&
  43. X                      (cur_line[cur_pos-1] != SPACE)) {
  44. X                    cur_pos -= 1;
  45. X                    putc(BACKSPACE, stderr);
  46. X                }
  47. X                clear_eoline();
  48. X                max_pos = cur_pos;
  49. X                break;
  50. X                break;
  51. X                case '\n': /* ^J */
  52. X                case '\r': /* ^M */
  53. X                cur_line[max_pos+1] = '\0';
  54. X                putc('\n', stderr);
  55. X                new_line = malloc(strlen(cur_line)+1);
  56. X                strcpy(new_line,cur_line);
  57. X                reset_termio();
  58. X                return(new_line);
  59. X                default:
  60. X                break;
  61. X            }
  62. X        }
  63. X    }
  64. }
  65. X
  66. /* fix up the line from cur_pos to max_pos */
  67. /* do not need any terminal capabilities except backspace,
  68. /* and space overwrites a character */
  69. static void
  70. fix_line()
  71. {
  72. X    int i;
  73. X
  74. X    /* write tail of string */
  75. X    for(i=cur_pos; i<max_pos; i++)
  76. X        putc(cur_line[i], stderr);
  77. X
  78. X    /* write a space at the end of the line in case we deleted one */
  79. X    putc(SPACE, stderr);
  80. X
  81. X    /* backup to original position */
  82. X    for(i=max_pos+1; i>cur_pos; i--)
  83. X        putc(BACKSPACE, stderr);
  84. X
  85. }
  86. X
  87. /* redraw the entire line, putting the cursor where it belongs */
  88. static void
  89. redraw_line(prompt)
  90. char *prompt;
  91. {
  92. X    int i;
  93. X
  94. X    fputs(prompt, stderr);
  95. X    fputs(cur_line, stderr);
  96. X
  97. X    /* put the cursor where it belongs */
  98. X    for(i=max_pos; i>cur_pos; i--)
  99. X        putc(BACKSPACE, stderr);
  100. }
  101. X
  102. /* clear cur_line and the screen line */
  103. static void
  104. clear_line(prompt)
  105. char *prompt;
  106. {
  107. X    int i;
  108. X    for(i=0; i<max_pos; i++)
  109. X        cur_line[i] = '\0';
  110. X
  111. X    for(i=cur_pos; i>0; i--)
  112. X        putc(BACKSPACE, stderr);
  113. X
  114. X    for(i=0; i<max_pos; i++)
  115. X        putc(SPACE, stderr);
  116. X
  117. X    putc('\r', stderr);
  118. X    fputs(prompt, stderr);
  119. X
  120. X    cur_pos = 0;
  121. X    max_pos = 0;
  122. }
  123. X
  124. /* clear to end of line and the screen end of line */
  125. static void
  126. clear_eoline(prompt)
  127. char *prompt;
  128. {
  129. X    int i;
  130. X    for(i=cur_pos; i<max_pos; i++)
  131. X        cur_line[i] = '\0';
  132. X
  133. X    for(i=cur_pos; i<max_pos; i++)
  134. X        putc(SPACE, stderr);
  135. X    for(i=cur_pos; i<max_pos; i++)
  136. X        putc(BACKSPACE, stderr);
  137. }
  138. X
  139. /* copy line to cur_line, draw it and set cur_pos and max_pos */
  140. static void
  141. copy_line(line)
  142. char *line;
  143. {
  144. X    strcpy(cur_line, line);
  145. X    fputs(cur_line, stderr);
  146. X    cur_pos = max_pos = strlen(cur_line);
  147. }
  148. X
  149. /* add line to the history */
  150. void
  151. add_history(line)
  152. char *line;
  153. {
  154. X    struct hist *entry;
  155. X    entry = (struct hist *)malloc(sizeof(struct hist));
  156. X    entry->line = malloc((unsigned int)strlen(line)+1);
  157. X    strcpy(entry->line, line);
  158. X
  159. X    entry->prev = history;
  160. X    entry->next = NULL;
  161. X    if(history != NULL) {
  162. X        history->next = entry;
  163. X    }
  164. X    history = entry;
  165. }
  166. X
  167. #ifdef MSDOS
  168. X
  169. /* Convert Arrow keystrokes to Control characters: */
  170. static  char
  171. msdos_getch()
  172. {
  173. X    char c = getch();
  174. X
  175. X    if (c == 0) {
  176. X    c = getch(); /* Get the extended code. */
  177. X    switch (c) {
  178. X        case 75: /* Left Arrow. */
  179. X        c = 002;
  180. X        break;
  181. X        case 77: /* Right Arrow. */
  182. X        c = 006;
  183. X        break;
  184. X        case 72: /* Up Arrow. */
  185. X        c = 020;
  186. X        break;
  187. X        case 80: /* Down Arrow. */
  188. X        c = 016;
  189. X        break;
  190. X        case 115: /* Ctl Left Arrow. */
  191. X        case 71: /* Home */
  192. X        c = 001;
  193. X        break;
  194. X        case 116: /* Ctl Right Arrow. */
  195. X        case 79: /* End */
  196. X        c = 005;
  197. X        break;
  198. X        case 83: /* Delete */
  199. X        c = 004;
  200. X        break;
  201. X        default:
  202. X        c = 0;
  203. X        break;
  204. X    }
  205. X    }
  206. X    else if (c == 033) { /* ESC */
  207. X    c = 025;
  208. X    }
  209. X
  210. X
  211. X    return c;
  212. }
  213. X
  214. #endif /* MSDOS */
  215. X
  216. /* set termio so we can do our own input processing */
  217. static void
  218. set_termio()
  219. {
  220. #ifndef MSDOS
  221. X    if(term_set == 0) {
  222. #ifdef TERMIOS
  223. #ifdef TCGETS
  224. X        ioctl(0, TCGETS, &orig_termio);
  225. #else
  226. X        tcgetattr(0, &orig_termio);
  227. #endif /* TCGETS */
  228. #else
  229. X        ioctl(0, TCGETA, &orig_termio);
  230. #endif /* TERMIOS */
  231. X        rl_termio = orig_termio;
  232. X
  233. X        rl_termio.c_iflag &= ~(BRKINT|PARMRK|INPCK|IUCLC|IXON|IXOFF);
  234. X        rl_termio.c_iflag |=  (IGNBRK|IGNPAR);
  235. X
  236. X        rl_termio.c_oflag &= ~(ONOCR);
  237. X
  238. X        rl_termio.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|NOFLSH);
  239. X        rl_termio.c_lflag |=  (ISIG);
  240. X
  241. X        rl_termio.c_cc[VMIN] = 1;
  242. X        rl_termio.c_cc[VTIME] = 0;
  243. X
  244. #ifdef VSUSP
  245. X        /* disable suspending process on ^Z */
  246. X        rl_termio.c_cc[VSUSP] = 0;
  247. #endif /* VSUSP */
  248. X
  249. #ifdef TERMIOS
  250. #ifdef TCSETSW
  251. X        ioctl(0, TCSETSW, &rl_termio);
  252. #else
  253. X        tcsetattr(0, TCSADRAIN, &rl_termio);
  254. #endif /* TCSETSW */
  255. #else
  256. X        ioctl(0, TCSETAW, &rl_termio);
  257. #endif /* TERMIOS */
  258. X        term_set = 1;
  259. X    }
  260. #endif /* MSDOS */
  261. }
  262. X
  263. static void
  264. reset_termio()
  265. {
  266. #ifndef MSDOS
  267. X    if(term_set == 1) {
  268. #ifdef TERMIOS
  269. #ifdef TCSETSW
  270. X        ioctl(0, TCSETSW, &orig_termio);
  271. #else
  272. X        tcsetattr(0, TCSADRAIN, &orig_termio);
  273. #endif /* TCSETSW */
  274. #else
  275. X        ioctl(0, TCSETAW, &orig_termio);
  276. #endif /* TERMIOS */
  277. X        term_set = 0;
  278. X    }
  279. #endif /* MSDOS */
  280. }
  281. #endif /* READLINE */
  282. SHAR_EOF
  283. echo 'File gnuplot/readline.c is complete' &&
  284. chmod 0644 gnuplot/readline.c ||
  285. echo 'restore of gnuplot/readline.c failed'
  286. Wc_c="`wc -c < 'gnuplot/readline.c'`"
  287. test 12274 -eq "$Wc_c" ||
  288.     echo 'gnuplot/readline.c: original size 12274, current size' "$Wc_c"
  289. rm -f _shar_wnt_.tmp
  290. fi
  291. # ============= gnuplot/help.h ==============
  292. if test -f 'gnuplot/help.h' -a X"$1" != X"-c"; then
  293.     echo 'x - skipping gnuplot/help.h (File already exists)'
  294.     rm -f _shar_wnt_.tmp
  295. else
  296. > _shar_wnt_.tmp
  297. echo 'x - extracting gnuplot/help.h (Text)'
  298. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/help.h' &&
  299. /* GNUPLOT - help.h */
  300. /*
  301. X * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  302. X *
  303. X * Permission to use, copy, and distribute this software and its
  304. X * documentation for any purpose with or without fee is hereby granted, 
  305. X * provided that the above copyright notice appear in all copies and 
  306. X * that both that copyright notice and this permission notice appear 
  307. X * in supporting documentation.
  308. X *
  309. X * Permission to modify the software is granted, but not the right to
  310. X * distribute the modified code.  Modifications are to be distributed 
  311. X * as patches to released version.
  312. X *  
  313. X * This software is provided "as is" without express or implied warranty.
  314. X * 
  315. X *
  316. X * AUTHORS
  317. X * 
  318. X *   Original Software:
  319. X *     Thomas Williams,  Colin Kelley.
  320. X * 
  321. X *   Gnuplot 2.0 additions:
  322. X *       Russell Lang, Dave Kotz, John Campbell.
  323. X *
  324. X *   Gnuplot 3.0 additions:
  325. X *       Gershon Elber and many others.
  326. X * 
  327. X * Send your comments or suggestions to 
  328. X *  pixar!info-gnuplot@sun.com.
  329. X * This is a mailing list; to join it send a note to 
  330. X *  pixar!info-gnuplot-request@sun.com.  
  331. X * Send bug reports to
  332. X *  pixar!bug-gnuplot@sun.com.
  333. X */
  334. X
  335. /* Exit status returned by help() */
  336. #define    H_FOUND        0    /* found the keyword */
  337. #define    H_NOTFOUND    1    /* didn't find the keyword */
  338. #define    H_ERROR        (-1)    /* didn't find the help file */
  339. X
  340. extern void FreeHelp();        /* use this if you need memory */
  341. SHAR_EOF
  342. chmod 0666 gnuplot/help.h ||
  343. echo 'restore of gnuplot/help.h failed'
  344. Wc_c="`wc -c < 'gnuplot/help.h'`"
  345. test 1383 -eq "$Wc_c" ||
  346.     echo 'gnuplot/help.h: original size 1383, current size' "$Wc_c"
  347. rm -f _shar_wnt_.tmp
  348. fi
  349. # ============= gnuplot/hrcgraph.asm ==============
  350. if test -f 'gnuplot/hrcgraph.asm' -a X"$1" != X"-c"; then
  351.     echo 'x - skipping gnuplot/hrcgraph.asm (File already exists)'
  352.     rm -f _shar_wnt_.tmp
  353. else
  354. > _shar_wnt_.tmp
  355. echo 'x - extracting gnuplot/hrcgraph.asm (Text)'
  356. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/hrcgraph.asm' &&
  357. TITLE    Hercules graphics module
  358. X
  359. ;    Michael Gordon - 8-Dec-86
  360. ;
  361. ; Certain routines were taken from the Hercules BIOS of    Dave Tutelman - 8/86
  362. ; Others came from pcgraph.asm included in GNUPLOT by Colin Kelley
  363. ;
  364. ; modified slightly by Colin Kelley - 22-Dec-86
  365. ;    added header.mac, parameterized declarations
  366. ; added dgroup: in HVmodem to reach HCh_Parms and HGr_Parms - 30-Jan-87
  367. ; modified by Russell Lang 3 Jun 1988
  368. ;    added H_init
  369. X
  370. include header.mac
  371. X
  372. if1
  373. include lineproc.mac
  374. endif
  375. X
  376. X
  377. GPg1_Base equ 0B800h    ; Graphics page 1 base address
  378. X
  379. _text    segment
  380. X
  381. X    public _H_line, _H_color, _H_mask, _HVmode, _H_puts
  382. X    public _H_init
  383. X
  384. HCfg_Switch equ    03BFH    ; Configuration Switch - software switch 
  385. X            ; to select graphics card memory map
  386. X
  387. beginproc _H_init
  388. X    mov al, 03H    ; allow graphics in b8000:bffff
  389. X    mov dx, HCfg_Switch
  390. X    out dx, al
  391. X    ret
  392. _H_init endp
  393. X
  394. hpixel    proc near
  395. X    ror word ptr bmask,1
  396. X    jc cont
  397. X    ret
  398. cont:
  399. X    push ax
  400. X    push bx
  401. X    push cx
  402. X    push dx
  403. X    push si
  404. X    mov cx,ax        ; x
  405. X    mov dx,bx        ; y
  406. ;
  407. ; [couldn't this be done faster with a lookup table? -cdk]
  408. ;
  409. X    ; first compute the address of byte to be modified
  410. X    ; = 90*[row/4] + [col/8] + 2^D*[row/4] + 2^F*page
  411. X    mov    bh,cl        ; col (low order) in BH
  412. X    mov    bl,dl        ; row (low order) in BL
  413. X    and    bx,0703H    ; mask the col & row remainders
  414. IFDEF iAPX286
  415. X    shr    cx,3        ; col / 8
  416. X    shr    dx,2        ; row / 4
  417. X    mov    al,90
  418. X    mul    dx        ; AX = 90*[ row/4 ]
  419. X    add    ax,cx        ;  ... + col/8
  420. X    shl    bl,5        ; align row remainder
  421. ELSE            ; same as above, obscure but fast for 8086
  422. X    shr    cx,1        ; divide col by 8
  423. X    shr    cx,1
  424. X    shr    cx,1
  425. X    shr    dx,1        ; divide row by 4
  426. X    shr    dx,1
  427. X    shl    dx,1        ; begin fast multiply by 90 (1011010 B)
  428. X    mov    ax,dx
  429. X    shl    dx,1
  430. X    shl    dx,1
  431. X    add    ax,dx
  432. X    shl    dx,1
  433. X    add    ax,dx
  434. X    shl    dx,1
  435. X    shl    dx,1
  436. X    add    ax,dx        ; end fast multiply by 90
  437. X    add    ax,cx        ; add on the col/8
  438. X    shl    bl,1        ; align row remainder
  439. X    shl    bl,1
  440. X    shl    bl,1
  441. X    shl    bl,1
  442. X    shl    bl,1
  443. ENDIF
  444. X    add    ah,bl        ; use aligned row remainder
  445. end_adr_calc:            ; address of byte is now in AX
  446. X    mov    dx,GPg1_Base    ; base of pixel display to DX
  447. X    mov    es,dx        ; ...and thence to segment reg
  448. X    mov    si,ax        ; address of byte w/ pixel to index reg
  449. X    mov    cl,bh        ; bit addr in byte
  450. X    mov    al,80H        ; '1000 0000' in AL 
  451. X    shr    al,cl        ; shift mask to line up with bit to read/write
  452. set_pix:            ; set the pixel
  453. X    or    es:[si],al    ; or the mask with the right byte
  454. X    pop si
  455. X    pop dx
  456. X    pop cx
  457. X    pop bx
  458. X    pop ax
  459. X    ret
  460. hpixel endp
  461. X
  462. lineproc _H_line, hpixel
  463. X
  464. ;
  465. ; clear - clear page 1 of the screen buffer to zero (effectively, blank
  466. ;    the screen)
  467. ;
  468. clear   proc near
  469. X    push es
  470. X    push ax
  471. X    push cx
  472. X    push di
  473. X    mov ax, GPg1_Base
  474. X    mov es, ax
  475. X    xor di, di
  476. X    mov cx, 4000h
  477. X    xor ax, ax
  478. X    cld
  479. X    rep stosw            ; zero out screen page
  480. X    pop di
  481. X    pop cx
  482. X    pop ax
  483. X    pop es
  484. X    ret
  485. clear    endp
  486. X
  487. beginproc _H_color
  488. X    push bp
  489. X    mov bp,sp
  490. X    mov al,[bp+X]            ; color
  491. X    mov byte ptr color,al
  492. X    pop bp
  493. X    ret
  494. _H_color endp
  495. X
  496. beginproc _H_mask
  497. X    push bp
  498. X    mov bp,sp
  499. X    mov ax,[bp+X]            ; mask
  500. X    mov word ptr bmask,ax
  501. X    pop bp
  502. X    ret
  503. _H_mask endp
  504. X
  505. HCtrl_Port    equ    03B8H    ; Hercules 6845 control port IO addr
  506. HIndx_Port    equ    03B4H    ; Hercules 6845 index port IO addr
  507. HScrn_Enable    equ    008h    ; Control port bit to enable video
  508. HCh_Mode    equ    020h    ; Character output mode
  509. HGr_Mode    equ    082h    ; Graphics output mode page 1
  510. X
  511. parm_count equ 12
  512. X
  513. beginproc _HVmode
  514. X    push bp
  515. X    mov bp, sp
  516. X    push si
  517. X    mov ax, [bp+X]
  518. X    or ah, al
  519. X    mov al, HCh_Mode        ; Assume character mode is wanted
  520. X    mov si, offset dgroup:HCh_Parms
  521. X    cmp ah, 0            ; nonzero means switch to graphics
  522. X    jz vmode_ok
  523. X    call near ptr clear        ; clear the graphics page
  524. X    mov al, HGr_Mode
  525. X    mov si, offset dgroup:HGr_Parms
  526. vmode_ok:
  527. X    mov dx, HCtrl_Port
  528. X    out dx, al            ; Set Hercules board to proper mode
  529. X    call near ptr setParms        ; Set the 6845 parameters
  530. X    or al, HScrn_Enable        ; Enable the video output
  531. X    out dx, al
  532. X    pop si
  533. X    pop bp
  534. X    ret
  535. _HVmode    endp
  536. X
  537. setParms proc near        ; Send 6845 parms to Hercules board
  538. X    push ax
  539. X    push dx
  540. X    push si            
  541. X    mov dx, HIndx_Port    ; Index port addr -> DX
  542. X    mov ah, 0        ; 0 -> parameter counter
  543. sp_loop:
  544. X    mov al, ah
  545. X    out dx, al        ; output to 6845 addr register
  546. X    inc dx            ; next output to data register
  547. X    mov al, [si]        ; next control byte -> al
  548. X    inc si
  549. X    out dx, al        ; output control byte
  550. X    dec dx            ; 6845 index addr -> dx
  551. X    inc ah            ; bump addr
  552. X    cmp ah, parm_count
  553. X    jnz sp_loop
  554. X    pop si
  555. X    pop dx
  556. X    pop ax
  557. X    ret
  558. setParms endp
  559. X
  560. ; H_puts - print text in graphics mode
  561. ;
  562. ;    cx = row
  563. ;    bx = column
  564. ;    si = address of string (null terminated) to print
  565. X
  566. beginproc _H_puts
  567. X    push bp
  568. X    mov bp, sp
  569. X    push si
  570. X    push ds
  571. X    mov si, [bp+X]            ; string offset
  572. X
  573. ifdef LARGE_DATA
  574. X    mov ds, [bp+X+2]        ; string segment
  575. X    mov cx, [bp+X+4]        ; row
  576. X    mov bx, [bp+X+6]        ; col
  577. else
  578. X    mov cx, [bp+X+2]        ; row
  579. X    mov bx, [bp+X+4]        ; col
  580. endif
  581. X
  582. ploop:    lodsb                ; get next char
  583. X    or    al, al            ; end of display?
  584. X    je    pdone
  585. X    call near ptr display
  586. X    inc    bx            ; bump to next column
  587. X    jmp    ploop
  588. pdone:    pop ds
  589. X    pop si
  590. X    pop bp
  591. X    ret
  592. _H_puts    endp
  593. X
  594. ;
  595. ; display - output an 8x8 character from the IBM ROM to the Herc board
  596. ;
  597. ; AX = char, BX = column (0-89), CX = row(0-42)  ** all preserved **
  598. ;
  599. CON8    db    8
  600. CON180    db    180
  601. IBMROM    equ    0F000h
  602. CHARTAB    equ    0FA6Eh
  603. X
  604. display    proc near
  605. X    push    ds            ; save the lot
  606. X    push    es
  607. X    push    ax
  608. X    push    bx
  609. X    push    cx
  610. X    push    dx
  611. X    push    si
  612. X    push    di
  613. X
  614. ; setup ds -> IBM ROM, and si -> index into IBM ROM character table located
  615. ;    at 0fa6eh in the ROM
  616. X
  617. X    and    ax, 07fh
  618. X    mul    cs:CON8            ; mult by 8 bytes of table per char
  619. X    mov    si, ax
  620. X    mov    ax, IBMROM
  621. X    mov    ds, ax
  622. X    assume    ds:nothing
  623. X    add    si, CHARTAB        ; add offset of character table
  624. X
  625. ; compute index into Hercules screen memory for scan line 0.  The remaining
  626. ;    seven scan lines are all at fixed offsets from the first.
  627. ;
  628. ;    Since graphics mode treats the screen as sets of 16x4 "characters",
  629. ;    we need to map an 8x8 real character onto the front or back of
  630. ;    a pair of graphics "characters".  The first four scan lines of our
  631. ;    8x8 character will map to the top graphics "character", and the second
  632. ;    four scan lines map to the graphics character on the "line" (4 scan
  633. ;    lines high) below it.
  634. ;
  635. ;    For some exotic hardware reason (probably speed), all scan line 0
  636. ;    bits (i.e. every fourth scan line) are stored in memory locations
  637. ;    0-2000h in the screen buffer.  All scan line 1 bits are stored
  638. ;    2000h-4000h.  Within these banks, they are stored by rows.  The first
  639. ;    scan line on the screen (scan line 0 of graphics character row 0)
  640. ;    is the first 45 words of memory in the screen buffer.  The next 45
  641. ;    words are the first scan line graphics row 1, and since graphics
  642. ;    "characters" are 4 bits high, this second scan line is physically
  643. ;    the fifth scan line displayed on the screen.
  644. ;
  645. ;    SO, to display an 8x8 character, the 1st and 5th rows of dots are
  646. ;    both scan line 0 of the graphics "character", the 2nd and 6th are
  647. ;    scan line 1, and so on.
  648. ;
  649. ;    The column (0-89) tells which byte in a scan line we need to load.
  650. ;    Since it takes two rows of graphics characters to hold one row of
  651. ;    our characters, column+90 is a index to scan line 4 rows of pixels
  652. ;    higher (n+4).  Thus 180 bytes of screen memory in any bank (0h, 2000h,
  653. ;    4000h, 6000h) represent a row of 8x8 characters.
  654. ;    
  655. ;    The starting location in screen memory for the first scan line of
  656. ;    a character to be displayed will be:      (row*180)+column
  657. ;    The 5th scan line will be at:        (row*180)+column+90
  658. ;
  659. ;    The second and 6th scan lines will be at the above offsets plus
  660. ;    the bank offset of 2000h.  The third and 7th, add 4000h and finally
  661. ;    the 4th and 8th, add 6000h.
  662. ;
  663. X    mov    ax, GPg1_Base
  664. X    mov    es, ax            ; es = hercules page 0
  665. X    mov    ax, cx            ; get row
  666. X    mul    cs:CON180        ; mult by 180(10)
  667. X    mov    di, ax            ; di = index reg
  668. X    cld                ; insure right direction
  669. X
  670. ;output 8 segments of character to video ram
  671. X
  672. X    lodsb                ; line 0
  673. X    mov    es:[di+bx], al
  674. X    lodsb
  675. X    mov    es:[di+bx+2000h], al    ; line 1
  676. X    lodsb
  677. X    mov    es:[di+bx+4000h], al    ; line 2
  678. X    lodsb
  679. X    mov    es:[di+bx+6000h], al    ; line 3
  680. X    lodsb
  681. X    mov    es:[di+bx+90], al    ; line 4
  682. X    lodsb
  683. X    mov    es:[di+bx+2000h+90], al    ; line 5
  684. X    lodsb
  685. X    mov    es:[di+bx+4000h+90], al    ; line 6
  686. X    lodsb
  687. X    mov    es:[di+bx+6000h+90], al    ; line 7
  688. X
  689. X    pop    di
  690. X    pop    si
  691. X    pop    dx
  692. X    pop    cx
  693. X    pop    bx
  694. X    pop    ax
  695. X    pop    es
  696. X    pop    ds
  697. X    ret
  698. display    endp
  699. X
  700. _text    ends
  701. X
  702. _data    segment
  703. bmask    dw -1
  704. color    db 1
  705. _data    ends
  706. X
  707. const    segment
  708. HCh_Parms db     61H, 50H, 52H, 0FH, 19H, 06H, 19H, 19H, 02H, 0DH, 0BH, 0CH
  709. HGr_Parms db    35H, 2DH, 2EH, 07H, 5BH, 02H, 57H, 57H, 02H, 03H, 00H, 00H
  710. const    ends
  711. X
  712. X    end
  713. X
  714. X
  715. SHAR_EOF
  716. chmod 0666 gnuplot/hrcgraph.asm ||
  717. echo 'restore of gnuplot/hrcgraph.asm failed'
  718. Wc_c="`wc -c < 'gnuplot/hrcgraph.asm'`"
  719. test 8192 -eq "$Wc_c" ||
  720.     echo 'gnuplot/hrcgraph.asm: original size 8192, current size' "$Wc_c"
  721. rm -f _shar_wnt_.tmp
  722. fi
  723. # ============= gnuplot/internal.c ==============
  724. if test -f 'gnuplot/internal.c' -a X"$1" != X"-c"; then
  725.     echo 'x - skipping gnuplot/internal.c (File already exists)'
  726.     rm -f _shar_wnt_.tmp
  727. else
  728. > _shar_wnt_.tmp
  729. echo 'x - extracting gnuplot/internal.c (Text)'
  730. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/internal.c' &&
  731. /* GNUPLOT - internal.c */
  732. /*
  733. X * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  734. X *
  735. X * Permission to use, copy, and distribute this software and its
  736. X * documentation for any purpose with or without fee is hereby granted, 
  737. X * provided that the above copyright notice appear in all copies and 
  738. X * that both that copyright notice and this permission notice appear 
  739. X * in supporting documentation.
  740. X *
  741. X * Permission to modify the software is granted, but not the right to
  742. X * distribute the modified code.  Modifications are to be distributed 
  743. X * as patches to released version.
  744. X *  
  745. X * This software is provided "as is" without express or implied warranty.
  746. X * 
  747. X *
  748. X * AUTHORS
  749. X * 
  750. X *   Original Software:
  751. X *     Thomas Williams,  Colin Kelley.
  752. X * 
  753. X *   Gnuplot 2.0 additions:
  754. X *       Russell Lang, Dave Kotz, John Campbell.
  755. X *
  756. X *   Gnuplot 3.0 additions:
  757. X *       Gershon Elber and many others.
  758. X * 
  759. X * Send your comments or suggestions to 
  760. X *  pixar!info-gnuplot@sun.com.
  761. X * This is a mailing list; to join it send a note to 
  762. X *  pixar!info-gnuplot-request@sun.com.  
  763. X * Send bug reports to
  764. X *  pixar!bug-gnuplot@sun.com.
  765. X */
  766. X
  767. #include <math.h>
  768. #include <stdio.h>
  769. #include "plot.h"
  770. X
  771. BOOLEAN undefined;
  772. X
  773. char *strcpy();
  774. X
  775. struct value *pop(), *complex(), *integer();
  776. double magnitude(), angle(), real();
  777. X
  778. struct value stack[STACK_DEPTH];
  779. X
  780. int s_p = -1;   /* stack pointer */
  781. X
  782. X
  783. /*
  784. X * System V and MSC 4.0 call this when they wants to print an error message.
  785. X * Don't!
  786. X */
  787. #ifdef MSDOS
  788. #ifdef __TURBOC__
  789. int matherr()    /* Turbo C */
  790. #else
  791. int matherr(x)    /* MSC 5.1 */
  792. struct exception *x;
  793. #endif /* TURBOC */
  794. #else /* not MSDOS */
  795. #ifdef apollo
  796. int matherr(struct exception *x)    /* apollo */
  797. #else /* apollo */
  798. #ifdef AMIGA_LC_5_1
  799. int matherr(x)    /* AMIGA_LC_5_1 */
  800. struct exception *x;
  801. #else    /* Most everyone else (not apollo). */
  802. int matherr()
  803. #endif /* AMIGA_LC_5_1 */
  804. #endif /* apollo */
  805. #endif /* MSDOS */
  806. {
  807. X    return (undefined = TRUE);        /* don't print error message */
  808. }
  809. X
  810. X
  811. reset_stack()
  812. {
  813. X    s_p = -1;
  814. }
  815. X
  816. X
  817. check_stack()    /* make sure stack's empty */
  818. {
  819. X    if (s_p != -1)
  820. X        fprintf(stderr,"\nwarning:  internal error--stack not empty!\n");
  821. }
  822. X
  823. X
  824. struct value *pop(x)
  825. struct value *x;
  826. {
  827. X    if (s_p  < 0 )
  828. X        int_error("stack underflow",NO_CARET);
  829. X    *x = stack[s_p--];
  830. X    return(x);
  831. }
  832. X
  833. X
  834. push(x)
  835. struct value *x;
  836. {
  837. X    if (s_p == STACK_DEPTH - 1)
  838. X        int_error("stack overflow",NO_CARET);
  839. X    stack[++s_p] = *x;
  840. }
  841. X
  842. X
  843. #define ERR_VAR "undefined variable: "
  844. X
  845. f_push(x)
  846. union argument *x;        /* contains pointer to value to push; */
  847. {
  848. static char err_str[sizeof(ERR_VAR) + MAX_ID_LEN] = ERR_VAR;
  849. struct udvt_entry *udv;
  850. X
  851. X    udv = x->udv_arg;
  852. X    if (udv->udv_undef) {     /* undefined */
  853. X        (void) strcpy(&err_str[sizeof(ERR_VAR) - 1], udv->udv_name);
  854. X        int_error(err_str,NO_CARET);
  855. X    }
  856. X    push(&(udv->udv_value));
  857. }
  858. X
  859. X
  860. f_pushc(x)
  861. union argument *x;
  862. {
  863. X    push(&(x->v_arg));
  864. }
  865. X
  866. X
  867. f_pushd1(x)
  868. union argument *x;
  869. {
  870. X    push(&(x->udf_arg->dummy_values[0]));
  871. }
  872. X
  873. X
  874. f_pushd2(x)
  875. union argument *x;
  876. {
  877. X    push(&(x->udf_arg->dummy_values[1]));
  878. }
  879. X
  880. X
  881. #define ERR_FUN "undefined function: "
  882. X
  883. f_call(x)  /* execute a udf */
  884. union argument *x;
  885. {
  886. static char err_str[sizeof(ERR_FUN) + MAX_ID_LEN] = ERR_FUN;
  887. register struct udft_entry *udf;
  888. struct value save_dummy;
  889. X
  890. X    udf = x->udf_arg;
  891. X    if (!udf->at) { /* undefined */
  892. X        (void) strcpy(&err_str[sizeof(ERR_FUN) - 1],
  893. X                udf->udf_name);
  894. X        int_error(err_str,NO_CARET);
  895. X    }
  896. X    save_dummy = udf->dummy_values[0];
  897. X    (void) pop(&(udf->dummy_values[0]));
  898. X
  899. X    execute_at(udf->at);
  900. X    udf->dummy_values[0] = save_dummy;
  901. }
  902. X
  903. f_call2(x)  /* execute a udf of two variables */
  904. union argument *x;
  905. {
  906. static char err_str[sizeof(ERR_FUN) + MAX_ID_LEN] = ERR_FUN;
  907. register struct udft_entry *udf;
  908. struct value save_dummy0, save_dummy1;
  909. X
  910. X    udf = x->udf_arg;
  911. X    if (!udf->at) { /* undefined */
  912. X        (void) strcpy(&err_str[sizeof(ERR_FUN) - 1],
  913. X                udf->udf_name);
  914. X        int_error(err_str,NO_CARET);
  915. X    }
  916. X    save_dummy1 = udf->dummy_values[1];
  917. X    save_dummy0 = udf->dummy_values[0];
  918. X    (void) pop(&(udf->dummy_values[1]));
  919. X    (void) pop(&(udf->dummy_values[0]));
  920. X
  921. X    execute_at(udf->at);
  922. X    udf->dummy_values[1] = save_dummy1;
  923. X    udf->dummy_values[0] = save_dummy0;
  924. }
  925. X
  926. X
  927. static int_check(v)
  928. struct value *v;
  929. {
  930. X    if (v->type != INT)
  931. X        int_error("non-integer passed to boolean operator",NO_CARET);
  932. }
  933. X
  934. X
  935. f_lnot()
  936. {
  937. struct value a;
  938. X    int_check(pop(&a));
  939. X    push(integer(&a,!a.v.int_val) );
  940. }
  941. X
  942. X
  943. f_bnot()
  944. {
  945. struct value a;
  946. X    int_check(pop(&a));
  947. X    push( integer(&a,~a.v.int_val) );
  948. }
  949. X
  950. X
  951. f_bool()
  952. {            /* converts top-of-stack to boolean */
  953. X    int_check(&top_of_stack);
  954. X    top_of_stack.v.int_val = !!top_of_stack.v.int_val;
  955. }
  956. X
  957. X
  958. f_lor()
  959. {
  960. struct value a,b;
  961. X    int_check(pop(&b));
  962. X    int_check(pop(&a));
  963. X    push( integer(&a,a.v.int_val || b.v.int_val) );
  964. }
  965. X
  966. f_land()
  967. {
  968. struct value a,b;
  969. X    int_check(pop(&b));
  970. X    int_check(pop(&a));
  971. X    push( integer(&a,a.v.int_val && b.v.int_val) );
  972. }
  973. X
  974. X
  975. f_bor()
  976. {
  977. struct value a,b;
  978. X    int_check(pop(&b));
  979. X    int_check(pop(&a));
  980. X    push( integer(&a,a.v.int_val | b.v.int_val) );
  981. }
  982. X
  983. X
  984. f_xor()
  985. {
  986. struct value a,b;
  987. X    int_check(pop(&b));
  988. X    int_check(pop(&a));
  989. X    push( integer(&a,a.v.int_val ^ b.v.int_val) );
  990. }
  991. X
  992. X
  993. f_band()
  994. {
  995. struct value a,b;
  996. X    int_check(pop(&b));
  997. X    int_check(pop(&a));
  998. X    push( integer(&a,a.v.int_val & b.v.int_val) );
  999. }
  1000. X
  1001. X
  1002. f_uminus()
  1003. {
  1004. struct value a;
  1005. X    (void) pop(&a);
  1006. X    switch(a.type) {
  1007. X        case INT:
  1008. X            a.v.int_val = -a.v.int_val;
  1009. X            break;
  1010. X        case CMPLX:
  1011. X            a.v.cmplx_val.real =
  1012. X                -a.v.cmplx_val.real;
  1013. X            a.v.cmplx_val.imag =
  1014. X                -a.v.cmplx_val.imag;
  1015. X    }
  1016. X    push(&a);
  1017. }
  1018. X
  1019. X
  1020. f_eq() /* note: floating point equality is rare because of roundoff error! */
  1021. {
  1022. struct value a, b;
  1023. X    register int result;
  1024. X    (void) pop(&b);
  1025. X    (void) pop(&a);
  1026. X    switch(a.type) {
  1027. X        case INT:
  1028. X            switch (b.type) {
  1029. X                case INT:
  1030. X                    result = (a.v.int_val ==
  1031. X                        b.v.int_val);
  1032. X                    break;
  1033. X                case CMPLX:
  1034. X                    result = (a.v.int_val ==
  1035. X                        b.v.cmplx_val.real &&
  1036. X                       b.v.cmplx_val.imag == 0.0);
  1037. X            }
  1038. X            break;
  1039. X        case CMPLX:
  1040. X            switch (b.type) {
  1041. X                case INT:
  1042. X                    result = (b.v.int_val == a.v.cmplx_val.real &&
  1043. X                       a.v.cmplx_val.imag == 0.0);
  1044. X                    break;
  1045. X                case CMPLX:
  1046. X                    result = (a.v.cmplx_val.real==
  1047. X                        b.v.cmplx_val.real &&
  1048. X                        a.v.cmplx_val.imag==
  1049. X                        b.v.cmplx_val.imag);
  1050. X            }
  1051. X    }
  1052. X    push(integer(&a,result));
  1053. }
  1054. X
  1055. X
  1056. f_ne()
  1057. {
  1058. struct value a, b;
  1059. X    register int result;
  1060. X    (void) pop(&b);
  1061. X    (void) pop(&a);
  1062. X    switch(a.type) {
  1063. X        case INT:
  1064. X            switch (b.type) {
  1065. X                case INT:
  1066. X                    result = (a.v.int_val !=
  1067. X                        b.v.int_val);
  1068. X                    break;
  1069. X                case CMPLX:
  1070. X                    result = (a.v.int_val !=
  1071. X                        b.v.cmplx_val.real ||
  1072. X                       b.v.cmplx_val.imag != 0.0);
  1073. X            }
  1074. X            break;
  1075. X        case CMPLX:
  1076. X            switch (b.type) {
  1077. X                case INT:
  1078. X                    result = (b.v.int_val !=
  1079. X                        a.v.cmplx_val.real ||
  1080. X                       a.v.cmplx_val.imag != 0.0);
  1081. X                    break;
  1082. X                case CMPLX:
  1083. X                    result = (a.v.cmplx_val.real !=
  1084. X                        b.v.cmplx_val.real ||
  1085. X                        a.v.cmplx_val.imag !=
  1086. X                        b.v.cmplx_val.imag);
  1087. X            }
  1088. X    }
  1089. X    push(integer(&a,result));
  1090. }
  1091. X
  1092. X
  1093. f_gt()
  1094. {
  1095. struct value a, b;
  1096. X    register int result;
  1097. X    (void) pop(&b);
  1098. X    (void) pop(&a);
  1099. X    switch(a.type) {
  1100. X        case INT:
  1101. X            switch (b.type) {
  1102. X                case INT:
  1103. X                    result = (a.v.int_val >
  1104. X                        b.v.int_val);
  1105. X                    break;
  1106. X                case CMPLX:
  1107. X                    result = (a.v.int_val >
  1108. X                        b.v.cmplx_val.real);
  1109. X            }
  1110. X            break;
  1111. X        case CMPLX:
  1112. X            switch (b.type) {
  1113. X                case INT:
  1114. X                    result = (a.v.cmplx_val.real >
  1115. X                        b.v.int_val);
  1116. X                    break;
  1117. X                case CMPLX:
  1118. X                    result = (a.v.cmplx_val.real >
  1119. X                        b.v.cmplx_val.real);
  1120. X            }
  1121. X    }
  1122. X    push(integer(&a,result));
  1123. }
  1124. X
  1125. X
  1126. f_lt()
  1127. {
  1128. struct value a, b;
  1129. X    register int result;
  1130. X    (void) pop(&b);
  1131. X    (void) pop(&a);
  1132. X    switch(a.type) {
  1133. X        case INT:
  1134. X            switch (b.type) {
  1135. X                case INT:
  1136. X                    result = (a.v.int_val <
  1137. X                        b.v.int_val);
  1138. X                    break;
  1139. X                case CMPLX:
  1140. X                    result = (a.v.int_val <
  1141. X                        b.v.cmplx_val.real);
  1142. X            }
  1143. X            break;
  1144. X        case CMPLX:
  1145. X            switch (b.type) {
  1146. X                case INT:
  1147. X                    result = (a.v.cmplx_val.real <
  1148. X                        b.v.int_val);
  1149. X                    break;
  1150. X                case CMPLX:
  1151. X                    result = (a.v.cmplx_val.real <
  1152. X                        b.v.cmplx_val.real);
  1153. X            }
  1154. X    }
  1155. X    push(integer(&a,result));
  1156. }
  1157. X
  1158. X
  1159. f_ge()
  1160. {
  1161. struct value a, b;
  1162. X    register int result;
  1163. X    (void) pop(&b);
  1164. X    (void) pop(&a);
  1165. X    switch(a.type) {
  1166. X        case INT:
  1167. X            switch (b.type) {
  1168. X                case INT:
  1169. X                    result = (a.v.int_val >=
  1170. X                        b.v.int_val);
  1171. X                    break;
  1172. X                case CMPLX:
  1173. X                    result = (a.v.int_val >=
  1174. X                        b.v.cmplx_val.real);
  1175. X            }
  1176. X            break;
  1177. X        case CMPLX:
  1178. X            switch (b.type) {
  1179. X                case INT:
  1180. X                    result = (a.v.cmplx_val.real >=
  1181. X                        b.v.int_val);
  1182. X                    break;
  1183. X                case CMPLX:
  1184. X                    result = (a.v.cmplx_val.real >=
  1185. X                        b.v.cmplx_val.real);
  1186. X            }
  1187. X    }
  1188. X    push(integer(&a,result));
  1189. }
  1190. X
  1191. X
  1192. f_le()
  1193. {
  1194. struct value a, b;
  1195. X    register int result;
  1196. X    (void) pop(&b);
  1197. X    (void) pop(&a);
  1198. X    switch(a.type) {
  1199. X        case INT:
  1200. X            switch (b.type) {
  1201. X                case INT:
  1202. X                    result = (a.v.int_val <=
  1203. X                        b.v.int_val);
  1204. X                    break;
  1205. X                case CMPLX:
  1206. X                    result = (a.v.int_val <=
  1207. X                        b.v.cmplx_val.real);
  1208. X            }
  1209. X            break;
  1210. X        case CMPLX:
  1211. X            switch (b.type) {
  1212. X                case INT:
  1213. X                    result = (a.v.cmplx_val.real <=
  1214. X                        b.v.int_val);
  1215. X                    break;
  1216. X                case CMPLX:
  1217. X                    result = (a.v.cmplx_val.real <=
  1218. X                        b.v.cmplx_val.real);
  1219. X            }
  1220. X    }
  1221. X    push(integer(&a,result));
  1222. }
  1223. X
  1224. X
  1225. f_plus()
  1226. {
  1227. struct value a, b, result;
  1228. X    (void) pop(&b);
  1229. X    (void) pop(&a);
  1230. X    switch(a.type) {
  1231. X        case INT:
  1232. X            switch (b.type) {
  1233. X                case INT:
  1234. X                    (void) integer(&result,a.v.int_val +
  1235. X                        b.v.int_val);
  1236. X                    break;
  1237. X                case CMPLX:
  1238. X                    (void) complex(&result,a.v.int_val +
  1239. X                        b.v.cmplx_val.real,
  1240. X                       b.v.cmplx_val.imag);
  1241. X            }
  1242. X            break;
  1243. X        case CMPLX:
  1244. X            switch (b.type) {
  1245. X                case INT:
  1246. X                    (void) complex(&result,b.v.int_val +
  1247. X                        a.v.cmplx_val.real,
  1248. X                       a.v.cmplx_val.imag);
  1249. X                    break;
  1250. X                case CMPLX:
  1251. X                    (void) complex(&result,a.v.cmplx_val.real+
  1252. X                        b.v.cmplx_val.real,
  1253. X                        a.v.cmplx_val.imag+
  1254. X                        b.v.cmplx_val.imag);
  1255. X            }
  1256. X    }
  1257. X    push(&result);
  1258. }
  1259. X
  1260. X
  1261. f_minus()
  1262. {
  1263. struct value a, b, result;
  1264. X    (void) pop(&b);
  1265. X    (void) pop(&a);        /* now do a - b */
  1266. X    switch(a.type) {
  1267. X        case INT:
  1268. X            switch (b.type) {
  1269. X                case INT:
  1270. X                    (void) integer(&result,a.v.int_val -
  1271. X                        b.v.int_val);
  1272. X                    break;
  1273. X                case CMPLX:
  1274. X                    (void) complex(&result,a.v.int_val -
  1275. X                        b.v.cmplx_val.real,
  1276. X                       -b.v.cmplx_val.imag);
  1277. X            }
  1278. X            break;
  1279. X        case CMPLX:
  1280. X            switch (b.type) {
  1281. X                case INT:
  1282. X                    (void) complex(&result,a.v.cmplx_val.real -
  1283. X                        b.v.int_val,
  1284. X                        a.v.cmplx_val.imag);
  1285. X                    break;
  1286. X                case CMPLX:
  1287. X                    (void) complex(&result,a.v.cmplx_val.real-
  1288. X                        b.v.cmplx_val.real,
  1289. X                        a.v.cmplx_val.imag-
  1290. X                        b.v.cmplx_val.imag);
  1291. X            }
  1292. X    }
  1293. X    push(&result);
  1294. }
  1295. X
  1296. X
  1297. f_mult()
  1298. {
  1299. struct value a, b, result;
  1300. X    (void) pop(&b);
  1301. X    (void) pop(&a);    /* now do a*b */
  1302. X
  1303. X    switch(a.type) {
  1304. X        case INT:
  1305. X            switch (b.type) {
  1306. X                case INT:
  1307. X                    (void) integer(&result,a.v.int_val *
  1308. X                        b.v.int_val);
  1309. X                    break;
  1310. X                case CMPLX:
  1311. X                    (void) complex(&result,a.v.int_val *
  1312. X                        b.v.cmplx_val.real,
  1313. X                        a.v.int_val *
  1314. X                        b.v.cmplx_val.imag);
  1315. X            }
  1316. X            break;
  1317. X        case CMPLX:
  1318. X            switch (b.type) {
  1319. X                case INT:
  1320. X                    (void) complex(&result,b.v.int_val *
  1321. X                        a.v.cmplx_val.real,
  1322. X                        b.v.int_val *
  1323. X                        a.v.cmplx_val.imag);
  1324. X                    break;
  1325. X                case CMPLX:
  1326. X                    (void) complex(&result,a.v.cmplx_val.real*
  1327. X                        b.v.cmplx_val.real-
  1328. X                        a.v.cmplx_val.imag*
  1329. X                        b.v.cmplx_val.imag,
  1330. X                        a.v.cmplx_val.real*
  1331. X                        b.v.cmplx_val.imag+
  1332. X                        a.v.cmplx_val.imag*
  1333. X                        b.v.cmplx_val.real);
  1334. X            }
  1335. X    }
  1336. X    push(&result);
  1337. }
  1338. X
  1339. X
  1340. f_div()
  1341. {
  1342. struct value a, b, result;
  1343. register double square;
  1344. X    (void) pop(&b);
  1345. X    (void) pop(&a);    /* now do a/b */
  1346. X
  1347. X    switch(a.type) {
  1348. X        case INT:
  1349. X            switch (b.type) {
  1350. X                case INT:
  1351. X                    if (b.v.int_val)
  1352. X                      (void) integer(&result,a.v.int_val /
  1353. X                        b.v.int_val);
  1354. X                    else {
  1355. X                      (void) integer(&result,0);
  1356. X                      undefined = TRUE;
  1357. X                    }
  1358. X                    break;
  1359. X                case CMPLX:
  1360. X                    square = b.v.cmplx_val.real*
  1361. X                        b.v.cmplx_val.real +
  1362. X                        b.v.cmplx_val.imag*
  1363. X                        b.v.cmplx_val.imag;
  1364. X                    if (square)
  1365. X                        (void) complex(&result,a.v.int_val*
  1366. X                        b.v.cmplx_val.real/square,
  1367. X                        -a.v.int_val*
  1368. X                        b.v.cmplx_val.imag/square);
  1369. X                    else {
  1370. X                        (void) complex(&result,0.0,0.0);
  1371. X                        undefined = TRUE;
  1372. X                    }
  1373. X            }
  1374. X            break;
  1375. X        case CMPLX:
  1376. X            switch (b.type) {
  1377. X                case INT:
  1378. X                    if (b.v.int_val)
  1379. X                      
  1380. X                      (void) complex(&result,a.v.cmplx_val.real/
  1381. X                        b.v.int_val,
  1382. X                        a.v.cmplx_val.imag/
  1383. X                        b.v.int_val);
  1384. X                    else {
  1385. X                        (void) complex(&result,0.0,0.0);
  1386. X                        undefined = TRUE;
  1387. X                    }
  1388. X                    break;
  1389. X                case CMPLX:
  1390. X                    square = b.v.cmplx_val.real*
  1391. X                        b.v.cmplx_val.real +
  1392. X                        b.v.cmplx_val.imag*
  1393. X                        b.v.cmplx_val.imag;
  1394. X                    if (square)
  1395. X                    (void) complex(&result,(a.v.cmplx_val.real*
  1396. X                        b.v.cmplx_val.real+
  1397. X                        a.v.cmplx_val.imag*
  1398. X                        b.v.cmplx_val.imag)/square,
  1399. X                        (a.v.cmplx_val.imag*
  1400. X                        b.v.cmplx_val.real-
  1401. X                        a.v.cmplx_val.real*
  1402. X                        b.v.cmplx_val.imag)/
  1403. X                            square);
  1404. X                    else {
  1405. X                        (void) complex(&result,0.0,0.0);
  1406. X                        undefined = TRUE;
  1407. X                    }
  1408. X            }
  1409. X    }
  1410. X    push(&result);
  1411. }
  1412. X
  1413. X
  1414. f_mod()
  1415. {
  1416. struct value a, b;
  1417. X    (void) pop(&b);
  1418. X    (void) pop(&a);    /* now do a%b */
  1419. X
  1420. X    if (a.type != INT || b.type != INT)
  1421. X        int_error("can only mod ints",NO_CARET);
  1422. X    if (b.v.int_val)
  1423. X        push(integer(&a,a.v.int_val % b.v.int_val));
  1424. X    else {
  1425. X        push(integer(&a,0));
  1426. X        undefined = TRUE;
  1427. X    }
  1428. }
  1429. X
  1430. X
  1431. f_power()
  1432. {
  1433. struct value a, b, result;
  1434. register int i, t, count;
  1435. register double mag, ang;
  1436. X    (void) pop(&b);
  1437. X    (void) pop(&a);    /* now find a**b */
  1438. X
  1439. X    switch(a.type) {
  1440. X        case INT:
  1441. X            switch (b.type) {
  1442. X                case INT:
  1443. X                    count = abs(b.v.int_val);
  1444. X                    t = 1;
  1445. X                    for(i = 0; i < count; i++)
  1446. X                        t *= a.v.int_val;
  1447. X                    if (b.v.int_val >= 0)
  1448. X                        (void) integer(&result,t);
  1449. X                    else
  1450. X                      if (t != 0)
  1451. X                        (void) complex(&result,1.0/t,0.0);
  1452. X                      else {
  1453. X                         undefined = TRUE;
  1454. X                         (void) complex(&result, 0.0, 0.0);
  1455. X                      }
  1456. X                    break;
  1457. X                case CMPLX:
  1458. X                    mag =
  1459. X                      pow(magnitude(&a),fabs(b.v.cmplx_val.real));
  1460. X                    if (b.v.cmplx_val.real < 0.0)
  1461. X                      if (mag != 0.0)
  1462. X                        mag = 1.0/mag;
  1463. X                      else 
  1464. X                        undefined = TRUE;
  1465. X                    mag *= exp(-b.v.cmplx_val.imag*angle(&a));
  1466. X                    ang = b.v.cmplx_val.real*angle(&a) +
  1467. X                          b.v.cmplx_val.imag*log(magnitude(&a));
  1468. X                    (void) complex(&result,mag*cos(ang),
  1469. X                        mag*sin(ang));
  1470. X            }
  1471. X            break;
  1472. X        case CMPLX:
  1473. X            switch (b.type) {
  1474. X                case INT:
  1475. X                    if (a.v.cmplx_val.imag == 0.0) {
  1476. X                        mag = pow(a.v.cmplx_val.real,(double)abs(b.v.int_val));
  1477. X                        if (b.v.int_val < 0)
  1478. X                          if (mag != 0.0)
  1479. X                            mag = 1.0/mag;
  1480. X                          else 
  1481. X                            undefined = TRUE;
  1482. X                        (void) complex(&result,mag,0.0);
  1483. X                    }
  1484. X                    else {
  1485. X                        /* not so good, but...! */
  1486. X                        mag = pow(magnitude(&a),(double)abs(b.v.int_val));
  1487. X                        if (b.v.int_val < 0)
  1488. X                          if (mag != 0.0)
  1489. X                            mag = 1.0/mag;
  1490. X                          else 
  1491. X                            undefined = TRUE;
  1492. X                        ang = angle(&a)*b.v.int_val;
  1493. X                        (void) complex(&result,mag*cos(ang),
  1494. X                            mag*sin(ang));
  1495. X                    }
  1496. X                    break;
  1497. X                case CMPLX:
  1498. X                    mag = pow(magnitude(&a),fabs(b.v.cmplx_val.real));
  1499. X                    if (b.v.cmplx_val.real < 0.0)
  1500. X                      if (mag != 0.0)
  1501. X                        mag = 1.0/mag;
  1502. X                      else 
  1503. X                        undefined = TRUE;
  1504. X                    mag *= exp(-b.v.cmplx_val.imag*angle(&a));
  1505. X                    ang = b.v.cmplx_val.real*angle(&a) +
  1506. X                          b.v.cmplx_val.imag*log(magnitude(&a));
  1507. X                    (void) complex(&result,mag*cos(ang),
  1508. X                        mag*sin(ang));
  1509. X            }
  1510. X    }
  1511. X    push(&result);
  1512. }
  1513. X
  1514. X
  1515. f_factorial()
  1516. {
  1517. struct value a;
  1518. register int i;
  1519. register double val;
  1520. X
  1521. X    (void) pop(&a);    /* find a! (factorial) */
  1522. X
  1523. X    switch (a.type) {
  1524. X        case INT:
  1525. X            val = 1.0;
  1526. X            for (i = a.v.int_val; i > 1; i--)  /*fpe's should catch overflows*/
  1527. X                val *= i;
  1528. X            break;
  1529. X        default:
  1530. X            int_error("factorial (!) argument must be an integer",
  1531. X            NO_CARET);
  1532. X        }
  1533. X
  1534. X    push(complex(&a,val,0.0));
  1535. X            
  1536. }
  1537. X
  1538. X
  1539. int
  1540. f_jump(x)
  1541. union argument *x;
  1542. {
  1543. X    return(x->j_arg);
  1544. }
  1545. X
  1546. X
  1547. int
  1548. f_jumpz(x)
  1549. union argument *x;
  1550. {
  1551. struct value a;
  1552. X    int_check(&top_of_stack);
  1553. X    if (top_of_stack.v.int_val) {    /* non-zero */
  1554. X        (void) pop(&a);
  1555. X        return 1;                /* no jump */
  1556. X    }
  1557. X    else
  1558. X        return(x->j_arg);        /* leave the argument on TOS */
  1559. }
  1560. X
  1561. X
  1562. int
  1563. f_jumpnz(x)
  1564. union argument *x;
  1565. {
  1566. struct value a;
  1567. X    int_check(&top_of_stack);
  1568. X    if (top_of_stack.v.int_val)    /* non-zero */
  1569. X        return(x->j_arg);        /* leave the argument on TOS */
  1570. X    else {
  1571. X        (void) pop(&a);
  1572. X        return 1;                /* no jump */
  1573. X    }
  1574. }
  1575. X
  1576. X
  1577. int
  1578. f_jtern(x)
  1579. union argument *x;
  1580. {
  1581. struct value a;
  1582. X
  1583. X    int_check(pop(&a));
  1584. X    if (a.v.int_val)
  1585. X        return(1);                /* no jump; fall through to TRUE code */
  1586. X    else
  1587. X        return(x->j_arg);        /* go jump to FALSE code */
  1588. }
  1589. SHAR_EOF
  1590. chmod 0644 gnuplot/internal.c ||
  1591. echo 'restore of gnuplot/internal.c failed'
  1592. Wc_c="`wc -c < 'gnuplot/internal.c'`"
  1593. test 16092 -eq "$Wc_c" ||
  1594.     echo 'gnuplot/internal.c: original size 16092, current size' "$Wc_c"
  1595. rm -f _shar_wnt_.tmp
  1596. fi
  1597. # ============= gnuplot/command.c ==============
  1598. if test -f 'gnuplot/command.c' -a X"$1" != X"-c"; then
  1599.     echo 'x - skipping gnuplot/command.c (File already exists)'
  1600.     rm -f _shar_wnt_.tmp
  1601. else
  1602. > _shar_wnt_.tmp
  1603. echo 'x - extracting gnuplot/command.c (Text)'
  1604. sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/command.c' &&
  1605. /* GNUPLOT - command.c */
  1606. /*
  1607. X * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  1608. X *
  1609. X * Permission to use, copy, and distribute this software and its
  1610. X * documentation for any purpose with or without fee is hereby granted, 
  1611. X * provided that the above copyright notice appear in all copies and 
  1612. X * that both that copyright notice and this permission notice appear 
  1613. X * in supporting documentation.
  1614. X *
  1615. X * Permission to modify the software is granted, but not the right to
  1616. X * distribute the modified code.  Modifications are to be distributed 
  1617. X * as patches to released version.
  1618. X *  
  1619. X * This software is provided "as is" without express or implied warranty.
  1620. X * 
  1621. X *
  1622. X * AUTHORS
  1623. X * 
  1624. X *   Original Software:
  1625. X *     Thomas Williams,  Colin Kelley.
  1626. X * 
  1627. X *   Gnuplot 2.0 additions:
  1628. X *       Russell Lang, Dave Kotz, John Campbell.
  1629. X *
  1630. X *   Gnuplot 3.0 additions:
  1631. X *       Gershon Elber and many others.
  1632. X * 
  1633. X * Send your comments or suggestions to 
  1634. X *  pixar!info-gnuplot@sun.com.
  1635. X * This is a mailing list; to join it send a note to 
  1636. X *  pixar!info-gnuplot-request@sun.com.  
  1637. X * Send bug reports to
  1638. X *  pixar!bug-gnuplot@sun.com.
  1639. X */
  1640. X
  1641. #include <stdio.h>
  1642. #include <math.h>
  1643. X
  1644. #ifdef AMIGA_AC_5
  1645. #include <time.h>
  1646. void sleep();        /* defined later */
  1647. #endif
  1648. X
  1649. #ifdef MSDOS
  1650. #include <process.h>
  1651. X
  1652. #ifdef __ZTC__
  1653. #define P_WAIT 0
  1654. #include <time.h>    /* usleep() */
  1655. #else
  1656. X
  1657. #ifdef __TURBOC__
  1658. #include <dos.h>    /* sleep() */
  1659. #include <conio.h>
  1660. extern unsigned _stklen = 16394;    /* increase stack size */
  1661. X
  1662. #else    /* must be MSC */
  1663. #include <time.h>    /* kludge to provide sleep() */
  1664. void sleep();        /* defined later */
  1665. #endif /* TURBOC */
  1666. #endif /* ZTC */
  1667. X
  1668. #endif /* MSDOS */
  1669. X
  1670. #ifdef AMIGA_LC_5_1
  1671. #include <proto/dos.h>
  1672. void sleep();
  1673. #endif    /* AMIGA_LC_5_1 */
  1674. X
  1675. #include "plot.h"
  1676. #include "setshow.h"
  1677. #include "help.h"
  1678. X
  1679. #ifndef STDOUT
  1680. #define STDOUT 1
  1681. #endif
  1682. X
  1683. #ifndef HELPFILE
  1684. #ifdef AMIGA_LC_5_1
  1685. #define HELPFILE "S:gnuplot.gih"
  1686. #else
  1687. #define HELPFILE "docs/gnuplot.gih" /* changed by makefile */
  1688. #endif
  1689. #endif
  1690. X
  1691. #define inrange(z,min,max) ((min<max) ? ((z>=min)&&(z<=max)) : ((z>=max)&&(z<=min)) )
  1692. X
  1693. /*
  1694. X * instead of <strings.h>
  1695. X */
  1696. X
  1697. extern char *gets(),*getenv();
  1698. extern char *strcpy(),*strncpy(),*strcat();
  1699. extern int strlen(), strcmp();
  1700. X
  1701. /*
  1702. X * Only reference to contours library.
  1703. X */
  1704. extern struct gnuplot_contours *contour();
  1705. X
  1706. #if defined(unix) && !defined(hpux)
  1707. #ifdef GETCWD
  1708. extern char *getcwd();    /* some Unix's use getcwd */
  1709. #else
  1710. extern char *getwd();    /* most Unix's use getwd */
  1711. #endif
  1712. #else
  1713. extern char *getcwd();    /* Turbo C, MSC and VMS use getcwd */
  1714. #endif
  1715. X
  1716. #ifdef vms
  1717. int vms_vkid; /* Virtual keyboard id */
  1718. #endif
  1719. X
  1720. extern int chdir();
  1721. X
  1722. extern double magnitude(),angle(),real(),imag();
  1723. extern struct value *const_express(), *pop(), *complex();
  1724. extern struct at_type *temp_at(), *perm_at();
  1725. extern struct udft_entry *add_udf();
  1726. extern struct udvt_entry *add_udv();
  1727. extern void squash_spaces();
  1728. extern void lower_case();
  1729. X
  1730. /* local functions */
  1731. static enum coord_type adjustlog();
  1732. X
  1733. extern BOOLEAN interactive;    /* from plot.c */
  1734. X
  1735. /* input data, parsing variables */
  1736. struct lexical_unit token[MAX_TOKENS];
  1737. char input_line[MAX_LINE_LEN+1] = "";
  1738. int num_tokens, c_token;
  1739. int inline_num = 0;            /* input line number */
  1740. X
  1741. char c_dummy_var[MAX_NUM_VAR][MAX_ID_LEN+1];    /* current dummy vars */
  1742. X
  1743. /* the curves/surfaces of the plot */
  1744. struct curve_points *first_plot = NULL;
  1745. struct surface_points *first_3dplot = NULL;
  1746. static struct udft_entry plot_func;
  1747. struct udft_entry *dummy_func;
  1748. X
  1749. /* support for replot command */
  1750. char replot_line[MAX_LINE_LEN+1] = "";
  1751. static int plot_token;                    /* start of 'plot' command */
  1752. X
  1753. /* If last plot was a 3d one. */
  1754. BOOLEAN is_3d_plot = FALSE;
  1755. X
  1756. com_line()
  1757. {
  1758. X    read_line(PROMPT);
  1759. X
  1760. X    /* So we can flag any new output: if false at time of error, */
  1761. X    /* we reprint the command line before printing caret. */
  1762. X    /* TRUE for interactive terminals, since the command line is typed. */
  1763. X    /* FALSE for non-terminal stdin, so command line is printed anyway. */
  1764. X    /* (DFK 11/89) */
  1765. X    screen_ok = interactive; 
  1766. X
  1767. X    do_line();
  1768. }
  1769. X
  1770. X
  1771. do_line()      /* also used in load_file */
  1772. {
  1773. X    if (is_system(input_line[0])) {
  1774. X        do_system();
  1775. X        (void) fputs("!\n",stderr);
  1776. X        return;
  1777. X    }
  1778. X    num_tokens = scanner(input_line);
  1779. X    c_token = 0;
  1780. X    while(c_token < num_tokens) {
  1781. X        command();
  1782. X        if (c_token < num_tokens)    /* something after command */
  1783. X            if (equals(c_token,";"))
  1784. X                c_token++;
  1785. X            else
  1786. X                    int_error("';' expected",c_token);
  1787. X    }
  1788. }
  1789. X
  1790. X
  1791. X
  1792. command()
  1793. {
  1794. X    int i;
  1795. X    char sv_file[MAX_LINE_LEN+1];
  1796. X    /* string holding name of save or load file */
  1797. X
  1798. X    for (i = 0; i < MAX_NUM_VAR; i++)
  1799. X        c_dummy_var[i][0] = '\0';        /* no dummy variables */
  1800. X
  1801. X    if (is_definition(c_token))
  1802. X        define();
  1803. X    else if (almost_equals(c_token,"h$elp") || equals(c_token,"?")) {
  1804. X        c_token++;
  1805. X        do_help();
  1806. X    }
  1807. X    else if (almost_equals(c_token,"test")) {
  1808. X        c_token++;
  1809. X        test_term();
  1810. X    }
  1811. X    else if (almost_equals(c_token,"pa$use")) {
  1812. X        struct value a;
  1813. X        int stime, text=0;
  1814. X        char buf[MAX_LINE_LEN+1];
  1815. X
  1816. X        c_token++;
  1817. X        stime = (int )real(const_express(&a));
  1818. X        if (!(END_OF_COMMAND)) {
  1819. X            if (!isstring(c_token))
  1820. X                int_error("expecting string",c_token);
  1821. X            else {
  1822. X                quotel_str(buf,c_token);
  1823. X                (void) fprintf (stderr, "%s",buf);
  1824. X                text = 1;
  1825. X            }
  1826. X        }
  1827. X        if (stime < 0) (void) fgets (buf,MAX_LINE_LEN,stdin);  
  1828. X                        /* Hold until CR hit. */
  1829. #ifdef __ZTC__
  1830. X        if (stime > 0) usleep((unsigned long) stime);
  1831. #else
  1832. X        if (stime > 0) sleep((unsigned int) stime);
  1833. #endif
  1834. X        if (text != 0 && stime >= 0) (void) fprintf (stderr,"\n");
  1835. X        c_token++;
  1836. X        screen_ok = FALSE;
  1837. X    }
  1838. X    else if (almost_equals(c_token,"pr$int")) {
  1839. X        struct value a;
  1840. X
  1841. X        c_token++;
  1842. X        (void) const_express(&a);
  1843. X        (void) putc('\t',stderr);
  1844. X        disp_value(stderr,&a);
  1845. X        (void) putc('\n',stderr);
  1846. X        screen_ok = FALSE;
  1847. X    }
  1848. X    else if (almost_equals(c_token,"p$lot")) {
  1849. X        plot_token = c_token++;
  1850. X        plotrequest();
  1851. X    }
  1852. X    else if (almost_equals(c_token,"sp$lot")) {
  1853. X        plot_token = c_token++;
  1854. X        plot3drequest();
  1855. X    }
  1856. X    else if (almost_equals(c_token,"rep$lot")) {
  1857. X        if (replot_line[0] == '\0') 
  1858. X            int_error("no previous plot",c_token);
  1859. X        c_token++;
  1860. X        replotrequest();
  1861. X    }
  1862. X    else if (almost_equals(c_token,"se$t"))
  1863. X        set_command();
  1864. X    else if (almost_equals(c_token,"sh$ow"))
  1865. X        show_command();
  1866. X    else if (almost_equals(c_token,"cl$ear")) {
  1867. X        if (!term_init) {
  1868. X            (*term_tbl[term].init)();
  1869. X            term_init = TRUE;
  1870. X        }
  1871. X        (*term_tbl[term].graphics)();
  1872. X        (*term_tbl[term].text)();
  1873. X        (void) fflush(outfile);
  1874. X        screen_ok = FALSE;
  1875. X        c_token++;
  1876. X    }
  1877. X    else if (almost_equals(c_token,"she$ll")) {
  1878. X        do_shell();
  1879. X        screen_ok = FALSE;
  1880. X        c_token++;
  1881. X    }
  1882. X    else if (almost_equals(c_token,"sa$ve")) {
  1883. X        if (almost_equals(++c_token,"f$unctions")) {
  1884. X            if (!isstring(++c_token))
  1885. X                int_error("expecting filename",c_token);
  1886. X            else {
  1887. X                quote_str(sv_file,c_token);
  1888. X                save_functions(fopen(sv_file,"w"));
  1889. X            }
  1890. X        }
  1891. X        else if (almost_equals(c_token,"v$ariables")) {
  1892. X            if (!isstring(++c_token))
  1893. X                int_error("expecting filename",c_token);
  1894. X            else {
  1895. X                quote_str(sv_file,c_token);
  1896. X                save_variables(fopen(sv_file,"w"));
  1897. X            }
  1898. X        }
  1899. X        else if (almost_equals(c_token,"s$et")) {
  1900. X            if (!isstring(++c_token))
  1901. X                int_error("expecting filename",c_token);
  1902. X            else {
  1903. X                quote_str(sv_file,c_token);
  1904. X                save_set(fopen(sv_file,"w"));
  1905. X            }
  1906. X        }
  1907. X        else if (isstring(c_token)) {
  1908. X            quote_str(sv_file,c_token);
  1909. X            save_all(fopen(sv_file,"w"));
  1910. X        }
  1911. X        else {
  1912. X            int_error(
  1913. X        "filename or keyword 'functions', 'variables', or 'set' expected",
  1914. X                    c_token);
  1915. X        }
  1916. X        c_token++;
  1917. X    }
  1918. X    else if (almost_equals(c_token,"l$oad")) {
  1919. X        if (!isstring(++c_token))
  1920. X            int_error("expecting filename",c_token);
  1921. X        else {
  1922. X            quote_str(sv_file,c_token);
  1923. X            load_file(fopen(sv_file,"r"), sv_file);    
  1924. X        /* input_line[] and token[] now destroyed! */
  1925. X            c_token = num_tokens = 0;
  1926. X        }
  1927. X    }
  1928. X    else if (almost_equals(c_token,"cd")) {
  1929. X        if (!isstring(++c_token))
  1930. X            int_error("expecting directory name",c_token);
  1931. X        else {
  1932. X            quotel_str(sv_file,c_token);
  1933. X            if (chdir(sv_file)) {
  1934. X              int_error("Can't change to this directory",c_token);
  1935. X            }
  1936. X        c_token++;
  1937. X        }
  1938. X    }
  1939. X    else if (almost_equals(c_token,"pwd")) {
  1940. #if defined(unix) && !defined(hpux)
  1941. #ifdef GETCWD
  1942. X      (void) getcwd(sv_file,MAX_ID_LEN); /* some Unix's use getcwd */
  1943. #else
  1944. X      (void) getwd(sv_file); /* most Unix's use getwd */
  1945. #endif
  1946. #else
  1947. /* Turbo C and VMS have getcwd() */
  1948. X      (void) getcwd(sv_file,MAX_ID_LEN);
  1949. #endif
  1950. X      fprintf(stderr,"%s\n", sv_file);
  1951. X      c_token++;
  1952. X    }
  1953. X    else if (almost_equals(c_token,"ex$it") ||
  1954. X            almost_equals(c_token,"q$uit")) {
  1955. X        done(IO_SUCCESS);
  1956. X    }
  1957. X    else if (!equals(c_token,";")) {        /* null statement */
  1958. X        int_error("invalid command",c_token);
  1959. X    }
  1960. }
  1961. X
  1962. replotrequest()
  1963. {
  1964. char str[MAX_LINE_LEN+1];
  1965. X        if(equals(c_token,"["))
  1966. X            int_error("cannot set range with replot",c_token);
  1967. X        if (!END_OF_COMMAND) {
  1968. X            capture(str,c_token,num_tokens-1);
  1969. X            if ( (strlen(str) + strlen(replot_line)) <= MAX_LINE_LEN-1) {
  1970. X                (void) strcat(replot_line,",");
  1971. X                (void) strcat(replot_line,str); 
  1972. X            } else {
  1973. X                int_error("plot line too long with replot arguments",c_token);
  1974. X            }
  1975. X        }
  1976. X        (void) strcpy(input_line,replot_line);
  1977. X        screen_ok = FALSE;
  1978. X        num_tokens = scanner(input_line);
  1979. X        c_token = 1;                    /* skip the 'plot' part */
  1980. X        is_3d_plot ? plot3drequest() : plotrequest();
  1981. }
  1982. X
  1983. X
  1984. plotrequest()
  1985. /*
  1986. X   In the parametric case we can say 
  1987. X      plot [a= -4:4] [-2:2] [-1:1] sin(a),a**2
  1988. X   while in the non-parametric case we would say only
  1989. X      plot [b= -2:2] [-1:1] sin(b)
  1990. */
  1991. {
  1992. X    BOOLEAN changed;
  1993. X    int dummy_token = -1;
  1994. X
  1995. X    is_3d_plot = FALSE;
  1996. X
  1997. X    if (parametric && strcmp(dummy_var[0], "u") == 0)
  1998. X    strcpy (dummy_var[0], "t");
  1999. X
  2000. X    autoscale_lt = autoscale_t;
  2001. X    autoscale_lx = autoscale_x;
  2002. X    autoscale_ly = autoscale_y;
  2003. X
  2004. X    if (!term)                    /* unknown */
  2005. X        int_error("use 'set term' to set terminal type first",c_token);
  2006. X
  2007. X    if (equals(c_token,"[")) {
  2008. X        c_token++;
  2009. X        if (isletter(c_token)) {
  2010. X            if (equals(c_token+1,"=")) {
  2011. X               dummy_token = c_token;
  2012. X               c_token += 2;
  2013. X            } else {
  2014. X               /* oops; probably an expression with a variable. */
  2015. X               /* Parse it as an xmin expression. */
  2016. X               /* used to be: int_error("'=' expected",c_token); */
  2017. X            }
  2018. X        }
  2019. X        changed = parametric ? load_range(&tmin,&tmax):load_range(&xmin,&xmax);
  2020. X        if (!equals(c_token,"]"))
  2021. X            int_error("']' expected",c_token);
  2022. X        c_token++;
  2023. X        if (changed) {
  2024. X            if (parametric)
  2025. X                autoscale_lt = FALSE;
  2026. X            else
  2027. X                autoscale_lx = FALSE;
  2028. X        }
  2029. X    }
  2030. X
  2031. X    if (parametric && equals(c_token,"[")) { /* set optional x ranges */
  2032. X        c_token++;
  2033. X        changed = load_range(&xmin,&xmax);
  2034. X        if (!equals(c_token,"]"))
  2035. X            int_error("']' expected",c_token);
  2036. X        c_token++;
  2037. X        if (changed)
  2038. X          autoscale_lx = FALSE;
  2039. X    }
  2040. X
  2041. X    if (equals(c_token,"[")) { /* set optional y ranges */
  2042. X        c_token++;
  2043. X        changed = load_range(&ymin,&ymax);
  2044. X        if (!equals(c_token,"]"))
  2045. X            int_error("']' expected",c_token);
  2046. X        c_token++;
  2047. X        if (changed)
  2048. X          autoscale_ly = FALSE;
  2049. X    }
  2050. X
  2051. X     /* use the default dummy variable unless changed */
  2052. X    if (dummy_token >= 0)
  2053. X      copy_str(c_dummy_var[0],dummy_token);
  2054. X    else
  2055. X      (void) strcpy(c_dummy_var[0],dummy_var[0]);
  2056. X
  2057. X    eval_plots();
  2058. }
  2059. X
  2060. plot3drequest()
  2061. /*
  2062. X   in the parametric case we would say
  2063. 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)
  2064. X   in the non-parametric case we would say only
  2065. X      splot [x= -2:2] [y= -5:5] sin(x)*cos(y)
  2066. X
  2067. */
  2068. {
  2069. X    BOOLEAN changed;
  2070. X    int dummy_token0 = -1,
  2071. X    dummy_token1 = -1;
  2072. X
  2073. X    is_3d_plot = TRUE;
  2074. X
  2075. X    if (parametric && strcmp(dummy_var[0], "t") == 0) {
  2076. X        strcpy (dummy_var[0], "u");
  2077. X        strcpy (dummy_var[1], "v");
  2078. X    }
  2079. X
  2080. X    autoscale_lx = autoscale_x;
  2081. X    autoscale_ly = autoscale_y;
  2082. X    autoscale_lz = autoscale_z;
  2083. X
  2084. X    if (!term)                    /* unknown */
  2085. X        int_error("use 'set term' to set terminal type first",c_token);
  2086. X
  2087. X    if (equals(c_token,"[")) {
  2088. X        c_token++;
  2089. X        if (isletter(c_token)) {
  2090. X            if (equals(c_token+1,"=")) {
  2091. X               dummy_token0 = c_token;
  2092. X               c_token += 2;
  2093. X            } else {
  2094. X               /* oops; probably an expression with a variable. */
  2095. X               /* Parse it as an xmin expression. */
  2096. X               /* used to be: int_error("'=' expected",c_token); */
  2097. X            }
  2098. X        }
  2099. X        changed = parametric ? load_range(&umin,&umax):load_range(&xmin,&xmax);
  2100. X        if (!equals(c_token,"]"))
  2101. X            int_error("']' expected",c_token);
  2102. X        c_token++;
  2103. X        if (changed && !parametric) {
  2104. X            autoscale_lx = FALSE;
  2105. X        }
  2106. X    }
  2107. X
  2108. X    if (equals(c_token,"[")) {
  2109. X        c_token++;
  2110. X        if (isletter(c_token)) {
  2111. X            if (equals(c_token+1,"=")) {
  2112. X               dummy_token1 = c_token;
  2113. X               c_token += 2;
  2114. X            } else {
  2115. X               /* oops; probably an expression with a variable. */
  2116. X               /* Parse it as an xmin expression. */
  2117. X               /* used to be: int_error("'=' expected",c_token); */
  2118. X            }
  2119. X        }
  2120. X        changed = parametric ? load_range(&vmin,&vmax):load_range(&ymin,&ymax);
  2121. X        if (!equals(c_token,"]"))
  2122. X            int_error("']' expected",c_token);
  2123. X        c_token++;
  2124. X        if (changed && !parametric) {
  2125. X            autoscale_ly = FALSE;
  2126. X        }
  2127. X    }
  2128. X
  2129. X    if (equals(c_token,"[")) { /* set optional x ranges */
  2130. X        c_token++;
  2131. X        changed = load_range(&xmin,&xmax);
  2132. X        if (!equals(c_token,"]"))
  2133. X            int_error("']' expected",c_token);
  2134. X        c_token++;
  2135. X        if (changed)
  2136. X          autoscale_lx = FALSE;
  2137. X    }
  2138. X
  2139. X    if (equals(c_token,"[")) { /* set optional y ranges */
  2140. X        c_token++;
  2141. X        changed = load_range(&ymin,&ymax);
  2142. X        if (!equals(c_token,"]"))
  2143. X            int_error("']' expected",c_token);
  2144. X        c_token++;
  2145. X        if (changed)
  2146. X          autoscale_ly = FALSE;
  2147. X    }
  2148. X
  2149. X    if (equals(c_token,"[")) { /* set optional z ranges */
  2150. X        c_token++;
  2151. X        changed = load_range(&zmin,&zmax);
  2152. X        if (!equals(c_token,"]"))
  2153. X            int_error("']' expected",c_token);
  2154. X        c_token++;
  2155. X        if (changed)
  2156. X          autoscale_lz = FALSE;
  2157. X    }
  2158. X
  2159. X     /* use the default dummy variable unless changed */
  2160. X    if (dummy_token0 >= 0)
  2161. X      copy_str(c_dummy_var[0],dummy_token0);
  2162. X    else
  2163. X      (void) strcpy(c_dummy_var[0],dummy_var[0]);
  2164. X
  2165. X    if (dummy_token1 >= 0)
  2166. X      copy_str(c_dummy_var[1],dummy_token1);
  2167. X    else
  2168. X      (void) strcpy(c_dummy_var[1],dummy_var[1]);
  2169. X
  2170. X    eval_3dplots();
  2171. }
  2172. X
  2173. X
  2174. define()
  2175. {
  2176. register int start_token;  /* the 1st token in the function definition */
  2177. register struct udvt_entry *udv;
  2178. register struct udft_entry *udf;
  2179. X
  2180. X    if (equals(c_token+1,"(")) {
  2181. SHAR_EOF
  2182. true || echo 'restore of gnuplot/command.c failed'
  2183. fi
  2184. echo 'End of  part 12'
  2185. echo 'File gnuplot/command.c is continued in part 13'
  2186. echo 13 > _shar_seq_.tmp
  2187. exit 0
  2188.  
  2189. exit 0 # Just in case...
  2190. -- 
  2191. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2192. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2193. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2194. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2195.