Sujet : Re: Writing own source disk
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.cDate : 04. Jun 2024, 01:18:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3lmgq$3psv$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 03/06/2024 14:47, Ben Bacarisse wrote:
Michael S <already5chosen@yahoo.com> writes:
On Sun, 2 Jun 2024 12:54:17 +0100
Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>
Writing a prgram which writes its own source to standard output is a
standard programming problem. It's called a quine.
>
Is it named after Willard Van Orman Quine?
In honour of rather than after since "after" is usually used for
discoverers. It was Douglas Hofstadter who coined the term.
>
/* source for a quine */
#include "bbx_filesystem.h"
int cescape_filter(FILE *fpout, FILE *fpin)
{
/* left as a little excercise for the reader */
return 0;
}
int bbx_filesystem_quine(BBX_FileSystem *bbx_fs, const char *path_to_source, FILE *fp)
{
FILE *src_xml_fp;;
FILE *source_fp;
src_xml_fp = tmpfile();
bbx_filesystem_dump(bbx_fs, src_xml_fp);
fseek(src_xml_fp, 0, SEEK_SET);
source_fp = bbx_filesystem_fopen(bbx_fs, path_to_source, "r");
fprintf(source_fp, "char source[] = ");
cescape_filter(source_fp, src_xml_fp);
fprintf(source_fp, "\';\n");
bbx_filesystem_dump(bbx_fs, fp);
}
extern char source[];
void quine(void)
{
BBX_FileSystem *bbx_fs;
bbx_fs = bbx_filesystem();
bbx_filesystem_set(bbx_fs, source, BBX_FS_STRING);
bbx_filesystem_quine(bbx_fs, "/src/quine/source.c", stdout);
bbx_filesystem_kill(bbx_fs);
}
-- Check out Basic Algorithms and my other books:https://www.lulu.com/spotlight/bgy1mm