Ejemplo n.º 1
0
/* Adrian Hernandez */
void displayPokerHand(Hand hand){
    
    char *handName = hand.handName;
    char *handRank = handRankName(hand.rank);
    
    int handNameLength = strlen(handName);
    int handRankLength = strlen(handRank);
    
    printf("\n");
    printSpaces(DEFAULT_ALIGN + MAX_CARD_NAME - handNameLength);
    printf("%s\n", handName);
    
    printSpaces(DEFAULT_ALIGN + MAX_CARD_NAME - handRankLength);
    printf("%s\n\n", handRank);
    
    int i;
    for (i = 0; i < POKER_HAND ; i++) {
        
        /* alignment */
        printSpaces(DEFAULT_ALIGN);
        
        displayCard(*(hand.cards[i]));
        printf("\n");
    }
    printf("\n");
}
Ejemplo n.º 2
0
void printNumber(parseTree curNode, FILE* fp)
{
    fprintf(fp, "-----------------        %d",curNode->tk->currentLine);
    printSpaces(14 - (curNode->tk->currentLine / 10 + 1),fp);
    fprintf(fp,"%s",grammarSymbols[curNode->tk->sym]);
    printSpaces(13 - strlen(grammarSymbols[curNode->tk->sym]),fp);
    fprintf(fp,"%s",curNode->tk->stringValue);
    printSpaces(21 - strlen(curNode->tk->stringValue),fp);
    fprintf(fp,"<%s>",grammarSymbols[curNode->parent->tk->sym]);
    printSpaces(22 - strlen(grammarSymbols[curNode->parent->tk->sym]),fp);
    fprintf(fp, "yes               ----------\n");
}
Ejemplo n.º 3
0
/* procedure printTree prints a syntax tree to the
 * listing file using indentation to indicate subtrees
 */
void printTree( TreeNode *tree )
{
    int i;
    INDENT;
    while (tree != NULL)
    {
        printSpaces();
        if (tree->nodekind == StmtK)
        {
            switch (tree->kind.stmt)
            {
                case IfK:
                    fprintf(listing, "If\n");
                    break;
                case RepeatK:
                    fprintf(listing, "Repeat\n");
                    break;
                case AssignK:
                    fprintf(listing, "Assign to: %s\n", tree->attr.name);
                    break;
                case ReadK:
                    fprintf(listing, "Read: %s\n", tree->attr.name);
                    break;
                case WriteK:
                    fprintf(listing, "Write\n");
                    break;
                default:
                    fprintf(listing, "Unknown ExpNode kind\n");
                    break;
            }
        }
        else if (tree->nodekind==ExpK)
        {
            switch (tree->kind.exp)
            {
                case OpK:
                    fprintf(listing, "Op: ");
                    printToken(tree->attr.op, "\0");
                    break;
                case ConstK:
                    fprintf(listing, "Const: %d\n",tree->attr.val);
                    break;
                case IdK:
                    fprintf(listing, "Id: %s\n",tree->attr.name);
                    break;
                default:
                    fprintf(listing, "Unknown ExpNode kind\n");
                    break;
            }
        }
        else
            fprintf(listing, "Unknown node kind\n");
        for (i=0; i<MAXCHILDREN; i++)
            printTree(tree->child[i]);
        tree = tree->sibling;
    }
    UNINDENT;
}
Ejemplo n.º 4
0
void FragmentList_print(FILE *outputHandle, uint indent, FragmentNode *fragmentNode)
{
  FragmentEntryNode *fragmentEntryNode;

  for (fragmentEntryNode = fragmentNode->fragmentEntryList.head; fragmentEntryNode != NULL; fragmentEntryNode = fragmentEntryNode->next)
  {
    printSpaces(outputHandle,indent); fprintf(outputHandle,"%8llu..%8llu\n",F0(fragmentEntryNode),F1(fragmentEntryNode));
  }
}
Ejemplo n.º 5
0
/* display hands. */
void displayHands(Hand hands[], Hand sortedHands[], int handSize, int nhands){

    
    int i, j;     /* loop variables */

    for (i = 0; i < nhands; i++) {
        
        Hand sorted = sortedHands[i];
        char *unsortedHandName = hands[i].handName;
        char *sortedHandName   = sorted.handName;
        
        /* align and print hands names */
        int handNameLen      = strlen(unsortedHandName);
        int sortedHandNamLen = strlen(sortedHandName);
        
        /* alignment */
        printSpaces(MAX_CARD_NAME + DEFAULT_ALIGN - handNameLen);
        printf("%s", unsortedHandName);
        
        /* alignment */
        printSpaces(MAX_CARD_NAME + DEFAULT_ALIGN - (sortedHandNamLen + 7));
        printf("%s sorted\n\n", sortedHandName);
        
        for (j = 0; j < handSize; j++) {
            
            /* alignment */
            printSpaces(DEFAULT_ALIGN);
            
            /* print original */
            displayCard(*(hands[i].cards[j]));
            
            /* alignment */
            printSpaces(DEFAULT_ALIGN);
            
            /* print sorted */
            displayCard(*(sorted.cards[j]));
            
            printf("\n");
            
        }
        printf("\n\n");
    }
}
Ejemplo n.º 6
0
static void Arg_print ()
{
  int left, i;

  for (i = 0; allArgs[i].action; ++i){
    left = INDENT_SIZE + 1+ strlen (allArgs[i].name)
      + 1 + strlen (allArgs[i].arg)+1;
    printSpaces (INDENT_SIZE);
    printf ("-%s", allArgs[i].name);
    printf (" ");
    printf ("%s", allArgs[i].arg);
    if (left>LEFT_SIZE) {
      printf ("\n");
      printSpaces (LEFT_SIZE);
    }
    else printSpaces (LEFT_SIZE-left);
    printf (" %s\n", allArgs[i].desc);
  }
  return;
}
Ejemplo n.º 7
0
void ModifiedTree::internalPrettyPrint(const Node *x, int depth)
{
    if (x == NULL)
        return;

    if (x != NULL)
    {
        internalPrettyPrint(x->getRight(), depth+1);
        printSpaces(depth);
        printf("%d\n", x->getKey());
        internalPrettyPrint(x->getLeft(), depth+1);
    }
}
Ejemplo n.º 8
0
void printNonTerminal(parseTree curNode, FILE *fp)
{
    if(curNode->parent == NULL)
    {
        fprintf(fp, "-----------------        ------        -----        -------------        ROOT                    no                <%s>\n",grammarSymbols[curNode->tk->sym]);
        return;
    }
    fprintf(fp, "-----------------        ------        -----        -------------        <%s>",grammarSymbols[curNode->parent->tk->sym]);
    printSpaces(22-strlen(grammarSymbols[curNode->parent->tk->sym]),fp);
    fprintf(fp,"no                ");
    fprintf(fp,"<%s>\n",grammarSymbols[curNode->tk->sym]);

}
Ejemplo n.º 9
0
/* Displays a pascal triangle in a visual format */
void displayPascal(int size)
{
	// Create a visual triangle starting in the middle
	for (int col = 0, leftSpaces = size; col <= size; col++, leftSpaces -= 1)
	{
		printSpaces(leftSpaces);
		for (int row = 0; row <= col; row++)
		{
			printf("%i ", pascal[col][row]);
		}
		printf("\n");
	}
}
Ejemplo n.º 10
0
/******************** printGraph **************************************
   void printGraph(int iRun, char *pszSubject, Graph graph)
Purpose:
    Prints a graph which is represensted by a double adjacency list.
    When printing the information about a vertex, it prints the PERT
    TE and TL.  For each vertex, it prints:
        vertex label
        TE
        TL
        predecessors
        successors
Parameters:
    I   int iRun                Identifies which graph is being displayed. 
    I   char *pszSubject        A message to display about this graph.
    I   Graph graph             A directed graph represented by a double
                                adjacency list.  
Notes:
    - Since predecessors and successors are printed on the same line,
      it uses the function printSpaces to help have all the lists of
      predecessors appear in the same column.
Returns:
    n/a
**************************************************************************/
void printGraph(int iRun, char *pszSubject, Graph graph)
{
    int iv;
    EdgeNode *e;
    int iCnt;
    // Print headings
    printf("Graph #%2d: %s\n", iRun, pszSubject);
    printf("%3s %2s %2s\t%-24s    %-24s\n"
        , "Vtx", "TE", "TL", "SUCCESSORS", "PREDECESSORS");
    // for each vertex in the graph
    for (iv = 0; iv < graph->iNumVertices; iv++)
    {
        // print the vertex label, TE, and TL
        printf("%c   %2d %2d\t", graph->vertexM[iv].cLabel
            , graph->vertexM[iv].iMaxFromSource
            , graph->vertexM[iv].iTL);
        iCnt = 0;
        // print each of its successors
        for (e = graph->vertexM[iv].successorList; e != NULL; e = e->pNextEdge)
        {
            iCnt++;
            printf("%c %2d  "
                , graph->vertexM[e->edge.iVertex].cLabel
                , e->edge.iPath);
        }
        // if it didn't have successors, print a "-"
        if (iCnt == 0)
        {
            printf("-     ");
            iCnt = 1;
        }
        // determine the variable-spaced amount for including spaces to get the 
        // predecessor list to print in a specific column
        printSpaces("      ", 4 - iCnt);
        printf("    ");
        iCnt = 0;
        // Print each of its predecessors
        for (e = graph->vertexM[iv].predecessorList; e != NULL; e = e->pNextEdge)
        {
            printf("%c %2d "
                , graph->vertexM[e->edge.iVertex].cLabel
                , e->edge.iPath);
            iCnt++;
        }
        // if it didn't have predecessors, print a "-"
        if (iCnt == 0)
            printf("-");
        printf("\n");
    }
}
Ejemplo n.º 11
0
/* Display a single card. */
void displayCard(Card card){
    
    int i;
    int nameLength;
    char *suit = suitName(card.suit);
    char *rank = rankName(card.rank);
    
    nameLength = strlen(suit) + strlen(rank) + 4;
    
    /* print spaces to right align */
    printSpaces(MAX_CARD_NAME - nameLength);
    
    /* print card */
    printf("%s OF %s", rank, suit);
}
Ejemplo n.º 12
0
/* Displays a deck of cards. */
void displayDeck(Card deck[], int size){
    
    int i;
    for (i = 0; i < size; i++) {
        
        /* alignment */
        printSpaces(DEFAULT_ALIGN);
        displayCard(deck[i]);
        
        if((i % DECK_COLUMNS) == (DECK_COLUMNS - 1)){
            /* start new row */
            printf("\n");
        }
    }
}
Ejemplo n.º 13
0
void
printDataDirectory(char* doRef, IedConnection con, int spaces) {
	IedClientError error;

	LinkedList dataAttributes = IedConnection_getDataDirectory(con, &error, doRef);

	if (dataAttributes != NULL) {
		LinkedList dataAttribute = LinkedList_getNext(dataAttributes);

		while (dataAttribute != NULL) {
			char* daName = (char*) dataAttribute->data;

			printSpaces(spaces);
			printf("DA: %s\n", (char*) dataAttribute->data);

			dataAttribute = LinkedList_getNext(dataAttribute);

			char* daRef = (char*) alloca(129);
			sprintf(daRef, "%s.%s", doRef, daName);
			printDataDirectory(daRef, con, spaces + 2);
		}

	}
}
Ejemplo n.º 14
0
/* procedure printTree prints a syntax tree to the 
 * listing file using indentation to indicate subtrees
 */
void printTree( TreeNode * tree )
{ int i;
  INDENT;
  while (tree != NULL) {
    printSpaces();
    if (tree->nodekind==StmtK)
    { switch (tree->kind.stmt) {
        case IfK:
          fprintf(listing,"If(condition, body, (optional)else)\n");
          break;
        case AssignK:
          fprintf(listing,"Assign (dest)(source):\n");
          break;
        case VarDecK:
          fprintf(listing,"Var Dec(following const:array length(optional)): %s\n",tree->attr.name);
          break;
        case ArrayDecK:
          fprintf(listing,"Array Dec(following const:array length(optional)): %s\n",tree->attr.name);
          break;
        case FuncDecK:
          if (tree->type == Integer)
            fprintf(listing,"int Function Dec: %s\n",tree->attr.name);
          else if (tree->type == Void)
            fprintf(listing,"void Function Dec: %s\n",tree->attr.name);
          break;
        case ParamK:
          if (tree->type == Void)
            fprintf(listing,"Para: Void\n");
           else
            fprintf(listing,"Para: %s\n",tree->attr.name);
          break;
        case ComK:
          fprintf(listing,"Compound Stmt\n");
          break;
        case WhileK:
          fprintf(listing,"While\n");
          break;
        case ReturnK:
          fprintf(listing,"Return\n");
          break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==ExpK)
    { switch (tree->kind.exp) {
        case OpK:
          fprintf(listing,"Op: ");
          printToken(tree->attr.op,"\0");
          break;
        case ConstK:
          fprintf(listing,"Const: %d\n",tree->attr.val);
          break;
        case IdK:
          fprintf(listing,"Id: %s\n",tree->attr.name);
          break;
	case CallK:
	  fprintf(listing,"Call(followings are args): %s\n", tree->attr.name);
	  break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else fprintf(listing,"Unknown node kind\n");
    for (i=0;i<MAXCHILDREN;i++)
         printTree(tree->child[i]);
    tree = tree->sibling;
  }
  UNINDENT;
}
Ejemplo n.º 15
0
void CmdOption_printHelp(FILE                    *outputHandle,
                         const CommandLineOption commandLineOptions[],
                         uint                    commandLineOptionCount,
                         int                     level
                        )
{
  #define PREFIX "Options: "

  uint i;
  uint maxNameLength;
  uint n;
  char name[128];
  uint j;
  char s[6];
  uint maxValueLength;

  assert(outputHandle != NULL);
  assert(commandLineOptions != NULL);

  /* get max. width of name column */
  maxNameLength = 0;
  for (i = 0; i < commandLineOptionCount; i++)
  {
    if ((level == CMD_LEVEL_ALL) || (level >= commandLineOptions[i].level))
    {
      n = 0;

      if (commandLineOptions[i].shortName != '\0')
      {
        n += 3; /* "-x|" */
      }

      assert(commandLineOptions[i].name != NULL);

      n += 2 + strlen(commandLineOptions[i].name); /* --name */
      switch (commandLineOptions[i].type)
      {
        case CMD_OPTION_TYPE_INTEGER:
          n += 4; /* =<n> */
          if (commandLineOptions[i].integerOption.units != NULL)
          {
            n += 1; /* [ */
            for (j = 0; j < commandLineOptions[i].integerOption.unitCount; j++)
            {
              if (j > 0) n += 1;
              n += strlen(commandLineOptions[i].integerOption.units[j].name);
            }       
            n += 1; /* ] */
          }
          break;
        case CMD_OPTION_TYPE_INTEGER64:
          n += 4; /* =<n> */
          if (commandLineOptions[i].integer64Option.units != NULL)
          {
            n += 1; /* [ */
            for (j = 0; j < commandLineOptions[i].integer64Option.unitCount; j++)
            {
              if (j > 0) n += 1;
              n += strlen(commandLineOptions[i].integer64Option.units[j].name);
            }       
            n += 1; /* ] */
          }
          break;
        case CMD_OPTION_TYPE_DOUBLE:
          n += 4; /* =<n> */
          break;
        case CMD_OPTION_TYPE_BOOLEAN:
          if (commandLineOptions[i].booleanOption.yesnoFlag) 
          {
            n += 9; /* [=yes|no] */
          }
          break;
        case CMD_OPTION_TYPE_ENUM:
          break;
        case CMD_OPTION_TYPE_SELECT:
          n += 7; /* =<name> */
          break;
        case CMD_OPTION_TYPE_SET:
          n += 19; /* =<name>[,<name>...] */
          break;
        case CMD_OPTION_TYPE_STRING:
          n += 2; /* =< */
          if (commandLineOptions[i].specialOption.helpArgument != NULL)
          {
            n += strlen(commandLineOptions[i].stringOption.helpArgument);
          }
          else
          {
            n += 6; /* string */
          }
          n += 1; /* > */
          break;
        case CMD_OPTION_TYPE_SPECIAL:
          n += 2; /* =< */
          if (commandLineOptions[i].specialOption.helpArgument != NULL)
          {
            n += strlen(commandLineOptions[i].specialOption.helpArgument);
          }
          else
          {
            n += 2; /* ... */
          }
          n += 1; /* > */
          break;
      }

      maxNameLength = MAX(n,maxNameLength);
    }
  }

  /* output help */
  for (i = 0; i < commandLineOptionCount; i++)
  {
    if ((level == CMD_LEVEL_ALL) || (level >= commandLineOptions[i].level))
    {
      /* output prefix */
      if (i == 0)
      {
        fprintf(outputHandle,PREFIX);
      }
      else
      {
        printSpaces(outputHandle,strlen(PREFIX));
      }

      /* output name */
      name[0] = '\0';
      if (commandLineOptions[i].shortName != '\0')
      {
        snprintf(s,sizeof(s)-1,"-%c|",commandLineOptions[i].shortName);
        strncat(name,s,sizeof(name)-strlen(name));
      }
      assert(commandLineOptions[i].name != NULL);
      strncat(name,"--",sizeof(name)-strlen(name));
      strncat(name,commandLineOptions[i].name,sizeof(name)-strlen(name));
      switch (commandLineOptions[i].type)
      {
        case CMD_OPTION_TYPE_INTEGER:
          strncat(name,"=<n>",sizeof(name)-strlen(name));
          if (commandLineOptions[i].integerOption.units != NULL)
          {
            strncat(name,"[",sizeof(name)-strlen(name));
            for (j = 0; j < commandLineOptions[i].integerOption.unitCount; j++)
            {
              if (j > 0) strncat(name,"|",sizeof(name)-strlen(name));
              strncat(name,commandLineOptions[i].integerOption.units[j].name,sizeof(name)-strlen(name));
            }       
            strncat(name,"]",sizeof(name)-strlen(name));
          }
          break;
        case CMD_OPTION_TYPE_INTEGER64:
          strncat(name,"=<n>",sizeof(name)-strlen(name));
          if (commandLineOptions[i].integer64Option.units != NULL)
          {
            strncat(name,"[",sizeof(name)-strlen(name));
            for (j = 0; j < commandLineOptions[i].integer64Option.unitCount; j++)
            {
              if (j > 0) strncat(name,"|",sizeof(name)-strlen(name));
              strncat(name,commandLineOptions[i].integer64Option.units[j].name,sizeof(name)-strlen(name));
            }       
            strncat(name,"]",sizeof(name)-strlen(name));
          }
          break;
        case CMD_OPTION_TYPE_DOUBLE:
          strncat(name,"=<n>",sizeof(name)-strlen(name));
          break;
        case CMD_OPTION_TYPE_BOOLEAN:
          if (commandLineOptions[i].booleanOption.yesnoFlag) 
          {
            strncat(name,"[=yes|no]",sizeof(name)-strlen(name));
          }
          break;
        case CMD_OPTION_TYPE_ENUM:
          break;
        case CMD_OPTION_TYPE_SELECT:
          strncat(name,"=<name>",sizeof(name)-strlen(name));
          break;
        case CMD_OPTION_TYPE_SET:
          strncat(name,"=<name>[,<name>...]",sizeof(name)-strlen(name));
          break;
        case CMD_OPTION_TYPE_STRING:
          strncat(name,"=<",sizeof(name)-strlen(name));
          if (commandLineOptions[i].stringOption.helpArgument != NULL)
          {
            strncat(name,commandLineOptions[i].stringOption.helpArgument,sizeof(name)-strlen(name));
          }
          else
          {
            strncat(name,"string",sizeof(name)-strlen(name));
          }
          strncat(name,">",sizeof(name)-strlen(name));
          break;
        case CMD_OPTION_TYPE_SPECIAL:
          strncat(name,"=<",sizeof(name)-strlen(name));
          if (commandLineOptions[i].specialOption.helpArgument != NULL)
          {
            strncat(name,commandLineOptions[i].specialOption.helpArgument,sizeof(name)-strlen(name));
          }
          else
          {
            strncat(name,"...",sizeof(name)-strlen(name));
          }
          strncat(name,">",sizeof(name)-strlen(name));
          break;
      }
      fprintf(outputHandle,"%s",name);

      /* output descriptions */
      printSpaces(outputHandle,maxNameLength-strlen(name));
      if (commandLineOptions[i].description != NULL)
      {
        fprintf(outputHandle," %s",commandLineOptions[i].description);
      }
      switch (commandLineOptions[i].type)
      {
        case CMD_OPTION_TYPE_INTEGER:
          if (commandLineOptions[i].integerOption.rangeFlag)
          {
            if      ((commandLineOptions[i].integerOption.min > INT_MIN) && (commandLineOptions[i].integerOption.max < INT_MAX))
            {
              fprintf(outputHandle," (%d..%d",commandLineOptions[i].integerOption.min,commandLineOptions[i].integerOption.max);
            }
            else if (commandLineOptions[i].integerOption.min > INT_MIN)
            {
              fprintf(outputHandle," (>= %d",commandLineOptions[i].integerOption.min);
            }
            else if (commandLineOptions[i].integerOption.max < INT_MAX)
            {
              fprintf(outputHandle," (<= %d",commandLineOptions[i].integerOption.max);
            }
            if (commandLineOptions[i].defaultValue.i != 0)
            {
              fprintf(outputHandle,", default: %d",commandLineOptions[i].defaultValue.i);
            }
            fprintf(outputHandle,")");
          }
          else 
          {
            if (commandLineOptions[i].defaultValue.i != 0)
            {
              fprintf(outputHandle," (default: %d)",commandLineOptions[i].defaultValue.i);
            }
          }
          break;
        case CMD_OPTION_TYPE_INTEGER64:
          if (commandLineOptions[i].integer64Option.rangeFlag)
          {
            if      ((commandLineOptions[i].integer64Option.min > INT_MIN) && (commandLineOptions[i].integer64Option.max < INT_MAX))
            {
              fprintf(outputHandle," (%lld..%lld",commandLineOptions[i].integer64Option.min,commandLineOptions[i].integer64Option.max);
            }
            else if (commandLineOptions[i].integer64Option.min > INT_MIN)
            {
              fprintf(outputHandle," (>= %lld",commandLineOptions[i].integer64Option.min);
            }
            else if (commandLineOptions[i].integer64Option.max < INT_MAX)
            {
              fprintf(outputHandle," (<= %lld",commandLineOptions[i].integer64Option.max);
            }
            if (commandLineOptions[i].defaultValue.l != 0LL)
            {
              fprintf(outputHandle,", default: %lld",commandLineOptions[i].defaultValue.l);
            }
            fprintf(outputHandle,")");
          }
          else
          {
            if (commandLineOptions[i].defaultValue.l != 0LL)
            {
              fprintf(outputHandle," (default: %lld)",commandLineOptions[i].defaultValue.l);
            }
          }
          break;
        case CMD_OPTION_TYPE_DOUBLE:
          if (commandLineOptions[i].doubleOption.rangeFlag)
          {
            if      ((commandLineOptions[i].doubleOption.min > DBL_MIN) && (commandLineOptions[i].doubleOption.max < DBL_MAX))
            {
              fprintf(outputHandle," (%lf..%lf",commandLineOptions[i].doubleOption.min,commandLineOptions[i].doubleOption.max);
            }
            else if (commandLineOptions[i].doubleOption.min > DBL_MIN)
            {
              fprintf(outputHandle," (>= %lf",commandLineOptions[i].doubleOption.min);
            }
            else if (commandLineOptions[i].doubleOption.max < DBL_MAX)
            {
              fprintf(outputHandle," (<= %lf",commandLineOptions[i].doubleOption.max);
            }
            if (commandLineOptions[i].defaultValue.d != 0.0)
            {
              fprintf(outputHandle,", default: %lf",commandLineOptions[i].defaultValue.d);
            }
            fprintf(outputHandle,")");
          }
          else
          {
            if (commandLineOptions[i].defaultValue.d != 0.0)
            {
              fprintf(outputHandle," (default: %lf)",commandLineOptions[i].defaultValue.d);
            }
          }
          break;
        case CMD_OPTION_TYPE_BOOLEAN:
          break;
        case CMD_OPTION_TYPE_ENUM:
          break;
        case CMD_OPTION_TYPE_SELECT:
          break;
        case CMD_OPTION_TYPE_SET:
          break;
        case CMD_OPTION_TYPE_STRING:
          if (commandLineOptions[i].defaultValue.string != NULL)
          {
            fprintf(outputHandle," (default: %s)",commandLineOptions[i].defaultValue.string);
          }
          break;
        case CMD_OPTION_TYPE_SPECIAL:
          break;
      }
      fprintf(outputHandle,"\n");
      switch (commandLineOptions[i].type)
      {
        case CMD_OPTION_TYPE_INTEGER:
        case CMD_OPTION_TYPE_INTEGER64:
          break;
        case CMD_OPTION_TYPE_DOUBLE:
          break;
        case CMD_OPTION_TYPE_BOOLEAN:
          break;
        case CMD_OPTION_TYPE_ENUM:
          break;
        case CMD_OPTION_TYPE_SELECT:
          maxValueLength = 0;
          for (j = 0; j < commandLineOptions[i].selectOption.selectCount; j++)
          {
            maxValueLength = MAX(strlen(commandLineOptions[i].selectOption.selects[j].name),maxValueLength);
          }

          for (j = 0; j < commandLineOptions[i].selectOption.selectCount; j++)
          {
            printSpaces(outputHandle,strlen(PREFIX)+maxNameLength+((commandLineOptions[i].description != NULL)?2:0)+1);
            fprintf(outputHandle,"%s",commandLineOptions[i].selectOption.selects[j].name);
            printSpaces(outputHandle,maxValueLength-strlen(commandLineOptions[i].selectOption.selects[j].name));
            fprintf(outputHandle,": %s",commandLineOptions[i].selectOption.selects[j].description);
            if (commandLineOptions[i].selectOption.selects[j].value == commandLineOptions[i].defaultValue.select)
            {
              fprintf(outputHandle," (default)");
            }
            fprintf(outputHandle,"\n");
          }
          break;
        case CMD_OPTION_TYPE_SET:
          maxValueLength = 0;
          for (j = 0; j < commandLineOptions[i].setOption.setCount; j++)
          {
            maxValueLength = MAX(strlen(commandLineOptions[i].setOption.set[j].name),maxValueLength);
          }

          for (j = 0; j < commandLineOptions[i].setOption.setCount; j++)
          {
            printSpaces(outputHandle,strlen(PREFIX)+maxNameLength+((commandLineOptions[i].description != NULL)?2:0)+1);
            fprintf(outputHandle,"%s",commandLineOptions[i].setOption.set[j].name);
            printSpaces(outputHandle,maxValueLength-strlen(commandLineOptions[i].setOption.set[j].name));
            fprintf(outputHandle,": %s",commandLineOptions[i].setOption.set[j].description);
            if (commandLineOptions[i].setOption.set[j].value == commandLineOptions[i].defaultValue.set)
            {
              fprintf(outputHandle," (default)");
            }
            fprintf(outputHandle,"\n");
          }
          break;
        case CMD_OPTION_TYPE_STRING:
          break;
        case CMD_OPTION_TYPE_SPECIAL:
          break;
      }
    }
  }
}
Ejemplo n.º 16
0
void printTree(TreeNode *tree)
{
    int i;

    INDENT;

    while (tree != NULL)  /* try not to visit null tree children */
    {
        printSpaces();

        /* Examine node type, and base output on that. */
        if (tree->nodekind == DecK)
        {
            switch(tree->kind.dec)
            {
            case ScalarDecK:
                fprintf(listing,"[Scalar declaration \"%s\" of type \"%s\"]\n"
			, tree->name, typeName(tree->variableDataType));
                break;
            case ArrayDecK:
                fprintf(listing, "[Array declaration \"%s\" of size %d"
                        " and type \"%s\"]\n",
                      tree->name, tree->val, typeName(tree->variableDataType));
                break;
            case FuncDecK:
                fprintf(listing, "[Function declaration \"%s()\""
                        " of return type \"%s\"]\n", 
                        tree->name, typeName(tree->functionReturnType));
                break;
            default:
                fprintf(listing, "<<<unknown declaration type>>>\n");
		break;
            }
        }
        else if (tree->nodekind == ExpK)
        {
            switch(tree->kind.exp)
            {
            case OpK:
                fprintf(listing, "[Operator \"");
                printToken(tree->op, "");
                fprintf(listing, "\"]\n");
                break;
            case IdK:
                fprintf(listing, "[Identifier \"%s", tree->name);
                if (tree->val != 0) /* array indexing */
                    fprintf(listing, "[%d]", tree->val);
                fprintf(listing, "\"]\n");
                break;
            case ConstK:
                fprintf(listing, "[Literal constant \"%d\"]\n", tree->val);
                break;
            case AssignK:
                fprintf(listing, "[Assignment]\n");
                break;
            default:
                fprintf(listing, "<<<unknown expression type>>>\n");
                break;
            }
        }
	else if (tree->nodekind == StmtK)
	{
	    switch(tree->kind.stmt)
	    {
		case CompoundK:
		    fprintf(listing, "[Compound statement]\n");
		    break;
                case IfK:
                    fprintf(listing, "[IF statement]\n");
                    break;
                case WhileK:
                    fprintf(listing, "[WHILE statement]\n");
                    break;
                case ReturnK:
                    fprintf(listing, "[RETURN statement]\n");
                    break;
                case CallK:
                    fprintf(listing, "[Call to function \"%s()\"]\n",
                             tree->name);
                    break;
		default:
		    fprintf(listing, "<<<unknown statement type>>>\n");
		    break;
	    }
	}
        else
            fprintf(listing, "<<<unknown node kind>>>\n");

        for (i=0; i<MAXCHILDREN; ++i)
            printTree(tree->child[i]);

        tree = tree->sibling;
    }

    UNINDENT;
}
Ejemplo n.º 17
0
Archivo: util.c Proyecto: isairz/cminus
/* procedure printTree prints a syntax tree to the 
 * listing file using indentation to indicate subtrees
 */
void printTree( TreeNode * tree )
{ int i;
  INDENT;
  while (tree != NULL) {
    printSpaces();
    if (tree->nodekind==StmtK)
    { switch (tree->kind.stmt) {
        case CompK:
          fprintf(listing,"Compound Statment\n");
          break;
        case IfK:
          fprintf(listing,"If\n");
          break;
        case IterK:
          fprintf(listing,"Repeat\n");
          break;
        case RetK:
          fprintf(listing,"Return\n");
          break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==ExpK)
    { switch (tree->kind.exp) {
        case AssignK:
          fprintf(listing,"Assign: ");
          //printToken(tree->attr.op,"\0");
          break;
        case OpK:
          fprintf(listing,"Op: ");
          printToken(tree->attr.op,"\0");
          break;
        case ConstK:
          fprintf(listing,"Const: %d\n",tree->attr.val);
          break;
        case IdK:
          fprintf(listing,"Id: %s\n",tree->attr.name);
          break;
        case ArrIdK:
          fprintf(listing,"ArrId\n");
          break;
        case CallK:
          fprintf(listing,"Call(followings are args) : %s\n", tree->attr.name);
          break;
        default:
          fprintf(listing,"Unknown ExpNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==DeclK)
    { switch (tree->kind.decl) {
        case FuncK:
          fprintf(listing,"Function Dec: %s\n",tree->attr.name);
          break;
        case VarK:
          fprintf(listing,"Var Dec: %s\n",tree->attr.name);
          break;
        case ArrVarK:
          fprintf(listing,
                  "Var Dec(following const:array length): %s %d\n",
                  tree->attr.arr.name,
                  tree->attr.arr.size);
          break;
        default:
          fprintf(listing,"Unknown DeclNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==ParamK)
    { switch (tree->kind.param) {
        case ArrParamK:
          fprintf(listing,"Array Parameter: %s\n",tree->attr.name);
          break;
        case NonArrParamK:
          fprintf(listing,"Parameter: %s\n",tree->attr.name);
          break;
        default:
          fprintf(listing,"Unknown ParamNode kind\n");
          break;
      }
    }
    else if (tree->nodekind==TypeK)
    { switch (tree->kind.type) {
        case TypeNameK:
          fprintf(listing,"Type: ");
          switch (tree->attr.type) {
            case INT:
              fprintf(listing,"int\n");
              break;
            case VOID:
              fprintf(listing,"void\n");
          }
          break;
        default:
          fprintf(listing,"Unknown TypeNode kind\n");
          break;
      }
    }
    else fprintf(listing,"Unknown node kind\n");
    for (i=0;i<MAXCHILDREN;i++) {
         printTree(tree->child[i]);
    }
    tree = tree->sibling;
  }
  UNINDENT;
}
Ejemplo n.º 18
0
// As per the tiny compiler. Probably the most ugly way to do a print statement.
void printTree(TreeNode *tree, int sibCount, bool annotated, bool scoped) {
    bool flag = false;
    if(sibCount == -1) {
        sibCount++;
        flag = true;
    } else {
        spaces += 4;
    }
    for(TreeNode *t = tree; t != NULL; t = t->sibling) {
        printSpaces();
        if(sibCount > 0) {
            printf("|Sibling: %i ", sibCount);
        } else if(sibCount == 0 && flag == false) {
            printf("Child: %i ", chiCount);
        }
        sibCount++;

        if(t->nodekind == StmtK) {
            switch(t->kind.stmt) {
            case IfK:
                printf("If ");
                break;
            case ForK:
                printf("Foreach ");
                break;
            case WhileK:
                printf("While ");
                break;
            case CompK:
                printf("Compound ");
                if(scoped) {
                    printf("with size %i at end of it's declarations ", t->memSize);
                }
                break;
            case ReturnK:
                printf("Return ");
                break;
            case BreakK:
                printf("Break ");
                break;
            }
        } else if(t->nodekind == ExprK) {
            switch(t->kind.expr) {
            case ConstK:
                printf("Const: ");
                switch(t->declType) {
                case Int:
                    printf("%i ", t->attr.ivalue);
                    break;
                case Bool:
                    if(t->attr.ivalue == 0) {
                        printf("false ");
                    } else {
                        printf("true ");
                    }
                    break;
                case Char:
                    if(t->isArray) {
                        printf("\"%s\" ", t->attr.svalue);
                    } else printf("'%c' ", t->attr.cvalue);
                    break;
                default:
                    break;
                }

                break;
            case IdK:
                printf("Id: %s ", t->attr.name);
                break;
            case OpK:
                printf("Op: %s ", t->attr.name);
                break;
            case AssignK:
                printf("Assign: %s ", t->attr.name);
                break;
            case CallK:
                printf("Call: %s ", t->attr.name);
                break;
            }
        } else if(t->nodekind == DeclK) {
            switch(t->kind.decl) {
            case FuncK:
                printf("Func %s returns type ", t->attr.name);
                break;
            case VarK:
                if(t->isArray == true) {
                    printf("Var %s is array of ", t->attr.name);
                } else {
                    printf("Var %s ", t->attr.name);
                }
                break;
            case ParamK:
                if(t->isArray == true) {
                    printf("Param %s is array of ", t->attr.name);
                } else {
                    printf("Param %s ", t->attr.name);
                }
                break;
            default:
                break;
            }
            switch(t->declType) {
            case Void:
                printf("void ");
                break;
            case Int:
                printf("int ");
                break;
            case Bool:
                printf("bool ");
                break;
            case Char:
                printf("char ");
                break;
            default:
                break;
            }
            if(scoped) {
                switch(t->kind.decl) {
                case FuncK:
                    printf("allocated as Global%s of size %i and exec location %i ", t->isStatic ? "Static" : "", t->memSize, t->memOffset);
                    break;
                case VarK:
                    printf("allocated as %s%s of size %i and data location %i ", t->isGlobal ? "Global" : "Local", t->isStatic ? "Static" : "", t->memSize, t->memOffset);
                    break;
                case ParamK:
                    printf("allocated as Parameter of size %i and data location %i ", t->memSize, t->memOffset);
                    break;
                default:
                    break;
                }
            }
        } else {
            printf("Unknown node kind.\n");
        }
        if(annotated && t->nodekind == ExprK) {
            if(t->isArray && t->child[0] == NULL) {
                printf("Type: is array of %s ", getTypeStr(t->declType));
            } else printf("Type: %s ", getTypeStr(t->declType));
        }
        printf("[line: %d]\n", t->lineno);
        for(int i = 0; i < MAXCHILDREN; i++) {
            chiCount = i;
            printTree(t->child[i], 0, annotated, scoped);
            chiCount = 0;
        }
    }
    siblingIndex--;
    spaces -= 4;
}
Ejemplo n.º 19
0
// Prints extra spaces after the name to maintain alignment
void Circuit::display_spaces(short maxSpaces)
{
	short a = maxSpaces-name.length();
	printSpaces(a);
}