Beispiel #1
0
 void NVPList::load(TAO_Notify_Property_Time& p) const
 {
   const char * v;
   if (find(p.name (), v))
   {
     p.assign (static_cast<TimeBase::TimeT> (string_to_uint64(v)));
   }
 }
/*!

\brief Converts Config to dmz::UInt64.
\details Defined in dmzRuntimeConfigToTypesBase.h.
This function uses dmz::config_to_sring to retrieve the value and then uses
dmz::string_to_uint64 to convert the returned String to a dmz::UInt64.
\param[in] Name String containing name of the attribute in the config context to convert.
\param[in] Source Config containing config context to convert.
\param[in] DefaultValue dmz::UInt64 containing default value that is returned if
the config context is not found.
\return Returns dmz::UInt64 containing value.
\sa dmz::config_to_string(const String &Name, const Config &Source, const String &DefaultValue)

*/
dmz::UInt64
dmz::config_to_uint64 (
      const String &Name,
      const Config &Source,
      const UInt64 DefaultValue) {

   UInt64 result (DefaultValue);
   String str;

   if (local_config_to_string (Name, Source, str)) { result = string_to_uint64 (str); }

   return result;
}
Beispiel #3
0
uint64_t
stream_read_uint64(stream_t* stream) {
	uint64_t value = 0;
	if (stream_is_binary(stream)) {
		stream_read(stream, &value, 8);
		if (stream->swap)
			value = byteorder_swap64(value);
	}
	else {
		char buffer[22] = {0};
		string_t str = stream_read_string_buffer(stream, buffer, 22);
		value = string_to_uint64(str.str, str.length, false);
	}
	return value;
}
Beispiel #4
0
uint64_t stream_read_uint64( stream_t* stream )
{
	uint64_t value = 0;
	if( stream_is_binary( stream ) )
	{
		stream_read( stream, &value, 8 );
		if( stream && stream->swap )
			value = byteorder_swap64( value );
	}
	else
	{
		char* str = stream_read_string( stream );
		value = string_to_uint64( str, false );
		string_deallocate( str );
	}
	return value;
}
Beispiel #5
0
int
hashify_read_hashes(stream_t* file, hashify_string_t** hashes) {
	//Read in hashes in file
	char line_buffer[HASHIFY_LINEBUFFER_LENGTH];
	string_const_t tokens[32];

	memset(line_buffer, 0, sizeof(line_buffer));
	do {
		string_t line = stream_read_line_buffer(file, line_buffer, sizeof(line_buffer), '\n');
		string_const_t stripped_line = string_strip(STRING_ARGS(line), STRING_CONST("\n\r"));
		if ((string_find_string(STRING_ARGS(stripped_line), STRING_CONST("define"), 0) != STRING_NPOS) &&
		        (string_find_string(STRING_ARGS(stripped_line), STRING_CONST("static_hash"), 0) != STRING_NPOS)) {
			//Format is: #define HASH_<hashstring> static_hash_string( "<string>", 0x<hashvalue>ULL )
			size_t num_tokens = string_explode(STRING_ARGS(stripped_line), STRING_CONST(" \t"), tokens, 32,
			                                   false);

			if (num_tokens >= 6) {
				hashify_string_t hash_string;
				string_const_t stripped = string_strip(STRING_ARGS(tokens[3]), STRING_CONST(","));
				stripped = string_strip(STRING_ARGS(stripped), STRING_CONST("\""));
				hash_string.string = string_copy(hash_string.buffer, HASHIFY_STRING_LENGTH, STRING_ARGS(stripped));
				hash_string.hash = string_to_uint64(STRING_ARGS(tokens[4]), true);

				if (hash(STRING_ARGS(hash_string.string)) != hash_string.hash) {
					log_errorf(0, ERROR_INVALID_VALUE,
					           STRING_CONST("  hash output file is out of date, %.*s is set to 0x%" PRIx64 " but should be 0x%"
					                        PRIx64),
					           STRING_FORMAT(hash_string.string), hash_string.hash, hash(STRING_ARGS(hash_string.string)));
					return HASHIFY_RESULT_OUTPUT_FILE_OUT_OF_DATE;
				}

				array_push_memcpy(*hashes, &hash_string);
			}
		}
	}
	while (!stream_eos(file));

	return 0;
}
Beispiel #6
0
int hashify_read_hashes( stream_t* file, hashify_string_t** hashes )
{
	//Read in hashes in file
	char* line;
	char line_buffer[HASHIFY_LINEBUFFER_LENGTH];

	do
	{
		stream_read_line_buffer( file, line_buffer, HASHIFY_LINEBUFFER_LENGTH-1, '\n' );
		line = string_strip( line_buffer, "\n\r" );
		if( ( string_find_string( line, "define", 0 ) != STRING_NPOS ) && ( string_find_string( line, "static_hash", 0 ) != STRING_NPOS ) )
		{
			//Format is: #define HASH_<hashstring> static_hash_string( "<string>", 0x<hashvalue>ULL )
			char** tokens = string_explode( line, " \t", false );

			if( array_size( tokens ) >= 6 )
			{
				hashify_string_t hash_string;

				string_copy( hash_string.string, string_strip( string_strip( tokens[3], "," ), "\"" ), HASHIFY_STRING_LENGTH );
				hash_string.hash = string_to_uint64( tokens[4], true );

				if( hash( hash_string.string, string_length( hash_string.string ) ) != hash_string.hash )
				{
					log_errorf( ERROR_INVALID_VALUE, "  hash output file is out of date, %s is set to 0x%llx but should be 0x%llx ", hash_string.string, hash_string.hash, hash( hash_string.string, string_length( hash_string.string ) ) );
					string_array_deallocate( tokens );
					return HASHIFY_RESULT_OUTPUT_FILE_OUT_OF_DATE;
				}

				array_push_memcpy( *hashes, &hash_string );
			}

			string_array_deallocate( tokens );
		}
	} while( !stream_eos( file ) );

	return 0;
}
Beispiel #7
0
int main()
{
    sg_set_output_directory("twiebs.github.io");

		char *post_info_buffer = (char *)malloc(1024*1024*4);
    memset(post_info_buffer, 0, 1024*1024*4);
		char *buffer_write = post_info_buffer;

		struct PostInfo {
			const char *filepath;
			const char *title;
			const char *permalink;
      uint8_t day;
      uint8_t month;
      uint16_t year; 
			uint64_t dateComparator;
		} post_info[1024];
		uint32_t post_index = 0;

		{ //Generate Posts
			char temp[1024];
			foreach_file_in_directory("posts", [&](FileInfo file_info) {
				char *data = read_file_into_memory_and_null_terminate(file_info.filepath);
				cstrcpy_without_filext(temp, file_info.name);

				sg_begin_document();
				sg_set_document_title(temp);
				sg_set_document_description("Torin wiebelts blog");
				sg_add_stylesheet_cstr("style.css");
				sg_set_document_filename(file_info.name);

				twiebs_site_navigation();
				sg_set_next_class("content");
				sg_begin_div();

				post_info[post_index].filepath = cstr_push_to_buffer(
						&buffer_write, file_info.filepath);

				sg_Markdown_Result parse_info;
				sg_parser_begin(data);

				while(sg_parse_markdown(&parse_info)) {
					if (parse_info.type == SG_MARKDOWN_PROCEDURE) {

						sg_MarkdownProcedureCall& call = parse_info.procedure_call;
						if (str_match_literal(call.name, call.name_length, "title")) {
              sg_set_next_class("post-header");
              sg_begin_div();
							post_info[post_index].title = str_push_to_buffer_as_cstr(
									&buffer_write, call.args[0].text, call.args[0].text_length);
							sg_set_document_title(post_info[post_index].title);
							sg_h(1, post_info[post_index].title);
						} else if (str_match_literal(call.name, call.name_length, "date")) {
              PostInfo& p = post_info[post_index];
              p.year = string_to_uint64(call.args[0].text, call.args[0].text_length);
              p.month = string_to_uint64(call.args[1].text, call.args[1].text_length);
              p.day  = string_to_uint64(call.args[2].text, call.args[2].text_length);
              p.dateComparator = (p.year * 366) + (p.month * 32) + (p.day);
							InsertDateTag(call);
              sg_end_div();
						} else if (str_match_literal(call.name, call.name_length, "permalink")) {
							post_info[post_index].permalink = str_push_to_buffer_as_cstr(
									&buffer_write, call.args[0].text, call.args[0].text_length);
							sg_set_document_filename(post_info[post_index].permalink);
						}
					}
				}
        sg_parser_end();
				
				post_index++;
				sg_end_div();
				sg_end_document();
				free(data);
			});
    }

    //dumb bubble sort
    bool are_posts_sorted = false;
    while (!are_posts_sorted) {
      are_posts_sorted = true;
      for (uint32_t i = 0; i < post_index - 1; i++) {
        if (post_info[i].dateComparator < post_info[i+1].dateComparator) {
          PostInfo temp = post_info[i];
          post_info[i] = post_info[i+1];
          post_info[i+1] = temp;
          are_posts_sorted = false;
        }
      }
    }
   
    { //Generate Pages
			char temp[1024];
			foreach_file_in_directory("pages", [&temp](FileInfo file_info){
				char *fileData = read_file_into_memory_and_null_terminate(file_info.filepath);
				cstrcpy_without_filext(temp, file_info.name);

				sg_begin_document();
				sg_set_document_title_fmt(temp);
				sg_set_document_filename_fmt("%s.html", temp);
				sg_set_document_description_fmt("Blog of Torin Wiebelt");
				sg_add_stylesheet_cstr("style.css");

				twiebs_site_navigation();
				sg_parser_begin(fileData);
				sg_Markdown_Result parse_info;
				while (sg_parse_markdown(&parse_info)) {
					if (parse_info.type == SG_MARKDOWN_PROCEDURE) {
						if (str_match_literal(parse_info.procedure_call.name, 
							parse_info.procedure_call.name_length, "begin_content")) {
							sg_set_next_class_fmt("content");
							sg_begin_div();
						} else if (str_match_literal(parse_info.procedure_call.name, 
							parse_info.procedure_call.name_length, "end_content")) {
							sg_end_div();
						}
					}
				}
        sg_parser_end();
				sg_end_document();
				free(fileData);
			});
		}	

    { //@Generate @Archive
      sg_begin_document();
      sg_set_document_title("Archive");
      sg_set_document_filename("archive.html");
      sg_add_stylesheet_cstr("style.css");
      twiebs_site_navigation();

      uint64_t currentIndex = 0;

     
      uint64_t currentYear = post_info[0].year;
      sg_set_next_class("content");
      sg_begin_div();
      sg_h(1, std::to_string(currentYear).c_str());

      for (uint32_t i = 0; i < post_index; i++) {
        const PostInfo& p = post_info[i];
        if (currentYear != p.year) {
          sg_end_div();
          sg_set_next_class("content");
          sg_begin_div();
          sg_h(1, std::to_string(currentYear).c_str());
          currentYear = p.year;
        }

        sg_begin_a("%s.html", p.permalink);
        sg_h(3, "%s %s, %s", MONTH_STRINGS[p.month], std::to_string(p.day).c_str(), p.title);
        sg_end_a();
      }
      sg_end_div();
      sg_end_document();
    }

    { //@Generate @Site @Index
      sg_begin_document();
      sg_set_document_title("Torin Wiebelt's Blog");
      sg_set_document_description("Torin wiebelts awesome blog and portfolio");
      sg_set_document_filename("index.html");
      sg_add_stylesheet_cstr("style.css");
      twiebs_site_navigation();

      for (uint32_t i = 0; i < post_index; i++) {
        char *data = read_file_into_memory_and_null_terminate(post_info[i].filepath);
        sg_set_next_class("content");
        sg_begin_div();
        sg_set_next_class("post-header");
        sg_begin_div();
        sg_begin_a_fmt("%s.html", post_info[i].permalink);
        sg_h(1,post_info[i].title);
        sg_end_a();

        sg_parser_begin(data);
        sg_Markdown_Result parse_result;
        while (sg_parse_markdown(&parse_result)) { 

          if (parse_result.type = SG_MARKDOWN_PROCEDURE) {
            if (str_match_literal(parse_result.procedure_call.name, parse_result.procedure_call.name_length, "date")) {
              InsertDateTag(parse_result.procedure_call);
              sg_end_div();
            }
          }
        }
        sg_parser_end();
        sg_end_div();
        free(data);
      }
      sg_end_document();
    }
 
    //sg_CopyFiles();
    return 0;
}