summaryrefslogtreecommitdiff
path: root/app/bin/cnote.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2024-11-14 19:35:45 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2024-11-14 19:35:45 +0100
commitdf5520aa2dae5b3ce7abf8733dcdd152898af163 (patch)
tree00d3047bfb14f682bfb5a21010c731ed649bfed7 /app/bin/cnote.c
parentdf247efec654e512242e4f4f1b0212034f9e01fe (diff)
parentec3c0f6f6e7153fa797dc57a0e95779cbc63a23b (diff)
Merge branch 'release/debian/1_5.3.0GA-1'debian/1_5.3.0GA-1
Diffstat (limited to 'app/bin/cnote.c')
-rw-r--r--app/bin/cnote.c133
1 files changed, 70 insertions, 63 deletions
diff --git a/app/bin/cnote.c b/app/bin/cnote.c
index 0a015f1..04d63f1 100644
--- a/app/bin/cnote.c
+++ b/app/bin/cnote.c
@@ -17,14 +17,12 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <string.h>
#include "custom.h"
#include "dynstring.h"
#include "fileio.h"
-#include "i18n.h"
#include "misc.h"
#include "param.h"
#include "include/utf8convert.h"
@@ -36,76 +34,83 @@ static paramTextData_t noteTextData = { 300, 150 };
static paramData_t notePLs[] = {
#define I_NOTETEXT (0)
#define noteT ((wText_p)notePLs[I_NOTETEXT].control)
- { PD_TEXT, NULL, "text", PDO_DLGRESIZE, &noteTextData }
+ { PD_TEXT, NULL, "text", PDO_DLGRESIZE, &noteTextData }
};
-static paramGroup_t notePG = { "note", 0, notePLs, sizeof notePLs/sizeof notePLs[0] };
+static paramGroup_t notePG = { "note", 0, notePLs, COUNT( notePLs ) };
void ClearNote(void)
{
- if (mainText) {
- MyFree(mainText);
- mainText = NULL;
- }
+ if (mainText) {
+ MyFree(mainText);
+ mainText = NULL;
+ }
}
-static void NoteOk(void * junk)
+static void NoteOk(void * unused)
{
- if (wTextGetModified(noteT)) {
- int len;
- ClearNote();
- len = wTextGetSize(noteT);
- mainText = (char*)MyMalloc(len+2);
- wTextGetText(noteT, mainText, len);
- }
-
- wHide(noteW);
+ if (wTextGetModified(noteT)) {
+ int len;
+ ClearNote();
+ len = wTextGetSize(noteT);
+ mainText = (char*)MyMalloc(len+2);
+ wTextGetText(noteT, mainText, len);
+ }
+
+ wHide(noteW);
}
-void DoNote(void)
+void DoNote(void * unused)
{
- if (noteW == NULL) {
- noteW = ParamCreateDialog(&notePG, MakeWindowTitle(_("Note")), _("Ok"), NoteOk,
- wHide, FALSE, NULL, F_NOTTRANSIENT|F_RESIZE, NULL);
- }
-
- wTextClear(noteT);
- wTextAppend(noteT, mainText?mainText:
- _("Replace this text with your layout notes"));
- wTextSetReadonly(noteT, FALSE);
- wShow(noteW);
+ if (noteW == NULL) {
+ noteW = ParamCreateDialog(&notePG, MakeWindowTitle(_("Note")), _("Ok"), NoteOk,
+ wHide, FALSE, NULL, F_NOTTRANSIENT|F_RESIZE, NULL);
+ }
+
+ wTextClear(noteT);
+ wTextAppend(noteT, mainText?mainText:
+ _("Replace this text with your layout notes"));
+ wTextSetReadonly(noteT, FALSE);
+ wShow(noteW);
}
+/**
+ * Save the main layout note to file. The note text is converted to
+ * UTF-8 if this is configured at compile time. Before saving characters that
+ * have special meanings in the XTC file (eg. ") are escaped.
+ *
+ * \param f open layout file
+ * \return
+ */
BOOL_T WriteMainNote(FILE* f)
{
- BOOL_T rc = TRUE;
+ BOOL_T rc = TRUE;
char *noteText = mainText;
if (noteText && *noteText) {
-#ifdef WINDOWS
+#ifdef UTFCONVERT
char *out = NULL;
if (RequiresConvToUTF8(mainText)) {
- unsigned cnt = strlen(mainText) * 2 + 1;
+ size_t cnt = strlen(mainText) * 2 + 1;
out = MyMalloc(cnt);
- wSystemToUTF8(mainText, out, cnt);
+ wSystemToUTF8(mainText, out, (unsigned int)cnt);
noteText = out;
}
-#endif // WINDOWS
-
+#endif // UTFCONVERT
- char * sText = ConvertToEscapedText( noteText );
- rc &= fprintf(f, "NOTE MAIN 0 0 0 0 0 \"%s\"\n", sText )>0;
- MyFree( sText );
+ char * sText = ConvertToEscapedText( noteText );
+ rc &= fprintf(f, "NOTE MAIN 0 0 0 0 0 \"%s\"\n", sText )>0;
+ MyFree( sText );
-#ifdef WINDOWS
+#ifdef UTFCONVERT
if (out) {
MyFree(out);
}
-#endif // WINDOWS
- }
- return rc;
+#endif // UTFCONVERT
+ }
+ return rc;
}
/**
@@ -116,28 +121,30 @@ BOOL_T WriteMainNote(FILE* f)
BOOL_T ReadMainNote(char *line)
{
- long size;
- char * sNote = NULL;
-
- if (!GetArgs(line + 9,
- paramVersion < 3 ? "l" :
- paramVersion < 12 ? "0000l":
- "0000lq", &size, &sNote)) {
- return FALSE;
- }
-
- if (mainText) {
- MyFree(mainText);
- }
-
- if ( paramVersion < 12 )
- mainText = ReadMultilineText();
- else
- mainText = sNote;
- return TRUE;
+ long size;
+ char * sNote = NULL;
+
+ if (!GetArgs(line + 9,
+ paramVersion < 3 ? "l" :
+ paramVersion < VERSION_INLINENOTE ? "0000l":
+ "0000lq", &size, &sNote)) {
+ return FALSE;
+ }
+
+ if (mainText) {
+ MyFree(mainText);
+ }
+
+ if ( paramVersion < VERSION_INLINENOTE ) {
+ mainText = ReadMultilineText();
+ } else {
+ mainText = sNote;
+ }
+
+ return TRUE;
}
void InitCmdNote()
{
- ParamRegister(&notePG);
+ ParamRegister(&notePG);
}