util.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. #include "bem.h"
  6. #ifndef NORSCID
  7. static char rcs_id[] = "$Header$" ;
  8. #endif
  9. #define abs(X) (X>=0?X:-X)
  10. /* Miscelaneous routines can be found here */
  11. int errorcnt;
  12. warning(str)
  13. char *str;
  14. {
  15. if (wflag) return;
  16. Xerror("WARNING", str);
  17. }
  18. error(str)
  19. char *str;
  20. {
  21. Xerror("ERROR", str);
  22. errorcnt++;
  23. }
  24. Xerror(type, str)
  25. char *str;
  26. char *type;
  27. {
  28. extern int listing;
  29. extern int basicline;
  30. if( !listing) fprint(STDERR, "LINE %d:",basicline);
  31. fprint(STDERR, "%s:%s\n",type, str);
  32. }
  33. fatal(str)
  34. char *str;
  35. {
  36. Xerror("FATAL",str);
  37. C_close();
  38. sys_stop(S_EXIT);
  39. }
  40. notyetimpl()
  41. {
  42. warning("not yet implemented");
  43. }
  44. illegalcmd()
  45. {
  46. warning("illegal command");
  47. }
  48. char *itoa(i)
  49. int i;
  50. {
  51. static char buf[30];
  52. (void) sprint(buf,"%d",i);
  53. return(buf);
  54. }
  55. char *salloc(length)
  56. unsigned length;
  57. {
  58. char *s,*c;
  59. extern char *malloc() ;
  60. s=c=malloc(length);
  61. if ( !s ) fatal("Out of memory") ;
  62. while(length--)*c++ =0;
  63. return(s);
  64. }