Exemple #1
0
/* *command handler */
_kernel_oserror *command_handler(const char *arg_string, int argc,
                                 int cmd_no, void *pw)
{
    UNUSED(arg_string);
    UNUSED(argc);
    UNUSED(pw);

    switch (cmd_no) {
    case CMD_Iconv:
        return do_iconv(argc, arg_string);
        break;
    case CMD_ReadAliases:
    {
        const char *aliases = get_aliases_path();

        if (aliases == NULL)
            return NULL;

        free_alias_data();
        if (!create_alias_data(aliases)) {
            strcpy(ErrorGeneric.errmess,
                   "Failed reading Aliases file.");
            return &ErrorGeneric;
        }
    }
    break;
    default:
        break;
    }

    return NULL;
}
Exemple #2
0
static int
fill_comments(struct ogg_context *ctx, struct ogg_oggfile *ogg)
{
    OggVorbis_File  ovf;
    vorbis_comment *ovc;
    char           *key, *value;
    int             i;

    assert(ctx != NULL);
    assert(ogg != NULL);

    if (ov_fopen(ogg->filename, &ovf) != 0) {
        warnx("could not open file: %s", ogg->filename);
        return (1);
    }
    if ((ovc = ov_comment(&ovf, -1)) == NULL) {
        warnx("could not read comments for file: %s", ogg->filename);
        return (1);
    }
    for (i = 0; i < ovc->comments; i++) {
        value = ovc->user_comments[i];
        key = strsep(&value, "=");
        if (strcasecmp(key, "artist") == 0)
            do_iconv(ctx, value, ogg->artist, sizeof(ogg->artist));
        else if (strcasecmp(key, "album") == 0)
            do_iconv(ctx, value, ogg->album, sizeof(ogg->album));
        else if (strcasecmp(key, "title") == 0)
            do_iconv(ctx, value, ogg->title, sizeof(ogg->title));
        if (ogg->artist == NULL || ogg->album == NULL || ogg->title == NULL) {
            warnx("insufficient comments for file: %s", ogg->filename);
            return (1);
        }
    }

    if (ov_clear(&ovf) != 0)
        warnx("could not close file: %s", ogg->filename);

    return (0);
}
Exemple #3
0
palo_err utf82wcs(struct conversions *convs, wchar_t **wcs, const char *utf8_str) {
#if defined(WIN32) || defined(WIN64)
	int len;

	if ((len = MultiByteToWideChar(CP_UTF8, 0, utf8_str, -1, NULL, 0)) == 0) {
		return PALO_ERR_STRING;
	}
	
	/* len in wchar's */
	*wcs = (wchar_t*)malloc(len*sizeof(wchar_t));
	if (*wcs == NULL) {
			return PALO_ERR_NO_MEM;
	}
	utf82wcs_conv(*wcs, utf8_str, len);

	return PALO_SUCCESS;
#else
	return do_iconv(convs->utf82wchar_t, utf8_str, (strlen(utf8_str) + 1)*sizeof(char), (char**)wcs);
#endif
}
Exemple #4
0
palo_err wcs2utf8(struct conversions *convs, char **utf8_str, const wchar_t *s) {
#if defined(WIN32) || defined(WIN64)
	size_t len;

	if ((len = wcs2utf8_len(s, (size_t) - 1)) == (size_t) - 1) {
		return PALO_ERR_STRING;
	}

	/* len in bytes */
	*utf8_str = (char*)malloc(len);
	if (*utf8_str == NULL) {
			return PALO_ERR_NO_MEM;
	}
	wcs2utf8_conv(*utf8_str, s, len);

	return PALO_SUCCESS;
#else
	return do_iconv(convs->wchar_t2utf8, (char*)s, (wcslen(s) + 1)*sizeof(wchar_t), utf8_str);
#endif
}
Exemple #5
0
palo_err mbs2utf8(struct conversions *convs, char **utf8_str, const char *mbs_str) {
#if defined(WIN32) || defined(WIN64)
	palo_err result;
	wchar_t *u;

	result = mbs2wcs(&u, mbs_str);
	if (result != PALO_SUCCESS) {
		return result;
	}

	result = wcs2utf8(convs, utf8_str, u);
	free(u);
	if (result != PALO_SUCCESS) {
		return result;
	}

	return PALO_SUCCESS;
#else
	return do_iconv(convs->local2utf8, mbs_str, (strlen(mbs_str) + 1)*sizeof(char), utf8_str);
#endif
}
Exemple #6
0
palo_err utf82mbs(struct conversions *convs, char **mbs, const char *utf8_str) {
#if defined(WIN32) || defined(WIN64)
	palo_err result;
	wchar_t *t;

	result = utf82wcs(convs, &t, utf8_str);
	if (result != PALO_SUCCESS) {
		return PALO_ERR_STRING;
	}

	result = wcs2mbs(mbs, t);
	free(t);
	if (result != PALO_SUCCESS) {
		return result;
	}

	return PALO_SUCCESS;
#else
	return do_iconv(convs->utf82local, utf8_str, (strlen(utf8_str) + 1)*sizeof(char), mbs);
#endif
}
Exemple #7
0
static unsigned char*
_get_utf8_text(const id3_ucs4_t* native_text)
{
	unsigned char *utf8_text = NULL;
	char *in, *in8, *iconv_buf;
	iconv_result rc;
	int i, n;

	in = (char*)id3_ucs4_latin1duplicate(native_text);
	if(!in)
	{
		goto out;
	}

	in8 = (char*)id3_ucs4_utf8duplicate(native_text);
	if(!in8)
	{
		free(in);
		goto out;
	}

	iconv_buf = (char*)calloc(MAX_ICONV_BUF, sizeof(char));
	if(!iconv_buf)
	{
		free(in); free(in8);
		goto out;
	}

	i = lang_index;
	// (1) try utf8 -> default
	rc = do_iconv(iconv_map[i].cpnames[0], "UTF-8", in8, strlen(in8), iconv_buf, MAX_ICONV_BUF);
	if(rc == ICONV_OK)
	{
		utf8_text = (unsigned char*)in8;
		free(iconv_buf);
	}
	else if(rc == ICONV_TRYNEXT)
	{
		// (2) try default -> utf8
		rc = do_iconv("UTF-8", iconv_map[i].cpnames[0], in, strlen(in), iconv_buf, MAX_ICONV_BUF);
		if(rc == ICONV_OK)
		{
			utf8_text = (unsigned char*)iconv_buf;
		}
		else if(rc == ICONV_TRYNEXT)
		{
			// (3) try other encodes
			for(n = 1; n < N_LANG_ALT && iconv_map[i].cpnames[n]; n++)
			{
				rc = do_iconv("UTF-8", iconv_map[i].cpnames[n], in, strlen(in), iconv_buf, MAX_ICONV_BUF);
				if(rc == ICONV_OK)
				{
					utf8_text = (unsigned char*)iconv_buf;
					break;
				}
			}
			if(!utf8_text)
			{
				// cannot iconv
				utf8_text = (unsigned char*)id3_ucs4_utf8duplicate(native_text);
				free(iconv_buf);
			}
		}
		free(in8);
	}
	free(in);

 out:
	if(!utf8_text)
	{
		utf8_text = (unsigned char*)strdup("UNKNOWN");
	}

	return utf8_text;
}
Exemple #8
0
 inline size_t call_iconv(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
 {
     return do_iconv( iconv, d, in,insize,out,outsize);
 }
Exemple #9
0
 inline size_t call_iconv(iconv_t d,char **in,size_t *insize,char **out,size_t *outsize)
 {
     char const **rin = const_cast<char const **>(in);
     return do_iconv(__iconv, d, in,insize,out,outsize);
 }
Exemple #10
0
/*
 * The main terminal loop:
 *	- If there are characters received send them
 *	  to the screen via the appropriate translate function.
 */
int do_terminal(void)
{
  char buf[128];
  int buf_offset = 0;
  int c;
  int x;
  int blen;
  int zauto = 0;
  static const char zsig[] = "**\030B00";
  int zpos = 0;
  const char *s;
  dirflush = 0;
  WIN *error_on_open_window = NULL;

dirty_goto:
  /* Show off or online time */
  update_status_time();

  /* If the status line was shown temporarily, delete it again. */
  if (tempst) {
    tempst = 0;
    mc_wclose(st, 1);
    st = NULL;
  }


  /* Auto Zmodem? */
  if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z')
    zauto = P_PAUTO[0];
  /* Set the terminal modes */
  setcbreak(2); /* Raw, no echo */

  keyboard(KSTART, 0);

  /* Main loop */
  while (1) {
    /* See if window size changed */
    if (size_changed) {
      size_changed = 0;
      wrapln = us->wrap;
      /* I got the resize code going again! Yeah! */
      mc_wclose(us, 0);
      us = NULL;
      if (st)
        mc_wclose(st, 0);
      st = NULL;
      mc_wclose(stdwin, 0);
      if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0)
        leave(_("Could not re-initialize window system."));
      /* Set the terminal modes */
      setcbreak(2); /* Raw, no echo */
      init_emul(terminal, 0);
    }
    /* Update the timer. */
    timer_update();

    /* check if device is ok, if not, try to open it */
    if (!get_device_status(portfd_connected)) {
      /* Ok, it's gone, most probably someone unplugged the USB-serial, we
       * need to free the FD so that a replug can get the same device
       * filename, open it again and be back */
      int reopen = portfd == -1;
      close(portfd);
      lockfile_remove();
      portfd = -1;
      if (open_term(reopen, reopen, 1) < 0) {
        if (!error_on_open_window)
          error_on_open_window = mc_tell(_("Cannot open %s!"), dial_tty);
      } else {
        if (error_on_open_window) {
          mc_wclose(error_on_open_window, 1);
          error_on_open_window = NULL;
        }
      }
    }

    /* Check for I/O or timer. */
    x = check_io(portfd_connected, 0, 1000,
                 buf + buf_offset, sizeof(buf) - buf_offset, &blen);
    blen += buf_offset;
    buf_offset = 0;

    /* Data from the modem to the screen. */
    if ((x & 1) == 1) {
      char obuf[sizeof(buf)];
      char *ptr;

      if (using_iconv()) {
        char *otmp = obuf;
        size_t output_len = sizeof(obuf);
        size_t input_len = blen;

        ptr = buf;
        do_iconv(&ptr, &input_len, &otmp, &output_len);

        // something happened at all?
        if (output_len < sizeof(obuf))
          {
            if (input_len)
              { // something remained, we need to adapt buf accordingly
                memmove(buf, ptr, input_len);
                buf_offset = input_len;
              }

            blen = sizeof(obuf) - output_len;
            ptr = obuf;
          }
	else
	  ptr = buf;
      } else {
        ptr = buf;
      }

      while (blen-- > 0) {
        /* Auto zmodem detect */
        if (zauto) {
          if (zsig[zpos] == *ptr)
            zpos++;
          else
            zpos = 0;
        }
        if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S')
          *ptr &= 0x7f;
        if (display_hex) {
          unsigned char c = *ptr++;
          unsigned char u = c >> 4;
          c &= 0xf;
          vt_out(u > 9 ? 'a' + (u - 10) : '0' + u);
          vt_out(c > 9 ? 'a' + (c - 10) : '0' + c);
          vt_out(' ');
        } else
          vt_out(*ptr++);
        if (zauto && zsig[zpos] == 0) {
          dirflush = 1;
          keyboard(KSTOP, 0);
          updown('D', zauto - 'A');
          dirflush = 0;
          zpos = 0;
          blen = 0;
          goto dirty_goto;
        }
      }
      mc_wflush();
    }