#include <stdio.h>
/* subroutine to format a UIC into [00g,00m] format */
/* checks for comma in UIC */
/*
	usage: format(uic) -- "uic" is a pointer to a string containing
	a primitive UFD spec, e.g. 23,10 or [1,2]. The string must be long
	enough to contain the expanded UFD spec, e.g. [023,010] and [001,002].
	If an error occurs in the input string, FORMAT returns string up to
	that point -- e.g. 1.2 will return [1.2]. (I don't claim this thing
	is efficient or even fully reasonable in error-handling, but it works
	if its input is good.)
*/

char *format(uic)
  /* convert g,mm or [g,mm] format to [  g, mm] format */
  char *uic;
{
  char buf[10];
  int j, k;
  char gr[4], mem[4];

  j=0;
  buf[0] = '[';
  if (*(uic+j) == '[')
	j++;
  for (k=0; (*(uic+j) != ',') && (k < 3); k++)
    gr[k] = *(uic+j++);
  gr[k] = NULL;
  if (*(uic+j++) != ',') 
    {
    printf("error in ggg,mmm format\n");
    uic[j] = NULL;
    }
  for(k = 0; ((*(uic+j) != ']') && (j < strlen(uic)) && (k < 3)); k++)
    mem[k] = *(uic+j++);
  mem[k] = NULL;
  j = 1;
  for (k=0; ((strlen(gr))+k) < 3; k++)
    buf[j++] = '0';
  cpystr(&buf[j], gr);
  j = j + strlen(gr);
  buf[j++] = ',';
  for (k=0; strlen(mem)+k < 3; k++)
    buf[j++] = '0';
  cpystr(&buf[j], mem);
  j = j + strlen(mem);
  buf[j++] = ']';
  buf[j] = NULL;
  cpystr (uic, buf);
  }


