void do_controller_buffer_code(int idx, const char *postfix, int buf_len, int rows) { int display_idx; char s[1024]; sprintf(s, "u8g2_m_%s_%d_%s", strlowercase(controller_list[idx].name), controller_list[idx].tile_width, postfix); if ( str_exists(s) == 0 ) { str_add(s); //FILE *fp = stdout; fprintf(buf_code_fp, "uint8_t *%s(uint8_t *page_cnt)\n", s); fprintf(buf_code_fp, "{\n"); fprintf(buf_code_fp, " static uint8_t buf[%d];\n", buf_len); fprintf(buf_code_fp, " *page_cnt = %d;\n", rows); fprintf(buf_code_fp, " return buf;\n"); fprintf(buf_code_fp, "}\n"); fprintf(buf_header_fp, "uint8_t *%s(uint8_t *page_cnt);\n", s); } display_idx = 0; fprintf(setup_code_fp, "/* %s %s */\n", controller_list[idx].name, postfix); while( controller_list[idx].display_list[display_idx].name != NULL ) { do_display(idx, display_idx, postfix); display_idx++; } }
const char *str_unique( const char *prefix ) { static int i = 1; char *buf = alloca( strlen( prefix ) + 100 ); do { sprintf( buf, "%s%d", prefix, i++ ); } while (str_exists( buf )); return str_find( buf ); }
void str_add(const char *s) { if ( str_exists(s) ) return; if ( str_cnt >= STR_MAX ) { error(1,0, "max number of strings reached"); } else { str_list[str_cnt] = strdup(s); str_cnt++; } }