// Function main - execution starts here int main(void) { size_t pS_size = INIT_NSTR; // count of pS elements char **pS = calloc(pS_size, sizeof(char*)); // Array of string pointers if(!pS) { printf("Failed to allocate memory for string pointers.\n"); exit(1); } char **pTemp = NULL; // Temporary pointer size_t str_count = 0; // Number of strings read char *pStr = NULL; // String pointer printf("Enter one string per line. Press Enter to end:\n"); while((pStr = str_in()) != NULL) { if(str_count == pS_size) { pS_size += NSTR_INCR; if(!(pTemp = realloc(pS, pS_size*sizeof(char*)))) { printf("Memory allocation for array of strings failed.\n"); return 2; } pS = pTemp; } pS[str_count++] = pStr; } str_sort(pS, str_count); // Sort strings str_out(pS, str_count); // Output strings free_memory(pS, str_count); // Free all heap memory return 0; }
int main(int argc,char** argv) { char *pS[NUMP]; int count=0; printf("\nEnter successive lines, pressing Enter at at the end of" " each line.\nJust press Enter to end.\n"); for(count = 0; count < NUMP; count ++) if(!str_in(&pS[count])) break; str_sort(pS,count); str_out(pS,count); return 0; }
/* Function main - execution starts here */ int main(void) { char *pS[NUM_P]; /* Array of string pointers */ int count = 0; /* Number of strings read */ printf("\nEnter successive lines, pressing Enter at the end of" " each line.\nJust press Enter to end.\n"); for(count = 0; count < NUM_P ; count++) /* Max of NUM_P strings */ if(!str_in(&pS[count])) /* Read a string */ break; /* Stop input on 0 return */ str_sort( pS, count); /* Sort strings */ str_out( pS, count); /* Output strings */ return 0; }
int Test_Bounded_WString::run_sii_test (Param_Test_ptr objref) { try { CORBA::WString_out str_out (this->out_); this->ret_ = objref->test_bounded_wstring (this->in_, this->inout_, str_out); return 0; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Test_Bounded_WString::run_sii_test\n"); } return -1; }
/* Function main */ int main(void) { char *pS[NUM_P]; /* Array of string pointers */ int count = 0; /* Number of strings read */ printf("\nEnter succesive lines, pressing Enter at the end of" " each line.\nJust press Enter to end.\n"); for(count = 0; count < NUM_P; count++) /* Max of NUM_P strings */ if(!str_in(&pS[count])) /* Read a string */ break; /* Stop input on 0 return */ /* * The argument to the function str_in is &pS[i]. This is the address of pS[i] - in other words, a pointer to pS[i]. * And pS[i] is a pointer to char. Hence the argument type for that function is to be declared as char**. * In this case we want to modify the contents of the elements of pS, so if we used one "*" in the parameter type * definition, instead and just used pS[i] as the argument, the function receives whatever is contained in pS[i] * which is a memory address. * * Because all the work is done in the str_in() function, all that's necessary here is to continue the loop until you * get false returned from the function, which will cause the break to be executed, or until you fill up the pointer * array pS, which is indicated by count reaching the value NUM_P, thus ending the loop. The loop also counts how many * strings are entered in count. */ str_sort(pS, count); /* * Having safely stored all the strings, main() then calls the function str_sort() to sort the strings. The first * argument is the array name, pS, so the address of the first location of the array is transferred to the function. * The second argument is the count of the number of strings so the function will know how many there are to be * sorted. */ str_out(pS, count); return 0; }
/* -- write heading with format -- */ static void write_headform(float lwidth) { char *p, *q; struct SYMBOL *s; struct FONTSPEC *f; int align, i, j; float x, y, xa[3], ya[3], sz, yb[3]; char inf_nb[26]; INFO inf_s; char inf_ft[26]; float inf_sz[26]; char fmt[64]; memset(inf_nb, 0, sizeof inf_nb); memset(inf_ft, HISTORYFONT, sizeof inf_ft); inf_ft['A' - 'A'] = INFOFONT; inf_ft['C' - 'A'] = COMPOSERFONT; inf_ft['O' - 'A'] = COMPOSERFONT; inf_ft['P' - 'A'] = PARTSFONT; inf_ft['Q' - 'A'] = TEMPOFONT; inf_ft['R' - 'A'] = INFOFONT; inf_ft['T' - 'A'] = TITLEFONT; inf_ft['X' - 'A'] = TITLEFONT; memcpy(inf_s, info, sizeof inf_s); memset(inf_sz, 0, sizeof inf_sz); inf_sz['A' - 'A'] = cfmt.infospace; inf_sz['C' - 'A'] = cfmt.composerspace; inf_sz['O' - 'A'] = cfmt.composerspace; inf_sz['R' - 'A'] = cfmt.infospace; p = cfmt.titleformat; j = 0; for (;;) { while (isspace((unsigned char) *p)) p++; if (*p == '\0') break; i = *p - 'A'; if ((unsigned) i < 26) { inf_nb[i]++; switch (p[1]) { default: align = A_CENTER; break; case '1': align = A_RIGHT; p++; break; case '-': align = A_LEFT; p++; break; } if (j < sizeof fmt - 4) { fmt[j++] = i; fmt[j++] = align; } } else if (*p == ',') { if (j < sizeof fmt - 3) fmt[j++] = 126; /* next line */ } else if (*p == '+') { if (j > 0 && fmt[j - 1] < 125 && j < sizeof fmt - 3) fmt[j++] = 125; /* concatenate */ /*new fixme: add free text "..." ?*/ } p++; } fmt[j++] = 126; /* newline */ fmt[j] = 127; /* end of format */ ya[0] = ya[1] = ya[2] = cfmt.titlespace;; xa[0] = 0; xa[1] = lwidth * 0.5; xa[2] = lwidth; p = fmt; for (;;) { yb[0] = yb[1] = yb[2] = y = 0; q = p; for (;;) { i = *q++; if (i >= 126) /* if newline */ break; align = *q++; if (yb[align + 1] != 0) continue; s = inf_s[i]; if (s == 0 || inf_nb[i] == 0) continue; j = inf_ft[i]; f = &cfmt.font_tb[j]; sz = f->size * 1.1 + inf_sz[i]; if (y < sz) y = sz; yb[align + 1] = sz; /*fixme:should count the height of the concatenated field*/ if (*q == 125) q++; } for (i = 0; i < 3; i++) ya[i] += y - yb[i]; for (;;) { i = *p++; if (i >= 126) /* if newline */ break; align = *p++; s = inf_s[i]; if (s == 0 || inf_nb[i] == 0) continue; j = inf_ft[i]; str_font(j); x = xa[align + 1]; f = &cfmt.font_tb[j]; sz = f->size * 1.1 + inf_sz[i]; y = ya[align + 1] + sz; PUT2("%.1f %.1f M ", x, -y); if (*p == 125) { /* concatenate */ p++; /*fixme: do it work with different fields*/ if (*p == i && p[1] == align && s->next != 0) { char buf[256], *r; q = s->as.text; if (q[1] == ':') q += 2; while (isspace((unsigned char) *q)) q++; if (i == 'T' - 'A') q = trim_title(q, s == inf_s['T' - 'A']); strncpy(buf, q, sizeof buf - 1); buf[sizeof buf - 1] = '\0'; j = strlen(buf); if (j < sizeof buf - 1) { buf[j] = ' '; buf[j + 1] = '\0'; } s = s->next; q = s->as.text; if (q[1] == ':') q += 2; while (isspace((unsigned char) *q)) q++; if (s->as.text[0] == 'T' && s->as.text[1] == ':') q = trim_title(q, 0); r = buf + strlen(buf); strncpy(r, q, buf + sizeof buf - r - 1); tex_str(buf); str_out(tex_buf, align); PUT0("\n"); inf_nb[i]--; p += 2; } } else if (i == 'Q' - 'A') { /* special case for tempo */ if (align != A_LEFT) { float w; w = tempo_width(s); if (align == A_CENTER) PUT1("-%.1f 0 RM ", w * 0.5); else PUT1("-%.1f 0 RM ", w); } write_tempo(s, 0, 0.75); } else put_inf2r(s, 0, align); if (inf_s[i] == info['T' - 'A']) { inf_ft[i] = SUBTITLEFONT; str_font(SUBTITLEFONT); f = &cfmt.font_tb[SUBTITLEFONT]; inf_sz[i] = cfmt.subtitlespace; sz = f->size * 1.1 + inf_sz[i]; } s = s->next; if (inf_nb[i] == 1) { while (s != 0) { y += sz; PUT2("%.1f %.1f M ", x, -y); put_inf2r(s, 0, align); s = s->next; } } inf_s[i] = s; inf_nb[i]--; ya[align + 1] = y; } if (ya[1] > ya[0]) ya[0] = ya[1]; if (ya[2] > ya[0]) ya[0] = ya[2]; if (*p == 127) { bskip(ya[0]); break; } ya[1] = ya[2] = ya[0]; } }
/* -- output a string with TeX translation -- */ void put_str(char *str, int action) { tex_str(str); str_out(tex_buf, action); PUT0("\n"); }
/* -- output the header or footer -- */ static float headfooter(int header, float pwidth, float pheight) { char tmp[2048], str[TEX_BUF_SZ + 512]; char *p, *q, *r, *outbuf_sav, *mbf_sav; float size, y, wsize; struct FONTSPEC *f, f_sav; int cft_sav, dft_sav, outbufsz_sav; if (header) { p = cfmt.header; f = &cfmt.font_tb[HEADERFONT]; size = f->size; y = -size; } else { p = cfmt.footer; f = &cfmt.font_tb[FOOTERFONT]; size = f->size; y = - (pheight - cfmt.topmargin - cfmt.botmargin) + size; } if (*p == '-') { if (pagenum == 1) return 0; p++; } get_str_font(&cft_sav, &dft_sav); memcpy(&f_sav, &cfmt.font_tb[0], sizeof f_sav); str_font(f - cfmt.font_tb); output(fout, "%.1f F%d ", size, f->fnum); outft = f - cfmt.font_tb; /* may have 2 lines */ wsize = size; if ((r = strstr(p, "\\n")) != NULL) { if (!header) y += size; wsize += size; *r = '\0'; } mbf_sav = mbf; outbuf_sav = outbuf; outbufsz_sav = outbufsz; outbuf = tmp; outbufsz = sizeof tmp; for (;;) { tex_str(p); strcpy(tmp, tex_buf); format_hf(str, tmp); /* left side */ p = str; if ((q = strchr(p, '\t')) != NULL) { if (q != p) { *q = '\0'; output(fout, "%.1f %.1f M ", p_fmt->leftmargin, y); mbf = tmp; str_out(p, A_LEFT); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } p = q + 1; } if ((q = strchr(p, '\t')) != NULL) *q = '\0'; /* center */ if (q != p) { output(fout, "%.1f %.1f M ", pwidth * 0.5, y); mbf = tmp; str_out(p, A_CENTER); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } /* right side */ if (q) { p = q + 1; if (*p != '\0') { output(fout, "%.1f %.1f M ", pwidth - p_fmt->rightmargin, y); mbf = tmp; str_out(p, A_RIGHT); a2b("\n"); if (svg) svg_write(tmp, strlen(tmp)); else fputs(tmp, fout); } } if (!r) break; *r = '\\'; p = r + 2; r = NULL; y -= size; } /* restore the buffer and fonts */ outbuf = outbuf_sav; outbufsz = outbufsz_sav; mbf = mbf_sav; memcpy(&cfmt.font_tb[0], &f_sav, sizeof cfmt.font_tb[0]); set_str_font(cft_sav, dft_sav); return wsize; }