main.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * main.c
  3. *
  4. * $Id$
  5. *
  6. * Main program
  7. *
  8. * The iODBC driver manager.
  9. *
  10. * Copyright (C) 1996-2021 OpenLink Software <[email protected]>
  11. * All Rights Reserved.
  12. *
  13. * This software is released under the terms of either of the following
  14. * licenses:
  15. *
  16. * - GNU Library General Public License (see LICENSE.LGPL)
  17. * - The BSD License (see LICENSE.BSD).
  18. *
  19. * Note that the only valid version of the LGPL license as far as this
  20. * project is concerned is the original GNU Library General Public License
  21. * Version 2, dated June 1991.
  22. *
  23. * While not mandated by the BSD license, any patches you make to the
  24. * iODBC source code may be contributed back into the iODBC project
  25. * at your discretion. Contributions will benefit the Open Source and
  26. * Data Access community as a whole. Submissions may be made at:
  27. *
  28. * http://www.iodbc.org
  29. *
  30. *
  31. * GNU Library Generic Public License Version 2
  32. * ============================================
  33. * This library is free software; you can redistribute it and/or
  34. * modify it under the terms of the GNU Library General Public
  35. * License as published by the Free Software Foundation; only
  36. * Version 2 of the License dated June 1991.
  37. *
  38. * This library is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  41. * Library General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU Library General Public
  44. * License along with this library; if not, write to the Free
  45. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  46. *
  47. *
  48. * The BSD License
  49. * ===============
  50. * Redistribution and use in source and binary forms, with or without
  51. * modification, are permitted provided that the following conditions
  52. * are met:
  53. *
  54. * 1. Redistributions of source code must retain the above copyright
  55. * notice, this list of conditions and the following disclaimer.
  56. * 2. Redistributions in binary form must reproduce the above copyright
  57. * notice, this list of conditions and the following disclaimer in
  58. * the documentation and/or other materials provided with the
  59. * distribution.
  60. * 3. Neither the name of OpenLink Software Inc. nor the names of its
  61. * contributors may be used to endorse or promote products derived
  62. * from this software without specific prior written permission.
  63. *
  64. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  65. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  66. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  67. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
  68. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  69. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  70. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  71. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  72. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  73. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  74. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  75. */
  76. #include <iodbc.h>
  77. #include <isql.h>
  78. #include <odbcinst.h>
  79. #include <unistd.h>
  80. #include <stdlib.h>
  81. #include "gui.h"
  82. int
  83. gtk_gui (int *argc, char **argv[])
  84. {
  85. GtkWidget *mainwnd;
  86. #if GTK_CHECK_VERSION(2,0,0)
  87. gtk_set_locale();
  88. #endif
  89. gtk_init (argc, argv);
  90. mainwnd = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  91. return SQLManageDataSources (mainwnd);
  92. }
  93. int
  94. kde_gui (int *argc, char **argv[])
  95. {
  96. return -1;
  97. }
  98. void
  99. display_help (void)
  100. {
  101. printf ("-help\t\t\tDisplay the list of options.\n\r");
  102. printf
  103. ("-odbc filename\t\tSet the location of the user ODBC.INI file.\n\r");
  104. printf
  105. ("-odbcinst filename\tSet the location of the user ODBCINST.INI file.\n\r");
  106. printf
  107. ("-sysodbc filename\tSet the location of the system ODBC.INI file.\n\r");
  108. printf
  109. ("-sysodbcinst filename\tSet the location of the system ODBCINST.INI file.\n\r");
  110. printf ("-gui guitype\t\tSet the GUI type : GTK, KDE.\n\r");
  111. printf ("-debug\t\t\tThe error messages are displayed on the console.\n\r");
  112. printf
  113. ("-admin odbcinstfile\tUsed to administrate the system odbcinst.ini file.\n\r\n\r");
  114. _exit (1);
  115. }
  116. #if !defined(HAVE_SETENV)
  117. static int
  118. setenv (const char *name, const char *value, int overwrite)
  119. {
  120. int rc;
  121. char *entry;
  122. /*
  123. * Allocate some space for new environment variable
  124. */
  125. if ((entry = (char *) malloc (strlen (name) + strlen (value) + 2)) == NULL)
  126. return -1;
  127. strcpy (entry, name);
  128. strcat (entry, "=");
  129. strcat (entry, value);
  130. /*
  131. * Check if variable already exists in current environment and whether
  132. * we want to overwrite it with a new value if it exists.
  133. */
  134. if (getenv (name) != NULL && !overwrite)
  135. {
  136. free (entry);
  137. return 0;
  138. }
  139. /*
  140. * Add the variable to the environment.
  141. */
  142. rc = putenv (entry);
  143. free (entry);
  144. return (rc == 0) ? 0 : -1;
  145. }
  146. #endif /* HAVE_SETENV */
  147. int
  148. main (int argc, char *argv[])
  149. {
  150. BOOL debug = FALSE;
  151. char path[4096];
  152. char *gui = NULL;
  153. int i = 1;
  154. printf ("iODBC Administrator (GTK)\n");
  155. printf ("%s\n", PACKAGE_STRING);
  156. printf ("Copyright (C) 2000-2021 OpenLink Software\n");
  157. printf ("Please report all bugs to <%s>\n\n", PACKAGE_BUGREPORT);
  158. /* Check options commands */
  159. if (argc > 1)
  160. {
  161. for (; i < argc; i++)
  162. {
  163. if (!strcasecmp (argv[i], "-help"))
  164. display_help ();
  165. if (!strcasecmp (argv[i], "-debug"))
  166. debug = TRUE;
  167. if (!strcasecmp (argv[i], "-odbc"))
  168. {
  169. if (i + 1 >= argc)
  170. display_help ();
  171. setenv ("ODBCINI", argv[++i], TRUE);
  172. }
  173. if (!strcasecmp (argv[i], "-admin"))
  174. {
  175. if (i + 1 >= argc)
  176. display_help ();
  177. setenv ("ODBCINSTINI", argv[++i], TRUE);
  178. setenv ("SYSODBCINSTINI", argv[i], TRUE);
  179. }
  180. if (!strcasecmp (argv[i], "-odbcinst"))
  181. {
  182. if (i + 1 >= argc)
  183. display_help ();
  184. setenv ("ODBCINSTINI", argv[++i], TRUE);
  185. }
  186. if (!strcasecmp (argv[i], "-sysodbc"))
  187. {
  188. if (i + 1 >= argc)
  189. display_help ();
  190. setenv ("SYSODBCINI", argv[++i], TRUE);
  191. }
  192. if (!strcasecmp (argv[i], "-sysodbcinst"))
  193. {
  194. if (i + 1 >= argc)
  195. display_help ();
  196. setenv ("SYSODBCINSTINI", argv[++i], TRUE);
  197. }
  198. if (!strcasecmp (argv[i], "-gui"))
  199. {
  200. if (i + 2 >= argc)
  201. display_help ();
  202. gui = argv[++i];
  203. }
  204. }
  205. }
  206. if (!getenv ("ODBCINI") && getenv ("HOME"))
  207. {
  208. STRCPY (path, getenv ("HOME"));
  209. STRCAT (path, "/.odbc.ini");
  210. setenv ("ODBCINI", path, TRUE);
  211. }
  212. if (!debug)
  213. {
  214. close (STDOUT_FILENO);
  215. close (STDERR_FILENO);
  216. }
  217. if (gui && !strcasecmp (gui, "KDE"))
  218. return kde_gui (&argc, &argv);
  219. return gtk_gui (&argc, &argv);
  220. }