예제 #1
0
파일: misc.c 프로젝트: ClaudioVZ/crengine
/*
 * Get the size of the specified file.
 * Returns -1 if the file does not exist or is not a proper file.
 */
long
lGetFilesize(const char *szFilename)
{
#if defined(__riscos)
	os_error	*e;
	int	iType, iSize;

	e = SWI(2, 5, SWI_OS_File | XOS_Bit,
		17, szFilename,
		&iType, NULL, NULL, NULL, &iSize);
	if (e != NULL) {
		werr(0, "Get Filesize error %d: %s",
			e->errnum, e->errmess);
		return -1;
	}
	if (iType != 1) {
		/* It's not a proper file or the file does not exist */
		return -1;
	}
	return (long)iSize;
#else
	struct stat	tBuffer;

	errno = 0;
	if (stat(szFilename, &tBuffer) != 0) {
		werr(0, "Get Filesize error %d", errno);
		return -1;
	}
	if (!S_ISREG(tBuffer.st_mode)) {
		/* It's not a regular file */
		return -1;
	}
	return (long)tBuffer.st_size;
#endif /* __riscos */
} /* end of lGetFilesize */
예제 #2
0
ret_code_t network_open_data_connection(context_t * context)
{
	IPaddress ip;
	TCPsocket socket;

	if (SDLNet_ResolveHost(&ip, context->hostname, PORT) < 0)
	{
		werr(LOGUSER, "Can't resolve %s:%d : %s\n", context->hostname, PORT,
				SDLNet_GetError());
		return RET_NOK;
	}

	if (!(socket = SDLNet_TCP_Open(&ip)))
	{
		werr(LOGUSER, "Can't open data connection to %s:%d : %s\n",
				context->hostname, PORT, SDLNet_GetError());
		return RET_NOK;
	}

	context_set_socket_data(context, socket);

	SDL_CreateThread(async_data_recv, "async_data_recv", (void*) context);

	return RET_OK;
}
예제 #3
0
void files(const char *from, const char *to, int error, xmpp_stanza_t *stanza,
           xmpp_conn_t *const conn, void *const userdata)
{
  wlog("files()");
  if (error == 0) {
    char *action_attr = xmpp_stanza_get_attribute(stanza, "action"); /* action attribute */
    if (action_attr == NULL) {
      werr("xmpp_stanza_get_attribute attribute = action");
    }
    wfatal(action_attr == NULL, "xmpp_stanza_get_attribute [attribute = action]");

    if (strcmp(action_attr, "attributes") == 0) {
      files_attr(stanza);
    } else if (strcmp(action_attr, "list") == 0) {
      files_list(stanza);
    } else if (strncasecmp(action_attr, "read", 4) == 0) {
      files_read(stanza);
    } else {
      werr("Unknown action: %s", action_attr);
    }
  } else {
    werr("error stanza %s %s", xmpp_stanza_get_attribute(stanza, "path"), xmpp_stanza_get_attribute(stanza, "action"));
  }

  wlog("Return from files()");
}
예제 #4
0
/*********************************************
Update an entry from a network frame
return RET_NOK on error
*********************************************/
ret_code_t entry_update(char * data)
{
	char * elements[5] = {NULL,NULL,NULL,NULL,NULL};
	config_setting_t * setting;
	const config_t * config= NULL;
	int value;
	char * token;
	int index = 0;
	ret_code_t ret = RET_NOK;

	token = _strsep(&data,NETWORK_DELIMITER);
	while( token != NULL ) {
		elements[index] = strdup(token);
		index++;
		if(index>5) {
			werr(LOGDEV,"Split string error");
			goto entry_update_cleanup;
		}
		token = _strsep(&data,NETWORK_DELIMITER);
	}

	SDL_LockMutex(entry_mutex);
	config = get_config(elements[1],elements[2]);
	if(config==NULL) {
		goto entry_update_cleanup;
	}

	setting = config_lookup (config, elements[3]);
	if(setting==NULL) {
		goto entry_update_cleanup;
	}

	if( strcmp(elements[0],ENTRY_TYPE_INT) == 0 ) {
		value = atoll(elements[4]);
		if(config_setting_set_int (setting, value) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %d",elements[1],elements[2],elements[3],value);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	} else if( strcmp(elements[0],ENTRY_TYPE_STRING) == 0 ) {
		if(config_setting_set_string (setting,elements[4]) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %s",elements[1],elements[2],elements[3],elements[4]);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	}

	ret = RET_OK;

entry_update_cleanup:
	SDL_UnlockMutex(entry_mutex);
	for(index=0; index<5; index++) {
		if(elements[index]) {
			free(elements[index]);
		}
	}

	return ret;
}
예제 #5
0
/*
 * UTF-8 stores wide characters in UTF-32 form.
 */
int
towide_utf8(wchar_t *wc, const char *mb, unsigned n)
{
	wchar_t	c;
	int	nb;
	int	lv;	/* lowest legal value */
	int	i;
	const uint8_t *s = (const uint8_t *)mb;

	c = *s;

	if ((c & 0x80) == 0) {
		/* 7-bit ASCII */
		*wc = c;
		return (1);
	} else if ((c & 0xe0) == 0xc0) {
		/* u80-u7ff - two bytes encoded */
		nb = 2;
		lv = 0x80;
		c &= ~0xe0;
	} else if ((c & 0xf0) == 0xe0) {
		/* u800-uffff - three bytes encoded */
		nb = 3;
		lv = 0x800;
		c &= ~0xf0;
	} else if ((c & 0xf8) == 0xf0) {
		/* u1000-u1fffff - four bytes encoded */
		nb = 4;
		lv = 0x1000;
		c &= ~0xf8;
	} else {
		/* 5 and 6 byte encodings are not legal unicode */
		werr("utf8 encoding too large (%s)", show_mb(mb));
		return (-1);
	}
	if (nb > n) {
		werr("incomplete utf8 sequence (%s)", show_mb(mb));
		return (-1);
	}

	for (i = 1; i < nb; i++) {
		if (((s[i]) & 0xc0) != 0x80) {
			werr("illegal utf8 byte (%x)", s[i]);
			return (-1);
		}
		c <<= 6;
		c |= (s[i] & 0x3f);
	}

	if (c < lv) {
		werr("illegal redundant utf8 encoding (%s)", show_mb(mb));
		return (-1);
	}
	*wc = c;
	return (nb);
}
예제 #6
0
void
printversion(void)
{
  if (printf(_("Debian `%s' package archive backend version %s.\n"),
	     BACKEND, DPKG_VERSION_ARCH) < 0) werr("stdout");
  if (printf(_("This is free software; see the GNU General Public License version 2 or\n"
	       "later for copying conditions. There is NO warranty.\n"
	       "See %s --license for copyright and license details.\n"),
	     BACKEND) < 0) werr("stdout");
}
예제 #7
0
static const char * getKey(int p_IsMoving, char p_Orientation)
{
	const char * l_pKey;

	if (p_IsMoving == true)
	{
		switch (p_Orientation)
		{
		case 'N':
			l_pKey = CHARACTER_KEY_MOV_N_SPRITE;
			break;
		case 'S':
			l_pKey = CHARACTER_KEY_MOV_S_SPRITE;
			break;
		case 'W':
			l_pKey = CHARACTER_KEY_MOV_W_SPRITE;
			break;
		case 'E':
			l_pKey = CHARACTER_KEY_MOV_E_SPRITE;
			break;
		default:
			werr(LOGDESIGNER,
					"l_item_set_anim_from_context: wrong main orientation");
			l_pKey = CHARACTER_KEY_MOV_S_SPRITE;
			break;
		}
	}
	else
	{
		switch (p_Orientation)
		{
		case 'N':
			l_pKey = CHARACTER_KEY_DIR_N_SPRITE;
			break;
		case 'S':
			l_pKey = CHARACTER_KEY_DIR_S_SPRITE;
			break;
		case 'W':
			l_pKey = CHARACTER_KEY_DIR_W_SPRITE;
			break;
		case 'E':
			l_pKey = CHARACTER_KEY_DIR_E_SPRITE;
			break;
		default:
			werr(LOGDESIGNER,
					"l_item_set_anim_from_context: wrong main orientation");
			l_pKey = CHARACTER_KEY_DIR_S_SPRITE;
			break;
		}
	}

	return l_pKey;
}
예제 #8
0
static void do_auth(char *service, char*user, char*pwd, char* mode, int sid)
{
    pam_handle_t *pamh=NULL;
    int retval;
    struct session *sessp;

    conv.appdata_ptr = (void*)strdup(pwd);
    retval = pam_start(service, user, &conv, &pamh);
    
    if (retval != PAM_SUCCESS) {
        werr(pamh, sid, retval, "start");
        return;
    }
    pam_set_item(pamh, PAM_RUSER, user);

    retval = pam_authenticate(pamh, 0); 
    if (retval != PAM_SUCCESS) {
        werr(pamh, sid, retval, "auth");
        return;
    }
    if (mode[0] == 'A') {
        retval = pam_acct_mgmt(pamh, 0); 
        if (retval != PAM_SUCCESS) {
            werr(pamh, sid, retval, "accounting");
            return;
        }
        /*fprintf(stderr, "did ok acct \n\r");*/
    }
    if (mode[1] == 'S') {
        retval = pam_open_session(pamh, 0);
        if (retval != PAM_SUCCESS) {
            werr(pamh, sid, retval, "session");
            return;
        }
        /*fprintf(stderr, "did ok open sess \n\r"); */
    }
    if ((sessp = malloc(sizeof(struct session))) == NULL) {
        werr(pamh, sid, -1, "malloc");
        return;
    }
    if (mode[1] == 'S') 
        sessp->session_mode = 1;
    else
        sessp->session_mode = 0;
    sessp->sid = sid;
    sessp->pamh = pamh;
    sessp->next = sessions;
    sessions = sessp;
    
    wok(sid);
}
예제 #9
0
static void files_attr(xmpp_stanza_t *stanza) {
  int rc; /* Return code */

  rc = pthread_mutex_lock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_lock");

  char *error_attr = xmpp_stanza_get_attribute(stanza, "error"); /* error attribute */
  wfatal(error_attr == NULL, "no error attribute in files stanza");

  if (strcmp(error_attr, "0") != 0) {
    wlog("Error in attributes: %s", error_attr);
    attributes.is_valid = -1;
  } else {
    char *type_attr = xmpp_stanza_get_attribute(stanza, "type"); /* type attribute */
    wfatal(type_attr == NULL, "no type attribute in files stanza");

    if (strcmp(type_attr, "directory") == 0) {
      attributes.is_valid = 1;
      attributes.type = DIR;
    } else if (strcmp(type_attr, "file") == 0) {
      attributes.is_valid = 1;
      attributes.type = REG;
    } else {
      werr("Unknown type: %s", type_attr);
      attributes.is_valid = -1;
    }

    char *size_attr = xmpp_stanza_get_attribute(stanza, "size"); /* size */
    if (size_attr == NULL) {
      werr("xmpp_stanza_get_attribute attribute = size (%s)", xmpp_stanza_get_attribute(stanza, "path"));
      attributes.size = 0;
    } else {
      char *endptr; /* strtol endptr */
      long int size = strtol(size_attr, &endptr, 10);
      if (*endptr != '\0') {
        werr("strtol error: str = %s, val = %ld", size_attr, size);
        attributes.size = 0;
      }
      attributes.size = size;
    }
  }

  signal_attr = true;

  rc = pthread_cond_signal(&cond);
  wsyserr(rc != 0, "pthread_cond_signal");

  rc = pthread_mutex_unlock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_unlock");
}
예제 #10
0
static void files_read(xmpp_stanza_t *stanza) {
  int rc;

  rc = pthread_mutex_lock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_lock");

  char *text = xmpp_stanza_get_text(stanza);
  if(text == NULL) {
    werr("xmpp_stanza_get_text returned NULL (%s, error %s)", xmpp_stanza_get_attribute(stanza, "path"), xmpp_stanza_get_attribute(stanza, "error"));
    read_data = strdup ("");
  }
  else
  {
    int dec_size = strlen(text) * 3 / 4 + 1;
    uint8_t *dec_text = (uint8_t *)calloc(dec_size, sizeof(uint8_t));
    rc = base64_decode(dec_text, text, dec_size);
    wfatal(rc < 0, "base64_decode");

    if (read_data != NULL) {
      free(read_data);
    }
    read_data = strdup((char *)dec_text);
    wsyserr(read_data == NULL, "strdup");

    free(text);
    free(dec_text);
  }

  signal_read = true;
  rc = pthread_cond_signal(&cond);
  wsyserr(rc != 0, "pthread_cond_signal");

  rc = pthread_mutex_unlock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_unlock");
}
예제 #11
0
파일: misc.c 프로젝트: ClaudioVZ/crengine
/*
 * szGetHomeDirectory - get the name of the home directory
 */
const char *
szGetHomeDirectory(void)
{
	const char	*szHome;

#if defined(__vms)
	szHome = decc$translate_vms(getenv("HOME"));
#elif defined(__Plan9__)
	szHome = getenv("home");
#else
	szHome = getenv("HOME");
#endif /* __vms */

	if (szHome == NULL || szHome[0] == '\0') {
#if defined(N_PLAT_NLM)
		szHome = "SYS:";
#elif defined(__dos)
		szHome = "C:";
#else
		werr(0, "I can't find the name of your HOME directory");
		szHome = "";
#endif /* __dos */
	}
	return szHome;
} /* end of szGetHomeDirectory */
예제 #12
0
static void config_print_error(char * file, const config_t * config)
{
	werr(LOGUSER,"libconfig error %s@%d : %s\n",
		 file,
		 config_error_line(config),
		 config_error_text(config));
}
예제 #13
0
int
tomb_utf8(char *mb, wchar_t wc)
{
	uint8_t *s = (uint8_t *)mb;
	uint8_t msk;
	int cnt;
	int i;

	if (wc <= 0x7f) {
		s[0] = wc & 0x7f;
		s[1] = 0;
		return (1);
	}
	if (wc <= 0x7ff) {
		cnt = 2;
		msk = 0xc0;
	} else if (wc <= 0xffff) {
		cnt = 3;
		msk = 0xe0;
	} else if (wc <= 0x1fffff) {
		cnt = 4;
		msk = 0xf0;
	} else {
		werr("illegal uf8 char (%x)", wc);
		return (-1);
	}
	for (i = cnt - 1; i; i--) {
		s[i] = (wc & 0x3f) | 0x80;
		wc >>= 6;
	}
	s[0] = (msk) | wc;
	s[cnt] = 0;
	return (cnt);
}
예제 #14
0
파일: icons.c 프로젝트: 99years/plan9
/*
 * vUpdateWriteable - update a writeable icon with a string
 */
void
vUpdateWriteable(window_handle tWindow, icon_handle tIconNumber,
	const char *szString)
{
	icon_block	tIcon;
	caret_block	tCaret;
	int		iLen;

	fail(szString == NULL);

	NO_DBG_DEC(tIconNumber);
	NO_DBG_MSG(szString);

	Error_CheckFatal(Wimp_GetIconState(tWindow, tIconNumber, &tIcon));
	NO_DBG_HEX(tIcon.flags);
	if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) {
		werr(1, "Icon %d must be indirected text", (int)tIconNumber);
		return;
	}
	strncpy(tIcon.data.indirecttext.buffer,
		szString,
		tIcon.data.indirecttext.bufflen - 1);
	/* Ensure the caret is behind the last character of the text */
	Error_CheckFatal(Wimp_GetCaretPosition(&tCaret));
	if (tCaret.window == tWindow && tCaret.icon == tIconNumber) {
		iLen = strlen(tIcon.data.indirecttext.buffer);
		if (tCaret.index != iLen) {
			tCaret.index = iLen;
			Error_CheckFatal(Wimp_SetCaretPosition(&tCaret));
		}
	}
	Error_CheckFatal(Wimp_SetIconState(tWindow, tIconNumber, 0, 0));
	vUpdateIcon(tWindow, &tIcon);
} /* end of vUpdateWriteable */
예제 #15
0
static void files_list(xmpp_stanza_t *stanza) {
  int rc; /* Return code */

  rc = pthread_mutex_lock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_lock");

  char *error_attr = xmpp_stanza_get_attribute(stanza, "error"); /* error attribute */
  wfatal(error_attr == NULL, "no error attribute in files stanza");

  if (strcmp(error_attr, "0") != 0) {
    wlog("Error in attributes: %s", error_attr);
  } else {
    char *path_attr = xmpp_stanza_get_attribute(stanza, "path"); /* path attribute */
    wfatal(path_attr == NULL, "xmpp_stanza_get_attribute [attribute = path]");

    xmpp_stanza_t *child = xmpp_stanza_get_children(stanza);
    while (child != NULL) {
      elem_t *elem = (elem_t *)malloc(sizeof(elem_t));
      wsyserr(elem == NULL, "malloc");

      elem->next = NULL;

      char *name = xmpp_stanza_get_name(child);
      wfatal(name == NULL, "xmpp_stanza_get_name");

      if (strcmp(name, "directory") == 0) {
        elem->type = DIR;
      } else if (strcmp(name, "file") == 0) {
        elem->type = REG;
      } else {
        werr("Unknown name: %s", name);
      }

      char *filename_attr = xmpp_stanza_get_attribute(child, "filename");
      wfatal(filename_attr == NULL, "xmpp_stanza_get_attribute [attribute = filename]");

      elem->filename = strdup(filename_attr);
      wsyserr(elem->filename == NULL, "strdup");

      /* Add elem in list */
      if (root == NULL) {
        root = elem;
      } else {
        last->next = elem;
      }
      last = elem;

      child = xmpp_stanza_get_next(child);
    }
  }

  /* Data set */
  signal_list = true;
  rc = pthread_cond_signal(&cond);
  wsyserr(rc != 0, "pthread_cond_signal");

  rc = pthread_mutex_unlock(&mutex);
  wsyserr(rc != 0, "pthread_mutex_unlock");
}
예제 #16
0
void
usage(void)
{
  if (printf(_(
"Usage: %s [<option> ...] <command>\n"
"\n"), BACKEND) < 0) werr("stdout");

  if (printf(_(
"Commands:\n"
"  -b|--build <directory> [<deb>]   Build an archive.\n"
"  -c|--contents <deb>              List contents.\n"
"  -I|--info <deb> [<cfile> ...]    Show info to stdout.\n"
"  -W|--show <deb>                  Show information on package(s)\n"
"  -f|--field <deb> [<cfield> ...]  Show field(s) to stdout.\n"
"  -e|--control <deb> [<directory>] Extract control info.\n"
"  -x|--extract <deb> <directory>   Extract files.\n"
"  -X|--vextract <deb> <directory>  Extract & list files.\n"
"  --fsys-tarfile <deb>             Output filesystem tarfile.\n"
"\n")) < 0) werr("stdout");

  if (printf(_(
"  -h|--help                        Show this help message.\n"
"  --version                        Show the version.\n"
"  --license|--licence              Show the copyright licensing terms.\n"
"\n")) < 0) werr("stdout");

  if (printf(_(
"<deb> is the filename of a Debian format archive.\n"
"<cfile> is the name of an administrative file component.\n"
"<cfield> is the name of a field in the main `control' file.\n"
"\n")) < 0) werr("stdout");

  if (printf(_(
"Options:\n"
"  --showformat=<format>            Use alternative format for --show.\n"
"  -D                               Enable debugging output.\n"
"  --old, --new                     Select archive format.\n"
"  --nocheck                        Suppress control file check (build bad\n"
"                                     packages).\n"
"  -z#                              Set the compression level when building.\n"
"  -Z<type>                         Set the compression type used when building.\n"
"                                     Allowed values: gzip, bzip2, lzma, none.\n"
"\n")) < 0) werr("stdout");

  if (printf(_(
"Format syntax:\n"
"  A format is a string that will be output for each package. The format\n"
"  can include the standard escape sequences \\n (newline), \\r (carriage\n"
"  return) or \\\\ (plain backslash). Package information can be included\n"
"  by inserting variable references to package fields using the ${var[;width]}\n"
"  syntax. Fields will be right-aligned unless the width is negative in which\n"
"  case left alignment will be used.\n")) < 0) werr("stdout");

  if (printf(_(
"\n"
"Use `dpkg' to install and remove packages from your system, or\n"
"`dselect' or `aptitude' for user-friendly package management.  Packages\n"
"unpacked using `dpkg-deb --extract' will be incorrectly installed !\n")) < 0)
    werr("stdout");
}
예제 #17
0
int sfx_play(context_t* p_Ctx, const std::string & p_FileName, int p_Channel,
		int p_Loops)
{
	auto l_It = g_SoundList.find(p_FileName);

	if (l_It != g_SoundList.end())
	{
		return Mix_PlayChannel(p_Channel, l_It->second, p_Loops);
	}

	const std::string l_TableFilename = std::string(SFX_TABLE)
			+ std::string("/") + p_FileName;
	const std::string l_FullName = std::string(base_directory) + "/"
			+ l_TableFilename;

	file_lock(l_TableFilename.c_str());

	SDL_RWops * l_pFileDesc = SDL_RWFromFile(l_FullName.c_str(), "r");
	if (l_pFileDesc == nullptr)
	{
		std::string l_Err = std::string("sfx_play: cannot open ")
				+ l_FullName.c_str();
		werr(LOGDESIGNER, l_Err.c_str());
		file_update(p_Ctx, l_TableFilename.c_str());
		file_unlock(l_TableFilename.c_str());
		return -1;
	}

	Mix_Chunk * l_pChunk = Mix_LoadWAV_RW(l_pFileDesc, 1);
	if (l_pChunk == nullptr)
	{
		std::string l_Err = std::string("sfx_play: cannot read ")
				+ l_FullName.c_str();
		werr(LOGDESIGNER, l_Err.c_str());
		file_update(p_Ctx, l_TableFilename.c_str());
		file_unlock(l_TableFilename.c_str());
		return -1;
	}

	g_SoundList[p_FileName] = l_pChunk;

	file_unlock(l_TableFilename.c_str());

	return Mix_PlayChannel(p_Channel, l_pChunk, p_Loops);
}
예제 #18
0
파일: saveas.c 프로젝트: 99years/plan9
static BOOL
bWrite2File(void *pvBytes, size_t tSize, FILE *pFile, const char *szFilename)
{
	if (fwrite(pvBytes, sizeof(char), tSize, pFile) != tSize) {
		werr(0, "I can't write to '%s'", szFilename);
		return FALSE;
	}
	return TRUE;
} /* end of bWrite2File */
예제 #19
0
파일: shell.c 프로젝트: Estella/wraith
char *move_bin(const char *ipath, const char *file, bool run)
{
  char *path = strdup(ipath);

  expand_tilde(&path);

  /* move the binary to the correct place */
  static char newbin[DIRMAX] = "";
  char real[DIRMAX] = "";

  simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);

  ContextNote(STR("realpath()"));
  realpath(binname, real);            /* get the realpath of binname */
  ContextNote(STR("realpath(): Success"));
  /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
  sdprintf(STR("binname: %s"), binname);
  sdprintf(STR("newbin: %s"), newbin);
  sdprintf(STR("real: %s"), real);
  if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
    bool ok = 1;

    sdprintf(STR("wrong dir, is: %s :: %s"), binname, newbin);

    unlink(newbin);
    if (copyfile(binname, newbin))
      ok = 0;

    if (ok && !can_stat(newbin)) {
       unlink(newbin);
       ok = 0;
    }

    if (ok && fixmod(newbin)) {
        unlink(newbin);
        ok = 0;
    }

    if (ok) {
      sdprintf(STR("Binary successfully moved to: %s"), newbin);
      unlink(binname);
      if (run) {
        simple_snprintf(newbin, sizeof newbin, "%s%s%s", 
                        path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file));
        system(newbin);
        sdprintf(STR("exiting to let new binary run..."));
        exit(0);
      }
    } else {
      if (run)
        werr(ERR_WRONGBINDIR);
      sdprintf(STR("Binary move failed to: %s"), newbin);
      return binname;
    }
  }
  return newbin;
}
예제 #20
0
      PluginInterfaceable* tryLoad(QPluginLoader* pluginLoader){
        this->loader = pluginLoader;

        if (!this->loadBinary()){
          werr(q_ptr, QString("Can't load binary!").arg(pluginLoader->errorString()));
          return 0;
        } else {
          if (!pluginLoader->isLoaded()){
            werr(q_ptr, QString("Failed to load plugin binary. Error: %1").arg(pluginLoader->errorString()));
            return 0;
          }

          else
            winfo(q_ptr, QString("Plugin interface loaded for %1").arg(id.toString()));
        }

        return this->getPluginInterface();
      }
예제 #21
0
/*
 * tOpenFont - make the specified font the current font
 *
 * Returns the font reference number for use in a draw file
 */
drawfile_fontref
tOpenFont(UCHAR ucWordFontNumber, USHORT usFontStyle, USHORT usWordFontSize)
{
    os_error	*e;
    const char	*szOurFontname;
    font_handle	tFont;
    int	iFontnumber;

    NO_DBG_MSG("tOpenFont");
    NO_DBG_DEC(ucWordFontNumber);
    NO_DBG_HEX(usFontStyle);
    NO_DBG_DEC(usWordFontSize);

    /* Keep the relevant bits */
    usFontStyle &= FONT_BOLD|FONT_ITALIC;
    NO_DBG_HEX(usFontStyle);

    iFontnumber = iGetFontByNumber(ucWordFontNumber, usFontStyle);
    szOurFontname = szGetOurFontname(iFontnumber);
    if (szOurFontname == NULL || szOurFontname[0] == '\0') {
        tFontCurr = (font_handle)-1;
        return (byte)0;
    }
    NO_DBG_MSG(szOurFontname);
    e = Font_FindFont(&tFont, (char *)szOurFontname,
                      (int)usWordFontSize * 8, (int)usWordFontSize * 8,
                      0, 0);
    if (e != NULL) {
        switch (e->errnum) {
        case 523:
            werr(0, "%s", e->errmess);
            break;
        default:
            werr(0, "Open font error %d: %s",
                 e->errnum, e->errmess);
            break;
        }
        tFontCurr = (font_handle)-1;
        return (drawfile_fontref)0;
    }
    tFontCurr = tFont;
    NO_DBG_DEC(tFontCurr);
    return (drawfile_fontref)(iFontnumber + 1);
} /* end of tOpenFont */
예제 #22
0
파일: misc.c 프로젝트: ClaudioVZ/crengine
/*
 * bReadBuffer
 * This function fills the specified buffer with the specified number of bytes,
 * starting at the specified offset within the Big/Small Block Depot.
 *
 * Returns TRUE when successful, otherwise FALSE
 */
BOOL
bReadBuffer(FILE *pFile, ULONG ulStartBlock,
	const ULONG *aulBlockDepot, size_t tBlockDepotLen, size_t tBlockSize,
	UCHAR *aucBuffer, ULONG ulOffset, size_t tToRead)
{
	ULONG	ulBegin, ulIndex;
	size_t	tLen;

	fail(pFile == NULL);
	fail(ulStartBlock > MAX_BLOCKNUMBER && ulStartBlock != END_OF_CHAIN);
	fail(aulBlockDepot == NULL);
	fail(tBlockSize != BIG_BLOCK_SIZE && tBlockSize != SMALL_BLOCK_SIZE);
	fail(aucBuffer == NULL);
	fail(tToRead == 0);

	for (ulIndex = ulStartBlock;
	     ulIndex != END_OF_CHAIN && tToRead != 0;
	     ulIndex = aulBlockDepot[ulIndex]) {
		if (ulIndex >= (ULONG)tBlockDepotLen) {
			DBG_DEC(ulIndex);
			DBG_DEC(tBlockDepotLen);
			if (tBlockSize >= BIG_BLOCK_SIZE) {
				werr(1, "The Big Block Depot is damaged");
			} else {
				werr(1, "The Small Block Depot is damaged");
			}
		}
		if (ulOffset >= (ULONG)tBlockSize) {
			ulOffset -= tBlockSize;
			continue;
		}
		ulBegin = ulDepotOffset(ulIndex, tBlockSize) + ulOffset;
		tLen = min(tBlockSize - (size_t)ulOffset, tToRead);
		ulOffset = 0;
		if (!bReadBytes(aucBuffer, tLen, ulBegin, pFile)) {
			werr(0, "Read big block 0x%lx not possible", ulBegin);
			return FALSE;
		}
		aucBuffer += tLen;
		tToRead -= tLen;
	}
	DBG_DEC_C(tToRead != 0, tToRead);
	return tToRead == 0;
} /* end of bReadBuffer */
예제 #23
0
int
tomb_none(char *mb, wchar_t wc)
{
	if (mb_cur_max != 1) {
		werr("invalid or unsupported multibyte locale");
		return (-1);
	}
	*(uint8_t *)mb = (wc & 0xff);
	mb[1] = 0;
	return (1);
}
예제 #24
0
파일: blocklist.c 프로젝트: 99years/plan9
/*
 * bAdd2TextBlockList - add an element to the text block list
 *
 * returns: TRUE when successful, otherwise FALSE
 */
BOOL
bAdd2TextBlockList(const text_block_type *pTextBlock)
{
	list_mem_type	*pListMember;

	fail(pTextBlock == NULL);
	fail(pTextBlock->ulFileOffset == FC_INVALID);
	fail(pTextBlock->ulCharPos == CP_INVALID);
	fail(pTextBlock->ulLength == 0);
	fail(pTextBlock->bUsesUnicode && odd(pTextBlock->ulLength));

	NO_DBG_MSG("bAdd2TextBlockList");
	NO_DBG_HEX(pTextBlock->ulFileOffset);
	NO_DBG_HEX(pTextBlock->ulCharPos);
	NO_DBG_HEX(pTextBlock->ulLength);
	NO_DBG_DEC(pTextBlock->bUsesUnicode);
	NO_DBG_DEC(pTextBlock->usPropMod);

	if (pTextBlock->ulFileOffset == FC_INVALID ||
	    pTextBlock->ulCharPos == CP_INVALID ||
	    pTextBlock->ulLength == 0 ||
	    (pTextBlock->bUsesUnicode && odd(pTextBlock->ulLength))) {
		werr(0, "Software (textblock) error");
		return FALSE;
	}
	/*
	 * Check for continuous blocks of the same character size and
	 * the same properties modifier
	 */
	if (pBlockLast != NULL &&
	    pBlockLast->tInfo.ulFileOffset +
	     pBlockLast->tInfo.ulLength == pTextBlock->ulFileOffset &&
	    pBlockLast->tInfo.ulCharPos +
	     pBlockLast->tInfo.ulLength == pTextBlock->ulCharPos &&
	    pBlockLast->tInfo.bUsesUnicode == pTextBlock->bUsesUnicode &&
	    pBlockLast->tInfo.usPropMod == pTextBlock->usPropMod) {
		/* These are continous blocks */
		pBlockLast->tInfo.ulLength += pTextBlock->ulLength;
		return TRUE;
	}
	/* Make a new block */
	pListMember = xmalloc(sizeof(list_mem_type));
	/* Add the block to the list */
	pListMember->tInfo = *pTextBlock;
	pListMember->pNext = NULL;
	if (pTextAnchor == NULL) {
		pTextAnchor = pListMember;
	} else {
		fail(pBlockLast == NULL);
		pBlockLast->pNext = pListMember;
	}
	pBlockLast = pListMember;
	return TRUE;
} /* end of bAdd2TextBlockList */
예제 #25
0
파일: blocklist.c 프로젝트: 99years/plan9
/*
 * vCheckList - check the number of bytes in a block list
 */
static void
vCheckList(const list_mem_type *pAnchor, ULONG ulListLen, char *szMsg)
{
	ULONG		ulTotal;

	ulTotal = ulComputeListLength(pAnchor);
	DBG_DEC(ulTotal);
	if (ulTotal != ulListLen) {
		DBG_DEC(ulListLen);
		werr(1, szMsg);
	}
} /* end of vCheckList */
예제 #26
0
/*
 * This is used for 8-bit encodings.
 */
int
towide_none(wchar_t *c, const char *mb, unsigned n)
{
	_NOTE(ARGUNUSED(n));

	if (mb_cur_max != 1) {
		werr("invalid or unsupported multibyte locale");
		return (-1);
	}
	*c = (uint8_t)*mb;
	return (1);
}
예제 #27
0
/*
 * GB18030.  This encodes as 8, 16, or 32-bits.
 * 7-bit values are in 1 byte,  4 byte sequences are used when
 * the second byte encodes 0x30-39 and all other sequences are 2 bytes.
 */
int
towide_gb18030(wchar_t *wc, const char *mb, unsigned n)
{
	wchar_t	c;

	c = *(uint8_t *)mb;

	if ((c & 0x80) == 0) {
		/* 7-bit */
		*wc = c;
		return (1);
	}
	if (n < 2) {
		werr("incomplete character sequence (%s)", show_mb(mb));
		return (-1);
	}

	/* pull in the second byte */
	c <<= 8;
	c |= (uint8_t)(mb[1]);

	if (((c & 0xff) >= 0x30) && ((c & 0xff) <= 0x39)) {
		if (n < 4) {
			werr("incomplete 4-byte character sequence (%s)",
			    show_mb(mb));
			return (-1);
		}
		c <<= 8;
		c |= (uint8_t)(mb[2]);
		c <<= 8;
		c |= (uint8_t)(mb[3]);
		*wc = c;
		return (4);
	}

	*wc = c;
	return (2);
}
예제 #28
0
/*********************************************************************
 return RET_NOK on error
 *********************************************************************/
ret_code_t network_connect(context_t * context, const char * hostname)
{
	IPaddress ip;
	TCPsocket socket;

	wlog(LOGUSER, "Trying to connect to %s:%d", hostname, PORT);

	if (SDLNet_Init() < 0)
	{
		werr(LOGUSER, "Can't init SDLNet: %s\n", SDLNet_GetError());
		return RET_NOK;
	}

	if (SDLNet_ResolveHost(&ip, hostname, PORT) < 0)
	{
		werr(LOGUSER, "Can't resolve %s:%d : %s\n", hostname, PORT,
				SDLNet_GetError());
		return RET_NOK;
	}

	if (!(socket = SDLNet_TCP_Open(&ip)))
	{
		werr(LOGUSER, "Can't connect to %s:%d : %s\n", hostname, PORT,
				SDLNet_GetError());
		return RET_NOK;
	}

	wlog(LOGUSER, "Connected to %s:%d", hostname, PORT);

	context_set_hostname(context, hostname);
	context_set_socket(context, socket);

	SDL_CreateThread(async_recv, "async_recv", (void*) context);

	return RET_OK;
}
예제 #29
0
/*
 * EUC forms.  EUC encodings are "variable".  FreeBSD carries some additional
 * variable data to encode these, but we're going to treat each as independent
 * instead.  Its the only way we can sensibly move forward.
 *
 * Note that the way in which the different EUC forms vary is how wide
 * CS2 and CS3 are and what the first byte of them is.
 */
static int
towide_euc_impl(wchar_t *wc, const char *mb, unsigned n,
    uint8_t cs2, uint8_t cs2width, uint8_t cs3, uint8_t cs3width)
{
	int i;
	int width = 2;
	wchar_t	c;

	c = *(uint8_t *)mb;

	/*
	 * All variations of EUC encode 7-bit ASCII as one byte, and use
	 * additional bytes for more than that.
	 */
	if ((c & 0x80) == 0) {
		/* 7-bit */
		*wc = c;
		return (1);
	}

	/*
	 * All EUC variants reserve 0xa1-0xff to identify CS1, which
	 * is always two bytes wide.  Note that unused CS will be zero,
	 * and that cannot be true because we know that the high order
	 * bit must be set.
	 */
	if (c >= 0xa1) {
		width = 2;
	} else if (c == cs2) {
		width = cs2width;
	} else if (c == cs3) {
		width = cs3width;
	}

	if (n < width) {
		werr("incomplete character sequence (%s)", show_mb(mb));
		return (-1);
	}

	for (i = 1; i < width; i++) {
		/* pull in the next byte */
		c <<= 8;
		c |= (uint8_t)(mb[i]);
	}

	*wc = c;
	return (width);
}
예제 #30
0
/*
 * bGetDocumentText - make a list of the text blocks of a Word document
 *
 * Return TRUE when succesful, otherwise FALSE
 */
static BOOL
bGetDocumentText(FILE *pFile, const UCHAR *aucHeader)
{
	text_block_type	tTextBlock;
	ULONG	ulBeginOfText, ulEndOfText;
	ULONG	ulTextLen;
	UCHAR	ucDocStatus;
	BOOL    bFastSaved;

	fail(pFile == NULL);
	fail(aucHeader == NULL);

	DBG_MSG("bGetDocumentText");

	NO_DBG_PRINT_BLOCK(aucHeader, 0x20);

	/* Get the status flags from the header */
	ucDocStatus = ucGetByte(0x0a, aucHeader);
	DBG_HEX(ucDocStatus);
	bFastSaved = (ucDocStatus & BIT(5)) != 0;
	DBG_MSG_C(bFastSaved, "This document is Fast Saved");
	if (bFastSaved) {
		werr(0, "MacWord: fast saved documents are not supported yet");
		return FALSE;
	}

	/* Get length information */
	ulBeginOfText = ulGetLongBE(0x14, aucHeader);
	DBG_HEX(ulBeginOfText);
	ulEndOfText = ulGetLongBE(0x18, aucHeader);
	DBG_HEX(ulEndOfText);
	ulTextLen = ulEndOfText - ulBeginOfText;
	DBG_DEC(ulTextLen);
	tTextBlock.ulFileOffset = ulBeginOfText;
	tTextBlock.ulCharPos = ulBeginOfText;
	tTextBlock.ulLength = ulTextLen;
	tTextBlock.bUsesUnicode = FALSE;
	tTextBlock.usPropMod = IGNORE_PROPMOD;
	if (!bAdd2TextBlockList(&tTextBlock)) {
		DBG_HEX(tTextBlock.ulFileOffset);
		DBG_HEX(tTextBlock.ulCharPos);
		DBG_DEC(tTextBlock.ulLength);
		DBG_DEC(tTextBlock.bUsesUnicode);
		DBG_DEC(tTextBlock.usPropMod);
		return FALSE;
	}
	return TRUE;
} /* end of bGetDocumentText */