xsum.c File Reference

#include "stdio.h"
#include "stdlib.h"
#include "sys/types.h"
#include "unistd.h"
#include "fcntl.h"

Include dependency graph for xsum.c:

Go to the source code of this file.

Defines

#define _POSIX_SOURCE
#define O_RDONLY   0
#define O_BINARY   O_RDONLY

Typedefs

typedef unsigned char Uchar

Functions

void usage (int rc)
long sum32 (register long sum, register Uchar *x, int n)
int cr_purge (Uchar *buf, int n)
void process (char *s, int x)
 main (int argc, char **argv)

Variables

char * progname
static int ignore_cr
static Uchar Buf [16 *1024]


Define Documentation

#define _POSIX_SOURCE

Definition at line 23 of file xsum.c.

#define O_BINARY   O_RDONLY

Definition at line 40 of file xsum.c.

Referenced by main().

#define O_RDONLY   0

Definition at line 37 of file xsum.c.


Typedef Documentation

typedef unsigned char Uchar

Definition at line 60 of file xsum.c.


Function Documentation

int cr_purge ( Uchar buf,
int  n 
)

Definition at line 152 of file xsum.c.

References b.

Referenced by process().

00154 {
00155         register Uchar *b, *b1, *be;
00156         b = buf;
00157         be = b + n;
00158         while(b < be)
00159                 if (*b++ == '\r') {
00160                         b1 = b - 1;
00161                         while(b < be)
00162                                 if ((*b1 = *b++) != '\r')
00163                                         b1++;
00164                         return b1 - buf;
00165                         }
00166         return n;
00167         }

Here is the caller graph for this function:

main ( int  argc,
char **  argv 
)

Definition at line 208 of file xsum.c.

References ignore_cr, O_BINARY, O_RDONLY, process(), progname, and usage().

00210 {
00211         int x;
00212         char *s;
00213         static int rc;
00214 
00215         progname = *argv;
00216         argc = argc;            /* turn off "not used" warning */
00217         s = *++argv;
00218         if (s && *s == '-') {
00219                 switch(s[1]) {
00220                         case '?':
00221                                 usage(0);
00222                         case 'r':
00223                                 ignore_cr = 1;
00224                         case '-':
00225                                 break;
00226                         default:
00227                                 fprintf(stderr, "invalid option %s\n", s);
00228                                 usage(1);
00229                         }
00230                 s = *++argv;
00231                 }
00232         if (s) do {
00233                 x = open(s, O_RDONLY|O_BINARY);
00234                 if (x < 0) {
00235                         fprintf(stderr, "%s: can't open %s\n", progname, s);
00236                         rc |= 1;
00237                         }
00238                 else
00239                         process(s, x);
00240                 }
00241                 while(s = *++argv);
00242         else {
00243                 process("/dev/stdin", fileno(stdin));
00244                 }
00245         return rc;
00246         }

Here is the call graph for this function:

void process ( char *  s,
int  x 
)

Definition at line 177 of file xsum.c.

References close(), cr_purge(), ignore_cr, read(), and sum32().

Referenced by main().

00185 {
00186         register int n;
00187         long fsize, sum;
00188 
00189         sum = 0;
00190         fsize = 0;
00191         while((n = read(x, (char *)Buf, sizeof(Buf))) > 0) {
00192                 if (ignore_cr)
00193                         n = cr_purge(Buf, n);
00194                 fsize += n;
00195                 sum = sum32(sum, Buf, n);
00196                 }
00197         sum &= 0xffffffff;
00198         if (n==0)
00199                 printf("%s\t%lx\t%ld\n", s, sum & 0xffffffff, fsize);
00200         else { perror(s); }
00201         close(x);
00202         }

Here is the call graph for this function:

Here is the caller graph for this function:

long sum32 ( register long  sum,
register Uchar x,
int  n 
)

Definition at line 69 of file xsum.c.

Referenced by process().

00071 {
00072         register Uchar *xe;
00073         static long crc_table[256] = {
00074                 0,              151466134,      302932268,      453595578,
00075                 -9583591,       -160762737,     -312236747,     -463170141,
00076                 -19167182,      -136529756,     -321525474,     -439166584,
00077                 28724267,       145849533,      330837255,      448732561,
00078                 -38334364,      -189783822,     -273059512,     -423738914,
00079                 47895677,       199091435,      282375505,      433292743,
00080                 57448534,       174827712,      291699066,      409324012,
00081                 -67019697,      -184128295,     -300991133,     -418902539,
00082                 -76668728,      -227995554,     -379567644,     -530091662,
00083                 67364049,       218420295,      369985021,      520795499,
00084                 95791354,       213031020,      398182870,      515701056,
00085                 -86479645,      -203465611,     -388624945,     -506380967,
00086                 114897068,      266207290,      349655424,      500195606,
00087                 -105581387,     -256654301,     -340093543,     -490887921,
00088                 -134039394,     -251295736,     -368256590,     -485758684,
00089                 124746887,      241716241,      358686123,      476458301,
00090                 -153337456,     -2395898,       -455991108,     -304803798,
00091                 162629001,      11973919,       465560741,      314102835,
00092                 134728098,      16841012,       436840590,      319723544,
00093                 -144044613,     -26395347,      -446403433,     -329032703,
00094                 191582708,      40657250,       426062040,      274858062,
00095                 -200894995,     -50223749,      -435620671,     -284179369,
00096                 -172959290,     -55056048,      -406931222,     -289830788,
00097                 182263263,      64630089,       416513267,      299125861,
00098                 229794136,      78991822,       532414580,      381366498,
00099                 -220224191,     -69691945,      -523123603,     -371788549,
00100                 -211162774,     -93398532,      -513308602,     -396314416,
00101                 201600371,      84090341,       503991391,      386759881,
00102                 -268078788,     -117292630,     -502591472,     -351526778,
00103                 258520357,      107972019,      493278217,      341959839,
00104                 249493774,      131713432,      483432482,      366454964,
00105                 -239911657,     -122417791,     -474129349,     -356881235,
00106                 -306674912,     -457198666,     -4791796,       -156118374,
00107                 315967289,      466778031,      14362133,       165418627,
00108                 325258002,      442776452,      23947838,       141187752,
00109                 -334573813,     -452329571,     -33509849,      -150495567,
00110                 269456196,      419996626,      33682024,       184992510,
00111                 -278767779,     -429561909,     -43239823,      -194312473,
00112                 -288089226,     -405591072,     -52790694,      -170046772,
00113                 297394031,      415166457,      62373443,       179343061,
00114                 383165416,      533828478,      81314500,       232780370,
00115                 -373594127,     -524527769,     -72022307,      -223201717,
00116                 -401789990,     -519431348,     -100447498,     -217810336,
00117                 392228803,      510123861,      91131631,       208256633,
00118                 -345918580,     -496598246,     -110112096,     -261561802,
00119                 336361365,      487278339,      100800185,      251995695,
00120                 364526526,      482151208,      129260178,      246639108,
00121                 -354943065,     -472854735,     -119955829,     -237064675,
00122                 459588272,      308539942,      157983644,      7181066,
00123                 -469170519,     -317835713,     -167286907,     -16754925,
00124                 -440448382,     -323454444,     -139383890,     -21619912,
00125                 450006683,      332774925,      148697015,      31186721,
00126                 -422325548,     -271261118,     -186797064,     -36011154,
00127                 431888077,      280569435,      196114401,      45565815,
00128                 403200742,      286222960,      168180682,      50400092,
00129                 -412770561,     -295522711,     -177471533,     -59977915,
00130                 -536157576,     -384970002,     -234585260,     -83643454,
00131                 526853729,      375396087,      225003341,      74348507,
00132                 517040714,      399923932,      215944038,      98057200,
00133                 -507728301,     -390357307,     -206385281,     -88735767,
00134                 498987548,      347783818,      263426864,      112501670,
00135                 -489671163,     -338229613,     -253864151,     -103192641,
00136                 -479823314,     -362722632,     -244835582,     -126932076,
00137                 470531639,      353144481,      235265819,      117632909
00138                 };
00139 
00140         xe = x + n;
00141         while(x < xe)
00142                 sum = crc_table[(sum ^ *x++) & 0xff] ^ (sum >> 8 & 0xffffff);
00143         return sum;
00144         }

Here is the caller graph for this function:

void usage ( int  rc  ) 

Definition at line 52 of file xsum.c.

References progname.

Referenced by main().

00054 {
00055         fprintf(stderr, "usage: %s [-r] [file [file...]]\n\
00056         option -r ignores carriage return characters\n", progname);
00057         exit(rc);
00058         }

Here is the caller graph for this function:


Variable Documentation

Uchar Buf[16 *1024] [static]

Definition at line 169 of file xsum.c.

int ignore_cr [static]

Definition at line 46 of file xsum.c.

Referenced by main(), and process().

char* progname

Definition at line 45 of file xsum.c.

Referenced by main(), startproc(), and usage().


Generated on Sun Mar 4 15:11:30 2007 for Scilab [trunk] by  doxygen 1.5.1