Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
9a5848cf
Commit
9a5848cf
authored
Jul 21, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrote main function, added some command-line arguments
parent
21017977
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
42 deletions
+73
-42
main.ml
main.ml
+65
-27
types.ml
types.ml
+0
-6
util.ml
util.ml
+8
-9
No files found.
main.ml
View file @
9a5848cf
open
Lexing
open
Lexing
open
Types
open
Types
type
args
=
{
mutable
infiles
:
string
list
;
mutable
outfile
:
string
option
;
mutable
verbose
:
int
;
mutable
echo
:
bool
;
mutable
keep_comments
:
bool
;
}
(* Parse command-line arguments *)
(* Parse command-line arguments *)
let
parse_args
()
=
let
parse_args
()
=
let
args
=
{
let
args
=
{
infiles
=
[]
;
infiles
=
[]
;
outfile
=
None
;
outfile
=
None
;
verbose
=
1
;
verbose
=
1
;
echo
=
false
;
keep_comments
=
false
;
}
in
}
in
let
args_spec
=
[
let
args_spec
=
[
(
"<file> ..."
,
Arg
.
Rest
(
fun
_
->
()
)
,
(
"<file> ..."
,
Arg
.
Rest
(
fun
_
->
()
)
,
...
@@ -18,6 +28,12 @@ let parse_args () =
...
@@ -18,6 +28,12 @@ let parse_args () =
(
"-v"
,
Arg
.
Int
(
fun
i
->
args
.
verbose
<-
i
)
,
(
"-v"
,
Arg
.
Int
(
fun
i
->
args
.
verbose
<-
i
)
,
"<num> Set verbosity (0: nothing, 1: errors (default), \
"<num> Set verbosity (0: nothing, 1: errors (default), \
2: compression rate, 3: debug)"
);
2: compression rate, 3: debug)"
);
(
"--echo"
,
Arg
.
Unit
(
fun
_
->
args
.
echo
<-
true
)
,
" Don't minify, just pretty-print the parsed CSS"
);
(
"--keep-comments"
,
Arg
.
Unit
(
fun
_
->
args
.
keep_comments
<-
true
)
,
"
\n
Preserve top-level comments"
);
]
in
]
in
let
usage
=
let
usage
=
...
@@ -27,35 +43,57 @@ let parse_args () =
...
@@ -27,35 +43,57 @@ let parse_args () =
Arg
.
parse
args_spec
(
fun
f
->
args
.
infiles
<-
args
.
infiles
@
[
f
])
usage
;
Arg
.
parse
args_spec
(
fun
f
->
args
.
infiles
<-
args
.
infiles
@
[
f
])
usage
;
args
args
(* Main function, returns exit status
let
parse_files
=
function
* Command-line arguments are stored in lobals.args *)
let
main
()
=
let
args
=
parse_args
()
in
try
let
stylesheet
=
match
args
.
infiles
with
|
[]
->
|
[]
->
let
input
=
Util
.
input_buffered
stdin
512
in
let
input
=
Util
.
input_buffered
stdin
512
in
Parse
.
parse_input
"<stdin>"
input
(
input
,
Parse
.
parse_input
"<stdin>"
input
)
|
files
->
|
files
->
let
rec
loop
=
function
let
rec
loop
=
function
|
[]
->
[]
|
[]
->
[]
|
filename
::
tl
->
|
filename
::
tl
->
let
input
=
Util
.
input_all
(
open_in
filename
)
in
let
input
=
Util
.
input_all
(
open_in
filename
)
in
let
stylesheet
=
Parse
.
parse_input
filename
input
in
let
stylesheet
=
Parse
.
parse_input
filename
input
in
stylesheet
@
loop
tl
(
input
,
stylesheet
)
::
loop
tl
in
in
loop
files
let
inputs
,
stylesheets
=
List
.
split
(
loop
files
)
in
(
String
.
concat
""
inputs
,
List
.
concat
stylesheets
)
let
handle_args
args
=
let
input
,
stylesheet
=
parse_files
args
.
infiles
in
let
write_output
=
match
args
.
outfile
with
|
None
->
print_endline
|
Some
name
->
fun
css
->
let
f
=
open_out
name
in
output_string
f
css
;
close_out
f
in
in
print_endline
(
Stringify
.
string_of_stylesheet
stylesheet
);
print_endline
"
\n
"
;
match
args
with
print_endline
(
Stringify
.
minify_stylesheet
stylesheet
);
|
{
echo
=
true
}
->
write_output
(
Stringify
.
string_of_stylesheet
stylesheet
)
|
_
->
let
output
=
Stringify
.
minify_stylesheet
stylesheet
in
write_output
output
;
if
args
.
verbose
>=
2
then
begin
let
il
=
String
.
length
input
in
let
ol
=
String
.
length
output
in
Printf
.
fprintf
stderr
"compression: %d -> %d bytes (%d%% of original)
\n
"
il
ol
(
int_of_float
(
float_of_int
ol
/.
float_of_int
il
*.
100
.
))
end
(* Main function, returns exit status *)
let
main
()
=
let
args
=
parse_args
()
in
begin
try
handle_args
args
;
exit
0
exit
0
with
with
|
LocError
(
loc
,
msg
)
->
|
LocError
(
loc
,
msg
)
->
Util
.
prerr_loc_msg
args
loc
(
"Error: "
^
msg
);
Util
.
prerr_loc_msg
(
args
.
verbose
>=
1
)
loc
(
"Error: "
^
msg
);
|
Failure
err
->
|
Failure
err
->
prerr_endline
(
"Error: "
^
err
);
prerr_endline
(
"Error: "
^
err
);
end
;
exit
1
exit
1
let
_
=
main
()
let
_
=
main
()
types.ml
View file @
9a5848cf
...
@@ -53,12 +53,6 @@ type statement =
...
@@ -53,12 +53,6 @@ type statement =
type
stylesheet
=
statement
list
type
stylesheet
=
statement
list
type
args
=
{
mutable
infiles
:
string
list
;
mutable
outfile
:
string
option
;
mutable
verbose
:
int
;
}
type
loc
=
string
*
int
*
int
*
int
*
int
type
loc
=
string
*
int
*
int
*
int
*
int
exception
SyntaxError
of
string
exception
SyntaxError
of
string
...
...
util.ml
View file @
9a5848cf
...
@@ -36,7 +36,8 @@ let count_tabs str upto =
...
@@ -36,7 +36,8 @@ let count_tabs str upto =
let
rec
count
n
=
function
let
rec
count
n
=
function
|
0
->
n
|
0
->
n
|
i
->
count
(
if
String
.
get
str
(
i
-
1
)
=
'\t'
then
n
+
1
else
n
)
(
i
-
1
)
|
i
->
count
(
if
String
.
get
str
(
i
-
1
)
=
'\t'
then
n
+
1
else
n
)
(
i
-
1
)
in
count
0
upto
in
count
0
upto
let
rec
repeat
s
n
=
if
n
<
1
then
""
else
s
^
(
repeat
s
(
n
-
1
))
let
rec
repeat
s
n
=
if
n
<
1
then
""
else
s
^
(
repeat
s
(
n
-
1
))
...
@@ -48,7 +49,7 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
...
@@ -48,7 +49,7 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
let
file
=
open_in
fname
in
let
file
=
open_in
fname
in
(* skip lines until the first matched line *)
(* skip lines until the first matched line *)
for
i
=
1
to
ystart
-
1
do
let
_
=
input_line
file
in
(
)
done
;
for
i
=
1
to
ystart
-
1
do
ignore
(
input_line
file
)
done
;
(* for each line in `loc`, print the source line with an underline *)
(* for each line in `loc`, print the source line with an underline *)
for
l
=
ystart
to
yend
do
for
l
=
ystart
to
yend
do
...
@@ -63,11 +64,10 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
...
@@ -63,11 +64,10 @@ let prerr_loc (fname, ystart, yend, xstart, xend) =
for
i
=
left
to
right
do
prerr_char
'
^
'
done
;
for
i
=
left
to
right
do
prerr_char
'
^
'
done
;
prerr_endline
""
;
prerr_endline
""
;
end
end
done
;
done
()
let
prerr_loc_msg
args
loc
msg
=
let
prerr_loc_msg
verbose
loc
msg
=
if
args
.
verbose
>=
1
then
begin
if
verbose
then
begin
let
(
fname
,
ystart
,
yend
,
xstart
,
xend
)
=
loc
in
let
(
fname
,
ystart
,
yend
,
xstart
,
xend
)
=
loc
in
if
loc
!=
noloc
then
begin
if
loc
!=
noloc
then
begin
let
line_s
=
if
yend
!=
ystart
let
line_s
=
if
yend
!=
ystart
...
@@ -82,8 +82,7 @@ let prerr_loc_msg args loc msg =
...
@@ -82,8 +82,7 @@ let prerr_loc_msg args loc msg =
end
;
end
;
eprintf
"%s
\n
"
msg
;
eprintf
"%s
\n
"
msg
;
if
args
.
verbose
>=
1
&&
loc
!=
noloc
then
if
verbose
&&
loc
!=
noloc
then
try
prerr_loc
loc
try
prerr_loc
loc
with
Sys_error
_
->
()
with
Sys_error
_
->
()
end
;
end
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment