Notepad++是一个免费、开源和绿色的多语言的代码编辑器,它提供了一个简洁高效的完全可定制的用户界面。该软件获得了sourceforge的很高评价。支持代码着色、高亮关键字、自动完成、自动缩进以及支持插件的功能。工程如图:
其中Scilexer是动态库!~
md5测试:
int main(argc, argv)
int argc; char *argv[];
{
int i, j, opt, cdata = FALSE, docheck = FALSE, showfile = TRUE, f = 0;
unsigned int bp;
char *cp, *clabel, *ifname, *hexfmt = "%02X";
FILE *in = stdin, *out = stdout;
unsigned char buffer[16384], signature[16], csig[16];
struct MD5Context md5c;
/* Build parameter quality control. Verify machine
properties were properly set in md5.h and refuse
to run if they're not correct. */
#ifdef CHECK_HARDWARE_PROPERTIES
/* Verify unit32 is, in fact, a 32 bit data type. */
if (sizeof(uint32) != 4) {
fprintf(stderr, "** Configuration error. Setting for uint32 in file md5.h\n");
fprintf(stderr, " is incorrect. This must be a 32 bit data type, but it\n");
fprintf(stderr, " is configured as a %d bit data type.\n", sizeof(uint32) * 8);
return 2;
}
/* If HIGHFIRST is not defined, verify that this machine is,
in fact, a little-endian architecture. */
#ifndef HIGHFIRST
{ uint32 t = 0x12345678;
if (*((char *) &t) != 0x78) {
fprintf(stderr, "** Configuration error. Setting for HIGHFIRST in file md5.h\n");
fprintf(stderr, " is incorrect. This symbol has not been defined, yet this\n");
fprintf(stderr, " machine is a big-endian (most significant byte first in\n");
fprintf(stderr, " memory) architecture. Please modify md5.h so HIGHFIRST is\n");
fprintf(stderr, " defined when building for this machine.\n");
return 2;
}
}
#endif
#endif
/* Process command line options. */
for (i = 1; i < argc; i++) {
cp = argv[i];
if (*cp == '-') {
if (strlen(cp) == 1) {
i++;
break; /* - -- Mark end of options; balance are files */
}
opt = *(++cp);
if (islower(opt)) {
opt = toupper(opt);
}
switch (opt) {
case 'C': /* -Csignature -- Check signature, set return code */
docheck = TRUE;
if (strlen(cp + 1) != 32) {
docheck = FALSE;
}
memset(csig, 0, 16);
clabel = cp + 1;
for (j = 0; j < 16; j++) {
if (isxdigit((int) clabel[0]) && isxdigit((int) clabel[1]) &&
sscanf((cp + 1 + (j * 2)), hexfmt, &bp) == 1) {
csig[j] = (unsigned char) bp;
} else {
docheck = FALSE;
break;
}
clabel += 2;
}
if (!docheck) {
fprintf(stderr, "Error in signature specification. Must be 32 hex digits.\n");
return 2;
}
break;
case 'D': /* -Dtext -- Compute signature of given text */
MD5Init(&md5c);
MD5Update(&md5c, (unsigned char *) (cp + 1), strlen(cp + 1));
cdata = TRUE;
f++; /* Mark no infile argument needed */
break;
case 'L': /* -L -- Use lower case letters as hex digits */
hexfmt = "%02x";
break;
case 'N': /* -N -- Don't show file name after sum */
showfile = FALSE;
break;
case 'O': /* -Ofname -- Write output to fname (- = stdout) */
cp++;
if (strcmp(cp, "-") != 0) {
if (out != stdout) {
fprintf(stderr, "Redundant output file specification.\n");
return 2;
}
if ((out = fopen(cp, "w")) == NULL) {
fprintf(stderr, "Cannot open output file %s\n", cp);
return 2;
}
}
break;
case '?': /* -U, -? -H -- Print how to call information. */
case 'H':
case 'U':
printf("\nMD5 -- Calculate MD5 signature of file. Call");
printf("\n with md5 [ options ] [file ...]");
printf("\n");
printf("\n Options:");
printf("\n -csig Check against sig, set exit status 0 = OK");
printf("\n -dtext Compute signature of text argument");
printf("\n -l Use lower case letters for hexadecimal digits");
printf("\n -n Do not show file name after sum");
printf("\n -ofname Write output to fname (- = stdout)");
printf("\n -u Print this message");
printf("\n -v Print version information");
printf("\n");
printf("\nby John Walker -- http://www.fourmilab.ch/");
printf("\nVersion %s\n", VERSION);
printf("\nThis program is in the public domain.\n");
printf("\n");
#ifdef CHECK_HARDWARE_PROPERTIES
#ifdef HIGHFIRST
{ uint32 t = 0x12345678;
if (*((char *) &t) == 0x78) {
fprintf(stderr, "** Note. md5 is not optimally configured for use on this\n");
fprintf(stderr, " machine. This is a little-endian (least significant byte\n");
fprintf(stderr, " first in memory) architecture, yet md5 has been built with the\n");
fprintf(stderr, " symbol HIGHFIRST defined in md5.h, which includes code which\n");
fprintf(stderr, " supports both big- and little-endian machines. Modifying\n");
fprintf(stderr, " md5.h to undefine HIGHFIRST for this platform will make md5\n");
fprintf(stderr, " run faster on it.\n");
}
}
#endif
#endif
return 0;
case 'V': /* -V -- Print version number */
printf("%s\n", VERSION);
return 0;
}
} else {
break;
}
}
if (cdata && (i < argc)) {
fprintf(stderr, "Cannot specify both -d option and input file.\n");
return 2;
}
if ((i >= argc) && (f == 0)) {
f++;
}
for (; (f > 0) || (i < argc); i++) {
if ((!cdata) && (f > 0)) {
ifname = "-";
} else {
ifname = argv[i];
}
f = 0;
if (!cdata) {
int opened = FALSE;
/* If the data weren't supplied on the command line with
the "-d" option, read it now from the input file. */
if (strcmp(ifname, "-") != 0) {
if ((in = fopen(ifname, "rb")) == NULL) {
fprintf(stderr, "Cannot open input file %s\n", ifname);
return 2;
}
opened = TRUE;
} else {
in = stdin;
}
#ifdef _WIN32
/** Warning! On systems which distinguish text mode and
binary I/O (MS-DOS, Macintosh, etc.) the modes in the open
statement for "in" should have forced the input file into
binary mode. But what if we're reading from standard
input? Well, then we need to do a system-specific tweak
to make sure it's in binary mode. While we're at it,
let's set the mode to binary regardless of however fopen
set it.
The following code, conditional on _WIN32, sets binary
mode using the method prescribed by Microsoft Visual C 7.0
("Monkey C"); this may require modification if you're
using a different compiler or release of Monkey C. If
you're porting this code to a different system which
distinguishes text and binary files, you'll need to add
the equivalent call for that system. */
_setmode(_fileno(in), _O_BINARY);
#endif
MD5Init(&md5c);
while ((j = (int) fread(buffer, 1, sizeof buffer, in)) > 0) {
MD5Update(&md5c, buffer, (unsigned) j);
}
if (opened) {
fclose(in);
}
}
MD5Final(signature, &md5c);
if (docheck) {
docheck = 0;
for (j = 0; j < sizeof signature; j++) {
if (signature[j] != csig[j]) {
docheck = 1;
break;
}
}
if (i < (argc - 1)) {
fprintf(stderr, "Only one file may be tested with the -c option.\n");
return 2;
}
} else {
for (j = 0; j < sizeof signature; j++) {
fprintf(out, hexfmt, signature[j]);
}
if ((!cdata) && showfile) {
fprintf(out, " %s", (in == stdin) ? "-" : ifname);
}
fprintf(out, "\n");
}
}
return docheck;
}
sorter测试:
int main(int argc, char *argv[])
{
const char * file = NULL;
if (argc < 2) {
cout << "Usage: sorter.exe xmlfile.xml" << endl;
return 1;
}
file = argv[1];
TiXmlDocument *pXmlApi = NULL;
pXmlApi = new TiXmlDocument(file);
bool loadOkay = pXmlApi->LoadFile();
if (!loadOkay) return 1;
TiXmlNode *root = pXmlApi->FirstChild("NotepadPlus");
if (!root) {
cout << "NotepadPlus node not found\n";
return 1;
}
TiXmlElement *autoc = root->FirstChildElement("AutoComplete");
if (!autoc) {
cout << "AutoComplete node not found\n";
return 1;
}
const char * langName = autoc->Attribute("language");
TiXmlElement *envNode = autoc->FirstChildElement("Environment");
bool ignoreCase = false;
if (envNode) {
cout << "Found environment settings\n";
const char * ignoreCaseText = envNode->Attribute("ignoreCase");
if (ignoreCaseText) {
ignoreCase = (strcmp(ignoreCaseText, "yes") == 0);
if (ignoreCase) {
cout << "Sorting case insensitive\n";
} else {
cout << "Sorting case sensitive\n";
}
} else {
cout <<"Cannot find attribute \"ignoreCase\", defaulting to case sensitive sort\nConsider adding the node\n";
}
} else {
cout << "No environment settings found, defaulting to case sensitive sort\nConsider adding the node\n";
}
vector<xmlname> words;
for (TiXmlElement *childNode = autoc->FirstChildElement("KeyWord");
childNode ;
childNode = childNode->NextSiblingElement("KeyWord") )
{
const char * name = childNode->Attribute("name");
if (!name) {
cout << "Warning: KeyWord without name!, skipping...\n";
continue;
} else {
int i = 0;
while(name[i] != 0) {
if (!isalnum(name[i]) && name[i] != '_') {
cout << "Warning, keyword " << name << " contains unsupported characters!\n";
break;
}
i++;
}
words.push_back(xmlname(childNode, name));
}
}
if (ignoreCase)
sort(words.begin(), words.end(), sortXML);
else
sort(words.begin(), words.end(), sortXMLCase);
for(size_t i = 1; i < words.size(); i++) {
//merge duplicates
if (!strcmp(words[i].name, words[i-1].name)) {
merge(words[i-1].node, words[i].node);
words.erase(words.begin() + i);
}
}
TiXmlDocument doc;
TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "Windows-1252", "" );
doc.LinkEndChild( decl );
TiXmlElement * element = new TiXmlElement( "NotepadPlus" );
doc.LinkEndChild( element );
TiXmlElement * element2 = new TiXmlElement( "AutoComplete" );
element->LinkEndChild( element2 );
if (langName)
element2->SetAttribute("language", langName);
if (envNode)
element2->LinkEndChild(envNode);
for(size_t i = 0; i < words.size(); i++) {
element2->LinkEndChild(words[i].node);
}
doc.SaveFile( file );
return 0;
}
xmlUpdater测试:
int main(int argc, char *argv[])
{
if (argc != 4)
{
printf("Syntax : xmlUpdater model.xml src.xml dest.xml");
return -1;
}
char *xmlModelPath = argv[1];
char *xmlSrcPath = argv[2];
char *xmlDestPath = argv[3];
//printf("%s\n", xmlModelPath);
//printf("%s\n", xmlSrcPath);
//printf("%s\n", xmlDestPath);
TiXmlDocument *pXmlModel = NULL;
TiXmlDocument *pXmlSrc = NULL;
TiXmlDocument *pXmlDest = NULL;
try {
pXmlModel = new TiXmlDocument(xmlModelPath);
bool loadOkay = pXmlModel->LoadFile();
if (!loadOkay) throw int(MODEL_INVALID);
pXmlSrc = new TiXmlDocument(xmlSrcPath);
loadOkay = pXmlSrc->LoadFile();
if (!loadOkay) throw int(SRC_INVALID);
pXmlDest = new TiXmlDocument(xmlDestPath);
loadOkay = pXmlDest->LoadFile();
if (!loadOkay) throw int(DEST_INVALID);
TiXmlNode *root = pXmlModel->FirstChild("Node");
const char *nodeRootName = (root->ToElement())->Attribute("nodeName");
if (nodeRootName)
{
TiXmlNode *srcRoot = pXmlSrc->FirstChild(nodeRootName);
if (!srcRoot) throw int(4);
TiXmlNode *destRoot = pXmlDest->FirstChild(nodeRootName);
if (!destRoot)
{
throw int(DEST_INVALID);
}
else
{
update(root, srcRoot, destRoot);
}
}
} catch (int errMsg) {
char *msg;
if (errMsg == MODEL_INVALID)
msg = "Model file is invalidated";
if (errMsg == SRC_INVALID)
msg = "Source file is invalidated";
if (errMsg == DEST_INVALID)
msg = "File to update is invalidated";
if (pXmlModel) delete pXmlModel;
if (pXmlSrc) delete pXmlSrc;
if (pXmlDest) delete pXmlDest;
printf(msg);
return -1;
}
pXmlDest->SaveFile();
delete pXmlModel;
delete pXmlSrc;
delete pXmlDest;
printf("Update successful");
return 0;
}
学习的目标是成熟!~~~~~