aboutsummaryrefslogtreecommitdiff
path: root/packages/patches/makefilename_scanformat-0.41.0-test04.patch
blob: d2c8ab2b6e775cdc1b7a5df670586b5dd15993c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Index: x_connective.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/x_connective.c,v
retrieving revision 1.9
diff -u -w -r1.9 x_connective.c
--- x_connective.c	24 Aug 2006 15:23:52 -0000	1.9
+++ x_connective.c	30 Jul 2007 18:15:23 -0000
@@ -1202,34 +1202,86 @@
 {
     t_object x_obj;
     t_symbol *x_format;
+    t_atomtype x_accept;
+    int x_intconvert;
 } t_makefilename;
 
+static void makefilename_scanformat(t_makefilename *x)
+{
+    int num=0, infmt=0;
+    char *str,*chr;
+    if (!x->x_format) return;
+    x->x_accept = A_NULL;
+    for (str=x->x_format->s_name; *str; str++) {
+        if (!infmt && *str=='%') {
+            infmt=1;
+            continue;
+        }
+        if (infmt) {
+            if (strchr("-.#0123456789",*str)!=0)
+                continue;
+            if (*str=='s') {
+                x->x_accept = A_SYMBOL;
+                x->x_intconvert = 0;
+                break;
+            }
+            if (strchr("fgGeE",*str)!=0) {
+                x->x_accept = A_FLOAT;
+                x->x_intconvert = 0;
+                break;
+            }
+            if (strchr("xXdiou",*str)!=0) {
+                x->x_accept = A_FLOAT;
+                x->x_intconvert = 1;
+                break;
+            }
+            infmt=0;
+        }
+    }
+}
+
 static void *makefilename_new(t_symbol *s)
 {
     t_makefilename *x = (t_makefilename *)pd_new(makefilename_class);
-    if (!s->s_name) s = gensym("file.%d");
+    if (!s || !s->s_name) s = gensym("file.%d");
     outlet_new(&x->x_obj, &s_symbol);
     x->x_format = s;
+    x->x_accept = A_NULL;
+    x->x_intconvert = 0;
+    makefilename_scanformat(x);
     return (x);
 }
 
 static void makefilename_float(t_makefilename *x, t_floatarg f)
 {
     char buf[MAXPDSTRING];
+    if (x->x_accept == A_FLOAT) {
+        if (x->x_intconvert)
     sprintf(buf, x->x_format->s_name, (int)f);
+        else
+            sprintf(buf, x->x_format->s_name, f);
+    }
+    else
+        sprintf(buf, x->x_format->s_name, "");
+    if (buf[0]!=0)
     outlet_symbol(x->x_obj.ob_outlet, gensym(buf));
 }
 
 static void makefilename_symbol(t_makefilename *x, t_symbol *s)
 {
     char buf[MAXPDSTRING];
+    if (x->x_accept == A_SYMBOL)
     sprintf(buf, x->x_format->s_name, s->s_name);
+    else
+        sprintf(buf, x->x_format->s_name, 0);
+    if (buf[0]!=0)
     outlet_symbol(x->x_obj.ob_outlet, gensym(buf));
 }
 
 static void makefilename_set(t_makefilename *x, t_symbol *s)
 {
     x->x_format = s;
+    makefilename_scanformat(x);
 }
 
 static void makefilename_setup(void)