|
@@ -19,13 +19,13 @@ char *repr(const char *data) {
|
|
|
while (*cp != 0) {
|
|
|
char c = *cp;
|
|
|
|
|
|
- if (isspace(c)) {
|
|
|
- if (c == ' ') {
|
|
|
- cp++;
|
|
|
- continue;
|
|
|
- };
|
|
|
- /* Ok, it's form-feed ('\f'), newline ('\n'), carriage return ('\r'),
|
|
|
- * horizontal tab ('\t'), and vertical tab ('\v') */
|
|
|
+ if (c == ' ') {
|
|
|
+ cp++;
|
|
|
+ continue;
|
|
|
+ };
|
|
|
+ /* Ok, it's form-feed ('\f'), newline ('\n'), carriage return ('\r'),
|
|
|
+ * horizontal tab ('\t'), and vertical tab ('\v') */
|
|
|
+ if (strchr("\f\n\r\t\v\?", c) != NULL) {
|
|
|
memmove(cp + 1, cp, strlen(cp) + 1);
|
|
|
*cp = '\\';
|
|
|
cp++;
|
|
@@ -58,30 +58,44 @@ char *repr(const char *data) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (isprint(c)) {
|
|
|
+ if (c == '\\') {
|
|
|
+ memmove(cp, cp + 1, strlen(cp) + 1);
|
|
|
+ *cp = '\\';
|
|
|
+ cp += 2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (c == '"') {
|
|
|
+ memmove(cp, cp + 1, strlen(cp) + 1);
|
|
|
+ *cp = '\\';
|
|
|
+ cp += 2;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (strchr("[()]{}:;,.<>?!@#$%^&*", c) != NULL) {
|
|
|
cp++;
|
|
|
continue;
|
|
|
- };
|
|
|
+ }
|
|
|
+ if (strchr("0123456789", c) != NULL) {
|
|
|
+ cp++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", c) !=
|
|
|
+ NULL) {
|
|
|
+ cp++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
// Ok, default to \xHH output.
|
|
|
memmove(cp + 3, cp, strlen(cp) + 1);
|
|
|
- *cp = '\\';
|
|
|
- cp++;
|
|
|
- *cp = 'x';
|
|
|
- cp++;
|
|
|
- char buffer[3];
|
|
|
- sprintf(buffer, "%02x", (int)c & 0xff);
|
|
|
- *cp = buffer[0];
|
|
|
- cp++;
|
|
|
- *cp = buffer[1];
|
|
|
- cp++;
|
|
|
+ char buffer[10];
|
|
|
+ sprintf(buffer, "\\x%02x", (int)c & 0xff);
|
|
|
+ strncpy(cp, buffer, 4);
|
|
|
+ cp += 4;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
return buffer;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
int read_file(const char *filename) {
|
|
|
FILE *fp;
|
|
|
char buffer[10240];
|
|
@@ -101,13 +115,12 @@ int read_file(const char *filename) {
|
|
|
}
|
|
|
cp = buffer;
|
|
|
while (*cp != 0) {
|
|
|
- if (! isalpha(*cp))
|
|
|
- memmove(cp, cp+1, strlen(cp));
|
|
|
+ if (!isalpha(*cp))
|
|
|
+ memmove(cp, cp + 1, strlen(cp));
|
|
|
cp++;
|
|
|
}
|
|
|
- printf( "const char * %s[] = {\n", buffer);
|
|
|
+ printf("const char * %s[] = {\n", buffer);
|
|
|
|
|
|
-
|
|
|
if ((read = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
|
|
|
char *nl;
|
|
|
|
|
@@ -124,11 +137,10 @@ int read_file(const char *filename) {
|
|
|
cp = nl + 4;
|
|
|
}
|
|
|
if (strlen(cp) > 0)
|
|
|
- printf( ",\n \"%s\"\n", cp);
|
|
|
+ printf(",\n \"%s\"\n", cp);
|
|
|
else
|
|
|
printf("\n");
|
|
|
- printf("}\n");
|
|
|
-
|
|
|
+ printf("};\n");
|
|
|
};
|
|
|
fclose(fp);
|
|
|
return 1;
|