"Fossies" - the Fresh Open Source Software Archive

Member "darkstat-3.0.721/static/c-ify.c" (12 Jan 2022, 754 Bytes) of package /linux/privat/darkstat-3.0.721.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "c-ify.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.0.719_vs_3.0.721.

    1 /* Converts a textfile to a const char array with characters escaped. */
    2 #include <stdio.h>
    3 #include <stdlib.h>
    4 
    5 int
    6 main(int argc, char **argv)
    7 {
    8     int c, eol;
    9     if (argc != 2) {
   10         fprintf(stderr, "usage: %s name <infile >outfile.h\n",
   11             argv[0]);
   12         exit(EXIT_FAILURE);
   13     }
   14     printf("/* this file was automatically generated with c-ify */\n"
   15            "static const char %s[] =", argv[1]);
   16     eol = 1;
   17     while ((c = getchar()) != EOF) {
   18         if (eol) {
   19             printf("\n\"");
   20             eol = 0;
   21         }
   22         switch (c) {
   23         case '\n': printf("\\n\""); eol = 1; break;
   24         case '"': printf("\\\""); break;
   25         case '\\': printf("\\\\"); break;
   26         default: putchar(c);
   27         }
   28     }
   29     printf(";\n"
   30            "static const size_t %s_len = sizeof(%s) - 1;\n",
   31            argv[1], argv[1]);
   32     return (0);
   33 }