/** * Actually gets the input from the user and puts this in the appropriate data area */ static struct value_defn performGetInputFromUser(char * toDisplay, int threadId) { struct value_defn v; v.dtype=SCALAR; char inputvalue[1000]; if (toDisplay != NULL) { printf("[host %d] %s", threadId, toDisplay); } else { printf("host %d> ", threadId); } scanf("%[^\n]", inputvalue); int inputType=getTypeOfInput(inputvalue); if (inputType==INT_TYPE) { v.type=INT_TYPE; *((int*) v.data)=atoi(inputvalue); } else if (inputType==REAL_TYPE) { v.type=REAL_TYPE; *((float*) v.data)=atof(inputvalue); } else { v.type=STRING_TYPE; char * newString=(char*) malloc(strlen(inputvalue)+1); strcpy(newString, inputvalue); cpy(&v.data, &newString, sizeof(char*)); } return v; }
/** * Inputs a message from the user, with some optional displayed message. */ static void inputCoreMessage(int coreId, struct core_ctrl * core) { char inputvalue[1000]; if (core->data[0] == STRING_TYPE) { unsigned int relativeLocation; memcpy(&relativeLocation, &core->data[1], sizeof(unsigned int)); char * message=core->host_shared_data_start+relativeLocation; printf("[device %d] %s", coreId, message); } else { printf("device %d> ", coreId); } scanf("%[^\n]", inputvalue); int inputType=getTypeOfInput(inputvalue); // The following 2 lines cleans up the input so it is ready for the next input call int c; while ( (c = getchar()) != '\n' && c != EOF ) { } if (inputType==INT_TYPE) { core->data[0]=INT_TYPE; int iv=atoi(inputvalue); memcpy(&core->data[1], &iv, sizeof(int)); } else if (inputType==REAL_TYPE) { core->data[0]=REAL_TYPE; float fv=atof(inputvalue); memcpy(&core->data[1], &fv, sizeof(float)); } else { core->data[0]=STRING_TYPE; unsigned int relativeLocation; memcpy(&relativeLocation, &core->data[6], sizeof(unsigned int)); char * target=core->host_shared_data_start+relativeLocation; strcpy(target, inputvalue); } }