Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/comm.c

    r821 r1765  
    88 */
    99
    10 #include <stdio.h>
    11 #include <stdlib.h>
    12 #include <string.h>
    13 #include <unistd.h>
    14 #include "busybox.h"
     10#include "libbb.h"
    1511
    16 #define COMM_OPT_1 0x01
    17 #define COMM_OPT_2 0x02
    18 #define COMM_OPT_3 0x04
    19 
    20 /* These three variables control behaviour if non-zero */
    21 
    22 static int only_file_1;
    23 static int only_file_2;
    24 static int both;
     12#define COMM_OPT_1 (1 << 0)
     13#define COMM_OPT_2 (1 << 1)
     14#define COMM_OPT_3 (1 << 2)
    2515
    2616/* writeline outputs the input given, appropriately aligned according to class */
    27 static void writeline(char *line, int class)
     17static void writeline(char *line, int class, int flags)
    2818{
    2919    if (class == 0) {
    30         if (!only_file_1)
     20        if (flags & COMM_OPT_1)
    3121            return;
    3222    } else if (class == 1) {
    33         if (!only_file_2)
     23        if (flags & COMM_OPT_2)
    3424            return;
    35         if (only_file_1)
     25        if (!(flags & COMM_OPT_1))
    3626            putchar('\t');
    37     }
    38     else /*if (class == 2)*/ {
    39         if (!both)
     27    } else /*if (class == 2)*/ {
     28        if (flags & COMM_OPT_3)
    4029            return;
    41         if (only_file_1)
     30        if (!(flags & COMM_OPT_1))
    4231            putchar('\t');
    43         if (only_file_2)
     32        if (!(flags & COMM_OPT_2))
    4433            putchar('\t');
    4534    }
     
    4736}
    4837
    49 /* This is the real core of the program - lines are compared here */
    50 static void cmp_files(char **infiles)
     38int comm_main(int argc, char **argv);
     39int comm_main(int argc, char **argv)
    5140{
    5241#define LINE_LEN 100
     
    5645    FILE *streams[2];
    5746    int i;
     47    unsigned flags;
     48
     49    opt_complementary = "=2";
     50    flags = getopt32(argv, "123");
     51    argv += optind;
    5852
    5953    for (i = 0; i < 2; ++i) {
    60         streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : bb_xfopen(infiles[i], "r"));
     54        streams[i] = (argv[i][0] == '-' && !argv[i][1]) ? stdin : xfopen(argv[i], "r");
    6155        fgets(thisline[i], LINE_LEN, streams[i]);
    6256    }
     57
     58    /* This is the real core of the program - lines are compared here */
    6359
    6460    while (*thisline[0] || *thisline[1]) {
     
    8379
    8480        if (order == 0 && !i)
    85             writeline(thisline[1], 2);
     81            writeline(thisline[1], 2, flags);
    8682        else if (order > 0 && !(i & BB_EOF_1))
    87             writeline(thisline[1], 1);
     83            writeline(thisline[1], 1, flags);
    8884        else if (order < 0 && !(i & BB_EOF_0))
    89             writeline(thisline[0], 0);
     85            writeline(thisline[0], 0, flags);
    9086
    9187        if (i & BB_EOF_0 & BB_EOF_1) {
     
    9692            while (!feof(streams[i])) {
    9793                if ((order < 0 && i) || (order > 0 && !i))
    98                     writeline(thisline[i], i);
     94                    writeline(thisline[i], i, flags);
    9995                fgets(thisline[i], LINE_LEN, streams[i]);
    10096            }
     
    109105    }
    110106
    111     fclose(streams[0]);
    112     fclose(streams[1]);
     107    if (ENABLE_FEATURE_CLEAN_UP) {
     108        fclose(streams[0]);
     109        fclose(streams[1]);
     110    }
     111
     112    return EXIT_SUCCESS;
    113113}
    114 
    115 int comm_main(int argc, char **argv)
    116 {
    117     unsigned long flags;
    118 
    119     flags = bb_getopt_ulflags(argc, argv, "123");
    120 
    121     if (optind + 2 != argc)
    122         bb_show_usage();
    123 
    124     only_file_1 = !(flags & COMM_OPT_1);
    125     only_file_2 = !(flags & COMM_OPT_2);
    126     both = !(flags & COMM_OPT_3);
    127 
    128     cmp_files(argv + optind);
    129     exit(EXIT_SUCCESS);
    130 }
Note: See TracChangeset for help on using the changeset viewer.