source: trunk/athena/bin/xcluster/read.c @ 12283

Revision 12283, 2.2 KB checked in by ghudson, 26 years ago (diff)
Move here from athena/bin/dash/src/xcluster and autoconfiscate.
Line 
1/*
2 *     Campus Cluster Monitering Program
3 *       John Welch and Chris Vanharen
4 *            MIT's Project Athena
5 *                Summer 1990
6 */
7
8#include "xcluster.h"           /* global include file. */
9#include "net.h"
10#include <ctype.h>
11
12/*
13 * GLOBAL VARIABLES
14 */
15struct cluster *cluster_list;   /* Pointer to list of clusters */
16static char *config[] = {"configplease3"};
17char machtypes[10][25];
18int num_machtypes;
19
20/*
21 *   read_clusters reads the cluster names and locations in from a file and
22 *   puts them into a linked list called cluster_list.
23 */
24void read_clusters()
25{
26  int num, trip=0, i;
27  struct cluster *new, *current = NULL;
28  FILE *f;
29  int s;
30  char buf[25];
31  char *ptr;
32
33  s = net(progname, 1, config);
34  if (s < 1)
35    {
36      fprintf(stderr,
37              "Error while contacting server, trying to get configuration information.\n");
38      exit(-1);
39    }
40
41/* read data from socket */
42
43  f = fdopen(s, "r");
44
45  fscanf(f, "%d", &num_machtypes);
46  for (i=1; i <= num_machtypes; i++)
47    {
48      fscanf(f, "%s", machtypes[i]);
49    }
50  strcpy(machtypes[i], "Totals");
51
52  cluster_list = (struct cluster *)malloc ((unsigned)sizeof(struct cluster));
53  while(fscanf(f, "%d", &num) != EOF)
54    {
55      if (trip == 1)
56        new = (struct cluster *) malloc ((unsigned) sizeof (struct cluster));
57      else
58        new = cluster_list;
59      if (new == NULL)
60        {
61          fprintf (stderr, "%s: Out of memory.\n", progname);
62          exit (-1);
63        }
64      new->cluster_number = num;
65
66      fgets(buf, 25, f);
67      ptr = buf;
68
69      while (isspace(*ptr))
70        ptr++;
71      ptr[strlen(ptr) - 1] = '\0';
72      strcpy(new->button_name, ptr);
73
74      for (i=0; TRUE; i++)
75        {
76          fscanf(f, "%s", new->cluster_names[i]);
77          if(!strcmp(new->cluster_names[i], "XXXXX"))
78            break;
79          fscanf(f, "%s", new->phone_num[i]);
80        }
81
82      fscanf(f, "%d%d", &new->x_coord, &new->y_coord);
83
84      for (i=0; TRUE; i++)
85        {
86          fscanf(f, "%s", new->prntr_name[i]);
87          strcpy(new->prntr_current_status[i], "?");
88          strcpy(new->prntr_num_jobs[i], "0");
89          if(!strcmp(new->prntr_name[i], "XXXXX"))
90            break;
91        }
92      new->next = NULL;
93      if (trip == 1)
94        current->next = new;
95      current = new;
96      trip = 1;
97    }
98  (void)fclose(f);
99}
Note: See TracBrowser for help on using the repository browser.