Copyleft(L) Dongxiao Yue, 1996. 
If you need the source code for commercial use, send email to dyue@cs.umn.edu.


                  The GB Formatter

The free formarting softwares on the net are somewhat unsatisfactory (try them).
After failing to find one that I like, I decicided to write my own. This should
be a  rather simple task, if one knows the GB code standard. 

The standards and GB table are found at ftp://ifcss.org

Using a Lexical analyzer generator, I wrote the gbformat program.
Its main function is to format GB files. It can also be used to
convert between GB and HZ formats.

Usage:
  % gbfmt

  and then answer questions.

Formating methods

   A) Fixed mode
      A line starting with spaces is considered the beginning of a
      new paragraph. The subsequent lines are formatted to within a
      fixed line width.

   B) Variable mode
      In the input, paragraphs are separated by blank lines.
      The first line of the paragraph is used to determine the width
      of the paragraph, the sencond line is used to determine to indentation
      of all subsequqnt lines. Indentations are rounded to the nearest
      even integer below.

example:
Before formatting:

                       °ËÄ꿹սÓëÖлªÃñ×åµÄ¾õÐÑ

         ÖйúÈËÔÚ¿¹ÈÕ¾ÈÍöµÄÕ½¶·ÖÐ, ÆäÃñ×徫Éñ´ÓÖ𽥸´ËÕÖÕ
    ÓÚ´ïµ½ÁËÍêÈ«µÄ¾õÐÑ; ÂúÇåÈý°ÙÄê, ÄÔºóÒ»¸ù³¤±èÔÚÖйúÈËÉíÉÏÔì³ÉµÄÅ«ÐÔºÍÂéľ,
 ÖÕÓÚ ´Ó¸ù±¾Éϱ»Çå³ý¡£

After formating with Variable Mode:

                      °ËÄ꿹սÓëÖлªÃñ×åµÄ¾õÐÑ

        ÖйúÈËÔÚ¿¹ÈÕ¾ÈÍöµÄÕ½¶·ÖУ,ÆäÃñ×徫Éñ´ÓÖ𽥸´ËÕÖÕ
    ÓÚ´ïµ½ÁËÍêÈ«µÄ¾õÐÑ£;ÂúÇåÈý°ÙÄê£,ÄÔºóÒ»¸ù³¤±èÔÚÖйúÈË
    ÉíÉÏÔì³ÉµÄÅ«ÐÔºÍÂéľ£,ÖÕÓÚ´Ó¸ù±¾Éϱ»Çå³ý¡£

Notes:
The program preserves the boundary of English words.
When format, it minimizes the number of ~{ ~}'s in the HZ format.
When format, it removes extra spaces between words.
The conversion between HZ and GB does not try to break lines, if
you want to break lines in a shorter ones, use the Format function.

I found it is often a good idea to format a file with Fixed mode, so
most of the lines are aligned, then change the first two lines of the
paragraphs which you want a different width, and use variable mode when
formatting (but you must make sure the paragraphs are separated by blank
lines). 

The Windows version is a simple MFC program, I plan to add editing
interface later, if there is a strong interest for it. 

Plans:
To write one with GUI.

==========================================================================
Dongxiao Yue
http://www.cs.umn.edu/~dyue/wiihist/