Exemple #1
0
int
mddl_cmd_merge(mddl_clo_t clo)
{
	const size_t indent = 0;
	mddl_doc_t res_doc;
	int res = 0;

	/* check if it's just a help request */
	if (clo->helpp) {
		print_usage(clo);
		goto out;
	}
	/* we destructively modify the first parsed document */
	if (clo->merge->nfiles == 0 ||
	    (res_doc = __read_file(clo->merge->files[0])) == NULL) {
		res = -1;
		goto out;
	}
	/* otherwise we have a valid target doc ... */
	for (size_t i = 1; i < clo->merge->nfiles; i++) {
		/* ... and merge the stuff one by one */
		const char *f = clo->merge->files[i];
		mddl_doc_t tmp;

		if (f != NULL && (tmp = __read_file(f)) != NULL) {
			(void)__merge(res_doc, tmp);
		}
	}
	/* fiddle with clo and print the result */
	clo->print->file = NULL;
	mddl_cmd_print(clo, res_doc);
out:
	return res;
}
Exemple #2
0
void merge_verify()
{
	int test[10] = {5, 8, 9, 23, 67, 1, 3, 7, 31, 56};

	__merge(test, 0, 4, 9);

	dump(test, 10);
}
Exemple #3
0
void __merge_sort(int *arr, int p, int r)
{
	int q;

	if (p >= r)
		return;

	q = (p + r) / 2;
	__merge_sort(arr, p, q);
	__merge_sort(arr, q + 1, r);
	__merge(arr, p, q, r);
}
Exemple #4
0
void merge_sort(void *base, size_t num, size_t size,
				CMP_FUNC cmpf, SWAP_FUNC swapf)
{
	unsigned int i, c, step=1;
	__assert(base && cmpf);
	if (!swapf)
		swapf = (size == 4 ? __swap : swap_dft);
	__dump(base, num, size);
	while (step < num) 
	{
		for(i = 0; i < num; i += 2*step)
		{
			c = (i+2*step)>num?num-i:step*2;
			__merge((char*)base+i*size, c, size, step-1, cmpf, swapf); 
		}
		step *= 2;
	}
	__dump(base, num, size);
	__verify(base, num, size, cmpf);
}
Exemple #5
0
static void __po2lang( char* po, iONode xml, const char* lang ) {
  int cnt = 0;
  char* msgid = StrOp.find( po, "msgid \"" );


  while( msgid != NULL ) {
    char* msgstr = StrOp.find( msgid, "msgstr \"" );
    char* endline = NULL;
    char* tmp = NULL;
    char* str = NULL;
    char* id  = NULL;

    if( msgstr != NULL ) {
      TraceOp.println( "try to find end of id..." );

      /* looking for all lines */
      endline = msgid + 5;
      while( endline[1] == '\"' ) {
        msgid = endline + 2;
        endline = StrOp.find( endline+1, "\n");
        tmp = endline;

        while( tmp[0] != '\"' && msgid != tmp ) {
          tmp--;
        }
        tmp[0] = '\0';

        id = StrOp.cat( id, msgid );
      }
      TraceOp.println( "id=%s", id );


      TraceOp.println( "try to find end of msgstr..." );
      /* looking for all lines */
      endline = msgstr + 6;
      while( endline[1] == '\"' ) {
        msgstr = endline + 2;
        endline = StrOp.find( endline+1, "\n");
        tmp = endline;

        while( tmp[0] != '\"' && msgstr != tmp ) {
          tmp--;
        }
        tmp[0] = '\0';

        str = StrOp.cat( str, msgstr );
        TraceOp.println( "id[%s] msgstr[%s]", id, str );
      }

      __merge( id, str, lang, xml );
      StrOp.free(id);
      StrOp.free(str);

      cnt++;
    }
    msgid = StrOp.find( endline + 1, "msgid \"" );

  };
  TraceOp.println( "Merged [%d] msgid's", cnt );

}