Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/coreutils/od.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 12  Line 12 
12   */   */
13    
14    
15    #include "libbb.h"
16  #if ENABLE_DESKTOP  #if ENABLE_DESKTOP
17  /* This one provides -t (busybox's own build script needs it) */  /* This one provides -t (busybox's own build script needs it) */
18  #include "od_bloaty.c"  #include "od_bloaty.c"
19  #else  #else
20    
 #include <getopt.h>  
 #include "busybox.h"  
21  #include "dump.h"  #include "dump.h"
22    
23  #define isdecdigit(c) isdigit(c)  #define isdecdigit(c) isdigit(c)
24  #define ishexdigit(c) (isxdigit)(c)  #define ishexdigit(c) (isxdigit)(c)
25    
26  static void  static void
27  odoffset(int argc, char ***argvp)  odoffset(dumper_t *dumper, int argc, char ***argvp)
28  {  {
29   char *num, *p;   char *num, *p;
30   int base;   int base;
# Line 58  odoffset(int argc, char ***argvp) Line 57  odoffset(int argc, char ***argvp)
57    
58   base = 0;   base = 0;
59   /*   /*
60   * bb_dump_skip over leading '+', 'x[0-9a-fA-f]' or '0x', and   * skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
61   * set base.   * set base.
62   */   */
63   if (p[0] == '+')   if (p[0] == '+')
# Line 71  odoffset(int argc, char ***argvp) Line 70  odoffset(int argc, char ***argvp)
70   base = 16;   base = 16;
71   }   }
72    
73   /* bb_dump_skip over the number */   /* skip over the number */
74   if (base == 16)   if (base == 16)
75   for (num = p; ishexdigit(*p); ++p);   for (num = p; ishexdigit(*p); ++p)
76     continue;
77   else   else
78   for (num = p; isdecdigit(*p); ++p);   for (num = p; isdecdigit(*p); ++p)
79     continue;
80    
81   /* check for no number */   /* check for no number */
82   if (num == p)   if (num == p)
# Line 88  odoffset(int argc, char ***argvp) Line 89  odoffset(int argc, char ***argvp)
89   base = 10;   base = 10;
90   }   }
91    
92   bb_dump_skip = strtol(num, &end, base ? base : 8);   dumper->dump_skip = strtol(num, &end, base ? base : 8);
93    
94   /* if end isn't the same as p, we got a non-octal digit */   /* if end isn't the same as p, we got a non-octal digit */
95   if (end != p)   if (end != p)
96   bb_dump_skip = 0;   dumper->dump_skip = 0;
97   else {   else {
98   if (*p) {   if (*p) {
99   if (*p == 'b') {   if (*p == 'b') {
100   bb_dump_skip *= 512;   dumper->dump_skip *= 512;
101   ++p;   ++p;
102   } else if (*p == 'B') {   } else if (*p == 'B') {
103   bb_dump_skip *= 1024;   dumper->dump_skip *= 1024;
104   ++p;   ++p;
105   }   }
106   }   }
107   if (*p)   if (*p)
108   bb_dump_skip = 0;   dumper->dump_skip = 0;
109   else {   else {
110   ++*argvp;   ++*argvp;
111   /*   /*
# Line 121  odoffset(int argc, char ***argvp) Line 122  odoffset(int argc, char ***argvp)
122   }   }
123   if (base == 10) {   if (base == 10) {
124   x_or_d = 'd';   x_or_d = 'd';
125   DO_X_OR_D:   DO_X_OR_D:
126   bb_dump_fshead->nextfu->fmt[TYPE_OFFSET]   dumper->fshead->nextfu->fmt[TYPE_OFFSET]
127   = bb_dump_fshead->nextfs->nextfu->fmt[TYPE_OFFSET]   = dumper->fshead->nextfs->nextfu->fmt[TYPE_OFFSET]
128   = x_or_d;   = x_or_d;
129   }   }
130   }   }
# Line 131  odoffset(int argc, char ***argvp) Line 132  odoffset(int argc, char ***argvp)
132   }   }
133  }  }
134    
135  static const char * const add_strings[] = {  static const char *const add_strings[] = {
136   "16/1 \"%3_u \" \"\\n\"", /* a */   "16/1 \"%3_u \" \"\\n\"", /* a */
137   "8/2 \" %06o \" \"\\n\"", /* B, o */   "8/2 \" %06o \" \"\\n\"", /* B, o */
138   "16/1 \"%03o \" \"\\n\"", /* b */   "16/1 \"%03o \" \"\\n\"", /* b */
# Line 147  static const char * const add_strings[] Line 148  static const char * const add_strings[]
148   "4/4 \"    %011o \" \"\\n\"", /* O */   "4/4 \"    %011o \" \"\\n\"", /* O */
149  };  };
150    
151  static const char od_opts[] = "aBbcDdeFfHhIiLlOoXxv";  static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv";
152    
153  static const char od_o2si[] = {  static const char od_o2si[] ALIGN1 = {
154   0, 1, 2, 3, 5,   0, 1, 2, 3, 5,
155   4, 6, 6, 7, 8,   4, 6, 6, 7, 8,
156   9, 0xa, 0xb, 0xa, 0xa,   9, 0xa, 0xb, 0xa, 0xa,
157   0xb, 1, 8, 9,   0xb, 1, 8, 9,
158  };  };
159    
160    int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
161  int od_main(int argc, char **argv)  int od_main(int argc, char **argv)
162  {  {
163   int ch;   int ch;
164   int first = 1;   int first = 1;
165   char *p;   char *p;
166   bb_dump_vflag = FIRST;   dumper_t *dumper = alloc_dumper();
  bb_dump_length = -1;  
167    
168   while ((ch = getopt(argc, argv, od_opts)) > 0) {   while ((ch = getopt(argc, argv, od_opts)) > 0) {
169   if (ch == 'v') {   if (ch == 'v') {
170   bb_dump_vflag = ALL;   dumper->dump_vflag = ALL;
171   } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {   } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {
172   if (first) {   if (first) {
173   first = 0;   first = 0;
174   bb_dump_add("\"%07.7_Ao\n\"");   bb_dump_add(dumper, "\"%07.7_Ao\n\"");
175   bb_dump_add("\"%07.7_ao  \"");   bb_dump_add(dumper, "\"%07.7_ao  \"");
176   } else {   } else {
177   bb_dump_add("\"         \"");   bb_dump_add(dumper, "\"         \"");
178   }   }
179   bb_dump_add(add_strings[(int)od_o2si[(p-od_opts)]]);   bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
180   } else { /* P, p, s, w, or other unhandled */   } else { /* P, p, s, w, or other unhandled */
181   bb_show_usage();   bb_show_usage();
182   }   }
183   }   }
184   if (!bb_dump_fshead) {   if (!dumper->fshead) {
185   bb_dump_add("\"%07.7_Ao\n\"");   bb_dump_add(dumper, "\"%07.7_Ao\n\"");
186   bb_dump_add("\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");   bb_dump_add(dumper, "\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
187   }   }
188    
189   argc -= optind;   argc -= optind;
190   argv += optind;   argv += optind;
191    
192   odoffset(argc, &argv);   odoffset(dumper, argc, &argv);
193    
194   return bb_dump_dump(argv);   return bb_dump_dump(dumper, argv);
195  }  }
196  #endif /* ENABLE_DESKTOP */  #endif /* ENABLE_DESKTOP */
197    

Legend:
Removed from v.532  
changed lines
  Added in v.816