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

Utility I wrote for GNU+Linux

Name: Anonymous 2012-02-13 3:19

It's a small utility like cat or sed that can be used on Linux systems. It's called why. Licensed under the GPLv3 (or later).

Here is the code (save it in `why.c'):
#include <stdio.h>

void main()
{
printf("Fuck you, that's why.\n");

}


Install with:
gcc -o why why.c ;sudo cp ./why /bin/why

Name: Anonymous 2012-02-16 18:21

I hacked it a little to include colors! Still under GPLv3, of course. Hope you like it.

Save to why.c:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>

int AttExch[] = {0,1,2,3,4,7,8};
int ColExch[] = {0,1,2,3,4,5,6,7};
typedef enum _Attr
{
Reset = 0,
Bright = 1,
Dim = 2,
Underline = 3,
Blink = 4,
Reverse = 7,
Hidden = 8,
}Attr;

typedef enum _Colors
{
Black = 0,
Red     = 1,
Green = 2,
Yellow = 3,
Blue = 4,
Magenta = 5,
Cyan = 6,
White = 7,
}Colors;


typedef struct _ColorCodes{
        Attr Attribute;
        Colors Foreground;
        Colors Background;
} ColorCodes;

/* Prototypes */
void textcolor(ColorCodes codes);
void RandomColors();
int * FillRandArray(int);
Attr RevAttr(int);
Colors RevColor(int);


int main()
{
        const char message[] = "Fuck you, that's why.";
        ColorCodes cc;
        int length = strlen(message);
        int * arr = (int *)FillRandArray(length);

        int i = 0, average = 0, secaver = 0;

        cc.Attribute = Bright;
        cc.Foreground = Red;
        cc.Background = Blue;
        textcolor(cc);

        i = 0;
        while(i < length)
        {
                if( i == length)
                {
                        free(arr);
                        // Uncomment the following lines and
                        // comment the break to loop forever.
                        //arr = (int *)FillRandArray(length);
                        //i=0;
                        break;
                }
                cc.Attribute = RevAttr(AttExch[arr[i] % 6]);
                cc.Foreground = RevColor(ColExch[0]);  // arr[i] % 7]); Only black
                cc.Background = RevColor(ColExch[arr[i] % 6] + 1); // no black
                textcolor(cc);
                //printf(" - [%d - %d - %d]\n",cc.Attribute,cc.Background,cc.Foreground);
                printf("%c", message[i]);
                i++;
        }

        cc.Attribute = Reset;
        cc.Foreground = White;
        cc.Background = Black;
        textcolor(cc);

        printf("\n");
        return 0;
}

void textcolor(ColorCodes codes)
{
        char* command = (char*)malloc(50 * sizeof(char));
        /* Command is the control command to the terminal */

        sprintf(command, "%c[%d;%d;%dm", 0x1B, codes.Attribute, codes.Foreground + 30, codes.Background + 40);

        printf("%s", command);
        free(command);
}

void RandomColors()
{
        int derp = 44;
        srand ((unsigned int) time(NULL) * derp );

}

int * FillRandArray(int len)
{
        int * Arr = (int*) malloc(len * sizeof(int));
        int * key = (int*) malloc(len * sizeof(int));
        int i;
        int temp;
        double temp2;

        srand ((unsigned int) time(NULL) );

        for(i = 0; i <= len - 2; i++)
        {
                 temp2 = pow((double)(rand() % 256),(rand() % 3) + 1);
                 temp = (int) ((double)((rand() >> 16) ^ ~(int)temp2));
                 Arr[i] = abs(temp) % 255;

                 /*temp2 = pow((double)(rand() % 256),(rand() % 3) + 1);
                 temp = (int) ((double)((rand() >> 16) ^ ~(int)temp2));
                 key[i] = abs(temp) % 255;

                Arr[i] = ( ( (Arr[i] * rand() ) % 255) >> 13) ^ ( ( (key[i]* rand() ) % 255) << 13 );
                Arr[i] = abs(Arr[i]) % 1023 * 1023;
                Arr[i] = ( ( (Arr[i] * rand() ) % 255) << 13) ^ ( ( (key[i]* rand() ) % 255) >> 13 );
                Arr[i] = abs(Arr[i]) % 767 * 767;
                Arr[i] = ( ( (Arr[i] * rand() ) % 255) >> 13) ^ ( ( (key[i]* rand() ) % 255) << 13 );
                Arr[i] = abs(Arr[i]) % 511 * 511;
                Arr[i] = ( ( (Arr[i] * rand() ) % 255) << 13) ^ ( ( (key[i]* rand() ) % 255) >> 13 );
                Arr[i] = abs(Arr[i]) % 255;
                */
        }

        return Arr;
}

Colors RevColor(int a)
{
        switch(a)
        {
        case 0:
                return Black;
        case 1:
                return Red;
        case 2:
                return Green;
        case 3:
                return Yellow;
        case 4:
                return Blue;
        case 5:
                return Magenta;
        case 6:
                return Cyan;
        case 7:
                return White;
        default:
                return Blue;

        }
}

Attr RevAttr(int a)
{
        switch(a)
        {
        case 0:
                return Reset;
        case 1:
                return Bright;
        case 2:
                return Dim;
        case 3:
                return Underline;
        case 4:
                return Blink;
        case 7:
                return Reverse;
        case 8:
                return Hidden;
        default:
                return Bright;
        }
}


Install with the following:
gcc -lm -o why why.c; sudo cp ./why /bin/why && echo "Done Installing!"

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