source: trunk/dll/menu.c@ 1395

Last change on this file since 1395 was 1395, checked in by Gregg Young, 17 years ago

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/***********************************************************************
2
3 $Id: menu.c 1395 2009-02-08 01:48:16Z gyoung $
4
5 Custom menu support routines for FM/2
6
7 Copyright (c) 1996-98 M. Kimes
8 Copyright (c) 2004, 2008 Steven H.Levine
9
10 01 Aug 04 SHL Rework lstrip/rstrip usage
11 22 Jul 06 SHL Check more run time errors
12 29 Jul 06 SHL Use xfgets_bstripcr
13 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
14 29 Feb 08 GKY Use xfree where appropriate
15
16***********************************************************************/
17
18#include <stdlib.h>
19#include <string.h>
20#include <share.h>
21
22#define INCL_WIN
23#define INCL_LONGLONG // dircnrs.h
24
25#include "fm3dll.h"
26#include "menu.h"
27#include "errutil.h" // Dos_Error...
28#include "delims.h" // skip_delim
29#include "wrappers.h" // xfgets_bstripcr
30#include "fortify.h"
31
32#pragma data_seg(DATA2)
33
34static PSZ pszSrcFile = __FILE__;
35
36MENU *menuhead = NULL;
37
38INT tokenize(CHAR * str, INT max, CHAR ** tokens)
39{
40 INT x = 0;
41 CHAR *p;
42
43 if (str && max && tokens) {
44 p = str;
45 for (;;) {
46 p = skip_delim(p, " \t");
47 if (!p)
48 break;
49 tokens[x++] = p;
50 if (x == max)
51 break;
52 p = to_delim(p, " \t");
53 if (!p)
54 break;
55 *p = 0;
56 p++;
57 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"\"%s\"\r\r%d",tokens[x - 1],x);
58 if (!*p)
59 break;
60 }
61 }
62 return x;
63}
64
65VOID FreeMenuList(MENU * head)
66{
67 MENU *info, *next;
68
69 info = head;
70 while (info) {
71 next = info->next;
72 xfree(info->text, pszSrcFile, __LINE__);
73 free(info);
74 info = next;
75 }
76}
77
78// fixme why do I exist since the only call passes no filename and FM3MENU.DAT doesn't exist. GKY 1-30-09
79BOOL AddToMenu(CHAR * filename, HWND hwndMenu)
80{
81 FILE *fp;
82 CHAR s[256];
83 CHAR *tokens[3];
84 INT lines = 0;
85 MENU *info, *last = NULL;
86 BOOL ret = FALSE;
87
88 // fixme to complain?
89 if (!hwndMenu) {
90 Runtime_Error(pszSrcFile, __LINE__, "no data");
91 return ret;
92 }
93 if (!filename)
94 filename = "FM3MENU.DAT";
95 fp = _fsopen(filename, "r", SH_DENYWR);
96 if (!fp) {
97 // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Couldn't open %s",filename);
98 }
99 else {
100 while (!feof(fp)) {
101 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
102 break;
103 lines++;
104 if (!*s || *s == ';')
105 continue;
106 if (tokenize(s, 3, tokens) == 3 && (USHORT) atoi(tokens[1])) {
107 info = xmallocz(sizeof(MENU), pszSrcFile, __LINE__);
108 if (info) {
109 info->size = sizeof(MENU);
110 info->text = xstrdup(tokens[2], pszSrcFile, __LINE__);
111 if (!info->text)
112 free(info);
113 else {
114 if (!stricmp(tokens[0], "MENUITEM"))
115 info->cmd = atoi(tokens[1]);
116 else if (!stricmp(tokens[0], "SEPARATOR"))
117 info->type = SEPARATOR;
118 else {
119 /* error! */
120 xfree(info->text, pszSrcFile, __LINE__);
121 free(info);
122 info = NULL;
123 }
124 if (info) {
125 if (!menuhead)
126 menuhead = info;
127 else
128 last->next = info;
129 info->next = NULL;
130 last = info;
131 }
132 }
133 }
134 }
135 else {
136 // fixme to complain?
137 // saymsg(MB_ENTER, HWND_DESKTOP, GetPString(IDS_DEBUG_STRING), "Tokenization failed");
138 }
139 }
140 fclose(fp);
141
142 if (menuhead) {
143 MENUITEM mi;
144
145 memset(&mi, 0, sizeof(mi));
146 info = menuhead;
147 WinEnableWindow(hwndMenu, FALSE);
148 while (info) {
149 mi.iPosition = MIT_END;
150 mi.id = info->cmd;
151 mi.afStyle =
152 (info->type == SEPARATOR) ? MIS_BREAKSEPARATOR : MIS_TEXT;
153 if (WinSendMsg
154 (hwndMenu, MM_INSERTITEM, MPFROMP(&mi), MPFROMP(info->text)))
155 ret = TRUE;
156 info = info->next;
157 }
158 WinEnableWindow(hwndMenu, TRUE);
159 FreeMenuList(menuhead);
160 menuhead = NULL;
161 }
162 }
163 return ret;
164}
165
166#pragma alloc_text(MENU,tokenize,FreeMenuList,AddToMenu)
Note: See TracBrowser for help on using the repository browser.