本文整理汇总了C++中sarrayToString函数的典型用法代码示例。如果您正苦于以下问题:C++ sarrayToString函数的具体用法?C++ sarrayToString怎么用?C++ sarrayToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sarrayToString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: captureProtoSignature
/*
* captureProtoSignature()
*
* Input: sa (output from cpp, by line)
* start (starting index to search; never a comment line)
* stop (index of line on which pattern is completed)
* charindex (char index of completing ')' character)
* Return: cleanstr (prototype string), or NULL on error
*
* Notes:
* (1) Return all characters, ending with a ';' after the ')'
*/
static char *
captureProtoSignature(SARRAY *sa,
l_int32 start,
l_int32 stop,
l_int32 charindex)
{
char *str, *newstr, *protostr, *cleanstr;
SARRAY *sap;
l_int32 i;
PROCNAME("captureProtoSignature");
if (!sa)
return (char *)ERROR_PTR("sa not defined", procName, NULL);
sap = sarrayCreate(0);
for (i = start; i < stop; i++) {
str = sarrayGetString(sa, i, L_COPY);
sarrayAddString(sap, str, L_INSERT);
}
str = sarrayGetString(sa, stop, L_COPY);
str[charindex + 1] = '\0';
newstr = stringJoin(str, ";");
sarrayAddString(sap, newstr, L_INSERT);
LEPT_FREE(str);
protostr = sarrayToString(sap, 2);
sarrayDestroy(&sap);
cleanstr = cleanProtoSignature(protostr);
LEPT_FREE(protostr);
return cleanstr;
}
示例2: parseForProtos
//.........这里部分代码省略.........
* prototypes have one or more sets of '(' followed eventually
* by a ')', and end with ';'. But function definitions have
* tokens, followed by '(', more tokens, ')' and then
* immediately a '{'. We would generate a prototype from this
* by adding a ';' to all tokens up to the ')'. So we use
* these special tokens to decide what we are parsing. And
* whenever a function definition is found and the prototype
* extracted, we skip through the rest of the function
* past the corresponding '}'. This token ends a line, and
* is often on a line of its own. But as it turns out,
* the only keyword we need to consider is 'static'.
* (4) Plan 3. Consider the parentheses and braces for various
* declarations. A struct, enum, or union has a pair of
* braces followed by a semicolon. They cannot have parentheses
* before the left brace, but a struct can have lots of parentheses
* within the brace set. A function prototype has no braces.
* A function declaration can have sets of left and right
* parentheses, but these are followed by a left brace.
* So plan 3 looks at the way parentheses and braces are
* organized. Once the beginning of a function definition
* is found, the prototype is extracted and we search for
* the ending right brace.
* (5) To find the ending right brace, it is necessary to do some
* careful parsing. For example, in this file, we have
* left and right braces as characters, and these must not
* be counted. Somewhat more tricky, the file fhmtauto.c
* generates code, and includes a right brace in a string.
* So we must not include braces that are in strings. But how
* do we know if something is inside a string? Keep state,
* starting with not-inside, and every time you hit a double quote
* that is not escaped, toggle the condition. Any brace
* found in the state of being within a string is ignored.
* (6) When a prototype is extracted, it is put in a canonical
* form (i.e., cleaned up). Finally, we check that it is
* not static and save it. (If static, it is ignored).
* (7) The @prestring for unix is NULL; it is included here so that
* you can use Microsoft's declaration for importing or
* exporting to a dll. See environ.h for examples of use.
* Here, we set: @prestring = "LEPT_DLL ". Note in particular
* the space character that will separate 'LEPT_DLL' from
* the standard unix prototype that follows.
*/
char *
parseForProtos(const char *filein,
const char *prestring)
{
char *strdata, *str, *newstr, *parsestr, *secondword;
l_int32 nbytes, start, next, stop, charindex, found;
SARRAY *sa, *saout, *satest;
PROCNAME("parseForProtos");
if (!filein)
return (char *)ERROR_PTR("filein not defined", procName, NULL);
/* Read in the cpp output into memory, one string for each
* line in the file, omitting blank lines. */
strdata = (char *)arrayRead(filein, &nbytes);
sa = sarrayCreateLinesFromString(strdata, 0);
saout = sarrayCreate(0);
next = 0;
while (1) { /* repeat after each non-static prototype is extracted */
searchForProtoSignature(sa, next, &start, &stop, &charindex, &found);
if (!found)
break;
/* fprintf(stderr, " start = %d, stop = %d, charindex = %d\n",
start, stop, charindex); */
str = captureProtoSignature(sa, start, stop, charindex);
/* Make sure it is not static. Note that 'extern' has
* been prepended to the prototype, so the 'static'
* keyword, if it exists, would be the second word. */
satest = sarrayCreateWordsFromString(str);
secondword = sarrayGetString(satest, 1, 0);
if (strcmp(secondword, "static")) { /* not static */
if (prestring) { /* prepend it to the prototype */
newstr = stringJoin(prestring, str);
sarrayAddString(saout, newstr, L_INSERT);
FREE(str);
}
else
sarrayAddString(saout, str, L_INSERT);
}
else
FREE(str);
sarrayDestroy(&satest);
skipToEndOfFunction(sa, stop, charindex, &next);
if (next == -1) break;
}
/* Flatten into a string with newlines between prototypes */
parsestr = sarrayToString(saout, 1);
FREE(strdata);
sarrayDestroy(&sa);
sarrayDestroy(&saout);
return parsestr;
}
示例3: cleanProtoSignature
/*
* cleanProtoSignature()
*
* Input: instr (input prototype string)
* Return: cleanstr (clean prototype string), or NULL on error
*
* Notes:
* (1) Adds 'extern' at beginning and regularizes spaces
* between tokens.
*/
static char *
cleanProtoSignature(char *instr)
{
char *str, *cleanstr;
char buf[L_BUF_SIZE];
char externstring[] = "extern";
l_int32 i, j, nwords, nchars, index, len;
SARRAY *sa, *saout;
PROCNAME("cleanProtoSignature");
if (!instr)
return (char *)ERROR_PTR("instr not defined", procName, NULL);
sa = sarrayCreateWordsFromString(instr);
nwords = sarrayGetCount(sa);
saout = sarrayCreate(0);
sarrayAddString(saout, externstring, 1);
for (i = 0; i < nwords; i++) {
str = sarrayGetString(sa, i, 0);
nchars = strlen(str);
index = 0;
for (j = 0; j < nchars; j++) {
if (index > L_BUF_SIZE - 6)
return (char *)ERROR_PTR("token too large", procName, NULL);
if (str[j] == '(') {
buf[index++] = ' ';
buf[index++] = '(';
buf[index++] = ' ';
}
else if (str[j] == ')') {
buf[index++] = ' ';
buf[index++] = ')';
}
else
buf[index++] = str[j];
}
buf[index] = '\0';
sarrayAddString(saout, buf, 1);
}
/* Flatten to a prototype string with spaces added after
* each word, and remove the last space */
cleanstr = sarrayToString(saout, 2);
len = strlen(cleanstr);
cleanstr[len - 1] = '\0';
sarrayDestroy(&sa);
sarrayDestroy(&saout);
return cleanstr;
}
示例4: l_genDataString
/*!
* \brief l_genDataString()
*
* \param[in] filein input file of serialized data
* \param[in] ifunc index into set of functions in output file
* \return encoded ascii data string, or NULL on error reading from file
*/
static char *
l_genDataString(const char *filein,
l_int32 ifunc)
{
char buf[80];
char *cdata1, *cdata2, *cdata3;
l_uint8 *data1, *data2;
l_int32 csize1, csize2;
size_t size1, size2;
SARRAY *sa;
PROCNAME("l_genDataString");
if (!filein)
return (char *)ERROR_PTR("filein not defined", procName, NULL);
/* Read it in, gzip it, encode, and reformat. We gzip because some
* serialized data has a significant amount of ascii content. */
if ((data1 = l_binaryRead(filein, &size1)) == NULL)
return (char *)ERROR_PTR("bindata not returned", procName, NULL);
data2 = zlibCompress(data1, size1, &size2);
cdata1 = encodeBase64(data2, size2, &csize1);
cdata2 = reformatPacked64(cdata1, csize1, 4, 72, 1, &csize2);
LEPT_FREE(data1);
LEPT_FREE(data2);
LEPT_FREE(cdata1);
/* Prepend the string declaration signature and put it together */
sa = sarrayCreate(3);
snprintf(buf, sizeof(buf), "static const char *l_strdata_%d =\n", ifunc);
sarrayAddString(sa, buf, L_COPY);
sarrayAddString(sa, cdata2, L_INSERT);
sarrayAddString(sa, (char *)";\n", L_COPY);
cdata3 = sarrayToString(sa, 0);
sarrayDestroy(&sa);
return cdata3;
}
示例5: gplotGenCommandFile
/*!
* gplotGenCommandFile()
*
* Input: gplot
* Return: 0 if OK, 1 on error
*/
l_int32
gplotGenCommandFile(GPLOT *gplot)
{
char buf[L_BUF_SIZE];
char *cmdstr, *plottitle, *dataname;
l_int32 i, plotstyle, nplots;
FILE *fp;
PROCNAME("gplotGenCommandFile");
if (!gplot)
return ERROR_INT("gplot not defined", procName, 1);
/* Remove any previous command data */
sarrayClear(gplot->cmddata);
/* Generate command data instructions */
if (gplot->title) { /* set title */
snprintf(buf, L_BUF_SIZE, "set title '%s'", gplot->title);
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
if (gplot->xlabel) { /* set xlabel */
snprintf(buf, L_BUF_SIZE, "set xlabel '%s'", gplot->xlabel);
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
if (gplot->ylabel) { /* set ylabel */
snprintf(buf, L_BUF_SIZE, "set ylabel '%s'", gplot->ylabel);
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
if (gplot->outformat == GPLOT_PNG) /* set terminal type and output */
snprintf(buf, L_BUF_SIZE, "set terminal png; set output '%s'",
gplot->outname);
else if (gplot->outformat == GPLOT_PS)
snprintf(buf, L_BUF_SIZE, "set terminal postscript; set output '%s'",
gplot->outname);
else if (gplot->outformat == GPLOT_EPS)
snprintf(buf, L_BUF_SIZE,
"set terminal postscript eps; set output '%s'",
gplot->outname);
else if (gplot->outformat == GPLOT_LATEX)
snprintf(buf, L_BUF_SIZE, "set terminal latex; set output '%s'",
gplot->outname);
else /* gplot->outformat == GPLOT_X11 */
#ifndef _WIN32
snprintf(buf, L_BUF_SIZE, "set terminal x11");
#else
snprintf(buf, L_BUF_SIZE, "set terminal windows");
#endif /* _WIN32 */
sarrayAddString(gplot->cmddata, buf, L_COPY);
if (gplot->scaling == GPLOT_LOG_SCALE_X ||
gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
snprintf(buf, L_BUF_SIZE, "set logscale x");
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
if (gplot->scaling == GPLOT_LOG_SCALE_Y ||
gplot->scaling == GPLOT_LOG_SCALE_X_Y) {
snprintf(buf, L_BUF_SIZE, "set logscale y");
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
nplots = sarrayGetCount(gplot->datanames);
for (i = 0; i < nplots; i++) {
plottitle = sarrayGetString(gplot->plottitles, i, L_NOCOPY);
dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
numaGetIValue(gplot->plotstyles, i, &plotstyle);
if (nplots == 1) {
snprintf(buf, L_BUF_SIZE, "plot '%s' title '%s' %s",
dataname, plottitle, gplotstylenames[plotstyle]);
} else {
if (i == 0)
snprintf(buf, L_BUF_SIZE, "plot '%s' title '%s' %s, \\",
dataname, plottitle, gplotstylenames[plotstyle]);
else if (i < nplots - 1)
snprintf(buf, L_BUF_SIZE, " '%s' title '%s' %s, \\",
dataname, plottitle, gplotstylenames[plotstyle]);
else
snprintf(buf, L_BUF_SIZE, " '%s' title '%s' %s",
dataname, plottitle, gplotstylenames[plotstyle]);
}
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
/* Write command data to file */
cmdstr = sarrayToString(gplot->cmddata, 1);
if ((fp = fopenWriteStream(gplot->cmdname, "w")) == NULL)
return ERROR_INT("cmd stream not opened", procName, 1);
fwrite(cmdstr, 1, strlen(cmdstr), fp);
fclose(fp);
FREE(cmdstr);
return 0;
}
示例6: gplotAddPlot
/*!
* gplotAddPlot()
*
* Input: gplot
* nax (<optional> numa: set to null for Y_VS_I;
* required for Y_VS_X)
* nay (numa: required for both Y_VS_I and Y_VS_X)
* plotstyle (GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES,
* GPLOT_LINESPOINTS, GPLOT_DOTS)
* plottitle (<optional> title for individual plot)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) There are 2 options for (x,y) values:
* o To plot an array vs a linear function of the
* index, set nax = NULL.
* o To plot one array vs another, use both nax and nay.
* (2) If nax is NULL, the x value corresponding to the i-th
* value of nay is found from the startx and delx fields
* in nay:
* x = startx + i * delx
* These are set with numaSetParameters(). Their default
* values are startx = 0.0, delx = 1.0.
* (3) If nax is defined, it must be the same size as nay.
* (4) The 'plottitle' string can have spaces, double
* quotes and backquotes, but not single quotes.
*/
l_int32
gplotAddPlot(GPLOT *gplot,
NUMA *nax,
NUMA *nay,
l_int32 plotstyle,
const char *plottitle)
{
char buf[L_BUF_SIZE];
char emptystring[] = "";
char *datastr, *title;
l_int32 n, i;
l_float32 valx, valy, startx, delx;
SARRAY *sa;
PROCNAME("gplotAddPlot");
if (!gplot)
return ERROR_INT("gplot not defined", procName, 1);
if (!nay)
return ERROR_INT("nay not defined", procName, 1);
if (plotstyle != GPLOT_LINES && plotstyle != GPLOT_POINTS &&
plotstyle != GPLOT_IMPULSES && plotstyle != GPLOT_LINESPOINTS &&
plotstyle != GPLOT_DOTS)
return ERROR_INT("invalid plotstyle", procName, 1);
n = numaGetCount(nay);
numaGetParameters(nay, &startx, &delx);
if (nax) {
if (n != numaGetCount(nax))
return ERROR_INT("nax and nay sizes differ", procName, 1);
}
/* Save plotstyle and plottitle */
numaAddNumber(gplot->plotstyles, plotstyle);
if (plottitle) {
title = stringNew(plottitle);
sarrayAddString(gplot->plottitles, title, L_INSERT);
} else {
sarrayAddString(gplot->plottitles, emptystring, L_COPY);
}
/* Generate and save data filename */
gplot->nplots++;
snprintf(buf, L_BUF_SIZE, "%s.data.%d", gplot->rootname, gplot->nplots);
sarrayAddString(gplot->datanames, buf, L_COPY);
/* Generate data and save as a string */
sa = sarrayCreate(n);
for (i = 0; i < n; i++) {
if (nax)
numaGetFValue(nax, i, &valx);
else
valx = startx + i * delx;
numaGetFValue(nay, i, &valy);
snprintf(buf, L_BUF_SIZE, "%f %f\n", valx, valy);
sarrayAddString(sa, buf, L_COPY);
}
datastr = sarrayToString(sa, 0);
sarrayAddString(gplot->plotdata, datastr, L_INSERT);
sarrayDestroy(&sa);
return 0;
}
示例7: main
//.........这里部分代码省略.........
error = TRUE;
sarrayAddString(sa, (char *)"conversion 4 bpp ==> 32 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 4 bpp <==> 32 bpp\n");
cmap = pixGetColormap(pixc4);
pixt4 = pixOctcubeQuantFromCmap(pixt3, cmap, 2, 4, L_EUCLIDEAN_DISTANCE);
pixEqual(pixc4, pixt4, &same);
if (!same) {
pixDisplayWithTitle(pixc4, 100, 100, "4 bpp, cmap", DFLAG);
pixDisplayWithTitle(pixt4, 500, 100, "4 bpp, cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 4 bpp <==> 32 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 4 bpp <==> 32 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
pixDestroy(&pixt4);
/* Conversion: 8 bpp --> 32 bpp --> 8 bpp */
pixt1 = pixConvertTo32(pixs8);
pixt2 = pixConvertTo8(pixt1, FALSE);
pixEqual(pixs8, pixt2, &same);
if (!same) {
pixDisplayWithTitle(pixs8, 100, 100, "8 bpp", DFLAG);
pixDisplayWithTitle(pixt2, 500, 100, "8 bpp", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 8 bpp <==> 32 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 8 bpp <==> 32 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
/* Conversion: 8 bpp --> 16 bpp --> 8 bpp */
pixt1 = pixConvert8To16(pixs8, 8);
pixt2 = pixConvertTo8(pixt1, FALSE);
pixEqual(pixs8, pixt2, &same);
if (!same) {
pixDisplayWithTitle(pixs8, 100, 100, "8 bpp", DFLAG);
pixDisplayWithTitle(pixt2, 500, 100, "8 bpp", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 8 bpp <==> 16 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 8 bpp <==> 16 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
/* Conversion: 16 bpp --> 8 bpp --> 16 bpp */
pixt1 = pixConvert16To8(pixs16, 1);
pixt2 = pixConvertTo16(pixt1);
pixWrite("/tmp/junkpix.png", pixt2, IFF_PNG);
pixEqual(pixs16, pixt2, &same);
if (!same) {
pixDisplayWithTitle(pixs16, 100, 100, "16 bpp", DFLAG);
pixDisplayWithTitle(pixt2, 500, 100, "16 bpp", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 16 bpp <==> 8 bpp", L_COPY);
} else
fprintf(stderr, "OK: conversion 16 bpp <==> 8 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
/* Conversion: 8 bpp cmap --> 32 bpp --> 8 bpp cmap */
/* Required to go to level 6 of octcube to get identical result */
pixt1 = pixConvertTo32(pixc8);
cmap = pixGetColormap(pixc8);
pixt2 = pixOctcubeQuantFromCmap(pixt1, cmap, 2, 6, L_EUCLIDEAN_DISTANCE);
pixEqual(pixc8, pixt2, &same);
if (!same) {
pixDisplayWithTitle(pixc8, 100, 100, "8 bpp cmap", DFLAG);
pixDisplayWithTitle(pixt2, 500, 100, "8 bpp cmap", DFLAG);
error = TRUE;
sarrayAddString(sa, (char *)"conversion 8 bpp cmap <==> 32 bpp cmap",
L_COPY);
} else
fprintf(stderr, "OK: conversion 8 bpp <==> 32 bpp\n");
pixDestroy(&pixt1);
pixDestroy(&pixt2);
/* Summarize results */
if (error == FALSE)
fprintf(stderr, "No errors found\n");
else {
errorstr = sarrayToString(sa, 1);
fprintf(stderr, "Errors in the following:\n %s", errorstr);
lept_free(errorstr);
}
sarrayDestroy(&sa);
pixDestroy(&pixs1);
pixDestroy(&pixs2);
pixDestroy(&pixs4);
pixDestroy(&pixc2);
pixDestroy(&pixc4);
pixDestroy(&pixs8);
pixDestroy(&pixc8);
pixDestroy(&pixs16);
pixDestroy(&pixs32);
return 0;
}
示例8: parseForProtos
//.........这里部分代码省略.........
* (4) Plan 3. Consider the parentheses and braces for various
* declarations. A struct, enum, or union has a pair of
* braces followed by a semicolon. They cannot have parentheses
* before the left brace, but a struct can have lots of parentheses
* within the brace set. A function prototype has no braces.
* A function declaration can have sets of left and right
* parentheses, but these are followed by a left brace.
* So plan 3 looks at the way parentheses and braces are
* organized. Once the beginning of a function definition
* is found, the prototype is extracted and we search for
* the ending right brace.
* (5) To find the ending right brace, it is necessary to do some
* careful parsing. For example, in this file, we have
* left and right braces as characters, and these must not
* be counted. Somewhat more tricky, the file fhmtauto.c
* generates code, and includes a right brace in a string.
* So we must not include braces that are in strings. But how
* do we know if something is inside a string? Keep state,
* starting with not-inside, and every time you hit a double quote
* that is not escaped, toggle the condition. Any brace
* found in the state of being within a string is ignored.
* (6) When a prototype is extracted, it is put in a canonical
* form (i.e., cleaned up). Finally, we check that it is
* not static and save it. (If static, it is ignored).
* (7) The @prestring for unix is NULL; it is included here so that
* you can use Microsoft's declaration for importing or
* exporting to a dll. See environ.h for examples of use.
* Here, we set: @prestring = "LEPT_DLL ". Note in particular
* the space character that will separate 'LEPT_DLL' from
* the standard unix prototype that follows.
*/
char *
parseForProtos(const char *filein,
const char *prestring)
{
char *strdata, *str, *newstr, *parsestr, *secondword;
l_int32 start, next, stop, charindex, found;
size_t nbytes;
SARRAY *sa, *saout, *satest;
PROCNAME("parseForProtos");
if (!filein)
return (char *)ERROR_PTR("filein not defined", procName, NULL);
/* Read in the cpp output into memory, one string for each
* line in the file, omitting blank lines. */
strdata = (char *)l_binaryRead(filein, &nbytes);
sa = sarrayCreateLinesFromString(strdata, 0);
saout = sarrayCreate(0);
next = 0;
while (1) { /* repeat after each non-static prototype is extracted */
searchForProtoSignature(sa, next, &start, &stop, &charindex, &found);
if (!found)
break;
/* fprintf(stderr, " start = %d, stop = %d, charindex = %d\n",
start, stop, charindex); */
str = captureProtoSignature(sa, start, stop, charindex);
/* Make sure that the signature found by cpp is neither
* static nor extern. We get 'extern' declarations from
* header files, and with some versions of cpp running on
* #include <sys/stat.h> we get something of the form:
* extern ... (( ... )) ... ( ... ) { ...
* For this, the 1st '(' is the lp, the 2nd ')' is the rp,
* and there is a lot of garbage between the rp and the lb.
* It is easiest to simply reject any signature that starts
* with 'extern'. Note also that an 'extern' token has been
* prepended to each prototype, so the 'static' or
* 'extern' keywords we are looking for, if they exist,
* would be the second word. */
satest = sarrayCreateWordsFromString(str);
secondword = sarrayGetString(satest, 1, L_NOCOPY);
if (strcmp(secondword, "static") && /* not static */
strcmp(secondword, "extern")) { /* not extern */
if (prestring) { /* prepend it to the prototype */
newstr = stringJoin(prestring, str);
sarrayAddString(saout, newstr, L_INSERT);
LEPT_FREE(str);
} else {
sarrayAddString(saout, str, L_INSERT);
}
} else {
LEPT_FREE(str);
}
sarrayDestroy(&satest);
skipToEndOfFunction(sa, stop, charindex, &next);
if (next == -1) break;
}
/* Flatten into a string with newlines between prototypes */
parsestr = sarrayToString(saout, 1);
LEPT_FREE(strdata);
sarrayDestroy(&sa);
sarrayDestroy(&saout);
return parsestr;
}
示例9: fmorphautogen2
//.........这里部分代码省略.........
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
sarrayAddString(sa4, str_doc2, L_INSERT);
sarrayAddString(sa4, str_doc3, L_INSERT);
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
/* Insert static protos */
for (i = 0; i < 2 * nsels; i++) {
if ((linestr = sarrayGetString(sa3, i, L_COPY)) == NULL) {
sarrayDestroy(&sa1);
sarrayDestroy(&sa2);
sarrayDestroy(&sa3);
sarrayDestroy(&sa4);
return ERROR_INT("linestr not retrieved", procName, 1);
}
sarrayAddString(sa4, linestr, L_INSERT);
}
/* Insert function header */
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
sarrayAddString(sa4, str_doc4, L_INSERT);
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
sarrayAddString(sa4, str_def1, L_INSERT);
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
/* Generate and insert the dispatcher code */
for (i = 0; i < 2 * nsels; i++) {
sprintf(bigbuf, " case %d:", i);
sarrayAddString(sa4, bigbuf, L_COPY);
sprintf(bigbuf, " %s(datad, w, h, wpld, datas, wpls);",
sarrayGetString(sa2, i, L_NOCOPY));
sarrayAddString(sa4, bigbuf, L_COPY);
sarrayAddString(sa4, breakstring, L_COPY);
}
/* Finish the dispatcher and introduce the low-level code */
sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa4, sa1, actstart, end);
/* Get the range for the args common to all functions */
sarrayParseRange(sa1, newstart, &argstart, &argend, &newstart, "--", 0);
/* Get the range for the loop code common to all functions */
sarrayParseRange(sa1, newstart, &loopstart, &loopend, &newstart, "--", 0);
/* Get the range for the ending code common to all functions */
sarrayParseRange(sa1, newstart, &finalstart, &finalend, &newstart, "--", 0);
/* Do all the static functions */
for (i = 0; i < 2 * nsels; i++) {
/* Generate the function header and add the common args */
sarrayAddString(sa4, staticstring, L_COPY);
fname = sarrayGetString(sa2, i, L_NOCOPY);
sprintf(bigbuf, "%s(l_uint32 *datad,", fname);
sarrayAddString(sa4, bigbuf, L_COPY);
sarrayAppendRange(sa4, sa1, argstart, argend);
/* Declare and define wplsN args, as necessary */
if ((sel = selaGetSel(sela, i/2)) == NULL) {
sarrayDestroy(&sa1);
sarrayDestroy(&sa2);
sarrayDestroy(&sa3);
sarrayDestroy(&sa4);
return ERROR_INT("sel not returned", procName, 1);
}
sa5 = sarrayMakeWplsCode(sel);
sarrayJoin(sa4, sa5);
sarrayDestroy(&sa5);
/* Add the function loop code */
sarrayAppendRange(sa4, sa1, loopstart, loopend);
/* Insert barrel-op code for *dptr */
sa6 = sarrayMakeInnerLoopDWACode(sel, i);
sarrayJoin(sa4, sa6);
sarrayDestroy(&sa6);
/* Finish the function code */
sarrayAppendRange(sa4, sa1, finalstart, finalend);
}
/* Output to file */
filestr = sarrayToString(sa4, 1);
nbytes = strlen(filestr);
if (filename)
snprintf(bigbuf, L_BUF_SIZE, "%slow.%d.c", filename, fileindex);
else
sprintf(bigbuf, "%slow.%d.c", OUTROOT, fileindex);
l_binaryWrite(bigbuf, "w", filestr, nbytes);
sarrayDestroy(&sa1);
sarrayDestroy(&sa2);
sarrayDestroy(&sa3);
sarrayDestroy(&sa4);
LEPT_FREE(filestr);
return 0;
}
示例10: fmorphautogen1
//.........这里部分代码省略.........
fileindex);
str_low_dtp1 = stringNew(bigbuf);
/* Make the output sa */
sa3 = sarrayCreate(0);
/* Copyright notice and info header */
sarrayParseRange(sa2, 0, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Insert function names as documentation */
sarrayAddString(sa3, str_doc1, L_INSERT);
sarrayAddString(sa3, str_doc2, L_INSERT);
/* Add '#include's */
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Insert function prototypes */
sarrayAddString(sa3, str_proto1, L_INSERT);
sarrayAddString(sa3, str_proto2, L_INSERT);
sarrayAddString(sa3, str_proto3, L_INSERT);
/* Add static globals */
sprintf(bigbuf, "\nstatic l_int32 NUM_SELS_GENERATED = %d;", nsels);
sarrayAddString(sa3, bigbuf, L_COPY);
sprintf(bigbuf, "static char SEL_NAMES[][80] = {");
sarrayAddString(sa3, bigbuf, L_COPY);
for (i = 0; i < nsels - 1; i++) {
sprintf(bigbuf, " \"%s\",",
sarrayGetString(sa1, i, L_NOCOPY));
sarrayAddString(sa3, bigbuf, L_COPY);
}
sprintf(bigbuf, " \"%s\"};",
sarrayGetString(sa1, i, L_NOCOPY));
sarrayAddString(sa3, bigbuf, L_COPY);
/* Start pixMorphDwa_*() function description */
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_doc3, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Finish pixMorphDwa_*() function definition */
sarrayAddString(sa3, str_def1, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_proc1, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_dwa1, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Start pixFMorphopGen_*() function description */
sarrayAddString(sa3, str_doc4, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Finish pixFMorphopGen_*() function definition */
sarrayAddString(sa3, str_def2, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_proc2, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_dt, L_COPY);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_ds, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_tsp1, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_dt, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_ts, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
sarrayAddString(sa3, str_low_dtp1, L_INSERT);
sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
sarrayAppendRange(sa3, sa2, actstart, end);
/* Output to file */
filestr = sarrayToString(sa3, 1);
nbytes = strlen(filestr);
if (filename)
snprintf(bigbuf, L_BUF_SIZE, "%s.%d.c", filename, fileindex);
else
sprintf(bigbuf, "%s.%d.c", OUTROOT, fileindex);
l_binaryWrite(bigbuf, "w", filestr, nbytes);
sarrayDestroy(&sa1);
sarrayDestroy(&sa2);
sarrayDestroy(&sa3);
LEPT_FREE(filestr);
return 0;
}
示例11: main
main(int argc,
char **argv)
{
char *filename, *filein, *str, *prestring;
const char *spacestr = " ";
char buf[L_BUF_SIZE];
l_int32 i, firstfile, len, ret;
SARRAY *sa;
static char mainName[] = "xtractprotos";
/* Output extern C head */
sa = sarrayCreate(0);
sarrayAddString(sa, (char *)"/*", 1);
snprintf(buf, L_BUF_SIZE,
" * This file was autogen'd by xtractprotos, v. %s", version);
sarrayAddString(sa, buf, 1);
sarrayAddString(sa, (char *)" */", 1);
sarrayAddString(sa, (char *)"#ifdef __cplusplus", 1);
sarrayAddString(sa, (char *)"extern \"C\" {", 1);
sarrayAddString(sa, (char *)"#endif /* __cplusplus */\n", 1);
str = sarrayToString(sa, 1);
fprintf(stdout, str);
sarrayDestroy(&sa);
FREE(str);
/* Prepend 'prestring' if requested */
firstfile = 1;
prestring = NULL;
if (argv[1][0] == '-') {
firstfile = 2;
if (sscanf(argv[1], "-prestring=%s", buf) != 1)
L_WARNING("Failure to parse prestring; omitting!", mainName);
else {
if ((len = strlen(buf)) > L_BUF_SIZE - 3)
L_WARNING("prestring too large; omitting!", mainName);
else {
buf[len] = ' ';
buf[len + 1] = '\0';
prestring = stringNew(buf);
}
}
}
for (i = firstfile; i < argc; i++) {
filein = argv[i];
len = strlen(filein);
if (filein[len - 1] == 'h')
continue;
snprintf(buf, L_BUF_SIZE, "cpp -ansi -DNO_PROTOS %s %s",
filein, tempfile);
ret = system(buf);
if (ret) {
fprintf(stderr, "cpp failure for %s; continuing\n", filein);
continue;
}
#ifndef _CYGWIN_ENVIRON
filename = stringNew(tempfile);
#else
filename = stringJoin(tempfile, ".exe");
#endif /* ~ _CYGWIN_ENVIRON */
if ((str = parseForProtos(filename, prestring)) == NULL) {
fprintf(stderr, "parse failure for %s; continuing\n", filein);
continue;
}
if (strlen(str) > 1) /* strlen(str) == 1 is a file without protos */
fprintf(stdout, str);
FREE(str);
FREE(filename);
}
/* Output extern C tail */
sa = sarrayCreate(0);
sarrayAddString(sa, (char *)"\n#ifdef __cplusplus", 1);
sarrayAddString(sa, (char *)"}", 1);
sarrayAddString(sa, (char *)"#endif /* __cplusplus */", 1);
str = sarrayToString(sa, 1);
fprintf(stdout, str);
sarrayDestroy(&sa);
FREE(str);
if (prestring)
FREE(prestring);
return 0;
}
示例12: main
main(int argc,
char **argv)
{
char *str;
l_int32 i, j, same, ok;
l_float32 sum, avediff, rmsdiff;
L_KERNEL *kel1, *kel2, *kel3, *kel4, *kelx, *kely;
BOX *box;
PIX *pix, *pixs, *pixb, *pixg, *pixr, *pixd, *pixp, *pixt;
PIX *pixt1, *pixt2, *pixt3;
PIXA *pixa;
SARRAY *sa;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
pixa = pixaCreate(0);
/* Test creating from a string */
kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr);
pixd = kernelDisplayInPix(kel1, 41, 2);
pixWrite("/tmp/pixkern.png", pixd, IFF_PNG);
regTestCheckFile(rp, "/tmp/pixkern.png"); /* 0 */
pixSaveTiled(pixd, pixa, 1, 1, 20, 8);
pixDestroy(&pixd);
kernelDestroy(&kel1);
/* Test read/write for kernel. Note that both get
* compared to the same golden file, which is
* overwritten with a copy of /tmp/kern2.kel */
kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr);
kernelWrite("/tmp/kern1.kel", kel1);
regTestCheckFile(rp, "/tmp/kern1.kel"); /* 1 */
kel2 = kernelRead("/tmp/kern1.kel");
kernelWrite("/tmp/kern2.kel", kel2);
regTestCheckFile(rp, "/tmp/kern2.kel"); /* 2 */
regTestCompareFiles(rp, 1, 2); /* 3 */
kernelDestroy(&kel1);
kernelDestroy(&kel2);
/* Test creating from a file */
sa = sarrayCreate(0);
sarrayAddString(sa, (char *)"# small 3x3 kernel", L_COPY);
sarrayAddString(sa, (char *)"3 5", L_COPY);
sarrayAddString(sa, (char *)"1 2", L_COPY);
sarrayAddString(sa, (char *)"20.5 50 80 50 20", L_COPY);
sarrayAddString(sa, (char *)"82. 120 180 120 80", L_COPY);
sarrayAddString(sa, (char *)"22.1 50 80 50 20", L_COPY);
str = sarrayToString(sa, 1);
l_binaryWrite("/tmp/kernfile.kel", "w", str, strlen(str));
kel2 = kernelCreateFromFile("/tmp/kernfile.kel");
pixd = kernelDisplayInPix(kel2, 41, 2);
pixSaveTiled(pixd, pixa, 1, 1, 20, 0);
pixWrite("/tmp/ker1.png", pixd, IFF_PNG);
regTestCheckFile(rp, "/tmp/ker1.png"); /* 4 */
pixDestroy(&pixd);
sarrayDestroy(&sa);
lept_free(str);
kernelDestroy(&kel2);
/* Test creating from a pix */
pixt = pixCreate(5, 3, 8);
pixSetPixel(pixt, 0, 0, 20);
pixSetPixel(pixt, 1, 0, 50);
pixSetPixel(pixt, 2, 0, 80);
pixSetPixel(pixt, 3, 0, 50);
pixSetPixel(pixt, 4, 0, 20);
pixSetPixel(pixt, 0, 1, 80);
pixSetPixel(pixt, 1, 1, 120);
pixSetPixel(pixt, 2, 1, 180);
pixSetPixel(pixt, 3, 1, 120);
pixSetPixel(pixt, 4, 1, 80);
pixSetPixel(pixt, 0, 0, 20);
pixSetPixel(pixt, 1, 2, 50);
pixSetPixel(pixt, 2, 2, 80);
pixSetPixel(pixt, 3, 2, 50);
pixSetPixel(pixt, 4, 2, 20);
kel3 = kernelCreateFromPix(pixt, 1, 2);
pixd = kernelDisplayInPix(kel3, 41, 2);
pixSaveTiled(pixd, pixa, 1, 0, 20, 0);
pixWrite("/tmp/ker2.png", pixd, IFF_PNG);
regTestCheckFile(rp, "/tmp/ker2.png"); /* 5 */
pixDestroy(&pixd);
pixDestroy(&pixt);
kernelDestroy(&kel3);
/* Test convolution with kel1 */
pixs = pixRead("test24.jpg");
pixg = pixScaleRGBToGrayFast(pixs, 3, COLOR_GREEN);
pixSaveTiled(pixg, pixa, 1, 1, 20, 0);
kel1 = kernelCreateFromString(5, 5, 2, 2, kdatastr);
pixd = pixConvolve(pixg, kel1, 8, 1);
pixSaveTiled(pixd, pixa, 1, 0, 20, 0);
pixWrite("/tmp/ker3.png", pixd, IFF_PNG);
regTestCheckFile(rp, "/tmp/ker3.png"); /* 6 */
pixDestroy(&pixs);
pixDestroy(&pixg);
pixDestroy(&pixd);
kernelDestroy(&kel1);
//.........这里部分代码省略.........
示例13: pixHtmlViewer
//.........这里部分代码省略.........
linknameshort = stringJoin(rootname, "-links.html");
if ((sathumbs = sarrayCreate(0)) == NULL)
return ERROR_INT("sathumbs not made", procName, 1);
if ((saviews = sarrayCreate(0)) == NULL)
return ERROR_INT("saviews not made", procName, 1);
/* Generate the thumbs and views */
nfiles = sarrayGetCount(safiles);
index = 0;
for (i = 0; i < nfiles; i++) {
fname = sarrayGetString(safiles, i, L_NOCOPY);
fullname = genPathname(dirin, fname);
fprintf(stderr, "name: %s\n", fullname);
if ((pix = pixRead(fullname)) == NULL) {
fprintf(stderr, "file %s not a readable image\n", fullname);
FREE(fullname);
continue;
}
FREE(fullname);
if (copyorig) {
outname = genPathname(dirout, fname);
pixWrite(outname, pix, IFF_JFIF_JPEG);
FREE(outname);
}
/* Make and store the thumb */
w = pixGetWidth(pix);
factor = (l_float32)thumbwidth / (l_float32)w;
if ((pixthumb = pixScale(pix, factor, factor)) == NULL)
return ERROR_INT("pixthumb not made", procName, 1);
sprintf(charbuf, "%s_thumb_%03d.jpg", rootname, index);
sarrayAddString(sathumbs, charbuf, L_COPY);
outname = genPathname(dirout, charbuf);
pixWrite(outname, pixthumb, IFF_JFIF_JPEG);
FREE(outname);
pixDestroy(&pixthumb);
/* Make and store the view */
factor = (l_float32)viewwidth / (l_float32)w;
if (factor >= 1.0) {
pixview = pixClone(pix); /* no upscaling */
} else {
if ((pixview = pixScale(pix, factor, factor)) == NULL)
return ERROR_INT("pixview not made", procName, 1);
}
sprintf(charbuf, "%s_view_%03d.jpg", rootname, index);
sarrayAddString(saviews, charbuf, L_COPY);
outname = genPathname(dirout, charbuf);
pixWrite(outname, pixview, IFF_JFIF_JPEG);
FREE(outname);
pixDestroy(&pixview);
pixDestroy(&pix);
index++;
}
/* Generate the main html file */
if ((sahtml = sarrayCreate(0)) == NULL)
return ERROR_INT("sahtml not made", procName, 1);
sarrayAddString(sahtml, htmlstring, L_COPY);
sprintf(charbuf, "<frameset cols=\"%d, *\">", thumbwidth + 30);
sarrayAddString(sahtml, charbuf, L_COPY);
sprintf(charbuf, "<frame name=\"thumbs\" src=\"%s\">", linknameshort);
sarrayAddString(sahtml, charbuf, L_COPY);
sprintf(charbuf, "<frame name=\"views\" src=\"%s\">",
sarrayGetString(saviews, 0, L_NOCOPY));
sarrayAddString(sahtml, charbuf, L_COPY);
sarrayAddString(sahtml, framestring, L_COPY);
shtml = sarrayToString(sahtml, 1);
l_binaryWrite(mainname, "w", shtml, strlen(shtml));
FREE(shtml);
FREE(mainname);
/* Generate the link html file */
nimages = sarrayGetCount(saviews);
fprintf(stderr, "num. images = %d\n", nimages);
if ((salink = sarrayCreate(0)) == NULL)
return ERROR_INT("salink not made", procName, 1);
for (i = 0; i < nimages; i++) {
viewfile = sarrayGetString(saviews, i, L_NOCOPY);
thumbfile = sarrayGetString(sathumbs, i, L_NOCOPY);
sprintf(charbuf, "<a href=\"%s\" TARGET=views><img src=\"%s\"></a>",
viewfile, thumbfile);
sarrayAddString(salink, charbuf, L_COPY);
}
slink = sarrayToString(salink, 1);
l_binaryWrite(linkname, "w", slink, strlen(slink));
FREE(slink);
FREE(linkname);
FREE(linknameshort);
sarrayDestroy(&safiles);
sarrayDestroy(&sathumbs);
sarrayDestroy(&saviews);
sarrayDestroy(&sahtml);
sarrayDestroy(&salink);
return 0;
}
示例14: sarrayConvertWordsToLines
/*!
* sarrayConvertWordsToLines()
*
* Input: sa (sa of individual words)
* linesize (max num of chars in each line)
* Return: saout (sa of formatted lines), or null on error
*
* This is useful for re-typesetting text to a specific maximum
* line length. The individual words in the input sarray
* are concatenated into textlines. An input word string of zero
* length is taken to be a paragraph separator. Each time
* such a string is found, the current line is ended and
* a new line is also produced that contains just the
* string of zero length (""). When the output sarray
* of lines is eventually converted to a string with newlines
* (typically) appended to each line string, the empty
* strings are just converted to newlines, producing the visible
* paragraph separation.
*
* What happens when a word is larger than linesize?
* We write it out as a single line anyway! Words preceding
* or following this long word are placed on lines preceding
* or following the line with the long word. Why this choice?
* Long "words" found in text documents are typically URLs, and
* it's often desirable not to put newlines in the middle of a URL.
* The text display program (e.g., text editor) will typically
* wrap the long "word" to fit in the window.
*/
SARRAY *
sarrayConvertWordsToLines(SARRAY *sa,
l_int32 linesize)
{
char *wd, *strl;
char emptystring[] = "";
l_int32 n, i, len, totlen;
SARRAY *sal, *saout;
PROCNAME("sarrayConvertWordsToLines");
if (!sa)
return (SARRAY *)ERROR_PTR("sa not defined", procName, NULL);
if ((saout = sarrayCreate(0)) == NULL)
return (SARRAY *)ERROR_PTR("saout not defined", procName, NULL);
n = sarrayGetCount(sa);
totlen = 0;
sal = NULL;
for (i = 0; i < n; i++) {
if (!sal) {
if ((sal = sarrayCreate(0)) == NULL)
return (SARRAY *)ERROR_PTR("sal not made", procName, NULL);
}
wd = sarrayGetString(sa, i, L_NOCOPY);
len = strlen(wd);
if (len == 0) { /* end of paragraph: end line & insert blank line */
if (totlen > 0) {
strl = sarrayToString(sal, 2);
sarrayAddString(saout, strl, L_INSERT);
}
sarrayAddString(saout, emptystring, L_COPY);
sarrayDestroy(&sal);
totlen = 0;
}
else if (totlen == 0 && len + 1 > linesize) { /* long word! */
sarrayAddString(saout, wd, L_COPY); /* copy to one line */
}
else if (totlen + len + 1 > linesize) { /* end line & start new one */
strl = sarrayToString(sal, 2);
sarrayAddString(saout, strl, L_INSERT);
sarrayDestroy(&sal);
if ((sal = sarrayCreate(0)) == NULL)
return (SARRAY *)ERROR_PTR("sal not made", procName, NULL);
sarrayAddString(sal, wd, L_COPY);
totlen = len + 1;
}
else { /* add to current line */
sarrayAddString(sal, wd, L_COPY);
totlen += len + 1;
}
}
if (totlen > 0) { /* didn't end with blank line; output last line */
strl = sarrayToString(sal, 2);
sarrayAddString(saout, strl, L_INSERT);
sarrayDestroy(&sal);
}
return saout;
}
示例15: main
int main(int argc,
char **argv)
{
l_int32 ignore;
size_t nbytesin, nbytesout;
char *infile, *instring, *outstring;
SARRAY *sa1, *sa2, *sa3, *sa4, *sa5;
char buf[256];
static char mainName[] = "string_reg";
if (argc != 2)
return ERROR_INT(" Syntax: string_reg infile", mainName, 1);
infile = argv[1];
instring = (char *)l_binaryRead(infile, &nbytesin);
if (!instring)
return ERROR_INT("file not read", mainName, 1);
sa1 = sarrayCreateWordsFromString(instring);
sa2 = sarrayCreateLinesFromString(instring, 0);
sa3 = sarrayCreateLinesFromString(instring, 1);
outstring = sarrayToString(sa1, 0);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk1.txt", "w", outstring, nbytesout);
lept_free(outstring);
outstring = sarrayToString(sa1, 1);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk2.txt", "w", outstring, nbytesout);
lept_free(outstring);
outstring = sarrayToString(sa2, 0);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk3.txt", "w", outstring, nbytesout);
lept_free(outstring);
outstring = sarrayToString(sa2, 1);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk4.txt", "w", outstring, nbytesout);
lept_free(outstring);
outstring = sarrayToString(sa3, 0);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk5.txt", "w", outstring, nbytesout);
lept_free(outstring);
outstring = sarrayToString(sa3, 1);
nbytesout = strlen(outstring);
l_binaryWrite("/tmp/junk6.txt", "w", outstring, nbytesout);
lept_free(outstring);
sprintf(buf, "diff -s /tmp/junk6.txt %s", infile);
ignore = system(buf);
/* write/read/write; compare /tmp/junkout5 with /tmp/junkout6 */
sarrayWrite("/tmp/junk7.txt", sa2);
sarrayWrite("/tmp/junk8.txt", sa3);
sa4 = sarrayRead("/tmp/junk8.txt");
sarrayWrite("/tmp/junk9.txt", sa4);
sa5 = sarrayRead("/tmp/junk9.txt");
ignore = system("diff -s /tmp/junk8.txt /tmp/junk9.txt");
sarrayDestroy(&sa1);
sarrayDestroy(&sa2);
sarrayDestroy(&sa3);
sarrayDestroy(&sa4);
sarrayDestroy(&sa5);
lept_free(instring);
return 0;
}