home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / unixtools / util / dev / c / x < prev   
Encoding:
Text File  |  1992-07-21  |  2.2 KB  |  124 lines

  1. /*      > C.X - X data type */
  2.  
  3. #include <stddef.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "X.h"
  7.  
  8. #ifdef test
  9. #include <stdio.h>
  10. #endif
  11.  
  12. struct link
  13. {
  14. };
  15.  
  16. typedef struct link *link;
  17.  
  18. /* Return values from functions */
  19.  
  20. #define OK      1
  21. #define ERR     0
  22.  
  23. /* General component routines */
  24.  
  25. X x_new (int obj_len)
  26. {
  27. }
  28.  
  29. void x_free (X x)
  30. {
  31. }
  32.  
  33. void x_clear (X x)
  34. {
  35. }
  36.  
  37. int x_copy (X x1, X x2)
  38. {
  39. }
  40.  
  41. int x_equal (X x1, X x2)
  42. {
  43. }
  44.  
  45. int x_empty (X x)
  46. {
  47. }
  48.  
  49. int x_size (X x)
  50. {
  51. }
  52.  
  53. int x_iterate (X x, int (*process)(void *))
  54. {
  55. }
  56.  
  57. /* X-specific routines */
  58.  
  59. /*---------------------------------------------------------------------------*/
  60.  
  61. #ifdef test
  62. int print (void *ptr)
  63. {
  64.         printf("%d ",*(int *)ptr);
  65.         return STATUS_CONTINUE;
  66. }
  67.  
  68. void x_dump (X x)
  69. {
  70.         printf("X: ");
  71.         x_iterate(x,print);
  72.         putchar('\n');
  73. }
  74. #endif
  75.  
  76. /*---------------------------------------------------------------------------*/
  77.  
  78. #ifdef test
  79.  
  80. #define BUFLEN 255
  81.  
  82. int main (void)
  83. {
  84.         char buf[BUFLEN];
  85.         int i, j, num;
  86.         X x[10];
  87.  
  88.         for ( i = 0; i < 10; ++i )
  89.                 x[i] = x_new(sizeof(int));
  90.  
  91.         for ( ; ; )
  92.         {
  93.                 printf(">");
  94.                 fgets(buf,BUFLEN,stdin);
  95.  
  96.                 if ( buf[0] == '\n' || buf[0] == '\0' )
  97.                         continue;
  98.                 else if ( sscanf(buf,"clear %1d",&i) == 1 )
  99.                         x_clear(x[i]);
  100.                 else if ( sscanf(buf,"copy %1d %1d",&i,&j) == 2 )
  101.                         x_copy(x[i],x[j]);
  102.                 else if ( sscanf(buf,"equal %1d %1d",&i,&j) == 2 )
  103.                         printf("%s\n",(x_equal(x[i],x[j]) ? "yes" : "no"));
  104.                 else if ( sscanf(buf,"empty %1d",&i) == 1 )
  105.                         printf("%s\n",(x_empty(x[i]) ? "yes" : "no"));
  106.                 else if ( sscanf(buf,"size %1d",&i) == 1 )
  107.                         printf("%d\n",x_size(x[i]));
  108.                 else if ( sscanf(buf,"dump %1d",&i) == 1 )
  109.                         x_dump(x[i]);
  110.                 else if ( strncmp(buf,"quit",4) == 0 )
  111.                         break;
  112.                 else
  113.                         printf("Mistake\n");
  114.         }
  115.  
  116.         printf("Deleting x[0-9]\n");
  117.         for ( i = 0; i < 10; ++i )
  118.                 x_free(x[i]);
  119.  
  120.         return 0;
  121. }
  122.  
  123. #endif
  124.