annotate src/if_sniff.c @ 1897:044d5e9b1292 v7.2.194

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