int ask_yes_no(const char *question) { INITIALIZE_LIBREPORT(); const char *yes = _("y"); const char *no = _("N"); char *env_response = getenv("REPORT_CLIENT_RESPONSE"); if (env_response) return strncasecmp(yes, env_response, strlen(yes)) == 0; if (is_slave_mode()) printf(REPORT_PREFIX_ASK_YES_NO "%s\n", question); else printf("%s [%s/%s] ", question, yes, no); fflush(stdout); if (!is_slave_mode() && is_noninteractive_mode()) { putchar('\n'); fflush(stdout); return 0; } char response[16]; if (NULL == fgets(response, sizeof(response), stdin)) return 0; return ((is_slave_mode() && response[0] == 'y') || strncasecmp(yes, response, strlen(yes)) == 0); }
char *ask_password(const char *question) { if (is_slave_mode()) printf(REPORT_PREFIX_ASK_PASSWORD "%s\n", question); else printf("%s ", question); fflush(stdout); if (!is_slave_mode() && is_noninteractive_mode()) { putchar('\n'); fflush(stdout); return xstrdup(""); } bool changed = set_echo(false); char *result = xmalloc_fgets(stdin); strtrimch(result, '\n'); if (changed) set_echo(true); return result; }
int ask_yes_no_yesforever(const char *key, const char *question) { INITIALIZE_LIBREPORT(); const char *yes = _("y"); const char *no = _("N"); const char *forever = _("f"); { /* Use response from REPORT_CLIENT_RESPONSE environment variable. * * The forever response is not allowed in this case. * There is no serious reason for that, it is just decision. * (It doesn't make much sense to allow the forever answer here.) */ const char *env_response = getenv("REPORT_CLIENT_RESPONSE"); if (env_response) return strncasecmp(yes, env_response, strlen(yes)) == 0; } { /* Load an value for the key from user setting. * NO means 'Don't ask me again, I said yes forever'. */ const char *option = get_user_setting(key); if (option && string_to_bool(option) == false) return 1; } if (is_slave_mode()) printf(REPORT_PREFIX_ASK_YES_NO_YESFOREVER "%s %s\n", key, question); else printf("%s [%s/%s/%s] ", question, yes, no, forever); fflush(stdout); if (!is_slave_mode() && is_noninteractive_mode()) { putchar('\n'); fflush(stdout); return 0; } char response[16]; if (NULL == fgets(response, sizeof(response), stdin)) return 0; if ((is_slave_mode() && response[0] == 'f') || strncasecmp(forever, response, strlen(forever)) == 0) { /* NO means 'Don't ask me again, I said yes forever'. */ set_user_setting(key, "no"); return 1; } else set_user_setting(key, "yes"); return ((is_slave_mode() && response[0] == 'y') || strncasecmp(yes, response, strlen(yes)) == 0); }
void alert(const char *message) { if (is_slave_mode()) printf(REPORT_PREFIX_ALERT); puts(message); fflush(stdout); }
void client_log(const char *message) { if (message != NULL && (message[0] == '.' && message[1] == '\0') && !is_slave_mode() ) putchar('.'); else printf("%s\n", message); fflush(stdout); }
char *ask(const char *question) { if (is_slave_mode()) printf(REPORT_PREFIX_ASK "%s\n", question); else printf("%s ", question); fflush(stdout); if (!is_slave_mode() && is_noninteractive_mode()) { putchar('\n'); fflush(stdout); return xstrdup(""); } char *result = xmalloc_fgets(stdin); strtrimch(result, '\n'); return result; }
/* * return: 0 - the chip is a i2c slave * 1 - the chip is a i2c master */ int i2c_slave_probe(u_int8_t chip) { int rc = 1; if ( is_own_slave(chip) ) { if ( !is_slave_mode() ) { printf("%s(): chip == REG(I2C_OA), not in slave mode\n", __FUNCTION__); i2c_slave_reset(chip); } rc = 0; } printf("davinci: %s(): Excuted %d\n", __FUNCTION__, rc); return rc; }
/// 콘솔 입력 처리 /// \param buf command string /// \param args serial fd int handle_console(char *buf, int args) { char *p; int fd_serial = args; // \n 제거 p = strrchr(buf, '\n'); if ( p ) { *p = 0; } if ( global_conf.flag | CONF_FLAG_CONSOLE ) { if ( strcmp(buf, "q") == 0 ) { return -ERR_STOP; } else if (strncmp(buf, "clm ", 4) == 0 ) { // test clm data struct clm_data test; char path[1024]; sprintf(path, "%s/%s.clm", global_conf.transfer, &buf[4]); clm_data_ImportFile(&test, path); } else if (strncmp(buf, "mrk ", 4) == 0 ) { // test mrk data struct mrk_data test; char path[1024]; sprintf(path, "%s/%s.mrk", global_conf.transfer, &buf[4]); mrk_data_ImportFile(&test, path); } else if (strncmp(buf, "send ", 5) == 0 ) { // send test struct clm_data clm_data; struct mrk_data mrk_data; char packet[1024]; int packet_size; int ret; char path[1024]; sprintf(path, "%s/%s", global_conf.transfer, &buf[5]); if ( strstr(&buf[5], ".mrk") != NULL) { if ( mrk_data_ImportFile(&mrk_data, path) == FALSE) { return 0; } packet_size = mrk_data_GetPacketStr(packet, sizeof(packet), 1, &mrk_data); DBG("mrk packet = [%s]\n", packet); ret = send_raw_packet(fd_serial, packet, packet_size); DBG("ret = %d\n", ret); } else if ( strstr(&buf[5], ".clm") != NULL ) { if ( clm_data_ImportFile(&clm_data, path) == FALSE ) { return 0; } ; packet_size = clm_data_GetPacketStr(packet, sizeof(packet), 1, &clm_data); DBG("cdr packet = [%s]\n", packet); ret = send_raw_packet(fd_serial, packet, packet_size); DBG("ret = %d\n", ret); } else { printf("Invalid filename. %s\n", &buf[5]); } } else if (strcmp(buf, "h") == 0 ) { printf("console command -------\n"); printf("q : quit\n"); printf("clm [filename] : load clm data. file ext not needed.\n"); printf("mrk [filename] : load mrk data. file ext not needed.\n"); printf("send [filename.ext] : send clm/mrk data to CDR.\n"); } } if ( is_slave_mode() ){ // slave mode process_gui_msg(fd_serial, buf); } return 0; }