File: insert.cc

package info (click to toggle)
gri 2.8.7-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,472 kB
  • ctags: 2,092
  • sloc: cpp: 33,255; lisp: 3,980; perl: 1,037; makefile: 668; sh: 301
file content (76 lines) | stat: -rw-r--r-- 1,830 bytes parent folder | download | duplicates (4)
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
#include	<string>
#include	<math.h>
#include	<stdio.h>
#include	"gr.hh"
#include	"extern.hh"
#include	"private.hh"
#include        "superus.hh"




bool
insertCmd()
{
	if (_nword != 2) {
		demonstrate_command_usage();
		NUMBER_WORDS_ERROR;
		return false;
	}
	std::string fname(_word[1]);
	if (!resolve_filename(fname, true, 'c')) {
		err("`source' cannot handle file named `\\", _word[1], "'", "\\");
		return false;
	}
	//printf("Sourcing '%s'\n", fname.c_str());
	FILE *fp = fopen(fname.c_str(), "r");
	if (NULL == fp) {
		extern char _grTempString[];
		sprintf(_grTempString, "`source' cannot open file `%s' (translated to `%s')", _word[1], fname.c_str());
		err(_grTempString);
		return false;
	}

#if 1
	CmdFile cf;			// as in file.cc
	cf.set(fname.c_str(), fp, false, 0, false);
	_cmdFILE.push_back(cf);
#else
	//printf("DEBUG %s:%d insert on file '%s'\n",__FILE__,__LINE__,fname.c_str());
	
	/*
	 * Scan through the file, doing lines.
	 */
	while (!feof(fp)) {
		/*
		 * See if hit EOF on a line with no text.
		 */
		if (NULL == fgets(_cmdLine, LineLength, fp))
			break;
		if (feof(fp)) {
			warning("Missing newline at end of inserted file `\\",
				fname.c_str(),
				"'",
				"\\");
			strcat(_cmdLine, "\n");
		}
		_cmdFILE.back().increment_line(); // BUG line numbers wrong BUG
		if (((unsigned) superuser()) & FLAG_AUT1) {
			void insert_source_indicator(char *cl); // in doline.cc
			insert_source_indicator(_cmdLine);
		}
		massage_command_line(_cmdLine);
		//printf("DEBUG %s:%d massaged line is '%s'\n",__FILE__,__LINE__,_cmdLine);
		// Kludge
		if (is_create_new_command(_cmdLine))
			insert_cmd_in_ps(_cmdLine/*, "insert.cc:66"*/);
		if (_nword > 0 && !strcmp(_word[0], "return") && !skipping_through_if())
			break;
		if (!perform_command_line(fp, false)) {
			return false;
		}
	}
#endif
	return true;
}