OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [sash/] [hexdump.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * Copyright (c) 1993 by David I. Bell
3
 * Permission is granted to use, distribute, or modify this source,
4
 * provided that this copyright notice remains intact.
5
 *
6
 * Most simple built-in commands are here.
7
 */
8
 
9
#include "sash.h"
10
 
11
#include <sys/types.h>
12
#include <sys/stat.h>
13
#include <unistd.h>
14
#include <fcntl.h>
15
#include <signal.h>
16
#include <pwd.h>
17
#include <grp.h>
18
#include <utime.h>
19
#include <errno.h>
20
 
21
void
22
do_hexdump(argc, argv)
23
        int     argc;
24
        char    **argv;
25
{
26
        FILE    *fp;
27
        int     count;
28
        int     c;
29
        char    text[17];
30
        unsigned char   buf[130];
31
 
32
        char    *name = 0;
33
        unsigned long pos = 0;
34
        char    *myname = argv[0];
35
 
36
        if ( (argc > 2) && !strcmp(argv[1],"-s") ) {
37
                pos = strtoul(argv[2], 0, 0);
38
                argc -= 2;
39
                argv += 2;
40
        }
41
 
42
        if ( argc > 0 )
43
                name = argv[1];
44
 
45
        fp = fopen(name, "r");
46
 
47
        fseek(fp, pos, SEEK_SET);
48
 
49
        c = 0;
50
 
51
        text[16] = 0;
52
 
53
        while(!feof(fp)) {
54
 
55
          strcmp(text, "                ");
56
 
57
          while (c < (pos & 0xf)) {
58
            if (c == 0)
59
              printf("%4X:", pos & 0xfffffff0);
60
            printf( (c == 8) ? "-  " : "   ");
61
            text[c] = ' ';
62
            c++;
63
          }
64
 
65
          {
66
            int p = 0;
67
            count = fread(buf, 1, 128 - (pos % 16), fp);
68
 
69
            if (count <= 0)
70
              break;
71
 
72
            while (p < count) {
73
              c = (pos & 0xf);
74
 
75
              if (c == 0)
76
                printf("%4X:", pos & 0xfffffff0);
77
 
78
              if ((buf[p] < 32) || (buf[p]>126))
79
                text[c] = '.';
80
              else
81
                text[c] = buf[p];
82
 
83
              printf( (c==15) ? " %02.2X" : (c == 8) ? "-%02.2X" : " %02.2X", buf[p]);
84
 
85
              if (c == 15)
86
                printf(" %s\n", text);
87
 
88
              pos++;
89
              p++;
90
            }
91
          }
92
 
93
          if (c = (pos & 0x0f)) {
94
 
95
            while (c < 16) {
96
              printf( (c == 8) ? "-  " : "   ");
97
              text[c] = ' ';
98
              c++;
99
            }
100
 
101
            printf(" %s\n", text);
102
          }
103
 
104
          if (feof(fp))
105
            break;
106
 
107
          printf("--more--");
108
          fflush(stdout);
109
 
110
          fgets(buf, 80, stdin);
111
          if (toupper(buf[0]) == 'Q')
112
            break;
113
        }
114
 
115
}
116
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.