/**************************************************************************/ /* Module UTIL.C- Utility functions */ /**************************************************************************/ #include #include #include #define ESC 27 void gpromp(char *a); void gterm(void); void exit (char); /**************************************************************************/ /* UCMATRIX- allocates space for a character 2D array */ /**************************************************************************/ char *ucmatrix(int a, int b) { char *m; m=(char *)malloc((unsigned) a*b*sizeof(char)); if (!m) return (NULL); return (m); } /**************************************************************************/ /* USMATRIX- allocates space for a short 2D array */ /**************************************************************************/ short *usmatrix(int a, int b) { short *m; m=(short *)malloc((unsigned) a*b*sizeof(short)); if (!m) return ((short *) NULL); return (m); } /**************************************************************************/ /* ULMATRIX- allocates space for a long 2D array */ /**************************************************************************/ long *ulmatrix(int a, int b) { long *m; m=(long *)malloc((unsigned) a*b*sizeof(long)); if (!m) return ((long *) NULL); return (m); } /**************************************************************************/ /* UFMATRIX- allocates space for a float 2D array */ /**************************************************************************/ float *ufmatrix(int a, int b) { float *m; m=(float *)malloc((unsigned) a*b*sizeof(float)); if (!m) return ((float*)NULL); return (m); } /**************************************************************************/ /* UFREE- frees up memory */ /**************************************************************************/ void ufree(char *m) { free(m); return; } /**************************************************************************/ /* UPAUSE- waits for any key, the returns */ int upause() { while(!kbhit()); return (0); } /**************************************************************************/ /* UABORT- tests for operator abort */ /***************************************************************************/ int uabort() { if(kbhit()) { char c; c=getch(); gpromp("Any key to continue, ESC to abort operation"); c=getch(); gpromp(" "); if(c==ESC) return(1); else return(0); } else return (0); } /**************************************************************************/ /* UERROR- prints error message and aborts program */ void uerror(char *string) { gterm(); printf("%s\n",string); exit(1); } /*************************************************************************/