home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / util / manip / general.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  1.9 KB  |  102 lines

  1. #define pi 3.14159265
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. #ifndef unix
  9. #include <stdarg.h>
  10. #endif
  11. #ifdef __TURBOC__
  12. #include <alloc.h>
  13. #else
  14. #define farcalloc calloc
  15. #endif
  16. polar_xy(double r, double angle, double *dx, double *dy)
  17. {
  18.     *dx = r*cos(angle*3.14159265/180);
  19.     *dy = r*sin(angle*3.14159265/180);
  20. }
  21. xy_polar(double dx,double dy,double *radius,double *angle)
  22. {
  23.     if (dx==0 && dy==0) {
  24.         printf("Cannot work out angle of zero length vector\n");
  25.         return;
  26.     }
  27.     if (dx==0) {
  28.         *angle = 90;
  29.         if (dy<0) *angle = -90;
  30.     } else {
  31.         *angle = atan2(dy,dx)*180/pi;
  32.     }
  33.     *radius = sqrt(pow(dx,2)+pow(dy,2));
  34. }
  35. ncpy(char *d, char *s, int n)
  36. {
  37.     strncpy(d,s,n);
  38.     *(d+n) = 0;
  39. }
  40. ncat(char *d, char *s, int n)
  41. {
  42.     int i;
  43.     i = strlen(d);
  44.     strncat(d,s,n);
  45.     *(d+i+n) = 0;
  46. }
  47. #ifdef __TURBOC__
  48. #else
  49. char *strdup(char *s)
  50. {
  51.     char *v;
  52.     v = malloc(strlen(s)+1);
  53.     strcpy(v,s);
  54.     return v;
  55. }
  56. #endif
  57. char *sdup(char *s)
  58. {
  59.     char *v;
  60.     v = malloc(strlen(s)+1);
  61.     strcpy(v,s);
  62.     return v;
  63. }
  64. /*
  65. var_getstr(int varnum,char *s){}
  66. sub_clear(void){}
  67. int sub_def(char *s){}
  68. sub_call(int idx,double *pval,char **pstr,int *npm){}
  69. sub_find(char *s,int *idx,int *zret, int *np, int **plist){*idx = 0;}
  70. sub_get_startend(int idx, int *ss, int *ee){}
  71. sub_param(int idx,char *s){}
  72. sub_set_return(double d){}
  73. sub_set_startend(int idx, int ss, int ee){}
  74. var_add(char *name,int *idx,int *type){}
  75. var_find(char *name,int *idx,int *type){*idx = 0;}
  76. var_findadd(char *name,int *idx,int *type){}
  77. var_get(int jj, double *v){}
  78. var_nlocal(int *l){}
  79. var_set(int jj, double v){}
  80. var_setstr(int jj, char *s){}
  81. */
  82.  
  83. void *myallocz(long size)
  84. {
  85.     static void *p;
  86.     static long *l;
  87.     p = farcalloc(1,size);
  88.     return p;
  89. }
  90. mystrcpy(char **d,char *s)
  91. {
  92.     if (*d!=0) free(*d);
  93.     *d = 0;
  94.     *d = malloc(strlen(s)+1);
  95.     if (d==NULL) gle_abort("Memory gone\n");
  96.     strcpy(*d,s);
  97. }
  98. do_pcode()
  99. {}
  100. int gpcode;
  101. int gplen;
  102.