code cleanup

This commit is contained in:
Campbell Barton 2012-12-29 02:57:52 +00:00
parent 6b05c887d3
commit c157f815a8
3 changed files with 31 additions and 27 deletions

@ -113,6 +113,14 @@ void flatten_string_free(FlattenString *fs)
MEM_freeN(fs->accum);
}
/* takes a string within fs->buf and returns its length */
int flatten_string_strlen(FlattenString *fs, const char *str)
{
const int len = (fs->pos - (int)(str - fs->buf)) - 1;
BLI_assert(strlen(str) == len);
return len;
}
/* Ensures the format string for the given line is long enough, reallocating
* as needed. Allocation is done here, alone, to ensure consistency. */
int text_check_format_len(TextLine *line, unsigned int len)

@ -43,6 +43,8 @@ typedef struct FlattenString {
int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in);
void flatten_string_free(FlattenString *fs);
int flatten_string_strlen(FlattenString *fs, const char *str);
int text_check_format_len(TextLine *line, unsigned int len);

@ -53,7 +53,7 @@
* http://docs.python.org/py3k/reference/lexical_analysis.html#keywords
*/
static int txtfmt_py_find_builtinfunc(char *string)
static int txtfmt_py_find_builtinfunc(const char *string)
{
int a, i;
/* list is from...
@ -98,22 +98,20 @@ static int txtfmt_py_find_builtinfunc(char *string)
* If a special name is found, the length of the matching name is returned.
* Otherwise, -1 is returned. */
static int txtfmt_py_find_specialvar(char *string)
static int txtfmt_py_find_specialvar(const char *string)
{
int i = 0;
/* Check for "def" */
if (string[0] == 'd' && string[1] == 'e' && string[2] == 'f')
i = 3;
/* Check for "class" */
else if (string[0] == 'c' && string[1] == 'l' && string[2] == 'a' && string[3] == 's' && string[4] == 's')
i = 5;
int i;
if (strncmp(string, "def", 3) == 0) i = 3;
else if (strncmp(string, "class", 5) == 0) i = 5;
else i = 0;
/* If next source char is an identifier (eg. 'i' in "definate") no match */
if (i == 0 || text_check_identifier(string[i]))
return -1;
return i;
}
static int txtfmt_py_find_decorator(char *string)
static int txtfmt_py_find_decorator(const char *string)
{
if (string[0] == '@') {
int i = 1;
@ -125,28 +123,26 @@ static int txtfmt_py_find_decorator(char *string)
return -1;
}
static int txtfmt_py_find_bool(char *string)
static int txtfmt_py_find_bool(const char *string)
{
int i = 0;
/* Check for "False" */
if (string[0] == 'F' && string[1] == 'a' && string[2] == 'l' && string[3] == 's' && string[4] == 'e')
i = 5;
/* Check for "True" */
else if (string[0] == 'T' && string[1] == 'r' && string[2] == 'u' && string[3] == 'e')
i = 4;
/* Check for "None" */
else if (string[0] == 'N' && string[1] == 'o' && string[2] == 'n' && string[3] == 'e')
i = 4;
/* If next source char is an identifier (eg. 'i' in "definate") no match */
int i;
if (strncmp(string, "None", 4) == 0) i = 4;
else if (strncmp(string, "True", 4) == 0) i = 4;
else if (strncmp(string, "False", 5) == 0) i = 5;
else i = 0;
/* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */
if (i == 0 || text_check_identifier(string[i]))
return -1;
return i;
}
static void txtfmt_py_format_line(SpaceText *st, TextLine *line, int do_next)
static void txtfmt_py_format_line(SpaceText *st, TextLine *line, const int do_next)
{
FlattenString fs;
char *str, *fmt, orig, cont, find, prev = ' ';
const char *str;
char *fmt;
char orig, cont, find, prev = ' ';
int len, i;
/* Get continuation from previous line */
@ -270,9 +266,7 @@ static void txtfmt_py_format_line(SpaceText *st, TextLine *line, int do_next)
}
}
}
prev = *fmt;
fmt++;
str++;
prev = *fmt; fmt++; str++;
}
/* Terminate and add continuation char */