File: input.cc

package info (click to toggle)
gri 2.4.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,540 kB
  • ctags: 1,966
  • sloc: cpp: 32,542; lisp: 3,243; perl: 806; makefile: 548; sh: 253
file content (81 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download
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
#include	<string>
#include	<math.h>
#include	<stdio.h>
#include	"gr.hh"
#include	"extern.hh"
#include	"private.hh"
extern char     _grTempString[];

/* `input \ps_filename [.xcm. .ycm. [.xmag. .ymag. [.rot_deg.]]]' */
bool
inputCmd()
{
    char *            filename;
    char *            longfilename;
    extern FILE    *_grPS;
    FILE           *fp;
    double          xcm = 0.0, ycm = 0.0, xmag = 1.0, ymag = 1.0, angle = 0.0;
    GET_STORAGE(longfilename, char, LineLength);
    filename = _word[1];	/* copy pointer */
    if (*_word[1] == '"')
	filename++;
    if (*(filename + strlen(filename) - 1) == '"')
	*(filename + strlen(filename) - 1) = '\0';
    filename = complete_filename(filename);
    switch (_nword) {
    case 7:
	getdnum(_word[6], &angle);
	getdnum(_word[5], &ymag);
	getdnum(_word[4], &xmag);
	getdnum(_word[3], &ycm);
	getdnum(_word[2], &xcm);
	break;
    case 6:
	getdnum(_word[5], &ymag);
	getdnum(_word[4], &xmag);
	getdnum(_word[3], &ycm);
	getdnum(_word[2], &xcm);
	break;
    case 4:
	getdnum(_word[3], &ycm);
	getdnum(_word[2], &xcm);
	break;
    default:
	demonstrate_command_usage();
	NUMBER_WORDS_ERROR;
	break;
    }
    /* Search directory only if not specified as local/fullpath */
    if (filename[0] != '/' && filename[0] != '.')
	longfilename = file_in_list(filename, false, false);
    else
	strcpy(longfilename, filename);
    if (NULL == (fp = fopen(longfilename, "r"))) {
	fatal_err("Cannot open `input' file named `\\",
		  longfilename,
		  "'",
		  "\\");
	free(filename);
	return false;
    }
    /*
     * Scan through the file, doing lines.
     */
    fprintf(_grPS, "q %% Beginning of `input' file named `%s'\n",
	    longfilename);
    fprintf(_grPS, "%f %f translate %f %f scale %f rotate\n",
	    xcm * PT_PER_CM, ycm * PT_PER_CM, xmag, ymag, angle);
    while (!feof(fp)) {
	/*
	 * See if hit EOF on a line with no text.
	 */
	if (NULL == fgets(_grTempString, LineLength, fp))
	    break;
	fprintf(_grPS, "%s", _grTempString);
    }
    fprintf(_grPS, "Q %% End of `input' file named `%s'\n",
	    longfilename);
    free(filename);
    fclose(fp);
    return true;
}