v1.0
Fork of RGB_Matrix by
Revision 1:0a1a89c55c7c, committed 2017-06-20
- Comitter:
- perlatecnica
- Date:
- Tue Jun 20 17:53:58 2017 +0000
- Parent:
- 0:04691de55153
- Commit message:
- v1.0;
Changed in this revision
diff -r 04691de55153 -r 0a1a89c55c7c Fonts.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Fonts.lib Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/star297/code/Fonts/#b7905075b31a
diff -r 04691de55153 -r 0a1a89c55c7c TTF_fonts.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TTF_fonts.lib Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/JackB/code/TTF_fonts/#53055c20e5e3
diff -r 04691de55153 -r 0a1a89c55c7c arial_8pt.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arial_8pt.c Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,405 @@ +/* +** Font data for Arial 8pt +*/ + +#include "font.h" +#include "arial_8pt.h" + +/* Character bitmaps for Arial 8pt */ +const uint8_t arial_8pt_char_bitmaps[] = +{ + /* @0 ' ' (2 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @10 '!' (1 pixels wide) */ + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, + + /* @20 '"' (3 pixels wide) */ + 0xA0, 0xA0, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @30 '#' (5 pixels wide) */ + 0x28, 0x28, 0xF8, 0x50, 0x50, 0xF8, 0xA0, 0xA0, 0x00, 0x00, + + /* @40 '$' (5 pixels wide) */ + 0x70, 0xA8, 0xA0, 0x70, 0x28, 0x28, 0xA8, 0x70, 0x20, 0x00, + + /* @50 '%' (9 pixels wide) */ + 0x62, 0x00, 0x94, 0x00, 0x94, 0x00, 0x68, 0x00, 0x0B, 0x00, 0x14, 0x80, 0x14, 0x80, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @70 '&' (6 pixels wide) */ + 0x30, 0x48, 0x48, 0x30, 0x50, 0x8C, 0x88, 0x74, 0x00, 0x00, + + /* @80 ''' (1 pixels wide) */ + 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @90 '(' (3 pixels wide) */ + 0x20, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x20, + + /* @100 ')' (3 pixels wide) */ + 0x80, 0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x40, 0x80, + + /* @110 '*' (3 pixels wide) */ + 0x40, 0xE0, 0x40, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @120 '+' (5 pixels wide) */ + 0x00, 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, 0x00, + + /* @130 ',' (1 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + + /* @140 '-' (3 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, + + /* @150 '.' (1 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + + /* @160 '/' (3 pixels wide) */ + 0x20, 0x20, 0x40, 0x40, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, + + /* @170 '0' (5 pixels wide) */ + 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, + + /* @180 '1' (3 pixels wide) */ + 0x20, 0x60, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, + + /* @190 '2' (5 pixels wide) */ + 0x70, 0x88, 0x08, 0x08, 0x10, 0x20, 0x40, 0xF8, 0x00, 0x00, + + /* @200 '3' (5 pixels wide) */ + 0x70, 0x88, 0x08, 0x30, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, + + /* @210 '4' (5 pixels wide) */ + 0x10, 0x30, 0x50, 0x50, 0x90, 0xF8, 0x10, 0x10, 0x00, 0x00, + + /* @220 '5' (5 pixels wide) */ + 0x78, 0x40, 0x80, 0xF0, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, + + /* @230 '6' (5 pixels wide) */ + 0x70, 0x88, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, + + /* @240 '7' (5 pixels wide) */ + 0xF8, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x00, 0x00, + + /* @250 '8' (5 pixels wide) */ + 0x70, 0x88, 0x88, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, + + /* @260 '9' (5 pixels wide) */ + 0x70, 0x88, 0x88, 0x88, 0x78, 0x08, 0x88, 0x70, 0x00, 0x00, + + /* @270 ':' (1 pixels wide) */ + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + + /* @280 ';' (1 pixels wide) */ + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, + + /* @290 '<' (5 pixels wide) */ + 0x00, 0x00, 0x08, 0x70, 0x80, 0x70, 0x08, 0x00, 0x00, 0x00, + + /* @300 '=' (5 pixels wide) */ + 0x00, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, + + /* @310 '>' (5 pixels wide) */ + 0x00, 0x00, 0x80, 0x70, 0x08, 0x70, 0x80, 0x00, 0x00, 0x00, + + /* @320 '?' (5 pixels wide) */ + 0x70, 0x88, 0x08, 0x10, 0x20, 0x20, 0x00, 0x20, 0x00, 0x00, + + /* @330 '@' (10 pixels wide) */ + 0x1F, 0x00, 0x60, 0x80, 0x4D, 0x40, 0x93, 0x40, 0xA2, 0x40, 0xA2, 0x40, 0xA6, 0x80, 0x9B, 0x00, 0x40, 0x40, 0x3F, 0x80, + + /* @350 'A' (7 pixels wide) */ + 0x10, 0x28, 0x28, 0x28, 0x44, 0x7C, 0x82, 0x82, 0x00, 0x00, + + /* @360 'B' (6 pixels wide) */ + 0xF8, 0x84, 0x84, 0xFC, 0x84, 0x84, 0x84, 0xF8, 0x00, 0x00, + + /* @370 'C' (6 pixels wide) */ + 0x38, 0x44, 0x80, 0x80, 0x80, 0x80, 0x44, 0x38, 0x00, 0x00, + + /* @380 'D' (6 pixels wide) */ + 0xF0, 0x88, 0x84, 0x84, 0x84, 0x84, 0x88, 0xF0, 0x00, 0x00, + + /* @390 'E' (5 pixels wide) */ + 0xF8, 0x80, 0x80, 0xF8, 0x80, 0x80, 0x80, 0xF8, 0x00, 0x00, + + /* @400 'F' (5 pixels wide) */ + 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @410 'G' (7 pixels wide) */ + 0x38, 0x44, 0x82, 0x80, 0x8E, 0x82, 0x44, 0x38, 0x00, 0x00, + + /* @420 'H' (6 pixels wide) */ + 0x84, 0x84, 0x84, 0xFC, 0x84, 0x84, 0x84, 0x84, 0x00, 0x00, + + /* @430 'I' (1 pixels wide) */ + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @440 'J' (4 pixels wide) */ + 0x10, 0x10, 0x10, 0x10, 0x10, 0x90, 0x90, 0x60, 0x00, 0x00, + + /* @450 'K' (6 pixels wide) */ + 0x84, 0x88, 0x90, 0xB0, 0xD0, 0x88, 0x88, 0x84, 0x00, 0x00, + + /* @460 'L' (5 pixels wide) */ + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, 0x00, + + /* @470 'M' (7 pixels wide) */ + 0x82, 0xC6, 0xC6, 0xAA, 0xAA, 0xAA, 0x92, 0x92, 0x00, 0x00, + + /* @480 'N' (6 pixels wide) */ + 0x84, 0xC4, 0xA4, 0xA4, 0x94, 0x94, 0x8C, 0x84, 0x00, 0x00, + + /* @490 'O' (7 pixels wide) */ + 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00, + + /* @500 'P' (5 pixels wide) */ + 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @510 'Q' (7 pixels wide) */ + 0x38, 0x44, 0x82, 0x82, 0x82, 0x9A, 0x44, 0x3A, 0x00, 0x00, + + /* @520 'R' (6 pixels wide) */ + 0xF8, 0x84, 0x84, 0xF8, 0x90, 0x88, 0x88, 0x84, 0x00, 0x00, + + /* @530 'S' (6 pixels wide) */ + 0x78, 0x84, 0x80, 0x60, 0x18, 0x04, 0x84, 0x78, 0x00, 0x00, + + /* @540 'T' (5 pixels wide) */ + 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, + + /* @550 'U' (6 pixels wide) */ + 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x78, 0x00, 0x00, + + /* @560 'V' (7 pixels wide) */ + 0x82, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, + + /* @570 'W' (11 pixels wide) */ + 0x84, 0x20, 0x8A, 0x20, 0x4A, 0x40, 0x4A, 0x40, 0x51, 0x40, 0x51, 0x40, 0x20, 0x80, 0x20, 0x80, 0x00, 0x00, 0x00, 0x00, + + /* @590 'X' (6 pixels wide) */ + 0x84, 0x48, 0x48, 0x30, 0x30, 0x48, 0x48, 0x84, 0x00, 0x00, + + /* @600 'Y' (7 pixels wide) */ + 0x82, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, + + /* @610 'Z' (6 pixels wide) */ + 0x7C, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0xFC, 0x00, 0x00, + + /* @620 '[' (2 pixels wide) */ + 0xC0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xC0, + + /* @630 '\' (3 pixels wide) */ + 0x80, 0x80, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, + + /* @640 ']' (2 pixels wide) */ + 0xC0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xC0, + + /* @650 '^' (5 pixels wide) */ + 0x20, 0x50, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @660 '_' (6 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, + + /* @670 '`' (2 pixels wide) */ + 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @680 'a' (5 pixels wide) */ + 0x00, 0x00, 0x70, 0x88, 0x78, 0x88, 0x98, 0x68, 0x00, 0x00, + + /* @690 'b' (5 pixels wide) */ + 0x80, 0x80, 0xB0, 0xC8, 0x88, 0x88, 0xC8, 0xB0, 0x00, 0x00, + + /* @700 'c' (5 pixels wide) */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x00, 0x00, + + /* @710 'd' (5 pixels wide) */ + 0x08, 0x08, 0x68, 0x98, 0x88, 0x88, 0x98, 0x68, 0x00, 0x00, + + /* @720 'e' (5 pixels wide) */ + 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, 0x00, + + /* @730 'f' (3 pixels wide) */ + 0x20, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, + + /* @740 'g' (5 pixels wide) */ + 0x00, 0x00, 0x68, 0x98, 0x88, 0x88, 0x98, 0x68, 0x08, 0xF0, + + /* @750 'h' (5 pixels wide) */ + 0x80, 0x80, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, + + /* @760 'i' (1 pixels wide) */ + 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @770 'j' (2 pixels wide) */ + 0x40, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, + + /* @780 'k' (4 pixels wide) */ + 0x80, 0x80, 0x90, 0xA0, 0xC0, 0xA0, 0xA0, 0x90, 0x00, 0x00, + + /* @790 'l' (1 pixels wide) */ + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @800 'm' (7 pixels wide) */ + 0x00, 0x00, 0xBC, 0xD2, 0x92, 0x92, 0x92, 0x92, 0x00, 0x00, + + /* @810 'n' (5 pixels wide) */ + 0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, + + /* @820 'o' (5 pixels wide) */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, + + /* @830 'p' (5 pixels wide) */ + 0x00, 0x00, 0xB0, 0xC8, 0x88, 0x88, 0xC8, 0xB0, 0x80, 0x80, + + /* @840 'q' (5 pixels wide) */ + 0x00, 0x00, 0x68, 0x98, 0x88, 0x88, 0x98, 0x68, 0x08, 0x08, + + /* @850 'r' (3 pixels wide) */ + 0x00, 0x00, 0xA0, 0xC0, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + + /* @860 's' (5 pixels wide) */ + 0x00, 0x00, 0x70, 0x88, 0x60, 0x10, 0x88, 0x70, 0x00, 0x00, + + /* @870 't' (3 pixels wide) */ + 0x40, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x40, 0x60, 0x00, 0x00, + + /* @880 'u' (5 pixels wide) */ + 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, 0x00, + + /* @890 'v' (5 pixels wide) */ + 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x00, 0x00, + + /* @900 'w' (9 pixels wide) */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x80, 0x94, 0x80, 0x55, 0x00, 0x55, 0x00, 0x22, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* @920 'x' (5 pixels wide) */ + 0x00, 0x00, 0x88, 0x50, 0x20, 0x20, 0x50, 0x88, 0x00, 0x00, + + /* @930 'y' (5 pixels wide) */ + 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x20, 0x40, + + /* @940 'z' (5 pixels wide) */ + 0x00, 0x00, 0xF8, 0x10, 0x20, 0x20, 0x40, 0xF8, 0x00, 0x00, + + /* @950 '{' (3 pixels wide) */ + 0x20, 0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x40, 0x40, 0x20, + + /* @960 '|' (1 pixels wide) */ + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + + /* @970 '}' (3 pixels wide) */ + 0x80, 0x40, 0x40, 0x40, 0x20, 0x40, 0x40, 0x40, 0x40, 0x80, + + /* @980 '~' (5 pixels wide) */ + 0x00, 0x00, 0x00, 0xE8, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +/* Character descriptors for Arial 8pt */ +/* { [Char width in bits], [Offset into arial8ptCharBitmaps in bytes] } */ +const FONT_CHAR_INFO arial_8pt_char_descriptors[] = +{ + {2, 0}, /* */ + {1, 10}, /* ! */ + {3, 20}, /* " */ + {5, 30}, /* # */ + {5, 40}, /* $ */ + {9, 50}, /* % */ + {6, 70}, /* & */ + {1, 80}, /* ' */ + {3, 90}, /* ( */ + {3, 100}, /* ) */ + {3, 110}, /* * */ + {5, 120}, /* + */ + {1, 130}, /* , */ + {3, 140}, /* - */ + {1, 150}, /* . */ + {3, 160}, /* / */ + {5, 170}, /* 0 */ + {3, 180}, /* 1 */ + {5, 190}, /* 2 */ + {5, 200}, /* 3 */ + {5, 210}, /* 4 */ + {5, 220}, /* 5 */ + {5, 230}, /* 6 */ + {5, 240}, /* 7 */ + {5, 250}, /* 8 */ + {5, 260}, /* 9 */ + {1, 270}, /* : */ + {1, 280}, /* ; */ + {5, 290}, /* < */ + {5, 300}, /* = */ + {5, 310}, /* > */ + {5, 320}, /* ? */ + {10, 330}, /* @ */ + {7, 350}, /* A */ + {6, 360}, /* B */ + {6, 370}, /* C */ + {6, 380}, /* D */ + {5, 390}, /* E */ + {5, 400}, /* F */ + {7, 410}, /* G */ + {6, 420}, /* H */ + {1, 430}, /* I */ + {4, 440}, /* J */ + {6, 450}, /* K */ + {5, 460}, /* L */ + {7, 470}, /* M */ + {6, 480}, /* N */ + {7, 490}, /* O */ + {5, 500}, /* P */ + {7, 510}, /* Q */ + {6, 520}, /* R */ + {6, 530}, /* S */ + {5, 540}, /* T */ + {6, 550}, /* U */ + {7, 560}, /* V */ + {11, 570}, /* W */ + {6, 590}, /* X */ + {7, 600}, /* Y */ + {6, 610}, /* Z */ + {2, 620}, /* [ */ + {3, 630}, /* \ */ + {2, 640}, /* ] */ + {5, 650}, /* ^ */ + {6, 660}, /* _ */ + {2, 670}, /* ` */ + {5, 680}, /* a */ + {5, 690}, /* b */ + {5, 700}, /* c */ + {5, 710}, /* d */ + {5, 720}, /* e */ + {3, 730}, /* f */ + {5, 740}, /* g */ + {5, 750}, /* h */ + {1, 760}, /* i */ + {2, 770}, /* j */ + {4, 780}, /* k */ + {1, 790}, /* l */ + {7, 800}, /* m */ + {5, 810}, /* n */ + {5, 820}, /* o */ + {5, 830}, /* p */ + {5, 840}, /* q */ + {3, 850}, /* r */ + {5, 860}, /* s */ + {3, 870}, /* t */ + {5, 880}, /* u */ + {5, 890}, /* v */ + {9, 900}, /* w */ + {5, 920}, /* x */ + {5, 930}, /* y */ + {5, 940}, /* z */ + {3, 950}, /* { */ + {1, 960}, /* | */ + {3, 970}, /* } */ + {5, 980}, /* ~ */ +}; + +/* Font information for Arial 8pt */ +const FONT_INFO arial_8pt_font_info = +{ + 10, /* Character height in bits */ + ' ', /* Start character */ + arial_8pt_char_descriptors, /* Character decriptor array */ + arial_8pt_char_bitmaps, /* Character bitmap array */ +};
diff -r 04691de55153 -r 0a1a89c55c7c arial_8pt.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arial_8pt.h Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,11 @@ +#ifndef __ARIAL_8PT_H__ +#define __ARIAL_8PT_H__ + + +/* Font data for Arial 8pt */ +extern const uint8_t arial_8pt_char_bitmaps[]; +extern const FONT_CHAR_INFO arial_8pt_char_descriptors[]; +extern const FONT_INFO arial_8pt_font_info; + + +#endif // __ARIAL_8PT_H__
diff -r 04691de55153 -r 0a1a89c55c7c font.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font.h Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,26 @@ +#ifndef __FONT_H__ +#define __FONT_H__ + + +typedef unsigned char uint8_t; + + +typedef struct +{ + int width; // Character width in bits. + int offset; // Offset in bytes into font bitmap. +} +FONT_CHAR_INFO; + + +typedef struct +{ + int height; // Character height in bits. + char start_char; // Start character. + const FONT_CHAR_INFO *p_character_descriptor; // Character decriptor array. + const uint8_t *p_character_bitmaps; // Character bitmap array. +} +FONT_INFO; + + +#endif // __FONT_H__
diff -r 04691de55153 -r 0a1a89c55c7c ini.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ini.c Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,130 @@ +/* inih -- simple .INI file parser + +inih is released under the New BSD license (see LICENSE.txt). Go to the project +home page for more info: + +http://code.google.com/p/inih/ + +*/ + +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#include "ini.h" + +#define MAX_LINE 200 +#define MAX_SECTION 50 +#define MAX_NAME 50 + +/* Strip whitespace chars off end of given string, in place. Return s. */ +static char* rstrip(char* s) +{ + char* p = s + strlen(s); + while (p > s && isspace(*--p)) + *p = '\0'; + return s; +} + +/* Return pointer to first non-whitespace char in given string. */ +static char* lskip(const char* s) +{ + while (*s && isspace(*s)) + s++; + return (char*)s; +} + +/* Return pointer to first char c or ';' in given string, or pointer to + null at end of string if neither found. */ +static char* find_char_or_comment(const char* s, char c) +{ + while (*s && *s != c && *s != ';') + s++; + return (char*)s; +} + +/* Version of strncpy that ensures dest (size bytes) is null-terminated. */ +static char* strncpy0(char* dest, const char* src, size_t size) +{ + strncpy(dest, src, size); + dest[size - 1] = '\0'; + return dest; +} + +/* See documentation in header file. */ +int ini_parse(const char* filename, + int (*handler)(void*, const char*, const char*, const char*), + void* user) +{ + /* Uses a fair bit of stack (use heap instead if you need to) */ + char line[MAX_LINE]; + char section[MAX_SECTION] = ""; + char prev_name[MAX_NAME] = ""; + + FILE* file; + char* start; + char* end; + char* name; + char* value; + int lineno = 0; + int error = 0; + + file = fopen(filename, "r"); + if (!file) + return -1; + + /* Scan through file line by line */ + while (fgets(line, sizeof(line), file) != NULL) { + lineno++; + start = lskip(rstrip(line)); + +#if INI_ALLOW_MULTILINE + if (*prev_name && *start && start > line) { + /* Non-black line with leading whitespace, treat as continuation + of previous name's value (as per Python ConfigParser). */ + if (!handler(user, section, prev_name, start) && !error) + error = lineno; + } + else +#endif + if (*start == '[') { + /* A "[section]" line */ + end = find_char_or_comment(start + 1, ']'); + if (*end == ']') { + *end = '\0'; + strncpy0(section, start + 1, sizeof(section)); + *prev_name = '\0'; + } + else if (!error) { + /* No ']' found on section line */ + error = lineno; + } + } + else if (*start && *start != ';') { + /* Not a comment, must be a name=value pair */ + end = find_char_or_comment(start, '='); + if (*end == '=') { + *end = '\0'; + name = rstrip(start); + value = lskip(end + 1); + end = find_char_or_comment(value, ';'); + if (*end == ';') + *end = '\0'; + rstrip(value); + + /* Valid name=value pair found, call handler */ + strncpy0(prev_name, name, sizeof(prev_name)); + if (!handler(user, section, name, value) && !error) + error = lineno; + } + else if (!error) { + /* No '=' found on name=value line */ + error = lineno; + } + } + } + + fclose(file); + + return error; +}
diff -r 04691de55153 -r 0a1a89c55c7c ini.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ini.h Tue Jun 20 17:53:58 2017 +0000 @@ -0,0 +1,45 @@ +/* inih -- simple .INI file parser + +inih is released under the New BSD license (see LICENSE.txt). Go to the project +home page for more info: + +http://code.google.com/p/inih/ + +*/ + +#ifndef __INI_H__ +#define __INI_H__ + +/* Make this header file easier to include in C++ code */ +#ifdef __cplusplus +extern "C" { +#endif + +/* Parse given INI-style file. May have [section]s, name=value pairs + (whitespace stripped), and comments starting with ';' (semicolon). Section + is "" if name=value pair parsed before any section heading. + + For each name=value pair parsed, call handler function with given user + pointer as well as section, name, and value (data only valid for duration + of handler call). Handler should return nonzero on success, zero on error. + + Returns 0 on success, line number of first error on parse error, or -1 on + file open error. +*/ +int ini_parse(const char* filename, + int (*handler)(void* user, const char* section, + const char* name, const char* value), + void* user); + +/* Nonzero to allow multi-line value parsing, in the style of Python's + ConfigParser. If allowed, ini_parse() will call the handler with the same + name for each subsequent line parsed. */ +#ifndef INI_ALLOW_MULTILINE +#define INI_ALLOW_MULTILINE 1 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __INI_H__ */