annotate src/if_sniff.c @ 7662:4d34891e98f4 v7.4.1130

commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jan 18 20:30:17 2016 +0100 patch 7.4.1130 Problem: Memory leak in :vimgrep. Solution: Call FreeWild(). (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Mon, 18 Jan 2016 20:45:04 +0100
parents 2ebc20378f68
children 37c929c4a073
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 * if_sniff.c Interface between Vim and SNiFF+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 # include <stdio.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 # include <process.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 # include <string.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 # include <assert.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 # ifdef FEAT_GUI_X11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 # include "gui_x11.pro"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 # include "os_unixx.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 static int sniffemacs_pid;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 int fd_from_sniff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 int sniff_connected = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 int sniff_request_waiting = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 int want_sniff_request = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #define MAX_REQUEST_LEN 512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #define NEED_SYMBOL 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #define EMPTY_SYMBOL 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #define NEED_FILE 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 #define SILENT 16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #define DISCONNECT 32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 #define CONNECT 64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #define RQ_NONE 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 #define RQ_SIMPLE 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #define RQ_CONTEXT NEED_FILE + NEED_SYMBOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 #define RQ_SCONTEXT NEED_FILE + NEED_SYMBOL + EMPTY_SYMBOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 #define RQ_NOSYMBOL NEED_FILE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 #define RQ_SILENT RQ_NOSYMBOL + SILENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 #define RQ_CONNECT RQ_NONE + CONNECT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 #define RQ_DISCONNECT RQ_SIMPLE + DISCONNECT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 struct sn_cmd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 char *cmd_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 char cmd_code;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 char *cmd_msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 int cmd_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 struct sn_cmd_list
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 struct sn_cmd* sniff_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 struct sn_cmd_list* next_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 static struct sn_cmd sniff_cmds[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 { "toggle", 'e', N_("Toggle implementation/definition"),RQ_SCONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 { "superclass", 's', N_("Show base class of"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 { "overridden", 'm', N_("Show overridden member function"),RQ_SCONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 { "retrieve-file", 'r', N_("Retrieve from file"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 { "retrieve-project",'p', N_("Retrieve from project"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 { "retrieve-all-projects",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 'P', N_("Retrieve from all projects"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 { "retrieve-next", 'R', N_("Retrieve"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 { "goto-symbol", 'g', N_("Show source of"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 { "find-symbol", 'f', N_("Find symbol"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 { "browse-class", 'w', N_("Browse class"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 { "hierarchy", 't', N_("Show class in hierarchy"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 { "restr-hier", 'T', N_("Show class in restricted hierarchy"),RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 { "xref-to", 'x', N_("Xref refers to"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 { "xref-by", 'X', N_("Xref referred by"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 { "xref-has", 'c', N_("Xref has a"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 { "xref-used-by", 'C', N_("Xref used by"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 { "show-docu", 'd', N_("Show docu of"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 { "gen-docu", 'D', N_("Generate docu for"), RQ_CONTEXT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 { "connect", 'y', NULL, RQ_CONNECT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 { "disconnect", 'q', NULL, RQ_DISCONNECT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 { "font-info", 'z', NULL, RQ_SILENT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 { "update", 'u', NULL, RQ_SILENT },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 { NULL, '\0', NULL, 0}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 static char *SniffEmacs[2] = {"sniffemacs", (char *)NULL}; /* Yes, Emacs! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static int fd_to_sniff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static int sniff_will_disconnect = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 static char msg_sniff_disconnect[] = N_("Cannot connect to SNiFF+. Check environment (sniffemacs must be found in $PATH).\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 static char sniff_rq_sep[] = " ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 static struct sn_cmd_list *sniff_cmd_ext = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 /* Initializing vim commands
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 * executed each time vim connects to Sniff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 static char *init_cmds[]= {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 "augroup sniff",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 "autocmd BufWritePost * sniff update",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 "autocmd BufReadPost * sniff font-info",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 "autocmd VimLeave * sniff disconnect",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 "augroup END",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 "let g:sniff_connected = 1",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 "if ! exists('g:sniff_mappings_sourced')|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 "if ! exists('g:sniff_mappings')|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 "if exists('$SNIFF_DIR4')|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 "let g:sniff_mappings='$SNIFF_DIR4/config/integrations/vim/sniff.vim'|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 "else|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 "let g:sniff_mappings='$SNIFF_DIR/config/sniff.vim'|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 "endif|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 "endif|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 "let g:sniff_mappings=expand(g:sniff_mappings)|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 "if filereadable(g:sniff_mappings)|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 "execute 'source' g:sniff_mappings|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 "let g:sniff_mappings_sourced=1|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 "endif|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 "endif",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 /*-------- Function Prototypes ----------------------------------*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 static int ConnectToSniffEmacs __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 static void sniff_connect __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 static void HandleSniffRequest __ARGS((char* buffer));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 static int get_request __ARGS((int fd, char *buf, int maxlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 static void WriteToSniff __ARGS((char *str));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 static void SendRequest __ARGS((struct sn_cmd *command, char* symbol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 static void vi_msg __ARGS((char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static void vi_error_msg __ARGS((char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 static char *vi_symbol_under_cursor __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 static void vi_open_file __ARGS((char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 static char *vi_buffer_name __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 static buf_T *vi_find_buffer __ARGS((char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 static void vi_exec_cmd __ARGS((char *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 static void vi_set_cursor_pos __ARGS((long char_nr));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 static long vi_cursor_pos __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 /* debug trace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 #if 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 static FILE* _tracefile = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 #define SNIFF_TRACE_OPEN(file) if (!_tracefile) _tracefile = fopen(file, "w")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 #define SNIFF_TRACE(msg) fprintf(_tracefile, msg); fflush(_tracefile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 #define SNIFF_TRACE1(msg, arg) fprintf(_tracefile, msg,arg); fflush(_tracefile);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 #define SNIFF_TRACE_CLOSE fclose(_tracefile); _tracefile=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 #define SNIFF_TRACE_OPEN(file)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 #define SNIFF_TRACE(msg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 #define SNIFF_TRACE1(msg, arg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 #define SNIFF_TRACE_CLOSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 /*-------- Windows Only Declarations -----------------------------*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 static int sniff_request_processed=1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 static HANDLE sniffemacs_handle=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 static HANDLE readthread_handle=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static HANDLE handle_to_sniff=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 static HANDLE handle_from_sniff=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 struct sniffBufNode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 struct sniffBufNode *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 int bufLen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 char buf[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 static struct sniffBufNode *sniffBufStart=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 static struct sniffBufNode *sniffBufEnd=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 static HANDLE hBufferMutex=NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 # ifdef FEAT_GUI_W32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 extern HWND s_hwnd; /* gvim's Window handle */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 * some helper functions for Windows port only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 static HANDLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 ExecuteDetachedProgram(char *szBinary, char *szCmdLine,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 HANDLE hStdInput, HANDLE hStdOutput)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 BOOL bResult;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 DWORD nError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 PROCESS_INFORMATION aProcessInformation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 PROCESS_INFORMATION *pProcessInformation= &aProcessInformation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 STARTUPINFO aStartupInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 STARTUPINFO *pStartupInfo= &aStartupInfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 DWORD dwCreationFlags= 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 char szPath[512];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 HINSTANCE hResult;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 hResult = FindExecutable(szBinary, ".", szPath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 if ((int)hResult <= 32)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 /* can't find the exe file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 ZeroMemory(pStartupInfo, sizeof(*pStartupInfo));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 pStartupInfo->dwFlags= STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 pStartupInfo->hStdInput = hStdInput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 pStartupInfo->hStdOutput = hStdOutput;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 pStartupInfo->wShowWindow= SW_HIDE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 pStartupInfo->cb = sizeof(STARTUPINFO);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 bResult= CreateProcess(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 szPath,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 szCmdLine,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 NULL, /* security attr for process */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 NULL, /* security attr for primary thread */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 TRUE, /* DO inherit stdin and stdout */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 dwCreationFlags, /* creation flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 NULL, /* environment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 ".", /* current directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 pStartupInfo, /* startup info: NULL crashes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 pProcessInformation /* process information: NULL crashes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 nError= GetLastError();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 if (bResult)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 CloseHandle(pProcessInformation->hThread);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 CloseHandle(hStdInput);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 CloseHandle(hStdOutput);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 return(pProcessInformation->hProcess);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 return(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 * write to the internal Thread / Thread communications buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 * Return TRUE if successful, FALSE else.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 static BOOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 writeToBuffer(char *msg, int len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 DWORD dwWaitResult; /* Request ownership of mutex. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 struct sniffBufNode *bn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 int bnSize;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 SNIFF_TRACE1("writeToBuffer %d\n", len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 bnSize = sizeof(struct sniffBufNode) - MAX_REQUEST_LEN + len + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 if (bnSize < 128) bnSize = 128; /* minimum length to avoid fragmentation */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 bn = (struct sniffBufNode *)malloc(bnSize);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 if (!bn)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 memcpy(bn->buf, msg, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 bn->buf[len]='\0'; /* terminate CString for added safety */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 bn->next = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 bn->bufLen = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 /* now, acquire a Mutex for adding the string to our linked list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 dwWaitResult = WaitForSingleObject(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 hBufferMutex, /* handle of mutex */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 1000L); /* one-second time-out interval */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 if (dwWaitResult == WAIT_OBJECT_0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 /* The thread got mutex ownership. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (sniffBufEnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 sniffBufEnd->next = bn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 sniffBufEnd = bn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 sniffBufStart = sniffBufEnd = bn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 /* Release ownership of the mutex object. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 if (! ReleaseMutex(hBufferMutex))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 /* Deal with error. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 /* Cannot get mutex ownership due to time-out or mutex object abandoned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 free(bn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 return FALSE;
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 * read from the internal Thread / Thread communications buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 * Return TRUE if successful, FALSE else.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 ReadFromBuffer(char *buf, int maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 DWORD dwWaitResult; /* Request ownership of mutex. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 int theLen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 struct sniffBufNode *bn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 dwWaitResult = WaitForSingleObject(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 hBufferMutex, /* handle of mutex */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 1000L); /* one-second time-out interval */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 if (dwWaitResult == WAIT_OBJECT_0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 if (!sniffBufStart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 /* all pending Requests Processed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 theLen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 bn = sniffBufStart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 theLen = bn->bufLen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 SNIFF_TRACE1("ReadFromBuffer %d\n", theLen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 if (theLen >= maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 /* notify the user of buffer overflow? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 theLen = maxlen-1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 memcpy(buf, bn->buf, theLen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 buf[theLen] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 if (! (sniffBufStart = bn->next))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 sniffBufEnd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 sniff_request_processed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 free(bn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 if (! ReleaseMutex(hBufferMutex))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 /* Deal with error. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 return theLen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 /* Cannot get mutex ownership due to time-out or mutex object abandoned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 /* on Win32, a separate Thread reads the input pipe. get_request is not needed here. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 static void __cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 SniffEmacsReadThread(void *dummy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 static char ReadThreadBuffer[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 int ReadThreadLen=0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 int result=0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 int msgLen=0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 char *msgStart, *msgCur;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 SNIFF_TRACE("begin thread\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 /* Read from the pipe to SniffEmacs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 while (sniff_connected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 if (!ReadFile(handle_from_sniff,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 ReadThreadBuffer + ReadThreadLen, /* acknowledge rest in buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 MAX_REQUEST_LEN - ReadThreadLen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 &result,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 DWORD err = GetLastError();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 result = -1;
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 if (result < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 /* probably sniffemacs died... log the Error? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 sniff_disconnect(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 else if (result > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 ReadThreadLen += result-1; /* total length of valid chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 for(msgCur=msgStart=ReadThreadBuffer; ReadThreadLen > 0; msgCur++, ReadThreadLen--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 if (*msgCur == '\0' || *msgCur == '\r' || *msgCur == '\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 msgLen = msgCur-msgStart; /* don't add the CR/LF chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 if (msgLen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 writeToBuffer(msgStart, msgLen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 msgStart = msgCur + 1; /* over-read single CR/LF chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 /* move incomplete message to beginning of buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 ReadThreadLen = msgCur - msgStart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 if (ReadThreadLen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 mch_memmove(ReadThreadBuffer, msgStart, ReadThreadLen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 if (sniff_request_processed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 /* notify others that new data has arrived */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 sniff_request_processed = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 sniff_request_waiting = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 #ifdef FEAT_GUI_W32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 PostMessage(s_hwnd, WM_USER, (WPARAM)0, (LPARAM)0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 SNIFF_TRACE("end thread\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 #endif /* WIN32 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 /*-------- End of Windows Only Declarations ------------------------*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /* ProcessSniffRequests
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 * Function that should be called from outside
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 * to process the waiting sniff requests
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 ProcessSniffRequests()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 static char buf[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 while (sniff_connected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 len = ReadFromBuffer(buf, sizeof(buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 len = get_request(fd_from_sniff, buf, sizeof(buf));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 if (len < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 vi_error_msg(_("E274: Sniff: Error during read. Disconnected"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 sniff_disconnect(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 else if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 HandleSniffRequest( buf );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 if (sniff_will_disconnect) /* Now the last msg has been processed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 sniff_disconnect(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 static struct sn_cmd *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 find_sniff_cmd(cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 char *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 struct sn_cmd *sniff_cmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 for(i=0; sniff_cmds[i].cmd_name; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 if (!strcmp(cmd, sniff_cmds[i].cmd_name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 sniff_cmd = &sniff_cmds[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 if (!sniff_cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 struct sn_cmd_list *list = sniff_cmd_ext;
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
452 while (list)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 if (!strcmp(cmd, list->sniff_cmd->cmd_name))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 sniff_cmd = list->sniff_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 list = list->next_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 return sniff_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 add_sniff_cmd(cmd, def, msg)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 char *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 char *def;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 char *msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 int rc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 if (def != NULL && def[0] != NUL && find_sniff_cmd(cmd) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 struct sn_cmd_list *list = sniff_cmd_ext;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 struct sn_cmd *sniff_cmd = (struct sn_cmd*)malloc(sizeof(struct sn_cmd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 struct sn_cmd_list *cmd_node = (struct sn_cmd_list*)malloc(sizeof(struct sn_cmd_list));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 int rq_type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 /* unescape message text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 char *p = msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 char *end = p+strlen(msg);
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
482 while (*p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 if (*p == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 mch_memmove(p,p+1,end-p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 SNIFF_TRACE1("request name = %s\n",cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 SNIFF_TRACE1("request def = %s\n",def);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 SNIFF_TRACE1("request msg = %s\n",msg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
492 while (list && list->next_cmd)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 list = list->next_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 if (!list)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 sniff_cmd_ext = cmd_node;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 list->next_cmd = cmd_node;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 sniff_cmd->cmd_name = cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 sniff_cmd->cmd_code = def[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 sniff_cmd->cmd_msg = msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 switch(def[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 case 'f':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 rq_type = RQ_NOSYMBOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 case 's':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 rq_type = RQ_CONTEXT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 case 'S':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 rq_type = RQ_SCONTEXT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 rq_type = RQ_SIMPLE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 sniff_cmd->cmd_type = rq_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 cmd_node->sniff_cmd = sniff_cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 cmd_node->next_cmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 rc = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 return rc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 /* ex_sniff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 * Handle ":sniff" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 ex_sniff(eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 exarg_T *eap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 char_u *arg = eap->arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 char_u *symbol = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 char_u *cmd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 SNIFF_TRACE_OPEN("if_sniff.log");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 if (ends_excmd(*arg)) /* no request: print available commands */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 msg_start();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 msg_outtrans_attr((char_u *)"-- SNiFF+ commands --", hl_attr(HLF_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 for(i=0; sniff_cmds[i].cmd_name; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 msg_outtrans((char_u *)":sniff ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 msg_outtrans((char_u *)sniff_cmds[i].cmd_name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 msg_putchar('\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 msg_outtrans((char_u *)_("SNiFF+ is currently "));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 if (!sniff_connected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 msg_outtrans((char_u *)_("not "));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 msg_outtrans((char_u *)_("connected"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 else /* extract command name and symbol if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 symbol = skiptowhite(arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 cmd = vim_strnsave(arg, (int)(symbol-arg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 symbol = skipwhite(symbol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 if (ends_excmd(*symbol))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 symbol = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 if (!strcmp((char *)cmd, "addcmd"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 char_u *def = skiptowhite(symbol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 char_u *name = vim_strnsave(symbol, (int)(def-symbol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 char_u *msg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 def = skipwhite(def);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 msg = skiptowhite(def);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 def = vim_strnsave(def, (int)(msg-def));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 msg = skipwhite(msg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 if (ends_excmd(*msg))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 msg = vim_strsave(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 msg = vim_strnsave(msg, (int)(skiptowhite_esc(msg)-msg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 if (!add_sniff_cmd((char*)name, (char*)def, (char*)msg))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 vim_free(msg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 vim_free(def);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 vim_free(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 struct sn_cmd* sniff_cmd = find_sniff_cmd((char*)cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 if (sniff_cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 SendRequest(sniff_cmd, (char *)symbol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 EMSG2(_("E275: Unknown SNiFF+ request: %s"), cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 vim_free(cmd);
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 sniff_connect()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 if (sniff_connected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 if (ConnectToSniffEmacs())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 vi_error_msg(_("E276: Error connecting to SNiFF+"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 for (i = 0; init_cmds[i]; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 vi_exec_cmd(init_cmds[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 sniff_disconnect(immediately)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 int immediately;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 if (!sniff_connected)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 if (immediately)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 vi_exec_cmd("augroup sniff");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 vi_exec_cmd("au!");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 vi_exec_cmd("augroup END");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 vi_exec_cmd("unlet g:sniff_connected");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 sniff_connected = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 want_sniff_request = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 sniff_will_disconnect = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 gui_mch_wait_for_chars(0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 #ifdef WIN32
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
631 while (sniffBufStart != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 struct sniffBufNode *node = sniffBufStart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 sniffBufStart = sniffBufStart->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 free(node);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 sniffBufStart = sniffBufEnd = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 sniff_request_processed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 CloseHandle(handle_to_sniff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 CloseHandle(handle_from_sniff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 WaitForSingleObject(sniffemacs_handle, 1000L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 CloseHandle(sniffemacs_handle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 sniffemacs_handle = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 WaitForSingleObject(readthread_handle, 1000L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 readthread_handle = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 CloseHandle(hBufferMutex);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 hBufferMutex = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 SNIFF_TRACE_CLOSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 close(fd_to_sniff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 close(fd_from_sniff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 wait(NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 #ifdef WIN32
7049
2ebc20378f68 commit https://github.com/vim/vim/commit/80ce282107849ef1a0e9b8a3be26c59c211b0957
Christian Brabandt <cb@256bit.org>
parents: 3935
diff changeset
658 # if (defined(_MSC_VER) && _MSC_VER >= 1400)
2ebc20378f68 commit https://github.com/vim/vim/commit/80ce282107849ef1a0e9b8a3be26c59c211b0957
Christian Brabandt <cb@256bit.org>
parents: 3935
diff changeset
659 Sleep(2);
2ebc20378f68 commit https://github.com/vim/vim/commit/80ce282107849ef1a0e9b8a3be26c59c211b0957
Christian Brabandt <cb@256bit.org>
parents: 3935
diff changeset
660 # else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 _sleep(2);
7049
2ebc20378f68 commit https://github.com/vim/vim/commit/80ce282107849ef1a0e9b8a3be26c59c211b0957
Christian Brabandt <cb@256bit.org>
parents: 3935
diff changeset
662 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 if (!sniff_request_processed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 ProcessSniffRequests();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 sleep(2); /* Incoming msg could disturb edit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 sniff_will_disconnect = 1; /* We expect disconnect msg in 2 secs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 /* ConnectToSniffEmacs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 * Connect to Sniff: returns 1 on error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 ConnectToSniffEmacs()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 #ifdef WIN32 /* Windows Version of the Code */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 HANDLE ToSniffEmacs[2], FromSniffEmacs[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 SECURITY_ATTRIBUTES sa;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 sa.nLength = sizeof(sa);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 sa.lpSecurityDescriptor = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 sa.bInheritHandle = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 if (! CreatePipe(&ToSniffEmacs[0], &ToSniffEmacs[1], &sa, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 if (! CreatePipe(&FromSniffEmacs[0], &FromSniffEmacs[1], &sa, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 sniffemacs_handle = ExecuteDetachedProgram(SniffEmacs[0], SniffEmacs[0],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 ToSniffEmacs[0], FromSniffEmacs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 if (sniffemacs_handle)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 handle_to_sniff = ToSniffEmacs[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 handle_from_sniff = FromSniffEmacs[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 sniff_connected = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 hBufferMutex = CreateMutex(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 NULL, /* no security attributes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 FALSE, /* initially not owned */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 "SniffReadBufferMutex"); /* name of mutex */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 if (hBufferMutex == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 /* Check for error. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 readthread_handle = (HANDLE)_beginthread(SniffEmacsReadThread, 0, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 /* error in spawn() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 #else /* UNIX Version of the Code */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 int ToSniffEmacs[2], FromSniffEmacs[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719
1774
196d564759eb updated for version 7.2-072
vimboss
parents: 1743
diff changeset
720 if (pipe(ToSniffEmacs) != 0)
196d564759eb updated for version 7.2-072
vimboss
parents: 1743
diff changeset
721 return 1;
196d564759eb updated for version 7.2-072
vimboss
parents: 1743
diff changeset
722 if (pipe(FromSniffEmacs) != 0)
196d564759eb updated for version 7.2-072
vimboss
parents: 1743
diff changeset
723 return 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 /* fork */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 if ((sniffemacs_pid=fork()) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 /* child */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 /* prepare communication pipes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 close(ToSniffEmacs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 close(FromSniffEmacs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 dup2(ToSniffEmacs[0],fileno(stdin)); /* write to ToSniffEmacs[1] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 dup2(FromSniffEmacs[1],fileno(stdout));/* read from FromSniffEmacs[0] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 close(ToSniffEmacs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 close(FromSniffEmacs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 /* start sniffemacs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 execvp (SniffEmacs[0], SniffEmacs);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 /* FILE *out = fdopen(FromSniffEmacs[1], "w"); */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 sleep(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 fputs(_(msg_sniff_disconnect), stdout);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 fflush(stdout);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 sleep(3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 gui_exit(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 exit(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 else if (sniffemacs_pid > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 /* parent process */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 close(ToSniffEmacs[0]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 fd_to_sniff = ToSniffEmacs[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 close(FromSniffEmacs[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 fd_from_sniff = FromSniffEmacs[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 sniff_connected = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 else /* error in fork() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 #endif /* UNIX Version of the Code */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 /* HandleSniffRequest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 * Handle one request from SNiFF+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 HandleSniffRequest(buffer)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 char *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 char VICommand[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 char command;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 char *arguments;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 char *token;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 char *argv[3];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 int argc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 const char *SetTab = "set tabstop=%d";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 const char *SelectBuf = "buf %s";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 const char *DeleteBuf = "bd %s";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 const char *UnloadBuf = "bun %s";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 const char *GotoLine = "%d";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 command = buffer[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 arguments = &buffer[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 token = strtok(arguments, sniff_rq_sep);
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
796 while (argc <3)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 if (token)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 argv[argc] = (char*)vim_strsave((char_u *)token);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 token = strtok(0, sniff_rq_sep);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 argv[argc] = strdup("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 argc++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 switch (command)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 case 'o' : /* visit file at char pos */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 case 'O' : /* visit file at line number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 char *file = argv[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 int position = atoi(argv[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 buf = vi_find_buffer(file);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 setpcmark(); /* insert current pos in jump list [mark.c]*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 if (!buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 vi_open_file(file);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 else if (buf!=curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 {
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
822 vim_snprintf(VICommand, sizeof(VICommand),
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
823 (char *)SelectBuf, file);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 vi_exec_cmd(VICommand);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 if (command == 'o')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 vi_set_cursor_pos((long)position);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 {
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
830 vim_snprintf(VICommand, sizeof(VICommand),
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
831 (char *)GotoLine, (int)position);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 vi_exec_cmd(VICommand);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 checkpcmark(); /* [mark.c] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_W32)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 if (gui.in_use && !gui.in_focus) /* Raise Vim Window */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 # ifdef FEAT_GUI_W32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 SetForegroundWindow(s_hwnd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 extern Widget vimShell;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 XSetInputFocus(gui.dpy, XtWindow(vimShell), RevertToNone,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 CurrentTime);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 XRaiseWindow(gui.dpy, XtWindow(vimShell));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 case 'p' : /* path of file has changed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 /* when changing from shared to private WS (checkout) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 char *file = argv[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 char *new_path = argv[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 buf = vi_find_buffer(file);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 if (buf && !buf->b_changed) /* delete buffer only if not modified */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 {
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
860 vim_snprintf(VICommand, sizeof(VICommand),
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
861 (char *)DeleteBuf, file);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 vi_exec_cmd(VICommand);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 vi_open_file(new_path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 case 'w' : /* writability has changed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 /* Sniff sends request twice,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 * but only the last one is the right one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 char *file = argv[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 int writable = atoi(argv[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 buf = vi_find_buffer(file);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 if (buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 buf->b_p_ro = !writable;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 if (buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 buf->b_flags |= BF_CHECK_RO + BF_NEVERLOADED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 if (writable && !buf->b_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 {
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
883 vim_snprintf(VICommand, sizeof(VICommand),
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
884 (char *)UnloadBuf, file);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 vi_exec_cmd(VICommand);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 else if (writable && !buf->b_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 vi_exec_cmd("e");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 case 'h' : /* highlight info */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 break; /* not implemented */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 case 't' : /* Set tab width */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 int tab_width = atoi(argv[1]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 if (tab_width > 0 && tab_width <= 16)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 {
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
904 vim_snprintf(VICommand, sizeof(VICommand),
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
905 (char *)SetTab, tab_width);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 vi_exec_cmd(VICommand);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 case '|':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 /* change the request separator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 sniff_rq_sep[0] = arguments[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 /* echo the request */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 WriteToSniff(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 case 'A' : /* Warning/Info msg */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 vi_msg(arguments);
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
920 if (!strncmp(arguments, "Disconnected", 12))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 sniff_disconnect(1); /* unexpected disconnection */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 case 'a' : /* Error msg */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 vi_error_msg(arguments);
426
eaf8b83ac767 updated for version 7.0111
vimboss
parents: 272
diff changeset
925 if (!strncmp(arguments, "Cannot connect", 14))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 sniff_disconnect(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 default :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 }
3935
ee138f29259e updated for version 7.3.723
Bram Moolenaar <bram@vim.org>
parents: 2666
diff changeset
932 while (argc)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 vim_free(argv[--argc]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 #ifndef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 /* get_request
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 * read string from fd up to next newline (excluding the nl),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 * returns length of string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 * 0 if no data available or no complete line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 * <0 on error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 get_request(fd, buf, maxlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 int fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 char *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 int maxlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 static char inbuf[1024];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 static int pos = 0, bytes = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 #ifdef HAVE_SELECT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 struct timeval tval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 fd_set rfds;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 FD_ZERO(&rfds);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 FD_SET(fd, &rfds);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 tval.tv_sec = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 tval.tv_usec = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 struct pollfd fds;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 fds.fd = fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 fds.events = POLLIN;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 for (len = 0; len < maxlen; len++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 if (pos >= bytes) /* end of buffer reached? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 #ifdef HAVE_SELECT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 if (select(fd + 1, &rfds, NULL, NULL, &tval) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 #else
2577
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
975 if (poll(&fds, 1, 0) > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 #endif
2577
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
977 {
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
978 pos = 0;
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
979 bytes = read(fd, inbuf, sizeof(inbuf));
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
980 if (bytes <= 0)
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
981 return bytes;
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
982 }
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
983 else
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
984 {
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
985 pos = pos-len;
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
986 buf[0] = '\0';
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
987 return 0;
073ff46fe397 Fold Vim 7.2 default branch back to trunk to avoid two heads. (Tony
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
988 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 if ((buf[len] = inbuf[pos++]) =='\n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 buf[len] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 return len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 #endif /* WIN32 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 SendRequest(command, symbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 struct sn_cmd *command;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 char *symbol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 int cmd_type = command->cmd_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 static char cmdstr[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 static char msgtxt[MAX_REQUEST_LEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 char *buffer_name = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 if (cmd_type == RQ_CONNECT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 sniff_connect();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 if (!sniff_connected && !(cmd_type & SILENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 vi_error_msg(_("E278: SNiFF+ not connected"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 if (cmd_type & NEED_FILE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 if (!curbuf->b_sniff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 if (!(cmd_type & SILENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 vi_error_msg(_("E279: Not a SNiFF+ buffer"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 buffer_name = vi_buffer_name();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 if (buffer_name == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 if (cmd_type & NEED_SYMBOL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 if (cmd_type & EMPTY_SYMBOL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 symbol = " ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 else if (!symbol && !(symbol = vi_symbol_under_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 return; /* error msg already displayed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 if (symbol)
272
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
1040 vim_snprintf(cmdstr, sizeof(cmdstr), "%c%s%s%ld%s%s\n",
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 command->cmd_code,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 buffer_name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 sniff_rq_sep,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 vi_cursor_pos(),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 sniff_rq_sep,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 symbol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 else
272
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
1049 vim_snprintf(cmdstr, sizeof(cmdstr), "%c%s\n",
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
1050 command->cmd_code, buffer_name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 else /* simple request */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 cmdstr[0] = command->cmd_code;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 cmdstr[1] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 cmdstr[2] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 if (command->cmd_msg && !(cmd_type & SILENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 if ((cmd_type & NEED_SYMBOL) && !(cmd_type & EMPTY_SYMBOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 {
272
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
1062 vim_snprintf(msgtxt, sizeof(msgtxt), "%s: %s",
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
1063 _(command->cmd_msg), symbol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 vi_msg(msgtxt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 vi_msg(_(command->cmd_msg));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 WriteToSniff(cmdstr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 if (cmd_type & DISCONNECT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 sniff_disconnect(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 WriteToSniff(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 char *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 int bytes;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 #ifdef WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 if (! WriteFile(handle_to_sniff, str, strlen(str), &bytes, NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 DWORD err=GetLastError();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 bytes = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 bytes = write(fd_to_sniff, str, strlen(str));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 if (bytes<0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 vi_msg(_("Sniff: Error during write. Disconnected"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 sniff_disconnect(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 /*-------- vim helping functions --------------------------------*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 vi_msg(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 char *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 if (str != NULL && *str != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 MSG((char_u *)str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 vi_error_msg(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 char *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 if (str != NULL && *str != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 EMSG((char_u *)str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 vi_open_file(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 char *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 ++no_wait_return;
1743
734d5bdae499 updated for version 7.2-041
vimboss
parents: 1619
diff changeset
1120 do_ecmd(0, (char_u *)fname, NULL, NULL, ECMD_ONE, ECMD_HIDE+ECMD_OLDBUF,
734d5bdae499 updated for version 7.2-041
vimboss
parents: 1619
diff changeset
1121 curwin);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 curbuf->b_sniff = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 --no_wait_return; /* [ex_docmd.c] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 static buf_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 vi_find_buffer(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 char *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 { /* derived from buflist_findname() [buffer.c] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 if (buf->b_sfname != NULL && fnamecmp(fname, buf->b_sfname) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 return (buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 vi_symbol_under_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 char *symbolp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 static char sniff_symbol[256];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 len = find_ident_under_cursor((char_u **)&symbolp, FIND_IDENT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 /* [normal.c] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 if (len <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 for (p=sniff_symbol; len; len--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 *p++ = *symbolp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 *p = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 return sniff_symbol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 static char *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 vi_buffer_name()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 return (char *)curbuf->b_sfname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 vi_exec_cmd(vicmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 char *vicmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 do_cmdline_cmd((char_u *)vicmd); /* [ex_docmd.c] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 }
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 * Set cursor on character position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 * derived from cursor_pos_info() [buffer.c]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 vi_set_cursor_pos(char_pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 long char_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 long char_count = 1; /* first position = 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 int line_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 int eol_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 if (char_pos == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 char_pos = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 if (get_fileformat(curbuf) == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 eol_size = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 eol_size = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 line_size = STRLEN(ml_get(lnum)) + eol_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 if (char_count+line_size > char_pos) break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 char_count += line_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 curwin->w_cursor.col = char_pos - char_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 static long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 vi_cursor_pos()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 long char_count=1; /* sniff starts with pos 1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 int line_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 int eol_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 if (curbuf->b_p_tx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 eol_size = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 eol_size = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 for (lnum = 1; lnum < curwin->w_cursor.lnum; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 line_size = STRLEN(ml_get(lnum)) + eol_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 char_count += line_size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 return char_count + curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 }