Leptonica 1.68
C Image Processing Library

string_reg.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  * string_reg.c
00018  *
00019  *    This tests several sarray functions.
00020  */
00021 
00022 #include <string.h>
00023 #include "allheaders.h"
00024 
00025 
00026 main(int    argc,
00027      char **argv)
00028 {
00029 l_int32      ignore;
00030 size_t       nbytesin, nbytesout;
00031 char        *infile, *outfile, *instring, *outstring;
00032 SARRAY      *sa1, *sa2, *sa3, *sa4, *sa5;
00033 char         buf[256];
00034 static char  mainName[] = "string_reg";
00035 
00036     if (argc != 2)
00037         return ERROR_INT(" Syntax:  string_reg infile", mainName, 1);
00038 
00039     infile = argv[1];
00040     instring = (char *)l_binaryRead(infile, &nbytesin);
00041 
00042     if (!instring)
00043         return ERROR_INT("file not read", mainName, 1);
00044 
00045     sa1 = sarrayCreateWordsFromString(instring);
00046     sa2 = sarrayCreateLinesFromString(instring, 0);
00047     sa3 = sarrayCreateLinesFromString(instring, 1);
00048 
00049     outstring = sarrayToString(sa1, 0);
00050     nbytesout = strlen(outstring);
00051     l_binaryWrite("/tmp/junk1.txt", "w", outstring, nbytesout);
00052     lept_free(outstring);
00053 
00054     outstring = sarrayToString(sa1, 1);
00055     nbytesout = strlen(outstring);
00056     l_binaryWrite("/tmp/junk2.txt", "w", outstring, nbytesout);
00057     lept_free(outstring);
00058 
00059     outstring = sarrayToString(sa2, 0);
00060     nbytesout = strlen(outstring);
00061     l_binaryWrite("/tmp/junk3.txt", "w", outstring, nbytesout);
00062     lept_free(outstring);
00063 
00064     outstring = sarrayToString(sa2, 1);
00065     nbytesout = strlen(outstring);
00066     l_binaryWrite("/tmp/junk4.txt", "w", outstring, nbytesout);
00067     lept_free(outstring);
00068 
00069     outstring = sarrayToString(sa3, 0);
00070     nbytesout = strlen(outstring);
00071     l_binaryWrite("/tmp/junk5.txt", "w", outstring, nbytesout);
00072     lept_free(outstring);
00073 
00074     outstring = sarrayToString(sa3, 1);
00075     nbytesout = strlen(outstring);
00076     l_binaryWrite("/tmp/junk6.txt", "w", outstring, nbytesout);
00077     lept_free(outstring);
00078     sprintf(buf, "diff -s /tmp/junk6.txt %s", infile);
00079     ignore = system(buf);
00080 
00081         /* write/read/write; compare /tmp/junkout5 with /tmp/junkout6 */
00082     sarrayWrite("/tmp/junk7.txt", sa2);
00083     sarrayWrite("/tmp/junk8.txt", sa3);
00084     sa4 = sarrayRead("/tmp/junk8.txt");
00085     sarrayWrite("/tmp/junk9.txt", sa4);
00086     sa5 = sarrayRead("/tmp/junk9.txt");
00087     ignore = system("diff -s /tmp/junk8.txt /tmp/junk9.txt");
00088 
00089     sarrayDestroy(&sa1);
00090     sarrayDestroy(&sa2);
00091     sarrayDestroy(&sa3);
00092     sarrayDestroy(&sa4);
00093     sarrayDestroy(&sa5);
00094     lept_free(instring);
00095 
00096     return 0;
00097 }
00098 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines