Skip to content

Commit

Permalink
[ICU-4450] Use apputil library for commonly used demo functions.
Browse files Browse the repository at this point in the history
X-SVN-Rev: 17698
  • Loading branch information
grhoten committed May 26, 2005
1 parent 5ccce7e commit d700e14
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 119 deletions.
1 change: 1 addition & 0 deletions convexp/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CLEANFILES = *~
TARGET = convexp

CPPFLAGS += -I$(ICU_SOURCE)/common -I$(top_srcdir)/apputil
ICULIBS += -L../apputil -lapputil

OBJECTS = printcp.o params.o convexp.o

Expand Down
53 changes: 14 additions & 39 deletions convexp/convexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

#include "printcp.h"
#include "params.h"

#include "demo_settings.h"
#include "demoutil.h"

/*
IANA states that an alias may be up to 40 characters.
Expand Down Expand Up @@ -715,37 +717,6 @@ static void printAliasTable() {
printf(endTable);
}

/**
* @returns 1 if open failed
*/
static int printTemplateFile(char *templateFileName) {
size_t size = 0;
size_t savedPos;
char *buffer;
FILE *templateFile = fopen(templateFileName, "rb");

if (templateFile == NULL) {
printf("<!-- ERROR: %s cannot be opened -->\n", templateFileName);
return 1;
}

/* Go to the end, find the size, and go back to the beginning. */
savedPos = ftell(templateFile);
fseek(templateFile, 0, SEEK_END);
size = ftell(templateFile);
fseek(templateFile, savedPos, SEEK_SET);

/* Read in the whole file and print it out */
buffer = (char *)malloc(size+1);
fread(buffer, size, 1, templateFile);
buffer[size] = 0; // NULL terminate for printing.
printf("%s", buffer);

free(buffer);
fclose(templateFile);
return 0;
}

U_CDECL_BEGIN
static int32_t U_CALLCONV
convexp_hashPointer(const UHashTok key) {
Expand All @@ -767,18 +738,22 @@ main(int argc, const char *argv[]) {
UErrorCode errorCode = U_ZERO_ERROR;
const char *cgi;

gScriptName=getenv("SCRIPT_NAME");
gScriptName=getenv("SCRIPT_NAME");
if (gScriptName == NULL) {
gScriptName = "convexp";
}

puts(htmlHeader);
if (printTemplateFile(DEMO_COMMON_DIR "convexp-header.html")) {
if (!printHTMLFragment(NULL, NULL, DEMO_COMMON_DIR "convexp-header.html")) {
puts(defaultHeader);
}
puts(endHeaderBeginBody);
printTemplateFile(DEMO_COMMON_MASTHEAD);
puts(DEMO_BEGIN_LEFT_NAV);
printTemplateFile(DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
if (printHTMLFragment(NULL, NULL, DEMO_COMMON_MASTHEAD)) {
puts(DEMO_BEGIN_LEFT_NAV);
printHTMLFragment(NULL, NULL, DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
}
puts(breadCrumbMainHeader);

gStandardsSelected = uhash_open(convexp_hashPointer, convexp_comparePointer, &errorCode);
Expand Down Expand Up @@ -845,7 +820,7 @@ main(int argc, const char *argv[]) {
printf(versions, icuVString);

puts(DEMO_END_CONTENT);
printTemplateFile(DEMO_COMMON_FOOTER);
printHTMLFragment(NULL, NULL, DEMO_COMMON_FOOTER);
puts(htmlFooter);

uhash_close(gStandardsSelected);
Expand Down
4 changes: 1 addition & 3 deletions idnbrowser/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ CLEANFILES = *~
## Target information
TARGET = idnbrowser

#LDFLAGS += -L../locexp/util -liculxutil $(LDFLAGS_USTDIO)
#LDFLAGS += $(LDFLAGS_TOOLUTIL)
CPPFLAGS += -I$(ICU_SOURCE)/common
CPPFLAGS += -I$(top_srcdir)/apputil

# ICULIBS includes all standard ICU libraries.
# if we wanted only part of the ICU, we could use (for example) just '$(LIBS) -licuuc -lusort' ...
# -ldl is needed for DLL version
#ICULIBS += -lustdio
ICULIBS += -L../apputil -lapputil

# Want to make sure the usort.h dependency is not on the installed version ..
CPPFLAGS += -I../locexp/util
Expand Down
48 changes: 10 additions & 38 deletions idnbrowser/idnbrwsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "unicode/uscript.h"
#include "unicode/uniset.h"
#include "idnbrwsr.h"

#include "demo_settings.h"
#include "demoutil.h"

//#ifdef WIN32
//# define _WIN32_WINNT 0x0400
Expand Down Expand Up @@ -619,37 +621,6 @@ parseString(const char *s, int32_t srcLen,
return length;
}

/**
* @returns 1 if open failed
*/
static int printTemplateFile(char *templateFileName) {
size_t size = 0;
size_t savedPos;
char *buffer;
FILE *templateFile = fopen(templateFileName, "rb");

if (templateFile == NULL) {
printf("<!-- ERROR: %s cannot be opened -->\n", templateFileName);
return 1;
}

/* Go to the end, find the size, and go back to the beginning. */
savedPos = ftell(templateFile);
fseek(templateFile, 0, SEEK_END);
size = ftell(templateFile);
fseek(templateFile, savedPos, SEEK_SET);

/* Read in the whole file and print it out */
buffer = (char *)malloc(size+1);
fread(buffer, size, 1, templateFile);
buffer[size] = 0; // NULL terminate for printing.
printf("%s", buffer);

free(buffer);
fclose(templateFile);
return 0;
}

enum QueryOptionsEnum {
INPUT,
INPUT_TYPE,
Expand All @@ -676,15 +647,16 @@ main(int argc, const char *argv[]) {

script=getenv("SCRIPT_NAME");
puts(htmlHeader);
if (printTemplateFile(DEMO_COMMON_DIR "idna-header.html")) {
if (!printHTMLFragment(NULL, NULL, DEMO_COMMON_DIR "idna-header.html")) {
puts(defaultHeader);
}
puts(endHeaderBeginBody);
printTemplateFile(DEMO_COMMON_MASTHEAD);
puts(DEMO_BEGIN_LEFT_NAV);
printTemplateFile(DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
if (printHTMLFragment(NULL, NULL, DEMO_COMMON_MASTHEAD)) {
puts(DEMO_BEGIN_LEFT_NAV);
printHTMLFragment(NULL, NULL, DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
}
puts(breadCrumbMainHeader);

inputLength=0;
Expand Down Expand Up @@ -827,7 +799,7 @@ main(int argc, const char *argv[]) {
printf(versions, "3.2", ivString);

puts(DEMO_END_CONTENT);
printTemplateFile(DEMO_COMMON_FOOTER);
printHTMLFragment(NULL, NULL, DEMO_COMMON_FOOTER);
puts(htmlFooter);

us.releaseBuffer();
Expand Down
2 changes: 1 addition & 1 deletion nbrowser/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CPPFLAGS += -I$(top_srcdir)/apputil
# ICULIBS includes all standard ICU libraries.
# if we wanted only part of the ICU, we could use (for example) just '$(LIBS) -licuuc -lusort' ...
# -ldl is needed for DLL version
#ICULIBS += -lustdio
ICULIBS += -L../apputil -lapputil

# Want to make sure the usort.h dependency is not on the installed version ..
CPPFLAGS += -I../locexp/util
Expand Down
48 changes: 10 additions & 38 deletions nbrowser/nbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include "unicode/unistr.h"
#include "unicode/unorm.h"
#include "unormimp.h" // ### TODO internal file, for normalization prototype

#include "demo_settings.h"
#include "demoutil.h"

#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))

Expand Down Expand Up @@ -286,37 +288,6 @@ parseString(const char *s,
}
}

/**
* @returns 1 if open failed
*/
static int printTemplateFile(char *templateFileName) {
size_t size = 0;
size_t savedPos;
char *buffer;
FILE *templateFile = fopen(templateFileName, "rb");

if (templateFile == NULL) {
printf("<!-- ERROR: %s cannot be opened -->\n", templateFileName);
return 1;
}

/* Go to the end, find the size, and go back to the beginning. */
savedPos = ftell(templateFile);
fseek(templateFile, 0, SEEK_END);
size = ftell(templateFile);
fseek(templateFile, savedPos, SEEK_SET);

/* Read in the whole file and print it out */
buffer = (char *)malloc(size+1);
fread(buffer, size, 1, templateFile);
buffer[size] = 0; // NULL terminate for printing.
printf("%s", buffer);

free(buffer);
fclose(templateFile);
return 0;
}

extern int
main(int argc, const char *argv[]) {
UChar input[100], buffer16[600]; // buffer16 should be 6 times longer than input for \\uhhhh
Expand All @@ -330,15 +301,16 @@ main(int argc, const char *argv[]) {

script=getenv("SCRIPT_NAME"); //"/cgi-bin/nbrowser"
puts(htmlHeader);
if (printTemplateFile(DEMO_COMMON_DIR "normalization-header.html")) {
if (!printHTMLFragment(NULL, NULL, DEMO_COMMON_DIR "normalization-header.html")) {
puts(defaultHeader);
}
puts(endHeaderBeginBody);
printTemplateFile(DEMO_COMMON_MASTHEAD);
puts(DEMO_BEGIN_LEFT_NAV);
printTemplateFile(DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
if (printHTMLFragment(NULL, NULL, DEMO_COMMON_MASTHEAD)) {
puts(DEMO_BEGIN_LEFT_NAV);
printHTMLFragment(NULL, NULL, DEMO_COMMON_LEFTNAV);
puts(DEMO_END_LEFT_NAV);
puts(DEMO_BEGIN_CONTENT);
}
puts(breadCrumbMainHeader);

inputLength=options=0;
Expand Down Expand Up @@ -427,7 +399,7 @@ main(int argc, const char *argv[]) {
printf(versions, uvString, ivString);

puts(DEMO_END_CONTENT);
printTemplateFile(DEMO_COMMON_FOOTER);
printHTMLFragment(NULL, NULL, DEMO_COMMON_FOOTER);
puts(htmlFooter);

return 0;
Expand Down

0 comments on commit d700e14

Please sign in to comment.