/* Calculates the truth value of the next condition starting from p. Returns the point after condition. */ static char *test_condition (char *p, int *condition) { WPanel *panel; char arg [256]; /* Handle one condition */ for (;*p != '\n' && *p != '&' && *p != '|'; p++){ if (*p == ' ' || *p == '\t') continue; if (*p >= 'a') panel = cpanel; else { if (get_other_type () == view_listing) panel = other_panel; else panel = NULL; } *p |= 0x20; switch (*p++){ case '!': p = test_condition (p, condition); *condition = ! *condition; p--; break; case 'f': p = extract_arg (p, arg); *condition = panel && regexp_match (arg, panel->dir.list [panel->selected].fname, match_file); break; case 'd': p = extract_arg (p, arg); *condition = panel && regexp_match (arg, panel->cwd, match_file); break; case 't': p = extract_arg (p, arg); *condition = panel && test_type (panel, arg); break; default: debug_error = 1; break; } /* switch */ } /* while */ return p; }
int32_t sinsp_filter_check_event::parse_field_name(const char* str) { string val(str); // // A couple of fields are handled in a custom way // if(string(val, 0, sizeof("evt.arg") - 1) == "evt.arg" && string(val, 0, sizeof("evt.args") - 1) != "evt.args") { m_field_id = TYPE_ARGSTR; m_field = &m_info.m_fields[m_field_id]; return extract_arg("evt.arg", val, NULL); } else if(string(val, 0, sizeof("evt.rawarg") - 1) == "evt.rawarg") { m_field_id = TYPE_ARGRAW; m_customfield = m_info.m_fields[m_field_id]; int32_t res = extract_arg("evt.rawarg", val, &m_arginfo); m_customfield.m_type = m_arginfo->type; return res; } else if(string(val, 0, sizeof("evt.latency") - 1) == "evt.latency" || string(val, 0, sizeof("evt.latency.s") - 1) == "evt.latency.s" || string(val, 0, sizeof("evt.latency.ns") - 1) == "evt.latency.ns") { // // These fields need to store the previuos event type in the thread state // m_th_state_id = m_inspector->reserve_thread_memory(sizeof(uint16_t)); return sinsp_filter_check::parse_field_name(str); } else { return sinsp_filter_check::parse_field_name(str); } }
void gdbscm_parse_function_args (const char *func_name, int beginning_arg_pos, const SCM *keywords, const char *format, ...) { va_list args; const char *p; int i, have_rest, num_keywords, length, position; int have_optional = 0; SCM status; SCM rest = SCM_EOL; /* Keep track of malloc'd strings. We need to free them upon error. */ VEC (char_ptr) *allocated_strings = NULL; char *ptr; have_rest = validate_arg_format (format); num_keywords = count_keywords (keywords); va_start (args, format); p = format; position = beginning_arg_pos; /* Process required, optional arguments. */ while (*p && *p != '#' && *p != '.') { SCM arg; void *arg_ptr; if (*p == '|') { have_optional = 1; ++p; continue; } arg = va_arg (args, SCM); if (!have_optional || !SCM_UNBNDP (arg)) { arg_ptr = va_arg (args, void *); status = extract_arg (*p, arg, arg_ptr, func_name, position); if (!gdbscm_is_false (status)) goto fail; if (*p == 's') VEC_safe_push (char_ptr, allocated_strings, *(char **) arg_ptr); } ++p; ++position; }
// ------------------------------------------------------------------------ // Main loop the program runs in while connected to the server. // Receives, authenticates, sends confirmation, and executes actions from // the server. // ------------------------------------------------------------------------ int Racr::daemon(){ char packet[PACKET_SIZE + 1]; if( _state != CONNECTED ){ return FAIL; } while( _ethernet_client.connected() ){ if( _ethernet_client.available() ){ // Packet read failed, flush stream and continue // (the continue will then check for connection status) if( !read_packet(packet) ){ Serial.println("Read Failed"); _ethernet_client.flush(); continue; } // If authentication fails, skip ahead to next packet. if( !auth_packet(packet) ){ Serial.println("Auth Failed"); continue; } // If we can't tell the server we got the command, // do not execute the command! if( !send_confirmation(packet) ){ Serial.println("Receipt confirmation failed"); continue; } // Execute the given action. int action = extract_action(packet); int arg = extract_arg(packet); (*_action_funcs[action])(arg); } } Serial.println("Connection died =("); _ethernet_client.stop(); _state = CONNECTION_SHUTDOWN; return SUCCESS; }
/* Calculates the truth value of the next condition starting from p. Returns the point after condition. */ static char *test_condition (WEdit *edit_widget, char *p, int *condition) { WPanel *panel; char arg [256]; /* Handle one condition */ for (;*p != '\n' && *p != '&' && *p != '|'; p++){ /* support quote space .mnu */ if ((*p == ' ' && *(p-1) != '\\') || *p == '\t') continue; if (*p >= 'a') panel = current_panel; else { if (get_other_type () == view_listing) panel = other_panel; else panel = NULL; } *p |= 0x20; switch (*p++){ case '!': p = test_condition (edit_widget, p, condition); *condition = ! *condition; p--; break; case 'f': /* file name pattern */ p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, panel->dir.list [panel->selected].fname, match_file, 0); break; case 'y': /* syntax pattern */ if (edit_widget && edit_widget->syntax_type) { p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, edit_widget->syntax_type, match_normal, 0); } break; case 'd': p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, panel->cwd, match_file, 0); break; case 't': p = extract_arg (p, arg, sizeof (arg)); *condition = panel && test_type (panel, arg); break; case 'x': /* executable */ { struct stat status; p = extract_arg (p, arg, sizeof (arg)); if (stat (arg, &status) == 0) *condition = is_exe (status.st_mode); else *condition = 0; break; } default: debug_error = 1; break; } /* switch */ } /* while */ return p; }
static char * test_condition (WEdit * edit_widget, char *p, int *condition) { char arg[256]; const mc_search_type_t search_type = easy_patterns ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX; /* Handle one condition */ for (; *p != '\n' && *p != '&' && *p != '|'; p++) { WPanel *panel = NULL; /* support quote space .mnu */ if ((*p == ' ' && *(p - 1) != '\\') || *p == '\t') continue; if (*p >= 'a') panel = current_panel; else if (get_other_type () == view_listing) panel = other_panel; *p |= 0x20; switch (*p++) { case '!': p = test_condition (edit_widget, p, condition); *condition = !*condition; str_prev_char (&p); break; case 'f': /* file name pattern */ p = extract_arg (p, arg, sizeof (arg)); #ifdef USE_INTERNAL_EDIT if (edit_widget != NULL) { char *edit_filename; edit_filename = edit_get_file_name (edit_widget); *condition = mc_search (arg, DEFAULT_CHARSET, edit_filename, search_type) ? 1 : 0; g_free (edit_filename); } else #endif *condition = panel != NULL && mc_search (arg, DEFAULT_CHARSET, panel->dir.list[panel->selected].fname, search_type) ? 1 : 0; break; case 'y': /* syntax pattern */ #ifdef USE_INTERNAL_EDIT if (edit_widget != NULL) { const char *syntax_type = edit_get_syntax_type (edit_widget); if (syntax_type != NULL) { p = extract_arg (p, arg, sizeof (arg)); *condition = mc_search (arg, DEFAULT_CHARSET, syntax_type, MC_SEARCH_T_NORMAL) ? 1 : 0; } } #endif break; case 'd': p = extract_arg (p, arg, sizeof (arg)); *condition = panel != NULL && mc_search (arg, DEFAULT_CHARSET, vfs_path_as_str (panel->cwd_vpath), search_type) ? 1 : 0; break; case 't': p = extract_arg (p, arg, sizeof (arg)); *condition = panel != NULL && test_type (panel, arg) ? 1 : 0; break; case 'x': /* executable */ { struct stat status; p = extract_arg (p, arg, sizeof (arg)); if (stat (arg, &status) == 0) *condition = is_exe (status.st_mode) ? 1 : 0; else *condition = 0; break; } default: debug_error = 1; break; } /* switch */ } /* while */ return p; }
/* curr_file pointer must point to a heap-allocated string */ int process_cmd(char **curr_file, char *cmd, bst **address_book, int *quit) { int parse_succeeded; char *cnet; char *infile; char *first_char; switch (cmd[0]) { case 'q': if (strcmp(cmd,"q")==0) { *quit = 1; return 1; } return 0; case 's': if (strcmp(cmd,"s")==0) { if (strlen(*curr_file)>0) fprintf(stdout,"Current file: %s.\n",*curr_file); addr_book_stats(*address_book); return 1; } return 0; case 'r': infile = extract_arg(cmd, &parse_succeeded); if (parse_succeeded) { bst *tmp = *address_book; *address_book = admin_addr_book_from_file(infile); if (*address_book==NULL) { /* restore address book */ *address_book = tmp; } else { free(*curr_file); *curr_file = infile; bst_free(tmp); } } return parse_succeeded; case 'c': first_char = extract_arg(cmd, &parse_succeeded); if (parse_succeeded) { if (strlen(first_char)!=1) fprintf(stdout,"Please type exactly one character as argument to c.\n"); else { unsigned int z = bst_c(*address_book, first_char[0]); printf("(found %u CNETs starting with '%c')\n",z,first_char[0]); } putchar('\n'); free(first_char); } return parse_succeeded; case 'l': cnet = extract_arg(cmd, &parse_succeeded); if (parse_succeeded) { int n_comparisons = 0; vcard *c = bst_search(*address_book, cnet, &n_comparisons); if (c==NULL) fprintf(stdout,"%s not found in current address book.\n", cnet); else vcard_show(c); fprintf(stdout,"(Performed %d comparisons in search.)\n", n_comparisons); putchar('\n'); } free(cnet); return parse_succeeded; case 'h': help_text(); return 1; default: return 0; } }