summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/m_binbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_binbuf.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/m_binbuf.c138
1 files changed, 124 insertions, 14 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_binbuf.c b/apps/plugins/pdbox/PDa/src/m_binbuf.c
index 03a560db7b..224d269559 100644
--- a/apps/plugins/pdbox/PDa/src/m_binbuf.c
+++ b/apps/plugins/pdbox/PDa/src/m_binbuf.c
@@ -10,9 +10,15 @@
10 * change marked with IOhannes 10 * change marked with IOhannes
11 */ 11 */
12 12
13#ifdef ROCKBOX
14#include "plugin.h"
15#include "pdbox.h"
16#ifdef SIMULATOR
17int printf(const char *fmt, ...);
18void perror(const char*);
19#endif
20#else /* ROCKBOX */
13#include <stdlib.h> 21#include <stdlib.h>
14#include "m_pd.h"
15#include "s_stuff.h"
16#include <stdio.h> 22#include <stdio.h>
17#ifdef UNIX 23#ifdef UNIX
18#include <unistd.h> 24#include <unistd.h>
@@ -21,8 +27,13 @@
21#include <io.h> 27#include <io.h>
22#endif 28#endif
23#include <fcntl.h> 29#include <fcntl.h>
30
24#include <string.h> 31#include <string.h>
25#include <stdarg.h> 32#include <stdarg.h>
33#endif /* ROCKBOX */
34
35#include "m_pd.h"
36#include "s_stuff.h"
26 37
27struct _binbuf 38struct _binbuf
28{ 39{
@@ -72,7 +83,9 @@ void binbuf_text(t_binbuf *x, char *text, size_t size)
72 x->b_n = 0; 83 x->b_n = 0;
73 while (1) 84 while (1)
74 { 85 {
86#ifndef ROCKBOX
75 int type; 87 int type;
88#endif
76 /* skip leading space */ 89 /* skip leading space */
77 while ((textp != etext) && (*textp == ' ' || *textp == '\n' 90 while ((textp != etext) && (*textp == ' ' || *textp == '\n'
78 || *textp == '\r' || *textp == '\t')) textp++; 91 || *textp == '\r' || *textp == '\t')) textp++;
@@ -158,6 +171,7 @@ void binbuf_text(t_binbuf *x, char *text, size_t size)
158#if 0 171#if 0
159 post("buf %s", buf); 172 post("buf %s", buf);
160#endif 173#endif
174
161 if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9' && !firstslash) 175 if (*buf == '$' && buf[1] >= '0' && buf[1] <= '9' && !firstslash)
162 { 176 {
163 for (bufp = buf+2; *bufp; bufp++) 177 for (bufp = buf+2; *bufp; bufp++)
@@ -219,7 +233,7 @@ void binbuf_gettext(t_binbuf *x, char **bufp, int *lengthp)
219 } 233 }
220 if (length && buf[length-1] == ' ') 234 if (length && buf[length-1] == ' ')
221 { 235 {
222 if (newbuf = t_resizebytes(buf, length, length-1)) 236 if((newbuf = t_resizebytes(buf, length, length-1)))
223 { 237 {
224 buf = newbuf; 238 buf = newbuf;
225 length--; 239 length--;
@@ -236,8 +250,8 @@ void binbuf_add(t_binbuf *x, int argc, t_atom *argv)
236{ 250{
237 int newsize = x->b_n + argc, i; 251 int newsize = x->b_n + argc, i;
238 t_atom *ap; 252 t_atom *ap;
239 if (ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec), 253 if((ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec),
240 newsize * sizeof(*x->b_vec))) 254 newsize * sizeof(*x->b_vec))))
241 x->b_vec = ap; 255 x->b_vec = ap;
242 else 256 else
243 { 257 {
@@ -310,11 +324,19 @@ void binbuf_addbinbuf(t_binbuf *x, t_binbuf *y)
310 SETSYMBOL(ap, gensym(",")); 324 SETSYMBOL(ap, gensym(","));
311 break; 325 break;
312 case A_DOLLAR: 326 case A_DOLLAR:
327#ifdef ROCKBOX
328 snprintf(tbuf, sizeof(tbuf)-1, "$%d", ap->a_w.w_index);
329#else /* ROCKBOX */
313 sprintf(tbuf, "$%d", ap->a_w.w_index); 330 sprintf(tbuf, "$%d", ap->a_w.w_index);
331#endif /* ROCKBOX */
314 SETSYMBOL(ap, gensym(tbuf)); 332 SETSYMBOL(ap, gensym(tbuf));
315 break; 333 break;
316 case A_DOLLSYM: 334 case A_DOLLSYM:
335#ifdef ROCKBOX
336 snprintf(tbuf, sizeof(tbuf)-1, "$%s", ap->a_w.w_symbol->s_name);
337#else /* ROCKBOX */
317 sprintf(tbuf, "$%s", ap->a_w.w_symbol->s_name); 338 sprintf(tbuf, "$%s", ap->a_w.w_symbol->s_name);
339#endif /* ROCKBOX */
318 SETSYMBOL(ap, gensym(tbuf)); 340 SETSYMBOL(ap, gensym(tbuf));
319 break; 341 break;
320 case A_SYMBOL: 342 case A_SYMBOL:
@@ -346,8 +368,8 @@ void binbuf_restore(t_binbuf *x, int argc, t_atom *argv)
346{ 368{
347 int newsize = x->b_n + argc, i; 369 int newsize = x->b_n + argc, i;
348 t_atom *ap; 370 t_atom *ap;
349 if (ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec), 371 if((ap = t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec),
350 newsize * sizeof(*x->b_vec))) 372 newsize * sizeof(*x->b_vec))))
351 x->b_vec = ap; 373 x->b_vec = ap;
352 else 374 else
353 { 375 {
@@ -374,7 +396,11 @@ void binbuf_restore(t_binbuf *x, int argc, t_atom *argv)
374 else 396 else
375 { 397 {
376 int dollar = 0; 398 int dollar = 0;
399#ifdef ROCKBOX
400 dollar = atoi(argv->a_w.w_symbol->s_name + 1);
401#else
377 sscanf(argv->a_w.w_symbol->s_name + 1, "%d", &dollar); 402 sscanf(argv->a_w.w_symbol->s_name + 1, "%d", &dollar);
403#endif
378 SETDOLLAR(ap, dollar); 404 SETDOLLAR(ap, dollar);
379 } 405 }
380 } 406 }
@@ -430,10 +456,18 @@ t_symbol *binbuf_realizedollsym(t_symbol *s, int ac, t_atom *av, int tonew)
430 { 456 {
431 if (!tonew) 457 if (!tonew)
432 return (0); 458 return (0);
459#ifdef ROCKBOX
460 else snprintf(buf, sizeof(buf)-1, "$%d", argno);
461#else /* ROCKBOX */
433 else sprintf(buf, "$%d", argno); 462 else sprintf(buf, "$%d", argno);
463#endif /* ROCKBOX */
434 } 464 }
435 else if (argno == 0) 465 else if (argno == 0)
466#ifdef ROCKBOX
467 snprintf(buf, sizeof(buf)-1, "%d", canvas_getdollarzero());
468#else /* ROCKBOX */
436 sprintf(buf, "%d", canvas_getdollarzero()); 469 sprintf(buf, "%d", canvas_getdollarzero());
470#endif /* ROCKBOX */
437 else 471 else
438 atom_string(av+(argno-1), buf, MAXPDSTRING/2-1); 472 atom_string(av+(argno-1), buf, MAXPDSTRING/2-1);
439 strncat(buf, sp, MAXPDSTRING/2-1); 473 strncat(buf, sp, MAXPDSTRING/2-1);
@@ -582,6 +616,10 @@ void binbuf_eval(t_binbuf *x, t_pd *target, int argc, t_atom *argv)
582 if (nargs == 1) pd_float(target, stackwas->a_w.w_float); 616 if (nargs == 1) pd_float(target, stackwas->a_w.w_float);
583 else pd_list(target, 0, nargs, stackwas); 617 else pd_list(target, 0, nargs, stackwas);
584 break; 618 break;
619#ifdef ROCKBOX
620 default:
621 break;
622#endif
585 } 623 }
586 } 624 }
587 msp = stackwas; 625 msp = stackwas;
@@ -606,12 +644,14 @@ static int binbuf_doopen(char *s, int mode)
606 return (open(namebuf, mode)); 644 return (open(namebuf, mode));
607} 645}
608 646
647#ifndef ROCKBOX
609static FILE *binbuf_dofopen(char *s, char *mode) 648static FILE *binbuf_dofopen(char *s, char *mode)
610{ 649{
611 char namebuf[MAXPDSTRING]; 650 char namebuf[MAXPDSTRING];
612 sys_bashfilename(s, namebuf); 651 sys_bashfilename(s, namebuf);
613 return (fopen(namebuf, mode)); 652 return (fopen(namebuf, mode));
614} 653}
654#endif
615 655
616int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag) 656int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
617{ 657{
@@ -620,30 +660,51 @@ int binbuf_read(t_binbuf *b, char *filename, char *dirname, int crflag)
620 int readret; 660 int readret;
621 char *buf; 661 char *buf;
622 char namebuf[MAXPDSTRING]; 662 char namebuf[MAXPDSTRING];
623 663
624 namebuf[0] = 0; 664 namebuf[0] = 0;
625 if (*dirname) 665 if (*dirname)
626 strcat(namebuf, dirname), strcat(namebuf, "/"); 666 strcat(namebuf, dirname), strcat(namebuf, "/");
627 strcat(namebuf, filename); 667 strcat(namebuf, filename);
628 668
629 if ((fd = binbuf_doopen(namebuf, 0)) < 0) 669 if ((fd = binbuf_doopen(namebuf, 0)) < 0)
630 { 670 {
671#ifdef ROCKBOX
672#ifdef SIMULATOR
673 printf("open: ");
674 perror(namebuf);
675#endif /* SIMULATOR */
676#else /* ROCKBOX */
631 fprintf(stderr, "open: "); 677 fprintf(stderr, "open: ");
632 perror(namebuf); 678 perror(namebuf);
679#endif /* ROCKBOX */
633 return (1); 680 return (1);
634 } 681 }
635 if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0, SEEK_SET) < 0 682 if ((length = lseek(fd, 0, SEEK_END)) < 0 || lseek(fd, 0, SEEK_SET) < 0
636 || !(buf = t_getbytes(length))) 683 || !(buf = t_getbytes(length)))
637 { 684 {
685#ifdef ROCKBOX
686#ifdef SIMULATOR
687 printf("lseek: ");
688 perror(namebuf);
689#endif /* SIMULATOR */
690#else /* ROCKBOX */
638 fprintf(stderr, "lseek: "); 691 fprintf(stderr, "lseek: ");
639 perror(namebuf); 692 perror(namebuf);
693#endif /* ROCKBOX */
640 close(fd); 694 close(fd);
641 return(1); 695 return(1);
642 } 696 }
643 if ((readret = read(fd, buf, length)) < length) 697 if ((readret = read(fd, buf, length)) < length)
644 { 698 {
699#ifdef ROCKBOX
700#ifdef SIMULATOR
701 printf("read (%d %ld) -> %d\n", fd, length, readret);
702 perror(namebuf);
703#endif /* SIMULATOR */
704#else /* ROCKBOX */
645 fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret); 705 fprintf(stderr, "read (%d %ld) -> %d\n", fd, length, readret);
646 perror(namebuf); 706 perror(namebuf);
707#endif /* ROCKBOX */
647 close(fd); 708 close(fd);
648 t_freebytes(buf, length); 709 t_freebytes(buf, length);
649 return(1); 710 return(1);
@@ -691,7 +752,11 @@ static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd);
691 semicolons. */ 752 semicolons. */
692int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag) 753int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
693{ 754{
755#ifdef ROCKBOX
756 int f = 0;
757#else /* ROCKBOX */
694 FILE *f = 0; 758 FILE *f = 0;
759#endif /* ROCKBOX */
695 char sbuf[WBUFSIZE], fbuf[MAXPDSTRING], *bp = sbuf, *ep = sbuf + WBUFSIZE; 760 char sbuf[WBUFSIZE], fbuf[MAXPDSTRING], *bp = sbuf, *ep = sbuf + WBUFSIZE;
696 t_atom *ap; 761 t_atom *ap;
697 int indx, deleteit = 0; 762 int indx, deleteit = 0;
@@ -707,9 +772,19 @@ int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
707 deleteit = 1; 772 deleteit = 1;
708 } 773 }
709 774
775#ifdef ROCKBOX
776 if(!(f = binbuf_doopen(fbuf, O_WRONLY|O_CREAT|O_TRUNC)))
777#else /* ROCKBOX */
710 if (!(f = binbuf_dofopen(fbuf, "w"))) 778 if (!(f = binbuf_dofopen(fbuf, "w")))
779#endif /* ROCKBOX */
711 { 780 {
781#ifdef ROCKBOX
782#ifdef SIMULATOR
783 printf("open: ");
784#endif /* SIMULATOR */
785#else /* ROCKBOX */
712 fprintf(stderr, "open: "); 786 fprintf(stderr, "open: ");
787#endif /* ROCKBOX */
713 sys_unixerror(fbuf); 788 sys_unixerror(fbuf);
714 goto fail; 789 goto fail;
715 } 790 }
@@ -723,7 +798,11 @@ int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
723 else length = 40; 798 else length = 40;
724 if (ep - bp < length) 799 if (ep - bp < length)
725 { 800 {
801#ifdef ROCKBOX
802 if(write(f, sbuf, bp-sbuf) < 1)
803#else /* ROCKBOX */
726 if (fwrite(sbuf, bp-sbuf, 1, f) < 1) 804 if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
805#endif /* ROCKBOX */
727 { 806 {
728 sys_unixerror(fbuf); 807 sys_unixerror(fbuf);
729 goto fail; 808 goto fail;
@@ -750,20 +829,32 @@ int binbuf_write(t_binbuf *x, char *filename, char *dir, int crflag)
750 ncolumn++; 829 ncolumn++;
751 } 830 }
752 } 831 }
832#ifdef ROCKBOX
833 if(write(f, sbuf, bp-sbuf) < 1)
834#else /* ROCKBOX */
753 if (fwrite(sbuf, bp-sbuf, 1, f) < 1) 835 if (fwrite(sbuf, bp-sbuf, 1, f) < 1)
836#endif /* ROCKBOX */
754 { 837 {
755 sys_unixerror(fbuf); 838 sys_unixerror(fbuf);
756 goto fail; 839 goto fail;
757 } 840 }
758 if (deleteit) 841 if (deleteit)
759 binbuf_free(x); 842 binbuf_free(x);
843#ifdef ROCKBOX
844 close(f);
845#else /* ROCKBOX */
760 fclose(f); 846 fclose(f);
847#endif /* ROCKBOX */
761 return (0); 848 return (0);
762fail: 849fail:
763 if (deleteit) 850 if (deleteit)
764 binbuf_free(x); 851 binbuf_free(x);
765 if (f) 852 if (f)
766 fclose(f); 853#ifdef ROCKBOX
854 close(f);
855#else /* ROCKBOX */
856 fclose(f);
857#endif /* ROCKBOX */
767 return (1); 858 return (1);
768} 859}
769 860
@@ -816,13 +907,21 @@ static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd)
816 if (nextmess[i].a_type == A_DOLLAR) 907 if (nextmess[i].a_type == A_DOLLAR)
817 { 908 {
818 char buf[100]; 909 char buf[100];
910#ifdef ROCKBOX
911 snprintf(buf, sizeof(buf)-1, "$%d", nextmess[i].a_w.w_index);
912#else /* ROCKBOX */
819 sprintf(buf, "$%d", nextmess[i].a_w.w_index); 913 sprintf(buf, "$%d", nextmess[i].a_w.w_index);
914#endif /* ROCKBOX */
820 SETSYMBOL(nextmess+i, gensym(buf)); 915 SETSYMBOL(nextmess+i, gensym(buf));
821 } 916 }
822 else if (nextmess[i].a_type == A_DOLLSYM) 917 else if (nextmess[i].a_type == A_DOLLSYM)
823 { 918 {
824 char buf[100]; 919 char buf[100];
920#ifdef ROCKBOX
921 snprintf(buf, sizeof(buf)-1, "$%s", nextmess[i].a_w.w_symbol->s_name);
922#else /* ROCKBOX */
825 sprintf(buf, "$%s", nextmess[i].a_w.w_symbol->s_name); 923 sprintf(buf, "$%s", nextmess[i].a_w.w_symbol->s_name);
924#endif /* ROCKBOX */
826 SETSYMBOL(nextmess+i, gensym(buf)); 925 SETSYMBOL(nextmess+i, gensym(buf));
827 } 926 }
828 } 927 }
@@ -846,7 +945,11 @@ static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd)
846 atom_getfloatarg(2, natom, nextmess), 945 atom_getfloatarg(2, natom, nextmess),
847 atom_getfloatarg(5, natom, nextmess) - 946 atom_getfloatarg(5, natom, nextmess) -
848 atom_getfloatarg(3, natom, nextmess), 947 atom_getfloatarg(3, natom, nextmess),
948#ifdef ROCKBOX
949 10.0);
950#else
849 (float)sys_defaultfont); 951 (float)sys_defaultfont);
952#endif
850 } 953 }
851 } 954 }
852 if (!strcmp(first, "#P")) 955 if (!strcmp(first, "#P"))
@@ -1157,13 +1260,13 @@ int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf)
1157 t_atom *a1 = &inbuf->b_vec[indexin + nmatched], 1260 t_atom *a1 = &inbuf->b_vec[indexin + nmatched],
1158 *a2 = &searchbuf->b_vec[nmatched]; 1261 *a2 = &searchbuf->b_vec[nmatched];
1159 if (a1->a_type != a2->a_type || 1262 if (a1->a_type != a2->a_type ||
1160 a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol 1263 (a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol)
1161 || 1264 ||
1162 a1->a_type == A_FLOAT && a1->a_w.w_float != a2->a_w.w_float 1265 (a1->a_type == A_FLOAT && a1->a_w.w_float != a2->a_w.w_float)
1163 || 1266 ||
1164 a1->a_type == A_DOLLAR && a1->a_w.w_index != a2->a_w.w_index 1267 (a1->a_type == A_DOLLAR && a1->a_w.w_index != a2->a_w.w_index)
1165 || 1268 ||
1166 a1->a_type == A_DOLLSYM && a1->a_w.w_symbol != a2->a_w.w_symbol) 1269 (a1->a_type == A_DOLLSYM && a1->a_w.w_symbol != a2->a_w.w_symbol))
1167 goto nomatch; 1270 goto nomatch;
1168 } 1271 }
1169 return (1); 1272 return (1);
@@ -1183,9 +1286,12 @@ void binbuf_evalfile(t_symbol *name, t_symbol *dir)
1183 /* set filename so that new canvases can pick them up */ 1286 /* set filename so that new canvases can pick them up */
1184 int dspstate = canvas_suspend_dsp(); 1287 int dspstate = canvas_suspend_dsp();
1185 glob_setfilename(0, name, dir); 1288 glob_setfilename(0, name, dir);
1289
1186 if (binbuf_read(b, name->s_name, dir->s_name, 0)) 1290 if (binbuf_read(b, name->s_name, dir->s_name, 0))
1187 { 1291 {
1292#if !defined(ROCKBOX) || (defined(ROCKBOX) && defined(SIMULATOR))
1188 perror(name->s_name); 1293 perror(name->s_name);
1294#endif
1189 } 1295 }
1190 else 1296 else
1191 { 1297 {
@@ -1205,6 +1311,10 @@ void binbuf_evalfile(t_symbol *name, t_symbol *dir)
1205void glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir) 1311void glob_evalfile(t_pd *ignore, t_symbol *name, t_symbol *dir)
1206{ 1312{
1207 t_pd *x = 0; 1313 t_pd *x = 0;
1314
1315#ifdef ROCKBOX
1316 (void) ignore;
1317#endif
1208 /* even though binbuf_evalfile appears to take care of dspstate, 1318 /* even though binbuf_evalfile appears to take care of dspstate,
1209 we have to do it again here, because canvas_startdsp() assumes 1319 we have to do it again here, because canvas_startdsp() assumes
1210 that all toplevel canvases are visible. LATER check if this 1320 that all toplevel canvases are visible. LATER check if this