aboutsummaryrefslogtreecommitdiff
path: root/src/rawprint.c
blob: 68aac73a1dcae09df60c6e1a8b1eb6adb54f5db7 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* 
 * rawprint:  print the incoming message as raw as possible
 *
 * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "zexy.h"
#include <stdio.h>

#ifdef _MSC_VER 
# define snprintf _snprintf
#endif

#if !defined( _MSC_VER ) && defined (_WIN32)
# ifndef _get_output_format
//int _get_output_format( void ){ return 0; }
# endif
#endif

static t_class *rawprint_class;

typedef struct _rawprint {
  t_object  x_obj;
  t_symbol*label;
} t_rawprint;

static void rawprint_any(t_rawprint *x, t_symbol*s, int argc, t_atom*argv)
{
  char buf[MAXPDSTRING];
  if(x->label) {
    startpost("%s: ", x->label->s_name);
  }
  startpost("\"%s\"", s->s_name);
  while(argc--) {
    switch(argv->a_type) {
    case A_FLOAT:
      snprintf(buf, MAXPDSTRING-1, "%f", atom_getfloat(argv));
      break;
    case A_SYMBOL:
      snprintf(buf, MAXPDSTRING-1, "'%s'", atom_getsymbol(argv)->s_name);
      break;
    case A_POINTER:
      snprintf(buf, MAXPDSTRING-1, "pointer[%p]", argv->a_w.w_gpointer);
      break;
    case A_SEMI:
      snprintf(buf, MAXPDSTRING-1, "SEMI");
      break;
    case A_COMMA:
      snprintf(buf, MAXPDSTRING-1, "COMMA");
      break;
    case A_DEFFLOAT:
      snprintf(buf, MAXPDSTRING-1, "DEFFLOAT[%f]", atom_getfloat(argv));
      break;
    case A_DEFSYM:
      snprintf(buf, MAXPDSTRING-1, "DEFSYM['%s']", atom_getsymbol(argv)->s_name);
      break;
    case A_DOLLAR:
      snprintf(buf, MAXPDSTRING-1, "DOLLAR['%s']", atom_getsymbol(argv)->s_name);
      break;
    case A_DOLLSYM:
      snprintf(buf, MAXPDSTRING-1, "DOLLSYM['%s']", atom_getsymbol(argv)->s_name);
      break;
    case A_GIMME:
      snprintf(buf, MAXPDSTRING-1, "GIMME");
      break;
    case A_CANT: // we _really_ cannot do CANT
      snprintf(buf, MAXPDSTRING-1, "CANT");
      break;
    default:
      snprintf(buf, MAXPDSTRING-1, "unknown[%d]", argv->a_type);
    }
    buf[MAXPDSTRING-1]=0;
    
    startpost(" %s", buf);
    argv++;
  }
  endpost();

}

static void *rawprint_new(t_symbol*s)
{
  t_rawprint *x = (t_rawprint *)pd_new(rawprint_class);
  x->label=NULL;
  if(s&&gensym("")!=s)
    x->label=s;

  return (x);
}

void rawprint_setup(void) {
  rawprint_class = class_new(gensym("rawprint"),
                             (t_newmethod)rawprint_new,
                             0, sizeof(t_rawprint),
                             CLASS_DEFAULT, A_DEFSYMBOL, 0);

  class_addanything(rawprint_class, rawprint_any);
  zexy_register("rawprint");
}