~ubuntu-branches/ubuntu/raring/siggen/raring

« back to all changes in this revision

Viewing changes to .pc/missing-include.diff/misc.c

  • Committer: Package Import Robot
  • Author(s): Thorsten Alteholz
  • Date: 2012-03-13 18:51:09 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120313185109-0zkxvq2vpwbjbkf2
Tags: 2.3.10-5
* new maintainer (closes: #628941)
* debian/rules: remove explicit patch targets
* debian/rules: replace dh_clean -k by dh_prep
* debian/rules: build-arch and build-indep introduced
* debian/rules: standard moved to 3.9.3 (no changes)
* debian/watch: added, but not working with upstreams website
* debian/control: dependency on quilt removed
* debian/control: no public vcs available
* debian/control: moved to dh 9
* debian/patches: add header
* debian/source/format: 3.0 (quilt) introduced

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* misc.c
 
2
 * Miscellaneous Functions 
 
3
 * Jim Jackson     Dec 96
 
4
 */
 
5
 
 
6
/*
 
7
 * Copyright (C) 1997-2008 Jim Jackson                    jj@franjam.org.uk
 
8
 * 
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 * 
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 * 
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program - see the file COPYING; if not, write to 
 
21
 *  the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 
22
 *  MA 02139, USA.
 
23
 */
 
24
 
 
25
#include <stdio.h>
 
26
#include <sys/time.h>
 
27
#include <sys/types.h>
 
28
#include <unistd.h>
 
29
#include <limits.h>
 
30
#include "config.h"
 
31
/*
 
32
 * delay(us)  wait us microsecs using select. Effectively
 
33
 *            causes current process to stop and a reschedule take place
 
34
 *            as well as doing the delay.
 
35
 */
 
36
 
 
37
delay(us)
 
38
int us;
 
39
{
 
40
        struct timeval tv;
 
41
 
 
42
        tv.tv_sec = 0;
 
43
        tv.tv_usec = us;
 
44
        (void)select( 1, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv );
 
45
}
 
46
 
 
47
/***ERR_RPT***/
 
48
/* err_rpt(err,msg)
 
49
 */
 
50
 
 
51
err_rpt(err,msg)
 
52
short int err;
 
53
char *msg;
 
54
 
 
55
 { 
 
56
   extern char *sys;
 
57
 
 
58
   if (err) fprintf(stderr,"[%s] %s : %s\n",sys,strerror(err),msg);
 
59
   return(err);
 
60
 }
 
61
 
 
62
/***HCF***/
 
63
/* hcf(x,y)   find highest common factor of x and y
 
64
 */
 
65
 
 
66
hcf(x,y)
 
67
unsigned x,y;
 
68
 
 
69
{
 
70
   register unsigned a,b,r;
 
71
   
 
72
   if (x>y) {
 
73
      a=x; b=y; 
 
74
   } else {
 
75
      a=y; b=x; 
 
76
   }
 
77
   for ( ; r=a%b ; a=b, b=r) { }
 
78
   return(b);
 
79
}
 
80
 
 
81
/***PARSE***/
 
82
/* parse(s,aa,sep) splits s up into parameters and stores ptrs
 
83
 *                   to each prm in ptr array aa (upto MAX_ARGS)
 
84
 *                   params are space or tab or 'sep' seperated, and may be
 
85
 *                   enclosed in single or double quotes e.g. 'this is 1 prm'
 
86
 *
 
87
 *   returns number of parameters parsed
 
88
 */
 
89
 
 
90
parse(s,aa,sep)
 
91
char *s,**aa,sep;
 
92
 
 
93
 
94
  char *p,*q,c;
 
95
  int i;
 
96
 
 
97
#define EOL ((*s=='\0') || (*s=='\n'))
 
98
#define EOP ((*s==' ') || (*s=='\t') || (*s==sep))
 
99
#define QUOTE ((*s=='\'') || (*s=='"'))
 
100
#define MAX_ARGS 50
 
101
 
 
102
   for ( i=1; ; i++) { 
 
103
      for ( ; EOP; s++) {}    /* skip leading  separators */
 
104
      *aa++=p=s;
 
105
      if (EOL) return((--i)?i:1);
 
106
      if (i==MAX_ARGS) {
 
107
         return(--i);
 
108
      }
 
109
      while (!(EOL || EOP)) {
 
110
         if (QUOTE) {
 
111
            for (s++; !(EOL || QUOTE); ) *p++=*s++;
 
112
            if (QUOTE) s++;
 
113
         } else *p++=*s++;
 
114
      }
 
115
      if (EOL) {*p='\0'; return(i);}
 
116
      *p='\0';
 
117
      ++s;
 
118
   }
 
119
}
 
120
 
 
121
#undef EOL
 
122
#undef EOP
 
123
 
 
124
/***mstosmaples***/
 
125
/*
 
126
 * mstosamples(ms,sr)  convert ms millisecs into number of samples
 
127
 *                     given that the sample rate is sr samples/sec
 
128
 */
 
129
 
 
130
mstosamples(ms,sr)
 
131
int ms;
 
132
int sr;
 
133
 
 
134
{
 
135
  int d;
 
136
  int m;
 
137
 
 
138
  m=INT_MAX/(4*sr);  /* we need to make sure we don't overflow INT size
 
139
                        including when no. of samples may get upped for stereo
 
140
                        16 bit into a byte count for getting buffers etc
 
141
                     */
 
142
  for ( d=1000; d>0 && ms>m; d/=10 ) { ms/=10; }
 
143
  if (d)
 
144
    return((sr*ms+d/2)/d);
 
145
  else 
 
146
    return(0);
 
147
}
 
148