Ignore:
Timestamp:
May 6, 2015, 1:10:17 PM (9 years ago)
Author:
Bruno Cornec
Message:
  • Rename mr_parted2fdisk to mr-parted2fdisk for consistency with all other new mr-* commands
  • Adds functions mr_center_string and mr_popup_and_get_string with dynamic allocation to solve a memory allocation issue reported on the ML
  • Fix mr_boot_type to detect correctly a UEFI based system
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3290 r3377  
    6969}
    7070
     71
     72/**
     73 * Pad a string on both sides so it appears centered.
     74 * @param in_out The string to be center-padded (modified).
     75 * @param width The width of the final result.
     76 */
     77char *mr_center_string(char *in, int width)
     78{
     79    char *scratch = NULL;
     80    char *out = NULL;
     81    int i;                      /* purpose */
     82    int len;                    /* purpose */
     83    int mid;                    /* purpose */
     84    int x;                      /* purpose */
     85
     86    assert(in != NULL);
     87    assert(width > 2);
     88
     89    if (strlen(in) == 0) {
     90        return(NULL);
     91    }
     92    /*  skip initial spaces */
     93    mr_asprintf(scratch, "%s", in);
     94    mr_strip_spaces(scratch);
     95    len = (int)strlen(scratch);
     96    mid = width / 2;
     97    x = mid - len / 2;
     98    for (i = 0; i < x; i++) {
     99        mr_strcat(out,' ');
     100    }
     101    mr_strcat(out, scratch);
     102    mr_free(scratch);
     103    for (i = x + len ; i < width - 1; i++) {
     104            mr_strcat(out,' ');
     105        }
     106    return(out);
     107}
    71108
    72109/**
Note: See TracChangeset for help on using the changeset viewer.