/* * Name: main * * Description: Gets the ball rolling... * */ int main(void) { signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGCHLD, SIG_IGN); Command cmd; int n; while (!done) { char *line; line = readline("> "); if (!line) { /* Encountered EOF at top level */// done = 1; } else { stripwhite(line); if(*line) { add_history(line); /* execute it */ n = parse(line, &cmd); PrintCommand(n, &cmd); if (! Builtexec(&cmd)) { /* If not a builtin cmd, fork */ pid_t child_pid; int child_status; child_pid = fork(); if(child_pid == 0){ Startexec(&cmd); // Child code, recursive helper function exit(0); }else{ pid_t tpid; // Parent code, to wait or not to wait for child if(!cmd.bakground){ tpid = waitpid(child_pid, &child_status, 0); } } } } /* Check for builtin command and execute it */ } if(line) { free(line); } } return 0; }
int main() { char s[200]; printf("Enter a string: \n"); fgets(s, sizeof s, stdin); Command command; command.num_sub_commands = 0; ReadCommand(s, &command); PrintCommand(&command); return 0; }
/* * Name: main * * Description: Gets the ball rolling... * */ int main(void) { Command cmd; int n; while (!done) { char *line; line = readline("> "); if (!line) { /* Encountered EOF at top level */ done = 1; } else { /* * Remove leading and trailing whitespace from the line * Then, if there is anything left, add it to the history list * and execute it. */ stripwhite(line); if (*line) { add_history(line); /* execute it */ n = parse(line, &cmd); PrintCommand(n, &cmd); } } /* Own stuff testing */ /* * Traverse through linked list, and fork process child per program * Sets up pipeline between child processes. */ runCommand(0, cmd.pgm); /* Own stuff testing - END*/ if (line) { free(line); } } return 0; }
int main() { char line[200]; /* Read a string from the user */ printf("Enter a string: "); fgets(line, sizeof line, stdin); /* Remove newline character from input */ line[strlen(line)-1] = '\0'; /* Parse string into subcommands and print */ struct Command command; ReadCommand(line, &command); ReadRedirectAndBackground(&command); PrintCommand(&command); return 0; }
/* * Name: main * * Description: Gets the ball rolling... * */ int main(void) { Command cmd; int n; while (!done) { char *line; line = readline("> "); if (!line) { /* Encountered EOF at top level */ done = 1; } else { /* * Remove leading and trailing whitespace from the line * Then, if there is anything left, add it to the history list * and execute it. */ stripwhite(line); if(*line) { add_history(line); /* execute it */ n = parse(line, &cmd); PrintCommand(n, &cmd); } } if(line) { free(line); } } return 0; }
void ConsolidateCommands(unsigned char *szCommand, int cntCommand) { /* In this function, INPUT: Read string from the serial port, that contains many different packets. OUTPUT: Parse the string received, segregate each packet and create a thread that calls the parseCommand() function for each packet. */ int i, copyToFrameArr; int cntTotalPacketsRead = 0; int cntLengthPacket = 0; int startFrame = 0, endFrame = 0; unsigned char data[260]; //data can be of maximum 251 bytes. unsigned char Frame[300]; unsigned char lengthPacket = 0; int frameCnt = 0; int dataCnt = 0; i = 0; while (i<cntCommand) { switch (szCommand[i]) { case 0x9C: if (0 == startFrame) { //we have come across the start byte, we call the start frame. // mark this as the beginning of the packet. startFrame = 1; cntLengthPacket = 0; //indicates that we are counting bytes of a new packet. Will be over-written. copyToFrameArr = 1; } else { //this indicates that the we have already initially encountered the start frame and whatever byte we are encountering now is a part of data mostly //i am using the word 'mostly' because, this should not be occuring as the 2nd,3rd,4th byte ( cntLengthPacket should be > 4 ) if (cntLengthPacket >= 4) { //now 0x9C is a part of data. //copy it into the data array data[dataCnt++] = szCommand[i]; } } break; case 0xC9: //this should happen only if startFrame is previously 1 if ((lengthPacket - 1 == cntLengthPacket) && (1 == startFrame)) { //indicates end of one packet. This byte is the end Frame. endFrame = 1; startFrame = 0; } else { //this is a part where this byte has occurred as data. } break; default: if (3 == cntLengthPacket + 1) { //indicates that we have reached the byte which gives us the length of the whole packet. lengthPacket = szCommand[i]; } break; }//switch case ends here if (copyToFrameArr) Frame[frameCnt++] = szCommand[i]; cntLengthPacket++; i++; if (1 == endFrame) { //create a thread for this packet and send this for processing. //for sending this for processing, don't terminate it with \0 and send both the count and array to the parseCommand thread. //But for the time-being just print the Frame. cntTotalPacketsRead++; printf("\n\nDatagram read -> "); PrintCommand(Frame, frameCnt); //ParseFrame(Frame, frameCnt - 1); //sending the total number of elements in the Frame array as the 2nd parameter. frameCnt = 0; //reset the frame count to read the next frame. cntLengthPacket = 0;//reset for counting the bytes of next frame. lengthPacket = 0;//reset this for the next packet. copyToFrameArr = 0; endFrame = 0; //no need to keep the flag set once you have processed this particular frame. } } if ((1 == startFrame) || (0 == cntTotalPacketsRead)) { //send a negative acknowledgement as the user has sent a command that is not in accordance with the length and other protocol standards. printf("\nErroneous bytes encountered! Sending NACK!"); writeDataToPort(NACK); } }
int _tmain(int argc, _TCHAR* argv[]) { if (!MD5Hash::Test()) return 2; if (!SHA256Hash::Test()) return 1; if (argc >= 3) { if (!_wcsicmp(argv[1], L"-p")) { const wchar_t *path = argv[2]; const wchar_t *logpath = 0; if (argc > 4 && !_wcsicmp(argv[3], L"-o")) { logpath = argv[4]; CreateOutputLog(logpath); } if (path && *path) { MappingFileClass map; int inner_argc = 0; if (map.Parse(path)) { wchar_t cmd[MAX_PATH]; do { wprintf_s(L"Command > "); if (ReadCmdFromCin(cmd, _countof(cmd))) { PrintCommand(logpath, cmd); LPWSTR *inner_argv = CommandLineToArgvW(cmd, &inner_argc); if (inner_argc && inner_argv) { if (inner_argc > 3) { if (!_wcsicmp(inner_argv[0], L"--consumerinstance")) { // --consumerinstance namespace type instancename ConsumerParserClass cp(map); if (cp.ParseConsumerInstance(path, inner_argv[1], inner_argv[2], inner_argv[3])) { cp.Print(logpath, path, inner_argv[1], inner_argv[2], inner_argv[3]); } } else if (!_wcsicmp(inner_argv[0], L"--instance")) { //--instance namespace classname instancename InstanceDeclarationParser instParser(path, inner_argv[1], map); instParser.Parse(inner_argv[2], inner_argv[3], logpath); } } else if (inner_argc > 2) { if (!_wcsicmp(inner_argv[0], L"--consumerinstance")) { // --consumerinstance namespace type ConsumerParserClass cp(map); if (cp.ParseAllConsumersByType(path, inner_argv[1], inner_argv[2])) { cp.Print(logpath, inner_argv[1], inner_argv[2]); } } else if (!_wcsicmp(inner_argv[0], L"--filterinstance")) { // --filterinstance namespace filtername EventFilterParserClass fl(map); if (fl.ParseFilterInstance(path, inner_argv[1], inner_argv[2])) { fl.Print(logpath, inner_argv[1], inner_argv[2]); } } else if (!_wcsicmp(inner_argv[0], L"--classdef")) { //--classdef namespace classname ClassDefinitionParser::Print(path, inner_argv[1], inner_argv[2], map, logpath); } else if (!_wcsicmp(inner_argv[0], L"--instance")) { //--instance namespace classname InstanceDeclarationParser instParser(path, inner_argv[1], map); instParser.Parse(inner_argv[2], logpath); } } else if (inner_argc > 1) { if (!_wcsicmp(inner_argv[0], L"--classdef")) { //--classdef namespace ClassDefinitionParser::Print(path, inner_argv[1], map, logpath); } else if (!_wcsicmp(inner_argv[0], L"--specified_classdef")) { //--specified_classdef classname ClassDefinitionParser::PrintAllClasses(path, inner_argv[1], map, logpath); } else if (!_wcsicmp(inner_argv[0], L"--consumerinstance")) { //--consumerinstance namespace ConsumerParserClass cp(map); if (cp.ParseAllConsumers(path, inner_argv[1])) { cp.Print(logpath, inner_argv[1]); } } else if (!_wcsicmp(inner_argv[0], L"--filterinstance")) { //--filterinstance namespace EventFilterParserClass fl(map); if (fl.ParseAllFilterInstances(path, inner_argv[1])) { fl.Print(logpath, inner_argv[1]); } } else if (!_wcsicmp(inner_argv[0], L"--bindinginstance")) { //--bindinginstance namespace FilterToConsumerBindingParserClass bd(map); if (bd.ParseAllBindings(path, inner_argv[1])) { bd.Print(inner_argv[1], logpath); } } else if (!_wcsicmp(inner_argv[0], L"--instance")) { //--instance classname InstanceDeclarationParser instParser(path, L"", map); instParser.ParseInAllNS(inner_argv[1], logpath); } } else if (inner_argc) { if (!_wcsicmp(inner_argv[0], L"--namespaceinstance")) ParseNamespace(path, map, logpath); else if (!_wcsicmp(inner_argv[0], L"--classdef")) { //--classdef ClassDefinitionParser::Print(path, map, logpath); } else if (!_wcsicmp(inner_argv[0], L"--index")) { ParseAllIndexFile(path, map, logpath); } else if (!_wcsicmp(inner_argv[0], L"--help")) { PrintHelp(); } else if (!_wcsicmp(inner_argv[0], L"--quit")) break; } else break; } } } while (true); } } } } else wprintf(L"Usage : WMIParser.exe -p $path_to_objects_data$ [-o $output_file_path$]\r\n"); return 0; }