/** * HOW TO USE THIS SHIT CODE? SEE BELOW! */ int main() { column c1,c2,c3, c4; column* cols; header h1; line l1; strncpy(c1.name, "struct member", 80); strncpy(c2.name, "Description", 80); strncpy(c3.name, "Value", 80); strncpy(c4.name, "Offset", 80); c1.size = c3.size = c4.size = 0; c2.size = 0; h1.n_col = 4; cols = malloc(4 * sizeof(column)); cols[0] = c1; cols[1] = c2; cols[2] = c3; cols[3] = c4; h1.col = cols; print_table_header(&h1, 0, 80); l1.n_col = 4; l1.col = cols; print_table_line(&l1, 0, 80); free(h1.col); return 0; }
/* * Print a table of the names */ static void print_name_table(FILE *output, char *type, char *key, char *code_page, int n, int use_strings) { int i; print_table_header(output, NAME_TABLE_T, type, key, code_page, n); for (i=0; i < n; i++) { if (use_strings) { fprintf(output, "\t%d,\n", sorted_indexes[i]); } else { fprintf(output, "\t0,\n"); } } fprintf(output, "};\n"); }
/* ----------------------------------------------------------------------- ** Print the table of tokens and names - sorted by token Also create a list of the items, sorted by name ** ----------------------------------------------------------------------- **/ static void print_token_table(FILE *output, FILE* outputHeader, char *type, char *key, char *code_page, int n, int use_strings) { static char tagTypeString[MAX_TYPE_NAME]; static char tokenTypeString[MAX_TYPE_NAME]; /* Must first sort by token */ int i, j; char *tmp_token; char *tmp_name; char *tagType = &tagTypeString[0]; if (strcmp("tag", type) == 0) { (void)sprintf(tagTypeString, ELEMENT_T, dict_name); (void)sprintf(tokenTypeString, ELEMENT_TOKEN_T, dict_name); } else if (strcmp("attribute", type) == 0) { (void)sprintf(tagTypeString, ATTRIBUTE_T, dict_name); (void)sprintf(tokenTypeString, ATTRIBUTE_TOKEN_T, dict_name); } else { fprintf(stderr, "ERROR: internal error\n"); exit_error(1); } /* make all the tokens lower case */ for (i=0; i < n; i++) { int l = (int)strlen(tokens[i]); if (l != 4) { fprintf(stderr, "ERROR: Badly formatted token %s\n" "All token values must be in the form 0x?? (e.g., 0x07) " "or the sorting algorithm won't work.\n" , tokens[i]); exit_error(1); } for (j=0; j < l; j++) { if (isupper(tokens[i][j])) { tokens[i][j] = (char)tolower(tokens[i][j]); } if ((tokens[i][j] != 'x') && isalpha(tokens[i][j])) { if ((tokens[i][j] < 'a') || (tokens[i][j] > 'f')) { fprintf(stderr, "ERROR: Illegal hex digit in token %s\n" , tokens[i]); exit_error(1); } } } } for (i=0; i < n-1; i++) { for (j=0; j < n-1; j++) { /* * Sort by token */ if ((strcmp(tokens[j], tokens[j+1])) > 0) { /* Swap the two elements */ tmp_token = tokens[j]; tmp_name = names[j]; tokens[j] = tokens[j+1]; names[j] = names[j+1]; tokens[j+1] = tmp_token; names[j+1] = tmp_name; } } } /* * print variables */ fprintf(output, "\n"); for (i=0; i < n; i++) { char tempName[MAX_NAME+1]; int l; if (isdigit(names[i][0])) { tempName[0] = '_'; strcpy(tempName+1, names[i]); } else { strcpy(tempName, names[i]); } l = (int)strlen(tempName); for (j = 0; j < l; j++) { if (isdigit(tempName[j]) || isalpha(tempName[j]) || (tempName[j] == '_')) { continue; } tempName[j] = '_'; } if (use_strings) { fprintf(output, "static const NW_Ucs2 %sTag_%s[] = {" , tagType, tempName); for (j=0; j < (int) strlen(names[i]); j++) { if (names[i][j] == '\\') { fprintf(output, "\'\\\\\',"); } else { fprintf(output, "\'%c\',", names[i][j]); } } fprintf(output, "\'\\0\'};\n"); } } if (!use_strings) { fprintf(output, "static const NW_Ucs2 %sTag_emptyString_%s[] = { \'\\0\' };\n" , tagType, code_page); } fprintf(output, "\n"); print_table_header(output, TOKEN_TABLE_T, type, key, code_page, n); if (use_strings) { fprintf(outputHeader, "\ntypedef enum %sToken_%s_e{\n", tagType, code_page); } /* * Print the table */ for (i=0; i < n; i++) { char tempName[MAX_NAME+1] ; char tempToken[6] ; char *token; int l; if (isdigit(names[i][0])) { tempName[0] = '_'; strcpy(tempName+1, names[i]); } else { strcpy(tempName, names[i]); } l = (int)strlen(tempName); for (j = 0; j < l; j++) { if (isdigit(tempName[j]) || isalpha(tempName[j]) || (tempName[j] == '_')) { continue; } tempName[j] = '_'; } strcpy(tempToken, tokens[i]); token = strchr(tempToken, 'x'); token++; if (use_strings) { fprintf(output, "\t{%s, (%s *) %sTag_%s", tokens[i], NAMES_T, tagType, tempName); fprintf(outputHeader, "\t%s_%s = 0x0%s%s", tokenTypeString, tempName, code_page, token); } else { fprintf(output, "\t{%s, &%sTag_emptyString_%s", tokens[i], tagType, code_page); } if (i == (n-1)) { fprintf(output, "}\n"); if (use_strings) { fprintf(outputHeader, "\n"); } } else { fprintf(output, "},\n"); if (use_strings) { fprintf(outputHeader, ",\n"); } } } fprintf(output, "};\n\n"); if (use_strings) { fprintf(outputHeader, "}%sToken_%s_t;\n\n", tagType, code_page); } if (use_strings) { /* * Create an array of the names sorted by index */ for (i=0; i < n-1; i++) { for (j=0; j < n-1; j++) { /* * Since we will need an array of the names sorted by index, * generate that arrary now. */ if ((strcmp(names[j], names[j+1])) > 0) { /* Swap the two names */ int tmp_token; tmp_name = names[j]; tmp_token = sorted_indexes[j]; names[j] = names[j+1]; names[j+1] = tmp_name; sorted_indexes[j] = sorted_indexes[j+1]; sorted_indexes[j+1] = tmp_token; } } } } }
int main(int argc, char **argv) { struct time_type time; ZOOM_connection *z; ZOOM_resultset *r; int *elc; struct event_line_t *els; ZOOM_options o; int i; int k; init_statics(); read_params(argc, argv, ¶meters); z = (ZOOM_connection *) xmalloc(sizeof(*z) * parameters.concurrent); r = (ZOOM_resultset *) xmalloc(sizeof(*r) * parameters.concurrent); elc = (int *) xmalloc(sizeof(*elc) * parameters.concurrent * parameters.repeat); els = (struct event_line_t *) xmalloc( sizeof(*els) * parameters.concurrent * parameters.repeat * 10); o = ZOOM_options_create(); /* async mode */ ZOOM_options_set (o, "async", "1"); /* get first record of result set (using piggypack) */ if (parameters.piggypack) ZOOM_options_set (o, "count", "1"); /* set proxy */ if (strlen(parameters.proxy)) ZOOM_options_set (o, "proxy", parameters.proxy); /* preferred record syntax */ if (0){ ZOOM_options_set (o, "preferredRecordSyntax", "usmarc"); ZOOM_options_set (o, "elementSetName", "F"); } time_init(&time); /* repeat loop */ for (k = 0; k < parameters.repeat; k++){ /* progress zeroing */ for (i = 0; i < 4096; i++){ parameters.progress[i] = k * 5 -1; } /* connect to all concurrent connections*/ for ( i = 0; i < parameters.concurrent; i++){ /* set event count to zero */ elc[k * parameters.concurrent + i] = 0; /* create connection - pass options (they are the same for all) */ z[i] = ZOOM_connection_create(o); /* connect and init */ ZOOM_connection_connect(z[i], parameters.host, 0); } /* search all */ for (i = 0; i < parameters.concurrent; i++) r[i] = ZOOM_connection_search_pqf (z[i], parameters.query); /* network I/O. pass number of connections and array of connections */ while ((i = ZOOM_event (parameters.concurrent, z))){ int event = ZOOM_connection_last_event(z[i-1]); const char *errmsg; const char *addinfo; int error = 0; //int progress = zoom_progress[event]; if (event == ZOOM_EVENT_SEND_DATA || event == ZOOM_EVENT_RECV_DATA) continue; time_stamp(&time); /* updating events and event list */ error = ZOOM_connection_error(z[i-1] , &errmsg, &addinfo); if (error) parameters.progress[i] = zoom_progress[ZOOM_EVENT_UNKNOWN]; //parameters.progress[i] = zoom_progress[ZOOM_EVENT_NONE]; else if (event == ZOOM_EVENT_CONNECT) parameters.progress[i] = zoom_progress[event]; else //parameters.progress[i] = zoom_progress[event]; parameters.progress[i] += 1; update_events(elc, els, k, i-1, time_sec(&time), time_usec(&time), parameters.progress[i], event, zoom_events[event], error, errmsg); } /* destroy connections */ for (i = 0; i<parameters.concurrent; i++) { ZOOM_resultset_destroy (r[i]); ZOOM_connection_destroy (z[i]); } } /* for (k = 0; k < parameters.repeat; k++) repeat loop */ /* output */ if (parameters.gnuplot){ printf("# gnuplot data and instruction file \n"); printf("# gnuplot thisfile \n"); printf("\n"); printf("set title \"Z39.50 connection plot\"\n"); printf("set xlabel \"Connection\"\n"); printf("set ylabel \"Time Seconds\"\n"); printf("set zlabel \"Progress\"\n"); printf("set ticslevel 0\n"); printf("set grid\n"); printf("set pm3d\n"); printf("splot '-' using ($1):($2):($3) t '' with points\n"); printf("\n"); printf("\n"); } print_table_header(); print_events(elc, els, parameters.concurrent); if (parameters.gnuplot){ printf("end\n"); printf("pause -1 \"Hit ENTER to return\"\n"); } /* destroy data structures and exit */ xfree(z); xfree(r); xfree(elc); xfree(els); ZOOM_options_destroy(o); exit (0); }