Commit 516bb4093dfdd43533b56ac85b9188871bd62826
1 parent
a7591578
Exists in
master
Melhorando objeto C#
Showing
4 changed files
with
39 additions
and
5 deletions
Show diff stats
src/native/private.h
@@ -100,6 +100,7 @@ | @@ -100,6 +100,7 @@ | ||
100 | DLL_PUBLIC int tn3270_get_program_message(h3270::session *ses); | 100 | DLL_PUBLIC int tn3270_get_program_message(h3270::session *ses); |
101 | DLL_PUBLIC int tn3270_get_secure(h3270::session *ses); | 101 | DLL_PUBLIC int tn3270_get_secure(h3270::session *ses); |
102 | 102 | ||
103 | + DLL_PUBLIC int tn3270_get_contents(h3270::session *ses, char* str, int strlen); | ||
103 | DLL_PUBLIC int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen); | 104 | DLL_PUBLIC int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen); |
104 | DLL_PUBLIC int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int strlen); | 105 | DLL_PUBLIC int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int strlen); |
105 | 106 |
src/native/screen.cc
@@ -31,6 +31,21 @@ | @@ -31,6 +31,21 @@ | ||
31 | 31 | ||
32 | /*---[ Implement ]----------------------------------------------------------------------------------*/ | 32 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
33 | 33 | ||
34 | +int tn3270_get_contents(h3270::session *ses, char* str, int sz) { | ||
35 | + | ||
36 | + std::string contents = ses->get_contents(); | ||
37 | + | ||
38 | + memset(str,0,sz); | ||
39 | + strncpy(str,contents.c_str(),sz); | ||
40 | + if(contents.size() < ((size_t) sz)) { | ||
41 | + str[contents.size()] = 0; | ||
42 | + return contents.size(); | ||
43 | + } | ||
44 | + | ||
45 | + return sz; | ||
46 | + | ||
47 | +} | ||
48 | + | ||
34 | int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { | 49 | int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { |
35 | memset(str,0,strlen); | 50 | memset(str,0,strlen); |
36 | strncpy(str,ses->get_string(addr,strlen).c_str(),strlen); | 51 | strncpy(str,ses->get_string(addr,strlen).c_str(),strlen); |
@@ -38,10 +53,8 @@ int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { | @@ -38,10 +53,8 @@ int tn3270_get_string(h3270::session *ses, int addr, char* str, int strlen) { | ||
38 | } | 53 | } |
39 | 54 | ||
40 | int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int sz) { | 55 | int tn3270_get_string_at(h3270::session *ses, int row, int col, char* str, int sz) { |
41 | - memset(str,0,sz); | 56 | + memset(str,0,sz+1); |
42 | strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz); | 57 | strncpy(str,ses->get_string_at(row,col,sz).c_str(),sz); |
43 | - str[sz] = 0; | ||
44 | - debug("%s(%d,%d) len=%u (Required=%d)\n",__FUNCTION__,row,col,(unsigned int) strlen(str), sz); | ||
45 | return (int) strlen(str); | 58 | return (int) strlen(str); |
46 | } | 59 | } |
47 | 60 |
src/pw3270-sharp/pw3270-sharp.cs
@@ -87,6 +87,9 @@ namespace pw3270 { | @@ -87,6 +87,9 @@ namespace pw3270 { | ||
87 | extern static int tn3270_get_secure(IntPtr Session); | 87 | extern static int tn3270_get_secure(IntPtr Session); |
88 | 88 | ||
89 | [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] | 89 | [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] |
90 | + extern static int tn3270_get_contents(IntPtr Session, StringBuilder str, int strlen); | ||
91 | + | ||
92 | + [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] | ||
90 | extern static int tn3270_get_string(IntPtr Session, int addr, StringBuilder str, int strlen); | 93 | extern static int tn3270_get_string(IntPtr Session, int addr, StringBuilder str, int strlen); |
91 | 94 | ||
92 | [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] | 95 | [DllImport ("lib3270-mono",CallingConvention=CallingConvention.Cdecl)] |
@@ -275,6 +278,22 @@ namespace pw3270 { | @@ -275,6 +278,22 @@ namespace pw3270 { | ||
275 | } | 278 | } |
276 | 279 | ||
277 | /// <summary> | 280 | /// <summary> |
281 | + /// Get contents | ||
282 | + /// </summary> | ||
283 | + /// | ||
284 | + /// <returns> | ||
285 | + /// Contents from terminal screen. | ||
286 | + /// </returns> | ||
287 | + /// | ||
288 | + public override string ToString() { | ||
289 | + int strlen = (tn3270_get_width(hSession)+1) * (tn3270_get_height(hSession)+1); | ||
290 | + StringBuilder str = new StringBuilder(strlen+1); | ||
291 | + strlen = tn3270_get_contents(hSession, str, strlen); | ||
292 | + return str.ToString(); | ||
293 | + } | ||
294 | + | ||
295 | + | ||
296 | + /// <summary> | ||
278 | /// Get contents at address | 297 | /// Get contents at address |
279 | /// </summary> | 298 | /// </summary> |
280 | /// | 299 | /// |
@@ -288,7 +307,7 @@ namespace pw3270 { | @@ -288,7 +307,7 @@ namespace pw3270 { | ||
288 | public string GetString(int addr, int strlen) { | 307 | public string GetString(int addr, int strlen) { |
289 | StringBuilder str = new StringBuilder(strlen+1); | 308 | StringBuilder str = new StringBuilder(strlen+1); |
290 | tn3270_get_string(hSession, addr, str, strlen); | 309 | tn3270_get_string(hSession, addr, str, strlen); |
291 | - return str.ToString(0,strlen); | 310 | + return str.ToString(); |
292 | } | 311 | } |
293 | 312 | ||
294 | /// <summary> | 313 | /// <summary> |
testprograms/sample.cs
@@ -38,6 +38,7 @@ class sample { | @@ -38,6 +38,7 @@ class sample { | ||
38 | System.Console.WriteLine("Using pw3270 version " + host.Version + " revision " + host.Revision); | 38 | System.Console.WriteLine("Using pw3270 version " + host.Version + " revision " + host.Revision); |
39 | System.Console.WriteLine("Screen size is " + host.Width + "x" + host.Height + " (" + host.Length + ")"); | 39 | System.Console.WriteLine("Screen size is " + host.Width + "x" + host.Height + " (" + host.Length + ")"); |
40 | 40 | ||
41 | + // host.Connect("tn3270://zos.efglobe.com:telnet",10); | ||
41 | host.Connect("tn3270://zos.efglobe.com:telnet",10); | 42 | host.Connect("tn3270://zos.efglobe.com:telnet",10); |
42 | 43 | ||
43 | if(host.Connected) { | 44 | if(host.Connected) { |
@@ -46,7 +47,7 @@ class sample { | @@ -46,7 +47,7 @@ class sample { | ||
46 | 47 | ||
47 | System.Console.WriteLine("Wait for ready returned " + host.WaitForReady(5)); | 48 | System.Console.WriteLine("Wait for ready returned " + host.WaitForReady(5)); |
48 | 49 | ||
49 | - System.Console.WriteLine(host.GetStringAt(14,19,38)); | 50 | + System.Console.WriteLine(host); |
50 | 51 | ||
51 | host.Disconnect(); | 52 | host.Disconnect(); |
52 | } | 53 | } |