annotate src/ex_cmds2.c @ 200:3585d1a53fa5

updated for version 7.0059
author vimboss
date Fri, 11 Mar 2005 22:49:40 +0000
parents 84c21eb4fc40
children d292c40ca788
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * ex_cmds2.c: some more functions for command line commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #if defined(WIN32) && defined(FEAT_CSCOPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 # include <io.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #if defined(WIN32) && defined(FEAT_CSCOPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 # include <fcntl.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #include "version.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 static void cmd_source __ARGS((char_u *fname, exarg_T *eap));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
28 #ifdef FEAT_EVAL
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
29 /* Growarray to store info about already sourced scripts.
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
30 * For Unix also store the dev/ino, so that we don't have to stat() each
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
31 * script when going through the list. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
32 typedef struct scriptitem_S
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
33 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
34 char_u *sn_name;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
35 # ifdef UNIX
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
36 int sn_dev;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
37 ino_t sn_ino;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
38 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
39 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
40 int sn_prof_on; /* TRUE when script is/was profiled */
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
41 int sn_pr_force; /* forceit: profile functions in this script */
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
42 proftime_T sn_pr_child; /* time set when going into first child */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
43 int sn_pr_nest; /* nesting for sn_pr_child */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
44 /* profiling the script as a whole */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
45 int sn_pr_count; /* nr of times sourced */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
46 proftime_T sn_pr_total; /* time spend in script + children */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
47 proftime_T sn_pr_self; /* time spend in script itself */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
48 proftime_T sn_pr_start; /* time at script start */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
49 proftime_T sn_pr_children; /* time in children after script start */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
50 /* profiling the script per line */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
51 garray_T sn_prl_ga; /* things stored for every line */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
52 proftime_T sn_prl_start; /* start time for current line */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
53 proftime_T sn_prl_children; /* time spent in children for this line */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
54 proftime_T sn_prl_wait; /* wait start time for current line */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
55 int sn_prl_idx; /* index of line being timed; -1 if none */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
56 int sn_prl_execed; /* line being timed was executed */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
57 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
58 } scriptitem_T;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
59
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
60 static garray_T script_items = {0, 0, sizeof(scriptitem_T), 4, NULL};
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
61 #define SCRIPT_ITEM(id) (((scriptitem_T *)script_items.ga_data)[(id) - 1])
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
62
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
63 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
64 /* Struct used in sn_prl_ga for every line of a script. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
65 typedef struct sn_prl_S
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
66 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
67 int snp_count; /* nr of times line was executed */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
68 proftime_T sn_prl_total; /* time spend in a line + children */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
69 proftime_T sn_prl_self; /* time spend in a line itself */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
70 } sn_prl_T;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
71
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
72 # define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)])
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
73 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
74 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
75
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 static int debug_greedy = FALSE; /* batch mode debugging: don't save
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 and restore typeahead. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 * do_debug(): Debug mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 * Repeatedly get Ex commands, until told to continue normal execution.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 do_debug(cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 int save_msg_scroll = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 int save_did_emsg = did_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 int save_cmd_silent = cmd_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 int save_msg_silent = msg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 int save_emsg_silent = emsg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 int save_redir_off = redir_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 tasave_T typeaheadbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 # ifdef FEAT_EX_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 int save_ex_normal_busy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 char_u *cmdline = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 char *tail = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 static int last_cmd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 #define CMD_CONT 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 #define CMD_NEXT 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 #define CMD_STEP 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 #define CMD_FINISH 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 #define CMD_QUIT 5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 #define CMD_INTERRUPT 6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 #ifdef ALWAYS_USE_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 /* Can't do this when there is no terminal for input/output. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 if (!gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 /* Break as soon as possible. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 debug_break_level = 9999;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 /* Make sure we are in raw mode and start termcap mode. Might have side
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 * effects... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 settmode(TMODE_RAW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 starttermcap();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 ++RedrawingDisabled; /* don't redisplay the window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 ++no_wait_return; /* don't wait for return */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 did_emsg = FALSE; /* don't use error from debugged stuff */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 cmd_silent = FALSE; /* display commands */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 msg_silent = FALSE; /* display messages */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 emsg_silent = FALSE; /* display error messages */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 redir_off = TRUE; /* don't redirect debug commands */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 #ifdef FEAT_SNIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 want_sniff_request = 0; /* No K_SNIFF wanted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 if (!debug_did_msg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 MSG(_("Entering Debug mode. Type \"cont\" to continue."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 if (sourcing_name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 msg(sourcing_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 if (sourcing_lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 smsg((char_u *)_("line %ld: %s"), (long)sourcing_lnum, cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 msg_str((char_u *)_("cmd: %s"), cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 * Repeat getting a command and executing it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 msg_scroll = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 need_wait_return = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 #ifdef FEAT_SNIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 ProcessSniffRequests();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 /* Save the current typeahead buffer and replace it with an empty one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 * This makes sure we get input from the user here and don't interfere
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 * with the commands being executed. Reset "ex_normal_busy" to avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 * the side effects of using ":normal". Save the stuff buffer and make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 * it empty. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 # ifdef FEAT_EX_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 save_ex_normal_busy = ex_normal_busy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 ex_normal_busy = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 if (!debug_greedy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 save_typeahead(&typeaheadbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 cmdline = getcmdline_prompt('>', NULL, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 if (!debug_greedy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 restore_typeahead(&typeaheadbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 # ifdef FEAT_EX_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 ex_normal_busy = save_ex_normal_busy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 cmdline_row = msg_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 if (cmdline != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 /* If this is a debug command, set "last_cmd".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 * If not, reset "last_cmd".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 * For a blank line use previous command. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 p = skipwhite(cmdline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 if (*p != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 switch (*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 case 'c': last_cmd = CMD_CONT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 tail = "ont";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 case 'n': last_cmd = CMD_NEXT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 tail = "ext";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 case 's': last_cmd = CMD_STEP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 tail = "tep";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 case 'f': last_cmd = CMD_FINISH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 tail = "inish";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 case 'q': last_cmd = CMD_QUIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 tail = "uit";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 case 'i': last_cmd = CMD_INTERRUPT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 tail = "nterrupt";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 default: last_cmd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 if (last_cmd != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 /* Check that the tail matches. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 while (*p != NUL && *p == *tail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 ++tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 if (ASCII_ISALPHA(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 last_cmd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 if (last_cmd != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 /* Execute debug command: decided where to break next and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 * return. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 switch (last_cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 case CMD_CONT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 debug_break_level = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 case CMD_NEXT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 debug_break_level = ex_nesting_level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 case CMD_STEP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 debug_break_level = 9999;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 case CMD_FINISH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 debug_break_level = ex_nesting_level - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 case CMD_QUIT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 debug_break_level = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 case CMD_INTERRUPT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 got_int = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 debug_break_level = 9999;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 /* Do not repeat ">interrupt" cmd, continue stepping. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 last_cmd = CMD_STEP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 /* don't debug this command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 n = debug_break_level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 debug_break_level = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 (void)do_cmdline(cmdline, getexline, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 DOCMD_VERBOSE|DOCMD_EXCRESET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 debug_break_level = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 vim_free(cmdline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 lines_left = Rows - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 vim_free(cmdline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 --RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 redraw_all_later(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 need_wait_return = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 msg_scroll = save_msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 lines_left = Rows - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 did_emsg = save_did_emsg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 cmd_silent = save_cmd_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 msg_silent = save_msg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 emsg_silent = save_emsg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 redir_off = save_redir_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 /* Only print the message again when typing a command before coming back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 * here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 debug_did_msg = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 * ":debug".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 ex_debug(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 int debug_break_level_save = debug_break_level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 debug_break_level = 9999;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 do_cmdline_cmd(eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 debug_break_level = debug_break_level_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 static char_u *debug_breakpoint_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 static linenr_T debug_breakpoint_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 * When debugging or a breakpoint is set on a skipped command, no debug prompt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 * is shown by do_one_cmd(). This situation is indicated by debug_skipped, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 * debug_skipped_name is then set to the source name in the breakpoint case. If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 * a skipped command decides itself that a debug prompt should be displayed, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 * can do so by calling dbg_check_skipped().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 static int debug_skipped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 static char_u *debug_skipped_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * Go to debug mode when a breakpoint was encountered or "ex_nesting_level" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * at or below the break level. But only when the line is actually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 * executed. Return TRUE and set breakpoint_name for skipped commands that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 * decide to execute something themselves.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 * Called from do_one_cmd() before executing a command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 dbg_check_breakpoint(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 debug_skipped = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 if (debug_breakpoint_name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 /* replace K_SNR with "<SNR>" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 if (debug_breakpoint_name[0] == K_SPECIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 && debug_breakpoint_name[1] == KS_EXTRA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 && debug_breakpoint_name[2] == (int)KE_SNR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 p = (char_u *)"<SNR>";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 p = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 smsg((char_u *)_("Breakpoint in \"%s%s\" line %ld"), p,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 debug_breakpoint_name + (*p == NUL ? 0 : 3),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 (long)debug_breakpoint_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 debug_breakpoint_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 do_debug(eap->cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 debug_skipped = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 debug_skipped_name = debug_breakpoint_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 debug_breakpoint_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 else if (ex_nesting_level <= debug_break_level)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 if (!eap->skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 do_debug(eap->cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 debug_skipped = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 debug_skipped_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 * Go to debug mode if skipped by dbg_check_breakpoint() because eap->skip was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 * set. Return TRUE when the debug mode is entered this time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 dbg_check_skipped(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 int prev_got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 if (debug_skipped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 * Save the value of got_int and reset it. We don't want a previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 * interruption cause flushing the input buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 prev_got_int = got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 debug_breakpoint_name = debug_skipped_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 /* eap->skip is TRUE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 eap->skip = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 (void)dbg_check_breakpoint(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 eap->skip = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 got_int |= prev_got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 * The list of breakpoints: dbg_breakp.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 * This is a grow-array of structs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 struct debuggy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 int dbg_nr; /* breakpoint number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 int dbg_type; /* DBG_FUNC or DBG_FILE */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 char_u *dbg_name; /* function or file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 regprog_T *dbg_prog; /* regexp program */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 linenr_T dbg_lnum; /* line number in function or file */
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
403 int dbg_forceit; /* ! used */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 static garray_T dbg_breakp = {0, 0, sizeof(struct debuggy), 4, NULL};
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
407 #define BREAKP(idx) (((struct debuggy *)dbg_breakp.ga_data)[idx])
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
408 #define DEBUGGY(gap, idx) (((struct debuggy *)gap->ga_data)[idx])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 static int last_breakp = 0; /* nr of last defined breakpoint */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
411 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
412 /* Profiling uses file and func names similar to breakpoints. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
413 static garray_T prof_ga = {0, 0, sizeof(struct debuggy), 4, NULL};
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
414 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 #define DBG_FUNC 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 #define DBG_FILE 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
418 static int dbg_parsearg __ARGS((char_u *arg, garray_T *gap));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
419 static linenr_T debuggy_find __ARGS((int file,char_u *fname, linenr_T after, garray_T *gap, int *fp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 /*
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
422 * Parse the arguments of ":profile", ":breakadd" or ":breakdel" and put them
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
423 * in the entry just after the last one in dbg_breakp. Note that "dbg_name"
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
424 * is allocated.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 * Returns FAIL for failure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 static int
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
428 dbg_parsearg(arg, gap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 char_u *arg;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
430 garray_T *gap; /* either &dbg_breakp or &prof_ga */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 char_u *p = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 char_u *q;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 struct debuggy *bp;
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
435 int here = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
437 if (ga_grow(gap, 1) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 return FAIL;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
439 bp = &DEBUGGY(gap, gap->ga_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 /* Find "func" or "file". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 if (STRNCMP(p, "func", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 bp->dbg_type = DBG_FUNC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 else if (STRNCMP(p, "file", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 bp->dbg_type = DBG_FILE;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
446 else if (
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
447 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
448 gap != &prof_ga &&
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
449 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
450 STRNCMP(p, "here", 4) == 0)
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
451 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
452 if (curbuf->b_ffname == NULL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
453 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
454 EMSG(_(e_noname));
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
455 return FAIL;
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
456 }
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
457 bp->dbg_type = DBG_FILE;
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
458 here = TRUE;
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
459 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 EMSG2(_(e_invarg2), p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 p = skipwhite(p + 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 /* Find optional line number. */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
468 if (here)
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
469 bp->dbg_lnum = curwin->w_cursor.lnum;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
470 else if (
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
471 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
472 gap != &prof_ga &&
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
473 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
474 VIM_ISDIGIT(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 bp->dbg_lnum = getdigits(&p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 bp->dbg_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 /* Find the function or file name. Don't accept a function name with (). */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
483 if ((!here && *p == NUL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
484 || (here && *p != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 || (bp->dbg_type == DBG_FUNC && strstr((char *)p, "()") != NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 EMSG2(_(e_invarg2), arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 if (bp->dbg_type == DBG_FUNC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 bp->dbg_name = vim_strsave(p);
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
493 else if (here)
4e2284e71352 updated for version 7.0002
vimboss
parents: 8
diff changeset
494 bp->dbg_name = vim_strsave(curbuf->b_ffname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 /* Expand the file name in the same way as do_source(). This means
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 * doing it twice, so that $DIR/file gets expanded when $DIR is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 * "~/dir". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 #ifdef RISCOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 q = mch_munge_fname(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 q = expand_env_save(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 if (q == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 #ifdef RISCOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 p = mch_munge_fname(q);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 p = expand_env_save(q);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 vim_free(q);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 return FAIL;
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
515 if (*p != '*')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
516 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
517 bp->dbg_name = fix_fname(p);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
518 vim_free(p);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
519 }
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
520 else
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
521 bp->dbg_name = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 #ifdef MACOS_CLASSIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 if (bp->dbg_name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 slash_n_colon_adjust(bp->dbg_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 if (bp->dbg_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 * ":breakadd".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 ex_breakadd(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 struct debuggy *bp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 char_u *pat;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
542 garray_T *gap;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
543
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
544 gap = &dbg_breakp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
545 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
546 if (eap->cmdidx == CMD_profile)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
547 gap = &prof_ga;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
548 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
549
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
550 if (dbg_parsearg(eap->arg, gap) == OK)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
551 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
552 bp = &DEBUGGY(gap, gap->ga_len);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
553 bp->dbg_forceit = eap->forceit;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
554
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 if (pat != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 if (pat == NULL || bp->dbg_prog == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 vim_free(bp->dbg_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 if (bp->dbg_lnum == 0) /* default line number is 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 bp->dbg_lnum = 1;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
567 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
568 if (eap->cmdidx != CMD_profile)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
569 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
570 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
571 DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
572 ++debug_tick;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
573 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
574 ++gap->ga_len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 * ":debuggreedy".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 ex_debuggreedy(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if (eap->addr_count == 0 || eap->line2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 debug_greedy = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 debug_greedy = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 * ":breakdel".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 ex_breakdel(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 struct debuggy *bp, *bpi;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 int nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 int todel = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 linenr_T best_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 if (vim_isdigit(*eap->arg))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 /* ":breakdel {nr}" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 nr = atol((char *)eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 for (i = 0; i < dbg_breakp.ga_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 if (BREAKP(i).dbg_nr == nr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 todel = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 /* ":breakdel {func|file} [lnum] {name}" */
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
619 if (dbg_parsearg(eap->arg, &dbg_breakp) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 bp = &BREAKP(dbg_breakp.ga_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 for (i = 0; i < dbg_breakp.ga_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 bpi = &BREAKP(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 if (bp->dbg_type == bpi->dbg_type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 && STRCMP(bp->dbg_name, bpi->dbg_name) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 && (bp->dbg_lnum == bpi->dbg_lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 || (bp->dbg_lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 && (best_lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 || bpi->dbg_lnum < best_lnum))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 todel = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 best_lnum = bpi->dbg_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 vim_free(bp->dbg_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 if (todel < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 EMSG2(_("E161: Breakpoint not found: %s"), eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 vim_free(BREAKP(todel).dbg_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 vim_free(BREAKP(todel).dbg_prog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 --dbg_breakp.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 if (todel < dbg_breakp.ga_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 mch_memmove(&BREAKP(todel), &BREAKP(todel + 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 (dbg_breakp.ga_len - todel) * sizeof(struct debuggy));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 ++debug_tick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 * ":breaklist".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 ex_breaklist(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 struct debuggy *bp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 if (dbg_breakp.ga_len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 MSG(_("No breakpoints defined"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 for (i = 0; i < dbg_breakp.ga_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 bp = &BREAKP(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 smsg((char_u *)_("%3d %s %s line %ld"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 bp->dbg_nr,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 bp->dbg_type == DBG_FUNC ? "func" : "file",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 bp->dbg_name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 (long)bp->dbg_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 * Find a breakpoint for a function or sourced file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 * Returns line number at which to break; zero when no matching breakpoint.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 linenr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 dbg_find_breakpoint(file, fname, after)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 int file; /* TRUE for a file, FALSE for a function */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 char_u *fname; /* file or function name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 linenr_T after; /* after this line number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 {
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
688 return debuggy_find(file, fname, after, &dbg_breakp, NULL);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
689 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
690
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
691 #if defined(FEAT_PROFILE) || defined(PROTO)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
692 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
693 * Return TRUE if profiling is on for a function or sourced file.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
694 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
695 int
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
696 has_profiling(file, fname, fp)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
697 int file; /* TRUE for a file, FALSE for a function */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
698 char_u *fname; /* file or function name */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
699 int *fp; /* return: forceit */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
700 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
701 return (debuggy_find(file, fname, (linenr_T)0, &prof_ga, fp)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
702 != (linenr_T)0);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
703 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
704 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
705
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
706 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
707 * Common code for dbg_find_breakpoint() and has_profiling().
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
708 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
709 static linenr_T
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
710 debuggy_find(file, fname, after, gap, fp)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
711 int file; /* TRUE for a file, FALSE for a function */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
712 char_u *fname; /* file or function name */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
713 linenr_T after; /* after this line number */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
714 garray_T *gap; /* either &dbg_breakp or &prof_ga */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
715 int *fp; /* if not NULL: return forceit */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
716 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 struct debuggy *bp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 linenr_T lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 char_u *name = fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 int prev_got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
724 /* Return quickly when there are no breakpoints. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
725 if (gap->ga_len == 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
726 return (linenr_T)0;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
727
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 /* Replace K_SNR in function name with "<SNR>". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 if (!file && fname[0] == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 name = alloc((unsigned)STRLEN(fname) + 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 if (name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 name = fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 STRCPY(name, "<SNR>");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 STRCPY(name + 5, fname + 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
741 for (i = 0; i < gap->ga_len; ++i)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
742 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
743 /* Skip entries that are not useful or are for a line that is beyond
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
744 * an already found breakpoint. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
745 bp = &DEBUGGY(gap, i);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
746 if (((bp->dbg_type == DBG_FILE) == file && (
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
747 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
748 gap == &prof_ga ||
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
749 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
750 (bp->dbg_lnum > after && (lnum == 0 || bp->dbg_lnum < lnum)))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 regmatch.regprog = bp->dbg_prog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 regmatch.rm_ic = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 /*
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
755 * Save the value of got_int and reset it. We don't want a
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
756 * previous interruption cancel matching, only hitting CTRL-C
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
757 * while matching should abort it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 prev_got_int = got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 if (vim_regexec(&regmatch, name, (colnr_T)0))
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
762 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 lnum = bp->dbg_lnum;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
764 if (fp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
765 *fp = bp->dbg_forceit;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
766 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 got_int |= prev_got_int;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 if (name != fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 return lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 * Called when a breakpoint was encountered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 dbg_breakpoint(name, lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 /* We need to check if this line is actually executed in do_one_cmd() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 debug_breakpoint_name = name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 debug_breakpoint_lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 }
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
788
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
789
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
790 # if defined(FEAT_PROFILE) || defined(PROTO)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
791 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
792 * Functions for profiling.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
793 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
794 static void script_do_profile __ARGS((scriptitem_T *si));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
795 static void script_dump_profile __ARGS((FILE *fd));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
796 static proftime_T prof_wait_time;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
797
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
798 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
799 * Set the time in "tm" to zero.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
800 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
801 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
802 profile_zero(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
803 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
804 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
805 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
806 tm->QuadPart = 0;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
807 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
808 tm->tv_usec = 0;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
809 tm->tv_sec = 0;
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
810 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
811 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
812
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
813 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
814 * Store the current time in "tm".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
815 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
816 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
817 profile_start(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
818 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
819 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
820 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
821 QueryPerformanceCounter(tm);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
822 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
823 gettimeofday(tm, NULL);
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
824 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
825 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
826
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
827 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
828 * Compute the elapsed time from "tm" till now and store in "tm".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
829 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
830 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
831 profile_end(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
832 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
833 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
834 proftime_T now;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
835
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
836 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
837 QueryPerformanceCounter(&now);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
838 tm->QuadPart = now.QuadPart - tm->QuadPart;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
839 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
840 gettimeofday(&now, NULL);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
841 tm->tv_usec = now.tv_usec - tm->tv_usec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
842 tm->tv_sec = now.tv_sec - tm->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
843 if (tm->tv_usec < 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
844 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
845 tm->tv_usec += 1000000;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
846 --tm->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
847 }
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
848 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
849 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
850
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
851 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
852 * Subtract the time "tm2" from "tm".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
853 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
854 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
855 profile_sub(tm, tm2)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
856 proftime_T *tm, *tm2;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
857 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
858 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
859 tm->QuadPart -= tm2->QuadPart;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
860 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
861 tm->tv_usec -= tm2->tv_usec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
862 tm->tv_sec -= tm2->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
863 if (tm->tv_usec < 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
864 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
865 tm->tv_usec += 1000000;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
866 --tm->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
867 }
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
868 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
869 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
870
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
871 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
872 * Add the time "tm2" to "tm".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
873 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
874 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
875 profile_add(tm, tm2)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
876 proftime_T *tm, *tm2;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
877 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
878 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
879 tm->QuadPart += tm2->QuadPart;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
880 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
881 tm->tv_usec += tm2->tv_usec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
882 tm->tv_sec += tm2->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
883 if (tm->tv_usec >= 1000000)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
884 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
885 tm->tv_usec -= 1000000;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
886 ++tm->tv_sec;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
887 }
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
888 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
889 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
890
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
891 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
892 * Get the current waittime.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
893 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
894 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
895 profile_get_wait(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
896 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
897 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
898 *tm = prof_wait_time;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
899 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
900
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
901 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
902 * Subtract the passed waittime since "tm" from "tma".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
903 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
904 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
905 profile_sub_wait(tm, tma)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
906 proftime_T *tm, *tma;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
907 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
908 proftime_T tm3 = prof_wait_time;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
909
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
910 profile_sub(&tm3, tm);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
911 profile_sub(tma, &tm3);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
912 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
913
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
914 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
915 * Return TRUE if "tm1" and "tm2" are equal.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
916 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
917 int
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
918 profile_equal(tm1, tm2)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
919 proftime_T *tm1, *tm2;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
920 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
921 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
922 return (tm1->QuadPart == tm2->QuadPart);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
923 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
924 return (tm1->tv_usec == tm2->tv_usec && tm1->tv_sec == tm2->tv_sec);
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
925 # endif
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
926 }
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
927
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
928 /*
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
929 * Return <0, 0 or >0 if "tm1" < "tm2", "tm1" == "tm2" or "tm1" > "tm2"
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
930 */
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
931 int
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
932 profile_cmp(tm1, tm2)
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
933 proftime_T *tm1, *tm2;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
934 {
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
935 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
936 return (int)(tm2->QuadPart - tm1->QuadPart);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
937 # else
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
938 if (tm1->tv_sec == tm2->tv_sec)
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
939 return tm2->tv_usec - tm1->tv_usec;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
940 return tm2->tv_sec - tm1->tv_sec;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
941 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
942 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
943
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
944 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
945 * Return a string that represents a time.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
946 * Uses a static buffer!
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
947 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
948 char *
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
949 profile_msg(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
950 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
951 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
952 static char buf[50];
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
953
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
954 # ifdef WIN3264
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
955 LARGE_INTEGER fr;
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
956
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
957 QueryPerformanceFrequency(&fr);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
958 sprintf(buf, "%10.6lf", (double)tm->QuadPart / (double)fr.QuadPart);
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
959 # else
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
960 sprintf(buf, "%3ld.%06ld", (long)tm->tv_sec, (long)tm->tv_usec);
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
961 #endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
962 return buf;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
963 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
964
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
965 static char_u *profile_fname = NULL;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
966
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
967 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
968 * ":profile cmd args"
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
969 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
970 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
971 ex_profile(eap)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
972 exarg_T *eap;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
973 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
974 char_u *e;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
975 int len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
976
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
977 e = skiptowhite(eap->arg);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
978 len = e - eap->arg;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
979 e = skipwhite(e);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
980
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
981 if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
982 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
983 vim_free(profile_fname);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
984 profile_fname = vim_strsave(e);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
985 do_profiling = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
986 profile_zero(&prof_wait_time);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
987 set_vim_var_nr(VV_PROFILING, 1L);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
988 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
989 else if (!do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
990 EMSG(_("E750: First use :profile start <fname>"));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
991 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
992 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
993 /* The rest is similar to ":breakadd". */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
994 ex_breakadd(eap);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
995 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
996 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
997
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
998 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
999 * Dump the profiling info.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1000 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1001 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1002 profile_dump()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1003 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1004 FILE *fd;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1005
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1006 if (profile_fname != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1007 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1008 fd = fopen((char *)profile_fname, "w");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1009 if (fd == NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1010 EMSG2(_(e_notopen), profile_fname);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1011 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1012 {
177
84c21eb4fc40 updated for version 7.0054
vimboss
parents: 170
diff changeset
1013 script_dump_profile(fd);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1014 func_dump_profile(fd);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1015 fclose(fd);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1016 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1017 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1018 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1019
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1020 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1021 * Start profiling script "fp".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1022 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1023 static void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1024 script_do_profile(si)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1025 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1026 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1027 si->sn_pr_count = 0;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1028 profile_zero(&si->sn_pr_total);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1029 profile_zero(&si->sn_pr_self);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1030
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1031 ga_init2(&si->sn_prl_ga, sizeof(sn_prl_T), 100);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1032 si->sn_prl_idx = -1;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1033 si->sn_prof_on = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1034 si->sn_pr_nest = 0;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1035 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1036
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1037 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1038 * save time when starting to invoke another script or function.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1039 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1040 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1041 script_prof_save(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1042 proftime_T *tm; /* place to store wait time */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1043 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1044 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1045
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1046 if (current_SID > 0 && current_SID <= script_items.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1047 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1048 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1049 if (si->sn_prof_on && si->sn_pr_nest++ == 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1050 profile_start(&si->sn_pr_child);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1051 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1052 profile_get_wait(tm);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1053 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1054
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1055 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1056 * Count time spent in children after invoking another script or function.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1057 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1058 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1059 script_prof_restore(tm)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1060 proftime_T *tm;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1061 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1062 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1063
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1064 if (current_SID > 0 && current_SID <= script_items.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1065 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1066 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1067 if (si->sn_prof_on && --si->sn_pr_nest == 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1068 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1069 profile_end(&si->sn_pr_child);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1070 profile_sub_wait(tm, &si->sn_pr_child); /* don't count wait time */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1071 profile_add(&si->sn_pr_children, &si->sn_pr_child);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1072 profile_add(&si->sn_prl_children, &si->sn_pr_child);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1073 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1074 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1075 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1076
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1077 static proftime_T inchar_time;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1078
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1079 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1080 * Called when starting to wait for the user to type a character.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1081 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1082 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1083 prof_inchar_enter()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1084 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1085 profile_start(&inchar_time);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1086 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1087
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1088 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1089 * Called when finished waiting for the user to type a character.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1090 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1091 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1092 prof_inchar_exit()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1093 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1094 profile_end(&inchar_time);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1095 profile_add(&prof_wait_time, &inchar_time);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1096 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1097
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1098 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1099 * Dump the profiling results for all scripts in file "fd".
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1100 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1101 static void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1102 script_dump_profile(fd)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1103 FILE *fd;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1104 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1105 int id;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1106 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1107 int i;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1108 FILE *sfd;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1109 sn_prl_T *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1110
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1111 for (id = 1; id <= script_items.ga_len; ++id)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1112 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1113 si = &SCRIPT_ITEM(id);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1114 if (si->sn_prof_on)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1115 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1116 fprintf(fd, "SCRIPT %s\n", si->sn_name);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1117 if (si->sn_pr_count == 1)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1118 fprintf(fd, "Sourced 1 time\n");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1119 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1120 fprintf(fd, "Sourced %d times\n", si->sn_pr_count);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1121 fprintf(fd, "Total time: %s\n", profile_msg(&si->sn_pr_total));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1122 fprintf(fd, " Self time: %s\n", profile_msg(&si->sn_pr_self));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1123 fprintf(fd, "\n");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1124 fprintf(fd, "count total (s) self (s)\n");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1125
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1126 sfd = fopen((char *)si->sn_name, "r");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1127 if (sfd == NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1128 fprintf(fd, "Cannot open file!\n");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1129 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1130 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1131 for (i = 0; i < si->sn_prl_ga.ga_len; ++i)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1132 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1133 if (vim_fgets(IObuff, IOSIZE, sfd))
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1134 break;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1135 pp = &PRL_ITEM(si, i);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1136 if (pp->snp_count > 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1137 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1138 fprintf(fd, "%5d ", pp->snp_count);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1139 if (profile_equal(&pp->sn_prl_total, &pp->sn_prl_self))
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1140 fprintf(fd, " ");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1141 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1142 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_total));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1143 fprintf(fd, "%s ", profile_msg(&pp->sn_prl_self));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1144 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1145 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1146 fprintf(fd, " ");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1147 fprintf(fd, "%s", IObuff);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1148 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1149 fclose(sfd);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1150 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1151 fprintf(fd, "\n");
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1152 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1153 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1154 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1155
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1156 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1157 * Return TRUE when a function defined in the current script should be
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1158 * profiled.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1159 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1160 int
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1161 prof_def_func()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1162 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1163 scriptitem_T *si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1164
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1165 return si->sn_pr_force;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1166 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1167
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
1168 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 * If 'autowrite' option set, try to write the file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 * Careful: autocommands may make "buf" invalid!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 autowrite(buf, forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 if (!(p_aw || p_awa) || !p_write
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 /* never autowrite a "nofile" or "nowrite" buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 || bt_dontwrite(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 return buf_write_all(buf, forceit);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 * flush all buffers, except the ones that are readonly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 autowrite_all()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 if (!(p_aw || p_awa) || !p_write)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 for (buf = firstbuf; buf; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 if (bufIsChanged(buf) && !buf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 (void)buf_write_all(buf, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 /* an autocommand may have deleted the buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 if (!buf_valid(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 buf = firstbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 * return TRUE if buffer was changed and cannot be abandoned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 check_changed(buf, checkaw, mult_win, forceit, allbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 int checkaw; /* do autowrite if buffer was changed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 int mult_win; /* check also when several wins for the buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 int allbuf; /* may write all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 if ( !forceit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 && bufIsChanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 && (mult_win || buf->b_nwindows <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 && (!checkaw || autowrite(buf, forceit) == FAIL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 if ((p_confirm || cmdmod.confirm) && p_write)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 buf_T *buf2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 if (allbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 if (bufIsChanged(buf2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 && (buf2->b_ffname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 # ifdef FEAT_BROWSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 || cmdmod.browse
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 # ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 if (!buf_valid(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 /* Autocommand deleted buffer, oops! It's not changed now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 dialog_changed(buf, count > 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 # ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 if (!buf_valid(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 /* Autocommand deleted buffer, oops! It's not changed now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 return bufIsChanged(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 EMSG(_(e_nowrtmsg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 #if defined(FEAT_BROWSE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 * When wanting to write a file without a file name, ask the user for a name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 browse_save_fname(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 if (buf->b_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 22
diff changeset
1280 fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"),
ac33b7c03fac updated for version 7.0018
vimboss
parents: 22
diff changeset
1281 NULL, NULL, NULL, NULL, buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 if (fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (setfname(buf, fname, NULL, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 buf->b_flags |= BF_NOTEDITED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 vim_free(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 * Ask the user what to do when abondoning a changed buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 * Must check 'write' option first!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 dialog_changed(buf, checkall)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 int checkall; /* may abandon all changed buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 char_u buff[IOSIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 int ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 buf_T *buf2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 dialog_msg(buff, _("Save changes to \"%.*s\"?"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 (buf->b_fname != NULL) ?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 buf->b_fname : (char_u *)_("Untitled"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 if (checkall)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 ret = vim_dialog_yesnoallcancel(VIM_QUESTION, NULL, buff, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 if (ret == VIM_YES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 #ifdef FEAT_BROWSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 /* May get file name, when there is none */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 browse_save_fname(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 if (buf->b_fname != NULL) /* didn't hit Cancel */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 (void)buf_write_all(buf, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 else if (ret == VIM_NO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 unchanged(buf, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 else if (ret == VIM_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 * Write all modified files that can be written.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 * Skip readonly buffers, these need to be confirmed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 * individually.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 if (bufIsChanged(buf2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 && (buf2->b_ffname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 #ifdef FEAT_BROWSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 || cmdmod.browse
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 && !buf2->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 #ifdef FEAT_BROWSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 /* May get file name, when there is none */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 browse_save_fname(buf2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 if (buf2->b_fname != NULL) /* didn't hit Cancel */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 (void)buf_write_all(buf2, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 /* an autocommand may have deleted the buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 if (!buf_valid(buf2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 buf2 = firstbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 else if (ret == VIM_DISCARDALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 * mark all buffers as unchanged
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 unchanged(buf2, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 * Return TRUE if the buffer "buf" can be abandoned, either by making it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 * hidden, autowriting it or unloading it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 can_abandon(buf, forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 return ( P_HID(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 || !bufIsChanged(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 || buf->b_nwindows > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 || autowrite(buf, forceit) == OK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 || forceit);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 * Return TRUE if any buffer was changed and cannot be abandoned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 * That changed buffer becomes the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 check_changed_any(hidden)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 int hidden; /* Only check hidden buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 int save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 /* check curbuf first: if it was changed we can't abandon it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 if (!hidden && curbufIsChanged())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 if (buf == NULL) /* No buffers changed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 if (check_changed(buf, p_awa, TRUE, FALSE, TRUE) && buf_valid(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 break; /* didn't save - still changes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 exiting = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 * When ":confirm" used, don't give an error message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 if (!(p_confirm || cmdmod.confirm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 /* There must be a wait_return for this message, do_buffer()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 * may cause a redraw. But wait_return() is a no-op when vgetc()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 * is busy (Quit used from window menu), then make sure we don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 * cause a scroll up. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 if (vgetc_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 msg_row = cmdline_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 msg_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 msg_didout = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 if (EMSG2(_("E162: No write since last change for buffer \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 buf_spname(buf) != NULL ? (char_u *)buf_spname(buf) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 buf->b_fname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 save = no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 no_wait_return = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 wait_return(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 no_wait_return = save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 /* Try to find a window that contains the buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 if (buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 if (wp->w_buffer == buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 win_goto(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 # ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 /* Paranoia: did autocms wipe out the buffer with changes? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 if (!buf_valid(buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 /* Open the changed buffer in the current window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 if (buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 set_curbuf(buf, DOBUF_GOTO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 * return FAIL if there is no file name, OK if there is one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 * give error message for FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 check_fname()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 if (curbuf->b_ffname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 EMSG(_(e_noname));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 * flush the contents of a buffer, unless it has no file name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 buf_write_all(buf, forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 buf_T *old_curbuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 retval = (buf_write(buf, buf->b_ffname, buf->b_fname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 (linenr_T)1, buf->b_ml.ml_line_count, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 FALSE, forceit, TRUE, FALSE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 if (curbuf != old_curbuf)
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
1503 {
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
1504 msg_source(hl_attr(HLF_W));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 MSG(_("Warning: Entered other buffer unexpectedly (check autocommands)"));
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
1506 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 * Code to handle the argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1515 static char_u *do_one_arg __ARGS((char_u *str));
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1516 static int do_arglist __ARGS((char_u *str, int what, int after));
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1517 static void alist_check_arg_idx __ARGS((void));
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1518 static int editing_arg_idx __ARGS((win_T *win));
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1519 #ifdef FEAT_LISTCMDS
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1520 static int alist_add_list __ARGS((int count, char_u **files, int after));
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1521 #endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1522 #define AL_SET 1
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1523 #define AL_ADD 2
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1524 #define AL_DEL 3
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1525
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1527 * Isolate one argument, taking backticks.
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1528 * Changes the argument in-place, puts a NUL after it. Backticks remain.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 * Return a pointer to the start of the next argument.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1531 static char_u *
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 do_one_arg(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 int inbacktick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 inbacktick = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 for (p = str; *str; ++str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1541 /* When the backslash is used for escaping the special meaning of a
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1542 * character we need to keep it until wildcard expansion. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 if (rem_backslash(str))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 *p++ = *str++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 *p++ = *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1550 /* An item ends at a space not in backticks */
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1551 if (!inbacktick && vim_isspace(*str))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 break;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1553 if (*str == '`')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 inbacktick ^= TRUE;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
1555 *p++ = *str;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 str = skipwhite(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 return str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1564 /*
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1565 * Separate the arguments in "str" and return a list of pointers in the
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1566 * growarray "gap".
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1567 */
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1568 int
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1569 get_arglist(gap, str)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1570 garray_T *gap;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1571 char_u *str;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1572 {
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1573 ga_init2(gap, (int)sizeof(char_u *), 20);
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1574 while (*str != NUL)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1575 {
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1576 if (ga_grow(gap, 1) == FAIL)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1577 {
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1578 ga_clear(gap);
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1579 return FAIL;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1580 }
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1581 ((char_u **)gap->ga_data)[gap->ga_len++] = str;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1582
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1583 /* Isolate one argument, change it in-place, put a NUL after it. */
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1584 str = do_one_arg(str);
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1585 }
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1586 return OK;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1587 }
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1588
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 * Redefine the argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 set_arglist(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 do_arglist(str, AL_SET, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 * "what" == AL_SET: Redefine the argument list to 'str'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 * "what" == AL_ADD: add files in 'str' to the argument list after "after".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 * "what" == AL_DEL: remove files in 'str' from the argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 * Return FAIL for failure, OK otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 do_arglist(str, what, after)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 int what;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 int after; /* 0 means before first one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 garray_T new_ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 int exp_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 char_u **exp_files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 #ifdef FEAT_LISTCMDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 int match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 * Collect all file name arguments in "new_ga".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 */
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1627 if (get_arglist(&new_ga, str) == FAIL)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1628 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 #ifdef FEAT_LISTCMDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 if (what == AL_DEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 int didone;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 * Delete the items: use each item as a regexp and find a match in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 * argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 #ifdef CASE_INSENSITIVE_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 regmatch.rm_ic = TRUE; /* Always ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 regmatch.rm_ic = FALSE; /* Never ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 for (i = 0; i < new_ga.ga_len && !got_int; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 p = ((char_u **)new_ga.ga_data)[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 p = file_pat_to_reg_pat(p, NULL, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 if (regmatch.regprog == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 didone = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 for (match = 0; match < ARGCOUNT; ++match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 (colnr_T)0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 didone = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 vim_free(ARGLIST[match].ae_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 mch_memmove(ARGLIST + match, ARGLIST + match + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 (ARGCOUNT - match - 1) * sizeof(aentry_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 --ALIST(curwin)->al_ga.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 if (curwin->w_arg_idx > match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 --curwin->w_arg_idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 --match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 if (!didone)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 ga_clear(&new_ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 ga_clear(&new_ga);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 if (i == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 if (exp_count == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 EMSG(_(e_nomatch));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 #ifdef FEAT_LISTCMDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 if (what == AL_ADD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 (void)alist_add_list(exp_count, exp_files, after);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 vim_free(exp_files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 else /* what == AL_SET */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 #endif
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
1702 alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 alist_check_arg_idx();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 * Check the validity of the arg_idx for each other window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 alist_check_arg_idx()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 for (win = firstwin; win != NULL; win = win->w_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 if (win->w_alist == curwin->w_alist)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 check_arg_idx(win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 check_arg_idx(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 /*
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1728 * Return TRUE if window "win" is editing then file at the current argument
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1729 * index.
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1730 */
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1731 static int
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1732 editing_arg_idx(win)
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1733 win_T *win;
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1734 {
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1735 return !(win->w_arg_idx >= WARGCOUNT(win)
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1736 || (win->w_buffer->b_fnum
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1737 != WARGLIST(win)[win->w_arg_idx].ae_fnum
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1738 && (win->w_buffer->b_ffname == NULL
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1739 || !(fullpathcmp(
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1740 alist_name(&WARGLIST(win)[win->w_arg_idx]),
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1741 win->w_buffer->b_ffname, TRUE) & FPC_SAME))));
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1742 }
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1743
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1744 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 * Check if window "win" is editing the w_arg_idx file in its argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 check_arg_idx(win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 {
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
1751 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 /* We are not editing the current entry in the argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 * Set "arg_had_last" if we are editing the last one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 win->w_arg_idx_invalid = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 if (win->w_arg_idx != WARGCOUNT(win) - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 && arg_had_last == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 && ALIST(win) == &global_alist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 && GARGCOUNT > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 && win->w_arg_idx < GARGCOUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 || (win->w_buffer->b_ffname != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 win->w_buffer->b_ffname, TRUE) & FPC_SAME))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 arg_had_last = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 /* We are editing the current entry in the argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 * Set "arg_had_last" if it's also the last one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 win->w_arg_idx_invalid = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 if (win->w_arg_idx == WARGCOUNT(win) - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 && win->w_alist == &global_alist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 arg_had_last = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 * ":args", ":argslocal" and ":argsglobal".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 ex_args(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 if (eap->cmdidx != CMD_args)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 alist_unlink(ALIST(curwin));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 if (eap->cmdidx == CMD_argglobal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 ALIST(curwin) = &global_alist;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 else /* eap->cmdidx == CMD_arglocal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 alist_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 ex_ni(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 if (!ends_excmd(*eap->arg))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 * ":args file ..": define new argument list, handle like ":next"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 * Also for ":argslocal file .." and ":argsglobal file ..".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 ex_next(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 if (eap->cmdidx == CMD_args)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 * ":args": list arguments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 if (ARGCOUNT > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 /* Overwrite the command, for a short list there is no scrolling
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 * required and no wait_return(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 gotocmdline(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 for (i = 0; i < ARGCOUNT; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 if (i == curwin->w_arg_idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 msg_putchar('[');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 msg_outtrans(alist_name(&ARGLIST[i]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 if (i == curwin->w_arg_idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 msg_putchar(']');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 msg_putchar(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 #if defined(FEAT_WINDOWS) && defined(FEAT_LISTCMDS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 else if (eap->cmdidx == CMD_arglocal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 garray_T *gap = &curwin->w_alist->al_ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 * ":argslocal": make a local copy of the global argument list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 if (ga_grow(gap, GARGCOUNT) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 for (i = 0; i < GARGCOUNT; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 if (GARGLIST[i].ae_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 vim_strsave(GARGLIST[i].ae_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 GARGLIST[i].ae_fnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 ++gap->ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 * ":previous", ":sprevious", ":Next" and ":sNext".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 ex_previous(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 /* If past the last one already, go to the last one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 do_argfile(eap, ARGCOUNT - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 do_argfile(eap, curwin->w_arg_idx - (int)eap->line2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * ":rewind", ":first", ":sfirst" and ":srewind".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 ex_rewind(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 do_argfile(eap, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 * ":last" and ":slast".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 ex_last(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 do_argfile(eap, ARGCOUNT - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 * ":argument" and ":sargument".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 ex_argument(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 if (eap->addr_count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 i = eap->line2 - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 i = curwin->w_arg_idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 do_argfile(eap, i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 * Edit file "argn" of the argument lists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 do_argfile(eap, argn)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 int argn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 int other;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 if (argn < 0 || argn >= ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 if (ARGCOUNT <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 EMSG(_("E163: There is only one file to edit"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 else if (argn < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 EMSG(_("E164: Cannot go before first file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 EMSG(_("E165: Cannot go beyond last file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 setpcmark();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 need_mouse_correct = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 if (*eap->cmd == 's') /* split window first */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 if (win_split(0, 0) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 # ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 curwin->w_p_scb = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 * if 'hidden' set, only check for changed file when re-editing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 * the same buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 other = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 if (P_HID(curbuf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 p = fix_fname(alist_name(&ARGLIST[argn]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 other = otherfile(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 if ((!P_HID(curbuf) || !other)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 && check_changed(curbuf, TRUE, !other, eap->forceit, FALSE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 curwin->w_arg_idx = argn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 if (argn == ARGCOUNT - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 && curwin->w_alist == &global_alist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 arg_had_last = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 /* Edit the file; always use the last known line number. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 (void)do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 eap, ECMD_LAST,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 (eap->forceit ? ECMD_FORCEIT : 0));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 /* like Vi: set the mark where the cursor is in the file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 if (eap->cmdidx != CMD_argdo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 setmark('\'');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 * ":next", and commands that behave like it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 ex_next(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 * check for changed buffer now, if this fails the argument list is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 * redefined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 if ( P_HID(curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 || eap->cmdidx == CMD_snext
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 || !check_changed(curbuf, TRUE, FALSE, eap->forceit, FALSE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 if (*eap->arg != NUL) /* redefine file list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 if (do_arglist(eap->arg, AL_SET, 0) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 i = curwin->w_arg_idx + (int)eap->line2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 do_argfile(eap, i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 #ifdef FEAT_LISTCMDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 * ":argedit"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 ex_argedit(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 int fnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 /* Add the argument to the buffer list and get the buffer number. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 fnum = buflist_add(eap->arg, BLN_LISTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 /* Check if this argument is already in the argument list. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 for (i = 0; i < ARGCOUNT; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 if (ARGLIST[i].ae_fnum == fnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 if (i == ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 /* Can't find it, add it to the argument list. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 s = vim_strsave(eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 if (s == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 i = alist_add_list(1, &s,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 if (i < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 curwin->w_arg_idx = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 alist_check_arg_idx();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 /* Edit the argument. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 do_argfile(eap, i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 * ":argadd"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 ex_argadd(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 do_arglist(eap->arg, AL_ADD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 maketitle();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 * ":argdelete"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 ex_argdelete(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 if (eap->addr_count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 /* ":1,4argdel": Delete all arguments in the range. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 if (eap->line2 > ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 eap->line2 = ARGCOUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 n = eap->line2 - eap->line1 + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 if (*eap->arg != NUL || n <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 EMSG(_(e_invarg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 for (i = eap->line1; i <= eap->line2; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 vim_free(ARGLIST[i - 1].ae_fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 ALIST(curwin)->al_ga.ga_len -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 if (curwin->w_arg_idx >= eap->line2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 curwin->w_arg_idx -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 else if (curwin->w_arg_idx > eap->line1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 curwin->w_arg_idx = eap->line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 else if (*eap->arg == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 EMSG(_(e_argreq));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 do_arglist(eap->arg, AL_DEL, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 maketitle();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 * ":argdo", ":windo", ":bufdo"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 ex_listdo(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 int next_fnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 char_u *save_ei = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 #endif
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2122 char_u *p_shm_save;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 #ifndef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 if (eap->cmdidx == CMD_windo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 ex_ni(eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 if (eap->cmdidx != CMD_windo)
123
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 45
diff changeset
2134 /* Don't do syntax HL autocommands. Skipping the syntax file is a
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 45
diff changeset
2135 * great speed improvement. */
f67f8a8d81ba updated for version 7.0043
vimboss
parents: 45
diff changeset
2136 save_ei = au_event_disable(",Syntax");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 if (eap->cmdidx == CMD_windo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 || P_HID(curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 || !check_changed(curbuf, TRUE, FALSE, eap->forceit, FALSE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 /* start at the first argument/window/buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 win = firstwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 /* set pcmark now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 if (eap->cmdidx == CMD_bufdo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 goto_buffer(eap, DOBUF_FIRST, FORWARD, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 setpcmark();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 listcmd_busy = TRUE; /* avoids setting pcmark below */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 while (!got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 if (eap->cmdidx == CMD_argdo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 /* go to argument "i" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 if (i == ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 /* Don't call do_argfile() when already there, it will try
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 * reloading the file. */
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 20
diff changeset
2164 if (curwin->w_arg_idx != i || !editing_arg_idx(curwin))
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2165 {
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2166 /* Clear 'shm' to avoid that the file message overwrites
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2167 * any output from the command. */
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2168 p_shm_save = vim_strsave(p_shm);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2169 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 do_argfile(eap, i);
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2171 set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2172 vim_free(p_shm_save);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2173 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 if (curwin->w_arg_idx != i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 else if (eap->cmdidx == CMD_windo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 /* go to window "win" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 if (!win_valid(win))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 win_goto(win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 win = win->w_next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 else if (eap->cmdidx == CMD_bufdo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 /* Remember the number of the next listed buffer, in case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 * ":bwipe" is used or autocommands do something strange. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 next_fnum = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 if (buf->b_p_bl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 next_fnum = buf->b_fnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 /* execute the command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 do_cmdline(eap->arg, eap->getline, eap->cookie,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 DOCMD_VERBOSE + DOCMD_NOWAIT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 if (eap->cmdidx == CMD_bufdo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 /* Done? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 if (next_fnum < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 /* Check if the buffer still exists. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 if (buf->b_fnum == next_fnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 break;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2216
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2217 /* Go to the next buffer. Clear 'shm' to avoid that the file
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2218 * message overwrites any output from the command. */
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2219 p_shm_save = vim_strsave(p_shm);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2220 set_option_value((char_u *)"shm", 0L, (char_u *)"", 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2222 set_option_value((char_u *)"shm", 0L, p_shm_save, 0);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2223 vim_free(p_shm_save);
410fa1a31baf updated for version 7.0023
vimboss
parents: 29
diff changeset
2224
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 /* If autocommands took us elsewhere, quit here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 if (curbuf->b_fnum != next_fnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 if (eap->cmdidx == CMD_windo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 validate_cursor(); /* cursor may have moved */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 #ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 /* required when 'scrollbind' has been set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 if (curwin->w_p_scb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 do_check_scrollbind(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 listcmd_busy = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
154
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2244 if (save_ei != NULL)
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2245 {
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2246 au_event_restore(save_ei);
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2247 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2248 curbuf->b_fname, TRUE, curbuf);
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
2249 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 * Add files[count] to the arglist of the current window after arg "after".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 * The file names in files[count] must have been allocated and are taken over.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 * Files[] itself is not taken over.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 * Returns index of first added argument. Returns -1 when failed (out of mem).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 alist_add_list(count, files, after)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 int after; /* where to add: 0 = before first one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 if (after < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 after = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 if (after > ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 after = ARGCOUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 if (after < ARGCOUNT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 (ARGCOUNT - after) * sizeof(aentry_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 for (i = 0; i < count; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 ARGLIST[after + i].ae_fname = files[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 ALIST(curwin)->al_ga.ga_len += count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 if (curwin->w_arg_idx >= after)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 ++curwin->w_arg_idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 return after;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 for (i = 0; i < count; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 vim_free(files[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 #endif /* FEAT_LISTCMDS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 * ":compiler[!] {name}"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 ex_compiler(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 char_u *old_cur_comp = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 if (*eap->arg == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 /* List all compiler scripts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 /* ) keep the indenter happy... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 buf = alloc((unsigned)(STRLEN(eap->arg) + 14));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 if (eap->forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 /* ":compiler! {name}" sets global options */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 do_cmdline_cmd((char_u *)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 "command -nargs=* CompilerSet set <args>");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 /* ":compiler! {name}" sets local options.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 * To remain backwards compatible "current_compiler" is always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 * used. A user's compiler plugin may set it, the distributed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 * plugin will then skip the settings. Afterwards set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 * "b:current_compiler" and restore "current_compiler". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 old_cur_comp = get_var_value((char_u *)"current_compiler");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 if (old_cur_comp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 old_cur_comp = vim_strsave(old_cur_comp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 do_cmdline_cmd((char_u *)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 "command -nargs=* CompilerSet setlocal <args>");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 }
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
2336 do_unlet((char_u *)"current_compiler", TRUE);
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
2337 do_unlet((char_u *)"b:current_compiler", TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 sprintf((char *)buf, "compiler/%s.vim", eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 if (cmd_runtime(buf, TRUE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 EMSG2(_("E666: compiler not supported: %s"), eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 do_cmdline_cmd((char_u *)":delcommand CompilerSet");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 /* Set "b:current_compiler" from "current_compiler". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 p = get_var_value((char_u *)"current_compiler");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 set_internal_string_var((char_u *)"b:current_compiler", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 /* Restore "current_compiler" for ":compiler {name}". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 if (!eap->forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 if (old_cur_comp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 set_internal_string_var((char_u *)"current_compiler",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 old_cur_comp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 vim_free(old_cur_comp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 else
148
72aefd4c1e0d updated for version 7.0046
vimboss
parents: 123
diff changeset
2361 do_unlet((char_u *)"current_compiler", TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 * ":runtime {name}"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 ex_runtime(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 cmd_runtime(eap->arg, eap->forceit);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 static void source_callback __ARGS((char_u *fname));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 source_callback(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 (void)do_source(fname, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 * Source the file "name" from all directories in 'runtimepath'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 * "name" can contain wildcards.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 * When "all" is TRUE, source all files, otherwise only the first one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 * return FAIL when no file could be sourced, OK otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 cmd_runtime(name, all)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 int all;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 return do_in_runtimepath(name, all, source_callback);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 * Find "name" in 'runtimepath'. When found, call the "callback" function for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 * it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 * When "all" is TRUE repeat for all matches, otherwise only the first one is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 * used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 * Returns OK when at least one match found, FAIL otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 do_in_runtimepath(name, all, callback)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 int all;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 void (*callback)__ARGS((char_u *fname));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 char_u *rtp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 char_u *np;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 char_u *rtp_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 int num_files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 int did_one = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 #ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 struct Process *proc = (struct Process *)FindTask(0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 APTR save_winptr = proc->pr_WindowPtr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 /* Avoid a requester here for a volume that doesn't exist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 proc->pr_WindowPtr = (APTR)-1L;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 /* Make a copy of 'runtimepath'. Invoking the callback may change the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 * value. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 rtp_copy = vim_strsave(p_rtp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 buf = alloc(MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 if (buf != NULL && rtp_copy != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 if (p_verbose > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 smsg((char_u *)_("Searching for \"%s\" in \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 (char *)name, (char *)p_rtp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 /* Loop over all entries in 'runtimepath'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 rtp = rtp_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 while (*rtp != NUL && (all || !did_one))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 /* Copy the path from 'runtimepath' to buf[]. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 copy_option_part(&rtp, buf, MAXPATHL, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 if (STRLEN(buf) + STRLEN(name) + 2 < MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 add_pathsep(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 tail = buf + STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 /* Loop over all patterns in "name" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 np = name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 while (*np != NUL && (all || !did_one))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 /* Append the pattern from "name" to buf[]. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 copy_option_part(&np, tail, (int)(MAXPATHL - (tail - buf)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 "\t ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 if (p_verbose > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 msg_str((char_u *)_("Searching for \"%s\""), buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 /* Expand wildcards, invoke the callback for each match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 if (gen_expand_wildcards(1, &buf, &num_files, &files,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 EW_FILE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 for (i = 0; i < num_files; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 (*callback)(files[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 did_one = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 if (!all)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 FreeWild(num_files, files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 vim_free(rtp_copy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 if (p_verbose > 0 && !did_one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 msg_str((char_u *)_("not found in 'runtimepath': \"%s\""), name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 #ifdef AMIGA
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 proc->pr_WindowPtr = save_winptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 return did_one ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 * ":options"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 ex_options(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 cmd_source((char_u *)SYS_OPTWIN_FILE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 * ":source {fname}"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 ex_source(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 #ifdef FEAT_BROWSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 if (cmdmod.browse)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 char_u *fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 22
diff changeset
2516 fname = do_browse(0, (char_u *)_("Source Vim script"), eap->arg,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 NULL, NULL, BROWSE_FILTER_MACROS, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 if (fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 cmd_source(fname, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 vim_free(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 cmd_source(eap->arg, eap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 cmd_source(fname, eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 if (*fname == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 EMSG(_(e_argreq));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 /* ":source!" read vi commands */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 else if (eap != NULL && eap->forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 /* Need to execute the commands directly when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 * - ":g" command busy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 * - after ":argdo", ":windo" or ":bufdo"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 * - another command follows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 * - inside a loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 openscript(fname, global_busy || listcmd_busy || eap->nextcmd != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 || eap->cstack->cs_idx >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 /* ":source" read ex commands */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 else if (do_source(fname, FALSE, FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 EMSG2(_(e_notopen), fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 * ":source" and associated commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 * Structure used to store info for each sourced file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 * It is shared between do_source() and getsourceline().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 * This is required, because it needs to be handed to do_cmdline() and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 * sourcing can be done recursively.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 struct source_cookie
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 FILE *fp; /* opened file for sourcing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 char_u *nextline; /* if not NULL: line that was read ahead */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 int finished; /* ":finish" used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 #if defined (USE_CRNL) || defined (USE_CR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 int fileformat; /* EOL_UNKNOWN, EOL_UNIX or EOL_DOS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 int error; /* TRUE if LF found after CR-LF */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 linenr_T breakpoint; /* next line with breakpoint or zero */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 char_u *fname; /* name of sourced file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 int dbg_tick; /* debug_tick when breakpoint was set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 int level; /* top nesting level of sourced file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 vimconv_T conv; /* type of conversion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587 * Return the address holding the next breakpoint line for a source cookie.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 linenr_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 source_breakpoint(cookie)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 void *cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 return &((struct source_cookie *)cookie)->breakpoint;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 * Return the address holding the debug tick for a source cookie.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2598 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 int *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 source_dbg_tick(cookie)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601 void *cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 return &((struct source_cookie *)cookie)->dbg_tick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 * Return the nesting level for a source cookie.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 source_level(cookie)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 void *cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 return ((struct source_cookie *)cookie)->level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 static char_u *get_one_sourceline __ARGS((struct source_cookie *sp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 #if defined(WIN32) && defined(FEAT_CSCOPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 static FILE *fopen_noinh_readbin __ARGS((char *filename));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 * Special function to open a file without handle inheritance.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 static FILE *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 fopen_noinh_readbin(filename)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 char *filename;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 {
40
f1d2a58883b9 updated for version 7.0024
vimboss
parents: 39
diff changeset
2629 int fd_tmp = mch_open(filename, O_RDONLY | O_BINARY | O_NOINHERIT, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 if (fd_tmp == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 return fdopen(fd_tmp, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 * do_source: Read the file "fname" and execute its lines as EX commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 * This function may be called recursively!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 * return FAIL if file could not be opened, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 do_source(fname, check_other, is_vimrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 int check_other; /* check for .vimrc and _vimrc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 int is_vimrc; /* call vimrc_found() when file exists */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 struct source_cookie cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 char_u *save_sourcing_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 linenr_T save_sourcing_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 char_u *fname_exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 int retval = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 scid_T save_current_SID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 static scid_T last_current_SID = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660 void *save_funccalp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 int save_debug_break_level = debug_break_level;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2662 scriptitem_T *si = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 struct stat st;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 int stat_ok;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 #ifdef STARTUPTIME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 struct timeval tv_rel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 struct timeval tv_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 #endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2672 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2673 proftime_T wait_start;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2674 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 #ifdef RISCOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 p = mch_munge_fname(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 p = expand_env_save(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 fname_exp = fix_fname(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 if (fname_exp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 #ifdef MACOS_CLASSIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688 slash_n_colon_adjust(fname_exp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 if (mch_isdir(fname_exp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 msg_str((char_u *)_("Cannot source a directory: \"%s\""), fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696 #if defined(WIN32) && defined(FEAT_CSCOPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 if (cookie.fp == NULL && check_other)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 * Try again, replacing file name ".vimrc" by "_vimrc" or vice versa,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 * and ".exrc" by "_exrc" or vice versa.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 p = gettail(fname_exp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 if ((*p == '.' || *p == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 && (STRICMP(p + 1, "vimrc") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 || STRICMP(p + 1, "gvimrc") == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 || STRICMP(p + 1, "exrc") == 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 if (*p == '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 *p = '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 *p = '_';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 #if defined(WIN32) && defined(FEAT_CSCOPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 cookie.fp = fopen_noinh_readbin((char *)fname_exp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 cookie.fp = mch_fopen((char *)fname_exp, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 if (cookie.fp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 if (p_verbose > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 if (sourcing_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 msg_str((char_u *)_("could not source \"%s\""), fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 smsg((char_u *)_("line %ld: could not source \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 sourcing_lnum, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 * The file exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 * - In verbose mode, give a message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 * - For a vimrc file, may want to set 'compatible', call vimrc_found().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 if (p_verbose > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 if (sourcing_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 msg_str((char_u *)_("sourcing \"%s\""), fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 smsg((char_u *)_("line %ld: sourcing \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 sourcing_lnum, fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 if (is_vimrc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 vimrc_found();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 #ifdef USE_CRNL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 /* If no automatic file format: Set default to CR-NL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 if (*p_ffs == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 cookie.fileformat = EOL_DOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 cookie.fileformat = EOL_UNKNOWN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 cookie.error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 #ifdef USE_CR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 /* If no automatic file format: Set default to CR. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 if (*p_ffs == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 cookie.fileformat = EOL_MAC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 cookie.fileformat = EOL_UNKNOWN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 cookie.error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 cookie.nextline = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 cookie.finished = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 * Check if this script has a breakpoint.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 cookie.breakpoint = dbg_find_breakpoint(TRUE, fname_exp, (linenr_T)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 cookie.fname = fname_exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 cookie.dbg_tick = debug_tick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 cookie.level = ex_nesting_level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 cookie.conv.vc_type = CONV_NONE; /* no conversion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 /* Try reading the first few bytes to check for a UTF-8 BOM. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 char_u buf[3];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 if (fread((char *)buf, sizeof(char_u), (size_t)3, cookie.fp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 == (size_t)3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 /* Found BOM, setup conversion and skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 /* No BOM found, rewind. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 fseek(cookie.fp, 0L, SEEK_SET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 * Keep the sourcing name/lnum, for recursive calls.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 save_sourcing_name = sourcing_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 sourcing_name = fname_exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 save_sourcing_lnum = sourcing_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 sourcing_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 #ifdef STARTUPTIME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 time_push(&tv_rel, &tv_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 #ifdef FEAT_EVAL
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2816 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2817 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2818 prof_child_enter(&wait_start); /* entering a child now */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2819 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2820
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2821 /* Don't use local function variables, if called from a function.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2822 * Also starts profiling timer for nested script. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2823 save_funccalp = save_funccal();
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2824
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 * Check if this script was sourced before to finds its SID.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 * If it's new, generate a new SID.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 save_current_SID = current_SID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 stat_ok = (mch_stat((char *)fname_exp, &st) >= 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2833 for (current_SID = script_items.ga_len; current_SID > 0; --current_SID)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2834 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2835 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2836 if (si->sn_name != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 && (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 # ifdef UNIX
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 154
diff changeset
2839 /* Compare dev/ino when possible, it catches symbolic
6df0106fc595 updated for version 7.0049
vimboss
parents: 154
diff changeset
2840 * links. Also compare file names, the inode may change
6df0106fc595 updated for version 7.0049
vimboss
parents: 154
diff changeset
2841 * when the file was edited. */
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2842 ((stat_ok && si->sn_dev != -1)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2843 && (si->sn_dev == st.st_dev
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2844 && si->sn_ino == st.st_ino)) ||
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2846 fnamecmp(si->sn_name, fname_exp) == 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 break;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2848 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 if (current_SID == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 current_SID = ++last_current_SID;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2852 if (ga_grow(&script_items, (int)(current_SID - script_items.ga_len))
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2853 == FAIL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2854 goto almosttheend;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2855 while (script_items.ga_len < current_SID)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 {
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2857 ++script_items.ga_len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2858 SCRIPT_ITEM(script_items.ga_len).sn_name = NULL;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2859 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2860 SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2861 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2862 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2863 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2864 si->sn_name = fname_exp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2865 fname_exp = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 # ifdef UNIX
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2867 if (stat_ok)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2868 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2869 si->sn_dev = st.st_dev;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2870 si->sn_ino = st.st_ino;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2871 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2872 else
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2873 si->sn_dev = -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 # endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2875
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 /* Allocate the local script variables to use for this script. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 new_script_vars(current_SID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2880 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2881 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2882 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2883 int forceit;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2884
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2885 /* Check if we do profiling for this script. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2886 if (!si->sn_prof_on && has_profiling(TRUE, si->sn_name, &forceit))
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2887 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2888 script_do_profile(si);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2889 si->sn_pr_force = forceit;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2890 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2891 if (si->sn_prof_on)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2892 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2893 ++si->sn_pr_count;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2894 profile_start(&si->sn_pr_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2895 profile_zero(&si->sn_pr_children);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2896 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2897 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2898 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 * Call do_cmdline, which will call getsourceline() to get the lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 do_cmdline(NULL, getsourceline, (void *)&cookie,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 retval = OK;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2908
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2909 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2910 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2911 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2912 /* Get "si" again, "script_items" may have been reallocated. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2913 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2914 if (si->sn_prof_on)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2915 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2916 profile_end(&si->sn_pr_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2917 profile_sub_wait(&wait_start, &si->sn_pr_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2918 profile_add(&si->sn_pr_total, &si->sn_pr_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2919 profile_add(&si->sn_pr_self, &si->sn_pr_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2920 profile_sub(&si->sn_pr_self, &si->sn_pr_children);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2921 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2922 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 EMSG(_(e_interr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 sourcing_name = save_sourcing_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 sourcing_lnum = save_sourcing_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 if (p_verbose > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 msg_str((char_u *)_("finished sourcing %s"), fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 if (sourcing_name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 msg_str((char_u *)_("continuing in %s"), sourcing_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 #ifdef STARTUPTIME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 # ifdef HAVE_SNPRINTF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 snprintf(IObuff, IOSIZE, "sourcing %s", fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 sprintf(IObuff, "sourcing %s", fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 time_msg(IObuff, &tv_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 time_pop(&tv_rel);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 * After a "finish" in debug mode, need to break at first command of next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 * sourced file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 if (save_debug_break_level > ex_nesting_level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 && debug_break_level == ex_nesting_level)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 ++debug_break_level;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2955 #ifdef FEAT_EVAL
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2956 almosttheend:
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2957 current_SID = save_current_SID;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2958 restore_funccal(save_funccalp);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2959 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2960 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2961 prof_child_exit(&wait_start); /* leaving a child now */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2962 # endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2963 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2964 fclose(cookie.fp);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2965 vim_free(cookie.nextline);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2966 #ifdef FEAT_MBYTE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2967 convert_setup(&cookie.conv, NULL, NULL);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2968 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2969
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 vim_free(fname_exp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 * ":scriptnames"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 ex_scriptnames(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2986 for (i = 1; i <= script_items.ga_len && !got_int; ++i)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2987 if (SCRIPT_ITEM(i).sn_name != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
2988 smsg((char_u *)"%3d: %s", i, SCRIPT_ITEM(i).sn_name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 * Fix slashes in the list of script names for 'shellslash'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 scriptnames_slash_adjust()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3000 for (i = 1; i <= script_items.ga_len; ++i)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3001 if (SCRIPT_ITEM(i).sn_name != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3002 slash_adjust(SCRIPT_ITEM(i).sn_name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 * Get a pointer to a script name. Used for ":verbose set".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 get_scriptname(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 scid_T id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 if (id == SID_MODELINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 return (char_u *)"modeline";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 if (id == SID_CMDARG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 return (char_u *)"--cmd argument";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 if (id == SID_CARG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 return (char_u *)"-c argument";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 if (id == SID_ENV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 return (char_u *)"environment variable";
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3021 return SCRIPT_ITEM(id).sn_name;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3022 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3023
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 #if defined(USE_CR) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 # if defined(__MSL__) && (__MSL__ >= 22)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 * Newer version of the Metrowerks library handle DOS and UNIX files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 * without help.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 * Test with earlier versions, MSL 2.2 is the library supplied with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 * Codewarrior Pro 2.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 fgets_cr(s, n, stream)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 char *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 FILE *stream;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 return fgets(s, n, stream);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 * Version of fgets() which also works for lines ending in a <CR> only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 * (Macintosh format).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 * For older versions of the Metrowerks library.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 * At least CodeWarrior 9 needed this code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 fgets_cr(s, n, stream)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 char *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 FILE *stream;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 int char_read = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 while (!feof(stream) && c != '\r' && c != '\n' && char_read < n - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 c = fgetc(stream);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 s[char_read++] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 /* If the file is in DOS format, we need to skip a NL after a CR. I
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 * thought it was the other way around, but this appears to work... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 if (c == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 c = fgetc(stream);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 if (c != '\r')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 ungetc(c, stream);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 s[char_read] = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 if (char_read == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 if (feof(stream) && char_read == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 * Get one full line from a sourced file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 * Called by do_cmdline() when it's called from do_source().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 * Return a pointer to the line in allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 * Return NULL for end-of-file or some error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 /* ARGSUSED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 getsourceline(c, cookie, indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 int c; /* not used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 void *cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 int indent; /* not used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 struct source_cookie *sp = (struct source_cookie *)cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 char_u *p, *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 /* If breakpoints have been added/deleted need to check for it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 if (sp->dbg_tick < debug_tick)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 sp->dbg_tick = debug_tick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 }
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3110 # ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3111 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3112 script_line_end();
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3113 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 * Get current line. If there is a read-ahead line, use it, otherwise get
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 * one now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 if (sp->finished)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 else if (sp->nextline == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 line = get_one_sourceline(sp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 line = sp->nextline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 sp->nextline = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 ++sourcing_lnum;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3128 #ifdef FEAT_PROFILE
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3129 if (do_profiling)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3130 script_line_start();
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3131 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 /* Only concatenate lines starting with a \ when 'cpoptions' doesn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 * contain the 'C' flag. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 if (line != NULL && (vim_strchr(p_cpo, CPO_CONCAT) == NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 /* compensate for the one line read-ahead */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 --sourcing_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 sp->nextline = get_one_sourceline(sp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 if (sp->nextline == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 p = skipwhite(sp->nextline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 if (*p != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 s = alloc((int)(STRLEN(line) + STRLEN(p)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 if (s == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 STRCPY(s, line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 STRCAT(s, p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 vim_free(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 line = s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 vim_free(sp->nextline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 if (line != NULL && sp->conv.vc_type != CONV_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 /* Convert the encoding of the script line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 s = string_convert(&sp->conv, line, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 vim_free(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 line = s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 /* Did we encounter a breakpoint? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 if (sp->breakpoint != 0 && sp->breakpoint <= sourcing_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 dbg_breakpoint(sp->fname, sourcing_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 /* Find next breakpoint. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 sp->breakpoint = dbg_find_breakpoint(TRUE, sp->fname, sourcing_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 sp->dbg_tick = debug_tick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 return line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 get_one_sourceline(sp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 struct source_cookie *sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 #ifdef USE_CRNL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 int has_cr; /* CR-LF found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 #ifdef USE_CR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198 char_u *scan;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 int have_read = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 /* use a growarray to store the sourced line */
154
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
3203 ga_init2(&ga, 1, 250);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 * Loop until there is a finished line (or end-of-file).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3208 sourcing_lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3209 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3210 {
154
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
3211 /* make room to read at least 120 (more) characters */
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
3212 if (ga_grow(&ga, 120) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3213 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3214 buf = (char_u *)ga.ga_data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216 #ifdef USE_CR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3217 if (sp->fileformat == EOL_MAC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 {
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
3219 if (fgets_cr((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
3220 sp->fp) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224 #endif
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
3225 if (fgets((char *)buf + ga.ga_len, ga.ga_maxlen - ga.ga_len,
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
3226 sp->fp) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 break;
154
1a145815483e updated for version 7.0047
vimboss
parents: 148
diff changeset
3228 len = ga.ga_len + (int)STRLEN(buf + ga.ga_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 #ifdef USE_CRNL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 /* Ignore a trailing CTRL-Z, when in Dos mode. Only recognize the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231 * CTRL-Z by its own, or after a NL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 if ( (len == 1 || (len >= 2 && buf[len - 2] == '\n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 && sp->fileformat == EOL_DOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234 && buf[len - 1] == Ctrl_Z)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 buf[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 #ifdef USE_CR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 /* If the read doesn't stop on a new line, and there's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 * some CR then we assume a Mac format */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244 if (sp->fileformat == EOL_UNKNOWN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 if (buf[len - 1] != '\n' && vim_strchr(buf, '\r') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 sp->fileformat = EOL_MAC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 sp->fileformat = EOL_UNIX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 if (sp->fileformat == EOL_MAC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 scan = vim_strchr(buf, '\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 if (scan != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3258 *scan = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 if (*(scan + 1) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 *(scan + 1) = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 fseek(sp->fp, (long)(scan - buf - len + 1), SEEK_CUR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 len = STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 have_read = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270 ga.ga_len = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272 /* If the line was longer than the buffer, read more. */
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 40
diff changeset
3273 if (ga.ga_maxlen - ga.ga_len == 1 && buf[len - 1] != '\n')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276 if (len >= 1 && buf[len - 1] == '\n') /* remove trailing NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278 #ifdef USE_CRNL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 has_cr = (len >= 2 && buf[len - 2] == '\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 if (sp->fileformat == EOL_UNKNOWN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 if (has_cr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 sp->fileformat = EOL_DOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 sp->fileformat = EOL_UNIX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3288 if (sp->fileformat == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3289 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3290 if (has_cr) /* replace trailing CR */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3292 buf[len - 2] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3293 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 --ga.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 else /* lines like ":map xx yy^M" will have failed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 if (!sp->error)
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
3299 {
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
3300 msg_source(hl_attr(HLF_W));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 EMSG(_("W15: Warning: Wrong line separator, ^M may be missing"));
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 15
diff changeset
3302 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3303 sp->error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304 sp->fileformat = EOL_UNIX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 /* The '\n' is escaped if there is an odd number of ^V's just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 * before it, first set "c" just before the 'V's and then check
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 * len&c parities (is faster than ((len-c)%2 == 0)) -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 for (c = len - 2; c >= 0 && buf[c] == Ctrl_V; c--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 if ((len & 1) != (c & 1)) /* escaped NL, read more */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 sourcing_lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 buf[len - 1] = NUL; /* remove the NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 * Check for ^C here now and then, so recursive :so can be broken.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 if (have_read)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330 return (char_u *)ga.ga_data;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 vim_free(ga.ga_data);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3333 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3336 #if defined(FEAT_PROFILE) || defined(PROTO)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3337 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3338 * Called when starting to read a script line.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3339 * "sourcing_lnum" must be correct!
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3340 * When skipping lines it may not actually be executed, but we won't find out
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3341 * until later and we need to store the time now.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3342 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3343 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3344 script_line_start()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3345 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3346 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3347 sn_prl_T *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3348
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3349 if (current_SID <= 0 || current_SID > script_items.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3350 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3351 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3352 if (si->sn_prof_on && sourcing_lnum >= 1)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3353 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3354 /* Grow the array before starting the timer, so that the time spend
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3355 * here isn't counted. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3356 ga_grow(&si->sn_prl_ga, (int)(sourcing_lnum - si->sn_prl_ga.ga_len));
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3357 si->sn_prl_idx = sourcing_lnum - 1;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3358 while (si->sn_prl_ga.ga_len <= si->sn_prl_idx
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3359 && si->sn_prl_ga.ga_len < si->sn_prl_ga.ga_maxlen)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3360 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3361 /* Zero counters for a line that was not used before. */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3362 pp = &PRL_ITEM(si, si->sn_prl_ga.ga_len);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3363 pp->snp_count = 0;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3364 profile_zero(&pp->sn_prl_total);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3365 profile_zero(&pp->sn_prl_self);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3366 ++si->sn_prl_ga.ga_len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3367 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3368 si->sn_prl_execed = FALSE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3369 profile_start(&si->sn_prl_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3370 profile_zero(&si->sn_prl_children);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3371 profile_get_wait(&si->sn_prl_wait);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3372 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3373 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3374
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3375 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3376 * Called when actually executing a function line.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3377 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3378 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3379 script_line_exec()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3380 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3381 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3382
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3383 if (current_SID <= 0 || current_SID > script_items.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3384 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3385 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3386 if (si->sn_prof_on && si->sn_prl_idx >= 0)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3387 si->sn_prl_execed = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3388 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3389
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3390 /*
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3391 * Called when done with a function line.
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3392 */
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3393 void
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3394 script_line_end()
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3395 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3396 scriptitem_T *si;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3397 sn_prl_T *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3398
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3399 if (current_SID <= 0 || current_SID > script_items.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3400 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3401 si = &SCRIPT_ITEM(current_SID);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3402 if (si->sn_prof_on && si->sn_prl_idx >= 0
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3403 && si->sn_prl_idx < si->sn_prl_ga.ga_len)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3404 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3405 if (si->sn_prl_execed)
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3406 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3407 pp = &PRL_ITEM(si, si->sn_prl_idx);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3408 ++pp->snp_count;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3409 profile_end(&si->sn_prl_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3410 profile_sub_wait(&si->sn_prl_wait, &si->sn_prl_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3411 profile_add(&pp->sn_prl_self, &si->sn_prl_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3412 profile_add(&pp->sn_prl_total, &si->sn_prl_start);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3413 profile_sub(&pp->sn_prl_self, &si->sn_prl_children);
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3414 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3415 si->sn_prl_idx = -1;
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3416 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3417 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3418 #endif
8c60f65311fa updated for version 7.0052
vimboss
parents: 161
diff changeset
3419
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 * ":scriptencoding": Set encoding conversion for a sourced script.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 * Without the multi-byte feature it's simply ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 ex_scriptencoding(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 struct source_cookie *sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 if (!getline_equal(eap->getline, eap->cookie, getsourceline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 EMSG(_("E167: :scriptencoding used outside of a sourced file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439 if (*eap->arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 name = enc_canonize(eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 if (name == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 name = eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 /* Setup for conversion from the specified encoding to 'encoding'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 sp = (struct source_cookie *)getline_cookie(eap->getline, eap->cookie);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 convert_setup(&sp->conv, name, p_enc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 if (name != eap->arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 * ":finish": Mark a sourced file as finished.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 ex_finish(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 if (getline_equal(eap->getline, eap->cookie, getsourceline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 do_finish(eap, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 EMSG(_("E168: :finish used outside of a sourced file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 * Mark a sourced file as finished. Possibly makes the ":finish" pending.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 * Also called for a pending finish at the ":endtry" or after returning from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 * an extra do_cmdline(). "reanimate" is used in the latter case.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 do_finish(eap, reanimate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 int reanimate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 if (reanimate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 ((struct source_cookie *)getline_cookie(eap->getline,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 eap->cookie))->finished = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 * Cleanup (and inactivate) conditionals, but stop when a try conditional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 * not in its finally clause (which then is to be executed next) is found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 * In this case, make the ":finish" pending for execution at the ":endtry".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 * Otherwise, finish normally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 if (idx >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 eap->cstack->cs_pending[idx] = CSTP_FINISH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 report_make_pending(CSTP_FINISH, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 ((struct source_cookie *)getline_cookie(eap->getline,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501 eap->cookie))->finished = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 * Return TRUE when a sourced file had the ":finish" command: Don't give error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 * message for missing ":endif".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3508 * Return FALSE when not sourcing a file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3509 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511 source_finished(getline, cookie)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3512 char_u *(*getline) __ARGS((int, void *, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 void *cookie;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 return (getline_equal(getline, cookie, getsourceline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 && ((struct source_cookie *)getline_cookie(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517 getline, cookie))->finished);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 #if defined(FEAT_LISTCMDS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 * ":checktime [buffer]"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 ex_checktime(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 int save_no_check_timestamps = no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 no_check_timestamps = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 if (eap->addr_count == 0) /* default is all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 check_timestamps(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 buf = buflist_findnr((int)eap->line2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 if (buf != NULL) /* cannot happen? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 (void)buf_check_timestamp(buf, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 no_check_timestamps = save_no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 #if defined(FEAT_PRINTER) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 * Printing code (Machine-independent.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 * To implement printing on a platform, the following functions must be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 * defined:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551 * int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3552 * Called once. Code should display printer dialogue (if appropriate) and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 * determine printer font and margin settings. Reset has_color if the printer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 * doesn't support colors at all.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555 * Returns FAIL to abort.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 * int mch_print_begin(prt_settings_T *settings)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 * Called to start the print job.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 * Return FALSE to abort.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 * int mch_print_begin_page(char_u *msg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 * Called at the start of each page.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563 * "msg" indicates the progress of the print job, can be NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 * Return FALSE to abort.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 * int mch_print_end_page()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 * Called at the end of each page.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 * Return FALSE to abort.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 * int mch_print_blank_page()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 * Called to generate a blank page for collated, duplex, multiple copy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 * document. Return FALSE to abort.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 * void mch_print_end(prt_settings_T *psettings)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 * Called at normal end of print job.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 * void mch_print_cleanup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 * Called if print job ends normally or is abandoned. Free any memory, close
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 * devices and handles. Also called when mch_print_begin() fails, but not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 * when mch_print_init() fails.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 * void mch_print_set_font(int Bold, int Italic, int Underline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 * Called whenever the font style changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 * void mch_print_set_bg(long bgcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 * Called to set the background color for the following text. Parameter is an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 * RGB value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 * void mch_print_set_fg(long fgcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 * Called to set the foreground color for the following text. Parameter is an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 * RGB value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 * mch_print_start_line(int margin, int page_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 * Sets the current position at the start of line "page_line".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 * If margin is TRUE start in the left margin (for header and line number).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 * int mch_print_text_out(char_u *p, int len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 * Output one character of text p[len] at the current position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 * Return TRUE if there is no room for another character in the same line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 * Note that the generic code has no idea of margins. The machine code should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3602 * simply make the page look smaller! The header and the line numbers are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 * printed in the margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 static const long_u cterm_color_8[8] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 (long_u)0x000000L, (long_u)0xff0000L, (long_u)0x00ff00L, (long_u)0xffff00L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 (long_u)0x0000ffL, (long_u)0xff00ffL, (long_u)0x00ffffL, (long_u)0xffffffL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 static const long_u cterm_color_16[16] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 (long_u)0x000000L, (long_u)0x0000c0L, (long_u)0x008000L, (long_u)0x004080L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 (long_u)0xc00000L, (long_u)0xc000c0L, (long_u)0x808000L, (long_u)0xc0c0c0L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 (long_u)0x808080L, (long_u)0x6060ffL, (long_u)0x00ff00L, (long_u)0x00ffffL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 (long_u)0xff8080L, (long_u)0xff40ffL, (long_u)0xffff00L, (long_u)0xffffffL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 static int current_syn_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 #define PRCOLOR_BLACK (long_u)0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 #define PRCOLOR_WHITE (long_u)0xFFFFFFL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 static int curr_italic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 static int curr_bold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 static int curr_underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 static long_u curr_bg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 static long_u curr_fg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 static int page_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 * These values determine the print position on a page.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 int lead_spaces; /* remaining spaces for a TAB */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 int print_pos; /* virtual column for computing TABs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 colnr_T column; /* byte column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 linenr_T file_line; /* line nr in the buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 long_u bytes_printed; /* bytes printed so far */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 int ff; /* seen form feed character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 } prt_pos_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 static long_u darken_rgb __ARGS((long_u rgb));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 static long_u prt_get_term_color __ARGS((int colorindex));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 static void prt_set_fg __ARGS((long_u fg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 static void prt_set_bg __ARGS((long_u bg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 static void prt_set_font __ARGS((int bold, int italic, int underline));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 static void prt_line_number __ARGS((prt_settings_T *psettings, int page_line, linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 static void prt_header __ARGS((prt_settings_T *psettings, int pagenum, linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 static void prt_message __ARGS((char_u *s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 static colnr_T hardcopy_line __ARGS((prt_settings_T *psettings, int page_line, prt_pos_T *ppos));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 static void prt_get_attr __ARGS((int hl_id, prt_text_attr_T* pattr, int modec));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3661 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3662 * If using a dark background, the colors will probably be too bright to show
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3663 * up well on white paper, so reduce their brightness.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665 static long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3666 darken_rgb(rgb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 long_u rgb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 return ((rgb >> 17) << 16)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3670 + (((rgb & 0xff00) >> 9) << 8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671 + ((rgb & 0xff) >> 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 static long_u
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 prt_get_term_color(colorindex)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 int colorindex;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678 /* TODO: Should check for xterm with 88 or 256 colors. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 if (t_colors > 8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 return cterm_color_16[colorindex % 16];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 return cterm_color_8[colorindex % 8];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 prt_get_attr(hl_id, pattr, modec)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 int hl_id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 prt_text_attr_T* pattr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 int modec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 int colorindex;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 long_u fg_color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 long_u bg_color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 char *color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695 pattr->bold = (highlight_has_attr(hl_id, HL_BOLD, modec) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 pattr->italic = (highlight_has_attr(hl_id, HL_ITALIC, modec) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 pattr->underline = (highlight_has_attr(hl_id, HL_UNDERLINE, modec) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 bg_color = highlight_gui_color_rgb(hl_id, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 if (bg_color == PRCOLOR_BLACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 bg_color = PRCOLOR_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 fg_color = highlight_gui_color_rgb(hl_id, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 bg_color = PRCOLOR_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713 color = (char *)highlight_color(hl_id, (char_u *)"fg", modec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 if (color == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 colorindex = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717 colorindex = atoi(color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719 if (colorindex >= 0 && colorindex < t_colors)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 fg_color = prt_get_term_color(colorindex);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3721 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 fg_color = PRCOLOR_BLACK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 if (fg_color == PRCOLOR_WHITE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 fg_color = PRCOLOR_BLACK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 else if (*p_bg == 'd')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 fg_color = darken_rgb(fg_color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 pattr->fg_color = fg_color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 pattr->bg_color = bg_color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 #endif /* FEAT_SYN_HL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736 prt_set_fg(fg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 long_u fg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3738 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 if (fg != curr_fg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 curr_fg = fg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3742 mch_print_set_fg(fg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3743 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747 prt_set_bg(bg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 long_u bg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 if (bg != curr_bg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 curr_bg = bg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 mch_print_set_bg(bg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 prt_set_font(bold, italic, underline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 int bold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 int italic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 int underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3762 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763 if (curr_bold != bold
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3764 || curr_italic != italic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3765 || curr_underline != underline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3767 curr_underline = underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3768 curr_italic = italic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 curr_bold = bold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3770 mch_print_set_font(bold, italic, underline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 * Print the line number in the left margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 prt_line_number(psettings, page_line, lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 int page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3781 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3782 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3783 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3784 char_u tbuf[20];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3786 prt_set_fg(psettings->number.fg_color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3787 prt_set_bg(psettings->number.bg_color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 prt_set_font(psettings->number.bold, psettings->number.italic, psettings->number.underline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3789 mch_print_start_line(TRUE, page_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3791 /* Leave two spaces between the number and the text; depends on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3792 * PRINT_NUMBER_WIDTH. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3793 sprintf((char *)tbuf, "%6ld", (long)lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3794 for (i = 0; i < 6; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3795 (void)mch_print_text_out(&tbuf[i], 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3797 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3798 if (psettings->do_syntax)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799 /* Set colors for next character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 current_syn_id = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 /* Set colors and font back to normal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 prt_set_fg(PRCOLOR_BLACK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806 prt_set_bg(PRCOLOR_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 prt_set_font(FALSE, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 static linenr_T printer_page_num;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 get_printer_page_num()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 return printer_page_num;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 * Get the currently effective header height.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 prt_header_height()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825 if (printer_opts[OPT_PRINT_HEADERHEIGHT].present)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 return printer_opts[OPT_PRINT_HEADERHEIGHT].number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 return 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 * Return TRUE if using a line number for printing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 prt_use_number()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 return (printer_opts[OPT_PRINT_NUMBER].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837 && TOLOWER_ASC(printer_opts[OPT_PRINT_NUMBER].string[0]) == 'y');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 * Return the unit used in a margin item in 'printoptions'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 * Returns PRT_UNIT_NONE if not recognized.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 prt_get_unit(idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 int u = PRT_UNIT_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 static char *(units[4]) = PRT_UNIT_NAMES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3851
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852 if (printer_opts[idx].present)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3853 for (i = 0; i < 4; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 if (STRNICMP(printer_opts[idx].string, units[i], 2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 u = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 return u;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3862 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 * Print the page header.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3865 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3866 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3867 prt_header(psettings, pagenum, lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3868 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 int pagenum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872 int width = psettings->chars_per_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873 int page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 char_u *tbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 /* Also use the space for the line number. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 if (prt_use_number())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 width += PRINT_NUMBER_WIDTH;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 tbuf = alloc(width + IOSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 if (tbuf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 #ifdef FEAT_STL_OPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 if (*p_header != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 linenr_T tmp_lnum, tmp_topline, tmp_botline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 * Need to (temporarily) set current line number and first/last line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3895 * number on the 'window'. Since we don't know how long the page is,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896 * set the first and current line number to the top line, and guess
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 * that the page length is 64.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899 tmp_lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3900 tmp_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 tmp_botline = curwin->w_botline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 curwin->w_topline = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 curwin->w_botline = lnum + 63;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 printer_page_num = pagenum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3907 build_stl_str_hl(curwin, tbuf, (size_t)(width + IOSIZE),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 p_header, ' ', width, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910 /* Reset line numbers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3911 curwin->w_cursor.lnum = tmp_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3912 curwin->w_topline = tmp_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3913 curwin->w_botline = tmp_botline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 sprintf((char *)tbuf, _("Page %d"), pagenum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 prt_set_fg(PRCOLOR_BLACK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 prt_set_bg(PRCOLOR_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 prt_set_font(TRUE, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 /* Use a negative line number to indicate printing in the top margin. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 page_line = 0 - prt_header_height();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 mch_print_start_line(TRUE, page_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 for (p = tbuf; *p != NUL; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 if (mch_print_text_out(p,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 (l = (*mb_ptr2len_check)(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 ++page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 if (page_line >= 0) /* out of room in header */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 mch_print_start_line(TRUE, page_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 p += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 vim_free(tbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 if (psettings->do_syntax)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 /* Set colors for next character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 current_syn_id = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3954 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 /* Set colors and font back to normal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 prt_set_fg(PRCOLOR_BLACK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 prt_set_bg(PRCOLOR_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 prt_set_font(FALSE, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 * Display a print status message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 prt_message(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 screen_puts(s, (int)Rows - 1, 0, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 ex_hardcopy(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 int collated_copies, uncollated_copies;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 prt_settings_T settings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 long_u bytes_to_print = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 int page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 int jobsplit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986 int id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 memset(&settings, 0, sizeof(prt_settings_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 settings.has_color = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 # ifdef FEAT_POSTSCRIPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 if (*eap->arg == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 char_u *errormsg = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 /* Expand things like "%.ps". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 if (expand_filename(eap, eap->cmdlinep, &errormsg) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 if (errormsg != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 EMSG(errormsg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 settings.outfile = skipwhite(eap->arg + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 else if (*eap->arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 settings.arguments = eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 * Initialise for printing. Ask the user for settings, unless forceit is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 * set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012 * The mch_print_init() code should set up margins if applicable. (It may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 * not be a real printer - for example the engine might generate HTML or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 * PS.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4015 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 if (mch_print_init(&settings,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 curbuf->b_fname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 ? (char_u *)buf_spname(curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 : curbuf->b_sfname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 ? curbuf->b_fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 : curbuf->b_sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 eap->forceit) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 settings.modec = 'g';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 if (t_colors > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 settings.modec = 'c';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 settings.modec = 't';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 if (!syntax_present(curbuf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4037 settings.do_syntax = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 else if (printer_opts[OPT_PRINT_SYNTAX].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 && TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) != 'a')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 settings.do_syntax =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 (TOLOWER_ASC(printer_opts[OPT_PRINT_SYNTAX].string[0]) == 'y');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 settings.do_syntax = settings.has_color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 /* Set up printing attributes for line numbers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 settings.number.fg_color = PRCOLOR_BLACK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 settings.number.bg_color = PRCOLOR_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 settings.number.bold = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 settings.number.italic = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 settings.number.underline = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 * Syntax highlighting of line numbers.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 if (prt_use_number() && settings.do_syntax)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 id = syn_name2id((char_u *)"LineNr");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 if (id > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 id = syn_get_final_id(id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 prt_get_attr(id, &settings.number, settings.modec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 #endif /* FEAT_SYN_HL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 * Estimate the total lines to be printed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 for (lnum = eap->line1; lnum <= eap->line2; lnum++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 bytes_to_print += (long_u)STRLEN(skipwhite(ml_get(lnum)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 if (bytes_to_print == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 MSG(_("No text to be printed"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 goto print_fail_no_begin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 /* Set colors and font to normal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 curr_bg = (long_u)0xffffffffL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 curr_fg = (long_u)0xffffffffL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 curr_italic = MAYBE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 curr_bold = MAYBE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 curr_underline = MAYBE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 prt_set_fg(PRCOLOR_BLACK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 prt_set_bg(PRCOLOR_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 prt_set_font(FALSE, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 current_syn_id = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 && TOLOWER_ASC(printer_opts[OPT_PRINT_JOBSPLIT].string[0]) == 'y');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 if (!mch_print_begin(&settings))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 goto print_fail_no_begin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 * Loop over collated copies: 1 2 3, 1 2 3, ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 page_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 for (collated_copies = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 collated_copies < settings.n_collated_copies;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 collated_copies++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 prt_pos_T prtpos; /* current print position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 prt_pos_T page_prtpos; /* print position at page start */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 int side;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 memset(&page_prtpos, 0, sizeof(prt_pos_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 page_prtpos.file_line = eap->line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 prtpos = page_prtpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 if (jobsplit && collated_copies > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 /* Splitting jobs: Stop a previous job and start a new one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 mch_print_end(&settings);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 if (!mch_print_begin(&settings))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 goto print_fail_no_begin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 * Loop over all pages in the print job: 1 2 3 ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 for (page_count = 0; prtpos.file_line <= eap->line2; ++page_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 * Loop over uncollated copies: 1 1 1, 2 2 2, 3 3 3, ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128 * For duplex: 12 12 12 34 34 34, ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 for (uncollated_copies = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 uncollated_copies < settings.n_uncollated_copies;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 uncollated_copies++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 /* Set the print position to the start of this page. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 prtpos = page_prtpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 * Do front and rear side of a page.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 for (side = 0; side <= settings.duplex; ++side)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 * Print one page.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 /* Check for interrupt character every page. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 if (got_int || settings.user_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149 goto print_fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 sprintf((char *)IObuff, _("Printing page %d (%d%%)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 page_count + 1 + side,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 prtpos.bytes_printed > 1000000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 ? (int)(prtpos.bytes_printed /
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 (bytes_to_print / 100))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 : (int)((prtpos.bytes_printed * 100)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 / bytes_to_print));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158 if (!mch_print_begin_page(IObuff))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 goto print_fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 if (settings.n_collated_copies > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 sprintf((char *)IObuff + STRLEN(IObuff),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 _(" Copy %d of %d"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 collated_copies + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 settings.n_collated_copies);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 prt_message(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 * Output header if required
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 if (prt_header_height() > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 prt_header(&settings, page_count + 1 + side,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 prtpos.file_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 for (page_line = 0; page_line < settings.lines_per_page;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 ++page_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 prtpos.column = hardcopy_line(&settings,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 page_line, &prtpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 if (prtpos.column == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 /* finished a file line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 prtpos.bytes_printed +=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 STRLEN(skipwhite(ml_get(prtpos.file_line)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 if (++prtpos.file_line > eap->line2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 break; /* reached the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 else if (prtpos.ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 /* Line had a formfeed in it - start new page but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 * stay on the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 if (!mch_print_end_page())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 goto print_fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 if (prtpos.file_line > eap->line2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 break; /* reached the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 * Extra blank page for duplexing with odd number of pages and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 * more copies to come.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 if (prtpos.file_line > eap->line2 && settings.duplex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 && side == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 && uncollated_copies + 1 < settings.n_uncollated_copies)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 if (!mch_print_blank_page())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 goto print_fail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 if (settings.duplex && prtpos.file_line <= eap->line2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 ++page_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 /* Remember the position where the next page starts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 page_prtpos = prtpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 sprintf((char *)IObuff, _("Printed: %s"), settings.jobname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 prt_message(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 print_fail:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 if (got_int || settings.user_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 sprintf((char *)IObuff, _("Printing aborted"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 prt_message(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 mch_print_end(&settings);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 print_fail_no_begin:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 mch_print_cleanup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 * Print one page line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 * Return the next column to print, or zero if the line is finished.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 static colnr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 hardcopy_line(psettings, page_line, ppos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4243 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 int page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 prt_pos_T *ppos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 int need_break = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 int outputlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 int tab_spaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 long_u print_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 prt_text_attr_T attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 int id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 if (ppos->column == 0 || ppos->ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 print_pos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 tab_spaces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 if (!ppos->ff && prt_use_number())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263 prt_line_number(psettings, page_line, ppos->file_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 ppos->ff = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 /* left over from wrap halfway a tab */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 print_pos = ppos->print_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 tab_spaces = ppos->lead_spaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 mch_print_start_line(0, page_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 line = ml_get(ppos->file_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 * Loop over the columns until the end of the file line or right margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 outputlen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283 if (has_mbyte && (outputlen = (*mb_ptr2len_check)(line + col)) < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 outputlen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4285 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288 * syntax highlighting stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 if (psettings->do_syntax)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 id = syn_get_id(ppos->file_line, (long)col, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 if (id > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 id = syn_get_final_id(id);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 id = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 /* Get the line again, a multi-line regexp may invalidate it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 line = ml_get(ppos->file_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 if (id != current_syn_id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 current_syn_id = id;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303 prt_get_attr(id, &attr, psettings->modec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 prt_set_font(attr.bold, attr.italic, attr.underline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 prt_set_fg(attr.fg_color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 prt_set_bg(attr.bg_color);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 #endif /* FEAT_SYN_HL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 * Appropriately expand any tabs to spaces.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314 if (line[col] == TAB || tab_spaces != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 if (tab_spaces == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 tab_spaces = curbuf->b_p_ts - (print_pos % curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 while (tab_spaces > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 need_break = mch_print_text_out((char_u *)" ", 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 print_pos++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323 tab_spaces--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 if (need_break)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 /* Keep the TAB if we didn't finish it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 if (need_break && tab_spaces > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331 else if (line[col] == FF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 && printer_opts[OPT_PRINT_FORMFEED].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 && TOLOWER_ASC(printer_opts[OPT_PRINT_FORMFEED].string[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4334 == 'y')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 ppos->ff = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 need_break = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 need_break = mch_print_text_out(line + col, outputlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 print_pos += (*mb_ptr2cells)(line + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 print_pos++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 ppos->lead_spaces = tab_spaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 ppos->print_pos = print_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 * Start next line of file if we clip lines, or have reached end of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 * line, unless we are doing a formfeed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 if (!ppos->ff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 && (line[col] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 || (printer_opts[OPT_PRINT_WRAP].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 && TOLOWER_ASC(printer_opts[OPT_PRINT_WRAP].string[0])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 == 'n')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364 return col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4367 # if defined(FEAT_POSTSCRIPT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 * PS printer stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4372 * Sources of information to help maintain the PS printing code:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374 * 1. PostScript Language Reference, 3rd Edition,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 * Addison-Wesley, 1999, ISBN 0-201-37922-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4376 * 2. PostScript Language Program Design,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4377 * Addison-Wesley, 1988, ISBN 0-201-14396-8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4378 * 3. PostScript Tutorial and Cookbook,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 * Addison Wesley, 1985, ISBN 0-201-10179-3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 * 4. PostScript Language Document Structuring Conventions Specification,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381 * version 3.0,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 * Adobe Technote 5001, 25th September 1992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383 * 5. PostScript Printer Description File Format Specification, Version 4.3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 * Adobe technote 5003, 9th February 1996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385 * 6. Adobe Font Metrics File Format Specification, Version 4.1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386 * Adobe Technote 5007, 7th October 1998
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4387 * 7. Adobe CMap and CIDFont Files Specification, Version 1.0,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4388 * Adobe Technote 5014, 8th October 1996
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4389 * 8. Adobe CJKV Character Collections and CMaps for CID-Keyed Fonts,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4390 * Adoboe Technote 5094, 8th September, 2001
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4391 * 9. CJKV Information Processing, 2nd Edition,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4392 * O'Reilly, 2002, ISBN 1-56592-224-7
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 * Some of these documents can be found in PDF form on Adobe's web site -
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4395 * http://www.adobe.com
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4398 #define NUM_ELEMENTS(arr) (sizeof(arr)/sizeof((arr)[0]))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4399
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 #define PRT_PS_DEFAULT_DPI (72) /* Default user space resolution */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401 #define PRT_PS_DEFAULT_FONTSIZE (10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 #define PRT_PS_DEFAULT_BUFFER_SIZE (80)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 struct prt_mediasize_S
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407 float width; /* width and height in points for portrait */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 float height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 #define PRT_MEDIASIZE_LEN (sizeof(prt_mediasize) / sizeof(struct prt_mediasize_S))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 static struct prt_mediasize_S prt_mediasize[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 {"A4", 595.0, 842.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 {"letter", 612.0, 792.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 {"10x14", 720.0, 1008.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4418 {"A3", 842.0, 1191.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 {"A5", 420.0, 595.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 {"B4", 729.0, 1032.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421 {"B5", 516.0, 729.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 {"executive", 522.0, 756.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4423 {"folio", 595.0, 935.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424 {"ledger", 1224.0, 792.0}, /* Yes, it is wider than taller! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425 {"legal", 612.0, 1008.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 {"quarto", 610.0, 780.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427 {"statement", 396.0, 612.0},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 {"tabloid", 792.0, 1224.0}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4429 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 /* PS font names, must be in Roman, Bold, Italic, Bold-Italic order */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 struct prt_ps_font_S
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 int wx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 int uline_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436 int uline_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 int bbox_min_y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 int bbox_max_y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439 char *(ps_fontname[4]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 #define PRT_PS_FONT_ROMAN (0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 #define PRT_PS_FONT_BOLD (1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 #define PRT_PS_FONT_OBLIQUE (2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445 #define PRT_PS_FONT_BOLDOBLIQUE (3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4447 /* Standard font metrics for Courier family */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4448 static struct prt_ps_font_S prt_ps_courier_font =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4450 600,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4451 -100, 50,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4452 -250, 805,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4453 {"Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique"}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4454 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4456 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4457 /* Generic font metrics for multi-byte fonts */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4458 static struct prt_ps_font_S prt_ps_mb_font =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4459 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4460 1000,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4461 -100, 50,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4462 -250, 805,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4463 {NULL, NULL, NULL, NULL}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4464 };
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4465 #endif
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4466
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4467 /* Pointer to current font set being used */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4468 static struct prt_ps_font_S* prt_ps_font;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4469
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4470 /* Structures to map user named encoding and mapping to PS equivalents for
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4471 * building CID font name */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4472 struct prt_ps_encoding_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4473 {
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4474 char *encoding;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4475 char *cmap_encoding;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4476 int needs_charset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4477 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4478
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4479 struct prt_ps_charset_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4480 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4481 char *charset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4482 char *cmap_charset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4483 int has_charset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4484 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4485
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4486 #ifdef FEAT_MBYTE
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4487
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4488 #define CS_JIS_C_1978 (0x01)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4489 #define CS_JIS_X_1983 (0x02)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4490 #define CS_JIS_X_1990 (0x04)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4491 #define CS_NEC (0x08)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4492 #define CS_MSWINDOWS (0x10)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4493 #define CS_CP932 (0x20)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4494 #define CS_KANJITALK6 (0x40)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4495 #define CS_KANJITALK7 (0x80)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4496
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4497 /* Japanese encodings and charsets */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4498 static struct prt_ps_encoding_S j_encodings[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4499 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4500 {"iso-2022-jp", NULL, (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990|
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4501 CS_NEC)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4502 {"euc-jp", "EUC", (CS_JIS_C_1978|CS_JIS_X_1983|CS_JIS_X_1990)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4503 {"sjis", "RKSJ", (CS_JIS_C_1978|CS_JIS_X_1983|CS_MSWINDOWS|
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4504 CS_KANJITALK6|CS_KANJITALK7)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4505 {"cp932", "RKSJ", CS_JIS_X_1983},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4506 {"ucs-2", "UCS2", CS_JIS_X_1990},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4507 {"utf-8", "UTF8" , CS_JIS_X_1990}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4508 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4509 static struct prt_ps_charset_S j_charsets[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4510 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4511 {"JIS_C_1978", "78", CS_JIS_C_1978},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4512 {"JIS_X_1983", NULL, CS_JIS_X_1983},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4513 {"JIS_X_1990", "Hojo", CS_JIS_X_1990},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4514 {"NEC", "Ext", CS_NEC},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4515 {"MSWINDOWS", "90ms", CS_MSWINDOWS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4516 {"CP932", "90ms", CS_JIS_X_1983},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4517 {"KANJITALK6", "83pv", CS_KANJITALK6},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4518 {"KANJITALK7", "90pv", CS_KANJITALK7}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4519 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4520
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4521 #define CS_GB_2312_80 (0x01)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4522 #define CS_GBT_12345_90 (0x02)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4523 #define CS_GBK2K (0x04)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4524 #define CS_SC_MAC (0x08)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4525 #define CS_GBT_90_MAC (0x10)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4526 #define CS_GBK (0x20)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4527 #define CS_SC_ISO10646 (0x40)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4528
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4529 /* Simplified Chinese encodings and charsets */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4530 static struct prt_ps_encoding_S sc_encodings[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4531 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4532 {"iso-2022", NULL, (CS_GB_2312_80|CS_GBT_12345_90)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4533 {"gb18030", NULL, CS_GBK2K},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4534 {"euc-cn", "EUC", (CS_GB_2312_80|CS_GBT_12345_90|CS_SC_MAC|
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4535 CS_GBT_90_MAC)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4536 {"gbk", "EUC", CS_GBK},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4537 {"ucs-2", "UCS2", CS_SC_ISO10646},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4538 {"utf-8", "UTF8", CS_SC_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4539 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4540 static struct prt_ps_charset_S sc_charsets[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4541 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4542 {"GB_2312-80", "GB", CS_GB_2312_80},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4543 {"GBT_12345-90","GBT", CS_GBT_12345_90},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4544 {"MAC", "GBpc", CS_SC_MAC},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4545 {"GBT-90_MAC", "GBTpc", CS_GBT_90_MAC},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4546 {"GBK", "GBK", CS_GBK},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4547 {"GB18030", "GBK2K", CS_GBK2K},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4548 {"ISO10646", "UniGB", CS_SC_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4549 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4550
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4551 #define CS_CNS_PLANE_1 (0x01)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4552 #define CS_CNS_PLANE_2 (0x02)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4553 #define CS_CNS_PLANE_1_2 (0x04)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4554 #define CS_B5 (0x08)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4555 #define CS_ETEN (0x10)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4556 #define CS_HK_GCCS (0x20)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4557 #define CS_HK_SCS (0x40)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4558 #define CS_HK_SCS_ETEN (0x80)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4559 #define CS_MTHKL (0x100)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4560 #define CS_MTHKS (0x200)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4561 #define CS_DLHKL (0x400)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4562 #define CS_DLHKS (0x800)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4563 #define CS_TC_ISO10646 (0x1000)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4564
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4565 /* Traditional Chinese encodings and charsets */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4566 static struct prt_ps_encoding_S tc_encodings[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4567 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4568 {"iso-2022", NULL, (CS_CNS_PLANE_1|CS_CNS_PLANE_2)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4569 {"euc-tw", "EUC", CS_CNS_PLANE_1_2},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4570 {"big5", "B5", (CS_B5|CS_ETEN|CS_HK_GCCS|CS_HK_SCS|
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4571 CS_HK_SCS_ETEN|CS_MTHKL|CS_MTHKS|CS_DLHKL|
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4572 CS_DLHKS)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4573 {"cp950", "B5", CS_B5},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4574 {"ucs-2", "UCS2", CS_TC_ISO10646},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4575 {"utf-8", "UTF8", CS_TC_ISO10646},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4576 {"utf-16", "UTF16", CS_TC_ISO10646},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4577 {"utf-32", "UTF32", CS_TC_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4578 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4579 static struct prt_ps_charset_S tc_charsets[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4580 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4581 {"CNS_1992_1", "CNS1", CS_CNS_PLANE_1},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4582 {"CNS_1992_2", "CNS2", CS_CNS_PLANE_2},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4583 {"CNS_1993", "CNS", CS_CNS_PLANE_1_2},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4584 {"BIG5", NULL, CS_B5},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4585 {"CP950", NULL, CS_B5},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4586 {"ETEN", "ETen", CS_ETEN},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4587 {"HK_GCCS", "HKgccs", CS_HK_GCCS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4588 {"SCS", "HKscs", CS_HK_SCS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4589 {"SCS_ETEN", "ETHK", CS_HK_SCS_ETEN},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4590 {"MTHKL", "HKm471", CS_MTHKL},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4591 {"MTHKS", "HKm314", CS_MTHKS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4592 {"DLHKL", "HKdla", CS_DLHKL},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4593 {"DLHKS", "HKdlb", CS_DLHKS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4594 {"ISO10646", "UniCNS", CS_TC_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4595 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4596
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4597 #define CS_KR_X_1992 (0x01)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4598 #define CS_KR_MAC (0x02)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4599 #define CS_KR_X_1992_MS (0x04)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4600 #define CS_KR_ISO10646 (0x08)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4601
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4602 /* Korean encodings and charsets */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4603 static struct prt_ps_encoding_S k_encodings[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4604 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4605 {"iso-2022-kr", NULL, CS_KR_X_1992},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4606 {"euc-kr", "EUC", (CS_KR_X_1992|CS_KR_MAC)},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4607 {"johab", "Johab", CS_KR_X_1992},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4608 {"cp1361", "Johab", CS_KR_X_1992},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4609 {"uhc", "UHC", CS_KR_X_1992_MS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4610 {"cp949", "UHC", CS_KR_X_1992_MS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4611 {"ucs-2", "UCS2", CS_KR_ISO10646},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4612 {"utf-8", "UTF8", CS_KR_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4613 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4614 static struct prt_ps_charset_S k_charsets[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4615 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4616 {"KS_X_1992", "KSC", CS_KR_X_1992},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4617 {"CP1361", "KSC", CS_KR_X_1992},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4618 {"MAC", "KSCpc", CS_KR_MAC},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4619 {"MSWINDOWS", "KSCms", CS_KR_X_1992_MS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4620 {"CP949", "KSCms", CS_KR_X_1992_MS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4621 {"WANSUNG", "KSCms", CS_KR_X_1992_MS},
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4622 {"ISO10646", "UniKS", CS_KR_ISO10646}
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4623 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4624
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4625 /* Collections of encodings and charsets for multi-byte printing */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4626 struct prt_ps_mbfont_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4627 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4628 int num_encodings;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4629 struct prt_ps_encoding_S *encodings;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4630 int num_charsets;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4631 struct prt_ps_charset_S *charsets;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4632 char *ascii_enc;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4633 char *defcs;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4634 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4635
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4636 static struct prt_ps_mbfont_S prt_ps_mbfonts[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4637 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4638 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4639 NUM_ELEMENTS(j_encodings),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4640 j_encodings,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4641 NUM_ELEMENTS(j_charsets),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4642 j_charsets,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4643 "jis_roman",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4644 "JIS_X_1983"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4645 },
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4646 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4647 NUM_ELEMENTS(sc_encodings),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4648 sc_encodings,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4649 NUM_ELEMENTS(sc_charsets),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4650 sc_charsets,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4651 "gb_roman",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4652 "GB_2312-80"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4653 },
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4654 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4655 NUM_ELEMENTS(tc_encodings),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4656 tc_encodings,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4657 NUM_ELEMENTS(tc_charsets),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4658 tc_charsets,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4659 "cns_roman",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4660 "BIG5"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4661 },
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4662 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4663 NUM_ELEMENTS(k_encodings),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4664 k_encodings,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4665 NUM_ELEMENTS(k_charsets),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4666 k_charsets,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4667 "ks_roman",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4668 "KS_X_1992"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4669 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4670 };
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4671 #endif /* FEAT_MBYTE */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4672
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 struct prt_ps_resource_S
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 char_u name[64];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4676 char_u filename[MAXPATHL + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4678 char_u title[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 char_u version[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4680 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 /* Types of PS resource file currently used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683 #define PRT_RESOURCE_TYPE_PROCSET (0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 #define PRT_RESOURCE_TYPE_ENCODING (1)
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4685 #define PRT_RESOURCE_TYPE_CMAP (2)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 /* The PS prolog file version number has to match - if the prolog file is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 * updated, increment the number in the file and here. Version checking was
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689 * added as of VIM 6.2.
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4690 * The CID prolog file version number behaves as per PS prolog.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 * Table of VIM and prolog versions:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4692 *
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4693 * VIM Prolog CIDProlog
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 * 6.2 1.3
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4695 * 7.0 1.4 1.0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 */
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
4697 #define PRT_PROLOG_VERSION ((char_u *)"1.4")
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4698 #define PRT_CID_PROLOG_VERSION ((char_u *)"1.0")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4699
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4700 /* String versions of PS resource types - indexed by constants above so don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4701 * re-order!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4702 */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4703 static char *prt_resource_types[] =
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 "procset",
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4706 "encoding",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4707 "cmap"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4708 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 /* Strings to look for in a PS resource file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 #define PRT_RESOURCE_HEADER "%!PS-Adobe-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 #define PRT_RESOURCE_RESOURCE "Resource-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 #define PRT_RESOURCE_PROCSET "ProcSet"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 #define PRT_RESOURCE_ENCODING "Encoding"
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4715 #define PRT_RESOURCE_CMAP "CMap"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4716
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4717
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4718 /* Data for table based DSC comment recognition, easy to extend if VIM needs to
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4719 * read more comments. */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4720 #define PRT_DSC_MISC_TYPE (-1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4721 #define PRT_DSC_TITLE_TYPE (1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4722 #define PRT_DSC_VERSION_TYPE (2)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4723 #define PRT_DSC_ENDCOMMENTS_TYPE (3)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4724
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4725 #define PRT_DSC_TITLE "%%Title:"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4726 #define PRT_DSC_VERSION "%%Version:"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4727 #define PRT_DSC_ENDCOMMENTS "%%EndComments:"
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4728
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4729 struct prt_dsc_comment_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4730 {
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4731 char *string;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4732 int len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4733 int type;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4734 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4735
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4736 struct prt_dsc_line_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4737 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4738 int type;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4739 char_u *string;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4740 int len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4741 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4742
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4743
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4744 #define SIZEOF_CSTR(s) (sizeof(s) - 1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4745 struct prt_dsc_comment_S prt_dsc_table[] =
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4746 {
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4747 {PRT_DSC_TITLE, SIZEOF_CSTR(PRT_DSC_TITLE), PRT_DSC_TITLE_TYPE},
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4748 {PRT_DSC_VERSION, SIZEOF_CSTR(PRT_DSC_VERSION),
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4749 PRT_DSC_VERSION_TYPE},
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4750 {PRT_DSC_ENDCOMMENTS, SIZEOF_CSTR(PRT_DSC_ENDCOMMENTS),
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4751 PRT_DSC_ENDCOMMENTS_TYPE}
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4752 };
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754 static void prt_write_file_raw_len __ARGS((char_u *buffer, int bytes));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 static void prt_write_file __ARGS((char_u *buffer));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 static void prt_write_file_len __ARGS((char_u *buffer, int bytes));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 static void prt_write_string __ARGS((char *s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4758 static void prt_write_int __ARGS((int i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 static void prt_write_boolean __ARGS((int b));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760 static void prt_def_font __ARGS((char *new_name, char *encoding, int height, char *font));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 static void prt_real_bits __ARGS((double real, int precision, int *pinteger, int *pfraction));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 static void prt_write_real __ARGS((double val, int prec));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763 static void prt_def_var __ARGS((char *name, double value, int prec));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4764 static void prt_flush_buffer __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4765 static void prt_resource_name __ARGS((char_u *filename));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4766 static int prt_find_resource __ARGS((char *name, struct prt_ps_resource_S *resource));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4767 static int prt_open_resource __ARGS((struct prt_ps_resource_S *resource));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768 static int prt_check_resource __ARGS((struct prt_ps_resource_S *resource, char_u *version));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4769 static void prt_dsc_start __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 static void prt_dsc_noarg __ARGS((char *comment));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771 static void prt_dsc_textline __ARGS((char *comment, char *text));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4772 static void prt_dsc_text __ARGS((char *comment, char *text));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4773 static void prt_dsc_ints __ARGS((char *comment, int count, int *ints));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4774 static void prt_dsc_requirements __ARGS((int duplex, int tumble, int collate, int color, int num_copies));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 static void prt_dsc_docmedia __ARGS((char *paper_name, double width, double height, double weight, char *colour, char *type));
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4776 static void prt_dsc_resources __ARGS((char *comment, char *type, char *strings));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4777 static void prt_dsc_font_resource __ARGS((char *resource, struct prt_ps_font_S *ps_font));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 static float to_device_units __ARGS((int idx, double physsize, int def_number));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4779 static void prt_page_margins __ARGS((double width, double height, double *left, double *right, double *top, double *bottom));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 static void prt_font_metrics __ARGS((int font_scale));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 static int prt_get_cpl __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 static int prt_get_lpp __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 static int prt_add_resource __ARGS((struct prt_ps_resource_S *resource));
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4784 static int prt_resfile_next_line __ARGS((void));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4785 static int prt_resfile_strncmp __ARGS((int offset, char *string, int len));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4786 static int prt_resfile_skip_nonws __ARGS((int offset));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4787 static int prt_resfile_skip_ws __ARGS((int offset));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4788 static int prt_next_dsc __ARGS((struct prt_dsc_line_S *p_dsc_line));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4789 #ifdef FEAT_MBYTE
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
4790 static int prt_build_cid_fontname __ARGS((int font, char_u *name, int name_len));
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4791 static void prt_def_cidfont __ARGS((char *new_name, int height, char *cidfont));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4792 static int prt_match_encoding __ARGS((char *p_encoding, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_encoding_S **pp_mbenc));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4793 static int prt_match_charset __ARGS((char *p_charset, struct prt_ps_mbfont_S *p_cmap, struct prt_ps_charset_S **pp_mbchar));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4794 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 * Variables for the output PostScript file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 static FILE *prt_ps_fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 static int prt_file_error;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801 static char_u *prt_ps_file_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 * Various offsets and dimensions in default PostScript user space (points).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805 * Used for text positioning calculations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 static float prt_page_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 static float prt_page_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 static float prt_left_margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 static float prt_right_margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 static float prt_top_margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 static float prt_bottom_margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813 static float prt_line_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 static float prt_first_line_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815 static float prt_char_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 static float prt_number_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 static float prt_bgcol_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818 static float prt_pos_x_moveto = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4819 static float prt_pos_y_moveto = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4822 * Various control variables used to decide when and how to change the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 * PostScript graphics state.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4824 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 static int prt_need_moveto;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4826 static int prt_do_moveto;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827 static int prt_need_font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4828 static int prt_font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4829 static int prt_need_underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830 static int prt_underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4831 static int prt_do_underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4832 static int prt_need_fgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 static int prt_fgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4834 static int prt_need_bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4835 static int prt_do_bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836 static int prt_bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 static int prt_new_bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 static int prt_attribute_change;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4839 static float prt_text_run;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840 static int prt_page_num;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4841 static int prt_bufsiz;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844 * Variables controlling physical printing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846 static int prt_media;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4847 static int prt_portrait;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4848 static int prt_num_copies;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4849 static int prt_duplex;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850 static int prt_tumble;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4851 static int prt_collate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 * Buffers used when generating PostScript output
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 static char_u prt_line_buffer[257];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857 static garray_T prt_ps_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860 static int prt_do_conv;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 static vimconv_T prt_conv;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4862
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4863 static int prt_out_mbyte;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4864 static int prt_custom_cmap;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4865 static char prt_cmap[80];
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4866 static int prt_use_courier;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4867 static int prt_in_ascii;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4868 static int prt_half_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4869 static char *prt_ascii_encoding;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4870 static char_u prt_hexchar[] = "0123456789abcdef";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4871 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 prt_write_file_raw_len(buffer, bytes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 int bytes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 if (!prt_file_error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 && fwrite(buffer, sizeof(char_u), bytes, prt_ps_fd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 != (size_t)bytes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 EMSG(_("E455: Error writing to PostScript output file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 prt_file_error = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 prt_write_file(buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 prt_write_file_len(buffer, STRLEN(buffer));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 prt_write_file_len(buffer, bytes)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 int bytes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 ebcdic2ascii(buffer, bytes);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 prt_write_file_raw_len(buffer, bytes);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906 * Write a string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 prt_write_string(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 char *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 sprintf((char *)prt_line_buffer, "%s", s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917 * Write an int and a space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920 prt_write_int(i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4923 sprintf((char *)prt_line_buffer, "%d ", i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 * Write a boolean and a space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931 prt_write_boolean(b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 int b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 sprintf((char *)prt_line_buffer, "%s ", (b ? "T" : "F"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4937
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4938 /*
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4939 * Write PostScript to re-encode and define the font.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4940 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942 prt_def_font(new_name, encoding, height, font)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 char *new_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 char *encoding;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 int height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 char *font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 {
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4948 sprintf((char *)prt_line_buffer, "/_%s /VIM-%s /%s ref\n",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4949 new_name, encoding, font);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 prt_write_file(prt_line_buffer);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4951 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4952 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4953 sprintf((char *)prt_line_buffer, "/%s %d %f /_%s sffs\n",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4954 new_name, height, 500./prt_ps_courier_font.wx, new_name);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4955 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4956 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 sprintf((char *)prt_line_buffer, "/%s %d /_%s ffs\n",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 new_name, height, new_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4962 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4963 /*
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4964 * Write a line to define the CID font.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4965 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4966 static void
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4967 prt_def_cidfont(new_name, height, cidfont)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4968 char *new_name;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4969 int height;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4970 char *cidfont;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4971 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4972 sprintf((char *)prt_line_buffer, "/_%s /%s[/%s] vim_composefont\n",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4973 new_name, prt_cmap, cidfont);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4974 prt_write_file(prt_line_buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4975 sprintf((char *)prt_line_buffer, "/%s %d /_%s ffs\n", new_name, height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4976 new_name);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4977 prt_write_file(prt_line_buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4978 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4979
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4980 /*
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4981 * Write a line to define a duplicate of a CID font
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4982 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4983 static void
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4984 prt_dup_cidfont(original_name, new_name)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4985 char *original_name;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4986 char *new_name;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4987 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4988 sprintf((char *)prt_line_buffer, "/%s %s d\n", new_name, original_name);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4989 prt_write_file(prt_line_buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4990 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4991 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
4992
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 * Convert a real value into an integer and fractional part as integers, with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 * the fractional part being in the range [0,10^precision). The fractional part
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 * is also rounded based on the precision + 1'th fractional digit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 prt_real_bits(real, precision, pinteger, pfraction)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000 double real;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 int precision;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 int *pinteger;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 int *pfraction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 int integer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 float fraction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009 integer = (int)real;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010 fraction = (float)(real - integer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 if (real < (double)integer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012 fraction = -fraction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 for (i = 0; i < precision; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 fraction *= 10.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 *pinteger = integer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 *pfraction = (int)(fraction + 0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021 * Write a real and a space. Save bytes if real value has no fractional part!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 * We use prt_real_bits() as %f in sprintf uses the locale setting to decide
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 * what decimal point character to use, but PS always requires a '.'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 prt_write_real(val, prec)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 double val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 int prec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 int integer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031 int fraction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 prt_real_bits(val, prec, &integer, &fraction);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 /* Emit integer part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035 sprintf((char *)prt_line_buffer, "%d", integer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5037 /* Only emit fraction if necessary */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 if (fraction != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 /* Remove any trailing zeros */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 while ((fraction % 10) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043 prec--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044 fraction /= 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 /* Emit fraction left padded with zeros */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 sprintf((char *)prt_line_buffer, ".%0*d", prec, fraction);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 sprintf((char *)prt_line_buffer, " ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 * Write a line to define a numeric variable.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 prt_def_var(name, value, prec)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 double value;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 int prec;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063 sprintf((char *)prt_line_buffer, "/%s ", name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 prt_write_real(value, prec);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 sprintf((char *)prt_line_buffer, "d\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 /* Convert size from font space to user space at current font scale */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 #define PRT_PS_FONT_TO_USER(scale, size) ((size) * ((scale)/1000.0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5073 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5074 prt_flush_buffer()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5076 if (prt_ps_buffer.ga_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078 /* Any background color must be drawn first */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081 int r, g, b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 if (prt_do_moveto)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5085 prt_write_real(prt_pos_x_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5086 prt_write_real(prt_pos_y_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087 prt_write_string("m\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 prt_do_moveto = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 /* Size of rect of background color on which text is printed */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5092 prt_write_real(prt_text_run, 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 prt_write_real(prt_line_height, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 /* Lastly add the color of the background */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 r = ((unsigned)prt_new_bgcol & 0xff0000) >> 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 g = ((unsigned)prt_new_bgcol & 0xff00) >> 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 b = prt_new_bgcol & 0xff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 prt_write_real(r / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 prt_write_real(g / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 prt_write_real(b / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 prt_write_string("bg\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 /* Draw underlines before the text as it makes it slightly easier to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 * find the starting point.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107 if (prt_do_underline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 if (prt_do_moveto)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111 prt_write_real(prt_pos_x_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 prt_write_real(prt_pos_y_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 prt_write_string("m\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 prt_do_moveto = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5117 /* Underline length of text run */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5118 prt_write_real(prt_text_run, 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 prt_write_string("ul\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 /* Draw the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 * Note: we write text out raw - EBCDIC conversion is handled in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 * PostScript world via the font encoding vector. */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5124 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5125 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5126 prt_write_string("<");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5127 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5128 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5129 prt_write_string("(");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 prt_write_file_raw_len(prt_ps_buffer.ga_data, prt_ps_buffer.ga_len);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5131 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5132 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5133 prt_write_string(">");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5134 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5135 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5136 prt_write_string(")");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 /* Add a moveto if need be and use the appropriate show procedure */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 if (prt_do_moveto)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 prt_write_real(prt_pos_x_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141 prt_write_real(prt_pos_y_moveto, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142 /* moveto and a show */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5143 prt_write_string("ms\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 prt_do_moveto = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 else /* Simple show */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 prt_write_string("s\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 ga_clear(&prt_ps_buffer);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5150 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 static char_u *resource_filename;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 prt_resource_name(filename)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 char_u *filename;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 if (STRLEN(filename) >= MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 *resource_filename = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 STRCPY(resource_filename, filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 prt_find_resource(name, resource)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 struct prt_ps_resource_S *resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171 char_u buffer[MAXPATHL + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5173 STRCPY(resource->name, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 /* Look for named resource file in runtimepath */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 STRCPY(buffer, "print");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 add_pathsep(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 STRCAT(buffer, name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 STRCAT(buffer, ".ps");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5179 resource_filename = resource->filename;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 *resource_filename = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 return (do_in_runtimepath(buffer, FALSE, prt_resource_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 && resource->filename[0] != NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 /* PS CR and LF characters have platform independent values */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 #define PSLF (0x0a)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187 #define PSCR (0x0d)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5189 /* Static buffer to read initial comments in a resource file, some can have a
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5190 * couple of KB of comments! */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5191 #define PRT_FILE_BUFFER_LEN (2048)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5192 struct prt_resfile_buffer_S
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5193 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5194 char_u buffer[PRT_FILE_BUFFER_LEN];
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5195 int len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5196 int line_start;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5197 int line_end;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5198 };
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5199
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5200 static struct prt_resfile_buffer_S prt_resfile;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5201
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5202 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5203 prt_resfile_next_line()
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5204 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5205 int index;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5206
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5207 /* Move to start of next line and then find end of line */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5208 index = prt_resfile.line_end + 1;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5209 while (index < prt_resfile.len)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5210 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5211 if (prt_resfile.buffer[index] != PSLF && prt_resfile.buffer[index]
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5212 != PSCR)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5213 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5214 index++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5215 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5216 prt_resfile.line_start = index;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5217
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5218 while (index < prt_resfile.len)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5219 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5220 if (prt_resfile.buffer[index] == PSLF || prt_resfile.buffer[index]
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5221 == PSCR)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5222 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5223 index++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5224 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5225 prt_resfile.line_end = index;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5226
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5227 return (index < prt_resfile.len);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5228 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5229
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5230 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5231 prt_resfile_strncmp(offset, string, len)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5232 int offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5233 char *string;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5234 int len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5235 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5236 /* Force not equal if string is longer than remainder of line */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5237 if (len > (prt_resfile.line_end - (prt_resfile.line_start + offset)))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5238 return 1;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5239
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5240 return STRNCMP(&prt_resfile.buffer[prt_resfile.line_start + offset],
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5241 string, len);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5242 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5243
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5244 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5245 prt_resfile_skip_nonws(offset)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5246 int offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5247 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5248 int index;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5249
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5250 index = prt_resfile.line_start + offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5251 while (index < prt_resfile.line_end)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5252 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5253 if (isspace(prt_resfile.buffer[index]))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5254 return index - prt_resfile.line_start;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5255 index++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5256 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5257 return -1;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5258 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5259
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5260 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5261 prt_resfile_skip_ws(offset)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5262 int offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5263 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5264 int index;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5265
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5266 index = prt_resfile.line_start + offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5267 while (index < prt_resfile.line_end)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5268 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5269 if (!isspace(prt_resfile.buffer[index]))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5270 return index - prt_resfile.line_start;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5271 index++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5272 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5273 return -1;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5274 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5275
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5276 /* prt_next_dsc() - returns detail on next DSC comment line found. Returns true
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5277 * if a DSC comment is found, else false */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5278 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5279 prt_next_dsc(p_dsc_line)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5280 struct prt_dsc_line_S *p_dsc_line;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5281 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5282 int comment;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5283 int offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5284
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5285 /* Move to start of next line */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5286 if (!prt_resfile_next_line())
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5287 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5288
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5289 /* DSC comments always start %% */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5290 if (prt_resfile_strncmp(0, "%%", 2) != 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5291 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5292
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5293 /* Find type of DSC comment */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5294 for (comment = 0; comment < NUM_ELEMENTS(prt_dsc_table); comment++)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5295 if (prt_resfile_strncmp(0, prt_dsc_table[comment].string,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5296 prt_dsc_table[comment].len) == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5297 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5298
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5299 if (comment != NUM_ELEMENTS(prt_dsc_table))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5300 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5301 /* Return type of comment */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5302 p_dsc_line->type = prt_dsc_table[comment].type;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5303 offset = prt_dsc_table[comment].len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5304 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5305 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5306 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5307 /* Unrecognised DSC comment, skip to ws after comment leader */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5308 p_dsc_line->type = PRT_DSC_MISC_TYPE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5309 offset = prt_resfile_skip_nonws(0);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5310 if (offset == -1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5311 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5312 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5313
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5314 /* Skip ws to comment value */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5315 offset = prt_resfile_skip_ws(offset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5316 if (offset == -1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5317 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5318
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5319 p_dsc_line->string = &prt_resfile.buffer[prt_resfile.line_start + offset];
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5320 p_dsc_line->len = prt_resfile.line_end - (prt_resfile.line_start + offset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5321
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5322 return TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5323 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5324
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5325 /* Improved hand crafted parser to get the type, title, and version number of a
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5326 * PS resource file so the file details can be added to the DSC header comments.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5327 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 prt_open_resource(resource)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 struct prt_ps_resource_S *resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 {
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5332 int offset;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5333 int seen_all;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5334 int seen_title;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5335 int seen_version;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 FILE *fd_resource;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5337 struct prt_dsc_line_S dsc_line;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 fd_resource = mch_fopen((char *)resource->filename, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 if (fd_resource == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 EMSG2(_("E624: Can't open file \"%s\""), resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 }
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5345 vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 /* Parse first line to ensure valid resource file */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5348 prt_resfile.len = fread((char *)prt_resfile.buffer, sizeof(char_u),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5349 PRT_FILE_BUFFER_LEN, fd_resource);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 if (ferror(fd_resource))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 EMSG2(_("E457: Can't read PostScript resource file \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5358 prt_resfile.line_end = -1;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5359 prt_resfile.line_start = 0;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5360 if (!prt_resfile_next_line())
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5361 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5362
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5363 offset = 0;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5364
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5365 if (prt_resfile_strncmp(offset, PRT_RESOURCE_HEADER,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5366 STRLEN(PRT_RESOURCE_HEADER)) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 EMSG2(_("E618: file \"%s\" is not a PostScript resource file"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 /* Skip over any version numbers and following ws */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5375 offset += STRLEN(PRT_RESOURCE_HEADER);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5376 offset = prt_resfile_skip_nonws(offset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5377 if (offset == -1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5378 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5379 offset = prt_resfile_skip_ws(offset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5380 if (offset == -1)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5381 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5382
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5383 if (prt_resfile_strncmp(offset, PRT_RESOURCE_RESOURCE,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5384 STRLEN(PRT_RESOURCE_RESOURCE)) != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 }
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5391 offset += STRLEN(PRT_RESOURCE_RESOURCE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 /* Decide type of resource in the file */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5394 if (prt_resfile_strncmp(offset, PRT_RESOURCE_PROCSET,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5395 STRLEN(PRT_RESOURCE_PROCSET)) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 resource->type = PRT_RESOURCE_TYPE_PROCSET;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5397 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_ENCODING,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5398 STRLEN(PRT_RESOURCE_ENCODING)) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 resource->type = PRT_RESOURCE_TYPE_ENCODING;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5400 else if (prt_resfile_strncmp(offset, PRT_RESOURCE_CMAP,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5401 STRLEN(PRT_RESOURCE_CMAP)) == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5402 resource->type = PRT_RESOURCE_TYPE_CMAP;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5411 /* Look for title and version of resource */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5412 resource->title[0] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5413 resource->version[0] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5414 seen_title = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5415 seen_version = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5416 seen_all = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5417 while (!seen_all && prt_next_dsc(&dsc_line))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5418 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5419 switch (dsc_line.type)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5420 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5421 case PRT_DSC_TITLE_TYPE:
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5422 STRNCPY(resource->title, dsc_line.string, dsc_line.len);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5423 resource->title[dsc_line.len] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5424 seen_title = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5425 if (seen_version)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5426 seen_all = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5427 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5428
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5429 case PRT_DSC_VERSION_TYPE:
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5430 STRNCPY(resource->version, dsc_line.string, dsc_line.len);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5431 resource->version[dsc_line.len] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5432 seen_version = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5433 if (seen_title)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5434 seen_all = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5435 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5436
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5437 case PRT_DSC_ENDCOMMENTS_TYPE:
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5438 /* Wont find title or resource after this comment, stop searching */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5439 seen_all = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5440 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5441
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5442 case PRT_DSC_MISC_TYPE:
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5443 /* Not interested in whatever comment this line had */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5444 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5445 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5446 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5447
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5448 if (!seen_title || !seen_version)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 EMSG2(_("E619: file \"%s\" is not a supported PostScript resource file"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 prt_check_resource(resource, version)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 struct prt_ps_resource_S *resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 char_u *version;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 /* Version number m.n should match, the revision number does not matter */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 if (STRNCMP(resource->version, version, STRLEN(version)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 EMSG2(_("E621: \"%s\" resource file has wrong version"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 resource->name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 /* Other checks to be added as needed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 prt_dsc_start()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 prt_write_string("%!PS-Adobe-3.0\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 prt_dsc_noarg(comment)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 char *comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 sprintf((char *)prt_line_buffer, "%%%%%s\n", comment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 prt_dsc_textline(comment, text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 char *comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 char *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 sprintf((char *)prt_line_buffer, "%%%%%s: %s\n", comment, text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 prt_dsc_text(comment, text)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 char *comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 char *text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 /* TODO - should scan 'text' for any chars needing escaping! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 sprintf((char *)prt_line_buffer, "%%%%%s: (%s)\n", comment, text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 #define prt_dsc_atend(c) prt_dsc_text((c), "atend")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 prt_dsc_ints(comment, count, ints)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 char *comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 int *ints;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 sprintf((char *)prt_line_buffer, "%%%%%s:", comment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 for (i = 0; i < count; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 sprintf((char *)prt_line_buffer, " %d", ints[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 prt_write_string("\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 static void
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5534 prt_dsc_resources(comment, type, string)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 char *comment; /* if NULL add to previous */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 char *type;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5537 char *string;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5538 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 if (comment != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 sprintf((char *)prt_line_buffer, "%%%%%s: %s", comment, type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 sprintf((char *)prt_line_buffer, "%%%%+ %s", type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5545 sprintf((char *)prt_line_buffer, " %s\n", string);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5546 prt_write_file(prt_line_buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5547 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5548
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5549 static void
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5550 prt_dsc_font_resource(resource, ps_font)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5551 char *resource;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5552 struct prt_ps_font_S *ps_font;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5553 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5554 int i;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5555
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5556 prt_dsc_resources(resource, "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5557 ps_font->ps_fontname[PRT_PS_FONT_ROMAN]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5558 for (i = PRT_PS_FONT_BOLD ; i <= PRT_PS_FONT_BOLDOBLIQUE ; i++)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5559 if (ps_font->ps_fontname[i] != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5560 prt_dsc_resources(NULL, "font", ps_font->ps_fontname[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 prt_dsc_requirements(duplex, tumble, collate, color, num_copies)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 int duplex;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 int tumble;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 int collate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 int color;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 int num_copies;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 /* Only output the comment if we need to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 * Note: tumble is ignored if we are not duplexing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 if (!(duplex || collate || color || (num_copies > 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 sprintf((char *)prt_line_buffer, "%%%%Requirements:");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 if (duplex)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 prt_write_string(" duplex");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 if (tumble)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 prt_write_string("(tumble)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 if (collate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 prt_write_string(" collate");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 if (color)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 prt_write_string(" color");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 if (num_copies > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 prt_write_string(" numcopies(");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 /* Note: no space wanted so dont use prt_write_int() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 sprintf((char *)prt_line_buffer, "%d", num_copies);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 prt_write_string(")");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 prt_write_string("\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 prt_dsc_docmedia(paper_name, width, height, weight, colour, type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 char *paper_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5604 double width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 double height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606 double weight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 char *colour;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 char *type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 sprintf((char *)prt_line_buffer, "%%%%DocumentMedia: %s ", paper_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 prt_write_file(prt_line_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 prt_write_real(width, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 prt_write_real(height, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 prt_write_real(weight, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 if (colour == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 prt_write_string("()");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618 prt_write_string(colour);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 prt_write_string(" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 if (type == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 prt_write_string("()");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 prt_write_string(type);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 prt_write_string("\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628 mch_print_cleanup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5629 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5631 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5632 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5633 int i;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5634
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5635 /* Free off all CID font names created, but first clear duplicate
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5636 * pointers to the same string (when the same font is used for more than
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5637 * one style).
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5638 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5639 for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5640 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5641 if (prt_ps_mb_font.ps_fontname[i] != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5642 vim_free(prt_ps_mb_font.ps_fontname[i]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5643 prt_ps_mb_font.ps_fontname[i] = NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5644 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5645 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5646
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 if (prt_do_conv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 convert_setup(&prt_conv, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650 prt_do_conv = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 if (prt_ps_fd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 fclose(prt_ps_fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 prt_ps_fd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 prt_file_error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 if (prt_ps_file_name != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5661 vim_free(prt_ps_file_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5662 prt_ps_file_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5666 static float
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667 to_device_units(idx, physsize, def_number)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 double physsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5670 int def_number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 float ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 int u;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 int nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676 u = prt_get_unit(idx);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677 if (u == PRT_UNIT_NONE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 u = PRT_UNIT_PERC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 nr = def_number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683 nr = printer_opts[idx].number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5684
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5685 switch (u)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5687 case PRT_UNIT_INCH:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5688 ret = (float)(nr * PRT_PS_DEFAULT_DPI);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 case PRT_UNIT_MM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 ret = (float)(nr * PRT_PS_DEFAULT_DPI) / (float)25.4;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 case PRT_UNIT_POINT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694 ret = (float)nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 case PRT_UNIT_PERC:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698 ret = (float)(physsize * nr) / 100;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 return ret;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5705 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 * Calculate margins for given width and height from printoptions settings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 prt_page_margins(width, height, left, right, top, bottom)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5710 double width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5711 double height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 double *left;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 double *right;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714 double *top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715 double *bottom;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717 *left = to_device_units(OPT_PRINT_LEFT, width, 10);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5718 *right = width - to_device_units(OPT_PRINT_RIGHT, width, 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 *top = height - to_device_units(OPT_PRINT_TOP, height, 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 *bottom = to_device_units(OPT_PRINT_BOT, height, 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 prt_font_metrics(font_scale)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 int font_scale;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 prt_line_height = (float)font_scale;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5728 prt_char_width = (float)PRT_PS_FONT_TO_USER(font_scale, prt_ps_font->wx);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 prt_get_cpl()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5735 if (prt_use_number())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 prt_number_width = PRINT_NUMBER_WIDTH * prt_char_width;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5738 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5739 /* If we are outputting multi-byte characters then line numbers will be
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5740 * printed with half width characters
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5741 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5742 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5743 prt_number_width /= 2;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5744 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5745 prt_left_margin += prt_number_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 prt_number_width = 0.0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 return (int)((prt_right_margin - prt_left_margin) / prt_char_width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5753 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5754 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5755 prt_build_cid_fontname(font, name, name_len)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5756 int font;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5757 char_u *name;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5758 int name_len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5759 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5760 char *fontname;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5761
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5762 fontname = (char *)alloc(name_len + 1);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5763 if (fontname == NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5764 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5765 STRNCPY(fontname, name, name_len);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5766 fontname[name_len] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5767 prt_ps_mb_font.ps_fontname[font] = fontname;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5768
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5769 return TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5770 }
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5771 #endif
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5772
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774 * Get number of lines of text that fit on a page (excluding the header).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5777 prt_get_lpp()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5779 int lpp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5781 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 * Calculate offset to lower left corner of background rect based on actual
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 * font height (based on its bounding box) and the line height, handling the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 * case where the font height can exceed the line height.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 prt_bgcol_offset = (float)PRT_PS_FONT_TO_USER(prt_line_height,
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5787 prt_ps_font->bbox_min_y);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5788 if ((prt_ps_font->bbox_max_y - prt_ps_font->bbox_min_y) < 1000.0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 prt_bgcol_offset -= (float)PRT_PS_FONT_TO_USER(prt_line_height,
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5791 (1000.0 - (prt_ps_font->bbox_max_y -
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5792 prt_ps_font->bbox_min_y)) / 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795 /* Get height for topmost line based on background rect offset. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 prt_first_line_height = prt_line_height + prt_bgcol_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5798 /* Calculate lpp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5799 lpp = (int)((prt_top_margin - prt_bottom_margin) / prt_line_height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5800
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5801 /* Adjust top margin if there is a header */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802 prt_top_margin -= prt_line_height * prt_header_height();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 return lpp - prt_header_height();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5806
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5807 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5808 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5809 prt_match_encoding(p_encoding, p_cmap, pp_mbenc)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5810 char *p_encoding;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5811 struct prt_ps_mbfont_S *p_cmap;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5812 struct prt_ps_encoding_S **pp_mbenc;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5813 {
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5814 int mbenc;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5815 int enc_len;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5816 struct prt_ps_encoding_S *p_mbenc;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5817
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5818 *pp_mbenc = NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5819 /* Look for recognised encoding */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5820 enc_len = STRLEN(p_encoding);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5821 p_mbenc = p_cmap->encodings;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5822 for (mbenc = 0; mbenc < p_cmap->num_encodings; mbenc++)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5823 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5824 if (STRNICMP(p_mbenc->encoding, p_encoding, enc_len) == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5825 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5826 *pp_mbenc = p_mbenc;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5827 return TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5828 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5829 p_mbenc++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5830 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5831 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5832 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5833
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5834 static int
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5835 prt_match_charset(p_charset, p_cmap, pp_mbchar)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5836 char *p_charset;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5837 struct prt_ps_mbfont_S *p_cmap;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5838 struct prt_ps_charset_S **pp_mbchar;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5839 {
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5840 int mbchar;
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5841 int char_len;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5842 struct prt_ps_charset_S *p_mbchar;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5843
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5844 /* Look for recognised character set, using default if one is not given */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5845 if (*p_charset == NUL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5846 p_charset = p_cmap->defcs;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5847 char_len = STRLEN(p_charset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5848 p_mbchar = p_cmap->charsets;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5849 for (mbchar = 0; mbchar < p_cmap->num_charsets; mbchar++)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5850 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5851 if (STRNICMP(p_mbchar->charset, p_charset, char_len) == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5852 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5853 *pp_mbchar = p_mbchar;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5854 return TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5855 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5856 p_mbchar++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5857 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5858 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5859 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5860 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5861
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 mch_print_init(psettings, jobname, forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 char_u *jobname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 int forceit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870 char *paper_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 int paper_strlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 int fontsize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 double left;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 double right;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5876 double top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877 double bottom;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5878 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5879 int cmap;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5880 int pmcs_len;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5881 char_u *p_encoding;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5882 struct prt_ps_encoding_S *p_mbenc;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5883 struct prt_ps_encoding_S *p_mbenc_first;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5884 struct prt_ps_charset_S *p_mbchar;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5885 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 * TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 * If "forceit" is false: pop up a dialog to select:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891 * - printer name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892 * - copies
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 * - collated/uncollated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 * - duplex off/long side/short side
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 * - paper size
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 * - portrait/landscape
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897 * - font size
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5899 * If "forceit" is true: use the default printer and settings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5901 if (forceit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902 s_pd.Flags |= PD_RETURNDEFAULT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5903 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5905 /*
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5906 * Set up font and encoding.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5907 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5908 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5909 p_encoding = enc_skip(p_penc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5910 if (*p_encoding == NUL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5911 p_encoding = enc_skip(p_enc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5912
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5913 /* Look for recognised multi-byte coding, and if the charset is recognised.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5914 * This is to cope with the fact that various unicode encodings are
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5915 * supported in more than one of CJK. */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5916 p_mbenc = NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5917 p_mbenc_first = NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5918 p_mbchar = NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5919 for (cmap = 0; cmap < NUM_ELEMENTS(prt_ps_mbfonts); cmap++)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5920 if (prt_match_encoding((char *)p_encoding, &prt_ps_mbfonts[cmap],
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5921 &p_mbenc))
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5922 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5923 if (p_mbenc_first == NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5924 p_mbenc_first = p_mbenc;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5925 if (prt_match_charset((char *)p_pmcs, &prt_ps_mbfonts[cmap],
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
5926 &p_mbchar))
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5927 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5928 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5929
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5930 /* Use first encoding matched if no charset matched */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5931 if (p_mbchar == NULL && p_mbenc_first != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5932 p_mbenc = p_mbenc_first;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5933
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5934 prt_out_mbyte = (p_mbenc != NULL);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5935 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5936 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5937 /* Build CMap name - will be same for all multi-byte fonts used */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5938 prt_cmap[0] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5939
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5940 prt_custom_cmap = prt_out_mbyte && p_mbchar == NULL;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5941
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5942 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5943 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5944 /* Check encoding and character set are compatible */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5945 if ((p_mbenc->needs_charset&p_mbchar->has_charset) == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5946 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5947 EMSG(_("E673: Incompatible multi-byte encoding and character set."));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5948 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5949 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5950
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5951 /* Add charset name if not empty */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5952 if (p_mbchar->cmap_charset != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5953 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5954 STRCAT(prt_cmap, p_mbchar->cmap_charset);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5955 STRCAT(prt_cmap, "-");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5956 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5957 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5958 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5959 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5960 /* Add custom CMap character set name */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5961 pmcs_len = STRLEN(p_pmcs);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5962 if (pmcs_len == 0)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5963 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5964 EMSG(_("E674: printmbcharset cannot be empty with multi-byte encoding."));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5965 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5966 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5967 STRNCPY(prt_cmap, p_pmcs, STRLEN(p_pmcs));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5968 prt_cmap[pmcs_len] = '\0';
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5969 STRCAT(prt_cmap, "-");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5970 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5971
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5972 /* CMap name ends with (optional) encoding name and -H for horizontal */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5973 if (p_mbenc->cmap_encoding != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5974 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5975 STRCAT(prt_cmap, p_mbenc->cmap_encoding);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5976 STRCAT(prt_cmap, "-");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5977 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5978 STRCAT(prt_cmap, "H");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5979
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5980 if (!mbfont_opts[OPT_MBFONT_REGULAR].present)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5981 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5982 EMSG(_("E675: No default font specfifed for multi-byte printing."));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5983 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5984 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5985
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5986 /* Derive CID font names with fallbacks if not defined */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5987 if (!prt_build_cid_fontname(PRT_PS_FONT_ROMAN,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5988 mbfont_opts[OPT_MBFONT_REGULAR].string,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5989 mbfont_opts[OPT_MBFONT_REGULAR].strlen))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5990 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5991 if (mbfont_opts[OPT_MBFONT_BOLD].present)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5992 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLD,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5993 mbfont_opts[OPT_MBFONT_BOLD].string,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5994 mbfont_opts[OPT_MBFONT_BOLD].strlen))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5995 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5996 if (mbfont_opts[OPT_MBFONT_OBLIQUE].present)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5997 if (!prt_build_cid_fontname(PRT_PS_FONT_OBLIQUE,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5998 mbfont_opts[OPT_MBFONT_OBLIQUE].string,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
5999 mbfont_opts[OPT_MBFONT_OBLIQUE].strlen))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6000 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6001 if (mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].present)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6002 if (!prt_build_cid_fontname(PRT_PS_FONT_BOLDOBLIQUE,
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6003 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].string,
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6004 mbfont_opts[OPT_MBFONT_BOLDOBLIQUE].strlen))
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6005 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6006
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6007 /* Check if need to use Courier for ASCII code range, and if so pick up
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6008 * the encoding to use */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6009 prt_use_courier = mbfont_opts[OPT_MBFONT_USECOURIER].present &&
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6010 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_USECOURIER].string[0]) == 'y');
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6011 if (prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6012 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6013 /* Use national ASCII variant unless ASCII wanted */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6014 if (mbfont_opts[OPT_MBFONT_ASCII].present &&
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6015 (TOLOWER_ASC(mbfont_opts[OPT_MBFONT_ASCII].string[0]) == 'y'))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6016 prt_ascii_encoding = "ascii";
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6017 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6018 prt_ascii_encoding = prt_ps_mbfonts[cmap].ascii_enc;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6019 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6020
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6021 prt_ps_font = &prt_ps_mb_font;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6022 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6023 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6024 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6025 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6026 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6027 prt_use_courier = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6028 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6029 prt_ps_font = &prt_ps_courier_font;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6030 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6031
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6032 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 * Find the size of the paper and set the margins.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 prt_portrait = (!printer_opts[OPT_PRINT_PORTRAIT].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 || TOLOWER_ASC(printer_opts[OPT_PRINT_PORTRAIT].string[0]) == 'y');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 if (printer_opts[OPT_PRINT_PAPER].present)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039 paper_name = (char *)printer_opts[OPT_PRINT_PAPER].string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 paper_strlen = printer_opts[OPT_PRINT_PAPER].strlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 paper_name = "A4";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 paper_strlen = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 for (i = 0; i < PRT_MEDIASIZE_LEN; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 if (STRLEN(prt_mediasize[i].name) == (unsigned)paper_strlen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 && STRNICMP(prt_mediasize[i].name, paper_name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 paper_strlen) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 if (i == PRT_MEDIASIZE_LEN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 prt_media = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057 * Set PS pagesize based on media dimensions and print orientation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 * Note: Media and page sizes have defined meanings in PostScript and should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 * be kept distinct. Media is the paper (or transparency, or ...) that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 * printed on, whereas the page size is the area that the PostScript
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 * interpreter renders into.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063 if (prt_portrait)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6065 prt_page_width = prt_mediasize[i].width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066 prt_page_height = prt_mediasize[i].height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 prt_page_width = prt_mediasize[i].height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 prt_page_height = prt_mediasize[i].width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 * Set PS page margins based on the PS pagesize, not the mediasize - this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 * needs to be done before the cpl and lpp are calculated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 prt_page_margins(prt_page_width, prt_page_height, &left, &right, &top,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 &bottom);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 prt_left_margin = (float)left;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 prt_right_margin = (float)right;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 prt_top_margin = (float)top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 prt_bottom_margin = (float)bottom;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 * Set up the font size.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 fontsize = PRT_PS_DEFAULT_FONTSIZE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 for (p = p_pfn; (p = vim_strchr(p, ':')) != NULL; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 if (p[1] == 'h' && VIM_ISDIGIT(p[2]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 fontsize = atoi((char *)p + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 prt_font_metrics(fontsize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 * Return the number of characters per line, and lines per page for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 * generic print code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 psettings->chars_per_line = prt_get_cpl();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 psettings->lines_per_page = prt_get_lpp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 /* Catch margin settings that leave no space for output! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 if (psettings->chars_per_line <= 0 || psettings->lines_per_page <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 * Sort out the number of copies to be printed. PS by default will do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 * uncollated copies for you, so once we know how many uncollated copies are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 * wanted cache it away and lie to the generic code that we only want one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 * uncollated copy.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 psettings->n_collated_copies = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 psettings->n_uncollated_copies = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 prt_num_copies = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 prt_collate = (!printer_opts[OPT_PRINT_COLLATE].present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 || TOLOWER_ASC(printer_opts[OPT_PRINT_COLLATE].string[0]) == 'y');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 if (prt_collate)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 /* TODO: Get number of collated copies wanted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 psettings->n_collated_copies = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 /* TODO: Get number of uncollated copies wanted and update the cached
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 * count.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 prt_num_copies = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 psettings->jobname = jobname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 * Set up printer duplex and tumble based on Duplex option setting - default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 * is long sided duplex printing (i.e. no tumble).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 prt_duplex = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 prt_tumble = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 psettings->duplex = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 if (printer_opts[OPT_PRINT_DUPLEX].present)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "off", 3) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 prt_duplex = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 psettings->duplex = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 else if (STRNICMP(printer_opts[OPT_PRINT_DUPLEX].string, "short", 5)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147 prt_tumble = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 /* For now user abort not supported */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151 psettings->user_abort = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 /* If the user didn't specify a file name, use a temp file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 if (psettings->outfile == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6156 prt_ps_file_name = vim_tempname('p');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6157 if (prt_ps_file_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 EMSG(_(e_notmp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 prt_ps_fd = mch_fopen((char *)prt_ps_file_name, WRITEBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 p = expand_env_save(psettings->outfile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 prt_ps_fd = mch_fopen((char *)p, WRITEBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 if (prt_ps_fd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 EMSG(_("E324: Can't open PostScript output file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 mch_print_cleanup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6180 prt_bufsiz = psettings->chars_per_line;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6181 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6182 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6183 prt_bufsiz *= 2;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6184 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6185 ga_init2(&prt_ps_buffer, (int)sizeof(char), prt_bufsiz);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187 prt_page_num = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189 prt_attribute_change = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 prt_need_moveto = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 prt_need_font = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6192 prt_need_fgcol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 prt_need_bgcol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6194 prt_need_underline = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 prt_file_error = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 prt_add_resource(resource)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 struct prt_ps_resource_S *resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 FILE* fd_resource;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 char_u resource_buffer[512];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 size_t bytes_read;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 fd_resource = mch_fopen((char *)resource->filename, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 if (fd_resource == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 EMSG2(_("E456: Can't open file \"%s\""), resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 }
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6215 prt_dsc_resources("BeginResource", prt_resource_types[resource->type],
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6216 (char *)resource->title);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 prt_dsc_textline("BeginDocument", (char *)resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 bytes_read = fread((char *)resource_buffer, sizeof(char_u),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 sizeof(resource_buffer), fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 if (ferror(fd_resource))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 EMSG2(_("E457: Can't read PostScript resource file \"%s\""),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 resource->filename);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 if (bytes_read == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 prt_write_file_raw_len(resource_buffer, bytes_read);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 if (prt_file_error)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 fclose(fd_resource);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 prt_dsc_noarg("EndDocument");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 prt_dsc_noarg("EndResource");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 mch_print_begin(psettings)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 time_t now;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 int bbox[4];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6255 char *p_time;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 double left;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 double right;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 double top;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 double bottom;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 struct prt_ps_resource_S res_prolog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 struct prt_ps_resource_S res_encoding;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6262 char buffer[256];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263 char_u *p_encoding;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6265 struct prt_ps_resource_S res_cidfont;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6266 struct prt_ps_resource_S res_cmap;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6270 * PS DSC Header comments - no PS code!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6271 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6272 prt_dsc_start();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 prt_dsc_textline("Title", (char *)psettings->jobname);
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6274 if (!get_user_name((char_u *)buffer, 256))
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6275 STRCPY(buffer, "Unknown");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6276 prt_dsc_textline("For", buffer);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6277 prt_dsc_textline("Creator", VIM_VERSION_LONG);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6278 /* Note: to ensure Clean8bit I don't think we can use LC_TIME */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 now = time(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6280 p_time = ctime(&now);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6281 /* Note: ctime() adds a \n so we have to remove it :-( */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6282 *(vim_strchr((char_u *)p_time, '\n')) = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 prt_dsc_textline("CreationDate", p_time);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6284 prt_dsc_textline("DocumentData", "Clean8Bit");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6285 prt_dsc_textline("Orientation", "Portrait");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 prt_dsc_atend("Pages");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6287 prt_dsc_textline("PageOrder", "Ascend");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 /* The bbox does not change with orientation - it is always in the default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6289 * user coordinate system! We have to recalculate right and bottom
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 * coordinates based on the font metrics for the bbox to be accurate. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6291 prt_page_margins(prt_mediasize[prt_media].width,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 prt_mediasize[prt_media].height,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 &left, &right, &top, &bottom);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 bbox[0] = (int)left;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6295 if (prt_portrait)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297 /* In portrait printing the fixed point is the top left corner so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 * derive the bbox from that point. We have the expected cpl chars
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299 * across the media and lpp lines down the media.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6300 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6301 bbox[1] = (int)(top - (psettings->lines_per_page + prt_header_height())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6302 * prt_line_height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6303 bbox[2] = (int)(left + psettings->chars_per_line * prt_char_width
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6304 + 0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6305 bbox[3] = (int)(top + 0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309 /* In landscape printing the fixed point is the bottom left corner so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6310 * derive the bbox from that point. We have lpp chars across the media
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311 * and cpl lines up the media.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6312 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 bbox[1] = (int)bottom;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314 bbox[2] = (int)(left + ((psettings->lines_per_page
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 + prt_header_height()) * prt_line_height) + 0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 bbox[3] = (int)(bottom + psettings->chars_per_line * prt_char_width
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317 + 0.5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 prt_dsc_ints("BoundingBox", 4, bbox);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6320 /* The media width and height does not change with landscape printing! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6321 prt_dsc_docmedia(prt_mediasize[prt_media].name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6322 prt_mediasize[prt_media].width,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6323 prt_mediasize[prt_media].height,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6324 (double)0, NULL, NULL);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6325 /* Define fonts needed */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6326 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6327 if (!prt_out_mbyte || prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6328 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6329 prt_dsc_font_resource("DocumentNeededResources", &prt_ps_courier_font);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6330 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6331 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6332 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6333 prt_dsc_font_resource((prt_use_courier ? NULL
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6334 : "DocumentNeededResources"), &prt_ps_mb_font);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6335 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6336 prt_dsc_resources(NULL, "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6337 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6338 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6339
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6340 /* Search for external resources VIM supplies */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341 if (!prt_find_resource("prolog", &res_prolog))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 EMSG(_("E456: Can't find PostScript resource file \"prolog.ps\""));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346 if (!prt_open_resource(&res_prolog))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 if (!prt_check_resource(&res_prolog, PRT_PROLOG_VERSION))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349 return FALSE;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6350 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6351 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6352 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6353 /* Look for required version of multi-byte printing procset */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6354 if (!prt_find_resource("cidfont", &res_cidfont))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6355 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6356 EMSG(_("E456: Can't find PostScript resource file \"cidfont.ps\""));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6357 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6358 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6359 if (!prt_open_resource(&res_cidfont))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6360 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6361 if (!prt_check_resource(&res_cidfont, PRT_CID_PROLOG_VERSION))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6362 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6363 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6364 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6365
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 /* Find an encoding to use for printing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6367 * Check 'printencoding'. If not set or not found, then use 'encoding'. If
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6368 * that cannot be found then default to "latin1".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6369 * Note: VIM specific encoding header is always skipped.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6371 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6372 if (!prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6373 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6374 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6375 p_encoding = enc_skip(p_penc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6376 if (*p_encoding == NUL
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6377 || !prt_find_resource((char *)p_encoding, &res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6378 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6379 /* 'printencoding' not set or not supported - find alternate */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6381 int props;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6382
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6383 p_encoding = enc_skip(p_enc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6384 props = enc_canon_props(p_encoding);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6385 if (!(props & ENC_8BIT)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6386 || !prt_find_resource((char *)p_encoding, &res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6387 /* 8-bit 'encoding' is not supported */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6388 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6389 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6390 /* Use latin1 as default printing encoding */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6391 p_encoding = (char_u *)"latin1";
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6392 if (!prt_find_resource((char *)p_encoding, &res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6393 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6394 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6395 p_encoding);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6396 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6397 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6398 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6399 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6400 if (!prt_open_resource(&res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6401 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6402 /* For the moment there are no checks on encoding resource files to
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6403 * perform */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 #ifdef FEAT_MBYTE
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6405 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6406 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6407 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6408 p_encoding = enc_skip(p_penc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6409 if (*p_encoding == NUL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6410 p_encoding = enc_skip(p_enc);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6411 if (prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6412 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6413 /* Include ASCII range encoding vector */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6414 if (!prt_find_resource(prt_ascii_encoding, &res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6415 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6416 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6417 prt_ascii_encoding);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6418 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6419 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6420 if (!prt_open_resource(&res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6421 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6422 /* For the moment there are no checks on encoding resource files to
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6423 * perform */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6424 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6425 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6426
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6427 prt_conv.vc_type = CONV_NONE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6428 if (!(enc_canon_props(p_enc) & enc_canon_props(p_encoding) & ENC_8BIT)) {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6429 /* Set up encoding conversion if required */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430 if (FAIL == convert_setup(&prt_conv, p_enc, p_encoding))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 {
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6432 EMSG2(_("E620: Unable to convert to print encoding \"%s\""),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 p_encoding);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 prt_do_conv = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 }
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6438 prt_do_conv = prt_conv.vc_type != CONV_NONE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6439
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6440 if (prt_out_mbyte && prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6441 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6442 /* Find user supplied CMap */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6443 if (!prt_find_resource(prt_cmap, &res_cmap))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6444 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6445 EMSG2(_("E456: Can't find PostScript resource file \"%s.ps\""),
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6446 prt_cmap);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6447 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6448 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6449 if (!prt_open_resource(&res_cmap))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6450 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6451 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6452 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 /* List resources supplied */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 STRCPY(buffer, res_prolog.title);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 STRCAT(buffer, " ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 STRCAT(buffer, res_prolog.version);
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6458 prt_dsc_resources("DocumentSuppliedResources", "procset", buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6459 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6460 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6461 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6462 STRCPY(buffer, res_cidfont.title);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6463 STRCAT(buffer, " ");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6464 STRCAT(buffer, res_cidfont.version);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6465 prt_dsc_resources(NULL, "procset", buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6466
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6467 if (prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6468 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6469 STRCPY(buffer, res_cmap.title);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6470 STRCAT(buffer, " ");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6471 STRCAT(buffer, res_cmap.version);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6472 prt_dsc_resources(NULL, "cmap", buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6473 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6474 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6475 if (!prt_out_mbyte || prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6476 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6477 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6478 STRCPY(buffer, res_encoding.title);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6479 STRCAT(buffer, " ");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6480 STRCAT(buffer, res_encoding.version);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6481 prt_dsc_resources(NULL, "encoding", buffer);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6482 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 prt_dsc_requirements(prt_duplex, prt_tumble, prt_collate,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6484 #ifdef FEAT_SYN_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6485 psettings->do_syntax
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489 , prt_num_copies);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 prt_dsc_noarg("EndComments");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 * PS Document page defaults
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 prt_dsc_noarg("BeginDefaults");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 /* List font resources most likely common to all pages */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6498 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6499 if (!prt_out_mbyte || prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6500 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6501 prt_dsc_font_resource("PageResources", &prt_ps_courier_font);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6502 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6503 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6504 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6505 prt_dsc_font_resource((prt_use_courier ? NULL : "PageResources"),
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6506 &prt_ps_mb_font);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6507 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6508 prt_dsc_resources(NULL, "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6509 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6510 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6511
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512 /* Paper will be used for all pages */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 prt_dsc_textline("PageMedia", prt_mediasize[prt_media].name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6515 prt_dsc_noarg("EndDefaults");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6518 * PS Document prolog inclusion - all required procsets.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520 prt_dsc_noarg("BeginProlog");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6522 /* Add required procsets - NOTE: order is important! */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6523 if (!prt_add_resource(&res_prolog))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6524 return FALSE;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6525 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6526 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6527 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6528 /* Add CID font procset, and any user supplied CMap */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6529 if (!prt_add_resource(&res_cidfont))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6530 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6531 if (prt_custom_cmap && !prt_add_resource(&res_cmap))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6532 return FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6533 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6534 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6535
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6536 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6537 if (!prt_out_mbyte || prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6538 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6539 /* There will be only one Roman font encoding to be included in the PS
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6540 * file. */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6541 if (!prt_add_resource(&res_encoding))
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6542 return FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 prt_dsc_noarg("EndProlog");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 * PS Document setup - must appear after the prolog
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 prt_dsc_noarg("BeginSetup");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 /* Device setup - page size and number of uncollated copies */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 prt_write_int((int)prt_mediasize[prt_media].width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 prt_write_int((int)prt_mediasize[prt_media].height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 prt_write_int(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 prt_write_string("sps\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 prt_write_int(prt_num_copies);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 prt_write_string("nc\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 prt_write_boolean(prt_duplex);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 prt_write_boolean(prt_tumble);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 prt_write_string("dt\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 prt_write_boolean(prt_collate);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 prt_write_string("c\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564 /* Font resource inclusion and definition */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6565 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6566 if (!prt_out_mbyte || prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6567 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6568 /* When using Courier for ASCII range when printing multi-byte, need to
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6569 * pick up ASCII encoding to use with it. */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6570 if (prt_use_courier)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6571 p_encoding = (char_u *)prt_ascii_encoding;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6572 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6573 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6574 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6575 prt_def_font("F0", (char *)p_encoding, (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6576 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_ROMAN]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6577 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6578 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6579 prt_def_font("F1", (char *)p_encoding, (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6580 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLD]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6581 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6582 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6583 prt_def_font("F2", (char *)p_encoding, (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6584 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6585 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6586 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6587 prt_def_font("F3", (char *)p_encoding, (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6588 prt_ps_courier_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6589 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6590 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6591 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6592 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6593 /* Define the CID fonts to be used in the job. Typically CJKV fonts do
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6594 * not have an italic form being a western style, so where no font is
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6595 * defined for these faces VIM falls back to an existing face.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6596 * Note: if using Courier for the ASCII range then the printout will
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6597 * have bold/italic/bolditalic regardless of the setting of printmbfont.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6598 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6599 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6600 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6601 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6602 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6603 prt_def_cidfont("CF0", (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6604 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_ROMAN]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6605
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6606 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD] != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6607 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6608 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6609 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6610 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6611 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6612 prt_def_cidfont("CF1", (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6613 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLD]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6614 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6615 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6616 /* Use ROMAN for BOLD */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6617 prt_dup_cidfont("CF0", "CF1");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6618
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6619 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE] != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6620 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6621 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6622 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6623 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6624 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6625 prt_def_cidfont("CF2", (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6626 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_OBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6627 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6628 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6629 /* Use ROMAN for OBLIQUE */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6630 prt_dup_cidfont("CF0", "CF2");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6631
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6632 if (prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE] != NULL)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6633 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6634 prt_dsc_resources("IncludeResource", "font",
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6635 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6636 if (!prt_custom_cmap)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6637 prt_dsc_resources("IncludeResource", "cmap", prt_cmap);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6638 prt_def_cidfont("CF3", (int)prt_line_height,
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6639 prt_ps_mb_font.ps_fontname[PRT_PS_FONT_BOLDOBLIQUE]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6640 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6641 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6642 /* Use BOLD for BOLDOBLIQUE */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6643 prt_dup_cidfont("CF1", "CF3");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6644 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6645 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 /* Misc constant vars used for underlining and background rects */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 prt_def_var("UO", PRT_PS_FONT_TO_USER(prt_line_height,
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6649 prt_ps_font->uline_offset), 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650 prt_def_var("UW", PRT_PS_FONT_TO_USER(prt_line_height,
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6651 prt_ps_font->uline_width), 2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6652 prt_def_var("BO", prt_bgcol_offset, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 prt_dsc_noarg("EndSetup");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 /* Fail if any problems writing out to the PS file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657 return !prt_file_error;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 mch_print_end(psettings)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662 prt_settings_T *psettings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664 prt_dsc_noarg("Trailer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667 * Output any info we don't know in toto until we finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669 prt_dsc_ints("Pages", 1, &prt_page_num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 prt_dsc_noarg("EOF");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
6673 /* Write CTRL-D to close serial communication link if used.
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
6674 * NOTHING MUST BE WRITTEN AFTER THIS! */
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6675 prt_write_file((char_u *)IF_EB("\004", "\067"));
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
6676
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 if (!prt_file_error && psettings->outfile == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 && !got_int && !psettings->user_abort)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 /* Close the file first. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 if (prt_ps_fd != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683 fclose(prt_ps_fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 prt_ps_fd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 prt_message((char_u *)_("Sending to printer..."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 /* Not printing to a file: use 'printexpr' to print the file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689 if (eval_printexpr(prt_ps_file_name, psettings->arguments) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 EMSG(_("E365: Failed to print PostScript file"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6691 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6692 prt_message((char_u *)_("Print job sent."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 mch_print_cleanup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 mch_print_end_page()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 prt_flush_buffer();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 prt_write_string("re sp\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705 prt_dsc_noarg("PageTrailer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 return !prt_file_error;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6710 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 mch_print_begin_page(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 int page_num[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717 prt_page_num++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 page_num[0] = page_num[1] = prt_page_num;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 prt_dsc_ints("Page", 2, page_num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 prt_dsc_noarg("BeginPageSetup");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6724 prt_write_string("sv\n0 g\n");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6725 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6726 prt_in_ascii = !prt_out_mbyte;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6727 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6728 prt_write_string("CF0 sf\n");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6729 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6730 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6731 prt_write_string("F0 sf\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732 prt_fgcol = PRCOLOR_BLACK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733 prt_bgcol = PRCOLOR_WHITE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 prt_font = PRT_PS_FONT_ROMAN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6736 /* Set up page transformation for landscape printing. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6737 if (!prt_portrait)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 prt_write_int(-((int)prt_mediasize[prt_media].width));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 prt_write_string("sl\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 prt_dsc_noarg("EndPageSetup");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 /* We have reset the font attributes, force setting them again. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 curr_bg = (long_u)0xffffffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 curr_fg = (long_u)0xffffffff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 curr_bold = MAYBE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 return !prt_file_error;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 mch_print_blank_page()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 return (mch_print_begin_page(NULL) ? (mch_print_end_page()) : FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 static float prt_pos_x = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760 static float prt_pos_y = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 mch_print_start_line(margin, page_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 int margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 int page_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 prt_pos_x = prt_left_margin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 if (margin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 prt_pos_x -= prt_number_width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 prt_pos_y = prt_top_margin - prt_first_line_height -
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772 page_line * prt_line_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 prt_attribute_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6775 prt_need_moveto = TRUE;
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6776 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6777 prt_half_width = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6778 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6779 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6781 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6782 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6783 mch_print_text_out(p, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6784 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6785 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787 int need_break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 char_u ch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6789 char_u ch_buff[8];
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6790 float char_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6791 float next_pos;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6792 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6793 int in_ascii;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6794 int half_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6795 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6796
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6797 char_width = prt_char_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6798
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6799 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6800 /* Ideally VIM would create a rearranged CID font to combine a Roman and
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6801 * CJKV font to do what VIM is doing here - use a Roman font for characters
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6802 * in the ASCII range, and the origingal CID font for everything else.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6803 * The problem is that GhostScript still (as of 8.13) does not support
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6804 * rearranged fonts even though they have been documented by Adobe for 7
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6805 * years! If they ever do, a lot of this code will disappear.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6806 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6807 if (prt_use_courier)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6808 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6809 in_ascii = (len == 1 && *p < 0x80);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6810 if (prt_in_ascii)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6811 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6812 if (!in_ascii)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6813 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6814 /* No longer in ASCII range - need to switch font */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6815 prt_in_ascii = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6816 prt_need_font = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6817 prt_attribute_change = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6818 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6819 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6820 else if (in_ascii)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6821 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6822 /* Now in ASCII range - need to switch font */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6823 prt_in_ascii = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6824 prt_need_font = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6825 prt_attribute_change = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6826 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6827 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6828 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6829 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6830 half_width = ((*mb_ptr2cells)(p) == 1);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6831 if (half_width)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6832 char_width /= 2;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6833 if (prt_half_width)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6834 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6835 if (!half_width)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6836 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6837 prt_half_width = FALSE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6838 prt_pos_x += prt_char_width/4;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6839 prt_need_moveto = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6840 prt_attribute_change = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6841 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6842 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6843 else if (half_width)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6844 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6845 prt_half_width = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6846 prt_pos_x += prt_char_width/4;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6847 prt_need_moveto = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6848 prt_attribute_change = TRUE;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6849 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6850 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6851 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 /* Output any required changes to the graphics state, after flushing any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 * text buffered so far.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856 if (prt_attribute_change)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 prt_flush_buffer();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859 /* Reset count of number of chars that will be printed */
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6860 prt_text_run = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862 if (prt_need_moveto)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 prt_pos_x_moveto = prt_pos_x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865 prt_pos_y_moveto = prt_pos_y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6866 prt_do_moveto = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6867
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6868 prt_need_moveto = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 if (prt_need_font)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871 {
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6872 #ifdef FEAT_MBYTE
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6873 if (!prt_in_ascii)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6874 prt_write_string("CF");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6875 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6876 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6877 prt_write_string("F");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6878 prt_write_int(prt_font);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6879 prt_write_string("sf\n");
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6880 prt_need_font = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 if (prt_need_fgcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 int r, g, b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 r = ((unsigned)prt_fgcol & 0xff0000) >> 16;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 g = ((unsigned)prt_fgcol & 0xff00) >> 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 b = prt_fgcol & 0xff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889 prt_write_real(r / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 if (r == g && g == b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 prt_write_string("g\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894 prt_write_real(g / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6895 prt_write_real(b / 255.0, 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 prt_write_string("r\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898 prt_need_fgcol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901 if (prt_bgcol != PRCOLOR_WHITE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 prt_new_bgcol = prt_bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904 if (prt_need_bgcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905 prt_do_bgcol = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 prt_do_bgcol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909 prt_need_bgcol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911 if (prt_need_underline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 prt_do_underline = prt_underline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913 prt_need_underline = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915 prt_attribute_change = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 if (prt_do_conv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921 /* Convert from multi-byte to 8-bit encoding */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 p = string_convert(&prt_conv, p, &len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 p = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 }
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6926
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6927 if (prt_out_mbyte)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6928 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6929 /* Multi-byte character strings are represented more efficiently as hex
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6930 * strings when outputting clean 8 bit PS.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6931 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6932 do
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6933 {
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 16
diff changeset
6934 ch = prt_hexchar[(unsigned)(*p) >> 4];
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6935 ga_append(&prt_ps_buffer, ch);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6936 ch = prt_hexchar[(*p) & 0xf];
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6937 ga_append(&prt_ps_buffer, ch);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6938 p++;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6939 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6940 while (--len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 else
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6943 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6944 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6945 /* Add next character to buffer of characters to output.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6946 * Note: One printed character may require several PS characters to
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6947 * represent it, but we only count them as one printed character.
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6948 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6949 ch = *p;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6950 if (ch < 32 || ch == '(' || ch == ')' || ch == '\\')
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6951 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6952 /* Convert non-printing characters to either their escape or octal
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6953 * sequence, ensures PS sent over a serial line does not interfere
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6954 * with the comms protocol. Note: For EBCDIC we need to write out
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6955 * the escape sequences as ASCII codes!
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6956 * Note 2: Char codes < 32 are identical in EBCDIC and ASCII AFAIK!
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6957 */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6958 ga_append(&prt_ps_buffer, IF_EB('\\', 0134));
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6959 switch (ch)
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6960 {
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6961 case BS: ga_append(&prt_ps_buffer, IF_EB('b', 0142)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6962 case TAB: ga_append(&prt_ps_buffer, IF_EB('t', 0164)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6963 case NL: ga_append(&prt_ps_buffer, IF_EB('n', 0156)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6964 case FF: ga_append(&prt_ps_buffer, IF_EB('f', 0146)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6965 case CAR: ga_append(&prt_ps_buffer, IF_EB('r', 0162)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6966 case '(': ga_append(&prt_ps_buffer, IF_EB('(', 0050)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6967 case ')': ga_append(&prt_ps_buffer, IF_EB(')', 0051)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6968 case '\\': ga_append(&prt_ps_buffer, IF_EB('\\', 0134)); break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6969
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6970 default:
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6971 sprintf((char *)ch_buff, "%03o", (unsigned int)ch);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6972 #ifdef EBCDIC
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6973 ebcdic2ascii(ch_buff, 3);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6974 #endif
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6975 ga_append(&prt_ps_buffer, ch_buff[0]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6976 ga_append(&prt_ps_buffer, ch_buff[1]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6977 ga_append(&prt_ps_buffer, ch_buff[2]);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6978 break;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6979 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6980 }
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6981 else
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6982 ga_append(&prt_ps_buffer, ch);
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6983 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 /* Need to free any translated characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 if (prt_do_conv && (*p != NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990
15
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6991 prt_text_run += char_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6992 prt_pos_x += char_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6993
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6994 /* The downside of fp - use relative error on right margin check */
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6995 next_pos = prt_pos_x + prt_char_width;
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6996 need_break = (next_pos > prt_right_margin) &&
631143ac4a01 updated for version 7.0007
vimboss
parents: 14
diff changeset
6997 ((next_pos - prt_right_margin) > (prt_right_margin*1e-5));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 if (need_break)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 prt_flush_buffer();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 return need_break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006 mch_print_set_font(iBold, iItalic, iUnderline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 int iBold;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 int iItalic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009 int iUnderline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7011 int font = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7013 if (iBold)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7014 font |= 0x01;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7015 if (iItalic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7016 font |= 0x02;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7018 if (font != prt_font)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7019 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7020 prt_font = font;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7021 prt_attribute_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7022 prt_need_font = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7024 if (prt_underline != iUnderline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7026 prt_underline = iUnderline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7027 prt_attribute_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7028 prt_need_underline = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7029 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7030 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7032 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7033 mch_print_set_bg(bgcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7034 long_u bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7035 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7036 prt_bgcol = bgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7037 prt_attribute_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7038 prt_need_bgcol = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7040
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7041 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 mch_print_set_fg(fgcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 long_u fgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045 if (fgcol != (long_u)prt_fgcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7047 prt_fgcol = fgcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048 prt_attribute_change = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 prt_need_fgcol = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 # endif /*FEAT_POSTSCRIPT*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 #endif /*FEAT_PRINTER*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 && (defined(FEAT_EVAL) || defined(FEAT_MULTI_LANG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 static char *get_locale_val __ARGS((int what));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061 get_locale_val(what)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 int what;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 char *loc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066 /* Obtain the locale value from the libraries. For DJGPP this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067 * redefined and it doesn't use the arguments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 loc = setlocale(what, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7070 # if defined(__BORLANDC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071 if (loc != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075 /* Borland returns something like "LC_CTYPE=<name>\n"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 * Let's try to fix that bug here... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 p = vim_strchr(loc, '=');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7078 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7080 loc = ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081 while (*p != NUL) /* remove trailing newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 if (*p < ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7086 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 return loc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7096 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 * On MS-Windows locale names are strings like "German_Germany.1252", but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102 * gettext expects "de". Try to translate one into another here for a few
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 * supported languages.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7106 gettext_lang(char_u *name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 static char *(mtable[]) = {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110 "afrikaans", "af",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 "czech", "cs",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7112 "dutch", "nl",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 "german", "de",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 "english_united kingdom", "en_GB",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 "spanish", "es",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116 "french", "fr",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 "italian", "it",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118 "japanese", "ja",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 "korean", "ko",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120 "norwegian", "no",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 "polish", "pl",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 "russian", "ru",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 "slovak", "sk",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 "swedish", "sv",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 "ukrainian", "uk",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126 "chinese_china", "zh_CN",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 "chinese_taiwan", "zh_TW",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128 NULL};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 for (i = 0; mtable[i] != NULL; i += 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131 if (STRNICMP(mtable[i], name, STRLEN(mtable[i])) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 return mtable[i + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 * Obtain the current messages language. Used to set the default for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140 * 'helplang'. May return NULL or an empty string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 get_mess_lang()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147 # if (defined(HAVE_LOCALE_H) || defined(X_LOCALE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 # if defined(LC_MESSAGES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 p = (char_u *)get_locale_val(LC_MESSAGES);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 * may be set to the LCID number. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 p = (char_u *)get_locale_val(LC_ALL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 p = mch_getenv((char_u *)"LC_ALL");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 p = mch_getenv((char_u *)"LC_MESSAGES");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 p = mch_getenv((char_u *)"LANG");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7163 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7164 # ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7165 p = gettext_lang(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7166 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7167 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7168 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170
45
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7171 /* Complicated #if; matches with where get_mess_env() is used below. */
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7172 #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7173 && defined(LC_MESSAGES))) \
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7174 || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7175 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) \
e474bae3795f updated for version 7.0027
vimboss
parents: 41
diff changeset
7176 && !defined(LC_MESSAGES))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 static char_u *get_mess_env __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7180 * Get the language used for messages from the environment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7181 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 get_mess_env()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7185 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187 p = mch_getenv((char_u *)"LC_ALL");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 p = mch_getenv((char_u *)"LC_MESSAGES");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 p = mch_getenv((char_u *)"LANG");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7194 if (p != NULL && VIM_ISDIGIT(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 p = NULL; /* ignore something like "1043" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7196 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7197 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 p = (char_u *)get_locale_val(LC_CTYPE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7204 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 #if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 * Set the "v:lang" variable according to the current locale setting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210 * Also do "v:lc_time"and "v:ctype".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7213 set_lang_var()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215 char_u *loc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 loc = (char_u *)get_locale_val(LC_CTYPE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 /* setlocale() not supported: use the default value */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221 loc = (char_u *)"C";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 set_vim_var_string(VV_CTYPE, loc, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7226 * back to LC_CTYPE if it's empty. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7227 # if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) && defined(LC_MESSAGES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7228 loc = (char_u *)get_locale_val(LC_MESSAGES);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7229 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7230 loc = get_mess_env();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7231 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7232 set_vim_var_string(VV_LANG, loc, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235 loc = (char_u *)get_locale_val(LC_TIME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7236 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 set_vim_var_string(VV_LC_TIME, loc, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7241 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7242 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7243 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7244 * ":language": Set the language (locale).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7245 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7246 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 ex_language(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7250 char *loc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7251 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 int what = LC_ALL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 char *whatstr = "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7255 #ifdef LC_MESSAGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7256 # define VIM_LC_MESSAGES LC_MESSAGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7257 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7258 # define VIM_LC_MESSAGES 6789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 name = eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7263 /* Check for "messages {name}", "ctype {name}" or "time {name}" argument.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264 * Allow abbreviation, but require at least 3 characters to avoid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265 * confusion with a two letter language name "me" or "ct". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266 p = skiptowhite(eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 if ((*p == NUL || vim_iswhite(*p)) && p - eap->arg >= 3)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7268 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271 what = VIM_LC_MESSAGES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 name = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 whatstr = "messages ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277 what = LC_CTYPE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 name = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 whatstr = "ctype ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 what = LC_TIME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284 name = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 whatstr = "time ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 if (*name == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 #ifndef LC_MESSAGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292 if (what == VIM_LC_MESSAGES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7293 p = get_mess_env();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296 p = (char_u *)setlocale(what, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297 if (p == NULL || *p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298 p = (char_u *)"Unknown";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 smsg((char_u *)_("Current %slanguage: \"%s\""), whatstr, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7301 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7302 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303 #ifndef LC_MESSAGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304 if (what == VIM_LC_MESSAGES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 loc = "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308 loc = setlocale(what, (char *)name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 if (loc == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 EMSG2(_("E197: Cannot set language to \"%s\""), name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7311 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7313 #ifdef HAVE_NL_MSG_CAT_CNTR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314 /* Need to do this for GNU gettext, otherwise cached translations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7315 * will be used again. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 extern int _nl_msg_cat_cntr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7318 ++_nl_msg_cat_cntr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 /* Reset $LC_ALL, otherwise it would overrule everyting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 vim_setenv((char_u *)"LC_ALL", (char_u *)"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 if (what != LC_TIME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325 /* Tell gettext() what to translate to. It apparently doesn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 * use the currently effective locale. Also do this when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 * FEAT_GETTEXT isn't defined, so that shell commands use this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328 * value. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329 if (what == LC_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330 vim_setenv((char_u *)"LANG", name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 if (what != LC_CTYPE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333 char_u *mname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 mname = gettext_lang(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 mname = name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7338 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339 vim_setenv((char_u *)"LC_MESSAGES", mname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 #ifdef FEAT_MULTI_LANG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341 set_helplang_default(mname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345 /* Set $LC_CTYPE, because it overrules $LANG, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7346 * gtk_set_locale() calls setlocale() again. gnome_init()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7347 * sets $LC_CTYPE to "en_US" (that's a bug!). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 if (what != VIM_LC_MESSAGES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7349 vim_setenv((char_u *)"LC_CTYPE", name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7350 # ifdef FEAT_GUI_GTK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 /* Let GTK know what locale we're using. Not sure this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352 * really needed... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354 (void)gtk_set_locale();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 /* Set v:lang, v:lc_time and v:ctype to the final result. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360 set_lang_var();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366 # if defined(FEAT_CMDL_COMPL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368 * Function given to ExpandGeneric() to obtain the possible arguments of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 * ":language" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371 /*ARGSUSED*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 get_lang_arg(xp, idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 expand_T *xp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377 if (idx == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 return (char_u *)"messages";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 if (idx == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380 return (char_u *)"ctype";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381 if (idx == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382 return (char_u *)"time";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 #endif