void Program::start() { if (!readCommandLine()) { return; } if (!initializeAudioDevice()) { return; } boost::system::error_code error; core->io_service.run(error); }
void Instruction_Repl(ForthVm *vm) { char maxLine[1024]; ForthStream *fstr; printf("%s\n", LEOFORTH_VERSION); printf("Code Space: %i\n", vm->hereCodePtr); printf("Data Space: %i\n", vm->hereDataPtr); printf("----\n\n"); fstr = ForthStream_NewForBuffer("<line>", ""); ForthVm_SetParser(vm, fstr); printf("\n\n"); while(TRUE) { if(vm->internalState == VM_COMPILER) { printf("(compiler) "); } printf("4> "); fflush(stdout); memset(maxLine, 0, 1024); if(!readCommandLine(maxLine, 1024)) { break; } ForthStream_ResetForBuffer(fstr, "<line>", maxLine); vm->exitFlag=0; ForthVm_Feed(vm); ForthVm_Output(vm, " ok\n"); fflush(stdout); } ForthStream_Delete(fstr); }
static int brl_construct (BrailleDisplay *brl, char **parameters, const char *device) { if (!allocateCommandDescriptors()) return 0; inputLength = 0; inputStart = 0; inputEnd = 0; outputLength = 0; if (isQualifiedDevice(&device, "client")) { static const ModeEntry clientModeEntry = { #ifdef AF_LOCAL requestLocalConnection, #endif /* AF_LOCAL */ #ifdef __MINGW32__ requestNamedPipeConnection, #endif /* __MINGW32__ */ requestInetConnection }; mode = &clientModeEntry; } else if (isQualifiedDevice(&device, "server")) { static const ModeEntry serverModeEntry = { #ifdef AF_LOCAL acceptLocalConnection, #endif /* AF_LOCAL */ #ifdef __MINGW32__ acceptNamedPipeConnection, #endif /* __MINGW32__ */ acceptInetConnection }; mode = &serverModeEntry; } else { unsupportedDevice(device); goto failed; } if (!*device) device = VR_DEFAULT_SOCKET; #ifdef AF_LOCAL if (device[0] == '/') { struct sockaddr_un address; if (setLocalAddress(device, &address)) { fileDescriptor = mode->getLocalConnection(&address); } } else #endif /* AF_LOCAL */ #ifdef __MINGW32__ if (device[0] == '\\') { fileDescriptor = mode->getNamedPipeConnection(device); } else { static WSADATA wsadata; if (WSAStartup(MAKEWORD(1, 1), &wsadata)) { logWindowsSystemError("socket library start"); goto failed; } } #endif /* __MINGW32__ */ { struct sockaddr_in address; if (setInetAddress(device, &address)) { fileDescriptor = mode->getInetConnection(&address); } } if (fileDescriptor != -1) { char *line = NULL; while (1) { if (line) free(line); if ((line = readCommandLine())) { const char *word; logMessage(LOG_DEBUG, "command received: %s", line); if ((word = strtok(line, inputDelimiters))) { if (testWord(word, "cells")) { if (dimensionsChanged(brl)) { free(line); return 1; } } else if (testWord(word, "quit")) { break; } else { logMessage(LOG_WARNING, "unexpected command: %s", word); } } } else { asyncWait(1000); } } if (line) free(line); close(fileDescriptor); fileDescriptor = -1; } failed: deallocateCommandDescriptors(); return 0; }
int main() { //This defines the signal interrupt behavior. init(); //Raw command line input, stored as char array char *rawInput; //Parsed command line input, arguments stored as array of char arrays struct job parsedInput; //Initialize the "status" member variable in case user calls it first. strcpy(parsedInput.exitStatus, "none"); //Loop runs indefinitely, until user enters "exit" command. while(1) { //Reset all variables regarding command line input. parsedInput.isInput = 0; parsedInput.isOutput = 0; parsedInput.isBackground = 0; parsedInput.argCount = 0; //Prints the command line. fflush(stdout); printf(": "); //Reads input from the command line, stored as char array. rawInput = readCommandLine(); //If user does not enter anything, or enters a comment, no need to process input. if(rawInput[0] == '\n' || rawInput[0] == '#') { free(rawInput); continue; } /*Since the testing script doesn't end with an "exit" statement, this prevents the program from running in an infinite loop. If the user enters a blank line, it actually includes a /n character. This runs when hitting the end of the input file.*/ if(rawInput[0] == '\0') break; //Process raw input, returns tokenized array with appropriate Bool values set. parseCommandLine(rawInput, &parsedInput); /*If user tries to enter only redirect and/or background characters, issues error. commented out to avoid a preposterous amount of error messages when the grading script runs indefinitely. Since this condition isn't explicitly checked for in the script, shouldn't cause a problem.*/ if(parsedInput.argCount == 0) { // printf("Error: Invalid syntax. Enter at least 1 argument at the command line.\n"); continue; } //If user calls built-in function "exit", exit the shell program. if (strcmp(parsedInput.args[0], "exit") == 0) break; //If user calls "cd" or "status", call those built in commands. else if(strcmp(parsedInput.args[0], "cd") == 0 || strcmp(parsedInput.args[0], "status") == 0 ) runBuiltIn(&parsedInput); //In all other cases, run the command. else runCommand(&parsedInput); free(rawInput); } exit(0); }
//this will be LinkLayerAbsInit when linked toghter with 6LowPan int main(int argc, char **argv) { int flags; // Used to set non-blocking for stdin int retval; ule6lo_status_t status; // Used as result in many ule6lo lib calls ule6lo_IPEI_t ipei; ule6lo_macAddr_t mac; //Initialize test hooks ule6loTestIn_regRxHook(&test_rx); ule6loTestIn_regTxHook(&test_tx); // Setup stdin to operate non blocking flags = fcntl(0, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(0, F_SETFL, flags); //Reset number of received bytes app_bytes_recv = 0; //Print instruction message printf("To send a message use this format and acknowledge with enter:\n<Destination ip> <Destination port> <message>\n"); printf("Use port 3001 for now\n"); // Debug print of contiki setup (defines etc) printContikiConfigurationInfo(); printf("Args: <LBR IP> <LN port> <LN IPEI(mac addr style,example:00:00:00:00:01)> <Mac addr>\n"); if(argc>=5) { status = ule6loGI_init(); printf("ule6loGI_init() returned %i\n", status); // Initialize link layer sscanf(argv[3],"%2hhX:%2hhX:%2hhX:%2hhX:%2hhX",&(ipei.id[0]),&(ipei.id[1]),&(ipei.id[2]),&(ipei.id[3]),&(ipei.id[4])); sscanf(argv[4],"%2hhX:%2hhX:%2hhX:%2hhX:%2hhX:%2hhX",&(mac.u8[0]),&(mac.u8[1]),&(mac.u8[2]),&(mac.u8[3]),&(mac.u8[4]),&(mac.u8[5])); ule6loGI_setMacAddress(&mac); lla_init(argv[1],atoi(argv[2]),&ipei); printf("Using IP %s and port %i and IPEI %s and MAC addr %s\n",argv[1],atoi(argv[2]), argv[3], argv[4]); } else { printf("Incorrect number of arguments"); return 1; } //Wait for connection while(ule6loGI_getStatus() != STATUS_SUCCESS) { sleep(1); } // Print our Link local address and our global address printLinkLocalAddress(); printGloballAddress(); //Create timer to print our IP addresses periodically stimer_set(&ipPrintTimer,10 ); // Print all our IP addresses printIPAddresses(); printIPV6Neighbourlist(); init_udp(); ule6lo_ip6addr_t loc_fipaddr2; memset(&loc_fipaddr2, 0x00, sizeof(loc_fipaddr2)); loc_fipaddr2.u8[0] = 0xff; loc_fipaddr2.u8[1] = 0x02; loc_fipaddr2.u8[10] = 0x00; loc_fipaddr2.u8[11] = 0x00; loc_fipaddr2.u8[12] = 0x00; loc_fipaddr2.u8[13] = 0x01; loc_fipaddr2.u8[15] = 0x05; ule6loGI_addMulticastAddr(&loc_fipaddr2); // Run forever while(1){ // Check the stdin for data readCommandLine(app_res, app_buffer, app_bytes_recv); // Let link layer receive data is any is present llaProcess(); debugPrint(); // Allow the stack to run ule6loOS_processRun(); } return 0; }