#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "interpreter.h"

#if 0
#include "header_file_for_library.h"
#endif

int
  CurrentNode = 0,
  CurrentContext = 0,
  CurrentThread = 0,
  CurrentFuncID = 0;

void main(void) {

  char
    cmdBuf[200],
    cmd[30],
    arg[5][30],
    *rtrnStr;

  int
    i,
    count,
    *intList,
    rtrnInt;

  float
    rtrnFloat;

  struct functionList
    *funcList;

  struct functionDatum 
    *funcDatum;

  struct callStack
    *rtrnCallStack;

  while(1) {

    cmd[0]='\0';
    printf(">> ");
    gets(cmdBuf);
    sscanf(cmdBuf, "%s %s %s ",cmd,arg[0],arg[1]);

    if(strcmp(cmd,"")==0) {
      continue;
    }

    if(strcmp(cmd,"attach")==0) {

#if 0
      printf("  %d\n",attach(arg[0]));
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"detach")==0) {

#if 0
      printf("  %d\n",detach());
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    /* getting information from the running application */

    if(strcmp(cmd,"getNodeList")==0) {

#if 0
      count = getNodeList(intList);
      printf("  List of nodes: \n");
      for(i=0;i<count;i++) {
	printf("    %4d\n",intList[i]);
      }
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"getContextList")==0) {
#if 0
      count = getContextList(CurrentNode, intList);
      printf("  List of contexts for node %d: \n",CurrentNode);
      for(i=0;i<count;i++) {
	printf("    %4d\n",intList[i]);
      }
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"getThreadList")==0) {
#if 0
      count = getThreadList(CurrentContext, CurrentNode, intList);
      printf("  List of threads for context %d of node %d: \n",
        CurrentContext,CurrentNode);
      for(i=0;i<count;i++) {
	printf("    %4d\n",intList[i]);
      }
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"getFunctionList")==0) {
#if 0
      count = getFunctionList(CurrentContext, CurrentNode, funcList);
      printf("  List of functions for context %d of node %d: \n",
        CurrentContext,CurrentNode);
      for(i=0;i<count;i++) {
	printf("    %4d, %s, %s\n",i,funcList[i].name,funcList[i].type);
      }
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"getFunctionData")==0) {
#if 0
      funcDatum = getFunctionData(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  Data for function %d of thread %d of context %d of node %d: \n",
        CurrentFunction, CurrentThread, CurrentContext, CurrentNode);
      printFunctionDatum(funcDatum);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"")==0) {
      continue;
    }

    if(strcmp(cmd,"getFunctionName") == 0) {
#if 0
      rtrnStr = getFunctionName(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnStr);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionType") == 0) {
#if 0
      rtrnStr = getFunctionType(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnStr);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionGroupName") == 0) {
#if 0
      rtrnStr = getFunctionGroupName(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnStr);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionFunctionId") == 0) {
#if 0
      rtrnInt = getFunctionFunctionId(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnInt);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionNumCalls") == 0) {
#if 0
      rtrnInt = getFunctionNumCalls(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnInt);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionNumSubrs") == 0) {
#if 0
      rtrnInt = getFunctionNumSubrs(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnInt);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionExclTime") == 0) {
#if 0
      rtrnFloat = getFunctionExclTime(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnFloat);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionInclTime") == 0) {
#if 0
      rtrnFloat = getFunctionInclTime(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnFloat);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    if(strcmp(cmd,"getFunctionSumExclSqr") == 0) {
#if 0
      rtrnFloat = getFunctionSumExclSqr(CurrentFunction, CurrentThread, 
        CurrentContext, CurrentNode);
      printf("  %s\n",rtrnFloat);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }

    if(strcmp(cmd,"getCallStack")==0) {
#if 0
      count = getCallStack(CurrentThread, CurrentContext,
         CurrentNode, struct rtrnCallStack *);
      printCallStack(count, rtrnCallStack);
#endif
      printf("  command not implemented: %s\n",cmd);
      continue;
    }


    /* setting and displaying "Current" variables */

    if(strcmp(cmd,"setCurrentNode")==0) {
      CurrentNode = atoi(arg[0]);
      printf("  %4d\n",CurrentNode);
      continue;
    }

    if(strcmp(cmd,"setCurrentContext")==0) {
      CurrentContext = atoi(arg[0]);
      printf("  %4d\n",CurrentContext);
      continue;
    }

    if(strcmp(cmd,"setCurrentThread")==0) {
      CurrentThread = atoi(arg[0]);
      printf("  %4d\n",CurrentThread);
      continue;
    }

    if(strcmp(cmd,"setCurrentFuncID")==0) {
      CurrentFuncID = atoi(arg[0]);
      printf("  %4d\n",CurrentFuncID);
      continue;
    }

    if(strcmp(cmd,"printCurrentInfo")==0) {
      printf("  CurrentFuncID:  %4d\n",CurrentFuncID);
      printf("  CurrentThread:  %4d\n",CurrentThread);
      printf("  CurrentContext: %4d\n",CurrentContext);
      printf("  CurrentNode:    %4d\n",CurrentNode);
      continue;
    }

    if(strcmp(cmd,"")==0) {
      continue;
    }

    if(strcmp(cmd,"quit")==0) {
      break;
    }

    /* default */
    printf("  invalid command:  %s\n", cmd);

  } /* end while(1) */
}

