|
Revision 1424, 6.8 kB
(checked in by crschmidt, 2 years ago)
|
Fix all cases where we have Windows line endings, and set eol-style="native"
on all files. Hopefully, this makes it easier for people to write patches
and do other neat things.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 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 |
|
|---|
| 26 |
|
|---|
| 27 |
#include <stdlib.h> |
|---|
| 28 |
#include <stdio.h> |
|---|
| 29 |
|
|---|
| 30 |
static int theA; |
|---|
| 31 |
static int theB; |
|---|
| 32 |
static int theLookahead = EOF; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
static int |
|---|
| 40 |
isAlphanum(int c) |
|---|
| 41 |
{ |
|---|
| 42 |
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || |
|---|
| 43 |
(c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || |
|---|
| 44 |
c > 126); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int |
|---|
| 54 |
get() |
|---|
| 55 |
{ |
|---|
| 56 |
int c = theLookahead; |
|---|
| 57 |
theLookahead = EOF; |
|---|
| 58 |
if (c == EOF) { |
|---|
| 59 |
c = getc(stdin); |
|---|
| 60 |
} |
|---|
| 61 |
if (c >= ' ' || c == '\n' || c == EOF) { |
|---|
| 62 |
return c; |
|---|
| 63 |
} |
|---|
| 64 |
if (c == '\r') { |
|---|
| 65 |
return '\n'; |
|---|
| 66 |
} |
|---|
| 67 |
return ' '; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
static int |
|---|
| 75 |
peek() |
|---|
| 76 |
{ |
|---|
| 77 |
theLookahead = get(); |
|---|
| 78 |
return theLookahead; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
static int |
|---|
| 87 |
next() |
|---|
| 88 |
{ |
|---|
| 89 |
int c = get(); |
|---|
| 90 |
if (c == '/') { |
|---|
| 91 |
switch (peek()) { |
|---|
| 92 |
case '/': |
|---|
| 93 |
for (;;) { |
|---|
| 94 |
c = get(); |
|---|
| 95 |
if (c <= '\n') { |
|---|
| 96 |
return c; |
|---|
| 97 |
} |
|---|
| 98 |
} |
|---|
| 99 |
case '*': |
|---|
| 100 |
get(); |
|---|
| 101 |
for (;;) { |
|---|
| 102 |
switch (get()) { |
|---|
| 103 |
case '*': |
|---|
| 104 |
if (peek() == '/') { |
|---|
| 105 |
get(); |
|---|
| 106 |
return ' '; |
|---|
| 107 |
} |
|---|
| 108 |
break; |
|---|
| 109 |
case EOF: |
|---|
| 110 |
fprintf(stderr, "Error: JSMIN Unterminated comment.\n"); |
|---|
| 111 |
exit(1); |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
default: |
|---|
| 115 |
return c; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
return c; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
static void |
|---|
| 131 |
action(int d) |
|---|
| 132 |
{ |
|---|
| 133 |
switch (d) { |
|---|
| 134 |
case 1: |
|---|
| 135 |
putc(theA, stdout); |
|---|
| 136 |
case 2: |
|---|
| 137 |
theA = theB; |
|---|
| 138 |
if (theA == '\'' || theA == '"') { |
|---|
| 139 |
for (;;) { |
|---|
| 140 |
putc(theA, stdout); |
|---|
| 141 |
theA = get(); |
|---|
| 142 |
if (theA == theB) { |
|---|
| 143 |
break; |
|---|
| 144 |
} |
|---|
| 145 |
if (theA <= '\n') { |
|---|
| 146 |
fprintf(stderr, |
|---|
| 147 |
"Error: JSMIN unterminated string literal: %c\n", theA); |
|---|
| 148 |
exit(1); |
|---|
| 149 |
} |
|---|
| 150 |
if (theA == '\\') { |
|---|
| 151 |
putc(theA, stdout); |
|---|
| 152 |
theA = get(); |
|---|
| 153 |
} |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
case 3: |
|---|
| 157 |
theB = next(); |
|---|
| 158 |
if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' || |
|---|
| 159 |
theA == ':' || theA == '[' || theA == '!' || theA == '&' || |
|---|
| 160 |
theA == '|')) { |
|---|
| 161 |
putc(theA, stdout); |
|---|
| 162 |
putc(theB, stdout); |
|---|
| 163 |
for (;;) { |
|---|
| 164 |
theA = get(); |
|---|
| 165 |
if (theA == '/') { |
|---|
| 166 |
break; |
|---|
| 167 |
} else if (theA =='\\') { |
|---|
| 168 |
putc(theA, stdout); |
|---|
| 169 |
theA = get(); |
|---|
| 170 |
} else if (theA <= '\n') { |
|---|
| 171 |
fprintf(stderr, |
|---|
| 172 |
"Error: JSMIN unterminated Regular Expression literal.\n", theA); |
|---|
| 173 |
exit(1); |
|---|
| 174 |
} |
|---|
| 175 |
putc(theA, stdout); |
|---|
| 176 |
} |
|---|
| 177 |
theB = next(); |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
static void |
|---|
| 190 |
jsmin() |
|---|
| 191 |
{ |
|---|
| 192 |
theA = '\n'; |
|---|
| 193 |
action(3); |
|---|
| 194 |
while (theA != EOF) { |
|---|
| 195 |
switch (theA) { |
|---|
| 196 |
case ' ': |
|---|
| 197 |
if (isAlphanum(theB)) { |
|---|
| 198 |
action(1); |
|---|
| 199 |
} else { |
|---|
| 200 |
action(2); |
|---|
| 201 |
} |
|---|
| 202 |
break; |
|---|
| 203 |
case '\n': |
|---|
| 204 |
switch (theB) { |
|---|
| 205 |
case '{': |
|---|
| 206 |
case '[': |
|---|
| 207 |
case '(': |
|---|
| 208 |
case '+': |
|---|
| 209 |
case '-': |
|---|
| 210 |
action(1); |
|---|
| 211 |
break; |
|---|
| 212 |
case ' ': |
|---|
| 213 |
action(3); |
|---|
| 214 |
break; |
|---|
| 215 |
default: |
|---|
| 216 |
if (isAlphanum(theB)) { |
|---|
| 217 |
action(1); |
|---|
| 218 |
} else { |
|---|
| 219 |
action(2); |
|---|
| 220 |
} |
|---|
| 221 |
} |
|---|
| 222 |
break; |
|---|
| 223 |
default: |
|---|
| 224 |
switch (theB) { |
|---|
| 225 |
case ' ': |
|---|
| 226 |
if (isAlphanum(theA)) { |
|---|
| 227 |
action(1); |
|---|
| 228 |
break; |
|---|
| 229 |
} |
|---|
| 230 |
action(3); |
|---|
| 231 |
break; |
|---|
| 232 |
case '\n': |
|---|
| 233 |
switch (theA) { |
|---|
| 234 |
case '}': |
|---|
| 235 |
case ']': |
|---|
| 236 |
case ')': |
|---|
| 237 |
case '+': |
|---|
| 238 |
case '-': |
|---|
| 239 |
case '"': |
|---|
| 240 |
case '\'': |
|---|
| 241 |
action(1); |
|---|
| 242 |
break; |
|---|
| 243 |
default: |
|---|
| 244 |
if (isAlphanum(theA)) { |
|---|
| 245 |
action(1); |
|---|
| 246 |
} else { |
|---|
| 247 |
action(3); |
|---|
| 248 |
} |
|---|
| 249 |
} |
|---|
| 250 |
break; |
|---|
| 251 |
default: |
|---|
| 252 |
action(1); |
|---|
| 253 |
break; |
|---|
| 254 |
} |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
extern int |
|---|
| 264 |
main(int argc, char* argv[]) |
|---|
| 265 |
{ |
|---|
| 266 |
int i; |
|---|
| 267 |
for (i = 1; i < argc; i += 1) { |
|---|
| 268 |
fprintf(stdout, "// %s\n", argv[i]); |
|---|
| 269 |
} |
|---|
| 270 |
jsmin(); |
|---|
| 271 |
return 0; |
|---|
| 272 |
} |
|---|