File: new.cc

package info (click to toggle)
gri 2.12.17-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,232 kB
  • ctags: 2,351
  • sloc: cpp: 35,661; lisp: 3,765; sh: 3,568; perl: 1,051; ansic: 1,046; makefile: 632
file content (124 lines) | stat: -rw-r--r-- 3,712 bytes parent folder | download | duplicates (3)
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
#include <string>
#include <math.h>
#include <stdio.h>
#include "gr.hh"
#include "extern.hh"
#include "defaults.hh"
extern char     _grTempString[];

bool            new_pageCmd();
bool            newCmd(void);	// for synonyms and vars

bool
new_pageCmd()
{
	extern void reset_top_of_plot(void); // in set.cc
	gr_showpage();
	gr_setfont(gr_currentfont(), true);
	_need_x_axis = true;
	_need_y_axis = true;
	reset_top_of_plot();
	return true;
}
// new postscript file "name"
bool
new_postscript_fileCmd()
{
	if (_nword < 4) {
		err("`new postscript file' needs a filename.");
		demonstrate_command_usage();
		return false;
	} else if (_nword > 4) {
		err("`new postscript file' takes just 1 argument, a filename");
		demonstrate_command_usage();
		return false;
	}
	//printf("DEBUG.  Should now start a new ps file named '%s'\n",_word[3]);
	gr_end("!");
	std::string unquoted(_word[3]);
	un_double_quote(unquoted);
	gr_setup_ps_filename(unquoted.c_str());
#if 0
	// BUG: don't know argc/argv from here!
	insert_creator_name_in_PS(argc, argv, psname);
#endif
	gr_begin(2);
	// Trick it into resetting to present font 
	gr_fontID present_font = gr_currentfont();
	gr_setfont(gr_font_Courier);
	gr_setfont(present_font);
	return true;
}

// new [.var.|\syn [.var.|\syn [...]]
bool
newCmd()
{
	if (_nword == 1) {
		err("Need name of thing (synonym or variable) to make new version of");
		demonstrate_command_usage();
		return false;
	}
	for (unsigned int i = 1; i < _nword; i++) {
                std::string w(_word[i]);
		un_double_quote(w);
		//printf("DEBUG %s:%d <%s>\n",__FILE__,__LINE__,w.c_str());
		std::string value;
		if (get_syn(w.c_str(), value, false)) {
			std::string coded_name;
			int coded_level = -1;
			//printf("DEBUG <%s>\n", value.c_str());
			if (is_coded_string(value.c_str(), coded_name, &coded_level)) {
				//printf("DEBUG %s:%d is <%s> <%s> level %d\n",__FILE__,__LINE__,value.c_str(),coded_name.c_str(),coded_level);
				if (coded_name[0] == '.') {
					int index = index_of_variable(coded_name.c_str(), coded_level);
					GriVariable newVariable(coded_name.c_str(), 0.0);
					variableStack.insert(variableStack.begin() + index + 1, newVariable);
					//printf("VAR index is %d\n", index);
				} else if (coded_name[0] == '\\'){
					int index = index_of_synonym(coded_name.c_str(), coded_level);
					//printf("SYN index is %d, now holds <%s>\n", index, synonymStack[index].get_value());
					GriSynonym newSynonym(coded_name.c_str(), "");
					synonymStack.insert(synonymStack.begin() + index + 1, newSynonym);
				} else {
					err("new cannot decode item `\\", _word[i], "'.", "\\");
					return false;
				}
				return true;
			}
		}

		// de_reference(w);

		if (is_syn(w)) {
			//printf("DEBUG 4-a SYN <%s>\n", w.c_str());
			if (w[1] == '@') {
				std::string clean("\\");
				clean.append(w.substr(2, w.size()));
				std::string named;
				get_syn(clean.c_str(), named, false);
				//printf("NEW IS AN ALIAS SYN %s:%d <%s>  [%s]\n",__FILE__,__LINE__,clean.c_str(),named.c_str());
				if (is_var(named.c_str())) {
					//printf("NEW VAR [%s]\n",named.c_str());
					create_variable(named.c_str(), 0.0);
				} else if (is_syn(named.c_str())) {
					//printf("NEW SYN [%s]\n",named.c_str());
					create_synonym(named.c_str(), "");
				} else {
					err("`new' cannot decode `\\", w.c_str(), "'", "\\");
					return false;
				}
			} else {
				create_synonym(w.c_str(), "");
			}
		} else if (is_var(w)) {
			//printf("DEBUG 4-b VAR <%s>\n", w.c_str());
			create_variable(w.c_str(), 0.0);
		} else {
			demonstrate_command_usage();
			err("`new' only works on synonyms and variables, not on an item named `\\", _word[i], "'", "\\");
			return false;
		}
	}
	return true;
}