Exemplo n.º 1
0
static void
_show_clip_list(MPLS_PL *pl, int level)
{
    int ii;

    for (ii = 0; ii < pl->list_count; ii++) {
        MPLS_PI *pi;
        str_t *m2ts_file;

        pi = &pl->play_item[ii];
        m2ts_file = str_substr(pi->clip_id, 0, 5);
        str_append(m2ts_file, ".m2ts");
        if (verbose) {
            uint32_t duration;

            duration = pi->out_time - pi->in_time;
            indent_printf(level, "%s -- Duration: %d:%02d", m2ts_file->buf,
                        duration / (45000 * 60), (duration / 45000) % 60);
        } else {
            indent_printf(level, "%s", m2ts_file->buf);
        }
        str_free(m2ts_file);
        free(m2ts_file);
    }
}
Exemplo n.º 2
0
static void
_show_marks(MPLS_PL *pl, int level)
{
    int ii;

    for (ii = 0; ii < pl->mark_count; ii++) {
        MPLS_PI *pi;
        MPLS_PLM *plm;
        str_t *clip_id;
        int min;
        double sec;

        plm = &pl->play_mark[ii];
        indent_printf(level, "PlayMark %d", ii);
        indent_printf(level+1, "Type: %02x", plm->mark_type);
        if (plm->play_item_ref < pl->list_count) {
            pi = &pl->play_item[plm->play_item_ref];
            clip_id = str_substr(pi->clip_id, 0, 5);
            indent_printf(level+1, "PlayItem: %s", clip_id->buf);
            str_free(clip_id);
            free(clip_id);
        } else {
            indent_printf(level+1, "PlayItem: Invalid reference");
        }
        indent_printf(level+1, "Time (ticks): %lu", plm->time);
        min = plm->abs_start / (45000*60);
        sec = (double)(plm->abs_start - min * 45000 * 60) / 45000;
        indent_printf(level+1, "Abs Time (mm:ss.ms): %d:%.2f", min, sec);
        printf("\n");
    }
}
Exemplo n.º 3
0
static void
_show_details(MPLS_PL *pl, int level)
{
    int ii, jj;

    for (ii = 0; ii < pl->list_count; ii++) {
        MPLS_PI *pi;
        str_t *clip_id;

        pi = &pl->play_item[ii];
        clip_id = str_substr(pi->clip_id, 0, 5);
        indent_printf(level, "Clip Id %s", clip_id->buf);
        str_free(clip_id);
        free(clip_id);
        indent_printf(level+1, "Connection Condition: %02x", 
                        pi->connection_condition);
        indent_printf(level+1, "Stc Id: %02x", pi->stc_id);
        indent_printf(level+1, "In-Time: %d", pi->in_time);
        indent_printf(level+1, "Out-Time: %d", pi->out_time);
        for (jj = 0; jj < pi->stn.num_video; jj++) {
            indent_printf(level+1, "Video Stream %d:", jj);
            _show_stream(&pi->stn.video[jj], level + 2);
        }
        for (jj = 0; jj < pi->stn.num_audio; jj++) {
            indent_printf(level+1, "Audio Stream %d:", jj);
            _show_stream(&pi->stn.audio[jj], level + 2);
        }
        for (jj = 0; jj < pi->stn.num_pg; jj++) {
            indent_printf(level+1, "Presentation Graphics Stream %d:", jj);
            _show_stream(&pi->stn.pg[jj], level + 2);
        }
        printf("\n");
    }
}
Exemplo n.º 4
0
/* Chomp the string, i.e. remove extra spaces/illegal chars from the ends,
    pointers can be same */
void str_chomp(str_t *str, const str_t *src)
{
    size_t st = 0, en = src->len;

    while (!isgraph(src->c_str[st]) && (st < en))
        st++;
    while (!isgraph(src->c_str[en-1]) && (en > 0))
        en--;

    str_substr(str, src, (int)st, (int)en);
}
Exemplo n.º 5
0
uint STDCALL str_getdirfile( pstr src, pstr dir, pstr name )
{
   uint   separ = str_find( src, 0, SLASH, 1 );
   uint   off;

   off = separ >= str_len( src ) ? 0 : separ + 1;
   
   if ( name )
      str_copyzero( name, str_ptr( src ) + off );
   if ( dir )
      str_substr( dir, src, 0, separ < str_len( src ) ? separ : 0 );
   return 1;
}
Exemplo n.º 6
0
void
QtSqlConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    ScopedLock lock(drv_->conn_mux_);
    own_handle_ = true;
    conn_name_ = dialect->get_name() + _T("_") + source.db()
        + _T("_") + to_string(drv_->seq_);
    ++drv_->seq_;
    String driver = source.driver();
    bool eat_slash = false;
    if (driver == _T("QTSQL"))
    {
        if (dialect->get_name() == _T("MYSQL"))
            driver = _T("QMYSQL");
        else if (dialect->get_name() == _T("POSTGRES"))
            driver = _T("QPSQL");
        else if (dialect->get_name() == _T("ORACLE"))
            driver = _T("QOCI");
        else if (dialect->get_name() == _T("INTERBASE"))
            driver = _T("QIBASE");
        else if (dialect->get_name() == _T("SQLITE"))
            driver = _T("QSQLITE");
        if (dialect->native_driver_eats_slash()
                && !str_empty(source.db())
                && char_code(source.db()[0]) == '/')
            eat_slash = true;
    }
    conn_ = new QSqlDatabase(QSqlDatabase::addDatabase(driver, conn_name_));
    if (eat_slash)
        conn_->setDatabaseName(str_substr(source.db(), 1));
    else
        conn_->setDatabaseName(source.db());
    conn_->setUserName(source.user());
    conn_->setPassword(source.passwd());
    if (source.port() > 0)
        conn_->setPort(source.port());
    if (!str_empty(source.host()))
        conn_->setHostName(source.host());
    String options;
    Strings keys = source.options();
    for (size_t i = 0; i < keys.size(); ++i) {
        if (!str_empty(options))
            options += _T(";");
        options += keys[i] + _T("=") + source[keys[i]];
    }
    if (!str_empty(options))
        conn_->setConnectOptions(options);
    if (!conn_->open())
        throw DBError(conn_->lastError().text());
}
Exemplo n.º 7
0
/* GPU disassembler tool */
void si_emu_disasm(char *path)
{
	struct elf_file_t *elf_file;
	struct elf_symbol_t *symbol;
	struct elf_section_t *section;

	struct si_bin_file_t *amd_bin;

	char kernel_name[MAX_STRING_SIZE];

	int i;

	/* Initialize disassembler */
	si_disasm_init();

	/* Decode external ELF */
	elf_file = elf_file_create_from_path(path);
	for (i = 0; i < list_count(elf_file->symbol_table); i++)
	{
		/* Get symbol and section */
		symbol = list_get(elf_file->symbol_table, i);
		section = list_get(elf_file->section_list, symbol->section);
		if (!section)
			continue;

		/* If symbol is '__OpenCL_XXX_kernel', it points to internal ELF */
		if (str_prefix(symbol->name, "__OpenCL_") && str_suffix(symbol->name, "_kernel"))
		{
			/* Decode internal ELF */
			str_substr(kernel_name, sizeof(kernel_name), symbol->name, 9, strlen(symbol->name) - 16);
			amd_bin = si_bin_file_create(section->buffer.ptr + symbol->value, symbol->size, kernel_name);

			/* Get kernel name */
			printf("**\n** Disassembly for '__kernel %s'\n**\n\n", kernel_name);
			si_disasm_buffer(&amd_bin->enc_dict_entry_southern_islands->sec_text_buffer, stdout);
			printf("\n\n\n");

			/* Free internal ELF */
			si_bin_file_free(amd_bin);
		}
	}

	/* Free external ELF */
	elf_file_free(elf_file);
	si_disasm_done();

	/* End */
	mhandle_done();
	exit(0);
}
Exemplo n.º 8
0
static mrb_value
mrb_str_aref_m(mrb_state *mrb, mrb_value str)
{
  mrb_value a1, a2;
  int argc;

  argc = mrb_get_args(mrb, "o|o", &a1, &a2);
  if (argc == 2) {
    regexp_check(mrb, a1);
    return str_substr(mrb, str, mrb_fixnum(a1), mrb_fixnum(a2));
  }
  if (argc != 1) {
    mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%S for 1)", mrb_fixnum_value(argc));
  }
  return mrb_str_aref(mrb, str, a1);
}
Exemplo n.º 9
0
ADTList list_from_str(char *str, void *(*from_str)(char *)) {
    ADTList list = list_new();
    int len = (int) strlen(str);
    for (int i = 0, escape = 0, start = 0; i <= len; i++) {
        if ((str[i] == ',' && !escape) || (i == len && len > 0)) {
            char *substr = str_substr(str, start, i - start);
            char *unescaped = str_unescape(substr);
            list_append(list, from_str(unescaped));
            start = i + 1;
            free(unescaped);
            free(substr);
        }
        if (str[i] == '\\' && !escape)
            escape = 1;
        else
            escape = 0;
    }
    return list;
}
Exemplo n.º 10
0
static int
_filter_repeats(MPLS_PL *pl, int repeats)
{
    int ii;

    for (ii = 0; ii < pl->list_count; ii++) {
        MPLS_PI *pi;
        str_t *m2ts_file;

        pi = &pl->play_item[ii];
        m2ts_file = str_substr(pi->clip_id, 0, 5);
        // Ignore titles with repeated segments
        if (_find_repeats(pl, m2ts_file->buf) > repeats) {
            return 0;
        }
        str_free(m2ts_file);
        free(m2ts_file);
    }
    return 1;
}
Exemplo n.º 11
0
static int
_find_repeats(MPLS_PL *pl, const char *m2ts)
{
    int ii, count = 0;

    for (ii = 0; ii < pl->list_count; ii++) {
        MPLS_PI *pi;
        str_t *m2ts_file;

        pi = &pl->play_item[ii];
        m2ts_file = str_substr(pi->clip_id, 0, 5);
        // Ignore titles with repeated segments
        if (strcmp(m2ts_file->buf, m2ts) == 0) {
            count++;
        }
        str_free(m2ts_file);
        free(m2ts_file);
    }
    return count;
}
Exemplo n.º 12
0
static mrb_value
mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx)
{
  mrb_int idx;

  regexp_check(mrb, indx);
  switch (mrb_type(indx)) {
    case MRB_TT_FIXNUM:
      idx = mrb_fixnum(indx);

num_index:
      str = str_substr(mrb, str, idx, 1);
      if (!mrb_nil_p(str) && RSTRING_LEN(str) == 0) return mrb_nil_value();
      return str;

    case MRB_TT_STRING:
      if (str_index(mrb, str, indx, 0) != -1)
        return mrb_str_dup(mrb, indx);
      return mrb_nil_value();

    case MRB_TT_RANGE:
      /* check if indx is Range */
      {
        mrb_int beg, len;
        mrb_value tmp;

        len = RSTRING_LEN_UTF8(str);
        if (mrb_range_beg_len(mrb, indx, &beg, &len, len)) {
          tmp = str_subseq(mrb, str, beg, len);
          return tmp;
        }
        else {
          return mrb_nil_value();
        }
      }
    default:
      idx = mrb_fixnum(indx);
      goto num_index;
    }
    return mrb_nil_value();    /* not reached */
}
Exemplo n.º 13
0
Arquivo: test.c Projeto: Jing0/neolibc
int main(int argc, char const *argv[]) {
    /* str_new */
    str_t string = str_new();
    /* str_set */
    str_set(string, "   %d%d%d", 1, 2, 3);
    /* str_append */
    str_append(string, "appending   end");
    /* str_println */
    str_println(string);
    /* str_reverse */
    str_reverse(string);
    str_println(string);
    /* str_length */
    printf("size before trimming:\t%zu\n", str_length(string));
    /* str_trim */
    str_trim(string);
    printf("size after trimming:\t%zu\n", str_length(string));
    /* str_substr */
    str_t substr = str_substr(string, 0, 3);
    printf("substr before swap:\t");
    str_println(substr);
    printf("string before swap:\t");
    str_println(string);
    str_swap(substr, string);
    printf("substr after swap:\t");
    str_println(substr);
    printf("string after swap:\t");
    str_println(string);
    printf("is string empty?\t%s\n",
           str_isempty(string) ? "Yes" : "No");
    printf("is substr equal to string?\t%s\n",
           str_compare(substr, string) ? "No" : "Yes");

    /* str_readFromFile */
    str_readFromFile(string, "neostring.c");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    str_set(string, "ok");
    printf("Before trimToSize():\n");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    /* str_trimToSize */
    str_trimToSize(string);
    printf("After trimToSize():\n");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    str_set(string, "hello, world");
    str_println(string);
    printf("%zu\n", string->size);
    printf("string has prefix ello?\t%s\n", str_hasPrefix(string, "ello") ? "Yes" : "No");
    printf("%zu\n", string->size);
    printf("string has suffix orld?\t%s\n", str_hasSuffix(string, "orld") ? "Yes" : "No");
    /* str_clone */
    str_t clone = str_clone(string);
    /* str_toupper */
    str_toupper(clone);
    /* str_writeToFile */
    str_writeToFile(clone, "./test.txt");
    /* str_destroy */
    str_destroy(string);
    str_destroy(clone);
    str_destroy(substr);
    return 0;
}
Exemplo n.º 14
0
void newsroom_fixup_str(newsroom_local *local) {

    /*
     * Substitution table

       1= Player1 - Crystal
       2= Player2 - Steffan
       3= HAR1 - jaguar
       4= HAR2 - shadow
       5= Arena - power plant
       6= His/Her P1 - Her
       7= Him/Her P1 - Her
       8= He/She P1 - She
       10= Him/Her P2 - Him
       11= He/She P2 - He
    */

    const char *text = NULL;

    if(local->screen == 0) {
        text = lang_get(NEWSROOM_TEXT+local->news_id);
    } else {
        text = lang_get(NEWSROOM_TEXT+local->news_id+1);
    }

    str textstr;
    size_t prevpos=0, pos = 0;

    str_create_from_cstr(&textstr, text);
    str_free(&local->news_str);
    while(str_next_of(&textstr, '~', &pos)) {
        str tmp;
        str_create(&tmp);
        str_substr(&tmp, &textstr, prevpos, pos);
        str_append(&local->news_str, &tmp);
        str_free(&tmp);

        // replace ~n tokens
        char n = str_at(&textstr, pos+1);
        char nn = str_at(&textstr, pos+2);
        switch(n) {
            case '1':
                if(nn == '0') {
                    // ~10
                    str_append_c(&local->news_str, object_pronoun(local->sex2));
                    pos++;
                } else if(nn == '1') {
                    // ~11
                    str_append_c(&local->news_str, subject_pronoun(local->sex2));
                    pos++;
                } else {
                    // ~1
                    str_append(&local->news_str, &local->pilot1);
                }
                break;
            case '2':
                str_append(&local->news_str, &local->pilot2);
                break;
            case '3':
                str_append(&local->news_str, &local->har1);
                break;
            case '4':
                str_append(&local->news_str, &local->har2);
                break;
            case '5':
                str_append_c(&local->news_str, "Stadium");
                break;
            case '6':
                str_append_c(&local->news_str, "The");
                break;
            case '7':
                str_append_c(&local->news_str, object_pronoun(local->sex1));
                break;
            case '8':
                str_append_c(&local->news_str, subject_pronoun(local->sex1));
                break;
            case '9':
                str_append_c(&local->news_str, "WTF");
                break;
        }
        pos+=2;
        prevpos = pos;
    }
    str tmp;
    str_create(&tmp);
    str_substr(&tmp, &textstr, pos, str_size(&textstr));
    str_append(&local->news_str, &tmp);
    str_free(&tmp);
    str_free(&textstr);
}
Exemplo n.º 15
0
/* Dump trace line */
static void X86ThraceDumpTraceCacheEntry(X86Thread *self,
	struct x86_trace_cache_entry_t *entry, FILE *f)
{
	struct mem_t *mem;
	char *comma;
	int i;

	/* Get memory object for the thread */
	assert(self->ctx && self->ctx->mem);
	mem = self->ctx->mem;

	/* Tag and number of branches */
	fprintf(f, "tag = 0x%x, ", entry->tag);

	/* Branch flags */
	fprintf(f, "branches = ");
	x86_trace_cache_pred_dump(entry->branch_flags, entry->branch_count, f);
	fprintf(f, "\n");

	/* Fall-through and target address */
	fprintf(f, "fall_through = 0x%x, ", entry->fall_through);
	fprintf(f, "target = 0x%x\n", entry->target);

	/* Macro-Instructions */
	fprintf(f, "uops = %d, ", entry->uop_count);
	fprintf(f, "mops = {");
	comma = "";
	for (i = 0; i < entry->mop_count; i++)
	{
		char mop_name[MAX_STRING_SIZE];
		char *mop_name_end;
		char mop_bytes[20];

		unsigned int addr;

		int mem_safe;
		int mop_name_length;

		struct x86_inst_t inst;

		/* Disable memory safe mode */
		mem_safe = mem->safe;
		mem->safe = 0;

		/* Read instruction */
		addr = entry->mop_array[i];
		mem_read(mem, addr, sizeof mop_bytes, mop_bytes);

		/* Disassemble */
		x86_inst_decode(&inst, addr, mop_bytes);

		/* Extract instruction name */
		mop_name_end = index(inst.format, '_');
		mop_name_length = mop_name_end ? mop_name_end - inst.format : strlen(inst.format);
		str_substr(mop_name, sizeof mop_name, inst.format, 0, mop_name_length);
		fprintf(f, "%s%s", comma, mop_name);
		comma = ", ";

		/* Restore safe mode */
		mem->safe = mem_safe;
	}
	fprintf(f, "}\n");
}
Exemplo n.º 16
0
static void
_show_stream(MPLS_STREAM *ss, int level)
{
    str_t *lang;

    indent_printf(level, "Codec (%04x): %s", ss->coding_type,
                    _lookup_str(codec_map, ss->coding_type));
    switch (ss->stream_type) {
        case 1:
            indent_printf(level, "PID: %04x", ss->pid);
            break;

        case 2:
        case 4:
            indent_printf(level, "SubPath Id: %02x", ss->subpath_id);
            indent_printf(level, "SubClip Id: %02x", ss->subclip_id);
            indent_printf(level, "PID: %04x", ss->pid);
            break;

        case 3:
            indent_printf(level, "SubPath Id: %02x", ss->subpath_id);
            indent_printf(level, "PID: %04x", ss->pid);
            break;

        default:
            fprintf(stderr, "unrecognized stream type %02x\n", ss->stream_type);
            break;
    };

    switch (ss->coding_type) {
        case 0x01:
        case 0x02:
        case 0xea:
        case 0x1b:
            indent_printf(level, "Format %02x: %s", ss->format,
                        _lookup_str(video_format_map, ss->format));
            indent_printf(level, "Rate %02x: %s", ss->rate,
                        _lookup_str(video_rate_map, ss->rate));
            break;

        case 0x03:
        case 0x04:
        case 0x80:
        case 0x81:
        case 0x82:
        case 0x83:
        case 0x84:
        case 0x85:
        case 0x86:
            indent_printf(level, "Format %02x: %s", ss->format,
                        _lookup_str(audio_format_map, ss->format));
            indent_printf(level, "Rate %02x:", ss->rate,
                        _lookup_str(audio_rate_map, ss->rate));
            lang = str_substr((char*)ss->lang, 0, 3);
            indent_printf(level, "Language: %s", lang->buf);
            str_free(lang);
            free(lang);
            break;

        case 0x90:
        case 0x91:
            lang = str_substr((char*)ss->lang, 0, 3);
            indent_printf(level, "Language: %s", lang->buf);
            str_free(lang);
            free(lang);
            break;

        case 0x92:
            indent_printf(level, "Char Code: %02x", ss->char_code);
            lang = str_substr((char*)ss->lang, 0, 3);
            indent_printf(level, "Language: %s", lang->buf);
            str_free(lang);
            free(lang);
            break;

        default:
            fprintf(stderr, "unrecognized coding type %02x\n", ss->coding_type);
            break;
    };
}