void function(void) { key_diy(); switch(key_status) { case 1: function1(); break; case 2: function2(); break; case 3: function3(); break; case 4: function4(); break; case 5: function5(); break; case 6: function6(); break; case 7: function7(); break; default: function0(); break; } }
int main() { int sel = -1; char buffer[INPUT_LENGTH]; int isInputValid = INPUT_INVALID; Num Num1; Num Num2; Num NumResult[5]; for(;;) { display_menu(); fflush(stdin); while(1) { isInputValid = getTwoInput(&Num1, &Num2); if(isInputValid == INPUT_INVALID) { printf("Please input again...\n"); } else { break; } } function1(&Num1, &Num2, &(NumResult[0])); function2(&Num1, &Num2, &(NumResult[1])); function3(&Num1, &Num2, &(NumResult[2])); function4(&Num1, &Num2, &(NumResult[3])); function5(&Num1, &Num2, &(NumResult[4])); printResult(&Num1, &Num2, NumResult); } printf("종료합니다.\n"); getchar(); return 0; }
void *print_functions (void *args) { int i = (int) args; int j; if (i % 4 == 0) { for(j = 0; j < 3; j++) { function1(); } for(j = 0; j < 3; j++) { function2(); } for(j = 0; j < 3; j++) { function3(); } for(j = 0; j < 3; j++) { function4(); } } if (i % 4 == 1) { for(j = 0; j < 3; j++) { function2(); } for(j = 0; j < 3; j++) { function3(); } for(j = 0; j < 3; j++) { function4(); } for(j = 0; j < 3; j++) { function1(); } } if (i % 4 == 2) { for(j = 0; j < 3; j++) { function3(); } for(j = 0; j < 3; j++) { function4(); } for(j = 0; j < 3; j++) { function1(); } for(j = 0; j < 3; j++) { function2(); } } if (i % 4 == 3) { for(j = 0; j < 3; j++) { function4(); } for(j = 0; j < 3; j++) { function1(); } for(j = 0; j < 3; j++) { function2(); } for(j = 0; j < 3; j++) { function3(); } } return 0; }
int main (int argc, char const * argv []) { static char const * optv [] = { "f:g:n:p:iqrvw:z", "", "PTS Module Controller", "f f\tport is (f) [" PTSCTL_PORT "]", "g n\tline ground attenuation is (n) [" LITERAL (PTSCTL_GRND_ATTN) "]", "n n\tline neutral attenuation is (n) [" LITERAL (PTSCTL_LINE_ATTN) "]", "p n\tpower is (n) [" LITERAL (PTSCTL_MODE) "]", "q\tquiet mode", "r\tread and display attenuator settings", "v\tverbose mode", "w n\twait (n) millseconds [" LITERAL (PTSCTL_WAIT) "]", (char const *) (0) }; struct _file_ port = { -1, PTSCTL_PORT }; #if defined (WIN32) HANDLE hSerial; DCB dcbSerial = { 0 }; #else struct termios termios; #endif char const * units = PTSCTL_UNITS; unsigned wait = PTSCTL_WAIT; unsigned mode = PTSCTL_MODE; unsigned echo = PTSCTL_ECHO; unsigned line = PTSCTL_LINE_ATTN; unsigned grnd = PTSCTL_GRND_ATTN; unsigned data = 0; flag_t flags = (flag_t)(0); signed c; optind = 1; if (getenv ("PTSCTL")) { port.name = strdup (getenv ("PTSCTL")); } while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 'f': port.name = optarg; break; case 'g': _setbits (flags, PTSCTL_CHANGE); grnd = (unsigned)(uintspec (optarg, 0, 0x7F)); break; case 'n': _setbits (flags, PTSCTL_CHANGE); line = (unsigned)(uintspec (optarg, 0, 0x7F)); break; case 'p': _setbits (flags, PTSCTL_CHANGE); mode = (unsigned)(uintspec (synonym (optarg, modes, SIZEOF (modes)), 0, 1)); break; case 'w': wait = (unsigned)(uintspec (optarg, 5, 100)); break; case 'q': _setbits (flags, PTSCTL_SILENCE); break; case 'r': _setbits (flags, PTSCTL_DISPLAY); break; case 'v': _setbits (flags, PTSCTL_VERBOSE); break; case 'z': _setbits (flags, PTSCTL_ITERATE); break; default: break; } } argc -= optind; argv += optind; if (argc) { error (1, ENOTSUP, ERROR_TOOMANY); } #if defined (WIN32) hSerial = CreateFile (port.name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hSerial == INVALID_HANDLE_VALUE) { error (1, errno, FILE_CANTOPEN, port.name); } dcbSerial.DCBlength = sizeof (dcbSerial); if (!GetCommState (hSerial, &dcbSerial)) { error (1, 0, FILE_CANTREAD " state", port.name); } dcbSerial.BaudRate = CBR_9600; dcbSerial.ByteSize = 8; dcbSerial.StopBits = ONESTOPBIT; dcbSerial.Parity = NOPARITY; if (!SetCommState (hSerial, &dcbSerial)) { error (1, 0, FILE_CANTSAVE " state", port.name); } CloseHandle (hSerial); if ((port.file = open (port.name, O_BINARY | O_RDWR)) == -1) { error (1, errno, FILE_CANTOPEN, port.name); } #else if ((port.file = open (port.name, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) { error (1, 0, FILE_CANTOPEN, port.name); } tcgetattr (port.file, &termios); termios.c_cflag = CS8; cfsetospeed (&termios, B9600); tcsetattr (port.file, TCSANOW, &termios); #endif function1 (&port, units, wait, echo); if (_anyset (flags, PTSCTL_CHANGE)) { data = line << 8 | grnd << 1 | mode; function2 (&port, units, wait, data); } if (_anyset (flags, PTSCTL_DISPLAY)) { function3 (&port, units, wait); } if (_anyset (flags, PTSCTL_ITERATE)) { function4 (&port, units, wait); } close (port.file); return (0); }