-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Extracted Piqi common library "piqilib" from Piqi tools.
- Reorganized directory layout accordingly.
- Loading branch information
Showing
71 changed files
with
610 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../piqi/piqi | ||
../piqi-tools/piqi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
piqi | ||
piqtype.* | ||
piqobj.ml | ||
descriptor.* | ||
piqi_version.ml | ||
piqi_json_parser.ml | ||
|
||
piqi_c_impl.c | ||
piqi_main.ml | ||
piqi.ml | ||
piq_parser.ml | ||
piqi_common.ml | ||
piqobj_to_piq.ml | ||
piqi_c.mli | ||
piqi_name.ml | ||
piqi_file.ml | ||
piqobj_common.ml | ||
piqobj_of_wire.ml | ||
piqloc.ml | ||
piq_lexer.ml | ||
piqi_config.ml | ||
piq_gen.ml | ||
piqobj_to_wire.ml | ||
piqi_iolist.ml | ||
piqi_wire.ml | ||
piqobj_of_piq.ml | ||
piqi_db.ml | ||
piqi_c.ml | ||
piqi_ext.ml | ||
piqi_func.ml | ||
|
||
# piqi lib | ||
|
||
piqi-boot.piqi | ||
piqi.piqi | ||
piqi-impl.piqi | ||
|
||
piqi_json_common.ml | ||
piqi_json_parser.mll | ||
piqi_json_gen.ml | ||
piqi_json.ml | ||
|
||
piqi_base64.ml | ||
piqobj_to_json.ml | ||
piqobj_of_json.ml | ||
|
||
piqi_pp.ml | ||
piq.ml | ||
|
||
piqi_light.ml | ||
piqi_getopt.ml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
include $(PIQI_ROOT)/make/Makefile.ocaml | ||
include $(PIQI_ROOT)/piqilib/Makefile.piqilib | ||
|
||
|
||
RESULT = piqi | ||
|
||
SOURCES += \ | ||
piqi_json_pp.ml \ | ||
\ | ||
piqi_pp_cmd.ml \ | ||
piqi_convert.ml \ | ||
piqi_check.ml \ | ||
piqi_expand.ml \ | ||
piqi_light_cmd.ml \ | ||
piqi_getopt_cmd.ml \ | ||
\ | ||
piqi_to_proto.ml \ | ||
\ | ||
descriptor.ml \ | ||
piqi_of_proto.ml \ | ||
\ | ||
piqi_run.ml \ | ||
|
||
|
||
|
||
PIQI_MODULES = descriptor.piqi | ||
PIQI_ML_SOURCES = $(PIQI_MODULES:%.piqi=%.ml) | ||
|
||
|
||
PRE_TARGETS += $(PIQI_SOURCES) $(PIQI_PIQI) $(PIQI_ML_SOURCES) | ||
|
||
|
||
PIQIC = ../piqic/piqic | ||
PIQIC_FLAGS = -I $(PIQI_ROOT) | ||
|
||
|
||
#OCAMLBLDFLAGS = -custom | ||
|
||
|
||
all: nc | ||
|
||
|
||
debug: dc top | ||
|
||
|
||
$(PIQI_ML_SOURCES): %.ml: %.piqi | ||
$(PIQIC) ocaml $(PIQIC_FLAGS) --pp -o $@ $< | ||
|
||
|
||
clean:: | ||
|
||
|
||
include $(OCAMLMAKEFILE) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
(*pp camlp4o -I $PIQI_ROOT/camlp4 pa_labelscope.cmo pa_openin.cmo *) | ||
(* | ||
Copyright 2009, 2010, 2011 Anton Lavrik | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*) | ||
|
||
|
||
(* | ||
* Command-line element parsing, pretty-printing and converting to various | ||
* output formats. | ||
*) | ||
|
||
|
||
module C = Piqi_common | ||
open C | ||
|
||
|
||
(* command-line arguments *) | ||
let output_encoding = ref "" | ||
let typename = ref "" | ||
|
||
|
||
(* index of the "--" element in argv array *) | ||
let argv_start_index = ref 0 | ||
|
||
|
||
module Main = Piqi_main | ||
open Main | ||
|
||
|
||
let validate_options () = | ||
if !typename = "" (* pretty-print mode *) | ||
then ( | ||
if !output_encoding <> "" | ||
then piqi_error "option -t can not be used without --piqtype"; | ||
) | ||
|
||
|
||
let getopt_command () = | ||
validate_options (); | ||
(* open output file *) | ||
let och = Main.open_output !ofile in | ||
(* interpret command-line arguments after "--" as Piq data *) | ||
let piq_ast = Piqi_getopt.getopt_piq !argv_start_index in | ||
match piq_ast with | ||
| None -> () (* no data *) | ||
| Some ast when !typename = "" -> | ||
(* with no --piqtype parameter given, just pretty-print the Piq AST *) | ||
Piqi_pp.prettyprint_ast och ast; | ||
output_char och '\n' | ||
| Some ast -> | ||
let writer = Piqi_convert.make_writer !output_encoding in | ||
let piqtype = Piqi_convert.find_piqtype !typename in | ||
(* parse the Piq AST according to "--piqtype" and convert to the output | ||
* format according to "-t" *) | ||
Piqobj_of_piq.resolve_defaults := !Piqi_convert.flag_add_defaults; | ||
Piqobj_of_piq.parse_words_as_strings := true; | ||
let piqobj = Piqobj_of_piq.parse_obj piqtype ast in | ||
(* write the object *) | ||
writer och (Piq.Typed_piqobj piqobj) | ||
|
||
|
||
(* find the position of the first argument after "--" *) | ||
let rest_fun arg = | ||
if !argv_start_index = 0 (* first argument after first occurence of "--" *) | ||
then argv_start_index := !Arg.current + 1 | ||
else () | ||
|
||
|
||
let usage = "Usage: piqi getopt [options] -- [<data arguments>] \nOptions:" | ||
|
||
|
||
let speclist = Main.common_speclist @ | ||
[ | ||
arg_o; | ||
|
||
"-t", Arg.Set_string output_encoding, | ||
"piq|wire|pb|json|piq-json output encoding (piq is used by default)"; | ||
|
||
"--piqtype", Arg.Set_string typename, | ||
"<typename> type of the object represented by data arguments"; | ||
|
||
"--add-defaults", Arg.Set Piqi_convert.flag_add_defaults, | ||
"add field default values while converting records"; | ||
|
||
"--", Arg.Rest rest_fun, | ||
"separator between piqi command-line arguments and data arguments"; | ||
] | ||
|
||
|
||
let run () = | ||
Main.parse_args () ~speclist ~usage ~min_arg_count:0 ~max_arg_count:0; | ||
if !argv_start_index = 0 (* "--" is not present in the list of arguments *) | ||
then argv_start_index := Array.length Sys.argv; | ||
getopt_command () | ||
|
||
|
||
let _ = | ||
Main.register_command run "getopt" | ||
"interpret command-line arguments as Piq data, pretty-print and convert to various encodings" | ||
|
Oops, something went wrong.