Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <string>
- #define ULL unsigned long long
- #define LL long long
- #define uint unsigned int
- #define uchar unsigned char
- #define IRQ true
- typedef struct {
- bool type;
- uchar irqbank;
- uchar irqnum;
- std::string name;
- } fun;
- typedef struct {
- std::string name;
- fun funcs[8];
- } pin;
- int main(void) {
- // Init table
- pin table[80];
- std::string line, name;
- for (uchar i = 0; i < 80; i++) {
- table[i].name = "-";
- for (uchar j = 0; j < 8; j++) {
- table[i].funcs[j].name = "-";
- table[i].funcs[j].type = 0;
- }
- }
- uint it = 0, mux, bank, num;
- // Fill the table object
- std::getline(std::cin, line);
- while (line[0] != 'e') {
- if (line[0] != 'P') {
- std::stringstream ss(line);
- if (line[0] == 'i') {
- ss.ignore(1);
- ss >> mux >> bank >> num;
- table[it - 1].funcs[mux].type = IRQ;
- table[it - 1].funcs[mux].irqbank = bank;
- table[it - 1].funcs[mux].irqnum = num;
- table[it - 1].funcs[mux].name = "IRQ";
- } else {
- ss >> mux >> name;
- table[it - 1].funcs[mux].name = name;
- }
- } else {
- it++;
- table[it - 1].name = line;
- }
- std::getline(std::cin, line);
- }
- // Print
- // Header
- printf("<div class=\"toccolours mw-collapsible mw-collapsed\">\nAllwinner "
- "B288 GPIO multiplex functions\n<div "
- "class=\"mw-collapsible-content\">\n{| class=\"wikitable\" "
- "style=\"margin:auto\"\n|-\n! rowspan=\"2\" | Pin !! colspan=\"8\" | "
- "function\n|-\n! 0 !! 1 !! 2 !! 3 !! "
- "4 !! 5 !! 6 !! 7\n");
- // Table's main part
- for (uint i = 0; i < 80; i++) {
- std::transform(table[i].name.begin(), table[i].name.end(),
- table[i].name.begin(), ::toupper);
- printf("|-");
- if (table[i].name[1] == 'C' || table[i].name[1] == 'F') {
- printf(" style=\"background-color: #d6d9db;\"");
- }
- printf("\n| %s ", table[i].name.c_str());
- for (uint j = 0; j < 8; j++) {
- std::transform(table[i].funcs[j].name.begin(),
- table[i].funcs[j].name.end(),
- table[i].funcs[j].name.begin(), ::toupper);
- printf(" || ");
- printf("%s", table[i].funcs[j].name.c_str());
- if (table[i].funcs[j].type == IRQ) {
- printf(" bank: %hhu num: %hhu", table[i].funcs[j].irqbank,
- table[i].funcs[j].irqnum);
- }
- }
- putchar('\n');
- }
- // Footer
- printf("|}\n</div>\n</div>\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement