FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/src/command.c at branch-4-2-stable · gnuplot/gnuplot-old · GitHub
gnuplot
gnuplot-old
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot-old
/
src
/
command.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
3024 lines (2639 loc) · 75.3 KB
Breadcrumbs
gnuplot-old
/
src
/
command.c
Copy path
File metadata and controls
3024 lines (2639 loc) · 75.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef
lint
static
char
*
RCSid
() {
return
RCSid
(
"$Id: command.c,v 1.144.2.11 2008/12/12 06:57:50 sfeam Exp $"
); }
#endif
/* GNUPLOT - command.c */
/*[
* Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* Changes:
*
* Feb 5, 1992 Jack Veenstra (veenstra@cs.rochester.edu) Added support to
* filter data values read from a file through a user-defined function before
* plotting. The keyword "thru" was added to the "plot" command. Example
* syntax: f(x) = x / 100 plot "test.data" thru f(x) This example divides all
* the y values by 100 before plotting. The filter function processes the
* data before any log-scaling occurs. This capability should be generalized
* to filter x values as well and a similar feature should be added to the
* "splot" command.
*
* 19 September 1992 Lawrence Crowl (crowl@cs.orst.edu)
* Added user-specified bases for log scaling.
*
* April 1999 Franz Bakan (bakan@ukezyk.desy.de)
* Added code to support mouse-input from OS/2 PM window
* Changes marked by USE_MOUSE
*
* May 1999, update by Petr Mikulik
* Use gnuplot's pid in shared mem name
*
* August 1999 Franz Bakan and Petr Mikulik
* Encapsulating read_line into a thread, acting on input when thread or
* gnupmdrv posts an event semaphore. Thus mousing works even when gnuplot
* is used as a plotting device (commands passed via pipe).
*
*/
#include
"command.h"
#include
"alloc.h"
#include
"eval.h"
#include
"fit.h"
#include
"binary.h"
#include
"datafile.h"
#include
"getcolor.h"
#include
"gp_hist.h"
#include
"gp_time.h"
#include
"misc.h"
#include
"parse.h"
#include
"plot.h"
#include
"plot2d.h"
#include
"plot3d.h"
#include
"readline.h"
#include
"save.h"
#include
"scanner.h"
#include
"setshow.h"
#include
"tables.h"
#include
"term_api.h"
#include
"util.h"
#ifdef
USE_MOUSE
# include
"mouse.h"
#endif
#define
PROMPT
"gnuplot> "
#if
(defined(
MSDOS
)
||
defined(
DOS386
))
&&
defined(
__TURBOC__
)
&&
!defined(
_Windows
)
unsigned
_stklen
=
16394
;
/* increase stack size */
#endif
/* MSDOS && TURBOC */
#ifdef
OS2_IPC
# define
INCL_DOSMEMMGR
# define
INCL_DOSPROCESS
# define
INCL_DOSSEMAPHORES
# include
<os2.h>
PVOID
input_from_PM_Terminal
=
NULL
;
char
mouseSharedMemName
[
40
]
=
""
;
HEV
semInputReady
=
0
;
/* semaphore to be created in plot.c */
int
thread_rl_Running
=
0
;
/* running status */
int
thread_rl_RetCode
=
-1
;
/* return code from readline in a thread */
#endif
/* OS2_IPC */
#ifndef
_Windows
# include
"help.h"
#else
# ifdef
USE_OWN_WINSYSTEM_FUNCTION
static
int
winsystem
__PROTO
((
const
char
*
));
# endif
#endif
/* _Windows */
#ifdef
_Windows
# include
<windows.h>
# ifdef
__MSC__
# include
<malloc.h>
# include
<direct.h>
/* getcwd() */
# else
# include
<alloc.h>
# ifndef
__WATCOMC__
# include
<dir.h>
/* setdisk() */
# endif
# endif
/* !MSC */
# include
"win/winmain.h"
#endif
/* _Windows */
#ifdef
VMS
int
vms_vkid
;
/* Virtual keyboard id */
int
vms_ktid
;
/* key table id, for translating keystrokes */
#endif
/* VMS */
/* static prototypes */
static
void
command
__PROTO
((
void
));
static
int
changedir
__PROTO
((
char
*
path
));
static
char
*
fgets_ipc
__PROTO
((
char
*
dest
,
int
len
));
static
int
read_line
__PROTO
((
const
char
*
prompt
));
static
void
do_system
__PROTO
((
const
char
*
));
static
void
test_palette_subcommand
__PROTO
((
void
));
static
void
test_time_subcommand
__PROTO
((
void
));
#ifdef
AMIGA_AC_5
static
void
getparms
__PROTO
((
char
*
,
char
*
*
));
#endif
#ifdef
GP_MACROS
static
int
string_expand
__PROTO
((
void
));
TBOOLEAN
expand_macros
=
FALSE;
#endif
struct
lexical_unit
*
token
;
int
token_table_size
;
char
*
gp_input_line
;
size_t
gp_input_line_len
;
int
inline_num
;
/* input line number */
struct
udft_entry
*
dummy_func
;
/* support for replot command */
char
*
replot_line
;
int
plot_token
;
/* start of 'plot' command */
/* flag to disable `replot` when some data are sent through stdin;
* used by mouse/hotkey capable terminals */
TBOOLEAN
replot_disabled
=
FALSE;
#ifdef
USE_MOUSE
int
paused_for_mouse
=
0
;
#endif
/* output file for the print command */
FILE
*
print_out
=
NULL
;
char
*
print_out_name
=
NULL
;
/* input data, parsing variables */
#ifdef
AMIGA_SC_6_1
__far
int
num_tokens
,
c_token
;
#else
int
num_tokens
,
c_token
;
#endif
static
int
if_depth
=
0
;
static
TBOOLEAN
if_condition
=
FALSE;
static
int
command_exit_status
=
0
;
/* support for dynamic size of input line */
void
extend_input_line
()
{
if
(
gp_input_line_len
==
0
) {
/* first time */
gp_input_line
=
gp_alloc
(
MAX_LINE_LEN
,
"gp_input_line"
);
gp_input_line_len
=
MAX_LINE_LEN
;
gp_input_line
[
0
]
=
NUL
;
#ifdef
OS2_IPC
sprintf
(
mouseSharedMemName
,
"\\SHAREMEM\\GP%i_Mouse_Input"
,
getpid
() );
if
(
DosAllocSharedMem
((
PVOID
)
&
input_from_PM_Terminal
,
mouseSharedMemName
,
MAX_LINE_LEN
,
PAG_WRITE
|
PAG_COMMIT
))
fputs
(
"command.c: DosAllocSharedMem ERROR\n"
,
stderr
);
#endif
/* OS2_IPC */
}
else
{
gp_input_line
=
gp_realloc
(
gp_input_line
,
gp_input_line_len
+
MAX_LINE_LEN
,
"extend input line"
);
gp_input_line_len
+=
MAX_LINE_LEN
;
FPRINTF
((
stderr
,
"extending input line to %d chars\n"
,
gp_input_line_len
));
}
}
/* constant by which token table grows */
#define
MAX_TOKENS
400
void
extend_token_table
()
{
if
(
token_table_size
==
0
) {
/* first time */
token
=
(
struct
lexical_unit
*
)
gp_alloc
(
MAX_TOKENS
*
sizeof
(
struct
lexical_unit
),
"token table"
);
token_table_size
=
MAX_TOKENS
;
/* HBB: for checker-runs: */
memset
(
token
,
0
,
MAX_TOKENS
*
sizeof
(
*
token
));
}
else
{
token
=
gp_realloc
(
token
, (
token_table_size
+
MAX_TOKENS
)
*
sizeof
(
struct
lexical_unit
),
"extend token table"
);
memset
(
token
+
token_table_size
,
0
,
MAX_TOKENS
*
sizeof
(
*
token
));
token_table_size
+=
MAX_TOKENS
;
FPRINTF
((
stderr
,
"extending token table to %d elements\n"
,
token_table_size
));
}
}
#ifdef
OS2_IPC
void
thread_read_line
()
{
thread_rl_Running
=
1
;
thread_rl_RetCode
=
(
read_line
(
PROMPT
) );
thread_rl_Running
=
0
;
DosPostEventSem
(
semInputReady
);
}
#endif
/* OS2_IPC */
int
com_line
()
{
#ifdef
OS2_IPC
static
char
*
input_line_SharedMem
=
NULL
;
if
(
input_line_SharedMem
==
NULL
) {
/* get shared mem only once */
if
(
DosGetNamedSharedMem
((
PVOID
)
&
input_line_SharedMem
,
mouseSharedMemName
,
PAG_WRITE
|
PAG_READ
))
fputs
(
"readline.c: DosGetNamedSharedMem ERROR\n"
,
stderr
);
else
*
input_line_SharedMem
=
0
;
}
#endif
/* OS2_IPC */
if
(
multiplot
) {
/* calls int_error() if it is not happy */
term_check_multiplot_okay
(
interactive
);
if
(
read_line
(
"multiplot> "
))
return
(
1
);
}
else
{
#ifndef
USE_MOUSE
if
(
read_line
(
PROMPT
))
return
(
1
);
#else
# ifdef
OS2_IPC
ULONG
u
;
if
(
thread_rl_Running
==
0
) {
int
res
=
_beginthread
(
thread_read_line
,
NULL
,
32768
,
NULL
);
if
(
res
==
-1
)
fputs
(
"error command.c could not begin thread\n"
,
stderr
);
}
/* wait until a line is read or gnupmdrv makes shared mem available */
DosWaitEventSem
(
semInputReady
,
SEM_INDEFINITE_WAIT
);
DosResetEventSem
(
semInputReady
,
&
u
);
if
(
thread_rl_Running
) {
if
(
input_line_SharedMem
==
NULL
||
!
*
input_line_SharedMem
)
return
(
0
);
if
(
*
input_line_SharedMem
==
'%'
) {
do_event
( (
struct
gp_event_t
*
)(
input_line_SharedMem
+
1
) );
/* pass terminal's event */
input_line_SharedMem
[
0
]
=
0
;
/* discard the whole command line */
thread_rl_RetCode
=
0
;
return
(
0
);
}
if
(
*
input_line_SharedMem
&&
strstr
(
input_line_SharedMem
,
"plot"
)
!=
NULL
&&
(
strcmp
(
term
->
name
,
"pm"
)
&&
strcmp
(
term
->
name
,
"x11"
))) {
/* avoid plotting if terminal is not PM or X11 */
fprintf
(
stderr
,
"\n\tCommand(s) ignored for other than PM and X11 terminals\a\n"
);
if
(
interactive
)
fputs
(
PROMPT
,
stderr
);
input_line_SharedMem
[
0
]
=
0
;
/* discard the whole command line */
return
(
0
);
}
# if
0
fprintf
(
stderr
,
"shared mem received: |%s|\n"
,
input_line_SharedMem
);
if
(
*
input_line_SharedMem
&&
input_line_SharedMem
[
strlen
(
input_line_SharedMem
)
-
1
]
!=
'\n'
)
fprintf
(
stderr
,
"\n"
);
# endif
strcpy
(
gp_input_line
,
input_line_SharedMem
);
input_line_SharedMem
[
0
]
=
0
;
thread_rl_RetCode
=
0
;
}
if
(
thread_rl_RetCode
)
return
(
1
);
# else
/* OS2_IPC */
if
(
read_line
(
PROMPT
))
return
(
1
);
# endif
/* OS2_IPC */
#endif
/* USE_MOUSE */
}
/* So we can flag any new output: if false at time of error,
* we reprint the command line before printing caret.
* TRUE for interactive terminals, since the command line is typed.
* FALSE for non-terminal stdin, so command line is printed anyway.
* (DFK 11/89)
*/
screen_ok
=
interactive
;
if
(
do_line
())
return
(
1
);
else
return
(
0
);
}
int
do_line
()
{
/* Line continuation has already been handled
* by read_line() */
char
*
inlptr
=
gp_input_line
;
/* Skip leading whitespace */
while
(
isspace
((
unsigned
char
)
*
inlptr
))
inlptr
++
;
if
(
inlptr
!=
gp_input_line
) {
/* If there was leading whitespace, copy the actual
* command string to the front. use memmove() because
* source and target may overlap */
memmove
(
gp_input_line
,
inlptr
,
strlen
(
inlptr
));
/* Terminate resulting string */
gp_input_line
[
strlen
(
inlptr
)]
=
NUL
;
}
FPRINTF
((
stderr
,
"Input line: \"%s\"\n"
,
gp_input_line
));
#ifdef
GP_MACROS
/* Expand any string variables in the current input line.
* Allow up to 4 levels of recursion */
if
(
expand_macros
)
if
(
string_expand
()
&&
string_expand
()
&&
string_expand
()
&&
string_expand
()
&&
string_expand
())
int_error
(
NO_CARET
,
"Too many levels of nested macros"
);
#endif
/* also used in load_file */
if
(
is_system
(
gp_input_line
[
0
])) {
do_system
(
gp_input_line
+
1
);
if
(
interactive
)
/* 3.5 did it unconditionally */
(
void
)
fputs
(
"!\n"
,
stderr
);
/* why do we need this ? */
return
(
0
);
}
if_depth
=
0
;
if_condition
=
TRUE;
num_tokens
=
scanner
(
&
gp_input_line
,
&
gp_input_line_len
);
c_token
=
0
;
while
(
c_token
<
num_tokens
) {
command
();
if
(
command_exit_status
) {
command_exit_status
=
0
;
return
1
;
}
if
(
c_token
<
num_tokens
) {
/* something after command */
if
(
equals
(
c_token
,
";"
))
c_token
++
;
else
int_error
(
c_token
,
"';' expected"
);
}
}
return
(
0
);
}
void
do_string
(
char
*
s
)
{
char
*
orig_input_line
=
gp_strdup
(
gp_input_line
);
while
(
gp_input_line_len
<
strlen
(
s
)
+
1
)
extend_input_line
();
strcpy
(
gp_input_line
,
s
);
#ifdef
USE_MOUSE
if
(
display_ipc_commands
())
fprintf
(
stderr
,
"%s\n"
,
s
);
#endif
do_line
();
strcpy
(
gp_input_line
,
orig_input_line
);
free
(
orig_input_line
);
}
#ifdef
USE_MOUSE
void
toggle_display_of_ipc_commands
()
{
if
(
mouse_setting
.
verbose
)
mouse_setting
.
verbose
=
0
;
else
mouse_setting
.
verbose
=
1
;
}
int
display_ipc_commands
()
{
return
mouse_setting
.
verbose
;
}
void
do_string_replot
(
char
*
s
)
{
char
*
orig_input_line
=
gp_strdup
(
gp_input_line
);
while
(
gp_input_line_len
<
strlen
(
s
)
+
1
)
extend_input_line
();
strcpy
(
gp_input_line
,
s
);
if
(
display_ipc_commands
())
fprintf
(
stderr
,
"%s\n"
,
s
);
do_line
();
if
(!
replot_disabled
)
replotrequest
();
strcpy
(
gp_input_line
,
orig_input_line
);
free
(
orig_input_line
);
}
void
restore_prompt
()
{
if
(
interactive
) {
#if
defined(
HAVE_LIBREADLINE
)
rl_forced_update_display
();
#else
#if
defined(
HAVE_LIBEDITLINE
)
/* FIXME: editline does not support forced update,
so this is probably not enough */
rl_redisplay
();
#endif
fputs
(
PROMPT
,
stderr
);
fflush
(
stderr
);
#endif
}
}
#endif
/* USE_MOUSE */
void
define
()
{
int
start_token
;
/* the 1st token in the function definition */
struct
udvt_entry
*
udv
;
struct
udft_entry
*
udf
;
struct
value
result
;
if
(
equals
(
c_token
+
1
,
"("
)) {
/* function ! */
int
dummy_num
=
0
;
struct
at_type
*
at_tmp
;
char
save_dummy
[
MAX_NUM_VAR
][
MAX_ID_LEN
+
1
];
memcpy
(
save_dummy
,
c_dummy_var
,
sizeof
(
save_dummy
));
start_token
=
c_token
;
do
{
c_token
+=
2
;
/* skip to the next dummy */
copy_str
(
c_dummy_var
[
dummy_num
++
],
c_token
,
MAX_ID_LEN
);
}
while
(
equals
(
c_token
+
1
,
","
)
&&
(
dummy_num
<
MAX_NUM_VAR
));
if
(
equals
(
c_token
+
1
,
","
))
int_error
(
c_token
+
2
,
"function contains too many parameters"
);
c_token
+=
3
;
/* skip (, dummy, ) and = */
if
(
END_OF_COMMAND
)
int_error
(
c_token
,
"function definition expected"
);
udf
=
dummy_func
=
add_udf
(
start_token
);
udf
->
dummy_num
=
dummy_num
;
if
((
at_tmp
=
perm_at
())
==
(
struct
at_type
*
)
NULL
)
int_error
(
start_token
,
"not enough memory for function"
);
if
(
udf
->
at
)
/* already a dynamic a.t. there */
free_at
(
udf
->
at
);
/* so free it first */
udf
->
at
=
at_tmp
;
/* before re-assigning it. */
memcpy
(
c_dummy_var
,
save_dummy
,
sizeof
(
save_dummy
));
m_capture
(
&
(
udf
->
definition
),
start_token
,
c_token
-
1
);
dummy_func
=
NULL
;
/* dont let anyone else use our workspace */
}
else
{
/* variable ! */
char
*
varname
=
gp_input_line
+
token
[
c_token
].
start_index
;
if
(!
strncmp
(
varname
,
"GPVAL_"
,
6
)
||
!
strncmp
(
varname
,
"MOUSE_"
,
6
))
int_error
(
c_token
,
"Cannot set internal variables GPVAL_ and MOUSE_"
);
start_token
=
c_token
;
c_token
+=
2
;
udv
=
add_udv
(
start_token
);
(
void
)
const_express
(
&
result
);
#ifdef
GP_STRING_VARS
/* Prevents memory leak if the variable name is re-used */
if
(!
udv
->
udv_undef
)
gpfree_string
(
&
udv
->
udv_value
);
#endif
udv
->
udv_value
=
result
;
udv
->
udv_undef
=
FALSE;
}
}
void
undefine_command
()
{
char
key
[
MAX_ID_LEN
+
1
];
struct
udvt_entry
*
*
udv_ptr
=
&
first_udv
;
c_token
++
;
while
(!
END_OF_COMMAND
) {
copy_str
(
key
,
c_token
,
MAX_ID_LEN
);
if
(
strncmp
(
key
,
"GPVAL_"
,
6
)
&&
strncmp
(
key
,
"MOUSE_"
,
6
)) {
udv_ptr
=
&
first_udv
;
while
(
*
udv_ptr
) {
if
(!
strcmp
(
key
, (
*
udv_ptr
)
->
udv_name
)) {
(
*
udv_ptr
)
->
udv_undef
=
TRUE;
gpfree_string
(
&
((
*
udv_ptr
)
->
udv_value
));
break
;
}
udv_ptr
=
&
((
*
udv_ptr
)
->
next_udv
);
}
}
c_token
++
;
}
}
static
void
command
()
{
int
i
;
for
(
i
=
0
;
i
<
MAX_NUM_VAR
;
i
++
)
c_dummy_var
[
i
][
0
]
=
NUL
;
/* no dummy variables */
if
(
is_definition
(
c_token
))
define
();
else
(
*
lookup_ftable
(
&
command_ftbl
[
0
],
c_token
))();
return
;
}
/* process the 'raise' or 'lower' command */
void
raise_lower_command
(
int
lower
)
{
++
c_token
;
if
(
END_OF_COMMAND
) {
if
(
lower
) {
#ifdef
OS2
pm_lower_terminal_window
();
#endif
#ifdef
X11
x11_lower_terminal_group
();
#endif
#ifdef
_Windows
win_lower_terminal_window
();
#endif
#ifdef
WXWIDGETS
wxt_lower_terminal_group
();
#endif
}
else
{
#ifdef
OS2
pm_raise_terminal_window
();
#endif
#ifdef
X11
x11_raise_terminal_group
();
#endif
#ifdef
_Windows
win_raise_terminal_window
();
#endif
#ifdef
WXWIDGETS
wxt_raise_terminal_group
();
#endif
}
return
;
}
else
{
int
number
;
int
negative
=
equals
(
c_token
,
"-"
);
if
(
negative
||
equals
(
c_token
,
"+"
))
c_token
++
;
if
(!
END_OF_COMMAND
&&
isanumber
(
c_token
)) {
struct
value
a
;
number
=
real
(
const_express
(
&
a
));
if
(
negative
)
number
=
-
number
;
if
(
lower
) {
#ifdef
OS2
pm_lower_terminal_window
();
#endif
#ifdef
X11
x11_lower_terminal_window
(
number
);
#endif
#ifdef
_Windows
win_lower_terminal_window
();
#endif
#ifdef
WXWIDGETS
wxt_lower_terminal_window
(
number
);
#endif
}
else
{
#ifdef
OS2
pm_raise_terminal_window
();
#endif
#ifdef
X11
x11_raise_terminal_window
(
number
);
#endif
#ifdef
_Windows
win_raise_terminal_window
();
#endif
#ifdef
WXWIDGETS
wxt_raise_terminal_window
(
number
);
#endif
}
++
c_token
;
return
;
}
}
int_error
(
c_token
,
"usage: raise {x11_plot_n}"
);
}
void
raise_command
(
void
)
{
raise_lower_command
(
0
);
}
void
lower_command
(
void
)
{
raise_lower_command
(
1
);
}
#ifdef
USE_MOUSE
#define
WHITE_AFTER_TOKEN
(
x
) \
(' ' == gp_input_line[token[x].start_index + token[x].length] \
|| '\t' == gp_input_line[token[x].start_index + token[x].length] \
|| '\0' == gp_input_line[token[x].start_index + token[x].length])
/* process the 'bind' command */
void
bind_command
()
{
char
*
lhs
=
(
char
*
)
0
;
char
*
rhs
=
(
char
*
)
0
;
TBOOLEAN
allwindows
=
FALSE;
++
c_token
;
if
(!
END_OF_COMMAND
&&
equals
(
c_token
,
"!"
)) {
bind_remove_all
();
++
c_token
;
return
;
}
if
(!
END_OF_COMMAND
&&
almost_equals
(
c_token
,
"all$windows"
)) {
allwindows
=
TRUE;
c_token
++
;
}
/* get left hand side: the key or key sequence */
if
(!
END_OF_COMMAND
) {
char
*
first
=
gp_input_line
+
token
[
c_token
].
start_index
;
int
size
=
(
int
) (
strchr
(
first
,
' '
)
-
first
);
if
(
size
<
0
) {
size
=
(
int
) (
strchr
(
first
,
'\0'
)
-
first
);
}
if
(
size
<
0
) {
fprintf
(
stderr
,
"(bind_command) %s:%d\n"
,
__FILE__
,
__LINE__
);
return
;
}
lhs
=
(
char
*
)
gp_alloc
(
size
+
1
,
"bind_command->lhs"
);
if
(
isstring
(
c_token
)) {
quote_str
(
lhs
,
c_token
,
token_len
(
c_token
));
}
else
{
char
*
ptr
=
lhs
;
while
(!
END_OF_COMMAND
) {
copy_str
(
ptr
,
c_token
,
token_len
(
c_token
)
+
1
);
ptr
+=
token_len
(
c_token
);
if
(
WHITE_AFTER_TOKEN
(
c_token
)) {
break
;
}
++
c_token
;
}
}
++
c_token
;
}
/* get right hand side: the command. allocating the size
* of gp_input_line is too big, but shouldn't hurt too much. */
if
(!
END_OF_COMMAND
) {
rhs
=
(
char
*
)
gp_alloc
(
strlen
(
gp_input_line
)
+
1
,
"bind_command->rhs"
);
if
(
isstring
(
c_token
)) {
/* bind <lhs> "..." */
quote_str
(
rhs
,
c_token
,
token_len
(
c_token
));
c_token
++
;
}
else
{
char
*
ptr
=
rhs
;
while
(!
END_OF_COMMAND
) {
/* bind <lhs> ... ... ... */
copy_str
(
ptr
,
c_token
,
token_len
(
c_token
)
+
1
);
ptr
+=
token_len
(
c_token
);
if
(
WHITE_AFTER_TOKEN
(
c_token
)) {
*
ptr
++
=
' '
;
*
ptr
=
'\0'
;
}
c_token
++
;
}
}
}
FPRINTF
((
stderr
,
"(bind_command) |%s| |%s|\n"
,
lhs
,
rhs
));
/* bind_process() will eventually free lhs / rhs ! */
bind_process
(
lhs
,
rhs
,
allwindows
);
}
#endif
/* USE_MOUSE */
/*
* Command parser functions
*/
/* process the 'call' command */
void
call_command
()
{
char
*
save_file
=
NULL
;
c_token
++
;
save_file
=
try_to_get_string
();
if
(!
save_file
)
int_error
(
c_token
,
"expecting filename"
);
gp_expand_tilde
(
&
save_file
);
/* Argument list follows filename */
load_file
(
loadpath_fopen
(
save_file
,
"r"
),
save_file
, TRUE);
/* gp_input_line[] and token[] now destroyed! */
c_token
=
0
;
num_tokens
=
0
;
free
(
save_file
);
}
/* process the 'cd' command */
void
changedir_command
()
{
char
*
save_file
=
NULL
;
c_token
++
;
save_file
=
try_to_get_string
();
if
(!
save_file
)
int_error
(
c_token
,
"expecting directory name"
);
gp_expand_tilde
(
&
save_file
);
if
(
changedir
(
save_file
))
int_error
(
c_token
,
"Can't change to this directory"
);
free
(
save_file
);
}
/* process the 'clear' command */
void
clear_command
()
{
term_start_plot
();
if
(
multiplot
&&
term
->
fillbox
) {
unsigned
int
xx1
=
(
unsigned
int
) (
xoffset
*
term
->
xmax
);
unsigned
int
yy1
=
(
unsigned
int
) (
yoffset
*
term
->
ymax
);
unsigned
int
width
=
(
unsigned
int
) (
xsize
*
term
->
xmax
);
unsigned
int
height
=
(
unsigned
int
) (
ysize
*
term
->
ymax
);
(
*
term
->
fillbox
) (
0
,
xx1
,
yy1
,
width
,
height
);
}
term_end_plot
();
screen_ok
=
FALSE;
c_token
++
;
}
/* process the 'exit' and 'quit' commands */
void
exit_command
()
{
/* If the command is "exit gnuplot" then do so */
if
(
equals
(
c_token
+
1
,
"gnuplot"
))
exit
(
0
);
/* else graphics will be tidied up in main */
command_exit_status
=
1
;
}
/* fit_command() is in fit.c */
/* help_command() is below */
/* process the 'history' command */
void
history_command
()
{
#if
defined(
READLINE
)
||
defined(
HAVE_LIBREADLINE
)
||
defined(
HAVE_LIBEDITLINE
)
c_token
++
;
if
(!
END_OF_COMMAND
&&
equals
(
c_token
,
"?"
)) {
static
char
*
search_str
=
NULL
;
/* string from command line to search for */
/* find and show the entries */
c_token
++
;
m_capture
(
&
search_str
,
c_token
,
c_token
);
/* reallocates memory */
printf
(
"history ?%s\n"
,
search_str
);
if
(!
history_find_all
(
search_str
))
int_error
(
c_token
,
"not in history"
);
c_token
++
;
}
else
if
(!
END_OF_COMMAND
&&
equals
(
c_token
,
"!"
)) {
char
*
search_str
=
NULL
;
/* string from command line to search for */
const
char
*
line_to_do
=
NULL
;
/* command to execute at end if necessary */
int
c_token_copy
;
static
char
*
gpil_copy
=
NULL
;
c_token
++
;
m_capture
(
&
search_str
,
c_token
,
c_token
);
line_to_do
=
history_find
(
search_str
);
free
(
search_str
);
if
(
line_to_do
==
NULL
)
int_error
(
c_token
,
"not in history"
);
/* Must keep current input line in case there are some remaining lines
* to process after a semicolon. However, could int_error() some where
* during do_line() so a static copy is kept.
*/
free
(
gpil_copy
);
gpil_copy
=
gp_strdup
(
gp_input_line
);
c_token_copy
=
c_token
;
while
(
gp_input_line_len
<
strlen
(
line_to_do
)
+
1
)
extend_input_line
();
strcpy
(
gp_input_line
,
line_to_do
);
if
(
scanner
(
&
gp_input_line
,
&
gp_input_line_len
)) {
if
(
almost_equals
(
0
,
"hi$story"
)
&&
equals
(
1
,
"!"
))
int_error
(
c_token
-
1
,
"petitio principii"
);
/* Oops... infinite loop */
else
{
printf
(
" Executing:\n\t%s\n"
,
line_to_do
);
do_line
();
}
}
/* Restore previous state of line and parser, gpil_copy will be freed next time */
strcpy
(
gp_input_line
,
gpil_copy
);
num_tokens
=
scanner
(
&
gp_input_line
,
&
gp_input_line_len
);
c_token
=
c_token_copy
+
1
;
}
else
{
struct
value
a
;
int
n
=
0
;
/* print only <last> entries */
TBOOLEAN
append
=
FALSE;
/* rewrite output file or append it */
static
char
*
name
=
NULL
;
/* name of the output file; NULL for stdout */
TBOOLEAN
quiet
=
FALSE;
if
(!
END_OF_COMMAND
&&
almost_equals
(
c_token
,
"q$uiet"
)) {
/* option quiet to suppress history entry numbers */
quiet
=
TRUE;
c_token
++
;
}
/* show history entries */
if
(!
END_OF_COMMAND
&&
isanumber
(
c_token
)) {
n
=
(
int
)
real
(
const_express
(
&
a
));
}
free
(
name
);
if
((
name
=
try_to_get_string
())) {
if
(!
END_OF_COMMAND
&&
almost_equals
(
c_token
,
"ap$pend"
)) {
append
=
TRUE;
c_token
++
;
}
}
write_history_n
(
n
, (
quiet
?
""
:
name
), (
append
?
"a"
:
"w"
));
}
#else
c_token
++
;
int_warn
(
NO_CARET
,
"You have to compile gnuplot with builtin readline or GNU readline to enable history support."
);
#endif
/* defined(READLINE) || defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDITLINE) */
}
#define
REPLACE_ELSE
(
tok
) \
do { \
int idx = token[tok].start_index; \
token[tok].length = 1; \
gp_input_line[idx++] = ';';
/* e */
\
gp_input_line
[
idx
++
]
=
' '
;
/* l */
\
gp_input_line
[
idx
++
]
=
' '
;
/* s */
\
gp_input_line
[
idx
++
]
=
' '
;
/* e */
\
}
while
(
0
)
#if
0
#define
PRINT_TOKEN
(
tok
) \
do { \
int i; \
int end_index = token[tok].start_index + token[tok].length; \
for (i = token[tok].start_index; i < end_index && gp_input_line[i]; i++) { \
fputc(gp_input_line[i], stderr); \
} \
fputc('\n', stderr); \
fflush(stderr); \
} while (0)
#endif
/* process the 'if' command */
void
if_command
()
{
double
exprval
;
struct
value
t
;
if_depth
++
;
if
(!
equals
(
++
c_token
,
"("
))
/* no expression */
int_error
(
c_token
,
"expecting (expression)"
);
exprval
=
real
(
const_express
(
&
t
));
if
(
exprval
!=
0.0
) {
/* fake the condition of a ';' between commands */
int
eolpos
=
token
[
num_tokens
-
1
].
start_index
+
token
[
num_tokens
-
1
].
length
;
--
c_token
;
token
[
c_token
].
length
=
1
;
token
[
c_token
].
start_index
=
eolpos
+
2
;
gp_input_line
[
eolpos
+
2
]
=
';'
;
gp_input_line
[
eolpos
+
3
]
=
NUL
;
if_condition
=
TRUE;
}
else
{
while
(
c_token
<
num_tokens
) {
/* skip over until the next command */
while
(!
END_OF_COMMAND
) {
++
c_token
;
}
if
(
++
c_token
<
num_tokens
&&
(
equals
(
c_token
,
"else"
))) {
/* break if an "else" was found */
if_condition
=
FALSE;
--
c_token
;
/* go back to ';' */
return
;
}
}
/* no else found */
c_token
=
num_tokens
=
0
;
}
}
/* process the 'else' command */
void
else_command
()
{
if
(
if_depth
<=
0
) {
int_error
(
c_token
,
"else without if"
);
return
;
}
else
{
if_depth
--
;
}
if
(TRUE
==
if_condition
) {
/* First part of line was true so
* discard the rest of the line. */
c_token
=
num_tokens
=
0
;
}
else
{
REPLACE_ELSE
(
c_token
);
if_condition
=
TRUE;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL