Commit c71ac41e authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

aesthetic improvements of source files (courtesy of Jonathan Wilkes)

parent 1169b045
......@@ -602,7 +602,8 @@ static void canvas_saveto(t_canvas *x, t_binbuf *b)
linetraverser_start(&t, x);
while (oc = linetraverser_next(&t))
{
if (outconnect_visible(oc)) {
if (outconnect_visible(oc))
{
int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
......
......@@ -197,7 +197,8 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
int *indexp)
{
//fprintf(stderr,"rtext_senditup <%s>\n", x->x_buf);
if (x) {
if (x)
{
t_float dispx, dispy;
char smallbuf[200], *tempbuf;
int outchars_b = 0, nlines = 0, ncolumns = 0,
......@@ -205,12 +206,15 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
int reportedindex = 0;
t_canvas *canvas = glist_getcanvas(x->x_glist);
int widthspec_c = x->x_text->te_width; // width if any specified
int widthlimit_c = (widthspec_c ? widthspec_c : BOXWIDTH); // width limit in chars
//fprintf(stderr,"senditup widthlimit_c %d %d\n", widthspec_c, widthlimit_c);
// width limit in chars
int widthlimit_c = (widthspec_c ? widthspec_c : BOXWIDTH);
//fprintf(stderr,"senditup widthlimit_c %d %d\n",
// widthspec_c, widthlimit_c);
int inindex_b = 0; // index location in the buffer
int inindex_c = 0; // index location in the u8 chars
int selstart_b = 0, selend_b = 0; // selection start and end
int x_bufsize_c = u8_charnum(x->x_buf, x->x_bufsize); // buffer size in u8 chars
// buffer size in u8 chars
int x_bufsize_c = u8_charnum(x->x_buf, x->x_bufsize);
/* if we're a GOP (the new, "goprect" style) borrow the font size
from the inside to preserve the spacing */
if (pd_class(&x->x_text->te_pd) == canvas_class &&
......@@ -220,7 +224,8 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
else font = glist_getfont(x->x_glist);
fontwidth = sys_fontwidth(font);
fontheight = sys_fontheight(font);
findx = (*widthp + (fontwidth/2)) / fontwidth; // calculating x and y in pixels
// calculating x and y in pixels
findx = (*widthp + (fontwidth/2)) / fontwidth;
findy = *heightp / fontheight;
if (x->x_bufsize >= 100)
tempbuf = (char *)t_getbytes(2 * x->x_bufsize + 1);
......@@ -229,7 +234,8 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
{
int inchars_b = x->x_bufsize - inindex_b;
int inchars_c = x_bufsize_c - inindex_c;
int maxindex_c = (inchars_c > widthlimit_c ? widthlimit_c : inchars_c);
int maxindex_c =
(inchars_c > widthlimit_c ? widthlimit_c : inchars_c);
int maxindex_b = u8_offset(x->x_buf + inindex_b, maxindex_c);
int eatchar = 1;
int foundit_b = firstone(x->x_buf + inindex_b, '\n', maxindex_b);
......@@ -237,7 +243,9 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
//following deals with \v replacement for \n in multiline comments
int foundit_bv = firstone(x->x_buf + inindex_b, '\v', maxindex_b);
//fprintf(stderr,"%d %d <%s>\n", foundit_b, foundit_bv, x->x_buf);
if ((foundit_bv < foundit_b && foundit_bv != -1) || (foundit_b == -1 && foundit_bv != -1)) foundit_b = foundit_bv;
if ((foundit_bv < foundit_b && foundit_bv != -1) ||
(foundit_b == -1 && foundit_bv != -1))
foundit_b = foundit_bv;
if (foundit_b < 0) //if we did not find an \n
{
/* too much text to fit in one line? */
......@@ -246,7 +254,8 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
/* is there a space to break the line at? OK if it's even
one byte past the end since in this context we know there's
more text */
foundit_b = lastone(x->x_buf + inindex_b, ' ', maxindex_b + 1);
foundit_b =
lastone(x->x_buf + inindex_b, ' ', maxindex_b + 1);
if (foundit_b < 0)
{
foundit_b = maxindex_b;
......@@ -286,12 +295,14 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
inindex_c += (foundit_c + eatchar);
if (inindex_b < x->x_bufsize)
tempbuf[outchars_b++] = '\n';
if (foundit_c > ncolumns) // if we found a row that is longer than previous (total width)
// if we found a row that is longer than previous (total width)
if (foundit_c > ncolumns)
ncolumns = foundit_c;
nlines++;
}
// append new line in case we end our input with an \n
if (x->x_buf[x_bufsize_c - 1] == '\n') {
if (x->x_buf[x_bufsize_c - 1] == '\n')
{
nlines++;
}
if (!reportedindex)
......@@ -324,31 +335,39 @@ static void rtext_senditup(t_rtext *x, int action, int *widthp, int *heightp,
if (newwidth/fontwidth != widthwas)
x->x_text->te_width = widthwas;
else x->x_text->te_width = 0;
//fprintf(stderr,"senditup width %d %d %d\n", newwidth/fontwidth, widthwas, x->x_text->te_width);
//fprintf(stderr,"senditup width %d %d %d\n",
// newwidth/fontwidth, widthwas, x->x_text->te_width);
}
if (action == SEND_FIRST) {
if (action == SEND_FIRST)
{
//fprintf(stderr,"canvas=.x%lx %s\n", (t_int)canvas, tempbuf);
sys_vgui("pdtk_text_new .x%lx.c {%s %s text} %f %f {%.*s} %d %s\n",
canvas, x->x_tag, rtext_gettype(x)->s_name,
dispx + LMARGIN, dispy + TMARGIN,
outchars_b, tempbuf, sys_hostfontsize(font),
(glist_isselected(x->x_glist,
&x->x_glist->gl_gobj)? "$pd_colors(selection)" : "$pd_colors(text)"));
&x->x_glist->gl_gobj)? "$pd_colors(selection)" :
"$pd_colors(text)"));
}
else if (action == SEND_UPDATE)
{
/*fprintf(stderr, "SEND_UPDATE canvas_class=%d isgraph=%d goprect=%d\n",
/*fprintf(stderr,
"SEND_UPDATE canvas_class=%d isgraph=%d goprect=%d\n",
(pd_class(&x->x_text->te_pd) == canvas_class ? 1 : 0),
((t_glist *)(x->x_text))->gl_isgraph,
((t_glist *)(x->x_text))->gl_goprect );*/
sys_vgui("pdtk_text_set .x%lx.c %s {%.*s}\n",
canvas, x->x_tag, outchars_b, tempbuf);
/*if ( pd_class(&x->x_text->te_pd) == canvas_class &&
((t_glist *)(x->x_text))->gl_isgraph &&
(((t_glist *)(x->x_text))->gl_goprect) ) {
(((t_glist *)(x->x_text))->gl_goprect) )
{
fprintf(stderr, "do not update outlets\n");
}
else */
if (pixwide != x->x_drawnwidth || pixhigh != x->x_drawnheight)
text_drawborder(x->x_text, x->x_glist, x->x_tag,
pixwide, pixhigh, 0);
......@@ -501,7 +520,8 @@ void rtext_select(t_rtext *x, int state)
if (glist_istoplevel(glist))
sys_vgui(".x%lx.c itemconfigure %s -fill %s\n", canvas,
x->x_tag, (state? "$pd_colors(selection)" : "$pd_colors(text)"));
if (x->x_text->te_pd->c_wb && x->x_text->te_pd->c_wb->w_displacefnwtag) {
if (x->x_text->te_pd->c_wb && x->x_text->te_pd->c_wb->w_displacefnwtag)
{
if (state)
sys_vgui(".x%lx.c addtag selected withtag %s\n",
glist_getcanvas(glist), x->x_tag);
......@@ -565,10 +585,12 @@ void rtext_key(t_rtext *x, int keynum, t_symbol *keysym)
{
....
} */
if (x->x_selstart && (x->x_selstart == x->x_selend)) {
if (x->x_selstart && (x->x_selstart == x->x_selend))
{
u8_dec(x->x_buf, &x->x_selstart);
if (glist_isvisible(glist_getcanvas(x->x_glist)))
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)glist_getcanvas(x->x_glist));
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n",
(t_int)glist_getcanvas(x->x_glist));
}
}
......@@ -577,7 +599,8 @@ void rtext_key(t_rtext *x, int keynum, t_symbol *keysym)
if (x->x_selend < x->x_bufsize && (x->x_selstart == x->x_selend))
u8_inc(x->x_buf, &x->x_selend);
if (glist_isvisible(glist_getcanvas(x->x_glist)))
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)glist_getcanvas(x->x_glist));
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n",
(t_int)glist_getcanvas(x->x_glist));
}
ndel = x->x_selend - x->x_selstart;
......@@ -607,7 +630,8 @@ be printable in whatever 8-bit character set we find ourselves. */
x->x_bufsize = newsize;
x->x_selstart = x->x_selstart + 1;
if (glist_isvisible(glist_getcanvas(x->x_glist)))
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)glist_getcanvas(x->x_glist));
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n",
(t_int)glist_getcanvas(x->x_glist));
}
/*--moo: check for unicode codepoints beyond 7-bit ASCII --*/
else if (n > 127)
......@@ -651,10 +675,13 @@ be printable in whatever 8-bit character set we find ourselves. */
else if (!strcmp(keysym->s_name, "ShiftRight"))
{
if (!last_sel) last_sel = 2;
if (last_sel == 1 && x->x_selstart < x->x_selend) {
if (last_sel == 1 && x->x_selstart < x->x_selend)
{
if (x->x_selstart < x->x_bufsize)
u8_inc(x->x_buf, &x->x_selstart);
} else {
}
else
{
last_sel = 2;
if (x->x_selend < x->x_bufsize)
u8_inc(x->x_buf, &x->x_selend);
......@@ -663,9 +690,12 @@ be printable in whatever 8-bit character set we find ourselves. */
else if (!strcmp(keysym->s_name, "ShiftLeft"))
{
if (!last_sel) last_sel = 1;
if (last_sel == 2 && x->x_selend > x->x_selstart) {
if (last_sel == 2 && x->x_selend > x->x_selstart)
{
x->x_selend = x->x_selend - 1;
} else {
}
else
{
last_sel = 1;
if (x->x_selstart > 0)
u8_dec(x->x_buf, &x->x_selstart);
......@@ -675,7 +705,9 @@ be printable in whatever 8-bit character set we find ourselves. */
{
if (x->x_selstart)
u8_dec(x->x_buf, &x->x_selstart);
while (x->x_selstart > 0 && (x->x_buf[x->x_selstart] != '\n' && x->x_buf[x->x_selstart] != '\v'))
while (x->x_selstart > 0 &&
(x->x_buf[x->x_selstart] != '\n' &&
x->x_buf[x->x_selstart] != '\v'))
u8_dec(x->x_buf, &x->x_selstart);
x->x_selend = x->x_selstart;
last_sel = 0;
......@@ -713,18 +745,23 @@ be printable in whatever 8-bit character set we find ourselves. */
{
//fprintf(stderr,"ctrleft\n");
/* first find first non-space char going back */
while (x->x_selstart > 0 && rtext_compare_special_chars(x->x_buf[x->x_selstart-1])) {
while (x->x_selstart > 0 &&
rtext_compare_special_chars(x->x_buf[x->x_selstart-1]))
{
//fprintf(stderr,"while 1 <%c>\n", x->x_buf[x->x_selstart-1]);
u8_dec(x->x_buf, &x->x_selstart);
}
/* now go back until you find another space or the beginning of the buffer */
/* now go back until you find another space or
the beginning of the buffer */
while (x->x_selstart > 0 &&
!rtext_compare_special_chars(x->x_buf[x->x_selstart-1])) {
!rtext_compare_special_chars(x->x_buf[x->x_selstart-1]))
{
//fprintf(stderr,"while 2 <%c>\n", x->x_buf[x->x_selstart-1]);
u8_dec(x->x_buf, &x->x_selstart);
}
if (x->x_buf[x->x_selstart+1] == ' ' &&
x->x_buf[x->x_selstart] == ' ') {
x->x_buf[x->x_selstart] == ' ')
{
//fprintf(stderr,"go forward\n");
u8_inc(x->x_buf, &x->x_selstart);
}
......@@ -732,7 +769,8 @@ be printable in whatever 8-bit character set we find ourselves. */
}
else if (!strcmp(keysym->s_name, "CtrlRight"))
{
/* now go forward until you find another space or the end of the buffer */
/* now go forward until you find another space
or the end of the buffer */
if (x->x_selend < x->x_bufsize - 1)
u8_inc(x->x_buf, &x->x_selend);
while (x->x_selend < x->x_bufsize &&
......@@ -748,36 +786,44 @@ be printable in whatever 8-bit character set we find ourselves. */
}
else if (!strcmp(keysym->s_name, "CtrlShiftLeft"))
{
//fprintf(stderr,"ctrlshiftleft %d %d %d\n", last_sel, x->x_selstart, x->x_selend);
//fprintf(stderr,"ctrlshiftleft %d %d %d\n",
// last_sel, x->x_selstart, x->x_selend);
int swap = 0;
int *target;
if (!last_sel) last_sel = 1;
if (last_sel == 2 && x->x_selend > x->x_selstart)
target = &x->x_selend;
else {
else
{
last_sel = 1;
target = &x->x_selstart;
}
/* first find first non-space char going back */
while (*target > 0 && rtext_compare_special_chars(x->x_buf[*target-1])) {
while (*target > 0 &&
rtext_compare_special_chars(x->x_buf[*target-1]))
{
u8_dec(x->x_buf, target);
//(*target)--;
}
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
/* now go back until you find another space or the beginning of the buffer */
/* now go back until you find another space or
the beginning of the buffer */
while (*target > 0 &&
!rtext_compare_special_chars(x->x_buf[*target-1])) {
!rtext_compare_special_chars(x->x_buf[*target-1]))
{
u8_dec(x->x_buf, target);
//(*target)--;
}
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
if (x->x_buf[*target+1] == ' ' &&
x->x_buf[x->x_selstart] == ' ') {
x->x_buf[x->x_selstart] == ' ')
{
u8_inc(x->x_buf, target);
//(*target)++;
}
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
if (x->x_selstart > x->x_selend) {
if (x->x_selstart > x->x_selend)
{
swap = x->x_selend;
x->x_selend = x->x_selstart;
x->x_selstart = swap;
......@@ -786,42 +832,52 @@ be printable in whatever 8-bit character set we find ourselves. */
}
else if (!strcmp(keysym->s_name, "CtrlShiftRight"))
{
//fprintf(stderr,"ctrlshiftright %d %d %d\n", last_sel, x->x_selstart, x->x_selend);
//fprintf(stderr,"ctrlshiftright %d %d %d\n",
// last_sel, x->x_selstart, x->x_selend);
int swap = 0;
int *target;
if (!last_sel) last_sel = 2;
if (last_sel == 1 && x->x_selstart < x->x_selend)
target = &x->x_selstart;
else {
else
{
last_sel = 2;
target = &x->x_selend;
}
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
/* now go forward until you find another space or the end of the buffer */
if (*target < x->x_bufsize - 1) {
/* now go forward until you find another space or
the end of the buffer */
if (*target < x->x_bufsize - 1)
{
//fprintf(stderr,"while 1 <%c>\n", x->x_buf[*target]);
u8_inc(x->x_buf, target);
//(*target)++;
}
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
while (*target < x->x_bufsize &&
!rtext_compare_special_chars(x->x_buf[*target])) {
!rtext_compare_special_chars(x->x_buf[*target]))
{
//fprintf(stderr,"while 2 <%c>\n", x->x_buf[*target]);
u8_inc(x->x_buf, target);
//(*target)++;
}
/* now skip all the spaces and land before next word */
/*while (*target < x->x_bufsize &&
x->x_buf[*target] == ' ') {
x->x_buf[*target] == ' ')
{
u8_inc(x->x_buf, target);
//(*target)++;
}
if (*target > 0 && x->x_buf[*target-1] == ' ') {
if (*target > 0 && x->x_buf[*target-1] == ' ')
{
u8_dec(x->x_buf, target);
//(*target)--;
}*/
//fprintf(stderr,"%d %d\n", x->x_selstart, x->x_selend);
if (x->x_selstart > x->x_selend) {
if (x->x_selstart > x->x_selend)
{
swap = x->x_selend;
x->x_selend = x->x_selstart;
x->x_selstart = swap;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment