model_server/project_file/src/char_based_merge.cxx
// returns: 1 on success
//          0 on failure
1 on success
0 on failure
1 on success 0 on failure
static int mrg_smt (smtHeader *h, FILE *diff, int& do_not_save_flag)
{
    Initialize(mrg_smt);
    objArr edits;
    char tmp[LINE_LEN];
    int n = 0; int m = 0;
    int in_txt  = 0; int in_long = 0; int sz = 0; char delem = 0;
    int linenm  = 0; int ret = 0; genString line; genString new_txt;
    while ( (fgets(tmp, LINE_LEN, diff)) ) {
	if (in_long) 
	    line += tmp;
	else {
	    line = tmp;
	    linenm ++;
	}
	sz = strlen(tmp);
	if (tmp[sz - 1] != '\n') {
	    in_long = 1;
	    continue;
	}
	in_long = 0;
	char *ll = (char *)line; char *ln_txt = 0; char *coma1 = 0;
	if (in_txt) {
	    if (ll[0] != '>' || ll[1] != ' ') {
		msg("Wrong continuation indent; line $1", error_sev) << linenm << eom;
		return ret;
	    }
	    ln_txt = ll + 2;
	} else {
	    coma1 = strchr (ll, ',');
	    if (!coma1) {
		msg("No first parameter; line $1", error_sev) << linenm << eom;
		return ret;
	    }
	    coma1[0] = 0; n = atoi (ll);
	    char *coma2 = strchr (coma1 + 1, ',');
	    if (!coma2) {
		msg("No second parameter; line $1", error_sev) << linenm << eom;
		return ret;
	    }
	    coma2[0]   = 0; m = atoi (coma1 + 1);
	    char *rest = coma2 + 1;
	    if (!rest[0] || !rest[1]) {
		msg("No delimiters; line $1", error_sev) << linenm << eom;
		return ret;
	    }
	    delem   = rest[0];
	    rest[0] = 0;
	    ln_txt  = rest + 1;
	}
	int len_ln      = strlen (ln_txt);
	char *end_delem = 0;
	if (len_ln > 1 && ln_txt[len_ln - 2] == delem)
	    end_delem = &ln_txt[len_ln - 2];
#ifdef _WIN32
	else if (len_ln > 2 && ln_txt[len_ln - 2] == '\015' && ln_txt[len_ln - 3] == delem)
	    end_delem = &ln_txt[len_ln - 3];
#endif
	in_txt = (end_delem) ? 0 : 1;
	if ( !in_txt ) {
	    end_delem[0] = 0;
	    new_txt += ln_txt;
	    oneEdit *ed = new oneEdit (h, n, m, (char *)new_txt);
	    if (ed->st && ed->en)
		edits.insert_last (ed);
	    else {
		msg("Failed to find token; offset $1, length $2", error_sev) << n << eoarg << m << eom;
		delete ed;
	    }
	    new_txt = 0; n = 0; m = 0; delem = 0;
	} else
	    new_txt += ln_txt;
    }
    ret = mrg_apply (h, edits, do_not_save_flag);
    return ret;
}
static int mrg_smt ( smtHeader * h , FILE * diff , int & do_not_save_flag ) { Initialize ( mrg_smt ) ; objArr edits ; char tmp [ LINE_LEN ] ; int n = 0 ; int m = 0 ; int in_txt = 0 ; int in_long = 0 ; int sz = 0 ; char delem = 0 ; int linenm = 0 ; int ret = 0 ; genString line ; genString new_txt ; while ( ( fgets ( tmp , LINE_LEN , diff ) ) ) { if ( in_long ) line += tmp ; else { line = tmp ; linenm ++ ; } sz = strlen ( tmp ) ; if ( tmp [ sz - 1 ] != ' \n ' ) { in_long = 1 ; continue ; } in_long = 0 ; char * ll = ( char * ) line ; char * ln_txt = 0 ; char * coma1 = 0 ; if ( in_txt ) { if ( ll [ 0 ] != ' ' || ll [ 1 ] != ' ' ) { msg ( " " , error_sev ) << linenm << eom ; return ret ; } ln_txt = ll + 2 ; } else { coma1 = strchr ( ll , ' ' ) ; if ( ! coma1 ) { msg ( " " , error_sev ) << linenm << eom ; return ret ; } coma1 [ 0 ] = 0 ; n = atoi ( ll ) ; char * coma2 = strchr ( coma1 + 1 , ' ' ) ; if ( ! coma2 ) { msg ( " " , error_sev ) << linenm << eom ; return ret ; } coma2 [ 0 ] = 0 ; m = atoi ( coma1 + 1 ) ; char * rest = coma2 + 1 ; if ( ! rest [ 0 ] || ! rest [ 1 ] ) { msg ( " " , error_sev ) << linenm << eom ; return ret ; } delem = rest [ 0 ] ; rest [ 0 ] = 0 ; ln_txt = rest + 1 ; } int len_ln = strlen ( ln_txt ) ; char * end_delem = 0 ; if ( len_ln > 1 && ln_txt [ len_ln - 2 ] == delem ) end_delem = & ln_txt [ len_ln - 2 ] ; #ifdef _WIN32 else if ( len_ln > 2 && ln_txt [ len_ln - 2 ] == ' \015 ' && ln_txt [ len_ln - 3 ] == delem ) end_delem = & ln_txt [ len_ln - 3 ] ; #endif in_txt = ( end_delem ) ? 0 : 1 ; if ( ! in_txt ) { end_delem [ 0 ] = 0 ; new_txt += ln_txt ; oneEdit * ed = new oneEdit ( h , n , m , ( char * ) new_txt ) ; if ( ed -> st && ed -> en ) edits . insert_last ( ed ) ; else { msg ( " " , error_sev ) << n << eoarg << m << eom ; delete ed ; } new_txt = 0 ; n = 0 ; m = 0 ; delem = 0 ; } else new_txt += ln_txt ; } ret = mrg_apply ( h , edits , do_not_save_flag ) ; return ret ; }
returns: 1 on success
0 on failure
returns : 1 on success 0 on failure