TinyChan

Topic: boners.cpp

+Anonymous A12.6 years ago #32,167

/****************************************************************************************
* usage: boners.exe <input_file> [-o output_filename] [-c] [-l num_of_blocks_in_1_line] *
* -c is for turning on cheapAssMode where RGB code only has 4 chars                     *
* TRUE and ORIGINAL code. DO NOT STEAL!                                                 *
****************************************************************************************/

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

char lowercase(char input) {
	return (input > 64 && input < 91) ? input + 32 : input;
}

int main(int argc, const char * argv[])
{
	if (argc < 2) {
		printf("At least give me the input file, fucking idiot.\n");
		return 9001;
	}
	
//Read all params
	const char* srzFileName = NULL;
	char* trgFileName = NULL;
	char cheapAssMode = 0;
	int blockPerLine = 0;
	
	int argindex = 1;
	const char* arg;
	while (argindex < argc) {
		arg = argv[argindex];
		if (strcmp(arg, "-c") == 0)
			cheapAssMode = 1;
		else if (strcmp(arg, "-o") == 0 && argindex+1 < argc)
			trgFileName = (char*)argv[++argindex];
		else if (strcmp(arg, "-l") == 0 && argindex+1 < argc)
			blockPerLine = atoi(argv[++argindex]);
		else if (srzFileName == NULL)
			srzFileName = arg;
		argindex++;
	}
	
	if (srzFileName == NULL) {
		printf("At least give me the input file, fucking idiot.\n");
		return 9001;
	}

//Check if source file is accessible
	FILE *srzFile = fopen(srzFileName, "r");
	if (srzFile == NULL) {
		printf("Unserious fraud input file detected.\n");
		return 9002;
	}
	
//Generate output filename if none is provided
	char trgFileNameNeedFreed = 0;
	if (trgFileName == NULL) {
		trgFileNameNeedFreed = 1;
		char* trgFileNamePostfix = "-boners";
		size_t trgFileNameLength = strlen(srzFileName) + strlen(trgFileNamePostfix);
		trgFileName = (char*)calloc(trgFileNameLength+1, sizeof(char));
		
		char* dot = strrchr(argv[1], '.');
		if (dot==NULL)
			sprintf(trgFileName, "%s%s", srzFileName, trgFileNamePostfix);
		else {
			size_t extLen = strlen(dot);
			char ext[extLen+1];
			strncpy(ext, dot, extLen);
			ext[extLen] = '\0';
			size_t fileNameLen = dot - argv[1];
			char fileName[fileNameLen+1];
			strncpy(fileName, srzFileName, fileNameLen);
			fileName[fileNameLen] = '\0';
			sprintf(trgFileName, "%s%s%s", fileName, trgFileNamePostfix, ext);
		}
		trgFileName[trgFileNameLength] = '\0';
	}
	
//Check if can create output file
	FILE *trgFile = fopen(trgFileName,"w");
	if (trgFile == NULL) {
		printf("Stop being dead and start creating output file.\n");
		return 9003;
	}

//Start printing
	int error = 0;
	char *block = "█";
	size_t blockLen = strlen(block);
	char r[3];
	char g[3];
	char b[3];
	size_t blockCount = 0;
	size_t totalLenCount = 0;
	size_t byteLen = cheapAssMode ? 1 : 2;
	size_t rgbLen = 3 * byteLen;
	char rgb[rgbLen+1];
	char prevRgb[rgbLen+1];
	char firstVal = 0;
	memset(prevRgb, 0, rgbLen+1);
	
	fprintf(trgFile, "[code]");
	totalLenCount += 6;
	
	while (!feof(srzFile)) {
		memset(r, 0, 3);
		memset(g, 0, 3);
		memset(b, 0, 3);
		fscanf(srzFile, "%s %s %s", r, g, b);
		if (ferror(srzFile)) {
			error = 9004;
			break;
		}
		
		if (cheapAssMode) {
			sprintf(rgb, "%c%c%c", lowercase(r[0]), lowercase(g[0]), lowercase(b[0]));
			rgb[3] = '\0';
		} else {
			sprintf(rgb, "%c%c%c%c%c%c", lowercase(r[0]), lowercase(r[1]), lowercase(g[0]), lowercase(g[1]), lowercase(b[0]), lowercase(b[1]));
			rgb[6] = '\0';
		}
		
		if (strcmp(rgb, prevRgb) != 0) {
			if (firstVal == 0)
				firstVal = 1;
			else {
				fprintf(trgFile, "[/color]");
				totalLenCount += 8;
				if (blockPerLine > 0 && blockCount >= blockPerLine) {
					fprintf(trgFile, "\n");
					blockCount = 0;
					totalLenCount++;
				}
			}
			fprintf(trgFile, "[color=#%s]", rgb);
			totalLenCount += 9;
			totalLenCount += rgbLen;
			
			strcpy(prevRgb, rgb);
			prevRgb[rgbLen] = '\0';
		}
		
		if (blockPerLine > 0 && blockCount >= blockPerLine) {
			fprintf(trgFile, "\n");
			blockCount = 0;
			totalLenCount++;
		}
		fprintf(trgFile, "%s", block);
		blockCount++;
		totalLenCount += blockLen;
	}
	
	if (error) {
//Fission mailed
		printf("CHECK. THE. GRAMMAR. OF. YOUR. INPUT. FILE. Jesus... ... ... ...\n");
	} else {
//Success!
		if (firstVal > 0) {
			fprintf(trgFile, "[/color]");
			totalLenCount += 8;
		}
		fprintf(trgFile, "
");
totalLenCount += 7;
printf("Outputted to %s. Total length: %lu.\nNow how about some donations, you ungrateful piece of shit?\n", trgFileName, totalLenCount);
}

//Clean up
fclose(srzFile);
fclose(trgFile);
if (trgFileNameNeedFreed)
free(trgFileName);

return error ? error : 0;
}[/code]

+ducky !MwWb.dJjRc12.6 years ago, 6 hours later[T] [B] #370,483

nigga u stole

·Anonymous A (OP) — 12.6 years ago, 4 hours later, 11 hours after the original post[T] [B] #370,535

@previous (ducky !MwWb.dJjRc)
nigga u high

+On !Uvm54ORbmo12.6 years ago, 9 hours later, 20 hours after the original post[T] [B] #370,629

> boners.cpp
> boners cp

pedo detected

·Anonymous A (OP) — 12.6 years ago, 11 hours later, 1 day after the original post[T] [B] #370,948

@previous (On !Uvm54ORbmo)
Unserious fraud file extension.

Start a new topic to continue this conversation.
Or browse the latest topics.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.



Please familiarise yourself with the rules and markup syntax before posting.