aboutsummaryrefslogtreecommitdiff
path: root/src/printwchars.c
blob: 376012013ef5e63961297aeef303dd5de3e0c3ed (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- Mode: C -*- */
/*=============================================================================*\
 * File: printwchars.c
 * Author: Bryan Jurish <moocow@ling.uni-potsdam.de>
 * Description: print byte-strings using post()
 *
 * Copyright (c) 2009 Bryan Jurish.
 *
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
 * WARRANTIES, see the file "COPYING", in this distribution.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *=============================================================================*/

#include <string.h>
#include <wchar.h>
#include <m_pd.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "mooPdUtils.h"
#include "pdstringUtils.h"

/*=====================================================================
 * Constants & Globals
 *=====================================================================*/
static char *printwchars_banner = "printwchars: pdstring version " PACKAGE_VERSION " by Bryan Jurish";

/*=====================================================================
 * Structures and Types: any2string
 *=====================================================================*/

static t_class *printwchars_class;

typedef struct _printwchars
{
  t_object           x_obj;
  t_symbol          *x_prefix;
} t_printwchars;


/*=====================================================================
 * Methods
 *=====================================================================*/

/*--------------------------------------------------------------------
 * anything
 */
static void printwchars_anything(t_printwchars *x, MOO_UNUSED t_symbol *sel, int argc, t_atom *argv)
{
  startpost("%s/%s: ", x->x_prefix->s_name, sel->s_name);
  for (; argc > 0; argc--, argv++) {
    wchar_t c = atom_getfloat(argv);
    startpost("%C", c);
  }
  endpost();
}

#if 0
static void printwchars_anything_v1(t_printwchars *x, MOO_UNUSED t_symbol *sel, int argc, t_atom *argv)
{
  t_pdstring_atoms arg_atoms = { argv, argc, 0 };
  pdstring_atoms2wchars(x, &x->x_wchars, &arg_atoms, PDSTRING_EOS_NONE);
  post("%S/%S: %S", x->x_prefix->s_name, sel->s_name, x->x_wchars.w_buf);
}
#endif

/*--------------------------------------------------------------------
 * new
 */
static void *printwchars_new(t_symbol *prefix)
{
    t_printwchars *x = (t_printwchars *)pd_new(printwchars_class);

    if (prefix == &s_) prefix = gensym("printwchars");
    x->x_prefix = prefix;

    //pdstring_wchars_init(&x->x_wchars, PDSTRING_DEFAULT_BUFLEN);
    return (void *)x;
}

/*--------------------------------------------------------------------
 * free
 */
static void printwchars_free(t_printwchars *x)
{
  //pdstring_wchars_clear(&x->x_wchars);
  return;
}

/*--------------------------------------------------------------------
 * setup: guts
 */
void printwchars_setup_guts(void)
{
  //-- check/set "initialized" flag
  //if (PRINTWCHARS_INITIALIZED) return;
  //PRINTWCHARS_INITIALIZED = 1;

  //-- class
  printwchars_class = class_new(gensym("printwchars"),
			       (t_newmethod)printwchars_new,
			       (t_method)printwchars_free,
			       sizeof(t_printwchars),
			       CLASS_DEFAULT,
			       A_DEFSYM,                   //-- print-prefix
			       0);

  //-- alias
  //class_addcreator((t_newmethod)printwchars_new, gensym("printstring"), A_GIMME, 0);
  
  //-- methods
  class_addanything(printwchars_class, (t_method)printwchars_anything);

  //-- help symbol
  //class_sethelpsymbol(printwchars_class, gensym("printwchars-help.pd")); //-- breaks pd-extended help lookup
}

/*--------------------------------------------------------------------
 * setup
 */
void printwchars_setup(void)
{
  post(printwchars_banner);
  printwchars_setup_guts();
}