Skip to content

Commit

Permalink
Merge branch 'master' into bitwise-expression
Browse files Browse the repository at this point in the history
Conflicts:
	doc/pycrc.xml
  • Loading branch information
tpircher-zz committed Jan 4, 2013
2 parents f08deac + b9e5442 commit d025ae5
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 210 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2006-2012, Thomas Pircher <tehpeh@gmx.net>
Copyright (c) 2006-2013, Thomas Pircher <tehpeh@gmx.net>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 27 additions & 2 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
#
# Version 0.7.12, 2012-xx-xx
# Version 0.7.12, 2013-xx-xx
#

2013-01-02 Thomas Pircher <tehpeh@gmx.net>

* crc_opt.py:
* doc/pycrc.xml:
Now it is possible to specify the --include option multiple times.

2013-01-02 Thomas Pircher <tehpeh@gmx.net>

* doc/pycrc.xml:
Completely revisited and reworked the documentation.

* crc_opt.py:
Updated the command line help screen with more useful command descriptions.

2013-01-01 Thomas Pircher <tehpeh@gmx.net>

* all *.py files:
Removed the -*- coding: Latin-1 -*- string.
Updated the copyright year to 2013.

* COPYING:
Updated the copyright year to 2013.

2012-11-25 Thomas Pircher <tehpeh@gmx.net>

* crc_opt.py:
Expand All @@ -24,7 +47,7 @@

* README.md:
Added a note to README.md that version 0.7.10 of pycrc is the last one
known to work with Python 2.x.
known to work with Python 2.4.

* doc/pycrc.xml:
Updated a link to the list of CRC models.
Expand Down Expand Up @@ -174,6 +197,8 @@
* crc_symtable.py:
C/C++ code can now be generated for the table-driven algorithm with widths
that are not byte-ligned or less than 8.
This feature was heavily inspired by a similar feature in Danjel McGougan's
Universal Crc (http://mcgougan.se/universal_crc/).

W A R N I N G: introduced new variable crc_shift, member of the crc_cfg_t
structure, that must be initialised manually when the width
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ System Requirements
===================

pycrc requires Python 2.6 or later. Python 3.x is supported.
The last version compatible with Python 2.x is pycrc v0.7.10.
The last version compatible with Python 2.4 is pycrc v0.7.10.



Expand Down
4 changes: 1 addition & 3 deletions crc_algorithms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
4 changes: 1 addition & 3 deletions crc_lexer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
4 changes: 1 addition & 3 deletions crc_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
58 changes: 28 additions & 30 deletions crc_opt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -87,7 +85,7 @@ def __init__(self):
self.Algorithm = self.Algo_None
self.SymbolPrefix = "crc_"
self.CrcType = None
self.IncludeFile = None
self.IncludeFiles = []
self.OutputFile = None
self.Action = self.Action_Check_String
self.CheckFile = None
Expand All @@ -102,43 +100,43 @@ def parse(self, argv = None):
Parses and validates the options given as arguments
"""
usage = """\
%prog [OPTIONS]
python %prog [OPTIONS]
To generate the checksum of a string or hexadecimal data:
%prog [model] --check-string "123456789"
%prog [model] --check-hexstring "313233343536373839"
To calculate the checksum of a string or hexadecimal data:
python %prog [model] --check-string "123456789"
python %prog [model] --check-hexstring "313233343536373839"
To generate the checksum of a file:
%prog [model] --check-file filename
To calculate the checksum of a file:
python %prog [model] --check-file filename
To generate the c-source and write it to filename:
%prog [model] --generate c -o filename
To generate the C source code and write it to filename:
python %prog [model] --generate c -o filename
The model can be defined by the --model switch or by specifying each of the
following parameters:
The model can be defined either with the --model switch or by specifying each
of the following parameters:
--width --poly --reflect-in --xor-in --reflect-out --xor-out"""

models = CrcModels()
model_list = ", ".join(models.getList())
parser = OptionParser(option_class=MyOption, usage=usage, version=self.VersionStr)
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="print information about the model")
help="be more verbose; print the value of the parameters and the chosen model to stdout")
parser.add_option("--check-string",
action="store", type="string", dest="check_string",
help="calculate the checksum of the given string (default: '123456789')", metavar="STRING")
help="calculate the checksum of a string (default: '123456789')", metavar="STRING")
parser.add_option("--check-hexstring",
action="store", type="string", dest="check_hexstring",
help="calculate the checksum of the given hexadecimal number string", metavar="STRING")
help="calculate the checksum of a hexadecimal number string", metavar="STRING")
parser.add_option("--check-file",
action="store", type="string", dest="check_file",
help="calculate the checksum of the given file", metavar="FILE")
help="calculate the checksum of a file", metavar="FILE")
parser.add_option("--generate",
action="store", type="string", dest="generate", default=None,
help="choose which type of code to generate from {c, h, c-main, table}", metavar="CODE")
help="generate C source code; choose the type from {h, c, c-main, table}", metavar="CODE")
parser.add_option("--std",
action="store", type="string", dest="c_std", default="C99",
help="C standard style of the generated code from {C89, ANSI, C99}", metavar="STD")
help="choose the C dialect of the generated code from {C89, ANSI, C99}", metavar="STD")
parser.add_option("--algorithm",
action="store", type="string", dest="algorithm", default="all",
help="choose an algorithm from {bit-by-bit, bbb, bit-by-bit-fast, bbf, bitwise-expression, bwe, table-driven, tbl, all}", metavar="ALGO")
Expand All @@ -150,31 +148,31 @@ def parse(self, argv = None):
help="use NUM bits in the polynomial", metavar="NUM")
parser.add_option("--poly",
action="store", type="hex", dest="poly",
help="use HEX as Polynom", metavar="HEX")
help="use HEX as polynomial", metavar="HEX")
parser.add_option("--reflect-in",
action="store", type="bool", dest="reflect_in",
help="reflect input bytes", metavar="BOOL")
help="reflect the octets in the input message", metavar="BOOL")
parser.add_option("--xor-in",
action="store", type="hex", dest="xor_in",
help="use HEX as initial value", metavar="HEX")
parser.add_option("--reflect-out",
action="store", type="bool", dest="reflect_out",
help="reflect output bytes", metavar="BOOL")
help="reflect the resulting checksum before applying the --xor-out value", metavar="BOOL")
parser.add_option("--xor-out",
action="store", type="hex", dest="xor_out",
help="xor the final crc value with HEX", metavar="HEX")
help="xor the final CRC value with HEX", metavar="HEX")
parser.add_option("--table-idx-width",
action="store", type="int", dest="table_idx_width",
help="use NUM bits to index the crc table; NUM must be one of the values {1, 2, 4, 8}", metavar="NUM")
help="use NUM bits to index the CRC table; NUM must be one of the values {1, 2, 4, 8}", metavar="NUM")
parser.add_option("--symbol-prefix",
action="store", type="string", dest="symbol_prefix",
help="when generating source code, use STRING as prefix to the generated symbols", metavar="STRING")
help="when generating source code, use STRING as prefix to the exported C symbols", metavar="STRING")
parser.add_option("--crc-type",
action="store", type="string", dest="crc_type",
help="when generating source code, use STRING as crc_t type", metavar="STRING")
parser.add_option("--include-file",
action="store", type="string", dest="include_file",
help="when generating source code, use FILE as additional include file", metavar="FILE")
action="append", type="string", dest="include_files",
help="when generating source code, include also FILE as header file; can be specified multiple times", metavar="FILE")
parser.add_option("-o", "--output",
action="store", type="string", dest="output_file",
help="write the generated code to file instead to stdout", metavar="FILE")
Expand Down Expand Up @@ -277,8 +275,8 @@ def parse(self, argv = None):
sys.exit(1)
if options.symbol_prefix != None:
self.SymbolPrefix = options.symbol_prefix
if options.include_file != None:
self.IncludeFile = options.include_file
if options.include_files != None:
self.IncludeFiles = options.include_files
if options.crc_type != None:
self.CrcType = options.crc_type
if options.output_file != None:
Expand Down
4 changes: 1 addition & 3 deletions crc_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down
36 changes: 19 additions & 17 deletions crc_symtable.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: Latin-1 -*-

# pycrc -- parameterisable CRC calculation utility and C source code generator
#
# Copyright (c) 2006-2012 Thomas Pircher <tehpeh@gmx.net>
# Copyright (c) 2006-2013 Thomas Pircher <tehpeh@gmx.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -131,7 +129,7 @@ def __init__(self, opt):
self.table["c_false"] = "$if ($c_std == C89) {:0:} $else {:false:}"

self.table["underlying_crc_t"] = self.__get_underlying_crc_t()
self.table["include_file"] = self.__get_include_file()
self.table["include_files"] = self.__get_include_files()

self.table["crc_prefix"] = self.opt.SymbolPrefix
self.table["crc_t"] = self.opt.SymbolPrefix + "t"
Expand Down Expand Up @@ -272,8 +270,8 @@ def __getTerminal(self, id):
#ifndef $header_protection
#define $header_protection
$if ($include_file != Undefined) {:
#include $include_file
$if ($include_files != Undefined) {:
$include_files
:}
#include <stdlib.h>
$if ($c_std != C89) {:
Expand Down Expand Up @@ -554,8 +552,8 @@ def __getTerminal(self, id):
elif id == "c_template":
return """\
$source_header
$if ($include_file != Undefined) {:
#include $include_file
$if ($include_files != Undefined) {:
$include_files
:}
#include "$header_filename" /* include the header file generated with pycrc */
#include <stdlib.h>
Expand Down Expand Up @@ -966,8 +964,8 @@ def __getTerminal(self, id):

elif id == "main_template":
return """\
$if ($include_file != Undefined) {:
#include $include_file
$if ($include_files != Undefined) {:
$include_files
:}
#include <stdio.h>
#include <getopt.h>
Expand Down Expand Up @@ -1334,17 +1332,21 @@ def __get_underlying_crc_t(self):
return "unsigned long"


# function __get_include_file
# function __get_include_files
###############################################################################
def __get_include_file(self):
def __get_include_files(self):
"""
Return an additional include instruction, if specified.
Return an additional include instructions, if specified.
"""
if self.opt.IncludeFile == None:
if self.opt.IncludeFiles == None or len(self.opt.IncludeFiles) == 0:
return None
if self.opt.IncludeFile[0] == '"' or self.opt.IncludeFile[0] == '<':
return self.opt.IncludeFile
return '"%s"' % self.opt.IncludeFile
ret = []
for include_file in self.opt.IncludeFiles:
if include_file[0] == '"' or include_file[0] == '<':
ret.append('#include %s' % include_file)
else:
ret.append('#include "%s"' % include_file)
return '\n'.join(ret)


# function __get_init_value
Expand Down
Loading

0 comments on commit d025ae5

Please sign in to comment.