bc_domtest.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "machdefs.h"
00003 #include "util.h"
00004 #include "tsp.h"
00005 
00006 static int receive_dominos (CC_SFILE * s),
00007   parseargs (int ac,
00008              char **av);
00009 
00010 static void usage (char *f);
00011 
00012 static int graphid = 1;
00013 static int sendgraph = 0;
00014 static int stopboss = 0;
00015 static int getdominos = 0;
00016 static char *hostname = (char *) NULL;
00017 
00018 int main (int ac,
00019           char **av)
00020 {
00021   CC_SFILE *s = (CC_SFILE *) NULL;
00022   int rval = 0;
00023 
00024   rval = parseargs (ac, av);
00025   if (rval)
00026     return 0;
00027 
00028   CCutil_printlabel ();
00029 
00030   s = CCutil_snet_open (hostname, CCtsp_DOMINO_PORT);
00031   if (!s)
00032   {
00033     fprintf (stderr, "CCutil_snet_open failed\n");
00034     rval = 1;
00035     goto CLEANUP;
00036   }
00037 
00038   if (stopboss)
00039   {
00040     printf ("stop the boss\n");
00041     fflush (stdout);
00042     rval = CCutil_swrite_char (s, CCtsp_DOMINO_EXIT);
00043     CCcheck_rval (rval, "CCutil_swrite_char failed (EXIT)");
00044   }
00045   else if (sendgraph)
00046   {
00047     printf ("Send graph id = %d\n", graphid);
00048     fflush (stdout);
00049     rval = CCutil_swrite_char (s, CCtsp_DOMINO_GRAPH);
00050     CCcheck_rval (rval, "CCutil_swrite_char failed (GRAPH)");
00051     rval = CCutil_swrite_int (s, graphid);
00052     CCcheck_rval (rval, "CCutil_swrite_int failed");
00053     rval = CCutil_swrite_int (s, 2 * graphid);
00054     CCcheck_rval (rval, "CCutil_swrite_int failed");
00055     rval = CCutil_swrite_int (s, 3 * graphid);
00056     CCcheck_rval (rval, "CCutil_swrite_int failed");
00057   }
00058   else if (getdominos)
00059   {
00060     printf ("get the domino list\n");
00061     fflush (stdout);
00062     rval = CCutil_swrite_char (s, CCtsp_DOMINO_SEND);
00063     CCcheck_rval (rval, "CCutil_swrite_char failed (SEND)");
00064     rval = receive_dominos (s);
00065     CCcheck_rval (rval, "receive_dominos failed");
00066   }
00067   else
00068   {
00069     printf ("Nothing to do.\n");
00070     fflush (stdout);
00071   }
00072 
00073 CLEANUP:
00074 
00075   if (s)
00076     CCutil_sclose (s);
00077   return rval;
00078 }
00079 
00080 static int parseargs (int ac,
00081                       char **av)
00082 {
00083   int c;
00084   int boptind = 1;
00085   char *boptarg = (char *) NULL;
00086 
00087   while ((c = CCutil_bix_getopt (ac, av, "xg:d", &boptind, &boptarg)) != EOF)
00088   {
00089     switch (c)
00090     {
00091     case 'x':
00092       stopboss = 1;
00093       break;
00094     case 'g':
00095       sendgraph = 1;
00096       graphid = atoi (boptarg);
00097       break;
00098     case 'd':
00099       getdominos = 1;
00100       break;
00101     default:
00102       usage (av[0]);
00103       return 1;
00104     }
00105   }
00106 
00107   if (boptind >= ac)
00108   {
00109     usage (av[0]);
00110     return 1;
00111   }
00112   hostname = av[boptind++];
00113   if (boptind != ac)
00114   {
00115     usage (av[0]);
00116     return 1;
00117   }
00118 
00119   return 0;
00120 }
00121 
00122 static int receive_dominos (CC_SFILE * s)
00123 {
00124   int rval = 0;
00125   int i,
00126     count;
00127   int *list = (int *) NULL;
00128 
00129   rval = CCutil_sread_int (s, &count);
00130   CCcheck_rval (rval, "CCutil_sread_int failed (count)");
00131 
00132   list = CC_SAFE_MALLOC (count, int);
00133   CCcheck_NULL (list, "out memory for list");
00134 
00135   for (i = 0; i < count; i++)
00136   {
00137     rval = CCutil_sread_int (s, &list[i]);
00138     CCcheck_rval (rval, "CCutil_sread_int failed (list)");
00139   }
00140 
00141   printf ("Dom List: %d\n", count);
00142   for (i = 0; i < count; i++)
00143   {
00144     printf ("%d ", list[i]);
00145   }
00146   printf ("\n");
00147   fflush (stdout);
00148 
00149 CLEANUP:
00150 
00151   CC_IFFREE (list, int);
00152   return rval;
00153 }
00154 
00155 static void usage (char *f)
00156 {
00157   fprintf (stderr, "Usage: %s [-see below-] hostname\n", f);
00158   fprintf (stderr, "   -d   tells the boss to send dominos\n");
00159   fprintf (stderr, "   -g # sends graph is id #\n");
00160   fprintf (stderr, "   -x   tells the boss to exit\n");
00161 }

Generated on Thu Oct 20 14:58:40 2005 for DominoParitySeparator by  doxygen 1.4.5