Re: C23 thoughts and opinions

Liste des GroupesRevenir à cl c 
Sujet : Re: C23 thoughts and opinions
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.c
Date : 01. Jun 2024, 01:53:02
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3drdg$2f1pg$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
User-Agent : Mozilla Thunderbird
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.
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Date Sujet#  Auteur
31 May 24 * Re: C23 thoughts and opinions73bart
31 May 24 +* Re: C23 thoughts and opinions67Michael S
31 May 24 i+* Re: C23 thoughts and opinions65Michael S
31 May 24 ii`* Re: C23 thoughts and opinions64Michael S
31 May 24 ii `* Re: C23 thoughts and opinions63bart
31 May 24 ii  `* Re: C23 thoughts and opinions62Michael S
31 May 24 ii   `* Re: C23 thoughts and opinions61bart
31 May 24 ii    +* Re: C23 thoughts and opinions39jak
31 May 24 ii    i+- Re: C23 thoughts and opinions1bart
6 Jun 24 ii    i`* Re: C23 thoughts and opinions37BGB-Alt
7 Jun 24 ii    i +* Re: C23 thoughts and opinions32Lawrence D'Oliveiro
7 Jun 24 ii    i i+* Re: C23 thoughts and opinions15BGB-Alt
8 Jun 24 ii    i ii`* Re: C23 thoughts and opinions14Lawrence D'Oliveiro
8 Jun 24 ii    i ii +* Re: C23 thoughts and opinions11BGB
8 Jun 24 ii    i ii i+- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
13 Jun 24 ii    i ii i`* Re: C23 thoughts and opinions9Bonita Montero
13 Jun 24 ii    i ii i `* Re: C23 thoughts and opinions8BGB
14 Jun 24 ii    i ii i  `* Re: C23 thoughts and opinions7Bonita Montero
14 Jun 24 ii    i ii i   `* Re: C23 thoughts and opinions6BGB
14 Jun 24 ii    i ii i    +* Re: C23 thoughts and opinions2Bonita Montero
14 Jun 24 ii    i ii i    i`- Re: C23 thoughts and opinions1BGB
15 Jun 24 ii    i ii i    `* Re: C23 thoughts and opinions3Lawrence D'Oliveiro
16 Jun 24 ii    i ii i     `* Re: C23 thoughts and opinions2BGB
16 Jun 24 ii    i ii i      `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
9 Jun 24 ii    i ii +- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
9 Jun 24 ii    i ii `- Re: C23 thoughts and opinions1Michael S
8 Jun 24 ii    i i`* Re: C23 thoughts and opinions16Malcolm McLean
8 Jun 24 ii    i i +* Re: C23 thoughts and opinions14BGB
9 Jun 24 ii    i i i`* Re: C23 thoughts and opinions13Michael S
9 Jun 24 ii    i i i +* Re: C23 thoughts and opinions11bart
9 Jun 24 ii    i i i i`* Re: C23 thoughts and opinions10Michael S
9 Jun 24 ii    i i i i +- Re: C23 thoughts and opinions1Michael S
9 Jun 24 ii    i i i i +* Re: C23 thoughts and opinions7bart
9 Jun 24 ii    i i i i i`* Re: C23 thoughts and opinions6Michael S
9 Jun 24 ii    i i i i i `* Re: C23 thoughts and opinions5bart
9 Jun 24 ii    i i i i i  `* Re: C23 thoughts and opinions4Michael S
9 Jun 24 ii    i i i i i   `* Re: C23 thoughts and opinions3bart
9 Jun 24 ii    i i i i i    `* Re: C23 thoughts and opinions2Michael S
10 Jun 24 ii    i i i i i     `- Re: C23 thoughts and opinions1bart
11 Jun 24 ii    i i i i `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
10 Jun 24 ii    i i i `- Re: C23 thoughts and opinions1BGB
9 Jun 24 ii    i i `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
7 Jun 24 ii    i `* Re: C23 thoughts and opinions4BGB
7 Jun 24 ii    i  `* Re: C23 thoughts and opinions3Lawrence D'Oliveiro
7 Jun 24 ii    i   `* Re: C23 thoughts and opinions2BGB
7 Jun 24 ii    i    `- Re: C23 thoughts and opinions1BGB
31 May 24 ii    +* Re: C23 thoughts and opinions19bart
1 Jun 24 ii    i+* Re: C23 thoughts and opinions4jak
1 Jun 24 ii    ii`* Re: C23 thoughts and opinions3bart
1 Jun 24 ii    ii `* Re: C23 thoughts and opinions2jak
2 Jun 24 ii    ii  `- Re: C23 thoughts and opinions1Tim Rentsch
1 Jun 24 ii    i+* Re: C23 thoughts and opinions10bart
1 Jun 24 ii    ii+* Re: C23 thoughts and opinions5Tim Rentsch
1 Jun 24 ii    iii+- Re: C23 thoughts and opinions1Michael S
2 Jun 24 ii    iii`* Re: C23 thoughts and opinions3Tim Rentsch
6 Jun 24 ii    iii `* objcopy -I binary etc... Was: C23 thoughts and opinions2Michael S
6 Jun 24 ii    iii  `- Re: objcopy -I binary etc... Was: C23 thoughts and opinions1Tim Rentsch
1 Jun 24 ii    ii+- Re: C23 thoughts and opinions1David Brown
1 Jun 24 ii    ii+* Re: C23 thoughts and opinions2bart
4 Jun 24 ii    iii`- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
4 Jun 24 ii    ii`- Re: Correct objcopy Usage (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
1 Jun 24 ii    i`* Re: C23 thoughts and opinions4Michael S
2 Jun 24 ii    i +* Re: C23 thoughts and opinions2bart
2 Jun 24 ii    i i`- Re: C23 thoughts and opinions1Michael S
6 Jun 24 ii    i `- Re: C23 thoughts and opinions1Michael S
1 Jun 24 ii    `* Re: C23 thoughts and opinions2Michael S
2 Jun 24 ii     `- Re: C23 thoughts and opinions1Tim Rentsch
31 May 24 i`- Re: C23 thoughts and opinions1bart
31 May 24 +- Re: C23 thoughts and opinions1Kaz Kylheku
31 May 24 +- Re: C23 thoughts and opinions1Malcolm McLean
1 Jun 24 `* Re: C23 thoughts and opinions3Malcolm McLean
1 Jun 24  `* Re: C23 thoughts and opinions2bart
1 Jun 24   `- Re: C23 thoughts and opinions1Malcolm McLean

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal