Exemplo n.º 1
0
int vi_set_pURLtoShorten_file_recs(){
	
	int UserIds_file_rec=2; // beging looping from second row after saving first row's value:
	lr_save_string(lr_eval_string("{UserIds_userid}"),"UserIds_userid_first");
	lr_advance_param("UserIds_use"); // Increment one row.

	// Loop through file until the first value appears again:
	while( 1==1 ){ // true
		// Catch if cycled back to first row:
		if( stricmp( lr_eval_string("{UserIds_userid_first}"),lr_eval_string("{UserIds_userid_first}") ) == FOUND ){
			// lr_output_message(">> {UserIds_userid_first}=%s", lr_eval_string("{UserIds_userid_first}") );
			return UserIds_file_rec - 1;
		}else{
			lr_advance_param("pURLtoShorten"); // Increment file one record.
			UserIds_file_rec = UserIds_file_rec + 1;
			// lr_output_message(">> UserIds_file_rec=%d UserIds_userid_first=%s", UserIds_file_rec, lr_eval_string("{UserIds_userid_first}"));
		}
	}
	return LR_FAIL; // drop-out after exhausting values in table.
} // vi_set_pURLtoShorten_file_recs()
Exemplo n.º 2
0
int vi_set_pURLtoShorten_file_recs(){
	
	int nURLtoShorten_file_rec=2; // beging looping from second row after saving first row's value:
	lr_save_string(lr_eval_string("{pURL_long}"),"pURLtoShorten_first");
	lr_advance_param("pURLtoShorten"); // Increment file one record.

	// Loop through file until the first value appears again:
	while( 1==1 ){ // true
		// Catch if cycled back to first row:
		if( stricmp( lr_eval_string("{pURLtoShorten_first}"),lr_eval_string("{pURL_long}") ) == FOUND ){
			// lr_output_message(">> pURLtoShorten=%s", lr_eval_string("{pURL_long}") );
			return nURLtoShorten_file_rec - 1;
		}else{
			lr_advance_param("pURLtoShorten"); // Increment file one record.
			nURLtoShorten_file_rec = nURLtoShorten_file_rec + 1;
			// lr_output_message(">> nURLtoShorten_file_rec=%d pURLtoShorten=%s", nURLtoShorten_file_rec, lr_eval_string("{pURL_long}"));
		}
	}
	
	return LR_FAIL;
} // vi_set_pURLtoShorten_file_recs()
Exemplo n.º 3
0
get_long_url_to_shorten(){
	int rc=LR_PASS;
	int i=0;
	
	if( iURLSource_setting == 1 && nURLtoShorten_file_recs > 0 ){
		for( nURLtoShorten_index=1; nURLtoShorten_index < nURLtoShorten_file_recs +1; nURLtoShorten_index++ ){
			// Loop to skip data records marked No for usage.
			// Referencing data in file URLtoShorten.dat:
			if( stricmp( "N", lr_eval_string("{pURL_use}") ) == FOUND ){
				lr_advance_param("pURL_long"); // Increment file one record.
			} // else fall through to use it.
		}
		lr_save_string(lr_eval_string("{pURL_use}"),"pURLtoShorten");

	#ifdef USE_VTS
	}else
	if( iURLSource_setting == 2 ){ // (use VTS)

		// ENHANCEMENT: The alternative to this loop is to use an increment.

		// Scan through the VTS table from top to bottom.
		// If short_url is not blank in VTS table, it's alreadry processed, so skip to next row:
		for( i=1; i <= nVTS_row_count; i++ ){
			rc = vtc_query_column(pvci, "web", i, &outvalue); // retrieve single field from a designated row.
			if( outvalue == NULL || sizeof( outvalue ) <= 0 ){ // there is no longURL, so skip that row;
				wi_startPrintingTrace();
				lr_output_message(">> row %d \"web\" value is blank. Skipping to next row. rc=%d.", i, rc);
				wi_stopPrinting();
			}else{
				rc = vtc_query_column(pvci, "shorturl", i, &shorturl); // retrieve single field from a designated row.
				// FIXME: Why is rc=10111 ?
				if( shorturl == NULL || sizeof( shorturl ) <= 0 ){ // a blank cell, so it needs a shorturl.
					lr_save_string(outvalue,"pURLtoShorten");
					wi_startPrintingTrace();
					lr_output_message(">> row %d \"shorturl\" is needed for \"web\"=%s. rc=%d.", i, lr_eval_string("{pURLtoShorten}"), rc);
					wi_stopPrinting();
					vtc_free(outvalue);
					rc=0; // FIXME: Why need to override rc=10111 again?
					break; // break out of loop for this script to get a shorturl for the web URL in VTS.
				}else{ 
					// there is a shortURL already, so cycle back up to top for another
					// unless this is the last row in the table:
					if( i == nVTS_row_count ){
						wi_startPrintingTrace();
						lr_output_message(">> Last row at %d has a shorturl of \"%s\". So no more to process.", i, shorturl);
						wi_stopPrinting();
						vtc_free(shorturl);
						rc = LR_FAIL;
					}
				}
	   		}
		} // for loop

	#endif // USE_VTS

	// ENHANCEMENT: else option to retrieve from on-line Google spreadsheet, etc.

	}else{
		wi_startPrintingError();
       	lr_output_message(">> iURLSource_setting=%s is invalid.", iURLSource_setting);
		wi_stopPrinting();
		rc=LR_FAIL; // This would be a programming error since editing occurred before this.
	} // if( iURLSource_setting 
	
	return rc;
} // get_long_url_to_shorten()