More whitelisted auto-indented files

This commit is contained in:
pancake 2015-12-08 13:24:21 +01:00
parent 7863995cca
commit 991c39a601
11 changed files with 100 additions and 98 deletions

View File

@ -112,8 +112,7 @@ R_API void r_cons_2048() {
twok_add ();
while (twok_fin ()) {
r_cons_clear00 ();
r_cons_printf ("[r2048] score: %d moves: %d\n",
score, moves);
r_cons_printf ("[r2048] score: %d moves: %d\n", score, moves);
r_cons_flush ();
twok_print ();
ch = r_cons_readchar ();

View File

@ -202,7 +202,7 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) {
if (!c || !s || !*s) return;
/* split the string into pieces of non-ANSI chars and print them normally,
* using the ANSI chars to set the attr of the canvas */
** using the ANSI chars to set the attr of the canvas */
orig_x = c->x;
do {
const char *s_part = set_attr (c, s);
@ -246,8 +246,7 @@ R_API char *r_cons_canvas_to_string(RConsCanvas *c) {
if (!c) return NULL;
b = c->b;
o = calloc (sizeof (char),
(c->w * (c->h + 1)) * (CONS_MAX_ATTR_SZ));
o = calloc (1, (c->w * (c->h + 1)) * (CONS_MAX_ATTR_SZ));
if (!o) return NULL;
for (y = 0; y < c->h; y++) {
if (!is_first) {

View File

@ -1,7 +1,7 @@
/* radare - LGPL - Copyright 2008-2015 - pancake */
#include <r_cons.h>
#define I r_cons_singleton()
#define I r_cons_singleton ()
/* TODO: remove global vars */
static char *path = NULL;
@ -15,13 +15,13 @@ static void setnewline(int old) {
snprintf (prompt, sizeof (prompt), "%d: ", _n);
r_line_set_prompt (prompt);
strncpy (I->line->buffer.data, r_str_word_get0 (lines, _n),
sizeof (I->line->buffer.data) - 1);
sizeof (I->line->buffer.data) - 1);
I->line->buffer.data[sizeof (I->line->buffer.data) - 1] = '\0';
I->line->buffer.index = I->line->buffer.length = strlen (I->line->buffer.data);
I->line->contents = I->line->buffer.data;
}
static void saveline (int n, const char *str) {
static void saveline(int n, const char *str) {
char *out;
if (!str) return;
out = r_str_word_get0set (lines, bytes, _n, str, &bytes);
@ -31,50 +31,46 @@ static void saveline (int n, const char *str) {
static int up(void *n) {
int old = _n;
if (_n>0) _n--;
if (_n > 0) _n--;
setnewline (old);
return -1;
}
static int down(void *n) {
int old = _n;
#if 0
if (_n<(nlines-1))
#endif
_n++;
int old = _n++;
setnewline (old);
return -1;
}
static void filesave () {
static void filesave() {
char buf[128];
int i;
if (!path) {
eprintf ("File: ");
buf[0] = 0;
fgets (buf, sizeof(buf)-1, stdin);
buf[sizeof(buf)-1] = 0;
fgets (buf, sizeof (buf) - 1, stdin);
buf[sizeof (buf) - 1] = 0;
i = strlen (buf);
if (i>0) {
buf[i-1] = 0;
if (i > 0) {
buf[i - 1] = 0;
free (path);
path = strdup (buf);
}
}
if (lines) {
for (i=0; i<bytes; i++) {
if (lines[i]=='\0')
lines[i]='\n';
for (i = 0; i < bytes; i++) {
if (lines[i] == '\0')
lines[i] = '\n';
}
}
if (r_file_dump (path, (const ut8*)lines, bytes, 0))
if (r_file_dump (path, (const ut8 *)lines, bytes, 0))
eprintf ("File '%s' saved (%d bytes)\n", path, bytes);
else eprintf ("Cannot save file\n");
// restore back zeroes
nlines = r_str_split (lines, '\n');
}
R_API char *r_cons_editor (const char *file, const char *str) {
R_API char *r_cons_editor(const char *file, const char *str) {
const char *line;
_n = 0;
if (I->editor) {
@ -87,7 +83,7 @@ R_API char *r_cons_editor (const char *file, const char *str) {
lines = r_file_slurp (file, &bytes);
nlines = r_str_split (lines, '\n');
eprintf ("Loaded %d lines on %d bytes\n",
(nlines?(nlines-1):0), bytes);
(nlines? (nlines - 1): 0), bytes);
} else path = NULL;
I->line->hist_up = up;
I->line->hist_down = down;
@ -102,7 +98,7 @@ R_API char *r_cons_editor (const char *file, const char *str) {
if (!line) break;
}
filesave ();
I->line->hist_up =
I->line->hist_up = NULL;
I->line->hist_down = NULL;
I->line->contents = NULL;
return lines;

View File

@ -14,27 +14,27 @@
#include <r_util.h>
#define SZ 1024
static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
static void b64_encode(const ut8 in[3], char out[4], int len) {
if (len<1) return;
out[0] = cb64[ in[0] >> 2 ];
out[1] = cb64[ ((in[0] & 0x03) << 4) | ((len>1)?((in[1] & 0xf0) >> 4):0) ];
out[2] = (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | (len > 2 ? ((in[2] & 0xc0) >> 6) : 0) ] : '=');
out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
if (len < 1) return;
out[0] = cb64[in[0] >> 2];
out[1] = cb64[((in[0] & 0x03) << 4) | ((len > 1)? ((in[1] & 0xf0) >> 4): 0)];
out[2] = (len > 1? cb64[((in[1] & 0x0f) << 2) | (len > 2? ((in[2] & 0xc0) >> 6): 0)]: '=');
out[3] = (len > 2? cb64[in[2] & 0x3f]: '=');
}
static int b64_decode(const char in[4], ut8 out[3]) {
ut8 len = 3, i, v[4] = {0};
for (i=0; i<4; i++) {
if (in[i]<43 || in[i]>122)
ut8 len = 3, i, v[4] = { 0 };
for (i = 0; i < 4; i++) {
if (in[i] < 43 || in[i] > 122)
return -1;
v[i] = cd64[in[i]-43];
if (v[i]=='$') {
len = i-1;
v[i] = cd64[in[i] - 43];
if (v[i] == '$') {
len = i - 1;
break;
} else v[i]-=62;
} else v[i] -= 62;
}
out[0] = v[0] << 2 | v[1] >> 4;
out[1] = v[1] << 4 | v[2] >> 2;
@ -44,11 +44,11 @@ static int b64_decode(const char in[4], ut8 out[3]) {
R_API int r_base64_decode(ut8 *bout, const char *bin, int len) {
int in, out, ret;
if (len<0)
if (len < 0)
len = strlen (bin);
for (in=out=0; in<len-1;in+=4) {
ret = b64_decode (bin+in, bout+out);
if (ret <1)
for (in = out = 0; in < len - 1; in += 4) {
ret = b64_decode (bin + in, bout + out);
if (ret < 1)
break;
out += ret;
}
@ -59,7 +59,7 @@ R_API int r_base64_decode(ut8 *bout, const char *bin, int len) {
R_API ut8 *r_base64_decode_dyn(const char *in, int len) {
ut8 *bout;
if (!in) return NULL;
if (len<0) len = strlen (in)+1;
if (len < 0) len = strlen (in) + 1;
bout = malloc (len);
r_base64_decode (bout, in, len);
return bout;
@ -67,11 +67,11 @@ R_API ut8 *r_base64_decode_dyn(const char *in, int len) {
R_API int r_base64_encode(char *bout, const ut8 *bin, int len) {
int in, out;
if (len<0)
len = strlen ((const char*)bin);
for (in=out=0; in<len; in+=3,out+=4)
b64_encode (bin+in, (char*)bout+out,
(len-in)>3?3:len-in);
if (len < 0)
len = strlen ((const char *)bin);
for (in = out = 0; in < len; in += 3, out += 4)
b64_encode (bin + in, (char *)bout + out,
(len - in) > 3? 3: len - in);
bout[out] = 0;
return out;
}
@ -85,8 +85,8 @@ R_API char *r_base64_encode_dyn(const char *str, int len) {
bout = (char *)malloc ((len * 4) + 2);
if (!bout) return NULL;
for (in = out = 0; in < len; in += 3, out += 4)
b64_encode ((const ut8*)str + in, (char*)bout + out,
(len - in) > 3 ? 3 : len - in);
b64_encode ((const ut8 *)str + in, (char *)bout + out,
(len - in) > 3? 3: len - in);
bout[out] = 0;
return bout;
}

View File

@ -18,17 +18,17 @@ R_API void r_cache_free(RCache *c) {
free (c);
}
R_API const ut8* r_cache_get(RCache *c, ut64 addr, int *len) {
R_API const ut8 *r_cache_get(RCache *c, ut64 addr, int *len) {
if (!c->buf)
return NULL;
if (len) *len = c->base - addr;
if (addr<c->base)
if (addr < c->base)
return NULL;
if (addr>(c->base+c->len))
if (addr > (c->base + c->len))
return NULL;
if (len) *len = c->len - (addr-c->base);
//eprintf ("4 - %d\n", (addr-c->base));
return c->buf + (addr-c->base);
if (len) *len = c->len - (addr - c->base);
//eprintf ("4 - %d\n", (addr-c->base));
return c->buf + (addr - c->base);
}
R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) {
@ -38,8 +38,7 @@ R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) {
memcpy (c->buf, buf, len);
c->base = addr;
c->len = len;
} else
if (addr < c->base) {
} else if (addr < c->base) {
ut8 *b;
int baselen = (c->base - addr);
int newlen = baselen + ((len > c->len)? len: c->base);
@ -47,19 +46,19 @@ R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) {
b = malloc (newlen);
if (!b) return 0;
memset (b, 0xff, newlen);
memcpy (b+baselen, c->buf, c->len);
memcpy (b + baselen, c->buf, c->len);
memcpy (b, buf, len);
free (c->buf);
c->buf = b;
c->base = addr;
c->len = newlen;
} else if ((addr+len)>(c->base+c->len)) {
} else if ((addr + len) > (c->base + c->len)) {
ut8 *b;
int baselen = (addr - c->base);
int newlen = baselen + len;
b = realloc (c->buf, newlen);
if (!b) return 0;
memcpy (b+baselen, buf, len);
memcpy (b + baselen, buf, len);
c->buf = b;
c->len = newlen;
} else {
@ -68,7 +67,7 @@ R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) {
return c->len;
}
R_API void r_cache_flush (RCache *c) {
R_API void r_cache_flush(RCache *c) {
c->base = 0;
c->len = 0;
free (c->buf);

View File

@ -23,7 +23,7 @@ R_API void r_log_msg(const char *str) {
R_API void r_log_error(const char *str) {
fputs ("ERR: ", stderr);
fputs (str, stderr);
r_log_file(str);
r_log_file (str);
}
R_API void r_log_progress(const char *str, int percent) {

View File

@ -2,10 +2,10 @@
#include <r_util.h>
#define IS_PRINTABLE(x) (x>=' '&&x<='~')
#define IS_PRINTABLE(x) (x >= ' ' && x <= '~')
R_API int r_name_validate_char(const char ch) {
if ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9'))
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))
return R_TRUE;
switch (ch) {
case ':':
@ -20,10 +20,10 @@ R_API int r_name_check(const char *name) {
if (!name || !*name)
return R_FALSE;
/* Cannot start by number */
if (*name>='0' && *name<='9')
if (*name >= '0' && *name <= '9')
return R_FALSE;
/* Cannot contain non-alphanumeric chars + [:._] */
for (;*name!='\0'; name++)
for (; *name != '\0'; name++)
if (!r_name_validate_char (*name))
return R_FALSE;
return R_TRUE;
@ -32,18 +32,18 @@ R_API int r_name_check(const char *name) {
R_API int r_name_filter(char *name, int maxlen) {
int i;
char *oname;
if (maxlen<0) {
if (maxlen < 0) {
maxlen = strlen (name);
}
name = oname = r_str_trim_head_tail (name);
for (i=0; *name; name++, i++) {
if (maxlen && i>maxlen) {
for (i = 0; *name; name++, i++) {
if (maxlen && i > maxlen) {
*name = '\0';
break;
}
if (!r_name_validate_char (*name)) {
*name = '_';
// r_str_ccpy (name, name+1, 0);
// r_str_ccpy (name, name+1, 0);
//name--;
}
}
@ -56,7 +56,7 @@ R_API char *r_name_filter2(const char *name) {
while (!IS_PRINTABLE (*name))
name++;
res = strdup (name);
for (i=0; res[i]; i++) {
for (i = 0; res[i]; i++) {
if (!r_name_validate_char (res[i])) {
res[i] = '_';
}

View File

@ -4,14 +4,13 @@
#include "r_util.h"
#include "r_slist.h"
R_API RSList *r_slist_new () {
R_API RSList *r_slist_new() {
RSList *s = R_NEW0 (RSList);
s->list = r_list_new ();
return s;
}
R_API void r_slist_free (RSList *s) {
R_API void r_slist_free(RSList *s) {
free (s->items);
free (s->alloc);
r_list_free (s->list);
@ -23,15 +22,15 @@ R_API int r_slist_get_slot(RSList *s, ut64 addr) {
return -1;
if (addr < s->min || addr > s->max)
return -1;
return (addr-s->min) / s->mod;
return (addr - s->min) / s->mod;
}
static RSListItem *get_new_item () {
static RSListItem *get_new_item() {
// TODO: use slices here!
return malloc (sizeof (RSListItem));
}
R_API RSList *r_slist_add (RSList *s, void *data, ut64 from, ut64 to) {
R_API RSList *r_slist_add(RSList *s, void *data, ut64 from, ut64 to) {
ut64 at = from;
int slot, lastslot;
RSListItem *item = get_new_item ();
@ -43,11 +42,11 @@ R_API RSList *r_slist_add (RSList *s, void *data, ut64 from, ut64 to) {
r_list_append (s->list, item); // item must be alloacted by slices
// find slot
slot = r_slist_get_slot (s, from);
if (slot<0) {
if (slot < 0) {
//r_slist_optimize ();
return NULL;
}
while (at<to && slot < s->nitems) {
while (at < to && slot < s->nitems) {
lastslot = s->last[slot];
if (lastslot == s->lastslot) {
// must optimize and exit
@ -66,7 +65,7 @@ R_API RSList *r_slist_add (RSList *s, void *data, ut64 from, ut64 to) {
return NULL;
}
R_API RSListItem **r_slist_get (RSList *s, ut64 addr) {
R_API RSListItem **r_slist_get(RSList *s, ut64 addr) {
int idx;
ut64 base;
if (s->min == 0 && s->min == s->max)
@ -81,17 +80,17 @@ R_API RSListItem **r_slist_get (RSList *s, ut64 addr) {
// r_slist_get_iter()
// r_slist_iter_has_next()
R_API void r_slist_del (RSList *s, RSListItem *p) {
R_API void r_slist_del(RSList *s, RSListItem *p) {
// delete from s->list
// remove lists
}
R_API void *r_slist_get_at (RSList *list, ut64 addr) {
R_API void *r_slist_get_at(RSList *list, ut64 addr) {
return NULL;
}
// called on add and del
R_API void r_slist_optimize (RSList *s) {
R_API void r_slist_optimize(RSList *s) {
RSListItem *ptr;
RListIter *iter;
ut64 min, max;
@ -117,13 +116,13 @@ R_API void r_slist_optimize (RSList *s) {
s->min = min;
s->max = max;
s->mod = ((max-min));
if (s->nitems * sizeof(void*) < s->nitems) {
s->mod = ((max - min));
if (s->nitems * sizeof (void *) < s->nitems) {
s->items = NULL;
} else {
s->items = malloc (1 + (sizeof (void*) * s->nitems));
s->items = malloc (1 + (sizeof (void *) * s->nitems));
}
//eprintf ("MOD %d (block size)\n", s->mod);
//eprintf ("MOD %d (block size)\n", s->mod);
// store integers as indexes inside the allocated heap
#if 0

View File

@ -2,11 +2,11 @@
#include <r_util.h>
R_API RStack *r_stack_new (unsigned int n) {
R_API RStack *r_stack_new(unsigned int n) {
RStack *s = R_NEW0 (RStack);
if (!s) return NULL;
s->elems = R_NEWS0 (void *, n);
if (!s->elems){
if (!s->elems) {
free (s);
return NULL;
}
@ -16,16 +16,16 @@ R_API RStack *r_stack_new (unsigned int n) {
return s;
}
R_API void r_stack_free (RStack *s) {
R_API void r_stack_free(RStack *s) {
free (s->elems);
free (s);
}
R_API int r_stack_push (RStack *s, void *el) {
R_API int r_stack_push(RStack *s, void *el) {
if (s->top == s->n_elems - 1) {
/* reallocate the stack */
s->n_elems *= 2;
s->elems = realloc (s->elems, s->n_elems * sizeof(void *));
s->elems = realloc (s->elems, s->n_elems * sizeof (void *));
if (!s->elems)
return R_FALSE;
}
@ -35,7 +35,7 @@ R_API int r_stack_push (RStack *s, void *el) {
return R_TRUE;
}
R_API void *r_stack_pop (RStack *s) {
R_API void *r_stack_pop(RStack *s) {
void *res;
if (s->top == -1)
return NULL;
@ -45,10 +45,10 @@ R_API void *r_stack_pop (RStack *s) {
return res;
}
R_API int r_stack_is_empty (RStack *s) {
R_API int r_stack_is_empty(RStack *s) {
return s->top == -1;
}
R_API unsigned int r_stack_size (RStack *s) {
R_API unsigned int r_stack_size(RStack *s) {
return (unsigned int)(s->top + 1);
}

View File

@ -4,6 +4,13 @@ libr/cons/hud.c
libr/cons/2048.c
libr/cons/line.c
libr/cons/canvas.c
libr/cons/editor.c
libr/util/base64.c
libr/util/name.c
libr/util/stack.c
libr/util/slist.c
libr/util/log.c
libr/util/cache.c
"
if [ "$1" = commit ]; then
sys/indent.sh -i ${FILES}

View File

@ -53,6 +53,9 @@ indentFile() {
# struct initializers with spaces wtf
mv .tmp-format .tmp-format2
awk '{gsub(/\{0\}/, "{ 0 }");print}' < .tmp-format2 > .tmp-format
# do not place spaces after tabs
mv .tmp-format .tmp-format2
perl -ne 's,\t[ +],\t,g;print' < .tmp-format2 > .tmp-format
if [ "$UNIFIED" = 1 ]; then
diff -ru "${IFILE}" .tmp-format