Small program to format text for copy/pasting into books
Posted: Tue Nov 06, 2012 6:50 pm
NOTE: The link to the program is in my next post (2 or 3 posts down), this one's just background and the question I asked before I'd written it.
//skip down if you don't want to read my rambling background post
Just today, I played with the new writeable books for the first time.
And HOLY SHIT, I am in love. I've wanted this functionality for ages, and I've already gone crazy in my world with the books. I've written books about my tunnel marking procedures for our communal mines, and, for each mining outpost, a small info packet which describes the areas that the mining outpost services, along with directions for returning home and other such tidbits.
This is cool. These books give a world history, and character, and I want to continue to make as many as I can. But what a drag, to type all that text manually, conforming to a 256 character limit for each page. And even copy-pasting is irritating, since you can't do it unless what's on your clipboard fits on one page.
But I'm a CS major, dammit, and I've taken enough programming to be able to build utilities for myself... so why should I work hard when a computer can do it for me? So I'm currently writing a simple program, which will take a text file for input, read in 256 characters at a time, and divide the original text into chunks for easy copy pasting, outputting the modified text to a file.
This program will also include a label above each page, so it'll be easy to know where you are, and also divide any text which is longer than one book into as many books as are necessary with a header indicating each new book. Lastly, the program will display the number of books required, and, based on that number, will calculate the necessary materials for making that many books, and how many chests will be necessary to contain them. Obviously, I doubt that most text that the program handles will require more than a couple of books, but I'm planning on doing Lovecraft's "The Dunwich Horror" as a test, and the first book in what will undoubtedly be an epic library, so it might take quite a few books.
//end of rambling background post.
The majority of the program is quite simple, and I don't need help with the looping or heading writing or anything. But there is one consideration I'd like to ask for some input on. I want to bring in 256 characters at a time of the text file I give the program, but I don't want to cut any words in half (or in any other fraction :p).
So what I need is a method to somehow ensure that the last word being brought in isn't cut off by the limit of 256 characters. If there is a word that will be cut off, I want to just stop at the last whole word, saving the word that would have been cut off for the beginning of the next page.
Currently, my idea is to use a cstring (an array of characters) with a size of 256 as a "holder" for each page. This will get loaded with 256 characters, then get written to the output file. One method I've thought of to check if a word has been cut off is to check the last space in the array to ensure that it's the space character. If not, then I would go backward through the array until I found the previous space (indicating the end of the last full word). Then I guess I'd run a loop to replace those last several characters with spaces.
Actually, having written this, I think this method will work well. Still, anyone with a good idea on how to prevent the aforementioned word cutoff issue should let me know. I know there's some good programmers on this forum, so I figured you guys would have some insight.
Also, when it's finished, which should be tonight after I finish up some homework, I'd be more than happy to post it here for anyone who would like to use such a utility (unless that violates the forum rules somehow, but I don't see why it would.)
Looking forward to any responses/insight!
//skip down if you don't want to read my rambling background post
Just today, I played with the new writeable books for the first time.
And HOLY SHIT, I am in love. I've wanted this functionality for ages, and I've already gone crazy in my world with the books. I've written books about my tunnel marking procedures for our communal mines, and, for each mining outpost, a small info packet which describes the areas that the mining outpost services, along with directions for returning home and other such tidbits.
This is cool. These books give a world history, and character, and I want to continue to make as many as I can. But what a drag, to type all that text manually, conforming to a 256 character limit for each page. And even copy-pasting is irritating, since you can't do it unless what's on your clipboard fits on one page.
But I'm a CS major, dammit, and I've taken enough programming to be able to build utilities for myself... so why should I work hard when a computer can do it for me? So I'm currently writing a simple program, which will take a text file for input, read in 256 characters at a time, and divide the original text into chunks for easy copy pasting, outputting the modified text to a file.
This program will also include a label above each page, so it'll be easy to know where you are, and also divide any text which is longer than one book into as many books as are necessary with a header indicating each new book. Lastly, the program will display the number of books required, and, based on that number, will calculate the necessary materials for making that many books, and how many chests will be necessary to contain them. Obviously, I doubt that most text that the program handles will require more than a couple of books, but I'm planning on doing Lovecraft's "The Dunwich Horror" as a test, and the first book in what will undoubtedly be an epic library, so it might take quite a few books.
//end of rambling background post.
The majority of the program is quite simple, and I don't need help with the looping or heading writing or anything. But there is one consideration I'd like to ask for some input on. I want to bring in 256 characters at a time of the text file I give the program, but I don't want to cut any words in half (or in any other fraction :p).
So what I need is a method to somehow ensure that the last word being brought in isn't cut off by the limit of 256 characters. If there is a word that will be cut off, I want to just stop at the last whole word, saving the word that would have been cut off for the beginning of the next page.
Currently, my idea is to use a cstring (an array of characters) with a size of 256 as a "holder" for each page. This will get loaded with 256 characters, then get written to the output file. One method I've thought of to check if a word has been cut off is to check the last space in the array to ensure that it's the space character. If not, then I would go backward through the array until I found the previous space (indicating the end of the last full word). Then I guess I'd run a loop to replace those last several characters with spaces.
Actually, having written this, I think this method will work well. Still, anyone with a good idea on how to prevent the aforementioned word cutoff issue should let me know. I know there's some good programmers on this forum, so I figured you guys would have some insight.
Also, when it's finished, which should be tonight after I finish up some homework, I'd be more than happy to post it here for anyone who would like to use such a utility (unless that violates the forum rules somehow, but I don't see why it would.)
Looking forward to any responses/insight!