void G_parser::rewrite(rule& r, vector<int>& seq_t){
    
    cout << "rewriting_Rule:";
    //for (int i=0; i<r.left_str.size(); i++) cout << r.left_str[i] << ", ";
    cout << endl;
    
    vector<elem_ID> production;
    int choice = rewrite_choice(r);
    
    //produce from rule
    for (int i=0; i<r.right_side[choice].right_str.size(); i++){
        
        production.push_back(elem_ID());
        production[i].name = r.right_side[choice].right_str[i];
        //else (generals.leftmost_time == {0 ,0})
        
        vector<int> t_aux(2);
        
        t_aux[0] = r.leftmost_time[0] % t_sign;
        t_aux[1] = ((r.leftmost_time[1]+i / harm_rh) + form_length) % form_length;
        
        production[i].time = t_aux;
    }
    
    update_cycle(production, r, seq_t);
    
    //production.clear();
    
    /*
     for (int i=0; i<production.size(); i++){
     cout << "name" << i << ": " << production[i].name << ", time: " << production[i].time[0] << " & " << production[i].time[1] << endl;
     }
     */
}
Ejemplo n.º 2
0
/* CAMqa54502 - pass in currency_struct */
int create_frn_send(CURRENCY_STRUCT *currency_struct)
{
    int	status = SUCCESS;
    int	num_trans = 0;
    int	num_closed = 0;
    Arb_numeric	debit_amt = ARB_NUMERIC_ZERO;	/* total amount of debits */
    Arb_numeric	credit_amt = ARB_NUMERIC_ZERO;	/* total amount of credits */
    Arb_numeric	result = ARB_NUMERIC_ZERO;
    CC_FILE_STATUS frec;
    char buff1[ARB_NUMERIC_LEN];
    char buff2[ARB_NUMERIC_LEN];
    int retval;

    /*DENqa62462, created file type*/
    int file_type = FILE_FRN_EFT_OUT;

    memset(&frec, 0, sizeof(CC_FILE_STATUS));
    gFile_id = 0;
    /*gCycle_id = 0;*/

    /* Check for, and reprocess any previous failures; i.e., any
    ** outgoing French files (file_type == FILE_FRN_EFT_OUT) where the
    ** file_status is FILE_STAT_INUSE or FILE_STAT_PROC_ERR.  Since
    ** we are just starting, and no other task can be running,
    ** then anything "INUSE" must be from a previous failure.
    */
    /* BUG: Future version should check for previous CREATE failures here. */


    /* Create unique file name for new send file using timestamp */
    /* Sets globals gFile_date_time and gFile_name */
    create_file_name();

    /* Create FILE_STATUS entry, Sets global gFile_id */
    if (insert_file_status(&gFile_id, gCycle_id, gFile_name) == FAILURE) {
        emit(FILE_LINE, EFT_FS_FILE_ERR, gFile_name, gFile_id);
        gContinue_create = 0;
        return(CREATE_FILE_FAILURE);
    }

    /*****************************/
    /* *** BEGIN TRANSACTION *** */
    /*****************************/

    if (arb_begin_tran(Dbpcust1, (char *) arb_get_process_id()) == FAILURE) {
	emit(FILE_LINE, EFT_BEGIN_TRAN_ERR, "send file");
	arb_cancel(Dbpcust1);
	rollback_file_status();
        return(CREATE_FILE_FAILURE);
    }
    if (gBalance_billing == 1) {
         /* Prepare PAYMENT_TRANS table: create rows with the current profiles */
         if (create_trans_current_profile()  == FAILURE) {
             arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id());
             rollback_file_status();
             emit(FILE_LINE, EFT_CURR_PROF_TRANS);
             return(CREATE_FILE_FAILURE);
         }
    }

    /* Lock and Count sendable transactions */
    if (lock_frn_trans(currency_struct) == FAILURE) {
	arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id());
	rollback_file_status();
	emit(FILE_LINE, EFT_LOCK_TRANS);
        return(CREATE_FILE_FAILURE);
    }

    emit(FILE_LINE, EFT_CREATE_SEND, gFile_name, gFile_id, gCycle_id);

    if (create_cycle_entry(gCH_curr.clearing_house_id, gCycle_id, CYCLE_INUSE) <= 0) {
	arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id());
	rollback_file_status();
	emit(FILE_LINE, EFT_CYCLE_CREATE_ERR, gCycle_id);
	return(CREATE_FILE_FAILURE);
    }

    if (arb_commit_tran(Dbpcust1) == FAILURE)	/*** COMMIT TRANSACTION ***/
    {
	emit(FILE_LINE, EFT_COMMIT_TRAN_ERR, "send file");
	arb_cancel(Dbpcust1);
	rollback_file_status();
        return(CREATE_FILE_FAILURE);
    }

    emit(FILE_LINE, EFT_BEGIN_PROCESSING, gTransactions, gFile_id);

    /* Create file, read TRANS records, write to the file, close file */

	/* CAMqa54502 - pass in currency_struct */
    if ((retval = create_frn_file(&num_trans, &num_closed, &debit_amt, &credit_amt,currency_struct)) <= 0) {
	emit(FILE_LINE, EFT_FILE_CREATE_ERR, gFile_id);

	if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_PROC_ERR, 0) != 1)
	{
	   emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_PROC_ERR);
	}

	/* update CYCLE_STATUS */
	if (update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, CYCLE_ERROR) <= 0)
	{
	    emit(FILE_LINE, EFT_CYCLE_ERR, "updating",
		gCH_curr.clearing_house_id, gCycle_id);
	}

	if (manual_rollback_trans(gFile_id) != 1) {
	   /* SERIOUS problem. Cannot unset TRANS entries. They may remain
	   ** marked as "PEN" (pending) and will NOT be sent out to clearing
	   ** house until status is changed.
	   */
	   emit(FILE_LINE, EFT_ROLLBACK_TRANS, gFile_id);
	}

        return(CREATE_FILE_FAILURE);
    }
    else if (retval == 2)
    {
        if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_PROC_ERR, 0) != 1) 
        {
            emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_NEW);
        }
        else if (update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, 
                     CYCLE_ERROR) <= 0)
        {
            emit(FILE_LINE, EFT_CYCLE_ERR, "updating", gCH_curr.clearing_house_id, gCycle_id);
        }
        emit(FILE_LINE, EFT_NO_SEND_FILE);
        return(CREATE_FILE_NODATA);
    }

    /* Successfully created output (send) file.  Update file & cycle status. */

    status = CREATE_FILE_SUCCESS;

    arb_num_arith(&result, &debit_amt, ARB_NUM_ADD, &credit_amt);

    if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_NEW, 0) != 1)
    {
	emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_NEW);
	status = CREATE_FILE_FAILURE;
    } else if (update_cycle(gCH_curr.clearing_house_id, gCycle_id, CYCLE_NEW,
	CYCLE_NEW_STATS, num_trans - num_closed, &result) <= 0)
    {
	/* update of CYCLE_STATUS to NEW failed; try to update status for
	** both cycle and file to ERROR.  Ignore errors updating since if we
	** got here, additional updates will probably fail.
	*/
	emit(FILE_LINE, EFT_CYCLE_ERR, "updating new", gCH_curr.clearing_house_id, gCycle_id);
	status = CREATE_FILE_FAILURE;
    }

    if (status == CREATE_FILE_FAILURE) {
	/* We were doing so well!  TRANS entries were successfully locked,
	** we successfully created output file.  And then at the last step, we get
	** an error trying to update the FILE_STATUS and/or CYCLE_STATUS
	** entries.  Let's try mark the file & cycle to ERROR and attempt to manually
	** rollback TRANS changes (i.e., reset the current "PEN" transactions
	** back to status = NULL so they can be sent out next time around).
	** NOTE: Most likely, the following updates and manual rollback will fail.
	** A likely problem to have gotten us here is full transaction log.  Manual
	** intervention may be required!  Don't bother checking return status from
	** these updates.
	*/
	if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_NEW, 0) != 1) {
	    emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_PROC_ERR);
	}

	/* update CYCLE_STATUS */
	if ((status = update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, CYCLE_ERROR)) <= 0) {
	    emit(FILE_LINE, EFT_CYCLE_ERR, "updating", gCH_curr.clearing_house_id, gCycle_id);
	}

	if (manual_rollback_trans(gFile_id) != 1) {
	   emit(FILE_LINE, EFT_ROLLBACK_TRANS, gFile_id);
	}

        return(CREATE_FILE_FAILURE);
    }

    arb_numeric_to_string(&debit_amt, buff1);
    arb_numeric_to_string(&credit_amt, buff2);
    if(!VerifyStringLength(buff1,REPORT_AMOUNT_MAX_LENGTH) || 
       !VerifyStringLength(buff2,REPORT_AMOUNT_MAX_LENGTH))
    	return (CREATE_FILE_FAILURE);

    /* CONTROL REPORT */
    fprintf(RptFileFD,"\n Send File Name: %s\n", gFile_name);
    fprintf(RptFileFD," ClearHouse  Cycle ID   File ID   # Trans           Debit Amt          Credit Amt\n");
    fprintf(RptFileFD," %10s  %8d  %8d  %8d  %18.18s  %18.18s\n",
	gCH_curr.clearing_house_id, gCycle_id,
	gFile_id, num_trans - num_closed, buff1, buff2);

    return(CREATE_FILE_SUCCESS);
}