home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2576 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.6 KB  |  124 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!news
  3. From: scs@adam.mit.edu (Steve Summit)
  4. Subject: two patches re: med -- expression evaluator and stream-based math processor
  5. Message-ID: <1992Nov20.160754.9553@athena.mit.edu>
  6. Followup-To: alt.sources.d
  7. Sender: news@athena.mit.edu (News system)
  8. Nntp-Posting-Host: adam.mit.edu
  9. Organization: none, at the moment
  10. References: <1992Nov16.160145.7707@athena.mit.edu>
  11. Date: Fri, 20 Nov 1992 16:07:54 GMT
  12. Lines: 110
  13.  
  14. The malloc/realloc front-end included with the recently-posted
  15. med package assumed an ANSI-compatible realloc (able to handle
  16. null first arguments).  The main-line code initialized a global
  17. FILE * with stdin, which fails under VMS and is not strictly
  18. ANSI-compatible.  Thanks to Jeff sondeen@ISI.EDU and Jerry
  19. Leichter for pointing these out.
  20.  
  21. A patch to med.c, and a new copy of alloc.c, are enclosed.
  22.  
  23.                     Steve Summit
  24.                     scs@adam.mit.edu
  25.                    
  26. ----8<-------8<----cut here for patch to med.c---8<-------8<-----
  27. *** med.old.c    Mon Jan 14 19:22:52 1991
  28. --- med.c    Wed Nov 18 19:22:42 1992
  29. ***************
  30. *** 40,46 ****
  31.   enum {ZERO, PREV, GARBAGE} missingaction = GARBAGE;
  32.                   /* what to do when requested column missing */
  33.   
  34. ! FILE *ofd = stdout;
  35.   
  36.   double consts[10];
  37.   int nconsts = 0;
  38. --- 40,46 ----
  39.   enum {ZERO, PREV, GARBAGE} missingaction = GARBAGE;
  40.                   /* what to do when requested column missing */
  41.   
  42. ! FILE *ofd;
  43.   
  44.   double consts[10];
  45.   int nconsts = 0;
  46. ***************
  47. *** 91,96 ****
  48. --- 91,98 ----
  49.   /* val filled in for each line */
  50.   
  51.   basenvars = nvars;
  52. + ofd = stdout;
  53.   
  54.   /*
  55.    *  Standard option file parse is rife with ambiguity:
  56. ----8<-------8<-cut here for replacement alloc.c-8<-------8<-----
  57. #include <stdio.h>
  58. #ifdef __STDC__
  59. #include <stdlib.h>
  60. #endif
  61. #include "alloc.h"
  62.  
  63. #ifdef __STDC__
  64. #define SIZE_T size_t
  65. #define SAFEREALLOC
  66. #else
  67. #define SIZE_T unsigned
  68. #endif
  69.  
  70. static char nomem[] = "out of memory";
  71.  
  72. extern char *progname;
  73.  
  74. #ifndef __STDC__
  75. extern char *malloc();
  76. extern char *realloc();
  77. #endif
  78.  
  79. char *
  80. alloc(size)
  81. int size;
  82. {
  83. char *ret;
  84.  
  85. ret = malloc((SIZE_T)size);
  86.  
  87. if(ret == NULL)
  88.     {
  89.     if(progname != NULL)
  90.         fprintf(stderr, "%s: ", progname);
  91.     fprintf(stderr, "%s\n", nomem);
  92.     exit(1);
  93.     }
  94.  
  95. return(ret);
  96. }
  97.  
  98. char *
  99. crealloc(oldptr, newsize)
  100. char *oldptr;
  101. int newsize;
  102. {
  103. char *newptr;
  104.  
  105. #ifndef SAFEREALLOC
  106. if(oldptr == NULL)
  107.     newptr = malloc((SIZE_T)newsize);
  108. else
  109. #endif
  110.     newptr = realloc(oldptr, (SIZE_T)newsize);
  111.  
  112. if(newptr == NULL)
  113.     {
  114.     if(progname != NULL)
  115.         fprintf(stderr, "%s: ", progname);
  116.     fprintf(stderr, "%s\n", nomem);
  117.     exit(1);
  118.     }
  119.  
  120. return(newptr);
  121. }
  122. ----8<-------8<-------8<-------8<-------8<-------8<-------8<-----
  123.