Exemplo n.º 1
0
int main (unsigned int argc, char **argv)
{
  process_arguments(argc, argv); /* g_module, db_name side-effected */

#ifdef _DBG_PRINT
  dbrecftos("/tmp/msg");
#endif

  dbproc = mydblogin();		
  if (dbproc == NULL) {
    fprintf(stderr, "Unable to log into DB.  Exiting.\n");
    exit(1);
  }
  initialize_message_system("UTL", dbproc);	/* a lie, but... */
  if(em_initialize_severity_codes(dbproc) == FAILURE)
  {
	fprintf(stderr,"Severity codes initialization failed.  Exiting.\n");
	exit(1);
  }
  if((nmodule_names = initialize_module_names(dbproc, &module_names)) < 0)
  {
	fprintf(stderr,"Module names initialization failed.  Exiting.\n");
	exit(1);
  }
  if (!g_module[0])		/* No module given.  Select "All". */
    strcpy(g_module, ALL);
  else {			/* module name not specified */
    /* 
     * Check if module name given is legal.  
     * If not, issue a message and exit.
     */
    int i;
    for (i = 0; i < nmodule_names; i++)
      if (!strcmp(g_module, module_names[i])) break;
    if (i == nmodule_names) {	/* module not found */
      fprintf(stderr, "Unknown module name '%s.'  Allowed modules are:\n\t", 
	      g_module);
      for (i = 0; i < nmodule_names; i++) 
	if (strcmp(module_names[i], ALL))
	  fprintf(stderr, " %s ", module_names[i]);
      fputc('\n', stderr);
      exit(1);
    }
  }
  XtToolkitInitialize ();
  app_context = XtCreateApplicationContext();
  display = XtOpenDisplay(app_context, NULL, argv[0], "EditMessage",
			   NULL, 0, &argc, argv);
  if (!display) {
    fprintf(stderr, "%s: can't open display, exiting...\n", argv[0]);
    exit (1);
  }
  XmRegisterConverters();
  XtAddConverter (XmRString, XmRUnitType, XmCvtStringToUnitType, NULL, 0);
  create_appShell ( display, argv[0], argc, argv );
  /* Cache the chosen module, for callbacks. 
     We could just use the set_module() callback, but that swaps labels etc.
     and we're cheap. */
  initialize_default_module(g_module);
  XtRealizeWidget(appShell);
  XtAppMainLoop(app_context);
  exit(0);			/* never get here */
}
Exemplo n.º 2
0
int
read_login_info(int argc, char **argv)
{
	int len;
	FILE *in = NULL;
#if !defined(__MINGW32__) && !defined(_MSC_VER)
	int ch;
#endif
	char line[512];
	char *s1, *s2;
	char filename[PATH_MAX];
	static const char *PWD = "../../../PWD";
	struct { char *username, *password, *servername, *database; char fverbose; } options;

#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_STACK)
#define MAX_STACK (8*1024*1024)

	struct rlimit rlim;

	if (!getrlimit(RLIMIT_STACK, &rlim) && (rlim.rlim_cur == RLIM_INFINITY || rlim.rlim_cur > MAX_STACK)) {
		rlim.rlim_cur = MAX_STACK;
		setrlimit(RLIMIT_STACK, &rlim);
	}
#endif

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);

	free(ARGV0);
#ifdef __VMS
	{
		/* basename expects unix format */
		s1 = strrchr(argv[0], ';'); /* trim version; extension trimmed later */
		if (s1) *s1 = 0;
		const char *unixspec = decc$translate_vms(argv[0]);
		ARGV0 = strdup(unixspec);
	}
#else
	ARGV0 = strdup(argv[0]);
#endif
	
	BASENAME = tds_basename(ARGV0);
#if defined(_WIN32) || defined(__VMS)
	s1 = strrchr(BASENAME, '.');
	if (s1) *s1 = 0;
#endif
	DIRNAME = dirname(ARGV0);
	
	memset(&options, 0, sizeof(options));
	
#if !defined(__MINGW32__) && !defined(_MSC_VER)
	/* process command line options (handy for manual testing) */
	while ((ch = getopt(argc, (char**)argv, "U:P:S:D:f:v")) != -1) {
		switch (ch) {
		case 'U':
			options.username = strdup(optarg);
			break;
		case 'P':
			options.password = strdup(optarg);
			break;
		case 'S':
			options.servername = strdup(optarg);
			break;
		case 'D':
			options.database = strdup(optarg);
			break;
		case 'f': /* override default PWD file */
			PWD = strdup(optarg);
			break;
		case 'v':
			options.fverbose = 1; /* doesn't normally do anything */
			break;
		case '?':
		default:
			fprintf(stderr, "usage:  %s \n"
					"        [-U username] [-P password]\n"
					"        [-S servername] [-D database]\n"
					"        [-i input filename] [-o output filename] "
					"[-e error filename]\n"
					, BASENAME);
			exit(1);
		}
	}
#endif
	strcpy(filename, PWD);

	s1 = getenv("TDSPWDFILE");
	if (s1 && s1[0])
		in = fopen(s1, "r");
	if (!in)
		in = fopen(filename, "r");
	if (!in)
		in = fopen("PWD", "r");
	if (!in) {
		sprintf(filename, "%s/%s", (DIRNAME) ? DIRNAME : ".", PWD);

		in = fopen(filename, "r");
		if (!in) {
			fprintf(stderr, "Can not open %s file\n\n", filename);
			goto Override;
		}
	}

	while (fgets(line, 512, in)) {
		s1 = strtok(line, "=");
		s2 = strtok(NULL, "\n");
		if (!s1 || !s2)
			continue;
		if (!strcmp(s1, "UID")) {
			strcpy(USER, s2);
		} else if (!strcmp(s1, "SRV")) {
			strcpy(SERVER, s2);
		} else if (!strcmp(s1, "PWD")) {
			strcpy(PASSWORD, s2);
		} else if (!strcmp(s1, "DB")) {
			strcpy(DATABASE, s2);
		}
	}
	fclose(in);
	
	Override:
	/* apply command-line overrides */
	if (options.username) {
		strcpy(USER, options.username);
		free(options.username);
	}
	if (options.password) {
		strcpy(PASSWORD, options.password);
		free(options.password);
	}
	if (options.servername) {
		strcpy(SERVER, options.servername);
		free(options.servername);
	}
	if (options.database) {
		strcpy(DATABASE, options.database);
		free(options.database);
	}

	if (!*SERVER) {
		fprintf(stderr, "no servername provided, quitting.\n");
		exit(1);
	}
	
	printf("found %s.%s for %s in \"%s\"\n", SERVER, DATABASE, USER, filename);
	
#if 0
	dbrecftos(BASENAME);
#endif
	len = snprintf(sql_file, sizeof(sql_file), "%s/%s.sql", FREETDS_SRCDIR, BASENAME);
	assert(len >= 0 && len <= sizeof(sql_file));

	if (input_file)
		fclose(input_file);
	if ((input_file = fopen(sql_file, "r")) == NULL) {
		fflush(stdout);
		fprintf(stderr, "could not open SQL input file \"%s\"\n", sql_file);
	}

	if (!free_file_registered)
		atexit(free_file);
	free_file_registered = 1;
	
	printf("SQL text will be read from %s\n", sql_file);

	return 0;
}