diff --git a/.gitignore b/.gitignore
index a4ff9d30..ab4c02f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
Makefile.in
version.m4
docs
+build
nbproject
autom4te.cache
/Mist*
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..a38eaab7
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,274 @@
+cmake_minimum_required (VERSION 2.6)
+project (MistServer)
+
+if(COMMAND cmake_policy)
+ cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+macro(makeAnalyser analyserName format)
+ add_executable( MistAnalyser${analyserName} src/analysers/${format}_analyser.cpp )
+ target_link_libraries( MistAnalyser${analyserName} mist )
+endmacro()
+
+macro(makeInput inputName format)
+ add_executable( MistIn${inputName} src/input/mist_in.cpp src/input/input.cpp src/input/input_${format}.cpp )
+ set_target_properties( MistIn${inputName} PROPERTIES COMPILE_DEFINITIONS INPUTTYPE=\"input_${format}.h\")
+ target_link_libraries( MistIn${inputName} mist )
+endmacro()
+
+macro(makeOutput outputName format)
+#check if 'http' is one of the argyments, if yes, this is an http output
+ if (";${ARGN};" MATCHES ";http;")
+ SET(httpOutput src/output/output_http.cpp)
+ SET(tsBaseClass Output)
+ if (";${ARGN};" MATCHES ";ts;")
+ SET(tsBaseClass HTTPOutput)
+ endif()
+ endif()
+ if (";${ARGN};" MATCHES ";ts;")
+ SET(tsOutput src/output/output_ts_base.cpp)
+ endif()
+ add_executable( MistOut${outputName} src/output/mist_out.cpp src/output/output.cpp ${httpOutput} ${tsOutput} src/output/output_${format}.cpp )
+ set_target_properties( MistOut${outputName} PROPERTIES COMPILE_DEFINITIONS "OUTPUTTYPE=\"output_${format}.h\";TS_BASECLASS=${tsBaseClass}")
+ target_link_libraries( MistOut${outputName} mist )
+endmacro()
+
+set(lspSOURCES lsp/plugins/md5.js lsp/plugins/cattablesort.js lsp/mist.js)
+set(lspSOURCESmin lsp/plugins/jquery.js lsp/plugins/jquery.flot.min.js lsp/plugins/jquery.flot.time.min.js lsp/plugins/jquery.qrcode.min.js)
+set(lspDATA lsp/header.html lsp/main.css lsp/footer.html)
+
+
+SET(SOURCE_DIR ${PROJECT_SOURCE_DIR})
+SET(BINARY_DIR ${PROJECT_BINARY_DIR})
+include_directories(${SOURCE_DIR})
+include_directories(${BINARY_DIR})
+
+enable_testing()
+include(CTest)
+
+find_package(Doxygen)
+find_package(Java)
+
+if(JAVA_FOUND)
+ SET(CLOSURE "java -jar closure-compiler.jar --warning_level QUIET")
+else()
+ SET(CLOSURE cat)
+endif()
+
+if (RELEASE)
+ set (RELEASE_RAW ${RELEASE})
+else()
+#get the bitlength of this system
+ execute_process(COMMAND getconf LONG_BIT OUTPUT_VARIABLE RELEASE_RAW )
+ set(RELEASE_RAW "Generic_${RELEASE_RAW}" )
+endif()
+string(STRIP ${RELEASE_RAW} RELEASE)
+set(RELEASE \"${RELEASE}\" )
+
+#See if we have a git repo to get the version from
+execute_process(COMMAND git describe --tags OUTPUT_VARIABLE PACKAGE_VERSION_RAW ERROR_QUIET)
+if (NOT PACKAGE_VERSION_RAW)
+ execute_process(COMMAND cat VERSION OUTPUT_VARIABLE PACKAGE_VERSION_RAW ERROR_QUIET)
+endif()
+if (NOT PACKAGE_VERSION_RAW)
+ set(PACKAGE_VERSION_RAW Unknown)
+endif()
+#strip off the trailing spaces and newline
+string(STRIP "${PACKAGE_VERSION_RAW}" PACKAGE_VERSION)
+set(PACKAGE_VERSION \"${PACKAGE_VERSION}\" )
+
+
+if (NOT DEBUG)
+ set(DEBUG 4)
+endif()
+
+message("Builing release ${RELEASE} for version ${PACKAGE_VERSION} @ debug level ${DEBUG}")
+
+add_definitions(-g -funsigned-char -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DDEBUG=${DEBUG} -DPACKAGE_VERSION=${PACKAGE_VERSION} -DRELEASE=${RELEASE})
+if (NOT DEFINED ${NOSHM} )
+ add_definitions(-DSHM_ENABLED=1)
+endif()
+if (DEFINED ${WITH_THREADNAMES} )
+ add_definitions(-DWITH_THREADNAMES=1)
+endif()
+
+if(DOXYGEN_FOUND)
+ configure_file(${SOURCE_DIR}/Doxyfile.in ${BINARY_DIR}/Doxyfile @ONLY)
+ add_custom_target( docs
+# ALL
+ ${DOXYGEN_EXECUTABLE} ${BINARY_DIR}/Doxyfile
+ COMMAND rm -rf ${BINARY_DIR}/docs
+ COMMAND mv ${SOURCE_DIR}/docs ${BINARY_DIR}
+ WORKING_DIRECTORY ${SOURCE_DIR}
+ COMMENT "Generating API documentation with Doxygen"
+ VERBATIM
+ )
+endif(DOXYGEN_FOUND)
+
+#Compile the lib
+set(libHeaders
+${SOURCE_DIR}/lib/config.h
+${SOURCE_DIR}/lib/flv_tag.h
+${SOURCE_DIR}/lib/mp4.h
+${SOURCE_DIR}/lib/dtsc.h
+${SOURCE_DIR}/lib/ts_packet.h
+${SOURCE_DIR}/lib/checksum.h
+${SOURCE_DIR}/lib/bitstream.h
+${SOURCE_DIR}/lib/bitfields.h
+${SOURCE_DIR}/lib/shared_memory.h
+${SOURCE_DIR}/lib/mp4_adobe.h
+${SOURCE_DIR}/lib/http_parser.h
+${SOURCE_DIR}/lib/converter.h
+${SOURCE_DIR}/lib/procs.h
+${SOURCE_DIR}/lib/defines.h
+${SOURCE_DIR}/lib/base64.h
+${SOURCE_DIR}/lib/ftp.h
+${SOURCE_DIR}/lib/socket.h
+${SOURCE_DIR}/lib/ogg.h
+${SOURCE_DIR}/lib/timing.h
+${SOURCE_DIR}/lib/filesystem.h
+${SOURCE_DIR}/lib/mp4_generic.h
+${SOURCE_DIR}/lib/amf.h
+${SOURCE_DIR}/lib/mp4_ms.h
+${SOURCE_DIR}/lib/rtmpchunks.h
+${SOURCE_DIR}/lib/tinythread.h
+${SOURCE_DIR}/lib/nal.h
+${SOURCE_DIR}/lib/vorbis.h
+${SOURCE_DIR}/lib/auth.h
+${SOURCE_DIR}/lib/stream.h
+${SOURCE_DIR}/lib/theora.h
+${SOURCE_DIR}/lib/json.h
+)
+set(libSources
+${SOURCE_DIR}/lib/tinythread.cpp
+${SOURCE_DIR}/lib/mp4_ms.cpp
+${SOURCE_DIR}/lib/filesystem.cpp
+${SOURCE_DIR}/lib/procs.cpp
+${SOURCE_DIR}/lib/bitfields.cpp
+${SOURCE_DIR}/lib/amf.cpp
+${SOURCE_DIR}/lib/mp4_adobe.cpp
+${SOURCE_DIR}/lib/ftp.cpp
+${SOURCE_DIR}/lib/base64.cpp
+${SOURCE_DIR}/lib/http_parser.cpp
+${SOURCE_DIR}/lib/ts_packet.cpp
+${SOURCE_DIR}/lib/auth.cpp
+${SOURCE_DIR}/lib/rtmpchunks.cpp
+${SOURCE_DIR}/lib/shared_memory.cpp
+${SOURCE_DIR}/lib/dtsc.cpp
+${SOURCE_DIR}/lib/converter.cpp
+${SOURCE_DIR}/lib/config.cpp
+${SOURCE_DIR}/lib/vorbis.cpp
+${SOURCE_DIR}/lib/nal.cpp
+${SOURCE_DIR}/lib/bitstream.cpp
+${SOURCE_DIR}/lib/socket.cpp
+${SOURCE_DIR}/lib/flv_tag.cpp
+${SOURCE_DIR}/lib/ogg.cpp
+${SOURCE_DIR}/lib/mp4_generic.cpp
+${SOURCE_DIR}/lib/mp4.cpp
+${SOURCE_DIR}/lib/theora.cpp
+${SOURCE_DIR}/lib/timing.cpp
+${SOURCE_DIR}/lib/dtscmeta.cpp
+${SOURCE_DIR}/lib/stream.cpp
+${SOURCE_DIR}/lib/json.cpp
+ )
+add_library ( mist ${libHeaders} ${libSources} )
+target_link_libraries( mist -lpthread -lrt)
+
+add_custom_command(TARGET mist
+ POST_BUILD
+ COMMAND mkdir -p ${BINARY_DIR}/mist
+ COMMAND cp ${libHeaders} ${BINARY_DIR}/mist
+ DEPENDS ${libHeaders}
+)
+
+makeAnalyser(RTMP rtmp)
+makeAnalyser(FLV flv)
+makeAnalyser(DTSC dtsc)
+makeAnalyser(AMF amf)
+makeAnalyser(MP4 mp4)
+makeAnalyser(OGG ogg)
+add_executable( MistInfo src/analysers/info.cpp )
+target_link_libraries( MistInfo mist )
+
+makeInput(DTSC dtsc)
+makeInput(MP3 mp3)
+makeInput(FLV flv)
+makeInput(OGG ogg)
+makeInput(Buffer buffer)
+
+makeOutput(RTMP rtmp)
+makeOutput(OGG progressive_ogg http)
+makeOutput(FLV progressive_flv http)
+makeOutput(MP4 progressive_mp4 http)
+makeOutput(MP3 progressive_mp3 http)
+makeOutput(HSS hss http)
+makeOutput(HDS hds http)
+makeOutput(SRT srt http)
+makeOutput(JSON json http)
+makeOutput(TS ts ts)
+makeOutput(HTTPTS httpts http ts)
+makeOutput(HLS hls http ts)
+
+add_executable( sourcery src/sourcery.cpp )
+
+add_custom_target( embedcode
+ ./sourcery ${CMAKE_CURRENT_SOURCE_DIR}/src/embed.js embed_js ${CMAKE_CURRENT_BINARY_DIR}/embed.js.h
+ DEPENDS sourcery ${CMAKE_CURRENT_SOURCE_DIR}/src/embed.js
+ VERBATIM
+)
+
+add_custom_target( lsp
+ ${SOURCE_DIR}/lsp/generateLSP.sh ${BINARY_DIR}/server.html "${CLOSURE}"
+ DEPENDS ${SOURCE_DIR}/lsp/generateLSP.sh ${lspSOURCES} ${lspSOURCESmin} ${lspDATA}
+ WORKING_DIRECTORY ${SOURCE_DIR}/lsp
+ VERBATIM
+)
+add_custom_target( localSettingsPage
+ ./sourcery ${BINARY_DIR}/server.html server_html ${CMAKE_CURRENT_BINARY_DIR}/server.html.h
+ DEPENDS sourcery lsp
+ VERBATIM
+)
+
+add_executable( MistOutHTTP src/output/mist_out.cpp src/output/output.cpp src/output/output_http.cpp src/output/output_http_internal.cpp)
+set_target_properties( MistOutHTTP PROPERTIES COMPILE_DEFINITIONS "OUTPUTTYPE=\"output_http_internal.h\"")
+add_dependencies(MistOutHTTP embedcode)
+target_link_libraries( MistOutHTTP mist )
+
+set(controllerHeaders
+ ${SOURCE_DIR}/src/controller/controller_api.h
+ ${SOURCE_DIR}/src/controller/controller_statistics.h
+ ${SOURCE_DIR}/src/controller/controller_connectors.h
+ ${SOURCE_DIR}/src/controller/controller_storage.h
+ ${SOURCE_DIR}/src/controller/controller_capabilities.h
+ ${SOURCE_DIR}/src/controller/controller_streams.h
+)
+set(controllerSources
+ ${SOURCE_DIR}/src/controller/controller.cpp
+ ${SOURCE_DIR}/src/controller/controller_streams.cpp
+ ${SOURCE_DIR}/src/controller/controller_storage.cpp
+ ${SOURCE_DIR}/src/controller/controller_connectors.cpp
+ ${SOURCE_DIR}/src/controller/controller_statistics.cpp
+ ${SOURCE_DIR}/src/controller/controller_capabilities.cpp
+ ${SOURCE_DIR}/src/controller/controller_api.cpp
+)
+
+add_executable( MistController ${controllerHeaders} ${controllerSources} )
+set_target_properties( MistController PROPERTIES COMPILE_DEFINITIONS RELEASE=${RELEASE})
+target_link_libraries( MistController mist )
+add_dependencies(MistController localSettingsPage)
+
+#make clean stuff
+add_custom_target(clean-all
+ COMMAND ${CMAKE_BUILD_TOOL} clean
+ COMMAND rm -rf ${BINARY_DIR}/CMakeCache.txt
+ COMMAND rm -rf ${BINARY_DIR}/cmake_install.cmake
+ COMMAND rm -rf ${BINARY_DIR}/Makefile
+ COMMAND rm -rf ${BINARY_DIR}/CMakeFiles
+ COMMAND rm -rf ${BINARY_DIR}/Testing
+ COMMAND rm -rf ${BINARY_DIR}/CTestTestfile.cmake
+ COMMAND rm -rf ${BINARY_DIR}/DartConfiguration.tcl
+ COMMAND rm -rf ${BINARY_DIR}/server.html
+ COMMAND rm -rf ${BINARY_DIR}/server.html.h
+ COMMAND rm -rf ${BINARY_DIR}/embed.js.h
+ COMMAND rm -rf ${BINARY_DIR}/mist
+)
diff --git a/Doxyfile b/Doxyfile.in
similarity index 99%
rename from Doxyfile
rename to Doxyfile.in
index 798db3d6..2c30f767 100644
--- a/Doxyfile
+++ b/Doxyfile.in
@@ -38,7 +38,7 @@ PROJECT_NAME = MistServer
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = 1
+PROJECT_NUMBER = "@PACKAGE_VERSION@ (@RELEASE@)"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 00000000..4b84051d
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1,69 @@
+add_library ( mist SHARED
+ amf.cpp
+ amf.h
+ auth.cpp
+ auth.h
+ base64.cpp
+ base64.h
+ bitfields.cpp
+ bitfields.h
+ bitstream.cpp
+ bitstream.h
+ checksum.h
+ CMakeLists.txt
+ config.cpp
+ config.h
+ converter.cpp
+ converter.h
+ defines.h
+ dtsc.cpp
+ dtsc.h
+ dtscmeta.cpp
+ filesystem.cpp
+ filesystem.h
+ flv_tag.cpp
+ flv_tag.h
+ ftp.cpp
+ ftp.h
+ http_parser.cpp
+ http_parser.h
+ json.cpp
+ json.h
+ mp4_adobe.cpp
+ mp4_adobe.h
+ mp4.cpp
+ mp4_generic.cpp
+ mp4_generic.h
+ mp4.h
+ mp4_ms.cpp
+ mp4_ms.h
+ nal.cpp
+ nal.h
+ ogg.cpp
+ ogg.h
+ procs.cpp
+ procs.h
+ rtmpchunks.cpp
+ rtmpchunks.h
+ shared_memory.cpp
+ shared_memory.h
+ socket.cpp
+ socket.h
+ stream.cpp
+ stream.h
+ theora.cpp
+ theora.h
+ timing.cpp
+ timing.h
+ tinythread.cpp
+ tinythread.h
+ ts_packet.cpp
+ ts_packet.h
+ vorbis.cpp
+ vorbis.h
+)
+
+target_link_libraries( mist
+ -lpthread
+ -lrt
+)
diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp
index f20d97f0..6990fb25 100644
--- a/lib/shared_memory.cpp
+++ b/lib/shared_memory.cpp
@@ -337,7 +337,9 @@ namespace IPC {
}
}
if (handle == -1) {
- FAIL_MSG("shm_open for page %s failed: %s", name.c_str(), strerror(errno));
+ if (!master_ && autoBackoff){
+ FAIL_MSG("shm_open for page %s failed: %s", name.c_str(), strerror(errno));
+ }
return;
}
if (master) {
diff --git a/lsp/CMakeLists.txt b/lsp/CMakeLists.txt
new file mode 100644
index 00000000..8a1e8161
--- /dev/null
+++ b/lsp/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(lspSOURCES plugins/md5.js plugins/cattablesort.js mist.js)
+set(lspSOURCESmin plugins/jquery.js plugins/jquery.flot.min.js plugins/jquery.flot.time.min.js plugins/jquery.qrcode.min.js)
+set(lspDATA header.html main.css footer.html)
+
+add_custom_target( lsp
+ ALL
+ ${CMAKE_CURRENT_SOURCE_DIR}/generateLSP.sh ${CMAKE_CURRENT_BINARY_DIR}/server.html
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/generateLSP.sh ${lspSOURCES} ${lspSOURCESmin} ${lspDATA}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ VERBATIM
+)
diff --git a/lsp/generateLSP.sh b/lsp/generateLSP.sh
new file mode 100755
index 00000000..38414a76
--- /dev/null
+++ b/lsp/generateLSP.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+cat header.html > $1
+echo "" >> $1
+cat footer.html >> $1
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 00000000..99e57029
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,101 @@
+macro(makeAnalyser analyserName format)
+ add_executable( MistAnalyser${analyserName} analysers/${format}_analyser.cpp )
+ target_link_libraries( MistAnalyser${analyserName} mist )
+endmacro()
+
+macro(makeInput inputName format)
+ add_executable( MistIn${inputName} input/mist_in.cpp input/input.cpp input/input_${format}.cpp )
+ set_target_properties( MistIn${inputName} PROPERTIES COMPILE_DEFINITIONS INPUTTYPE=\"input_${format}.h\")
+ target_link_libraries( MistIn${inputName} mist )
+endmacro()
+
+macro(makeOutput outputName format)
+#check if 'http' is one of the argyments, if yes, this is an http output
+ if (";${ARGN};" MATCHES ";http;")
+ SET(httpOutput output/output_http.cpp)
+ if (";${ARGN};" MATCHES ";ts;")
+ SET(tsBaseClass HTTPOutput)
+ else()
+ SET(tsBaseClass Output)
+ endif()
+ endif()
+ if (";${ARGN};" MATCHES ";ts;")
+ SET(tsOutput output/output_ts_base.cpp)
+ endif()
+ add_executable( MistOut${outputName} output/mist_out.cpp output/output.cpp ${httpOutput} ${tsOutput} output/output_${format}.cpp )
+ set_target_properties( MistOut${outputName} PROPERTIES COMPILE_DEFINITIONS "OUTPUTTYPE=\"output_${format}.h\";TS_BASECLASS=${tsBaseClass}")
+ target_link_libraries( MistOut${outputName} mist )
+endmacro()
+
+makeAnalyser(RTMP rtmp)
+makeAnalyser(FLV flv)
+makeAnalyser(DTSC dtsc)
+makeAnalyser(AMF amf)
+makeAnalyser(MP4 mp4)
+makeAnalyser(OGG ogg)
+
+makeInput(DTSC dtsc)
+makeInput(MP3 mp3)
+makeInput(FLV flv)
+makeInput(OGG ogg)
+makeInput(Buffer buffer)
+
+makeOutput(RTMP rtmp)
+makeOutput(OGG progressive_ogg http)
+makeOutput(FLV progressive_flv http)
+makeOutput(MP4 progressive_mp4 http)
+makeOutput(MP3 progressive_mp3 http)
+makeOutput(HSS hss http)
+makeOutput(HDS hds http)
+makeOutput(SRT srt http)
+makeOutput(JSON json http)
+makeOutput(TS ts ts)
+makeOutput(HTTPTS httpts http ts)
+makeOutput(HLS hls http ts)
+
+#get the bitlength of this system
+execute_process(COMMAND getconf LONG_BIT OUTPUT_VARIABLE RELEASE_RAW )
+#strip off the trailing spaces and newline
+string(STRIP ${RELEASE_RAW} RELEASE)
+set(RELEASE \"${RELEASE}\" )
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+add_executable( sourcery sourcery.cpp )
+
+add_custom_target( embedcode
+ ALL
+ ./sourcery ${CMAKE_CURRENT_SOURCE_DIR}/embed.js embed_js ${CMAKE_CURRENT_BINARY_DIR}/embed.js.h
+ DEPENDS sourcery ${CMAKE_CURRENT_SOURCE_DIR}/embed.js
+ VERBATIM
+)
+
+add_custom_target( localSettingsPage
+ ALL
+ ./sourcery ${BINARY_DIR}/lsp/server.html server_html ${CMAKE_CURRENT_BINARY_DIR}/server.html.h
+ DEPENDS sourcery lsp
+ VERBATIM
+)
+
+add_executable( MistOutHTTP output/mist_out.cpp output/output.cpp output/output_http.cpp output/output_http_internal.cpp)
+set_target_properties( MistOutHTTP PROPERTIES COMPILE_DEFINITIONS "OUTPUTTYPE=\"output_http_internal.h\"")
+add_dependencies(MistOutHTTP embedcode)
+target_link_libraries( MistOutHTTP mist )
+
+add_executable( MistController
+ controller/controller.cpp
+ controller/controller_api.h
+ controller/controller_api.cpp
+ controller/controller_capabilities.h
+ controller/controller_capabilities.cpp
+ controller/controller_connectors.h
+ controller/controller_connectors.cpp
+ controller/controller_statistics.h
+ controller/controller_statistics.cpp
+ controller/controller_storage.h
+ controller/controller_storage.cpp
+ controller/controller_streams.h
+ controller/controller_streams.cpp
+)
+set_target_properties( MistController PROPERTIES COMPILE_DEFINITIONS RELEASE=${RELEASE})
+target_link_libraries( MistController mist )
+add_dependencies(MistController localSettingsPage)
diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp
index 2eab50b5..f3932dd8 100644
--- a/src/output/output_http_internal.cpp
+++ b/src/output/output_http_internal.cpp
@@ -365,7 +365,7 @@ namespace Mist {
response = json_resp.toString();
}
if (rURL.substr(0, 7) == "/embed_" && !json_resp.isMember("error")){
- #include "../embed.js.h"
+ #include "embed.js.h"
response.append("\n(");
if (embed_js[embed_js_len - 2] == ';'){//check if we have a trailing ;\n or just \n
response.append((char*)embed_js, (size_t)embed_js_len - 2); //remove trailing ";\n" from xxd conversion
diff --git a/src/sourcery.cpp b/src/sourcery.cpp
index e3db80ef..f7f82afe 100644
--- a/src/sourcery.cpp
+++ b/src/sourcery.cpp
@@ -5,10 +5,11 @@
#include
int main(int argc, char* argv[]){
- if (argc < 3) {
- std::cerr << "Usage: " << argv[0] << " " << std::endl;
+ if (argc < 4) {
+ std::cerr << "Usage: " << argv[0] << " " << std::endl;
}
- std::cout << "const char *" << argv[2] << " = " << std::endl << " \"";
+ std::ofstream tmp(argv[3]);
+ tmp << "const char *" << argv[2] << " = " << std::endl << " \"";
int i = 0;
int total = 0;
std::ifstream inFile(argv[1]);
@@ -17,27 +18,28 @@ int main(int argc, char* argv[]){
if (!inFile.good()){break;}
switch (thisChar){
//Filter special characters.
- case '\n': std::cout << "\\n"; i += 2; total--; break;
- case '\r': std::cout << "\\r"; i += 2; total--; break;
- case '\t': std::cout << "\\t"; i += 2; total--; break;
- case '\\': std::cout << "\\\\"; i += 2; total --; break;
- case '\"': std::cout << "\\\""; i += 2; total --; break;
+ case '\n': tmp << "\\n"; i += 2; total--; break;
+ case '\r': tmp << "\\r"; i += 2; total--; break;
+ case '\t': tmp << "\\t"; i += 2; total--; break;
+ case '\\': tmp << "\\\\"; i += 2; total --; break;
+ case '\"': tmp << "\\\""; i += 2; total --; break;
default:
if (thisChar < 32 || thisChar > 126){
//Convert to octal.
- std::cout << '\\' << std::oct << std::setw(3) << std::setfill('0') << (unsigned int)thisChar << std::dec;
+ tmp << '\\' << std::oct << std::setw(3) << std::setfill('0') << (unsigned int)thisChar << std::dec;
i += 4;
}else{
- std::cout << thisChar;
+ tmp << thisChar;
i ++;
}
}
if (i >= 80){
- std::cout << "\" \\" << std::endl << " \"";
+ tmp << "\" \\" << std::endl << " \"";
total += i;
i = 0;
}
}
- std::cout << "\";" << std::endl << "unsigned int " << argv[2] << "_len = " << i + total << ";" << std::endl;
+ tmp << "\";" << std::endl << "unsigned int " << argv[2] << "_len = " << i + total << ";" << std::endl;
+ tmp.close();
return 0;
}