Page Contents
Case 1
The original C code:
#define STPMIC_BUCKS_PD_BUCK2 2U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE_ENA 0U
#define STPMIC_BUCKS_PD_BUCK2_HIGH_ACTIVE_ENA 1U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_HIGH_INACTIVE 3U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE 4U
Copy to spreadsheet:
The modification script
function addRows(){
var startRow = 1;
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
sheet.insertColumnBefore(3);
for (var i=numRows; i > -1; i--) {
var currentRow = i + startRow;
var firstCellOnCurrentRow = sheet.getRange(currentRow,1).getValue();
// insert blank row after current row
sheet.insertRowsAfter(currentRow, 1);
// insert text from current row into new row with new "Mask" postfix - this is the macro name
sheet.getRange(currentRow + 1, 1).setValue(firstCellOnCurrentRow + "_Mask");
// On the new row, add new cell text based on text from original row - this is the macro definition
//sheet.getRange(currentRow + 1, 3).setValue("( 1U << " + firstCellOnCurrentRow.replace("#define ", " ") + " )");
sheet.getRange(currentRow + 1, 3).setValue("( " + firstCellOnCurrentRow.replace("#define ", " ") + " << STPMIC_BUCKS_PD_BUCK2 )");
}
}
The output:
The final C code:
#define STPMIC_BUCKS_PD_BUCK2 2U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE_ENA 0U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE_ENA_Mask ( STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE_ENA << STPMIC_BUCKS_PD_BUCK2 )
#define STPMIC_BUCKS_PD_BUCK2_HIGH_ACTIVE_ENA 1U
#define STPMIC_BUCKS_PD_BUCK2_HIGH_ACTIVE_ENA_Mask ( STPMIC_BUCKS_PD_BUCK2_HIGH_ACTIVE_ENA << STPMIC_BUCKS_PD_BUCK2 )
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_HIGH_INACTIVE 3U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_HIGH_INACTIVE_Mask ( STPMIC_BUCKS_PD_BUCK2_LIGHT_HIGH_INACTIVE << STPMIC_BUCKS_PD_BUCK2 )
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE 4U
#define STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE_Mask ( STPMIC_BUCKS_PD_BUCK2_LIGHT_ACTIVE << STPMIC_BUCKS_PD_BUCK2 )