Info.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Info.c /main/1 1996/03/25 19:10:11 barstow $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. *
  33. * This file contains the main program for: dtinfo_start
  34. */
  35. #include <stdlib.h>
  36. #include <sys/param.h> /* MAXHOSTNAMELEN */
  37. #include <Tt/tt_c.h>
  38. #include <Dt/Info.h>
  39. #include <Dt/Connect.h>
  40. /*
  41. * External declaration for Xegethostname
  42. */
  43. extern int Xegetshorthostname (char * hostname, unsigned int size);
  44. /*
  45. * Static variables
  46. */
  47. static const char * DTINFOLIBDEFAULT_NAME = "DTINFOLIBDEFAULT";
  48. static const char * DTINFOLIBDEFAULT_DEFAULT = "cde";
  49. static const char * SHOW_INFO_OP_NAME = "DtInfo_ShowInfoAtLoc";
  50. static const char * SHOW_INFO_DEFAULT_ACTION = "DtInfoStartAtLoc";
  51. static const char * LOCALE_NAME = "LANG";
  52. static const char * DEFAULT_LOCALE = "C";
  53. static const char * STRING_ARG_TYPE = "string";
  54. /*
  55. * Forward declarations for static functions
  56. */
  57. static DtInfoShowStatus ConnectToMessageServer ();
  58. /*
  59. * Public functions
  60. */
  61. DtInfoShowStatus
  62. DtInfoShowTopic (
  63. const char * info_lib, /* the InfoLib */
  64. const char * locator) /* the generalized locator
  65. format */
  66. {
  67. Tt_message message;
  68. Tt_status status;
  69. DtInfoShowStatus ret_val;
  70. const char * file = info_lib;
  71. const char * locale;
  72. char host[MAXHOSTNAMELEN];
  73. /*
  74. * Check the arguments
  75. */
  76. if (!locator)
  77. return (DtINFO_SHOW_BAD_LOCATOR);
  78. if ((ret_val = ConnectToMessageServer ()) != DtINFO_SHOW_OK)
  79. return (ret_val);
  80. if (!file) {
  81. if ((file = getenv (DTINFOLIBDEFAULT_NAME)) == NULL)
  82. file = DTINFOLIBDEFAULT_DEFAULT;
  83. }
  84. if ((locale = getenv (LOCALE_NAME)) == NULL)
  85. locale = DEFAULT_LOCALE;
  86. message = tt_message_create ();
  87. status = tt_ptr_error (message);
  88. if (status != TT_OK)
  89. return (DtINFO_SHOW_MSG_CREATE_FAIL);
  90. /*
  91. * Initialize message
  92. */
  93. tt_message_class_set (message, TT_REQUEST);
  94. tt_message_scope_set (message, TT_SESSION);
  95. tt_message_address_set (message, TT_PROCEDURE);
  96. tt_message_session_set (message, tt_default_session());
  97. tt_message_op_set (message, SHOW_INFO_OP_NAME);
  98. tt_message_file_set (message, info_lib);
  99. /*
  100. * Add the arguments
  101. */
  102. tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE,
  103. SHOW_INFO_DEFAULT_ACTION);
  104. if ((Xegetshorthostname (host, MAXHOSTNAMELEN)) != 0)
  105. tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, NULL);
  106. else
  107. tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, host);
  108. tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, locale);
  109. tt_message_arg_add (message, TT_IN, STRING_ARG_TYPE, locator);
  110. /*
  111. * Send it
  112. */
  113. status = tt_message_send (message);
  114. if (status != TT_OK)
  115. return (DtINFO_SHOW_MSG_SEND_FAIL);
  116. return (DtINFO_SHOW_OK);
  117. }
  118. static DtInfoShowStatus
  119. ConnectToMessageServer (void)
  120. {
  121. char * procid;
  122. Tt_status status;
  123. procid = tt_default_procid ();
  124. status = tt_ptr_error (procid);
  125. if (status == TT_OK) {
  126. tt_free (procid);
  127. }
  128. if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) {
  129. procid = tt_open ();
  130. status = tt_ptr_error (procid);
  131. if (status != TT_OK) {
  132. return (DtINFO_SHOW_TT_OPEN_FAIL);
  133. }
  134. }
  135. return (DtINFO_SHOW_OK);
  136. }