Exemple #1
0
static void text_heading(textfile *tf, word *tprefix, word *nprefix,
			 word *text, alignstruct align,
			 int indent, int width, textconfig *cfg) {
    rdstring t = { 0, 0, NULL };
    int margin, length;
    int firstlinewidth, wrapwidth;
    wrappedline *wrapping, *p;

    if (align.just_numbers && nprefix) {
	text_rdaddw(&t, nprefix, NULL, cfg);
	rdadds(&t, align.number_suffix);
    } else if (!align.just_numbers && tprefix) {
	text_rdaddw(&t, tprefix, NULL, cfg);
	rdadds(&t, align.number_suffix);
    }
    margin = length = ustrwid(t.text ? t.text : L"", cfg->charset);

    if (align.align == LEFTPLUS) {
	margin = indent - margin;
	if (margin < 0) margin = 0;
	firstlinewidth = indent + width - margin - length;
	wrapwidth = width;
    } else if (align.align == LEFT || align.align == CENTRE) {
	margin = 0;
	firstlinewidth = indent + width - length;
	wrapwidth = indent + width;
    }

    wrapping = wrap_para(text, firstlinewidth, wrapwidth,
			 text_width, cfg, 0);
    for (p = wrapping; p; p = p->next) {
	text_rdaddw(&t, p->begin, p->end, cfg);
	length = ustrwid(t.text ? t.text : L"", cfg->charset);
	if (align.align == CENTRE) {
	    margin = (indent + width - length)/2;
	    if (margin < 0) margin = 0;
	}
	text_output_many(tf, margin, L' ');
	text_output(tf, t.text);
	text_output(tf, L"\n");
	if (*align.underline) {
	    text_output_many(tf, margin, L' ');
	    while (length > 0) {
		text_output(tf, align.underline);
		length -= ustrwid(align.underline, cfg->charset);
	    }
	    text_output(tf, L"\n");
	}
	if (align.align == LEFTPLUS)
	    margin = indent;
	else
	    margin = 0;
	sfree(t.text);
	t = empty_rdstring;
    }
    wrap_free(wrapping);
    text_output(tf, L"\n");

    sfree(t.text);
}
Exemple #2
0
static void text_codepara(textfile *tf, word *text, int indent, int width) {
    for (; text; text = text->next) if (text->type == word_WeakCode) {
	int wid = ustrwid(text->text, tf->charset);
	if (wid > width)
	    err_text_codeline(&text->fpos, wid, width);
	text_output_many(tf, indent, L' ');
	text_output(tf, text->text);
	text_output(tf, L"\n");
    }

    text_output(tf, L"\n");
}
Exemple #3
0
static void text_rule(textfile *tf, int indent, int width, textconfig *cfg) {
    text_output_many(tf, indent, L' ');
    while (width > 0) {
	text_output(tf, cfg->rule);
	width -= ustrwid(cfg->rule, cfg->charset);
    }
    text_output_many(tf, 2, L'\n');
}
Exemple #4
0
static void text_output_many(textfile *tf, int n, wchar_t c)
{
    wchar_t s[2];
    s[0] = c;
    s[1] = L'\0';
    while (n-- > 0)
	text_output(tf, s);
}
Exemple #5
0
static void text_para(textfile *tf, word *prefix, wchar_t *prefixextra,
		      word *text, int indent, int extraindent, int width,
		      textconfig *cfg) {
    wrappedline *wrapping, *p;
    rdstring pfx = { 0, 0, NULL };
    int e;
    int firstlinewidth = width;

    if (prefix) {
	text_rdaddw(&pfx, prefix, NULL, cfg);
	if (prefixextra)
	    rdadds(&pfx, prefixextra);
	text_output_many(tf, indent, L' ');
	text_output(tf, pfx.text);
	/* If the prefix is too long, shorten the first line to fit. */
	e = extraindent - ustrwid(pfx.text ? pfx.text : L"", cfg->charset);
	if (e < 0) {
	    firstlinewidth += e;       /* this decreases it, since e < 0 */
	    if (firstlinewidth < 0) {
		e = indent + extraindent;
		firstlinewidth = width;
		text_output(tf, L"\n");
	    } else
		e = 0;
	}
	sfree(pfx.text);
    } else
	e = indent + extraindent;

    wrapping = wrap_para(text, firstlinewidth, width,
			 text_width, cfg, 0);
    for (p = wrapping; p; p = p->next) {
	rdstring t = { 0, 0, NULL };
	text_rdaddw(&t, p->begin, p->end, cfg);
	text_output_many(tf, e, L' ');
	text_output(tf, t.text);
	text_output(tf, L"\n");
	e = indent + extraindent;
	sfree(t.text);
    }
    wrap_free(wrapping);
    text_output(tf, L"\n");
}
Exemple #6
0
static void text_versionid(textfile *tf, word *text, textconfig *cfg) {
    rdstring t = { 0, 0, NULL };

    rdadd(&t, L'[');
    text_rdaddw(&t, text, NULL, cfg);
    rdadd(&t, L']');
    rdadd(&t, L'\n');

    text_output(tf, t.text);
    sfree(t.text);
}
Exemple #7
0
void outtextxy(int x, int y, const char* str)
{
    if (text_align_mode != NOT_UPDATE_CP) {
	text_align_mode = NOT_UPDATE_CP;
	int align = (text_settings.direction == HORIZ_DIR)
	            ? (TA_NOUPDATECP | 
		       text_halign_cnv[text_settings.horiz] | 
		       text_valign_cnv[text_settings.vert])
	            : (TA_NOUPDATECP |
		       text_valign_cnv[text_settings.horiz] | 
		       text_halign_cnv[text_settings.vert]);
	SetTextAlign(hdc[0], align);
	SetTextAlign(hdc[1], align);
    }
    text_output(x, y, str);
}
static abi_diff::CompatibilityStatus MergeDiffReports(
    const std::vector<std::string> &diff_reports,
    const std::string &merged_diff_report) {
  abi_diff::MergedTranslationUnitDiff merged_tu_diff;
  std::ofstream text_output(merged_diff_report);
  google::protobuf::io::OstreamOutputStream text_os(&text_output);
  abi_diff::CompatibilityStatus status =
      abi_diff::CompatibilityStatus::COMPATIBLE;

  for (auto &&i : diff_reports) {
    abi_diff::TranslationUnitDiff diff_tu;
    std::ifstream input(i);
    google::protobuf::io::IstreamInputStream text_is(&input);
    if (!google::protobuf::TextFormat::Parse(&text_is, &diff_tu)) {
      llvm::errs() << "Failed to parse diff report\n";
      ::exit(1);
    }
    abi_diff::ConciseDiffReportInformation *added_tu_diff =
        merged_tu_diff.add_diff_reports();
    if (!added_tu_diff) {
      llvm::errs() << "Failed to add diff report to merged report\n";
      ::exit(1);
    }
    abi_diff::CompatibilityStatus new_status = diff_tu.compatibility_status();
    added_tu_diff->set_lib_name(diff_tu.lib_name());
    added_tu_diff->set_arch(diff_tu.arch());
    added_tu_diff->set_diff_report_path(i);
    added_tu_diff->set_compatibility_status(new_status);
    // Only, if the status is downgraded, change it.
    if (IsStatusDowngraded(status, new_status)) {
      status = new_status;
    }
  }

  if (!google::protobuf::TextFormat::Print(merged_tu_diff, &text_os)) {
    llvm::errs() << "Serialization to ostream failed\n";
    ::exit(1);
  }
  return status;
}
Exemple #9
0
void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
{
    wxTextCtrl& textCtrl = * GetTextCtrl();

    textCtrl.Clear();
    textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");

    textCtrl.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") );

    wxSTD ofstream std_file_output( "test_std.dat" );
    wxFileOutputStream file_output( file_name );
    wxBufferedOutputStream buf_output( file_output );
    wxTextOutputStream text_output( buf_output );

    wxString tmp;
    signed int si = 0xFFFFFFFF;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );
    text_output << si << _T("\n");
    std_file_output << si << "\n";

    unsigned int ui = 0xFFFFFFFF;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );
    text_output << ui << _T("\n");
    std_file_output << ui << "\n";

    double d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    text_output << d << _T("\n");
    std_file_output << d << "\n";

    float f = (float)0.00001;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );
    text_output << f << _T("\n");
    std_file_output << f << "\n";

    wxString str( _T("Hello!") );
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    text_output << str << _T("\n");
    std_file_output << str.ToAscii() << "\n";

    textCtrl.WriteText( _T("\nReading from ifstream:\n") );

    wxSTD ifstream std_file_input( "test_std.dat" );

    std_file_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    std_file_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    std_file_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    std_file_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    char std_buf[200];
    std_file_input >> std_buf;
    str = wxString::FromAscii(std_buf);
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );

    textCtrl.WriteText( _T("\nReading from wxFileInputStream:\n") );

    buf_output.Sync();

    wxFileInputStream file_input( file_name );
    wxBufferedInputStream buf_input( file_input );
    wxTextInputStream text_input( file_input );

    text_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    text_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    text_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    text_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    text_input >> str;
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );



    textCtrl << _T("\nTest for wxDataStream:\n\n");

    textCtrl.WriteText( _T("Writing to wxDataOutputStream:\n") );

    file_output.SeekO( 0 );
    wxDataOutputStream data_output( buf_output );

    wxInt16 i16 = (unsigned short)0xFFFF;
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( i16 );

    wxUint16 ui16 = 0xFFFF;
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( ui16 );

    d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    data_output.WriteDouble( d );

    str = _T("Hello!");
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    data_output.WriteString( str );

    buf_output.Sync();

    textCtrl.WriteText( _T("\nReading from wxDataInputStream:\n") );

    file_input.SeekI( 0 );
    wxDataInputStream data_input( buf_input );

    i16 = data_input.Read16();
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );

    ui16 = data_input.Read16();
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );

    d = data_input.ReadDouble();
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    str = data_input.ReadString();
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
}
Exemple #10
0
void text_backend(paragraph *sourceform, keywordlist *keywords,
		  indexdata *idx, void *unused) {
    paragraph *p;
    textconfig conf;
    word *prefix, *body, *wp;
    word spaceword;
    textfile tf;
    wchar_t *prefixextra;
    int nesting, nestbase, nestindent;
    int indentb, indenta;

    IGNORE(unused);
    IGNORE(keywords);		       /* we don't happen to need this */
    IGNORE(idx);		       /* or this */

    conf = text_configure(sourceform);

    /*
     * Open the output file.
     */
    if (!strcmp(conf.filename, "-"))
	tf.fp = stdout;
    else
	tf.fp = fopen(conf.filename, "w");
    if (!tf.fp) {
	err_cantopenw(conf.filename);
	return;
    }
    tf.charset = conf.charset;
    tf.state = charset_init_state;

    /* Do the title */
    for (p = sourceform; p; p = p->next)
	if (p->type == para_Title)
	    text_heading(&tf, NULL, NULL, p->words,
			 conf.atitle, conf.indent, conf.width, &conf);

    nestindent = conf.listindentbefore + conf.listindentafter;
    nestbase = (conf.indent_preambles ? 0 : -conf.indent);
    nesting = nestbase;

    /* Do the main document */
    for (p = sourceform; p; p = p->next) switch (p->type) {

      case para_QuotePush:
	nesting += 2;
	break;
      case para_QuotePop:
	nesting -= 2;
	assert(nesting >= 0);
	break;

      case para_LcontPush:
	nesting += nestindent;
	break;
      case para_LcontPop:
	nesting -= nestindent;
	assert(nesting >= nestbase);
	break;

	/*
	 * Things we ignore because we've already processed them or
	 * aren't going to touch them in this pass.
	 */
      case para_IM:
      case para_BR:
      case para_Biblio:		       /* only touch BiblioCited */
      case para_VersionID:
      case para_NoCite:
      case para_Title:
	break;

	/*
	 * Chapter titles.
	 */
      case para_Chapter:
      case para_Appendix:
      case para_UnnumberedChapter:
	text_heading(&tf, p->kwtext, p->kwtext2, p->words,
		     conf.achapter, conf.indent, conf.width, &conf);
	nesting = 0;
	break;

      case para_Heading:
      case para_Subsect:
	text_heading(&tf, p->kwtext, p->kwtext2, p->words,
		     conf.asect[p->aux>=conf.nasect ? conf.nasect-1 : p->aux],
		     conf.indent, conf.width, &conf);
	break;

      case para_Rule:
	text_rule(&tf, conf.indent + nesting, conf.width - nesting, &conf);
	break;

      case para_Normal:
      case para_Copyright:
      case para_DescribedThing:
      case para_Description:
      case para_BiblioCited:
      case para_Bullet:
      case para_NumberedList:
	if (p->type == para_Bullet) {
	    prefix = &conf.bullet;
	    prefixextra = NULL;
	    indentb = conf.listindentbefore;
	    indenta = conf.listindentafter;
	} else if (p->type == para_NumberedList) {
	    prefix = p->kwtext;
	    prefixextra = conf.listsuffix;
	    indentb = conf.listindentbefore;
	    indenta = conf.listindentafter;
	} else if (p->type == para_Description) {
	    prefix = NULL;
	    prefixextra = NULL;
	    indentb = conf.listindentbefore;
	    indenta = conf.listindentafter;
	} else {
	    prefix = NULL;
	    prefixextra = NULL;
	    indentb = indenta = 0;
	}
	if (p->type == para_BiblioCited) {
	    body = dup_word_list(p->kwtext);
	    for (wp = body; wp->next; wp = wp->next);
	    wp->next = &spaceword;
	    spaceword.next = p->words;
	    spaceword.alt = NULL;
	    spaceword.type = word_WhiteSpace;
	    spaceword.text = NULL;
	} else {
	    wp = NULL;
	    body = p->words;
	}
	text_para(&tf, prefix, prefixextra, body,
		  conf.indent + nesting + indentb, indenta,
		  conf.width - nesting - indentb - indenta, &conf);
	if (wp) {
	    wp->next = NULL;
	    free_word_list(body);
	}
	break;

      case para_Code:
	text_codepara(&tf, p->words,
		      conf.indent + nesting + conf.indent_code,
		      conf.width - nesting - 2 * conf.indent_code);
	break;
    }

    /* Do the version ID */
    if (conf.include_version_id) {
	for (p = sourceform; p; p = p->next)
	    if (p->type == para_VersionID)
 		text_versionid(&tf, p->words, &conf);
    }

    /*
     * Tidy up
     */
    text_output(&tf, NULL);	       /* end charset conversion */
    if (tf.fp != stdout)
	fclose(tf.fp);
    sfree(conf.asect);
    sfree(conf.filename);
}
Exemple #11
0
//
// This program is a driver to test the first assignment functions.
//  The first 4 are tested.
//
int main(int argc, char** argv)
{
  bool ans;
  int armstrong_test = 8;  // true
  char brackets[5] = "[[]]";  // true
  int perfect_test = 28; // true
  int rotate_test = 1234;
  int r = 1;
  int rotate_test_solution = 4123;
  int rotate_test_ans = 0;
  char pattern_test[] = "ana";
  char text_test[] = "ana ate the banana";
  int str_search_solution = 3;
  int str_search_ans =0;
  int collatz_count_ans = 0;
  int collatz_count_solution = 7;
  int collatz_test = 20;
  int f_array_test = 15;
  char string_1[6] = "HELLO";
  char string_2[3] = "hi";
  char string_result[10];
  char string_ans[10] = "hiHELLOhi";
  int num1=14, num2=13, num3=12;
  int ascending [3] = {0};
  int ascending_ans[3] = {12,13,14};
  int cube_sum_this_num = 54;


  printf("Testing functions:\n");


  //1
  ans = f_armstrong(armstrong_test);
  text_output(1, ans==true);

  //2
  ans = f_brackets(brackets);
  text_output(2, ans==true);

  //3
  ans = f_perfect(perfect_test);
  text_output(3, ans==true);

  //4
  rotate_test_ans = f_rotate(rotate_test,r);
  if(rotate_test_ans == rotate_test_solution)
  {
      ans = true;
  }
  else
  {
      ans = false;
  }
  text_output(4,ans);

  //5
  str_search_ans = f_str_search(&pattern_test, &text_test);
  if(str_search_ans == str_search_solution)
  {
      ans = true;
  }
  else
  {
      ans = false;
  }
  text_output(5,ans);

  //6
  collatz_count_ans = f_collatz_count(collatz_test);
    if(collatz_count_ans == collatz_count_solution)
    {
        ans = true;
    }
    else
    {
        ans = false;
    }
    text_output(6,ans);

    //7
    text_output(7, ans);
    f_array(f_array_test);

    //8
    f_strings(&string_1, &string_2, &string_result);
    printf("The input strings were '%s' and '%s'.\n", string_1, string_2);
    printf("The answer should be '%s'\nYour answer is '%s'\n\n", string_ans, string_result);

    //9
    f_sort(num1, num2, num3, &ascending);
    if (ascending[0]==ascending_ans[0] && ascending[1]==ascending_ans[1] && ascending[2]==ascending_ans[2])
    {
        ans = true;
    }
    else
    {
        ans = false;
    }
    text_output(9,ans);

    //10
    if ((f_cubes_sum(cube_sum_this_num)[0] + f_cubes_sum(cube_sum_this_num)[1]) == cube_sum_this_num)
    {
        ans=true;
    }
    else
    {
        ans=false;
    }
    text_output(10,ans);
}