Ejemplo n.º 1
0
// Set up a connection to a ScrollView on hostname:port.
SVNetwork::SVNetwork(const char* hostname, int port) {
  mutex_send_ = new SVMutex();
  msg_buffer_in_ = new char[kMaxMsgSize + 1];
  msg_buffer_in_[0] = '\0';

  has_content = false;
  buffer_ptr_ = NULL;

  struct addrinfo *addr_info = NULL;

  if (GetAddrInfo(hostname, port, &addr_info) != 0) {
    std::cerr << "Error resolving name for ScrollView host "
              << std::string(hostname) << ":" << port << std::endl;
  }

  stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
                   addr_info->ai_protocol);

  // If server is not there, we will start a new server as local child process.
  if (connect(stream_, addr_info->ai_addr, addr_info->ai_addrlen) < 0) {
    const char* scrollview_path = getenv("SCROLLVIEW_PATH");
    if (scrollview_path == NULL) {
#ifdef SCROLLVIEW_PATH
#define _STR(a) #a
#define _XSTR(a) _STR(a)
      scrollview_path = _XSTR(SCROLLVIEW_PATH);
#undef _XSTR
#undef _STR
#else
      scrollview_path = ".";
#endif
    }
    const char *prog = ScrollViewProg();
    std::string command = ScrollViewCommand(scrollview_path);
    SVSync::StartProcess(prog, command.c_str());

    // Wait for server to show up.
    // Note: There is no exception handling in case the server never turns up.

    stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
                   addr_info->ai_protocol);

    while (connect(stream_, addr_info->ai_addr,
                   addr_info->ai_addrlen) < 0) {
      std::cout << "ScrollView: Waiting for server...\n";
#ifdef _WIN32
      Sleep(1000);
#else
      sleep(1);
#endif

      stream_ = socket(addr_info->ai_family, addr_info->ai_socktype,
                   addr_info->ai_protocol);
    }
  }
  FreeAddrInfo(addr_info);
}
Ejemplo n.º 2
0
/**
 * @brief CCUtil::main_setup - set location of tessdata and name of image
 *
 * @param argv0 - paths to the directory with language files and config files.
 * An actual value of argv0 is used if not NULL, otherwise TESSDATA_PREFIX is
 * used if not NULL, next try to use compiled in -DTESSDATA_PREFIX. If previous
 * is not successful - use current directory.
 * @param basename - name of image
 */
void CCUtil::main_setup(const char *argv0, const char *basename) {
  imagebasename = basename;      /**< name of image */

  char *tessdata_prefix = getenv("TESSDATA_PREFIX");

  if (argv0 != NULL) {
    /* Use tessdata prefix from the command line. */
    datadir = argv0;
  } else if (tessdata_prefix) {
    /* Use tessdata prefix from the environment. */
    datadir = tessdata_prefix;
#if defined(_WIN32)
  } else if (datadir == NULL || access(datadir.string(), 0) != 0) {
    /* Look for tessdata in directory of executable. */
    static char dir[128];
    static char exe[128];
    DWORD length = GetModuleFileName(NULL, exe, sizeof(exe));
    if (length > 0 && length < sizeof(exe)) {
      _splitpath(exe, NULL, dir, NULL, NULL);
      datadir = dir;
    }
#endif /* _WIN32 */
#if defined(TESSDATA_PREFIX)
  } else {
    /* Use tessdata prefix which was compiled in. */
#define _STR(a) #a
#define _XSTR(a) _STR(a)
    datadir = _XSTR(TESSDATA_PREFIX);
#undef _XSTR
#undef _STR
#endif
  }

  // datadir may still be empty:
  if (datadir.length() == 0) {
    datadir = "./";
  } else {
    // Remove tessdata from the end if present, as we will add it back!
    int length = datadir.length();
    if (length >= 8 && strcmp(&datadir[length - 8], "tessdata") == 0)
      datadir.truncate_at(length - 8);
    else if (length >= 9 && strcmp(&datadir[length - 9], "tessdata/") == 0)
      datadir.truncate_at(length - 9);
  }

  // check for missing directory separator
  const char *lastchar = datadir.string();
  lastchar += datadir.length() - 1;
  if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0))
    datadir += "/";

  datadir += m_data_sub_dir;     /**< data directory */
}
Ejemplo n.º 3
0
void CCUtil::main_setup(                 /*main demo program */
                const char *argv0,       //program name
                const char *basename     //name of image
               ) {
  imagebasename = basename;      /*name of image */

#ifdef WINAPI_FAMILY
  datadir = "./";
#else
  // TESSDATA_PREFIX Environment variable overrules everything.
  // Compiled in -DTESSDATA_PREFIX is next.
  // An actual value of argv0 is used if not NULL, otherwise current directory.
  if (!getenv("TESSDATA_PREFIX")) {
#ifdef TESSDATA_PREFIX
#define _STR(a) #a
#define _XSTR(a) _STR(a)
    datadir = _XSTR(TESSDATA_PREFIX);
#undef _XSTR
#undef _STR
#else
    if (argv0 != NULL) {
      datadir = argv0;
      // Remove tessdata from the end if present, as we will add it back!
      int length = datadir.length();
      if (length >= 8 && strcmp(&datadir[length - 8], "tessdata") == 0)
        datadir.truncate_at(length - 8);
      else if (length >= 9 && strcmp(&datadir[length - 9], "tessdata/") == 0)
        datadir.truncate_at(length - 9);
      if (datadir.length() == 0)
        datadir = "./";
    } else {
      datadir = "./";
    }
#endif
  } else {
    datadir = getenv("TESSDATA_PREFIX");
  }
#endif // WINAPI_FAMILY

  // check for missing directory separator
  const char *lastchar = datadir.string();
  lastchar += datadir.length() - 1;
  if ((strcmp(lastchar, "/") != 0) && (strcmp(lastchar, "\\") != 0))
    datadir += "/";

  datadir += m_data_sub_dir;     /*data directory */
}
Ejemplo n.º 4
0
void CCUtil::main_setup(                 /*main demo program */
                const char *argv0,       //program name
                const char *basename     //name of image
               ) {
  imagebasename = basename;      /*name of image */
  STRING dll_module_name;
  #ifdef _WIN32
  dll_module_name = tessedit_module_name;
  #endif

  // TESSDATA_PREFIX Environment variable overrules everything.
  // Compiled in -DTESSDATA_PREFIX is next.
  // NULL goes to current directory.
  // An actual value of argv0 is used if getpath is successful.
  if (!getenv("TESSDATA_PREFIX")) {
#ifdef TESSDATA_PREFIX
#define _STR(a) #a
#define _XSTR(a) _STR(a)
    datadir = _XSTR(TESSDATA_PREFIX);
#undef _XSTR
#undef _STR
#else
    if (argv0 != NULL) {
      if (getpath(argv0, dll_module_name, datadir) < 0)
#ifdef __UNIX__
        CANTOPENFILE.error("main", ABORT, "%s to get path", argv0);
#else
        NO_PATH.error("main", DBG, NULL);
#endif
    } else {
      datadir = "./";
    }
#endif
  } else {
    datadir = getenv("TESSDATA_PREFIX");
  }

  datadir += m_data_sub_dir;     /*data directory */
}