add: LibBase = OpenLibrary("keymap.library", 36); if (NULL != LibBase) { IKeymap = (struct KeymapIFace *)GetInterface(LibBase, "main", 1, NULL); if (!IKeymap) CloseLibrary(LibBase); } if( NULL == IKeymap) { error( "Unable to open '%s'.\n", "keymap.library" ); return RETURN_FAIL; }
context: main(int argc, char *argv[]){  char server[64];  char fullhostname[64];  char domain[16];  char password[64];  char shell[128];  char directory[32];  Bool prompt_password, rdp_retval = False;  struct passwd *pw;  uint32 flags;  char *p;  struct Node* node;  struct KeyMap* default_keymap;    char pubscreen[64];  struct RDArgs* rdargs = NULL;  char* wbargs = NULL;  int rc = RETURN_OK;  atexit(cleanup);#ifndef __amigaos4__  AslBase = OpenLibrary( AslName, 39 );    if( AslBase == NULL )  {    error( "Unable to open '%s'.\n", AslName );    return RETURN_FAIL;  }  GfxBase = (struct GfxBase*) OpenLibrary( "graphics.library", 39 );    if( GfxBase == NULL )  {    error( "Unable to open '%s'.\n", "graphics.library" );    return RETURN_FAIL;  }  KeymapBase = OpenLibrary("keymap.library", 36);  if( KeymapBase == NULL )  {    error( "Unable to open '%s'.\n", "keymap.library" );  }  KeymapResource = OpenResource("keymap.resource");   if( KeymapResource == NULL )  {    error( "Unable to open '%s'.\n", "keymap.resource" );  }   IconBase = OpenLibrary("icon.library", 0);  if( IconBase == NULL )  {    error( "Unable to open '%s'.\n", "icon.library" );  }        IFFParseBase = OpenLibrary("iffparse.library", 39);  if( IFFParseBase == NULL )  {    error( "Unable to open '%s'.\n", "iffparse.library" );  }  IntuitionBase = (struct IntuitionBase*) OpenLibrary( "intuition.library", 39 );    if( IntuitionBase == NULL )  {    error( "Unable to open '%s'.\n", "intuition.library" );    return RETURN_FAIL;  }#endif#ifdef __amigaos4__{  struct Library *LibBase;  LibBase = OpenLibrary("bsdsocket.library", 3L);  if (NULL != LibBase)  {     ISocket = (struct SocketIFace *)GetInterface(LibBase, "main", 1, NULL);     if (!ISocket) CloseLibrary(LibBase);  }  if (!LibBase || !ISocket)  {     error( "Unable to open '%s'.\n", "bsdsocket.library" );     return RETURN_FAIL;  }  LibBase = OpenLibrary("usergroup.library", 0L);  if (LibBase)  {     IUserGroup = (struct UserGroupIFace *)GetInterface(LibBase, "main", 1, NULL);     if (!IUserGroup) CloseLibrary(LibBase);  }  if (!LibBase || !IUserGroup)  {     error( "Unable to open '%s'.\n", "usergroup.library" );     return RETURN_FAIL;  }  LibBase = OpenLibrary("amissl.library", 1);  if (LibBase)  {     IAmiSSL = (struct AmiSSLIFace *)GetInterface(LibBase, "main", 1, NULL);     if (!IAmiSSL) CloseLibrary(LibBase);  }  if (!LibBase || !IAmiSSL)  {     error( "Unable to open '%s'.\n", "amissl.library" );     return RETURN_FAIL;  }  if (!InitAmiSSL(AmiSSL_Version, AmiSSL_CurrentVersion,                  AmiSSL_Revision, AmiSSL_CurrentRevision,                  /* AmiSSL_VersionOverride, TRUE,*/                  AmiSSL_SocketBase, ((struct Interface *)ISocket)->Data.LibBase,                  TAG_DONE))  {     AmiSSL_initialized = TRUE;  } else {     error( "Unable to initialize AmiSSL\n" );     return RETURN_FAIL;  }  SetErrnoPtr(&errno, 4);}#endif  LayersBase = OpenLibrary( "layers.library", 39 );#ifdef __amigaos4__  ILayers = (struct LayersIFace *)GetInterface(LayersBase, "main", 1, NULL);  if (!ILayers)  {     CloseLibrary(LayersBase);     LayersBase = NULL;  }#endif    if( LayersBase == NULL )  {    error( "Unable to open '%s'.\n", "layers.library" );    return RETURN_FAIL;  }#ifndef __amigaos4__  UtilityBase = (struct UtilityBase*) OpenLibrary( "utility.library", 37 );    if( UtilityBase == NULL )  {    error( "Unable to open '%s'.\n", "utility.library" );    return RETURN_FAIL;  }  WorkbenchBase = OpenLibrary( "workbench.library", 37 );    if( WorkbenchBase == NULL )  {    error( "Unable to open '%s'.\n", "workbench.library" );    return RETURN_FAIL;  }#endif    CyberGfxBase = OpenLibrary( "cybergraphics.library", 40 );#ifdef __amigaos4__  if (CyberGfxBase)  {    ICyberGfx = (struct CyberGfxIFace *)GetInterface(CyberGfxBase, "main", 1, NULL);    if (!ICyberGfx)    {      CloseLibrary(CyberGfxBase);      CyberGfxBase = NULL;    }  }#endif  // Don't care if we're unable to open it    flags = RDP_LOGON_NORMAL;  prompt_password = False;  domain[0] = password[0] = shell[0] = directory[0] = 0;  strcpy(keymapname, "en-us");  g_embed_wnd = 0;  g_num_devices = 0;  pw = getpwuid(getuid());  if ((pw != NULL) && (pw->pw_name != NULL))  {    a_args.a_user = pw->pw_name;  }  if (gethostname(fullhostname, sizeof(fullhostname)) != -1)  {    p = strchr(fullhostname, '.');    if (p != NULL)      *p = 0;    a_args.a_client = fullhostname;  }  Forbid();  // According to RKRM, it's ok to check this against the keymap list  default_keymap = AskKeyMapDefault();  ForeachNode (&KeymapResource->kr_List, node) {    struct KeyMapNode* keymapnode = (struct KeyMapNode*) node;    if (default_keymap == &keymapnode->kn_KeyMap) {      int i;      for (i = 0; keymap_codes[i].name != NULL; ++i) {	if (Stricmp(keymapnode->kn_Node.ln_Name, keymap_codes[i].name) == 0) {	  keylayout = keymap_codes[i].win_code;	}      }    }  }  Permit();    if (argc == 0)  {    struct DiskObject* icon;    BPTR cd;    int length = 1; // space for one nul character    int i, t;    cd = CurrentDir( 0 );        wb_msg = (struct WBStartup*) argv;    for( i = wb_msg->sm_NumArgs - 1; i >= 0; --i )    {      CurrentDir( wb_msg->sm_ArgList[ i ].wa_Lock );      icon = GetDiskObject( wb_msg->sm_ArgList[ i ].wa_Name );      if( amiga_icon == NULL )      {	amiga_icon = icon;      }            if( icon != NULL && icon->do_ToolTypes != NULL )      {	for( t = 0;  icon->do_ToolTypes[ t ] != NULL; ++t )	{	  char* tt = icon->do_ToolTypes[ t ];	  if( isalpha( tt[ 0 ] ) && strncmp( tt, "WINDOW", 6 ) != 0 )	  {	    // Add length + space	    length = length + strlen( tt ) + 1;	  }	}	if( icon != amiga_icon )	{	  FreeDiskObject( icon );	}      }    }    wbargs = malloc( length );    wbargs[0] = 0;    if( wbargs != NULL )    {      for( i = wb_msg->sm_NumArgs - 1; i >= 0; --i )      {	CurrentDir( wb_msg->sm_ArgList[ i ].wa_Lock );	icon = GetDiskObject( wb_msg->sm_ArgList[ i ].wa_Name );		if( icon != NULL && icon->do_ToolTypes != NULL )	{	  for( t = 0;  icon->do_ToolTypes[ t ] != NULL; ++t )	  {	    char* tt = icon->do_ToolTypes[ t ];	    	    if( isalpha( tt[ 0 ] ) && Strnicmp( tt, "WINDOW", 6 ) != 0 )	    {	      int tt_len;	      char* args = wbargs;	      for( tt_len = 0; isalnum( tt[ tt_len ] ); ++tt_len );	      while( 1 )	      {		if( Strnicmp( args, tt, tt_len ) == 0 &&		    ! isalnum( tt[ tt_len ] ) )		{		  break;		}		else		{		  while( *args != 0 )		  {		    ++args;		    if( *args == '\n' )		    {		      ++args;		      break;		    }		  }		  if( *args == 0 )		  {		    strcat( args, tt );		    strcat( args, "\n" ); // Marker!		    break;		  }		}	      }	    }	  }	  	  FreeDiskObject( icon );	}      }      // Fix for ReadArgs: replace all but the last LF with a space      length = strlen( wbargs );      for( i = 0; i < length - 1; ++i )      {	if( wbargs[ i ] == '\n' )	{	  wbargs[ i ] = ' ';	}      }      rdargs = AllocDosObjectTags( DOS_RDARGS, TAG_DONE );	      if( rdargs != NULL )      {	rdargs->RDA_Source.CS_Buffer = wbargs;	rdargs->RDA_Source.CS_Length = length;	rdargs->RDA_Source.CS_CurChr = 0;      }    }    CurrentDir( cd );  }  if( amiga_icon == NULL )  {    BPTR cd = CurrentDir( GetProgramDir() );    char name[ 256 ];        if( GetProgramName( name, sizeof( name ) ) ) {      amiga_icon = GetDiskObject( name );    }    CurrentDir( cd );  }  if (0 == argc)  {     rdargs = ReadArgs(wbtemplate, (LONG*) &a_args, rdargs);  } else {     rdargs = ReadArgs(template, (LONG*)&a_args, rdargs);  }  if (rdargs == NULL)  {    char txt[128];		    Fault(IoErr(), NULL, txt, sizeof(txt));    error("%s\n", txt);    return RETURN_ERROR;  }    if (a_args.a_user == NULL)  {    error("Could not determine username.\nYou have to specify it manually.\n");    rc = RETURN_ERROR;  }  if (a_args.a_client == NULL)  {    error("Could not determine client name.\nYou have to specify it manually.\n");    rc = RETURN_ERROR;  }  if (a_args.a_server != NULL) STRNCPY(server, a_args.a_server, sizeof(server));  if (a_args.a_user != NULL)   STRNCPY(g_username, a_args.a_user, sizeof(g_username));	  if (a_args.a_domain != NULL) STRNCPY(domain, a_args.a_domain, sizeof(domain));  if (a_args.a_shell != NULL)  STRNCPY(shell, a_args.a_shell, sizeof(shell));  if (a_args.a_dir != NULL)    STRNCPY(directory, a_args.a_dir, sizeof(directory));  if (a_args.a_password != NULL)  {    STRNCPY(password, a_args.a_password, sizeof(password));    flags |= RDP_LOGON_AUTO;  }  if (a_args.a_client != NULL) STRNCPY(hostname, a_args.a_client, sizeof(hostname));  if (a_args.a_pubscreen != NULL)  {    STRNCPY(pubscreen, a_args.a_pubscreen, sizeof(pubscreen));    amiga_pubscreen_name = pubscreen;  }  if (a_args.a_screenmode != NULL)  {    amiga_screen_id = *a_args.a_screenmode;    a_args.a_fullscreen = TRUE;  }  g_fullscreen      = a_args.a_fullscreen;  if (a_args.a_left != NULL) amiga_left = *a_args.a_left;  if (a_args.a_top != NULL)  amiga_top  = *a_args.a_top;  if (a_args.a_fullscreen && (a_args.a_left != NULL || a_args.a_top != NULL || a_args.a_pubscreen != NULL))  {    warning( "The LEFT, TOP and PUBSCREEN arguments are ignored in fullscreen mode.\n");  }	  g_width           = *a_args.a_width;  g_height          = *a_args.a_height;	  g_orders          = ! a_args.a_bitmapsonly;  g_encryption      = ! a_args.a_french;  packet_encryption = ! a_args.a_noenc;  g_sendmotion      = ! a_args.a_nomouse;#ifdef WITH_RDPSND  if( a_args.a_audio != NULL) amiga_audio_unit = *a_args.a_audio;#endif  if (a_args.a_remoteaudio)  {    flags |= RDP_LOGON_LEAVE_AUDIO;    if (a_args.a_audio != NULL)    {      warning( "The AUDIO argument is ignored when REMOTEAUDIO is used.\n");    }  }#ifdef WITH_RDPSND  else  {    g_rdpsnd = True;  }#endif	  if( a_args.a_title != NULL) STRNCPY(g_title, a_args.a_title, sizeof(g_title));  g_server_bpp = *a_args.a_depth;  if (g_server_bpp < 0 ||      (g_server_bpp > 8 && g_server_bpp != 16 && g_server_bpp != 15       && g_server_bpp != 24))  {    error("invalid server bpp\n");    rc = RETURN_ERROR;  }  if (a_args.a_experience != NULL)  {    toupper_str(a_args.a_experience);		    if (strcmp("28K8", a_args.a_experience) == 0)    {      g_rdp5_performanceflags =	RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |	RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;    }    else if (strcmp("56K", a_args.a_experience) == 0)    {      g_rdp5_performanceflags =	RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |	RDP5_NO_MENUANIMATIONS;    }    else if (strcmp("DSL", a_args.a_experience) == 0)    {      g_rdp5_performanceflags = RDP5_NO_WALLPAPER;    }    else if (strcmp("LAN", a_args.a_experience) == 0)    {      g_rdp5_performanceflags = RDP5_DISABLE_NOTHING;    }    else    {      error("Illegal EXPERIENCE value: %s\n", a_args.a_experience);      rc = RETURN_ERROR;    }  }		  g_console_session = a_args.a_console;  g_use_rdp5 = ! a_args.a_rdp4;  if (a_args.a_keymap != NULL) keylayout = *a_args.a_keymap;  if (server[0] == 0)  {    error("No server specified\n");    rc = RETURN_ERROR;  }  parse_server_and_port(server);  if (strcmp(password, "-") == 0)  {    read_password(password, sizeof(password));  }  if (g_title[0] == 0)  {    strcpy(g_title, "RDesktop - ");    strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));  }  FreeArgs( rdargs );  free( wbargs );#define PRINTS( s ) //printf( "%s: %s\n", #s, s );#define PRINTI( i ) //printf( "%s: %d\n", #i, i );	  PRINTI( amiga_left );  PRINTI( amiga_top );  PRINTI( amiga_screen_id );  PRINTS( amiga_pubscreen_name );   PRINTS(  g_title );  PRINTS(  g_username );  PRINTS(  hostname );  PRINTS(  keymapname );  PRINTI(  keylayout );  PRINTI(  g_width );  PRINTI(  g_height );  PRINTI(  tcp_port_rdp );  PRINTI(  g_server_bpp );  PRINTI(  g_win_button_size );  PRINTI(  g_bitmap_compression );  PRINTI(  g_sendmotion );  PRINTI(  g_orders );  PRINTI(  g_encryption );  PRINTI(  packet_encryption );  PRINTI(  g_desktop_save );  PRINTI(  g_fullscreen );  PRINTI(  g_grab_keyboard );  PRINTI(  g_hide_decorations );  PRINTI(  g_use_rdp5 );  PRINTI(  g_console_session );  PRINTI(  g_numlock_sync );  PRINTI(  g_owncolmap );  PRINTI(  g_ownbackstore );  PRINTI(  g_embed_wnd );  PRINTI(  g_rdp5_performanceflags );	  if (rc != RETURN_OK)  {    return rc;  }	  if (!ui_init())    return RETURN_FAIL;  startup |= UI_INIT;	#ifdef WITH_RDPSND  if (g_rdpsnd)  {    rdpsnd_init();    startup |= RDPSND_INIT;  }#endif  rdpdr_init();  startup |= RDPDR_INIT;  if (!rdp_connect(server, flags, domain, password, shell, directory))    return RETURN_FAIL;  startup |= RDP_CONNECT;	  /* By setting encryption to False here, we have an encrypted login      packet but unencrypted transfer of other packets */  if (!packet_encryption)    g_encryption = False;  DEBUG(("Connection successful.\n"));  memset(password, 0, sizeof(password));  cache_create();  if (ui_create_window())  {    startup |= UI_CREATE_WINDOW;    rdp_retval = rdp_main_loop();  }	  if (True == rdp_retval)    return RETURN_OK;  else    return RETURN_WARN;}