Added endian byteorder code for menu editor

This commit is contained in:
Michiel Broek 2003-02-10 22:17:35 +00:00
parent 694a34159d
commit 75831ac20c
5 changed files with 430 additions and 339 deletions

View File

@ -1,5 +1,8 @@
$Id$ $Id$
WARNING, users of Sparc and HP-PA systems should not edit bbs menus now!
All other users on Intel machines (99,9% I think) can use this version.
v0.37.01 14-Jan-2003. v0.37.01 14-Jan-2003.
@ -36,6 +39,8 @@ v0.37.01 14-Jan-2003.
common.a: common.a:
Removed charset conversion/translation. Removed charset conversion/translation.
Added integer endian byteorder swapper, usefull for non-Intel
hardware.
mbtask: mbtask:
Arcmail for non-CM nodes and Txx nodes is now sent during the Arcmail for non-CM nodes and Txx nodes is now sent during the
@ -70,6 +75,7 @@ v0.37.01 14-Jan-2003.
Added new menu item 319, removed menu items 22 and 23. Added new menu item 319, removed menu items 22 and 23.
Added setup for rules directory. Added setup for rules directory.
Added setup for menu 221. Changed description of menu 103. Added setup for menu 221. Changed description of menu 103.
The menu editor is machine endian independant.
mbsebbs: mbsebbs:
It will now refuse to up/download OLR packets when the system It will now refuse to up/download OLR packets when the system

View File

@ -11,12 +11,12 @@ COMMON_SRCS = attach.c falists.c hdr.c parsedate.c rfcmsg.c unpacker.c \
batchrd.c charset.c ftn.c pktname.c mangle.c sectest.c \ batchrd.c charset.c ftn.c pktname.c mangle.c sectest.c \
dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \ dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \
execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \ execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \
faddr.c gmtoffset.c packet.c rfcdate.c term.c faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c
COMMON_OBJS = ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \ COMMON_OBJS = ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \
batchrd.o ftn.o pktname.o mangle.o sectest.o \ batchrd.o ftn.o pktname.o mangle.o sectest.o \
dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o \ dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o \
execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \ execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \
faddr.o gmtoffset.o packet.o rfcdate.o term.o faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o
COMMON_HDRS = common.h COMMON_HDRS = common.h
NODELIST_SRCS = nodelist.c NODELIST_SRCS = nodelist.c
NODELIST_OBJS = nodelist.o NODELIST_OBJS = nodelist.o
@ -158,6 +158,7 @@ gmtoffset.o: ../config.h libs.h memwatch.h structs.h common.h
packet.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h dbnode.h packet.o: ../config.h libs.h memwatch.h structs.h users.h records.h clcomm.h common.h dbnode.h
rfcdate.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h rfcdate.o: ../config.h libs.h memwatch.h structs.h common.h clcomm.h
term.o: ../config.h libs.h memwatch.h structs.h users.h ansi.h records.h common.h term.o: ../config.h libs.h memwatch.h structs.h users.h ansi.h records.h common.h
endian.o: ../config.h libs.h memwatch.h structs.h common.h
dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h dbcfg.o: ../config.h libs.h memwatch.h mbse.h structs.h users.h records.h mberrors.h dbcfg.h
dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h dbdupe.h dbdupe.o: ../config.h libs.h memwatch.h structs.h clcomm.h mberrors.h dbdupe.h
dbftn.o: ../config.h libs.h memwatch.h structs.h users.h records.h dbcfg.h dbftn.h dbftn.o: ../config.h libs.h memwatch.h structs.h users.h records.h dbcfg.h dbftn.h

View File

@ -176,6 +176,13 @@ struct termios tbufs, tbufsavs; /* Structure for raw mode */
/*
* From endian.c
*/
int le_int(int);
/* /*
* From attach.c * From attach.c
*/ */

64
lib/endian.c Normal file
View File

@ -0,0 +1,64 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Change integer value CPU endian independant
*
*****************************************************************************
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "../config.h"
#include "libs.h"
#include "memwatch.h"
#include "structs.h"
#include "common.h"
/*
* Return an integer in endian independent format. This is used to make menu
* files portable on little and big-endian systems. Normal datafiles are
* not portable, only the menus.
*/
int le_int(int val)
{
#ifdef BYTE_ORDER
if (BYTE_ORDER == 1234) {
return val;
} else if (BYTE_ORDER == 4321) {
return ((val & 0xff) << 24) | (((val >> 8) & 0xff) << 16) | (((val >> 16) & 0xff) << 8) | ((val >> 24) & 0xff);
} else {
#endif
#ifdef __i386__
return val;
#else
return ((val & 0xff) << 24) | (((val >> 8) & 0xff) << 16) | (((val >> 16) & 0xff) << 8) | ((val >> 24) & 0xff);
#endif
#ifdef BYTE_ORDER
}
#endif
return val;
}

View File

@ -44,6 +44,7 @@
char *select_menurec(int max) char *select_menurec(int max)
{ {
static char *menu=(char *)"-"; static char *menu=(char *)"-";
@ -114,7 +115,7 @@ void Show_A_Menu(void)
mvprintw(17, 2, "10. Lo-colors"); mvprintw(17, 2, "10. Lo-colors");
mvprintw(18, 2, "11. Hi-colors"); mvprintw(18, 2, "11. Hi-colors");
mvprintw(19, 2, "12. Autoexec"); mvprintw(19, 2, "12. Autoexec");
if (menus.MenuType == 7) { if (le_int(menus.MenuType) == 7) {
mvprintw(15,42, "13. No door.sys"); mvprintw(15,42, "13. No door.sys");
mvprintw(16,42, "14. Y2K style"); mvprintw(16,42, "14. Y2K style");
mvprintw(17,42, "15. Use Comport"); mvprintw(17,42, "15. Use Comport");
@ -124,23 +125,23 @@ void Show_A_Menu(void)
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
show_str( 7,16, 1, menus.MenuKey); show_str( 7,16, 1, menus.MenuKey);
show_int( 8,16, menus.MenuType); show_str( 8, 26,29, menus.TypeDesc); show_int( 8,16, le_int(menus.MenuType)); show_str( 8, 26,29, menus.TypeDesc);
show_str( 9,16,64, menus.OptionalData); show_str( 9,16,64, menus.OptionalData);
show_str(10,16,64,(char *)"1234567890123456789012345678901234567890123456789012345678901234"); show_str(10,16,64,(char *)"1234567890123456789012345678901234567890123456789012345678901234");
show_str(11,16,64, menus.Display); show_str(11,16,64, menus.Display);
show_sec(12,16, menus.MenuSecurity); show_sec(12,16, menus.MenuSecurity);
show_int(13,16, menus.Age); show_int(13,16, le_int(menus.Age));
show_int(14,16, menus.MaxSecurity); show_int(14,16, le_int(menus.MaxSecurity));
if (strlen(menus.Password)) if (strlen(menus.Password))
show_str(15,16,14, (char *)"**************"); show_str(15,16,14, (char *)"**************");
else else
show_str(15,16,14, (char *)"<null>"); show_str(15,16,14, (char *)"<null>");
show_int(16,16, menus.Credit); show_int(16,16, menus.Credit);
S_COL(17,16, "Normal display color", menus.ForeGnd, menus.BackGnd) S_COL(17,16, "Normal display color", le_int(menus.ForeGnd), le_int(menus.BackGnd))
S_COL(18,16, "Bright display color", menus.HiForeGnd, menus.HiBackGnd) S_COL(18,16, "Bright display color", le_int(menus.HiForeGnd), le_int(menus.HiBackGnd))
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
show_bool(19,16, menus.AutoExec); show_bool(19,16, menus.AutoExec);
if (menus.MenuType == 7) { if (le_int(menus.MenuType) == 7) {
show_bool(15,58, menus.NoDoorsys); show_bool(15,58, menus.NoDoorsys);
show_bool(16,58, menus.Y2Kdoorsys); show_bool(16,58, menus.Y2Kdoorsys);
show_bool(17,58, menus.Comport); show_bool(17,58, menus.Comport);
@ -213,7 +214,7 @@ int GetMenuType(void)
void Edit_A_Menu(void); void Edit_A_Menu(void);
void Edit_A_Menu(void) void Edit_A_Menu(void)
{ {
int fg, bg; int temp, fg, bg;
Show_A_Menu(); Show_A_Menu();
@ -222,53 +223,67 @@ void Edit_A_Menu(void)
case 0: return; case 0: return;
break; break;
case 1: E_UPS( 7,16, 1, menus.MenuKey, "The ^key^ to select this menu item") case 1: E_UPS( 7,16, 1, menus.MenuKey, "The ^key^ to select this menu item")
case 2: menus.MenuType = GetMenuType(); case 2: temp = GetMenuType();
memset(&menus.TypeDesc, 0, sizeof(menus.TypeDesc)); memset(&menus.TypeDesc, 0, sizeof(menus.TypeDesc));
if (menus.MenuType) if (temp)
strcpy(menus.TypeDesc, getmenutype(menus.MenuType)); strcpy(menus.TypeDesc, getmenutype(temp));
if (menus.MenuType == 21) if (temp == 21)
menus.AutoExec = TRUE; menus.AutoExec = TRUE;
menus.MenuType = le_int(temp);
Show_A_Menu(); Show_A_Menu();
break; break;
case 3: E_STR( 9,16,64, menus.OptionalData, "The ^optional data^ for this menu item") case 3: E_STR( 9,16,64, menus.OptionalData, "The ^optional data^ for this menu item")
case 4: E_STR(11,16,64, menus.Display, "The text to ^display^ for this menu") case 4: E_STR(11,16,64, menus.Display, "The text to ^display^ for this menu")
case 5: E_SEC(12,16, menus.MenuSecurity, "8.3.5 MENU ACCESS SECURITY", Show_A_Menu) case 5: menus.MenuSecurity.level = le_int(menus.MenuSecurity.level);
case 6: E_INT(13,16, menus.Age, "The minimum ^Age^ to select this menu, 0 is don't care") menus.MenuSecurity = edit_sec(12,16, menus.MenuSecurity, (char *)"8.3.5 MENU ACCESS SECURITY");
case 7: E_INT(14,16, menus.MaxSecurity, "The maximum ^Security level^ to access this menu") menus.MenuSecurity.level = le_int(menus.MenuSecurity.level);
case 8: E_STR(15,16,14, menus.Password, "The ^password^ to access this menu item")
case 9: E_INT(16,16, menus.Credit, "The ^credit cost^ for this menu item")
case 10:fg = menus.ForeGnd;
bg = menus.BackGnd;
edit_color(&fg, &bg, (char *)"8.3.10 EDIT COLOR", (char *)"normal");
menus.ForeGnd = fg;
menus.BackGnd = bg;
Show_A_Menu(); Show_A_Menu();
break; break;
case 11:fg = menus.HiForeGnd; case 6: temp = le_int(menus.Age);
bg = menus.HiBackGnd; temp = edit_int(13,16, temp, (char *)"The minimum ^Age^ to select this menu, 0 is don't care");
menus.Age = le_int(temp);
break;
case 7: temp = le_int(menus.MaxSecurity);
temp = edit_int(14,16, temp, (char *)"The maximum ^Security level^ to access this menu");
menus.MaxSecurity = le_int(temp);
break;
case 8: E_STR(15,16,14, menus.Password, "The ^password^ to access this menu item")
case 9: temp = le_int(menus.Credit);
temp = edit_int(16,16, temp, (char *)"The ^credit cost^ for this menu item");
menus.Credit = le_int(temp);
break;
case 10:fg = le_int(menus.ForeGnd);
bg = le_int(menus.BackGnd);
edit_color(&fg, &bg, (char *)"8.3.10 EDIT COLOR", (char *)"normal");
menus.ForeGnd = le_int(fg);
menus.BackGnd = le_int(bg);
Show_A_Menu();
break;
case 11:fg = le_int(menus.HiForeGnd);
bg = le_int(menus.HiBackGnd);
edit_color(&fg, &bg, (char *)"8.3.11 EDIT COLOR", (char *)"bright"); edit_color(&fg, &bg, (char *)"8.3.11 EDIT COLOR", (char *)"bright");
menus.HiForeGnd = fg; menus.HiForeGnd = le_int(fg);
menus.HiBackGnd = bg; menus.HiBackGnd = le_int(bg);
Show_A_Menu(); Show_A_Menu();
break; break;
case 12:E_BOOL(19,16, menus.AutoExec, "Is this an ^Autoexecute^ menu item") case 12:E_BOOL(19,16, menus.AutoExec, "Is this an ^Autoexecute^ menu item")
case 13:if (menus.MenuType == 7) { case 13:if (le_int(menus.MenuType) == 7) {
E_BOOL(15,58, menus.NoDoorsys, "Suppress writing ^door.sys^ dropfile") E_BOOL(15,58, menus.NoDoorsys, "Suppress writing ^door.sys^ dropfile")
} else } else
break; break;
case 14:if (menus.MenuType == 7) { case 14:if (le_int(menus.MenuType) == 7) {
E_BOOL(16,58, menus.Y2Kdoorsys, "Create ^door.sys^ with 4 digit yearnumbers") E_BOOL(16,58, menus.Y2Kdoorsys, "Create ^door.sys^ with 4 digit yearnumbers")
} else } else
break; break;
case 15:if (menus.MenuType == 7) { case 15:if (le_int(menus.MenuType) == 7) {
E_BOOL(17,58, menus.Comport, "Write real ^COM port^ in door.sys for Vmodem patch") E_BOOL(17,58, menus.Comport, "Write real ^COM port^ in door.sys for Vmodem patch")
} else } else
break; break;
case 16:if (menus.MenuType == 7) { case 16:if (le_int(menus.MenuType) == 7) {
E_BOOL(18,58, menus.NoSuid, "Run the door as ^real user (nosuid)^") E_BOOL(18,58, menus.NoSuid, "Run the door as ^real user (nosuid)^")
} else } else
break; break;
case 17:if (menus.MenuType == 7) { case 17:if (le_int(menus.MenuType) == 7) {
E_BOOL(19,58, menus.NoPrompt, "^Don't display prompt^ when door is finished") E_BOOL(19,58, menus.NoPrompt, "^Don't display prompt^ when door is finished")
} else } else
break; break;
@ -281,13 +296,11 @@ void Edit_A_Menu(void)
void EditMenu(char *); void EditMenu(char *);
void EditMenu(char *Name) void EditMenu(char *Name)
{ {
char mtemp[PATH_MAX], temp[PATH_MAX]; char mtemp[PATH_MAX], temp[PATH_MAX], pick[12];
FILE *fil, *tmp; FILE *fil, *tmp;
int records = 0, i, o, y; int records = 0, i, o, y, MenuUpdated = FALSE, from, too;
char pick[12];
long offset; long offset;
unsigned long crc, crc1; unsigned long crc, crc1;
int MenuUpdated = FALSE, from, too;
struct menufile tmenus; struct menufile tmenus;
clr_index(); clr_index();
@ -329,14 +342,14 @@ void EditMenu(char *Name)
set_color(LIGHTRED, BLACK); set_color(LIGHTRED, BLACK);
mvprintw(y, 10, "a"); mvprintw(y, 10, "a");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
} else } else {
mvprintw(y, 10, "%1s", menus.MenuKey); mvprintw(y, 10, "%1s", menus.MenuKey);
if (menus.MenuType == 999 ){ }
mvprintw(y, 12, "%-29s %5d %s", menus.TypeDesc, if (le_int(menus.MenuType) == 999 ) {
menus.MenuSecurity.level, menus.Display); mvprintw(y, 12, "%-29s %5d %s", menus.TypeDesc, le_int(menus.MenuSecurity.level), menus.Display);
} else } else {
mvprintw(y, 12, "%-29s %5d %s", menus.TypeDesc, mvprintw(y, 12, "%-29s %5d %s", menus.TypeDesc, le_int(menus.MenuSecurity.level), menus.OptionalData);
menus.MenuSecurity.level, menus.OptionalData); }
} else { } else {
set_color(LIGHTBLUE, BLACK); set_color(LIGHTBLUE, BLACK);
mvprintw(y, 5, "%3d.", o + i); mvprintw(y, 5, "%3d.", o + i);
@ -377,8 +390,8 @@ void EditMenu(char *Name)
if (strncmp(pick, "A", 1) == 0) { if (strncmp(pick, "A", 1) == 0) {
working(1, 0, 0); working(1, 0, 0);
memset(&menus, 0, sizeof(menus)); memset(&menus, 0, sizeof(menus));
menus.ForeGnd = LIGHTGRAY; menus.ForeGnd = le_int(LIGHTGRAY);
menus.HiForeGnd = WHITE; menus.HiForeGnd = le_int(WHITE);
fseek(tmp, 0, SEEK_END); fseek(tmp, 0, SEEK_END);
fwrite(&menus, sizeof(menus), 1, tmp); fwrite(&menus, sizeof(menus), 1, tmp);
records++; records++;
@ -589,19 +602,19 @@ int bbs_menu_doc(FILE *fp, FILE *toc, int page)
fprintf(fp, " Menu select %s\n", menus.MenuKey); fprintf(fp, " Menu select %s\n", menus.MenuKey);
if (menus.AutoExec) if (menus.AutoExec)
fprintf(fp, " Menu select Autoexec\n"); fprintf(fp, " Menu select Autoexec\n");
fprintf(fp, " Type %d %s\n", menus.MenuType, menus.TypeDesc); fprintf(fp, " Type %d %s\n", le_int(menus.MenuType), menus.TypeDesc);
fprintf(fp, " Opt. data %s\n", menus.OptionalData); fprintf(fp, " Opt. data %s\n", menus.OptionalData);
fprintf(fp, " Display %s\n", menus.Display); fprintf(fp, " Display %s\n", menus.Display);
fprintf(fp, " Security %s\n", get_secstr(menus.MenuSecurity)); fprintf(fp, " Security %s\n", get_secstr(menus.MenuSecurity));
fprintf(fp, " Minimum age %d\n", menus.Age); fprintf(fp, " Minimum age %d\n", menus.Age);
fprintf(fp, " Maximum level %d\n", menus.MaxSecurity); fprintf(fp, " Maximum level %d\n", le_int(menus.MaxSecurity));
fprintf(fp, " Password %s\n", menus.Password); fprintf(fp, " Password %s\n", menus.Password);
fprintf(fp, " Credits %ld\n", menus.Credit); fprintf(fp, " Credits %d\n", le_int(menus.Credit));
fprintf(fp, " Lo-colors %s on %s\n", fprintf(fp, " Lo-colors %s on %s\n",
get_color(menus.ForeGnd), get_color(menus.BackGnd)); get_color(le_int(menus.ForeGnd)), get_color(le_int(menus.BackGnd)));
fprintf(fp, " Hi-colors %s on %s\n", fprintf(fp, " Hi-colors %s on %s\n",
get_color(menus.HiForeGnd), get_color(menus.HiBackGnd)); get_color(le_int(menus.HiForeGnd)), get_color(le_int(menus.HiBackGnd)));
if (menus.MenuType == 7) { if (le_int(menus.MenuType) == 7) {
fprintf(fp, " No door.sys %s\n", getboolean(menus.NoDoorsys)); fprintf(fp, " No door.sys %s\n", getboolean(menus.NoDoorsys));
fprintf(fp, " Y2K door.sys %s\n", getboolean(menus.Y2Kdoorsys)); fprintf(fp, " Y2K door.sys %s\n", getboolean(menus.Y2Kdoorsys));
fprintf(fp, " Use COM port %s\n", getboolean(menus.Comport)); fprintf(fp, " Use COM port %s\n", getboolean(menus.Comport));