Currently guards to throw an error if it finds the file to be included multiple times, can make it do a more traditional guard fairly easy if you would prefer.
Hope someone here has use for it :)
http://i.imgur.com/DpeWLol.gifv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | void str_cpy(char* dst, const char* src,unsigned len) {
for(;len;--len,++src,++dst)
*dst = *src;
}
void replace_chars(char* str, unsigned len, char find, char replace) {
for(;len;--len,++str)
if(*str == find)
*str = replace;
}
void to_upper(char* str,unsigned len){
for(;len;--len,++str)
if(*str >= 0x61 && *str <= 0x7A)
*str -= 0x20;
}
CUSTOM_COMMAND_SIG(include_guard_header){
uint32_t access = AccessOpen;
View_Summary view = get_active_view(app, access);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, access);
char filenamebuf[0x100];
char cbuffer[0x200];
String str = make_fixed_width_string(cbuffer);
unsigned len = 0;
char* fileshort = buffer.file_name + buffer.file_name_len;
for(;*fileshort != '/'; --fileshort, ++len)
;
fileshort++; len--;
str_cpy(filenamebuf, fileshort, len);
replace_chars(filenamebuf, len, ' ', '_');
replace_chars(filenamebuf, len, '.', '_');
to_upper(filenamebuf, len);
String fstr = make_string(filenamebuf, len);
append(&str, "#ifdef ");
append(&str, fstr);
append(&str, "\n#error \"File included multiple times.\"\n#endif\n#define ");
append(&str, fstr);
write_string(app, str);
}
|