source: trunk/dll/menu.c@ 827

Last change on this file since 827 was 793, checked in by Gregg Young, 18 years ago

Move #pragma alloc_text to end for OpenWatcom compat

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