Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/tr.c


Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (12 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/coreutils/tr.c

    r821 r1770  
    1616 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    1717 */
    18 
    19 #include "busybox.h"
    20 
    21 // Even with -funsigned-char, gcc still complains about char as an array index.
    22 
    23 #define GCC4_IS_STUPID int
     18/* http://www.opengroup.org/onlinepubs/009695399/utilities/tr.html
     19 * TODO: xdigit, graph, print
     20 */
     21#include "libbb.h"
    2422
    2523#define ASCII 0377
    2624
    27 /* some "globals" shared across this file */
    28 static char com_fl, del_fl, sq_fl;
    29 /* these last are pointers to static buffers declared in tr_main */
    30 static char *poutput, *pvector, *pinvec, *poutvec;
    31 
    32 static void convert(void)
    33 {
    34     int read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1;
    35 
    36     for (;;) {
    37         // If we're out of input, flush output and read more input.
    38 
    39         if (in_index == read_chars) {
    40             if (out_index) {
    41                 if (write(1, (char *) poutput, out_index) != out_index)
    42                     bb_error_msg_and_die(bb_msg_write_error);
    43                 out_index = 0;
    44             }
    45 
    46             if ((read_chars = read(0, bb_common_bufsiz1, BUFSIZ)) <= 0) {
    47                 if (write(1, (char *) poutput, out_index) != out_index)
    48                     bb_error_msg(bb_msg_write_error);
    49                 exit(0);
    50             }
    51             in_index = 0;
    52         }
    53         c = bb_common_bufsiz1[in_index++];
    54         coded = pvector[c];
    55         if (del_fl && pinvec[c])
    56             continue;
    57         if (sq_fl && last == coded && (pinvec[c] || poutvec[coded]))
    58             continue;
    59         poutput[out_index++] = last = coded;
    60     }
    61 
    62     /* NOTREACHED */
    63 }
    64 
    65 static void map(char *string1, unsigned int string1_len,
    66         char *string2, unsigned int string2_len)
     25#define TR_OPT_complement   (1<<0)
     26#define TR_OPT_delete       (1<<1)
     27#define TR_OPT_squeeze_reps (1<<2)
     28
     29static void map(char *pvector,
     30        unsigned char *string1, unsigned int string1_len,
     31        unsigned char *string2, unsigned int string2_len)
    6732{
    6833    char last = '0';
     
    7136    for (j = 0, i = 0; i < string1_len; i++) {
    7237        if (string2_len <= j)
    73             pvector[(GCC4_IS_STUPID)string1[i]] = last;
     38            pvector[string1[i]] = last;
    7439        else
    75             pvector[(GCC4_IS_STUPID)string1[i]] = last = string2[j++];
     40            pvector[string1[i]] = last = string2[j++];
    7641    }
    7742}
     
    8550{
    8651    char *buffer_start = buffer;
    87     int i, ac;
    88 
     52    unsigned i; /* XXX: FIXME: use unsigned char? */
     53    unsigned char ac;
     54#define CLO ":]\0"
     55    static const char classes[] ALIGN1 =
     56        "alpha"CLO "alnum"CLO "digit"CLO "lower"CLO "upper"CLO "space"CLO
     57        "blank"CLO "punct"CLO "cntrl"CLO;
     58#define CLASS_invalid 0 /* we increment the retval */
     59#define CLASS_alpha 1
     60#define CLASS_alnum 2
     61#define CLASS_digit 3
     62#define CLASS_lower 4
     63#define CLASS_upper 5
     64#define CLASS_space 6
     65#define CLASS_blank 7
     66#define CLASS_punct 8
     67#define CLASS_cntrl 9
     68//#define CLASS_xdigit 10
     69//#define CLASS_graph 11
     70//#define CLASS_print 12
    8971    while (*arg) {
    9072        if (*arg == '\\') {
     
    9375        } else if (*(arg+1) == '-') {
    9476            ac = *(arg+2);
    95             if(ac == 0) {
     77            if (ac == 0) {
    9678                *buffer++ = *arg++;
    9779                continue;
     
    10587            i = *arg++;
    10688            if (ENABLE_FEATURE_TR_CLASSES && i == ':') {
    107                 if (strncmp(arg, "alpha", 5) == 0) {
     89                smalluint j;
     90                { /* not really pretty.. */
     91                    char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7
     92                    j = index_in_strings(classes, tmp) + 1;
     93                    free(tmp);
     94                }
     95                if (j == CLASS_alnum || j == CLASS_digit) {
     96                    for (i = '0'; i <= '9'; i++)
     97                        *buffer++ = i;
     98                }
     99                if (j == CLASS_alpha || j == CLASS_alnum || j == CLASS_upper) {
    108100                    for (i = 'A'; i <= 'Z'; i++)
    109101                        *buffer++ = i;
     102                }
     103                if (j == CLASS_alpha || j == CLASS_alnum || j == CLASS_lower) {
    110104                    for (i = 'a'; i <= 'z'; i++)
    111105                        *buffer++ = i;
    112106                }
    113                 else if (strncmp(arg, "alnum", 5) == 0) {
    114                     for (i = '0'; i <= '9'; i++)
    115                         *buffer++ = i;
    116                     for (i = 'A'; i <= 'Z'; i++)
    117                         *buffer++ = i;
    118                     for (i = 'a'; i <= 'z'; i++)
    119                         *buffer++ = i;
    120                 }
    121                 else if (strncmp(arg, "digit", 5) == 0)
    122                     for (i = '0'; i <= '9'; i++)
    123                         *buffer++ = i;
    124                 else if (strncmp(arg, "lower", 5) == 0)
    125                     for (i = 'a'; i <= 'z'; i++)
    126                         *buffer++ = i;
    127                 else if (strncmp(arg, "upper", 5) == 0)
    128                     for (i = 'A'; i <= 'Z'; i++)
    129                         *buffer++ = i;
    130                 else if (strncmp(arg, "space", 5) == 0) {
    131                     const char s[] = "\t\n\v\f\r ";
    132                     strcat((char*)buffer, s);
    133                     buffer += sizeof(s) - 1;
    134                 }
    135                 else if (strncmp(arg, "blank", 5) == 0) {
     107                if (j == CLASS_space || j == CLASS_blank) {
    136108                    *buffer++ = '\t';
     109                    if (j == CLASS_space) {
     110                        *buffer++ = '\n';
     111                        *buffer++ = '\v';
     112                        *buffer++ = '\f';
     113                        *buffer++ = '\r';
     114                    }
    137115                    *buffer++ = ' ';
    138116                }
    139                 /* gcc gives a warning if braces aren't used here */
    140                 else if (strncmp(arg, "punct", 5) == 0) {
     117                if (j == CLASS_punct || j == CLASS_cntrl) {
    141118                    for (i = 0; i <= ASCII; i++)
    142                         if (isprint(i) && (!isalnum(i)) && (!isspace(i)))
     119                        if ((j == CLASS_punct &&
     120                             isprint(i) && (!isalnum(i)) && (!isspace(i))) ||
     121                            (j == CLASS_cntrl && iscntrl(i)))
    143122                            *buffer++ = i;
    144123                }
    145                 else if (strncmp(arg, "cntrl", 5) == 0) {
    146                     for (i = 0; i <= ASCII; i++)
    147                         if (iscntrl(i))
    148                             *buffer++ = i;
    149                 }
    150                 else {
     124                if (j == CLASS_invalid) {
    151125                    *buffer++ = '[';
    152126                    *buffer++ = ':';
     
    157131            if (ENABLE_FEATURE_TR_EQUIV && i == '=') {
    158132                *buffer++ = *arg;
    159                 /* skip the closing =] */
    160                 arg += 3;
     133                arg += 3;   /* Skip the closing =] */
    161134                continue;
    162135            }
     
    169142            while (i <= ac)
    170143                *buffer++ = i++;
    171             arg++;              /* Skip the assumed ']' */
     144            arg++;  /* Skip the assumed ']' */
    172145        } else
    173146            *buffer++ = *arg++;
    174147    }
    175 
    176148    return (buffer - buffer_start);
    177149}
     
    179151static int complement(char *buffer, int buffer_len)
    180152{
    181     register short i, j, ix;
     153    int i, j, ix;
    182154    char conv[ASCII + 2];
    183155
     
    194166}
    195167
     168int tr_main(int argc, char **argv);
    196169int tr_main(int argc, char **argv)
    197170{
    198     register unsigned char *ptr;
    199     int output_length=0, input_length;
     171    unsigned char *ptr;
     172    int output_length = 0, input_length;
    200173    int idx = 1;
    201174    int i;
    202     RESERVE_CONFIG_BUFFER(output, BUFSIZ);
     175    smalluint flags = 0;
     176    size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1;
     177    RESERVE_CONFIG_UBUFFER(output, BUFSIZ);
    203178    RESERVE_CONFIG_BUFFER(vector, ASCII+1);
    204179    RESERVE_CONFIG_BUFFER(invec,  ASCII+1);
    205180    RESERVE_CONFIG_BUFFER(outvec, ASCII+1);
    206181
    207     /* ... but make them available globally */
    208     poutput = output;
    209     pvector = vector;
    210     pinvec  = invec;
    211     poutvec = outvec;
    212 
    213182    if (argc > 1 && argv[idx][0] == '-') {
    214183        for (ptr = (unsigned char *) &argv[idx][1]; *ptr; ptr++) {
    215             switch (*ptr) {
    216             case 'c':
    217                 com_fl = TRUE;
    218                 break;
    219             case 'd':
    220                 del_fl = TRUE;
    221                 break;
    222             case 's':
    223                 sq_fl = TRUE;
    224                 break;
    225             default:
     184            if (*ptr == 'c')
     185                flags |= TR_OPT_complement;
     186            else if (*ptr == 'd')
     187                flags |= TR_OPT_delete;
     188            else if (*ptr == 's')
     189                flags |= TR_OPT_squeeze_reps;
     190            else
    226191                bb_show_usage();
    227             }
    228192        }
    229193        idx++;
     
    234198    }
    235199
     200#define tr_buf bb_common_bufsiz1
    236201    if (argv[idx] != NULL) {
    237         input_length = expand(argv[idx++], bb_common_bufsiz1);
    238         if (com_fl)
    239             input_length = complement(bb_common_bufsiz1, input_length);
     202        input_length = expand(argv[idx++], tr_buf);
     203        if (flags & TR_OPT_complement)
     204            input_length = complement(tr_buf, input_length);
    240205        if (argv[idx] != NULL) {
    241206            if (*argv[idx] == '\0')
    242207                bb_error_msg_and_die("STRING2 cannot be empty");
    243208            output_length = expand(argv[idx], output);
    244             map(bb_common_bufsiz1, input_length, output, output_length);
     209            map(vector, tr_buf, input_length, output, output_length);
    245210        }
    246211        for (i = 0; i < input_length; i++)
    247             invec[(GCC4_IS_STUPID)bb_common_bufsiz1[i]] = TRUE;
     212            invec[(unsigned char)tr_buf[i]] = TRUE;
    248213        for (i = 0; i < output_length; i++)
    249             outvec[(GCC4_IS_STUPID)output[i]] = TRUE;
    250     }
    251     convert();
    252     return (0);
    253 }
     214            outvec[output[i]] = TRUE;
     215    }
     216
     217    for (;;) {
     218        /* If we're out of input, flush output and read more input. */
     219        if (in_index == read_chars) {
     220            if (out_index) {
     221                xwrite(STDOUT_FILENO, (char *)output, out_index);
     222                out_index = 0;
     223            }
     224            read_chars = read(STDIN_FILENO, tr_buf, BUFSIZ);
     225            if (read_chars <= 0) {
     226                if (write(STDOUT_FILENO, (char *)output, out_index) != out_index)
     227                    bb_perror_msg(bb_msg_write_error);
     228                exit(EXIT_SUCCESS);
     229            }
     230            in_index = 0;
     231        }
     232        c = tr_buf[in_index++];
     233        coded = vector[c];
     234        if ((flags & TR_OPT_delete) && invec[c])
     235            continue;
     236        if ((flags & TR_OPT_squeeze_reps) && last == coded &&
     237            (invec[c] || outvec[coded]))
     238            continue;
     239        output[out_index++] = last = coded;
     240    }
     241    /* NOTREACHED */
     242    return EXIT_SUCCESS;
     243}
Note: See TracChangeset for help on using the changeset viewer.