home *** CD-ROM | disk | FTP | other *** search
- /* > C.X - X data type */
-
- #include <stddef.h>
- #include <stdlib.h>
- #include <string.h>
- #include "X.h"
-
- #ifdef test
- #include <stdio.h>
- #endif
-
- struct link
- {
- };
-
- typedef struct link *link;
-
- /* Return values from functions */
-
- #define OK 1
- #define ERR 0
-
- /* General component routines */
-
- X x_new (int obj_len)
- {
- }
-
- void x_free (X x)
- {
- }
-
- void x_clear (X x)
- {
- }
-
- int x_copy (X x1, X x2)
- {
- }
-
- int x_equal (X x1, X x2)
- {
- }
-
- int x_empty (X x)
- {
- }
-
- int x_size (X x)
- {
- }
-
- int x_iterate (X x, int (*process)(void *))
- {
- }
-
- /* X-specific routines */
-
- /*---------------------------------------------------------------------------*/
-
- #ifdef test
- int print (void *ptr)
- {
- printf("%d ",*(int *)ptr);
- return STATUS_CONTINUE;
- }
-
- void x_dump (X x)
- {
- printf("X: ");
- x_iterate(x,print);
- putchar('\n');
- }
- #endif
-
- /*---------------------------------------------------------------------------*/
-
- #ifdef test
-
- #define BUFLEN 255
-
- int main (void)
- {
- char buf[BUFLEN];
- int i, j, num;
- X x[10];
-
- for ( i = 0; i < 10; ++i )
- x[i] = x_new(sizeof(int));
-
- for ( ; ; )
- {
- printf(">");
- fgets(buf,BUFLEN,stdin);
-
- if ( buf[0] == '\n' || buf[0] == '\0' )
- continue;
- else if ( sscanf(buf,"clear %1d",&i) == 1 )
- x_clear(x[i]);
- else if ( sscanf(buf,"copy %1d %1d",&i,&j) == 2 )
- x_copy(x[i],x[j]);
- else if ( sscanf(buf,"equal %1d %1d",&i,&j) == 2 )
- printf("%s\n",(x_equal(x[i],x[j]) ? "yes" : "no"));
- else if ( sscanf(buf,"empty %1d",&i) == 1 )
- printf("%s\n",(x_empty(x[i]) ? "yes" : "no"));
- else if ( sscanf(buf,"size %1d",&i) == 1 )
- printf("%d\n",x_size(x[i]));
- else if ( sscanf(buf,"dump %1d",&i) == 1 )
- x_dump(x[i]);
- else if ( strncmp(buf,"quit",4) == 0 )
- break;
- else
- printf("Mistake\n");
- }
-
- printf("Deleting x[0-9]\n");
- for ( i = 0; i < 10; ++i )
- x_free(x[i]);
-
- return 0;
- }
-
- #endif
-