MODULE get_user_command_input (THREAD *thread) { static struct { char *name; event_t event; } keywords [] = { { "LIST", list_event }, { "STATUS", status_event }, { "START", start_event }, { "PAUSE", pause_event }, { "STOP", stop_event }, { "HALT", halt_event }, { "EXIT", exit_event }, { "QUIT", exit_event }, { "HELP", help_event }, { "VERSION", version_event }, { "REFRESH", refresh_event }, { NULL, 0 } }; int keyword_nbr; /* If we got a command from the user, use it, else prompt */ if (command && strused (command)) { strncpy (input_line, command, LINE_MAX); input_line [LINE_MAX] = '\0'; /* Ensure delimited, if looong */ command = "exit"; /* Next time treat as Exit */ } else { /* Show syscli prompt and wait for user command */ printf ("syscli> "); fflush (stdout); if (fgets (input_line, LINE_MAX, stdin) == NULL) strclr (input_line); /* Treat EOF as empty */ } if (token_list) tok_free (token_list); token_list = tok_split (input_line); /* Get event corresponding to user command */ if (token_list [0] && *token_list [0]) { the_next_event = error_event; strupc (token_list [0]); for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++) if (streq (token_list [0], keywords [keyword_nbr].name)) { the_next_event = keywords [keyword_nbr].event; break; } /* Specific handling for stop command without arguments */ if (the_next_event == stop_event && token_list [1] == NULL) the_next_event = stop_all_event; } else the_next_event = empty_event; }
MODULE get_user_command_input (THREAD *thread) { static char input_line [LINE_MAX + 1]; static struct { char *name; event_t event; } keywords [] = { { "LIST", list_event }, { "START", start_event }, { "STOP", stop_event }, { "STATUS", status_event }, { "HALT", halt_event }, { "EXIT", exit_event }, { "QUIT", exit_event }, { "HELP", help_event }, { "VERSION", version_event }, { NULL, 0 } }; int keyword_nbr; /* If we got function arguments, use those, else prompt the user */ if (args && strused (args)) { strncpy (input_line, args, LINE_MAX); input_line [LINE_MAX] = '\0'; /* Ensure delimited, if looong */ args = "exit"; /* Next time treat as Exit */ } else { /* Show upmc prompt and wait for user command */ printf ("upmc> "); fflush (stdout); if (fgets (input_line, LINE_MAX, stdin) == NULL) strclr (input_line); /* Treat EOF as empty */ } if (token_list) tok_free (token_list); token_list = tok_split (input_line); /* Get event corresponding to user command */ if (token_list [0] && *token_list [0]) { the_next_event = error_event; strupc (token_list [0]); for (keyword_nbr = 0; keywords [keyword_nbr].name; keyword_nbr++) if (streq (token_list [0], keywords [keyword_nbr].name)) { the_next_event = keywords [keyword_nbr].event; break; } } else the_next_event = empty_event; }
void add_host_line_in_cache (char *line) { char **host_list, *ip_value; SYMBOL *symbol; int index, list_size; host_list = tok_split (line); if (host_list) { list_size = tok_size (host_list); if (list_size >= 2) { ip_value = host_list [0]; for (index = 1; index < list_size && *host_list [index] != '#'; index++) { symbol = sym_lookup_symbol (cache_table, host_list [index]); if (symbol == NULL) { symbol = sym_assume_symbol (cache_table, host_list [index], ip_value); if (symbol) { symbol-> data = mem_alloc (sizeof (long)); if (symbol-> data) *(long *)symbol-> data = -1; } } } } tok_free (host_list); } }
MODULE load_host_file_in_cache (THREAD *thread) { /* Load content of host file into cache table. Skip comment line * beginning with '#' character. The search key in the cache is the * host name, which is a unique value. */ FILE *f_host; Bool read_line = TRUE; char **host_list, *p_char, *ip_value; SYMBOL *symbol; int index, list_size; tcb = thread-> tcb; /* Point to thread's context */ f_host = file_open (get_host_file (), 'r'); if (f_host == NULL) return; read_line = file_read (f_host, buffer); while (read_line) { p_char = strskp (buffer); if (*p_char != '#') { host_list = tok_split (p_char); if (host_list) { list_size = tok_size (host_list); if (list_size >= 2) { ip_value = host_list [0]; for (index = 1; index < list_size && *host_list [index] != '#'; index++) { symbol = sym_assume_symbol ( cache_table, host_list [index], ip_value); if (symbol) { symbol-> data = mem_alloc (sizeof (long)); if (symbol-> data) *(long *)symbol-> data = -1; } } } tok_free (host_list); } } read_line = file_read (f_host, buffer); } file_close (f_host); }
static void parse_slot_specifier (THREAD *thread, SPEC *spec) { int day, /* Specifier is weekday */ time_nbr, /* Index into spec_list */ time_from, /* Start and end of range */ time_to; /* of minutes for specifier */ long date, /* Converted date value */ time; /* Converted time value */ Bool use_spec; /* Do we want this specifier? */ char **spec_list, /* Broken-up specifier list */ *time_ptr; /* Delimiter in specifier */ tcb = thread-> tcb; /* Point to thread's context */ spec_list = tok_split (spec-> times); day = conv_str_day (spec_list [0]); if (day != -1) use_spec = (day == day_of_week (tcb-> today)); else { /* Try to parse date as YY/MM/DD */ date = conv_str_date (spec_list [0], 0, DATE_YMD_DELIM, DATE_ORDER_YMD); if (date == 0) { /* If that fails, try as MM/DD */ date = conv_str_date (spec_list [0], 0, DATE_MD_DELIM, DATE_ORDER_YMD); if (date > 0) /* Add in current century/year */ date += (tcb-> today % 10000L) * 10000L; } use_spec = (date == tcb-> today); } /* If specification matches today, parse the specifier */ if (use_spec) { for (time_nbr = 1; spec_list [time_nbr]; time_nbr++) { /* We expect either "off" or a time range specification */ if (streq (spec_list [time_nbr], "off")) { day_range_empty (tcb-> range); continue; } /* Split string at hyphen; if not found, means single minute */ time_ptr = strchr (spec_list [time_nbr], '-'); if (time_ptr) *time_ptr++ = '\0'; /* Split the string into 2 pieces */ else /* Or parse the same string twice */ time_ptr = spec_list [time_nbr]; time = conv_str_time (spec_list [time_nbr]); if (time <= 0) continue; /* Invalid or empty time */ time_from = time_to_min (time); time = conv_str_time (time_ptr); if (time <= 0) continue; /* Invalid or empty time */ time_to = time_to_min (time); day_slot_set (tcb-> range, time_from, time_to); } } tok_free (spec_list); }
static void point_in_map_element (char *line, char *return_url, int point_x, int point_y, char *default_url) { char **tokens, /* Line split into tokens */ *map_type, /* Element type name */ *map_url, /* Element URL value */ *comma; /* Split x,y at comma */ FPOINT click_point, /* Request point */ shape_points [MAP_MAX_POINTS]; /* Array of element point */ int token_nbr, /* Index into token array */ nbr_points; /* Number of points in element */ /* Store selected point in image */ click_point.x = (double) point_x; click_point.y = (double) point_y; /* Now parse the map file line into space-delimited tokens */ tokens = tok_split (line); /* Ignore anything which is unparsable */ if (tokens [0] == NULL || tokens [1] == NULL) { tok_free (tokens); /* Release memory */ return; } /* First token is image element type; second is the URL */ map_type = strlwc (tokens [0]); map_url = tokens [1]; /* Third to n tokens are x,y pairs... */ token_nbr = 2; for (nbr_points = 0; nbr_points < MAP_MAX_POINTS; nbr_points++) { if (!tokens [token_nbr]) break; /* Null token => finished */ comma = strchr (tokens [token_nbr], ','); if (!comma) break; /* Syntax error in line => quit */ *comma = '\0'; /* Else break into separate x & y */ shape_points [nbr_points].x = atof (tokens [token_nbr]); shape_points [nbr_points].y = atof (comma + 1); token_nbr++; /* Bump to next token */ } /* Check element type and test the request point */ if (streq (map_type, "poly")) { if (point_in_poly (&click_point, shape_points, nbr_points)) strcpy (return_url, map_url); } else if (streq (map_type, "circle")) { if (point_in_circle (&click_point, shape_points)) strcpy (return_url, map_url); } else if (streq (map_type, "rect")) { if (point_in_rect (&click_point, shape_points)) strcpy (return_url, map_url); } else if (streq (map_type, "point")) { double dist; dist = ((click_point.x - shape_points [0].x) * (click_point.x - shape_points [0].x)) + ((click_point.y - shape_points [0].y) * (click_point.y - shape_points [0].y)); if (dist < 10) strcpy (return_url, map_url); } else if (streq (map_type, "default")) strcpy (default_url, map_url); tok_free (tokens); /* Release memory */ }