Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Cats

Name: Anonymous 2011-09-26 2:54

Tell me about your cat(s), /prog/.

Name: Anonymous 2011-09-26 3:08

$ whatis cat
cat (1)         - concatenate files and print on the standard output
$

Name: Anonymous 2011-09-26 3:30

my cat hsa a long neck and he picks fish out of the water w/ his beak.

Name: Anonymous 2011-09-26 3:58

>>2

LoseThos does not have streams, more or less.  It's supposed to be for recreational programming.  Streams and pipes are more often for admins.  In the actual act of programming and debugging, do you find you use them?  For video games, you don't.  For more adult things, you use printf() and cmd line, but pipes?  LoseThos has printf.

asm is a mark of IQ
interrupts are a mark of IQ
pipes are a mark of IQ
pipes and regexs are a mark of IQ
spelling and grammar is a mark of IQ
wit is not a mark of IQ -- wisdom.

They are pretty-much IQ by common concensus.

Name: Anonymous 2011-09-26 3:58

wisdom is not IQ

Name: Anonymous 2011-09-26 4:25

Chen

Name: Anonymous 2011-09-26 4:26

I opened the window and the sun came in, my cat sits on the table soaking up the sun

Name: Cudder !MhMRSATORI!FBeUS42x4uM+kgp 2011-09-26 4:42

https://gist.github.com/665971
All the cats you want.

Here's Anonix cat:
/* @cat.c */
/* NOTE: GNU's cat will not cat a file into itself. Should we check for this?
   Possibility of infinite loop here. POSIX doesn't specify what happens if
   standard input happens to be standard output (cat to temp. file and then
   write that to the output? don't write what was already written?) */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define CATBUF_SIZE 65536 /* increase this if you want OMG MOAR SPEED! */

char catbuf[CATBUF_SIZE];

int main(int argc, char** argv) {
 int uflag = 0, retval = 0, i = 1, c;
 FILE *input;

 while((c=getopt(argc,argv,"u"))!=-1)
  if(c=='u') {
   uflag=1;
   retval=setvbuf(stdout,NULL,_IONBF,0);
  } else {
   fprintf(stderr,"usage: %s [-u] file...\n",argv[0]);
   return 1;
  }
 if(optind>=argc) { /* catting stdin */
  input=stdin;
  goto cat_stdin;
 }
 i=optind;
 while(argv[i]) {
  int l;
  if(strcmp(argv[i],"-")) {
   if(!(input=fopen(argv[i++],"rb"))) {
    fprintf(stderr,"%s: could not open %s: %s\n",argv[0],argv[i-1],strerror(errno));
    retval=1;
    continue;
   }
  } else {
   input=stdin;
   i++;
  }
 cat_stdin:
  if(uflag)
   retval|=setvbuf(input, NULL, _IONBF, 0);

  while(l=fread(catbuf,1,CATBUF_SIZE,input)) {
   if(fwrite(catbuf,1,l,stdout)!=l) {
    fprintf(stderr,"%s: error writing to stdout: %s\n",argv[0],strerror(errno));
    retval=1;
    break;
   }
  }
  if(ferror(input))
   fprintf(stderr,"%s: error reading %s: %s\n",argv[0],argv[i-1],strerror(errno));
  if(input!=stdin)
   retval|=fclose(input);
 }
 return retval;
}

Name: Anonymous 2011-09-26 4:52

>>8
It... isn't seriously reading the data into memory?
That's just fucking stupid.

Name: Anonymous 2011-09-26 4:57

>>9
They all do that.

Name: VIPPER 2011-09-26 5:13

>>8
That looks really messy.

Name: Anonymous 2011-09-26 8:25

>>11
Of course it is. Is C

Name: Anonymous 2011-09-26 8:51

Everything is messy under the hood. You just don't know it if you don't write in a low-level language.

Name: Anonymous 2011-09-26 8:58

>>13
In fact i do. I'm now in the greener pastures of dynamic languages

Name: FrozenVoid 2011-09-26 9:32

>>13
I tend to check asm output for each change to get the feel of what treachery each compiler tries to do. I don't program in asm, but i have the tables/opcode latencies and their args/call/regs and i can handle checking small functions very closely for optimization.

Name: Anonymous 2011-09-26 9:55

>one-width indentations
>space indentations
>lack of spaces in syntax
>having options in cat (this is POSIX invalid)
>putting the asterisks next to the base type
>taking more than ~10 lines for cat
PIG DISGUSTING

Name: Anonymous 2011-09-26 10:06

>>16

I was referring to >>8 by the way.

Here's a better version:

#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (i++ < argc) {
        f = fopen(argv[i], "rb");
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
    }
    return 0;
}


>waaaah, you don't have -e!
Use printf. This is not cat's purpose.

>waaaah, you don't have -n!
Use printf. This is not cat's purpose.

>waaaah, you don't have --squeeze-blank/--show-tabs/--show-nonprinting/--gnu-bloat-option-frice!
Fuck you.

Name: Anonymous 2011-09-26 10:15

>>17
#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (i++ < argc) {
        f = fopen(argv[i], "rb");
        if (!f) {
            fprintf("cat: error opening %s", argv[i]);
            return 1;
        }
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
    }
    return 0;
}

Name: Anonymous 2011-09-26 10:15

>>18
#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (i++ < argc) {
        f = fopen(argv[i], "rb");
        if (!f) {
            fprintf(stderr, "cat: error opening %s", argv[i]);
            return 1;
        }
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
    }
    return 0;
}

Name: Anonymous 2011-09-26 10:16

>>18

Fixed segfaulting loop.

#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (++i < argc) {
        f = fopen(argv[i], "rb");
        if (!f) {
            fprintf(stderr, "cat: error opening %s", argv[i]);
            return 1;
        }
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
    }
    return 0;
}

Name: Anonymous 2011-09-26 10:16

>>20

Newlines are nice.

#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (++i < argc) {
        f = fopen(argv[i], "rb");
        if (!f) {
            fprintf(stderr, "cat: error opening %s\n", argv[i]);
            return 1;
        }
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
    }
    return 0;
}

Name: Anonymous 2011-09-26 10:19

>>21

Flush your buffers between files.

#include <stdio.h>
int main(int argc, char **argv) {
    int i = 0, c;
    FILE *f = stdin;
    if (argc == 1)
        goto no_arguments;
    while (++i < argc) {
        f = fopen(argv[i], "rb");
        if (!f) {
            fprintf(stderr, "cat: error opening %s\n", argv[i]);
            return 1;
        }
        no_arguments:
        while ((c = fgetc(f)) != EOF)
            putchar(c);
        fflush(stdout);
    }
    return 0;
}

Name: Anonymous 2011-09-26 10:21

>having options in cat (this is POSIX invalid)

http://pubs.opengroup.org/onlinepubs/009695399/utilities/cat.html

OPTIONS
The cat utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.

The following option shall be supported:

-u Write bytes from the input file to the standard output without delay as each is read.

Name: Anonymous 2011-09-26 10:22

>>23
What if I have a file named ``-u''?

Name: Anonymous 2011-09-26 10:23

#!/usr/bin/perl
print while <>;

Name: Anonymous 2011-09-26 10:26

mercury tmp # time dd if=/dev/zero bs=4096 count=1048576 | cat > /dev/null
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 1.77577 s, 2.4 GB/s

real    0m1.776s
user    0m0.218s
sys     0m1.576s
mercury tmp # time dd if=/dev/zero bs=4096 count=1048576 | ./a.out > /dev/null
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 59.5882 s, 72.1 MB/s

real    0m59.590s
user    0m57.176s
sys     0m2.389s


I do wonder why GNU cat is so much faster than my cat.

Name: Anonymous 2011-09-26 10:26

>>24

you can use ``./-u''. I was so confused this one time I had to delete a file that began with a hyphen.

Name: Anonymous 2011-09-26 10:28

>>24
cat -- -u

http://pubs.opengroup.org/onlinepubs/009604499/basedefs/xbd_chap12.html

Guideline 10:
The argument -- should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character. The -- argument should not be used as an option or as an operand.
--

And if you're wondering "what if I have a file named '--'", that would be cat -- --.

>>17-22
These are going to be slow as fuck because they're all reading and writing one char at a time.

Name: Anonymous 2011-09-26 10:28

>>28
Oh, so that's why it can only do 72.1 MB/s. >>26

Name: Anonymous 2011-09-26 10:30

>>29
Time the Anonix version >>8. I bet it'll be at least twice as fast, if not more. GNU cat is doing some weird voodoo.

Name: Anonymous 2011-09-26 10:31

>>30
mercury tmp # cc -xc -Wall -Werror -Wextra -ansi -pedantic -
[code goes here lol]
cc1: warnings being treated as errors
<stdin>: In function 'main':
<stdin>:19:2: error: implicit declaration of function 'getopt'
<stdin>:27:5: error: 'optind' undeclared (first use in this function)
<stdin>:27:5: note: each undeclared identifier is reported only once for each function it appears in
<stdin>:48:3: error: suggest parentheses around assignment used as truth value
<stdin>:49:32: error: comparison between signed and unsigned integer expressions


Your code is invalid C.

Name: Anonymous 2011-09-26 10:49

>>31
Not mine. It compiles fine here.


$ cc cat.c
$ time dd if=/dev/zero bs=4096 count=1048576 | cat > /dev/null
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 1.65333 s, 2.6 GB/s

real    0m1.670s
user    0m0.196s
sys     0m3.096s
$ time dd if=/dev/zero bs=4096 count=1048576 | ./a.out > /dev/null
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 2.23426 s, 1.9 GB/s

real    0m2.237s
user    0m0.240s
sys     0m4.080s
$

Name: Anonymous 2011-09-26 10:52

>>32
That's because you're not using -Wall -Werror -Wextra -ansi -pedantic which is the minimum required to ensure good code.

Name: Anonymous 2011-09-26 11:03

>>33
Similarly, -O3 -ffast-math -march=native -mtune=native is required for benchmarks.

Name: Anonymous 2011-09-26 11:04

>>34
-O3 is bloat and cache-miss-happy. -ffast-math is unsafe. -march implicitly implies -mtune, making -mtune unnecessary.

Good flags:

-Wall -Werror -Wextra -ansi -pedantic -O2 -march=native

Name: Anonymous 2011-09-26 11:32

SUSSIX cat uses open, mmap and fstat.

I guess that's why it's so fast.

Name: Anonymous 2011-09-26 11:33

>>36
I wonder if cat could benefit from multi-threading.

Name: FrozenVoid 2011-09-26 11:50

>>37
Adding complexity is not justified just because you want that 5% speedup. You have to think about what you need to multithread, unlike some people who make 10 threads which eat up cpu time doing 1 threads work and decreasing OS performance.

Name: Anonymous 2011-09-26 12:15

>>17
if (argc == 1)
    goto no_arguments;


It's sort of like something in the PS3 supervisor's code:

if (gamec == 0)
    goto no_games;

Name: Anonymous 2011-09-26 12:17

>>37
>implying extra threads would make an I/O bound program go any faster

Name: Anonymous 2011-09-26 12:31

>>40
Obviously I would only spawn a new thread if there were several files on different hard drives and then only one per hard drive.

You probably don't know how this stuff works anyway.

Name: Anonymous 2011-09-26 12:34

Tell me about your toxoplasmosis, /prog/.

Name: Anonymous 2011-09-26 13:05

>>40
>of course it would you moron

Name: Anonymous 2011-09-26 13:50

>>37
You don't need that shit, it either works or doesn't. Those error messages broken down:
<stdin>:19:2: error: implicit declaration of function 'getopt'
Your system is not POSIX. getopt is in unistd.h.
(http://pubs.opengroup.org/onlinepubs/000095399/functions/getopt.html)
<stdin>:27:5: error: 'optind' undeclared (first use in this function)
Same thing.
<stdin>:48:3: error: suggest parentheses around assignment used as truth value
Not an error.
<stdin>:49:32: error: comparison between signed and unsigned integer expressions
Doesn't matter, it's only checking for equality between however many bytes read and written.

I should've stopped at the first error; compiling a POSIX utility on a non-POSIX system is already doing it wrong.

>>37
It's an inherently serial process. The only speedup possible is by reading/writing bigger chunks.

Name: Anonymous 2011-09-26 14:09

>>44
It's an inherently serial process. The only speedup possible is by reading/writing bigger chunks.
Nope.

Name: Anonymous 2011-09-26 14:17

>>8
0-65536
is it weird that it bothers me that this isn't 65535

Name: Anonymous 2011-09-26 14:19

>>44

You should learn to cast so you don't get such shitty errors.
If when you compile your code it spews out a bunch of warnings and errors you're a terrible person and you should feel bad.

Name: Anonymous 2011-09-26 14:22

>>47
Your an even more terrible person. Casting in such cases is only a way of asking the compiler to shut up; it doesn't magically makes the code correct.

Name: Anonymous 2011-09-26 14:29

>>48

Well played, Anon.

Name: FrozenVoid 2011-09-26 14:33

>>48
All pointers are equal size physically.

Name: Anonymous 2011-09-26 14:37

>>50
False. data pointers are one byte, cdata and xdata pointers are two bytes, a generic pointer is three bytes long.

Name: FrozenVoid 2011-09-26 14:45

>>51
1 byte size pointer? do you have only 255bytes of RAM

Name: Anonymous 2011-09-26 15:02

>>52
Perhaps he does, what are you, some kind of anti-low memory person?

Name: FrozenVoid 2011-09-26 15:06

>>53
No, just a normal 32-bit system user. I don't see char,int,long long or double having different pointer sizes(they are all 32-bit int pointers)

Name: Anonymous 2011-09-26 15:12

>>54
That's system specific.

Name: Anonymous 2011-09-26 15:12

Imagine if all you had was 1 byte of pointers. The amount of memory saved. Lower CPU usage. Safety. Green computing
Switch to TROLLGOL today to experience the benefits of 1-byte addressing. Enterprises can't go wrong with 60-year proven solution.

--TROLLGOL design commitee

Name: Anonymous 2011-09-26 15:40

>>56
No, we should divide memory space into segments. Each segment will have a 1 byte address, and then sub-segments will have their own addresses, and so on for sub-sub-segments. Then all addresses to bytes will be stores in a linked list of pointers. It's the future.

Name: Anonymous 2011-09-26 16:21

Name: Anonymous 2011-09-26 16:23

Hi! shut up!

Sorry, just testing.

Name: Anonymous 2011-09-26 16:31

EXPERT PROGRAMMER!testanotheryet another

OKAY!

Name: Anonymous 2011-09-26 17:12

I loved you so much, /prog/.

Name: Anonymous 2011-09-27 4:05

>>44
You're a fucking idiot. I'm on a POSIX system, but my CFLAGS restrict to the use of standard features only.

Name: Anonymous 2011-09-27 5:10

>>62
getopt is a standard feature, can't you read?
http://pubs.opengroup.org/onlinepubs/000095399/functions/getopt.html

Name: Anonymous 2011-09-27 5:52

>>63
I'm not sure if it's -ansi or -pedantic, but one of them restricts GCC to only define standard C features, which basically undefines the macros GNU_SOURCE, POSIX_SOURCE, XOPEN_SOURCE, etc. etc. and therefore removes the availability of non-standard functions.

Name: Anonymous 2011-09-27 5:57

THIS IS NOT YOSPOS

Name: Anonymous 2011-09-27 6:03

>>64
It's -ansi, -pedantic only adds warnings.

Name: Anonymous 2011-09-27 6:55

>>62
implying POSIX is not standard
>>64,66
Then don't use that option, idiot.

Name: Anonymous 2011-09-27 7:28

>>67
Back to the imageboards.

Name: Anonymous 2011-09-27 14:03

>>68
hurr durr fuck you faggot

Name: sOoOoOoO random 2011-09-29 1:11

cat /dev/urandom xD

Don't change these.
Name: Email:
Entire Thread Thread List