Deutsch   English   Français   Italiano  
<v3euis$2o6gv$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!feeds.phibee-telecom.net!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: C23 thoughts and opinions
Date: Sat, 1 Jun 2024 11:53:15 +0100
Organization: A noiseless patient Spider
Lines: 199
Message-ID: <v3euis$2o6gv$1@dont-email.me>
References: <v2l828$18v7f$1@dont-email.me>
 <00297443-2fee-48d4-81a0-9ff6ae6481e4@gmail.com>
 <v2lji1$1bbcp$1@dont-email.me> <87msoh5uh6.fsf@nosuchdomain.example.com>
 <f08d2c9f-5c2e-495d-b0bd-3f71bd301432@gmail.com>
 <v2nbp4$1o9h6$1@dont-email.me> <v2ng4n$1p3o2$1@dont-email.me>
 <87y18047jk.fsf@nosuchdomain.example.com>
 <87msoe1xxo.fsf@nosuchdomain.example.com> <v2sh19$2rle2$2@dont-email.me>
 <87ikz11osy.fsf@nosuchdomain.example.com> <v2v59g$3cr0f$1@dont-email.me>
 <v30l15$3mcj6$1@dont-email.me> <v30lls$3mepf$1@dont-email.me>
 <v30sai$3rilf$1@dont-email.me> <v320am$1km5$1@dont-email.me>
 <v33ggr$e0ph$1@dont-email.me> <v34bne$i85p$1@dont-email.me>
 <v3758s$14hfp$1@raubtier-asyl.eternal-september.org>
 <v38of2$1gsj2$1@dont-email.me> <v39v87$1n7bk$1@dont-email.me>
 <20240530170836.00005fa0@yahoo.com> <v3a3k5$1ntrn$1@dont-email.me>
 <20240530180345.00003d9f@yahoo.com> <v3chc4$27uij$1@dont-email.me>
 <v3drdg$2f1pg$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 01 Jun 2024 12:53:16 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="91ec5d79126354b953c01cb00293891d";
	logging-data="2890271"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+UpNWwnLFrJsU4p+jln5Tt"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:UiwC1tMwQwEHYZVVF5JJy1rJJL4=
In-Reply-To: <v3drdg$2f1pg$1@dont-email.me>
Content-Language: en-GB
Bytes: 8826

On 01/06/2024 01:53, Malcolm McLean wrote:
> On 31/05/2024 13:55, bart wrote:
>> On 30/05/2024 16:03, Michael S wrote:
>>> On Thu, 30 May 2024 15:48:39 +0100
>>> bart <bc@freeuk.com> wrote:
>>>
>>>>
>>>> Where do the _binary_logo_bmp_start and ...-size symbols come from?
>>>> That is, how do they get into the object file.
>>>>
>>>
>>> objcopy generates names of the symbols from the name of input binary
>>> file. I would think that it is possible to change these symbols to
>>> something else, but I am not sure that it is possible withing the same
>>> invocation of objcopy. It certainly is possible with a second pass.
>>> Lawrence probably can give more authoritative answer.
>>> Or as a last resort you can RTFM.
>>>
>> I gave myself the simple task of incorporating the source text of 
>> hello.c into a program, and printing it out.
>>
>> Here's how builtin embedding worked using a feature of my older C 
>> compiler:
>>
>>    #include <stdio.h>
>>    #include <string.h>
>>
>>    char hello[] = strinclude("hello.c");
>>
>>    int main(void) {
>>        printf("hello =\n%s\n", hello);
>>        printf("strlen(hello) = %zu\n", strlen(hello));
>>        printf("sizeof(hello) = %zu\n", sizeof(hello));
>>    }
>>
>>
>> I build it and run it like this:
>>
>>    C:\c>bcc c
>>    Compiling c.c to c.exe
>>
>>    C:\c>c
>>    hello =
>>    #include "stdio.h"
>>
>>    int main(void) {
>>        printf("Hello, World!\n");
>>    }
>>
>>    strlen(hello) = 70
>>    sizeof(hello) = 71
>>
>>    C:\c>dir hello.c
>>    31/05/2024  13:48                70 hello.c
>>
>>
>> It just works; no messing about with objcopy parameters; no long 
>> unwieldy names; no link errors due to unsupported file formats; no 
>> problems with missing terminators for embedded text files imported as 
>> strings; no funny ways of getting size info.
>>
> Here's my solution. It's a bit more complicated.
> 
> 
> int bbx_write_source (const char *source_xml, char *path, const char 
> *source_xml_file, const char *source_xml_name)
> {
>      XMLDOC *doc = 0;
>      char error[1024];
>      char buff[1024];
>      XMLNODE *root;
>      XMLNODE *node;
>      const char *name;
>      FILE *fpout;
>      FILE *fpin;
>      int ch;
> 
>      doc = xmldocfromstring(source_xml, error, 1024);
>      if (!doc)
>      {
>          fprintf(stderr, "%s\n", error);
>          return -1;
>      }
>      root = xml_getroot(doc);
>      if (strcmp(xml_gettag(root), "FileSystem"))
>          return -1;
> 
>      if (!root->child)
>          return -1;
>      if (strcmp(xml_gettag(root->child), "directory"))
>          return -1;
> 
>      for (node = root->child->child; node != NULL; node = node->next)
>      {
>          if (!strcmp(xml_gettag(node), "file"))
>          {
>              name = xml_getattribute(node, "name");
>              snprintf(buff, 1024, "%s%s", path, name);
>              fpout = fopen(buff, "w");
>              if (!fpout)
>                  break;
>              fpin = file_fopen(node);
>              if (!fpin)
>                  break;
>              if (!strcmp(name, source_xml_file))
>              {
>                  char *escaped = texttostring(source_xml);
>                  if (!escaped)
>                      break;
>                  fprintf(fpout, "char %s[] = %s;\n", source_xml_name, 
> escaped);
>                  free(escaped);
>              }
>              else
>              {
>                 while ((ch = fgetc(fpin)) != EOF)
>                     fputc(ch, fpout);
>              }
>              fclose(fpout);
>              fclose(fpin);
>              fpout = 0;
>              fpin = 0;
>          }
>      }
>      if (fpin || fpout)
>      {
>          fclose(fpin);
>          fclose(fpout);
>          return -1;
>      }
> 
>      return 0;
> 
> }
> 
> It's leveraging the Baby X resource compiler, the xmparser, and my 
> filesystem programs. You can't include the source of a program in the 
> program as a C string, because then the source changes to include that 
> string. So what you do is this.
> 
> You first place a placeholder C source file containing a short dummy 
> string.
> The you convert the source to an XML file, and turn it into a string 
> with the Baby X Resource compiler. Then you drop the source into the
> file, removing the placeholder.
> 
> Then the program walks the file list, detects that file, and replaces it 
> with the xml string it has been passed.
> 
> And this system works, and it's an easy way of adding source output to
> ptograms. Of course the function now needs to be modified to walk the 
> entire tree recursively and I will need a makedirectory function. I've 
> got it to work for flat source directories.

Sorry, I don't understand what that does; what is the input and what is 
the output?

In the case of a very simple requirement of incorporating a text file 
into a C program as data, usually string data (which I have to say is 
much more common for me than doing anything with XML), how would a BBX 
solution work?

This doesn't work:

========== REMAINDER OF ARTICLE TRUNCATED ==========