MetaC
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
| Designed by | Jannes |
|---|---|
| Appeared in | 2024 |
| Dimensions | one-dimensional |
| Computational class | Meta Turing-complete |
| Reference implementation | See #Implementations |
| Influenced by | C, MetaGolfScript |
| File extension(s) | .c |
MetaC is a family of esoteric programming languages. Every single language in the family is a version of C.
Overview
The family consists of infinite amount of languages, named metaC-X, where X is a valid base64 string of any length. If a compiler for metaC-X is called with an empty file it will base64 decode X and compile the decoded string, else it will just compile the file.
Implementations
C
/**
* metagcc-n compiler
* Copyright (c) 2024 Jannes Althoff
*
* This software may be distributed under the terms of the BSD license.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Base64 encoding/decoding (RFC1341)
* Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
*/
static const unsigned char base64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* base64_decode - Base64 decode
* @src: Data to be decoded
* @len: Length of the data to be decoded
* @out_len: Pointer to output length variable
* Returns: Allocated buffer of out_len bytes of decoded data,
* or %NULL on failure
*
* Caller is responsible for freeing the returned buffer.
*/
unsigned char * base64_decode(const unsigned char *src, size_t len,
size_t *out_len)
{
unsigned char dtable[256], *out, *pos, block[4], tmp;
size_t i, count, olen;
int pad = 0;
memset(dtable, 0x80, 256);
for (i = 0; i < sizeof(base64_table) - 1; i++)
dtable[base64_table[i]] = (unsigned char) i;
dtable['='] = 0;
count = 0;
for (i = 0; i < len; i++) {
if (dtable[src[i]] != 0x80)
count++;
}
if (count == 0 || count % 4)
return NULL;
olen = count / 4 * 3;
pos = out = malloc(olen);
if (out == NULL)
return NULL;
count = 0;
for (i = 0; i < len; i++) {
tmp = dtable[src[i]];
if (tmp == 0x80)
continue;
if (src[i] == '=')
pad++;
block[count] = tmp;
count++;
if (count == 4) {
*pos++ = (block[0] << 2) | (block[1] >> 4);
*pos++ = (block[1] << 4) | (block[2] >> 2);
*pos++ = (block[2] << 6) | block[3];
count = 0;
if (pad) {
if (pad == 1)
pos--;
else if (pad == 2)
pos -= 2;
else {
/* Invalid padding */
free(out);
return NULL;
}
break;
}
}
}
*out_len = pos - out;
return out;
}
int
main(int argc, char ** argv)
{
if(argc > 2)
{
fprintf(stderr, "%s [file]\n", argv[0]);
return -1;
}
if(strlen(argv[0])>8)
{
size_t bytes;
unsigned char * byte_array = base64_decode(argv[0]+8, strlen(argv[0]+8), &bytes);
if(byte_array == NULL)
{
fprintf(stderr, "An error happend in base64 decode maybe your trying to programm in an invalid language", argv[0]);
return -1;
}
FILE * fp;
fp = fopen( argv[1],"r");
int empty = 0;
if ( fp == NULL )
{
empty = 1;
}
else
{
fseek (fp, 0, SEEK_END);
size_t size = ftell(fp);
if (0 == size)
{
empty = 1;
}
fclose(fp);
}
FILE * fp_tmp;
if((fp_tmp = fopen(".tmp_metagcc", "w")) == NULL)
{
fprintf(stderr, "Could not open tmpfile");
return -1;
}
else
{
if(empty)
{
fprintf(fp_tmp, "%.*s", bytes, byte_array);
fclose(fp_tmp);
system("gcc .tmp_metagcc");
system("rm .tmp_metagcc");
}
else
{
char * cmd = malloc(10 + strlen(argv[1]));
cmd[0] = 'g'; cmd[1] = 'c'; cmd[2] = 'c';
cmd[3] = ' '; cmd[4] = '\0';
system(strcat(cmd, argv[1]));
free(cmd);
}
}
}
return 0;
}
metaC-n
m