Changeset 356 for trunk/dll/menu.c


Ignore:
Timestamp:
Jul 26, 2006, 9:58:37 PM (19 years ago)
Author:
root
Message:

Check more run time errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/menu.c

    r123 r356  
    77
    88  Copyright (c) 1996-98 M. Kimes
    9   Copyright (c) 2004 Steven H.Levine
     9  Copyright (c) 2004, 2006 Steven H.Levine
    1010
    11   Revisions     01 Aug 04 SHL - Rework lstrip/rstrip usage
     11  01 Aug 04 SHL Rework lstrip/rstrip usage
     12  22 Jul 06 SHL Check more run time errors
    1213
    1314***********************************************************************/
     
    1516#define INCL_DOS
    1617#define INCL_WIN
     18#include <os2.h>
    1719
    18 #include <os2.h>
    1920#include <stdio.h>
    2021#include <stdlib.h>
    2122#include <string.h>
    2223#include <share.h>
     24
    2325#include "fm3dll.h"
    2426#include "menu.h"
    2527
    2628#pragma data_seg(DATA2)
     29
     30static PSZ pszSrcFile = __FILE__;
     31
    2732#pragma alloc_text(MENU,tokenize,FreeMenuList,AddToMenu)
    2833
    2934MENU *menuhead = NULL;
    3035
    31 
    32 INT tokenize (CHAR *str,INT max,CHAR **tokens) {
    33 
     36INT tokenize (CHAR *str,INT max,CHAR **tokens)
     37{
    3438  INT   x = 0;
    3539  CHAR *p;
     
    4953      *p = 0;
    5054      p++;
    51 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"\"%s\"\r\r%d",tokens[x - 1],x);
     55      // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"\"%s\"\r\r%d",tokens[x - 1],x);
    5256      if(!*p)
    5357        break;
     
    5862
    5963
    60 VOID FreeMenuList (MENU *head) {
    61 
     64VOID FreeMenuList (MENU *head)
     65{
    6266  MENU *info,*next;
    6367
     
    7377
    7478
    75 BOOL AddToMenu (CHAR *filename,HWND hwndMenu) {
    76 
     79BOOL AddToMenu (CHAR *filename,HWND hwndMenu)
     80{
    7781  FILE *fp;
    7882  CHAR  s[256];
     
    8286  BOOL  ret = FALSE;
    8387
    84   if(!hwndMenu)
     88  // fixme to complain?
     89  if (!hwndMenu) {
     90    Runtime_Error(pszSrcFile, __LINE__, "no data");
    8591    return ret;
    86   if(!filename)
     92  }
     93  if (!filename)
    8794    filename = "FM3MENU.DAT";
    8895  fp = _fsopen(filename,"r",SH_DENYWR);
    89   if(fp) {
    90     while(!feof(fp)) {
    91       if(!fgets(s,256,fp))
     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 (!fgets(s,256,fp))
    92102        break;
    93103      lines++;
     
    95105      if(!*s || *s == ';')
    96106        continue;
    97       if(tokenize(s,3,tokens) == 3 && (USHORT)atoi(tokens[1])) {
    98 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"%s\r\r%s\r\r%s",tokens[0],tokens[1],tokens[2]);
    99         info = malloc(sizeof(MENU));
    100         if(info) {
    101           memset(info,0,sizeof(MENU));
     107      if (tokenize(s,3,tokens) == 3 && (USHORT)atoi(tokens[1])) {
     108        info = xmallocz(sizeof(MENU),pszSrcFile,__LINE__);
     109        if (info) {
    102110          info->size = sizeof(MENU);
    103           info->text = strdup(tokens[2]);
    104           if(info->text) {
    105             if(!stricmp(tokens[0],"MENUITEM"))
     111          info->text = xstrdup(tokens[2],pszSrcFile,__LINE__);
     112          if (!info->text)
     113            free(info);
     114          else {
     115            if (!stricmp(tokens[0],"MENUITEM"))
    106116              info->cmd = atoi(tokens[1]);
    107             else if(!stricmp(tokens[0],"SEPARATOR"))
     117            else if (!stricmp(tokens[0],"SEPARATOR"))
    108118              info->type = SEPARATOR;
    109             else { /* error! */
     119            else {
     120              /* error! */
    110121              free(info->text);
    111122              free(info);
    112123              info = NULL;
    113124            }
    114             if(info) {
     125            if (info) {
    115126              if(!menuhead)
    116127                menuhead = info;
     
    121132            }
    122133          }
    123           else
    124             free(info);
    125134        }
    126135      }
    127       else {  /* error! */
    128 // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Tokenization failed");
     136      else {
     137        // fixme to complain?
     138        // saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Tokenization failed");
    129139      }
    130140    }
    131141    fclose(fp);
    132     if(menuhead) {
    133142
     143    if (menuhead) {
    134144      MENUITEM mi;
    135145
     
    137147      info = menuhead;
    138148      WinEnableWindow(hwndMenu,FALSE);
    139       while(info) {
     149      while (info) {
    140150        mi.iPosition = MIT_END;
    141151        mi.id = info->cmd;
    142152        mi.afStyle = (info->type == SEPARATOR) ? MIS_BREAKSEPARATOR : MIS_TEXT;
    143         if(WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi),
    144                       MPFROMP(info->text)))
     153        if (WinSendMsg(hwndMenu, MM_INSERTITEM, MPFROMP(&mi),
     154                       MPFROMP(info->text)))
    145155          ret = TRUE;
    146156        info = info->next;
     
    151161    }
    152162  }
    153 // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Couldn't open %s",filename);
    154163  return ret;
    155164}
Note: See TracChangeset for help on using the changeset viewer.