static void print_tag(tag_t *tag, char *name) { tag_t *base; tag_t *temp; record_t *record; if (tag->type & type_unsigned) printf("unsigned"); else if (tag->type & type_struct) printf("struct"); else if (tag->type & type_union) printf("union"); for (base = tag; base->tag; base = base->tag) ; record = base->name; if (record->name) { if (tag->type & (type_unsigned | type_struct | type_union)) putchar(' '); printf("%s", record->name->name.string); } if ((tag->type & type_struct) || (tag->type & type_union)) print_fields(record); for (temp = tag; temp != base; temp = temp->tag) if (type_mask(temp->type) != type_vector) printf(" %s", (char *)temp->name); if (name) printf(" %s", name); for (temp = tag; temp != base; temp = temp->tag) if (type_mask(temp->type) == type_vector) printf(" [ %s ]", (char *)temp->name); }
/* print a struct */ void print_struct(Struct *s) { fppush(); printf("Type: %d\nDataOrDataOffset: %d\nField Count: %d\n", s->Type, s->DataOrDataOffset, s->FieldCount); print_fields(s); fppop(); }
gboolean print_dhcp6_config (NMDHCP6Config *dhcp6, NmCli *nmc, const char *group_prefix) { GHashTable *table; guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; if (dhcp6 == NULL) return FALSE; table = nm_dhcp6_config_get_options (dhcp6); if (table) { GHashTableIter table_iter; gpointer key, value; char **options_arr = NULL; int i = 0; nmc->allowed_fields = nmc_fields_dhcp6_config; nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DHCP6_CONFIG_ALL, nmc->allowed_fields, NULL); print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ options_arr = g_new (char *, g_hash_table_size (table) + 1); g_hash_table_iter_init (&table_iter, table); while (g_hash_table_iter_next (&table_iter, &key, &value)) options_arr[i++] = g_strdup_printf ("%s = %s", (char *) key, (char *) value); options_arr[i] = NULL; set_val_str (nmc->allowed_fields, 0, group_prefix); set_val_arr (nmc->allowed_fields, 1, (const char **) options_arr); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ g_strfreev (options_arr); return TRUE; } return FALSE; }
void cpp_idt::print(std::ostream &out, unsigned indent) const { print_fields(out, indent); if(!sub.empty()) { for(cpp_id_mapt::const_iterator it=sub.begin(); it!=sub.end(); it++) it->second.print(out, indent+2); out << std::endl; } }
int main() { FILE *fp = NULL; char *line1 = NULL; char *lines = NULL; char line[LINE_SIZE]; int len = 0; char *tap = NULL; int offset = 0; int st_index = 0; int halt_index = 0; char *st_info = NULL; int read = 0; int file_offset = 0; int total_bytes = 0; fp = fopen("file.txt", "r"); fgets(line, 10, fp); chomp_new_line(line, &len); tap = malloc(sizeof(char) * len); strncpy(tap, line, len); printf("Tape: %s\n", tap); fgets(line, 10, fp); offset = atoi(line); printf("Offset: %d\n", offset); fgets(line, 10, fp); st_index = atoi(line); printf("Start Index: %d\n", st_index); fgets(line, 10, fp); halt_index = atoi(line); printf("Halt Index: %d\n", halt_index); file_offset = ftell(fp); fseek(fp, 0, SEEK_END); total_bytes = ftell(fp); total_bytes = total_bytes - file_offset; fseek(fp, file_offset, SEEK_SET); lines = malloc(sizeof(char) * total_bytes); fread(lines, 1, total_bytes, fp); printf("%s ", lines); line1 = strtok(lines, "\n"); while (line1) { print_fields(line1); line1 = strtok(NULL, "\n"); } }
int main() { char* tests[] = { "hello", "field1,field2", ",f", "", ",,,,", NULL }; int i; for(i = 0; tests[i] != NULL; i++) { printf("split('%s') -> ", tests[i]); // you need the strdup since we modify the string in place int nf = split_csv(strdup(tests[i])); printf("%d fields\n", nf); print_fields(); } }
int _do_stat(uint32_t jobid, uint32_t stepid, char *nodelist, uint32_t req_cpufreq) { job_step_stat_response_msg_t *step_stat_response = NULL; int rc = SLURM_SUCCESS; ListIterator itr; slurmdb_stats_t temp_stats; job_step_stat_t *step_stat = NULL; int ntasks = 0; int tot_tasks = 0; hostlist_t hl = NULL; debug("requesting info for job %u.%u", jobid, stepid); if ((rc = slurm_job_step_stat(jobid, stepid, nodelist, &step_stat_response)) != SLURM_SUCCESS) { if (rc == ESLURM_INVALID_JOB_ID) { debug("job step %u.%u has already completed", jobid, stepid); } else { error("problem getting step_layout for %u.%u: %s", jobid, stepid, slurm_strerror(rc)); } return rc; } memset(&job, 0, sizeof(slurmdb_job_rec_t)); job.jobid = jobid; memset(&step, 0, sizeof(slurmdb_step_rec_t)); memset(&temp_stats, 0, sizeof(slurmdb_stats_t)); temp_stats.cpu_min = NO_VAL; memset(&step.stats, 0, sizeof(slurmdb_stats_t)); step.stats.cpu_min = NO_VAL; step.job_ptr = &job; step.stepid = stepid; step.nodes = xmalloc(BUF_SIZE); step.req_cpufreq = req_cpufreq; step.stepname = NULL; step.state = JOB_RUNNING; hl = hostlist_create(NULL); itr = list_iterator_create(step_stat_response->stats_list); while ((step_stat = list_next(itr))) { if (!step_stat->step_pids || !step_stat->step_pids->node_name) continue; if (step_stat->step_pids->pid_cnt > 0 ) { int i; for(i=0; i<step_stat->step_pids->pid_cnt; i++) { if (step.pid_str) xstrcat(step.pid_str, ","); xstrfmtcat(step.pid_str, "%u", step_stat->step_pids->pid[i]); } } if (params.pid_format) { step.nodes = step_stat->step_pids->node_name; print_fields(&step); xfree(step.pid_str); } else { hostlist_push(hl, step_stat->step_pids->node_name); jobacctinfo_2_stats(&temp_stats, step_stat->jobacct); ntasks += step_stat->num_tasks; aggregate_stats(&step.stats, &temp_stats); } } list_iterator_destroy(itr); slurm_job_step_pids_response_msg_free(step_stat_response); /* we printed it out already */ if (params.pid_format) return rc; hostlist_sort(hl); hostlist_ranged_string(hl, BUF_SIZE, step.nodes); hostlist_destroy(hl); tot_tasks += ntasks; if (tot_tasks) { step.stats.cpu_ave /= (double)tot_tasks; step.stats.rss_ave /= (double)tot_tasks; step.stats.vsize_ave /= (double)tot_tasks; step.stats.pages_ave /= (double)tot_tasks; step.stats.disk_read_ave /= (double)tot_tasks; step.stats.disk_write_ave /= (double)tot_tasks; step.stats.act_cpufreq /= (double)tot_tasks; step.ntasks = tot_tasks; } print_fields(&step); return rc; }
gboolean print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix) { GSList *list, *iter; const GArray *array; const GPtrArray *ptr_array; char **addr_arr = NULL; char **route_arr = NULL; char **dns_arr = NULL; char **domain_arr = NULL; char **wins_arr = NULL; int i = 0; guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0; guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0; guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0; if (cfg4 == NULL) return FALSE; nmc->allowed_fields = nmc_fields_ip4_config; nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES; nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_IP4_CONFIG_ALL, nmc->allowed_fields, NULL); print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */ /* addresses */ list = (GSList *) nm_ip4_config_get_addresses (cfg4); addr_arr = g_new (char *, g_slist_length (list) + 1); for (iter = list; iter; iter = g_slist_next (iter)) { NMIP4Address *addr = (NMIP4Address *) iter->data; guint32 prefix; char *ip_str, *gw_str; ip_str = nmc_ip4_address_as_string (nm_ip4_address_get_address (addr), NULL); prefix = nm_ip4_address_get_prefix (addr); gw_str = nmc_ip4_address_as_string (nm_ip4_address_get_gateway (addr), NULL); addr_arr[i++] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str); g_free (ip_str); g_free (gw_str); } addr_arr[i] = NULL; /* routes */ list = (GSList *) nm_ip4_config_get_routes (cfg4); route_arr = g_new (char *, g_slist_length (list) + 1); i = 0; for (iter = list; iter; iter = g_slist_next (iter)) { NMIP4Route *route = (NMIP4Route *) iter->data; guint32 prefix, metric; char *dest_str, *nexthop_str; dest_str = nmc_ip4_address_as_string (nm_ip4_route_get_dest (route), NULL); nexthop_str = nmc_ip4_address_as_string (nm_ip4_route_get_next_hop (route), NULL); prefix = nm_ip4_route_get_prefix (route); metric = nm_ip4_route_get_metric (route); route_arr[i++] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric); g_free (dest_str); g_free (nexthop_str); } route_arr[i] = NULL; /* DNS */ array = nm_ip4_config_get_nameservers (cfg4); if (array) { dns_arr = g_new (char *, array->len + 1); for (i = 0; i < array->len; i++) dns_arr[i] = nmc_ip4_address_as_string (g_array_index (array, guint32, i), NULL); dns_arr[i] = NULL; } /* domains */ ptr_array = nm_ip4_config_get_domains (cfg4); if (ptr_array) { domain_arr = g_new (char *, ptr_array->len + 1); for (i = 0; i < ptr_array->len; i++) domain_arr[i] = g_ptr_array_index (ptr_array, i); domain_arr[i] = NULL; } /* WINS */ array = nm_ip4_config_get_wins_servers (cfg4); if (array) { wins_arr = g_new (char *, array->len + 1); for (i = 0; i < array->len; i++) wins_arr[i] = nmc_ip4_address_as_string (g_array_index (array, guint32, i), NULL); wins_arr[i] = NULL; } set_val_str (nmc->allowed_fields, 0, group_prefix); set_val_arr (nmc->allowed_fields, 1, (const char **) addr_arr); set_val_arr (nmc->allowed_fields, 2, (const char **) route_arr); set_val_arr (nmc->allowed_fields, 3, (const char **) dns_arr); set_val_arr (nmc->allowed_fields, 4, (const char **) domain_arr); set_val_arr (nmc->allowed_fields, 5, (const char **) wins_arr); nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX; print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */ g_strfreev (addr_arr); g_strfreev (route_arr); g_strfreev (dns_arr); g_free (domain_arr); g_strfreev (wins_arr); return TRUE; }
void cmd_ls(struct fcrondyn_cl *client, long int *cmd, int fd, int is_root) /* run a command which lists some jobs */ { int found = 0; int all = (cmd[1] == ALL) ? 1 : 0; char *user = NULL; struct job_t *j; int i; unsigned char fields[FIELD_NUM_SIZE]; for (i = 0; i < FIELD_NUM_SIZE; i++) fields[i] = 0; switch ( cmd[0] ) { case CMD_DETAILS: bit_set(fields, FIELD_SCHEDULE); bit_set(fields, FIELD_RQ); bit_set(fields, FIELD_USER); bit_set(fields, FIELD_OPTIONS); print_fields(fd, fields); for ( j = queue_base; j != NULL; j = j->j_next ) { if ( cmd[1] == j->j_line->cl_id ) { if (strcmp(client->fcl_user, j->j_line->cl_file->cf_user) == 0 || is_root ) print_line(fd, j->j_line, fields, 0, 0, 0); else Send_err_msg(fd, err_job_nallowed_str); found = 1; break; } } break; case CMD_LIST_JOBS: case CMD_LIST_LAVGQ: case CMD_LIST_SERIALQ: case CMD_LIST_EXEQ: if ( cmd[0] == CMD_LIST_LAVGQ ) { double lavg[3] = {0, 0, 0}; char lavg_str[TERM_LEN]; getloadavg(lavg, 3); i = snprintf(lavg_str, sizeof(lavg_str), "Current load average : " "%.1f, %.1f, %.1f\n", lavg[0], lavg[1], lavg[2]); send(fd, lavg_str, i, 0); bit_set(fields, FIELD_LAVG); } else bit_set(fields, FIELD_SCHEDULE); if ( cmd[0] == CMD_LIST_SERIALQ ) bit_set(fields, FIELD_INDEX); if ( cmd[0] == CMD_LIST_EXEQ ) bit_set(fields, FIELD_PID); if ( all && ! is_root) { warn("User %s tried to list *all* jobs.", client->fcl_user); Send_err_msg_end(fd, err_all_nallowed_str); } if ( all ) bit_set(fields, FIELD_USER); print_fields(fd, fields); if (! all) { struct passwd *pass; #ifdef SYSFCRONTAB if ( cmd[1] == SYSFCRONTAB_UID ) user = SYSFCRONTAB; else { #endif if ( (pass = getpwuid( (uid_t) cmd[1] )) == NULL ) { warn_e("Unable to find passwd entry for %ld", cmd[1]); Send_err_msg_end(fd, err_invalid_user_str); } if ( ! is_root && strcmp(pass->pw_name, client->fcl_user) != 0 ) { warn_e("%s is not allowed to see %s's jobs. %ld", client->fcl_user, pass->pw_name); Send_err_msg_end(fd, err_others_nallowed_str); } user = pass->pw_name; #ifdef SYSFCRONTAB } #endif } /* list all jobs one by one and find the corresponding ones */ switch ( cmd[0] ) { case CMD_LIST_JOBS: for ( j = queue_base; j != NULL; j = j->j_next ) Test_line(j->j_line, 0, 0, 0); break; case CMD_LIST_EXEQ: for ( i = 0; i < exe_num; i++) Test_line(exe_array[i].e_line, exe_array[i].e_job_pid, 0, 0); break; case CMD_LIST_LAVGQ: for ( i = 0; i < lavg_num; i++) Test_line(lavg_array[i].l_line, 0, 0, lavg_array[i].l_until); break; case CMD_LIST_SERIALQ: { int j; i = serial_array_index; for ( j = 0; j < serial_num; j++ ) { Test_line(serial_array[i], 0, j, 0); if ( ++i >= serial_array_size ) i -= serial_array_size; } break; } } break; } if ( ! found ) Send_err_msg(fd, err_job_nfound_str); /* to tell fcrondyn there's no more data to wait */ Tell_no_more_data(fd); }