Skip to content

Commit eb0419d

Browse files
committed
Merge branch 'master' of github.com:fletcher/c-template
2 parents 2038f6b + fa00bc2 commit eb0419d

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ cmake_minimum_required (VERSION 2.6)
77

88
set (My_Project_Title "Some Project")
99
set (My_Project_Description "A project built using the c-template system.")
10-
set (My_Project_Author "Somebody")
11-
set (My_Project_Revised_Date "2015-06-05")
10+
set (My_Project_Author "Fletcher T. Penney")
11+
set (My_Project_Revised_Date "2016-05-06")
1212
set (My_Project_Version_Major 1)
1313
set (My_Project_Version_Minor 0)
14-
set (My_Project_Version_Patch 1)
14+
set (My_Project_Version_Patch 2)
1515

1616
set (My_Project_Version "${My_Project_Version_Major}.${My_Project_Version_Minor}.${My_Project_Version_Patch}")
1717

18-
set (My_Project_Copyright_Date "2015")
18+
set (My_Project_Copyright_Date "2015-2016")
1919
set (My_Project_Copyright "Copyright © ${My_Project_Copyright_Date} ${My_Project_Author}.")
2020

2121
string(TOUPPER ${My_Project_Title} My_Project_Title_Caps )

src/GLibFacade.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* https://github.com/fletcher/MultiMarkdown-4/
66
*
77
* Created by Daniel Jalkut on 7/26/11.
8-
* Modified by Fletcher T. Penney on 9/15/11.
8+
* Modified by Fletcher T. Penney 9/15/11 - 5/6/16.
99
* Modified by Dan Lowe on 1/3/12.
1010
* Copyright 2011 __MyCompanyName__. All rights reserved.
1111
*/
@@ -137,6 +137,17 @@ void g_string_append_c(GString* baseString, char appendedCharacter)
137137
baseString->str[baseString->currentStringLength] = '\0';
138138
}
139139

140+
void g_string_append_c_array(GString *baseString, char * appendedChars, size_t bytes)
141+
{
142+
size_t newSizeNeeded = baseString->currentStringLength + bytes;
143+
ensureStringBufferCanHold(baseString, newSizeNeeded);
144+
145+
memcpy(baseString->str + baseString->currentStringLength,appendedChars, bytes);
146+
147+
baseString->currentStringLength = newSizeNeeded;
148+
baseString->str[baseString->currentStringLength] = '\0';
149+
}
150+
140151
void g_string_append_printf(GString* baseString, char* format, ...)
141152
{
142153
va_list args;

src/GLibFacade.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*
77
* Created by Daniel Jalkut on 7/26/11.
88
* Copyright 2011 __MyCompanyName__. All rights reserved.
9+
*
10+
* Modified by Fletcher T. Penney
11+
* Changes Copyright 2011-2016
912
*/
1013

1114
#ifndef __MARKDOWN_GLIB_FACADE__
@@ -51,6 +54,7 @@ GString* g_string_new(char *startingString);
5154
char* g_string_free(GString* ripString, bool freeCharacterData);
5255

5356
void g_string_append_c(GString* baseString, char appendedCharacter);
57+
void g_string_append_c_array(GString *baseString, char * appendedChars, size_t bytes);
5458
void g_string_append(GString* baseString, char *appendedString);
5559

5660
void g_string_prepend(GString* baseString, char* prependedString);

src/main.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
main.c -- Template main()
44
5-
Copyright © 2015 Fletcher T. Penney.
5+
Copyright © 2015-2016 Fletcher T. Penney.
66
77
88
This program is free software you can redistribute it and/or modify
@@ -26,24 +26,48 @@
2626

2727
#include "GLibFacade.h"
2828

29-
char * stdin_buffer() {
30-
/* Read from stdin and return a char *
31-
`result` will need to be freed elsewhere */
29+
#define kBUFFERSIZE 4096 // How many bytes to read at a time
30+
31+
GString * stdin_buffer() {
32+
/* Read from stdin and return a GString *
33+
`buffer` will need to be freed elsewhere */
34+
35+
char chunk[kBUFFERSIZE];
36+
size_t bytes;
3237

3338
GString * buffer = g_string_new("");
34-
char curchar;
35-
char * result;
3639

37-
while ((curchar = fgetc(stdin)) != EOF)
38-
g_string_append_c(buffer, curchar);
40+
while ((bytes = fread(chunk, 1, kBUFFERSIZE, stdin)) > 0) {
41+
g_string_append_c_array(buffer, chunk, bytes);
42+
}
3943

4044
fclose(stdin);
4145

42-
result = buffer->str;
46+
return buffer;
47+
}
48+
49+
GString * scan_file(char * fname) {
50+
/* Read from stdin and return a GString *
51+
`buffer` will need to be freed elsewhere */
52+
53+
char chunk[kBUFFERSIZE];
54+
size_t bytes;
55+
56+
FILE * file;
57+
58+
if ((file = fopen(fname, "r")) == NULL ) {
59+
return NULL;
60+
}
61+
62+
GString * buffer = g_string_new("");
63+
64+
while ((bytes = fread(chunk, 1, kBUFFERSIZE, file)) > 0) {
65+
g_string_append_c_array(buffer, chunk, bytes);
66+
}
4367

44-
g_string_free(buffer, false);
68+
fclose(file);
4569

46-
return result;
70+
return buffer;
4771
}
4872

4973
int main( int argc, char** argv ) {

0 commit comments

Comments
 (0)