qemacs-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-commit] qemacs/libqhtml csstoqe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs/libqhtml csstoqe.c
Date: Sat, 15 Dec 2007 15:44:36 +0000

CVSROOT:        /cvsroot/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        07/12/15 15:44:36

Modified files:
        libqhtml       : csstoqe.c 

Log message:
        fixed C comment parsing, improved output

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/libqhtml/csstoqe.c?cvsroot=qemacs&r1=1.5&r2=1.6

Patches:
Index: csstoqe.c
===================================================================
RCS file: /cvsroot/qemacs/qemacs/libqhtml/csstoqe.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- csstoqe.c   6 Dec 2007 17:43:49 -0000       1.5
+++ csstoqe.c   15 Dec 2007 15:44:36 -0000      1.6
@@ -1,9 +1,37 @@
-/* convert a CSS style sheet to C buffer so that it can be statically
-   linked with qemacs */
+/*
+ * convert a CSS style sheet to C buffer so that it can be statically
+ * linked with qemacs
+ *
+ * Copyright (c) 2002 Fabrice Bellard.
+ * Copyright (c) 2007 Charlie Gordon.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <ctype.h>
 
+static int peekc(FILE *f)
+{
+    int c = getc(f);
+    if (c != EOF)
+        ungetc(c, f);
+    return c;
+}
+
 int main(int argc, char **argv)
 {
     int c, n, last_c, got_space, in_string;
@@ -18,14 +46,13 @@
            "#include \"qe.h\"\n"
            "#include \"css.h\"\n"
            "\n");
-    printf("const char %s[] =\n", argv[1]);
+    printf("const char %s[] = {\n", argv[1]);
     n = 0;
     got_space = 0;
     last_c = 0;
     in_string = 0;
     for (;;) {
         c = getchar();
-    redo:
         if (c == EOF)
             break;
         if (!in_string) {
@@ -34,14 +61,9 @@
                 continue;
             }
             /* comments */
-            if (c == '/') {
-                c = getchar();
                 /* CG: allow // comments ? */
-                if (c != '*') {
-                    /* CG: incorrect if n == 0, also n++ missing */
-                    putchar('/');
-                    goto redo;
-                }
+            if (c == '/' && peekc(stdin) == '*') {
+                getchar();
                 for (;;) {
                     c = getchar();
                     if (c == EOF)
@@ -60,15 +82,21 @@
             }
         }
         if (n == 0)
-            printf("\"");
+            printf("    \"");
         /* add separator if needed */
-        if (!in_string && got_space && isalnum(c) && isalnum(last_c))
+        if (!in_string && got_space && isalnum(c) && isalnum(last_c)) {
             putchar(' ');
-        if (c == '\"' || c == '\'' || c == '\\')
+            n++;
+        }
+        if (c == '\"' || c == '\'' || c == '\\') {
             putchar('\\');
+            n++;
+        }
         putchar(c);
-        if (c == '\"')
+        if (c == '\"') {
+            /* CG: does not work for ' ' */
             in_string ^= 1;
+        }
         last_c = c;
         got_space = 0;
         if (++n >= 64) {
@@ -79,6 +107,6 @@
  the_end:
     if (n > 0)
         printf("\"\n");
-    printf(";\n\n");
+    printf("};\n\n");
     return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]