aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2006-06-27 16:44:42 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2006-06-27 16:44:42 +0000
commit0955f6d47a84dd1e510649b1659dfa0fe28cd076 (patch)
tree4bb584ce48ed64e95719b43bff5fdda3ca0f6148
parent3f05771340e68450a712681277a6ab28fc73a32c (diff)
added a new writing mode: '$$' which converts occurences of "$$" to "\$", in order to be able to write pd-patches which make use of arguments
svn path=/trunk/externals/zexy/; revision=5306
-rw-r--r--examples/msgfile.pd22
-rw-r--r--src/msgfile.c30
2 files changed, 41 insertions, 11 deletions
diff --git a/examples/msgfile.pd b/examples/msgfile.pd
index fb375f6..e41c0b3 100644
--- a/examples/msgfile.pd
+++ b/examples/msgfile.pd
@@ -112,7 +112,7 @@ if the [msgfile];
#X connect 20 0 0 0;
#X connect 22 0 0 0;
#X restore 443 104 pd editing;
-#N canvas -25 21 576 302 searching 0;
+#N canvas 0 21 576 302 searching 0;
#X obj 54 272 outlet;
#X msg 70 180 find test 6;
#X msg 70 239 find test * 7 *;
@@ -130,11 +130,11 @@ and the list is output (via the 2nd and 1st outlet).;
#X connect 2 0 0 0;
#X connect 6 0 0 0;
#X restore 443 124 pd searching;
-#N canvas 0 0 626 356 file-i/o 0;
-#X obj 54 272 outlet;
-#X text 195 75 read a file;
-#X text 229 96 write one;
-#X text 254 164 write a file \, terminating lines only with carriage
+#N canvas 0 0 853 402 file-i/o 0;
+#X obj 54 312 outlet;
+#X text 265 75 read a file;
+#X text 299 96 write one;
+#X text 305 164 write a file \, terminating lines only with carriage
return (omitting semicolons.) You can read files this way too \, in
which case carriage returns are mapped to semicolons.;
#X msg 87 76 read msgfile.txt;
@@ -143,13 +143,19 @@ which case carriage returns are mapped to semicolons.;
#X msg 87 97 write /tmp/msgfile.txt;
#X text 51 26 reading from and writing the contents of [msgfile] to
files;
+#X msg 111 248 write /tmp/msgfile3.txt $$;
+#X text 331 238 on writing replace every occurence of $$ with a single
+$. This way you can write pd-patches which can handle arguments.;
+#X msg 146 291 add #X obj f $$1;
#X connect 4 0 0 0;
#X connect 5 0 0 0;
#X connect 6 0 0 0;
#X connect 7 0 0 0;
+#X connect 9 0 0 0;
+#X connect 11 0 0 0;
#X restore 443 144 pd file-i/o;
-#N canvas 0 0 450 199 misc 0;
-#X obj 84 142 outlet;
+#N canvas 0 0 450 397 misc 0;
+#X obj 84 282 outlet;
#X msg 84 112 print;
#X text 40 72 miscellaneous functionality of [msgfile];
#X text 126 114 debugging printout of the contents to the console;
diff --git a/src/msgfile.c b/src/msgfile.c
index 29c3121..bdc94e6 100644
--- a/src/msgfile.c
+++ b/src/msgfile.c
@@ -653,6 +653,8 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format)
char separator, eol;
int mode = x->mode;
+ int dollarmode = 0;
+
FILE *f=0;
while (x->current && x->current->previous) x->current=x->current->previous;
@@ -667,6 +669,7 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format)
canvas_makefilename(x->x_canvas, filename->s_name,
buf, MAXPDSTRING);
+#if 0
if (!strcmp(format->s_name, "cr")) {
mode = CR_MODE;
} else if (!strcmp(format->s_name, "csv")) {
@@ -675,6 +678,22 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format)
mode = PD_MODE;
} else if (*format->s_name)
error("msgfile_write: unknown flag: %s", format->s_name);
+#else
+ if(gensym("cr")==format) {
+ mode = CR_MODE;
+ } else if(gensym("cvs")==format) {
+ mode = CSV_MODE;
+ } else if(gensym("pd")==format) {
+ mode = PD_MODE;
+ } else if(gensym("$$")==format) {
+ mode = PD_MODE;
+ dollarmode=1;
+ } else if(format&&format->s_name) {
+ error("msgfile_write: ignoring unknown flag: %s", format->s_name);
+ }
+
+
+#endif
switch (mode) {
case CR_MODE:
@@ -696,11 +715,15 @@ static void msgfile_write(t_msgfile *x, t_symbol *filename, t_symbol *format)
i = textlen;
while(i--) {
- if (*dumtext==' ') *dumtext=separator;
- if ((*dumtext==';') && (dumtext[1]=='\n')) *dumtext = eol;
+ if (*dumtext==' ')
+ *dumtext=separator;
+ else if ((*dumtext==';') && (dumtext[1]=='\n'))
+ *dumtext = eol;
+ else if(dollarmode && (*dumtext=='$') && (dumtext[1]=='$'))
+ *dumtext='\\';
dumtext++;
}
-
+
/* open */
sys_bashfilename(filename->s_name, filnam);
if (!(f = fopen(filnam, "w"))) {
@@ -787,6 +810,7 @@ static void *msgfile_new(t_symbol *s, int argc, t_atom *argv)
x->eol=' ';
x->separator=',';
+
return (x);
}