Commit 812d5650eccba47522768c5ee9c111ee46c215d4
1 parent
9e0f89c5
Exists in
master
and in
5 other branches
Sample funcional
Showing
3 changed files
with
72 additions
and
2 deletions
Show diff stats
src/sample/Makefile.in
| @@ -35,6 +35,8 @@ MKDIR=@MKDIR_P@ | @@ -35,6 +35,8 @@ MKDIR=@MKDIR_P@ | ||
| 35 | CC=@CC@ | 35 | CC=@CC@ |
| 36 | LD=@CC@ | 36 | LD=@CC@ |
| 37 | 37 | ||
| 38 | +CFLAGS=-g -Wall | ||
| 39 | + | ||
| 38 | #---[ Targets ]---------------------------------------------------------------- | 40 | #---[ Targets ]---------------------------------------------------------------- |
| 39 | 41 | ||
| 40 | all: connect$(EXEEXT) | 42 | all: connect$(EXEEXT) |
src/sample/connect.c
| @@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
| 31 | 31 | ||
| 32 | #include <stdio.h> | 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
| 34 | + #include <string.h> | ||
| 34 | #include <lib3270.h> | 35 | #include <lib3270.h> |
| 35 | 36 | ||
| 36 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 37 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| @@ -38,14 +39,49 @@ | @@ -38,14 +39,49 @@ | ||
| 38 | int main(int numpar, char *param[]) | 39 | int main(int numpar, char *param[]) |
| 39 | { | 40 | { |
| 40 | H3270 *hSession; | 41 | H3270 *hSession; |
| 42 | + int rc; | ||
| 41 | 43 | ||
| 42 | - if(numpar != 1) | 44 | + if(numpar != 2) |
| 43 | { | 45 | { |
| 44 | fprintf(stderr,"Inform host URI as argument\n"); | 46 | fprintf(stderr,"Inform host URI as argument\n"); |
| 45 | exit(-1); | 47 | exit(-1); |
| 46 | - } | 48 | + } |
| 47 | 49 | ||
| 50 | + /* Get session handle */ | ||
| 51 | + hSession = lib3270_session_new(""); | ||
| 48 | 52 | ||
| 53 | + /* Connect to the requested URI, wait for 3270 negotiation */ | ||
| 54 | + rc = lib3270_connect(hSession,param[1],1); | ||
| 55 | + if(rc) | ||
| 56 | + { | ||
| 57 | + fprintf(stderr,"Can't connect to %s: %s\n",param[1],strerror(rc)); | ||
| 58 | + return rc; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + printf("Connected to LU %s\n",lib3270_get_luname(hSession)); | ||
| 62 | + | ||
| 63 | + /* Wait until the host is ready for commands */ | ||
| 64 | + rc = lib3270_wait_for_ready(hSession,60); | ||
| 65 | + if(rc) | ||
| 66 | + { | ||
| 67 | + fprintf(stderr,"Error waiting for session negotiation: %s\n",strerror(rc)); | ||
| 68 | + return rc; | ||
| 69 | + } | ||
| 70 | + else | ||
| 71 | + { | ||
| 72 | + /* Host is ready, get screen contents */ | ||
| 73 | + char *text = lib3270_get_text(hSession,0,-1); | ||
| 74 | + | ||
| 75 | + printf("\nScreen contents:\n%s\n",text); | ||
| 76 | + | ||
| 77 | + lib3270_free(text); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + | ||
| 82 | + | ||
| 83 | + /* Release session handle */ | ||
| 84 | + lib3270_session_free(hSession); | ||
| 49 | return 0; | 85 | return 0; |
| 50 | } | 86 | } |
| 51 | 87 |
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
| 2 | +<CodeBlocks_project_file> | ||
| 3 | + <FileVersion major="1" minor="6" /> | ||
| 4 | + <Project> | ||
| 5 | + <Option title="pw3270 Samples" /> | ||
| 6 | + <Option makefile_is_custom="1" /> | ||
| 7 | + <Option pch_mode="2" /> | ||
| 8 | + <Option compiler="gcc" /> | ||
| 9 | + <Build> | ||
| 10 | + <Target title="connect"> | ||
| 11 | + <Option output="connect" prefix_auto="1" extension_auto="1" /> | ||
| 12 | + <Option object_output=".obj/Debug/" /> | ||
| 13 | + <Option type="1" /> | ||
| 14 | + <Option compiler="gcc" /> | ||
| 15 | + <Compiler> | ||
| 16 | + <Add option="-g" /> | ||
| 17 | + </Compiler> | ||
| 18 | + </Target> | ||
| 19 | + </Build> | ||
| 20 | + <Compiler> | ||
| 21 | + <Add option="-Wall" /> | ||
| 22 | + </Compiler> | ||
| 23 | + <Unit filename="Makefile.in" /> | ||
| 24 | + <Unit filename="connect.c"> | ||
| 25 | + <Option compilerVar="CC" /> | ||
| 26 | + </Unit> | ||
| 27 | + <Extensions> | ||
| 28 | + <code_completion /> | ||
| 29 | + <debugger /> | ||
| 30 | + </Extensions> | ||
| 31 | + </Project> | ||
| 32 | +</CodeBlocks_project_file> |