~ubuntu-branches/ubuntu/trusty/pd-zexy/trusty-proposed

« back to all changes in this revision

Viewing changes to src/date.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard, IOhannes m zmölnig, Jonas Smedegaard
  • Date: 2010-08-20 12:17:41 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100820121741-4kxozn8b9rhee9fr
Tags: 2.2.3-1
* New upstream version

[ IOhannes m zmölnig ]
* Adopt package, on behalf of Multimedia Team.
  Closes: #546964
* Simply debian/rules with CDBS, and don't unconditionally strip
  binaries.
  Closes: #437763
* Install into /usr/lib/pd/extra/zexy/. Document usage in REAME.Debian
  and warn about change in NEWS.
* git'ify package. Add Vcs-* stanzas to control file.
* Use dpkg source format 3.0 (quilt). Drop build-dependency on quilt.

[ Jonas Smedegaard ]
* Enable CDBS copyright-check routine.
* Add copyright and licensing header to debian/rules.
* Add myself as uploader.
* Rewrite debian/copyright using rev. 135 of draft DEP5 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
 *
 
3
 * zexy - implementation file
 
4
 *
 
5
 * copyleft (c) IOhannes m zm�lnig
 
6
 *
 
7
 *   1999:forum::f�r::uml�ute:2004
 
8
 *
 
9
 *   institute of electronic music and acoustics (iem)
 
10
 *
 
11
 ******************************************************
 
12
 *
 
13
 * license: GNU General Public License v.2
 
14
 *
 
15
 ******************************************************/
 
16
 
 
17
/* 
 
18
   (c) 1202:forum::f�r::uml�ute:2000
 
19
   1506:forum::f�r::uml�ute:2003: use timeb only if needed (like on windoze)
 
20
   
 
21
   "time" gets the current time from the system
 
22
   "date" gets the current date from the system
 
23
   
 
24
*/
 
25
 
 
26
#include "zexy.h"
 
27
 
 
28
#ifdef __WIN32__
 
29
# define USE_TIMEB
 
30
#endif
 
31
 
 
32
#ifdef __APPLE__
 
33
# include <sys/types.h>
 
34
/* typedef     _BSD_TIME_T_    time_t;                */
 
35
#endif
 
36
 
 
37
 
 
38
#include <time.h>
 
39
 
 
40
#ifdef USE_TIMEB
 
41
# include <sys/timeb.h>
 
42
#else
 
43
# include <sys/time.h>
 
44
#endif
 
45
 
 
46
 
 
47
/* ----------------------- date --------------------- */
 
48
 
 
49
static t_class *date_class;
 
50
 
 
51
typedef struct _date
 
52
{
 
53
  t_object x_obj;
 
54
  
 
55
  int GMT;
 
56
  
 
57
  t_outlet *x_outlet1;
 
58
  t_outlet *x_outlet2;
 
59
  t_outlet *x_outlet3;
 
60
  t_outlet *x_outlet4;
 
61
  t_outlet *x_outlet5;
 
62
  t_outlet *x_outlet6;
 
63
} t_date;
 
64
 
 
65
static void *date_new(t_symbol *s, int argc, t_atom *argv)
 
66
{
 
67
  t_date *x = (t_date *)pd_new(date_class);
 
68
  char buf[5];
 
69
  ZEXY_USEVAR(s);
 
70
 
 
71
  x->GMT=0;
 
72
  if (argc) {
 
73
    atom_string(argv, buf, 5);
 
74
    if (buf[0]=='G' && buf[1]=='M' && buf[2]=='T')
 
75
      x->GMT = 1;
 
76
  }
 
77
  
 
78
  x->x_outlet1 = outlet_new(&x->x_obj, &s_float);
 
79
  x->x_outlet2 = outlet_new(&x->x_obj, &s_float);
 
80
  x->x_outlet3 = outlet_new(&x->x_obj, &s_float);
 
81
  x->x_outlet4 = outlet_new(&x->x_obj, &s_float);
 
82
  x->x_outlet5 = outlet_new(&x->x_obj, &s_float);
 
83
  x->x_outlet6 = outlet_new(&x->x_obj, &s_float);
 
84
  
 
85
  return (x);
 
86
}
 
87
 
 
88
static void date_bang(t_date *x)
 
89
{
 
90
  struct tm *resolvetime;
 
91
#ifdef USE_TIMEB
 
92
  struct timeb mytime;
 
93
  ftime(&mytime);
 
94
  resolvetime=(x->GMT)?gmtime(&mytime.time):localtime(&mytime.time);
 
95
#else
 
96
  struct timeval tv;
 
97
  gettimeofday(&tv, 0);
 
98
  resolvetime = (x->GMT)?gmtime(&tv.tv_sec):localtime(&tv.tv_sec);
 
99
#endif
 
100
  outlet_float(x->x_outlet6, (t_float)resolvetime->tm_isdst);
 
101
  outlet_float(x->x_outlet5, (t_float)resolvetime->tm_yday);
 
102
  outlet_float(x->x_outlet4, (t_float)resolvetime->tm_wday);
 
103
  outlet_float(x->x_outlet3, (t_float)resolvetime->tm_mday);
 
104
  outlet_float(x->x_outlet2, (t_float)resolvetime->tm_mon + 1);
 
105
  outlet_float(x->x_outlet1, (t_float)resolvetime->tm_year + 1900);
 
106
}
 
107
 
 
108
static void help_date(t_date *x)
 
109
{
 
110
  ZEXY_USEVAR(x);
 
111
  post("\n%c date\t\t:: get the current system date", HEARTSYMBOL);
 
112
  post("\noutputs are\t: year / month / day / day of week /day of year / daylightsaving (1/0)");
 
113
  post("\ncreation\t::'date [GMT]': show local date or GMT");
 
114
}
 
115
 
 
116
void date_setup(void)
 
117
{
 
118
  date_class = class_new(gensym("date"),
 
119
                         (t_newmethod)date_new, 0,
 
120
                         sizeof(t_date), 0, A_GIMME, 0);
 
121
  
 
122
  class_addbang(date_class, date_bang);
 
123
  
 
124
  class_addmethod(date_class, (t_method)help_date, gensym("help"), 0);
 
125
  zexy_register("date");
 
126
}