Changeset 6045ecf in mainline


Ignore:
Timestamp:
2011-08-21T10:28:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f737c1d5
Parents:
19d007e
Message:

Enhance justify aligment mode and align bdsh help to the left

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/help/help.c

    r19d007e r6045ecf  
    153153            "To learn more please point your browser to the HelenOS User's "
    154154            "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n",
    155              ALIGN_JUSTIFY);
     155            ALIGN_LEFT);
    156156}
    157157
  • uspace/lib/fmtutil/fmtutil.c

    r19d007e r6045ecf  
    6060}
    6161
    62 static int print_line(wchar_t *wstr, size_t chars, void *data)
    63 {
    64         //char *line = wstr_to_astr(wstr);
     62/** Line consumer that prints the lines aligned according to spec
     63 *
     64 **/
     65static int print_line(wchar_t *wstr, size_t chars, bool last, void *data)
     66{
    6567        printmode_t *pm = (printmode_t *) data;
    66         //if (line == NULL) {
    67         //      return ENOMEM;
    68         //}
     68        wchar_t old_char = wstr[chars];
    6969        wstr[chars] = 0;
    70         return print_aligned_w(wstr, pm->width, pm->alignment);
    71         //printf("%s", line);
    72         //if (pm->newline_always || chars < pm->width)
    73         //      printf("\n");
    74         //free(line);
    75         //return EOK;
     70        int rc = print_aligned_w(wstr, pm->width, last, pm->alignment);
     71        wstr[chars] = old_char;
     72        return rc;
    7673}
    7774
     
    9188}
    9289
    93 int print_aligned_w(const wchar_t *wstr, size_t width, align_mode_t mode)
     90int print_aligned_w(const wchar_t *wstr, size_t width, bool last,
     91    align_mode_t mode)
    9492{
    9593        size_t i;
    9694        size_t len = wstr_length(wstr);
    97         if (mode == ALIGN_LEFT) {
     95        if (mode == ALIGN_LEFT || (mode == ALIGN_JUSTIFY && last)) {
    9896                for (i = 0; i < width; i++) {
    9997                        if (i < len)
     
    171169        return EOK;
    172170}
    173 int print_aligned(const char *str, size_t width, align_mode_t mode)
     171int print_aligned(const char *str, size_t width, bool last, align_mode_t mode)
    174172{
    175173        wchar_t *wstr = str_to_awstr(str);
     
    177175                return ENOMEM;
    178176        }
    179         int rc = print_aligned_w(wstr, width, mode);
     177        int rc = print_aligned_w(wstr, width, last, mode);
    180178        free(wstr);
    181179        return rc;
    182180}
    183181
    184 /**
    185  */
    186182int wrap(wchar_t *wstr, size_t width, line_consumer_fn consumer, void *data)
    187183{
     
    202198                while (wstr[pos] == ' ' || wstr[pos] == '\n') {
    203199                        if (wstr[pos] == '\n') {
    204                                 consumer(wstr + line_start, line_len, data);
     200                                consumer(wstr + line_start, line_len, true,
     201                                    data);
    205202                                last_word_end = line_start = pos + 1;
    206203                                line_len = 0;
     
    213210                    wstr[pos] != '\n')
    214211                        pos++;
     212                bool last = wstr[pos] == 0;
    215213                /* Check if the line still fits width */
    216214                if (pos - line_start > width) {
    217215                        if (line_len > 0)
    218                                 consumer(wstr + line_start, line_len, data);
     216                                consumer(wstr + line_start, line_len, last,
     217                                    data);
    219218                        line_start = last_word_end = word_start;
    220219                        line_len = 0;
     
    222221                /* Check if we need to force wrap of long word*/
    223222                if (pos - word_start > width) {
    224                         consumer(wstr + word_start, width, data);
     223                        consumer(wstr + word_start, width, last, data);
    225224                        pos = line_start = last_word_end = word_start + width;
    226225                        line_len = 0;
     
    233232         */
    234233        if (pos - line_start > 0)
    235                 consumer(wstr + line_start, pos - line_start, data);
     234                consumer(wstr + line_start, pos - line_start, true, data);
    236235
    237236        return EOK;
  • uspace/lib/fmtutil/fmtutil.h

    r19d007e r6045ecf  
    3939 * @param content pointer to line data (note: this is NOT null-terminated)
    4040 * @param size number of characters in line
     41 * @param end_of_para true if the line is the last line of the paragraph
    4142 * @param data user data
    4243 *
    4344 * @returns EOK on success or error code on failure
    4445 */
    45 typedef int (*line_consumer_fn)(wchar_t *, size_t, void *);
     46typedef int (*line_consumer_fn)(wchar_t *, size_t, bool, void *);
    4647
    47 extern int print_aligned_w(const wchar_t *, size_t, align_mode_t);
    48 extern int print_aligned(const char *, size_t, align_mode_t);
     48extern int print_aligned_w(const wchar_t *, size_t, bool, align_mode_t);
     49extern int print_aligned(const char *, size_t, bool, align_mode_t);
    4950extern int print_wrapped(const char *, size_t, align_mode_t);
    5051extern int print_wrapped_console(const char *, align_mode_t);
Note: See TracChangeset for help on using the changeset viewer.