Guest User

wc.c by FrozenVoid

a guest
Aug 8th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. /* WORD COUNT UTILITY
  2. wc.c by FrozenVoid
  3. licensed under UFIL1.02 http://pastebin.com/L3p9XK3T
  4. @..\dmc  -gg -Nc -Jm  -o+all -o-dv %1.c -o%1.exe
  5.  
  6. */
  7. #include "void.h" // http://pastebin.com/L4bT9u1b
  8.  
  9. STDSTART
  10. u1 anum[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  11. u1 at[256]={0};u4 i=0;
  12. for(i=0;i<(sizeof(anum));i++){at[anum[i]]=1;}
  13. if(argc<2){epr("Syntax: wc filename");exit(1);}
  14. u4 fsize;u1* c=getfile(argv[1],&fsize);
  15. if(!fsize||!c){epr("File %s cannot be opened or empty",argv[1]);exit(2);};
  16. u8 exstart=rdtsc();//start of operation
  17. u4 count=0;u4 old=0,state=0;
  18. for(i=0;i<fsize;i++){
  19. state=at[c[i]];//if 1^1 0^0 same word.
  20. count+=(old^state);old=state;};
  21. count>>=1;
  22. u8 endbench=rdtsc()-exstart;
  23. pr("%"PRIu32" words in file %s \n cycles spent:%"PRIu64,count,argv[1],endbench);
  24.  
  25. STDEND
Advertisement
Add Comment
Please, Sign In to add comment