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 984 by niro, Sun May 30 11:32:42 2010 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    
 #define isdecdigit(c) isdigit(c)  
 #define ishexdigit(c) (isxdigit)(c)  
   
23  static void  static void
24  odoffset(int argc, char ***argvp)  odoffset(dumper_t *dumper, int argc, char ***argvp)
25  {  {
26   char *num, *p;   char *num, *p;
27   int base;   int base;
# Line 52  odoffset(int argc, char ***argvp) Line 48  odoffset(int argc, char ***argvp)
48    
49   if ((*p != '+')   if ((*p != '+')
50   && (argc < 2   && (argc < 2
51   || (!isdecdigit(p[0])   || (!isdigit(p[0])
52   && ((p[0] != 'x') || !ishexdigit(p[1])))))   && ((p[0] != 'x') || !isxdigit(p[1])))))
53   return;   return;
54    
55   base = 0;   base = 0;
56   /*   /*
57   * bb_dump_skip over leading '+', 'x[0-9a-fA-f]' or '0x', and   * skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
58   * set base.   * set base.
59   */   */
60   if (p[0] == '+')   if (p[0] == '+')
61   ++p;   ++p;
62   if (p[0] == 'x' && ishexdigit(p[1])) {   if (p[0] == 'x' && isxdigit(p[1])) {
63   ++p;   ++p;
64   base = 16;   base = 16;
65   } else if (p[0] == '0' && p[1] == 'x') {   } else if (p[0] == '0' && p[1] == 'x') {
# Line 71  odoffset(int argc, char ***argvp) Line 67  odoffset(int argc, char ***argvp)
67   base = 16;   base = 16;
68   }   }
69    
70   /* bb_dump_skip over the number */   /* skip over the number */
71   if (base == 16)   if (base == 16)
72   for (num = p; ishexdigit(*p); ++p);   for (num = p; isxdigit(*p); ++p)
73     continue;
74   else   else
75   for (num = p; isdecdigit(*p); ++p);   for (num = p; isdigit(*p); ++p)
76     continue;
77    
78   /* check for no number */   /* check for no number */
79   if (num == p)   if (num == p)
# Line 88  odoffset(int argc, char ***argvp) Line 86  odoffset(int argc, char ***argvp)
86   base = 10;   base = 10;
87   }   }
88    
89   bb_dump_skip = strtol(num, &end, base ? base : 8);   dumper->dump_skip = strtol(num, &end, base ? base : 8);
90    
91   /* 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 */
92   if (end != p)   if (end != p)
93   bb_dump_skip = 0;   dumper->dump_skip = 0;
94   else {   else {
95   if (*p) {   if (*p) {
96   if (*p == 'b') {   if (*p == 'b') {
97   bb_dump_skip *= 512;   dumper->dump_skip *= 512;
98   ++p;   ++p;
99   } else if (*p == 'B') {   } else if (*p == 'B') {
100   bb_dump_skip *= 1024;   dumper->dump_skip *= 1024;
101   ++p;   ++p;
102   }   }
103   }   }
104   if (*p)   if (*p)
105   bb_dump_skip = 0;   dumper->dump_skip = 0;
106   else {   else {
107   ++*argvp;   ++*argvp;
108   /*   /*
# Line 121  odoffset(int argc, char ***argvp) Line 119  odoffset(int argc, char ***argvp)
119   }   }
120   if (base == 10) {   if (base == 10) {
121   x_or_d = 'd';   x_or_d = 'd';
122   DO_X_OR_D:   DO_X_OR_D:
123   bb_dump_fshead->nextfu->fmt[TYPE_OFFSET]   dumper->fshead->nextfu->fmt[TYPE_OFFSET]
124   = bb_dump_fshead->nextfs->nextfu->fmt[TYPE_OFFSET]   = dumper->fshead->nextfs->nextfu->fmt[TYPE_OFFSET]
125   = x_or_d;   = x_or_d;
126   }   }
127   }   }
# Line 131  odoffset(int argc, char ***argvp) Line 129  odoffset(int argc, char ***argvp)
129   }   }
130  }  }
131    
132  static const char * const add_strings[] = {  static const char *const add_strings[] = {
133   "16/1 \"%3_u \" \"\\n\"", /* a */   "16/1 \"%3_u \" \"\\n\"", /* a */
134   "8/2 \" %06o \" \"\\n\"", /* B, o */   "8/2 \" %06o \" \"\\n\"", /* B, o */
135   "16/1 \"%03o \" \"\\n\"", /* b */   "16/1 \"%03o \" \"\\n\"", /* b */
# Line 147  static const char * const add_strings[] Line 145  static const char * const add_strings[]
145   "4/4 \"    %011o \" \"\\n\"", /* O */   "4/4 \"    %011o \" \"\\n\"", /* O */
146  };  };
147    
148  static const char od_opts[] = "aBbcDdeFfHhIiLlOoXxv";  static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv";
149    
150  static const char od_o2si[] = {  static const char od_o2si[] ALIGN1 = {
151   0, 1, 2, 3, 5,   0, 1, 2, 3, 5,
152   4, 6, 6, 7, 8,   4, 6, 6, 7, 8,
153   9, 0xa, 0xb, 0xa, 0xa,   9, 0xa, 0xb, 0xa, 0xa,
154   0xb, 1, 8, 9,   0xb, 1, 8, 9,
155  };  };
156    
157    int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
158  int od_main(int argc, char **argv)  int od_main(int argc, char **argv)
159  {  {
160   int ch;   int ch;
161   int first = 1;   int first = 1;
162   char *p;   char *p;
163   bb_dump_vflag = FIRST;   dumper_t *dumper = alloc_dumper();
  bb_dump_length = -1;  
164    
165   while ((ch = getopt(argc, argv, od_opts)) > 0) {   while ((ch = getopt(argc, argv, od_opts)) > 0) {
166   if (ch == 'v') {   if (ch == 'v') {
167   bb_dump_vflag = ALL;   dumper->dump_vflag = ALL;
168   } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {   } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {
169   if (first) {   if (first) {
170   first = 0;   first = 0;
171   bb_dump_add("\"%07.7_Ao\n\"");   bb_dump_add(dumper, "\"%07.7_Ao\n\"");
172   bb_dump_add("\"%07.7_ao  \"");   bb_dump_add(dumper, "\"%07.7_ao  \"");
173   } else {   } else {
174   bb_dump_add("\"         \"");   bb_dump_add(dumper, "\"         \"");
175   }   }
176   bb_dump_add(add_strings[(int)od_o2si[(p-od_opts)]]);   bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
177   } else { /* P, p, s, w, or other unhandled */   } else { /* P, p, s, w, or other unhandled */
178   bb_show_usage();   bb_show_usage();
179   }   }
180   }   }
181   if (!bb_dump_fshead) {   if (!dumper->fshead) {
182   bb_dump_add("\"%07.7_Ao\n\"");   bb_dump_add(dumper, "\"%07.7_Ao\n\"");
183   bb_dump_add("\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");   bb_dump_add(dumper, "\"%07.7_ao  \" 8/2 \"%06o \" \"\\n\"");
184   }   }
185    
186   argc -= optind;   argc -= optind;
187   argv += optind;   argv += optind;
188    
189   odoffset(argc, &argv);   odoffset(dumper, argc, &argv);
190    
191   return bb_dump_dump(argv);   return bb_dump_dump(dumper, argv);
192  }  }
193  #endif /* ENABLE_DESKTOP */  #endif /* ENABLE_DESKTOP */
194    

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