123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /* NUMf2c.c */
- #include <ctype.h>
- #include "NUMf2c.h"
- //#include "melder.h"
- double d_sign (double *a, double *b) {
- double x;
- x = (*a >= 0.0 ? *a : - *a);
- return (*b >= 0.0 ? x : -x);
- }
- integer lsame_ (const char *ca, const char *cb) {
- int a = * (unsigned char *) ca;
- int b = * (unsigned char *) cb;
- return tolower (a) == tolower (b);
- }
- double pow_di (double *ap, integer *bp) {
- double pow, x;
- integer n;
- uinteger u;
- pow = 1;
- x = *ap;
- n = *bp;
- if (n != 0) {
- if (n < 0) {
- n = -n;
- x = 1.0 / x;
- }
- for (u = n; ;) {
- if (u & 01) {
- pow *= x;
- }
- if (u >>= 1) {
- x *= x;
- } else {
- break;
- }
- }
- }
- return (pow);
- }
- void s_cat (char *lp, const char *rpp[], integer rnp[], integer *np, integer ll) {
- integer i, nc;
- char *rp;
- integer n = *np;
- #ifndef NO_OVERWRITE
- integer L, m;
- char *lp0, *lp1;
- lp0 = 0;
- lp1 = lp;
- L = ll;
- i = 0;
- while (i < n) {
- rp = (char *) rpp[i];
- m = rnp[i++];
- if (rp >= lp1 || rp + m <= lp) {
- if ( (L -= m) <= 0) {
- n = i;
- break;
- }
- lp1 += m;
- continue;
- }
- lp0 = lp;
- lp = lp1 = Melder_malloc_f (char, L = ll);
- break;
- }
- lp1 = lp;
- #endif /* NO_OVERWRITE */
- for (i = 0 ; i < n ; ++i) {
- nc = ll;
- if (rnp[i] < nc) {
- nc = rnp[i];
- }
- ll -= nc;
- rp = (char *) rpp[i];
- while (--nc >= 0) {
- *lp++ = *rp++;
- }
- }
- while (--ll >= 0) {
- *lp++ = ' ';
- }
- #ifndef NO_OVERWRITE
- if (lp0) {
- memcpy (lp0, lp1, L);
- free (lp1);
- }
- #endif
- }
- /* compare two strings */
- integer s_cmp (const char *a0, const char *b0, integer la, integer lb) {
- unsigned char *a, *aend, *b, *bend;
- a = (unsigned char *) a0;
- b = (unsigned char *) b0;
- aend = a + la;
- bend = b + lb;
- if (la <= lb) {
- while (a < aend)
- if (*a != *b) {
- return (*a - *b);
- } else {
- ++a;
- ++b;
- }
- while (b < bend)
- if (*b != ' ') {
- return (' ' - *b);
- } else {
- ++b;
- }
- }
- else {
- while (b < bend)
- if (*a == *b) {
- ++a;
- ++b;
- } else {
- return (*a - *b);
- }
- while (a < aend)
- if (*a != ' ') {
- return (*a - ' ');
- } else {
- ++a;
- }
- }
- return (0);
- }
- void s_copy (char *a, char *b, integer la, integer lb) {
- char *aend, *bend;
- aend = a + la;
- if (la <= lb)
- #ifndef NO_OVERWRITE
- if (a <= b || a >= b + la)
- #endif
- while (a < aend) {
- *a++ = *b++;
- }
- #ifndef NO_OVERWRITE
- else
- for (b += la; a < aend;) {
- *--aend = *--b;
- }
- #endif
- else {
- bend = b + lb;
- #ifndef NO_OVERWRITE
- if (a <= b || a >= bend)
- #endif
- while (b < bend) {
- *a++ = *b++;
- }
- #ifndef NO_OVERWRITE
- else {
- a += lb;
- while (b < bend) {
- *--a = *--bend;
- }
- a += lb;
- }
- #endif
- while (a < aend) {
- *a++ = ' ';
- }
- }
- }
- /* End of file NUMf2c.c */
|