Example #1
0
/*------------Main Function Starts Here----------------*/
void main(void)
{
textcolor(BLACK);
textbackground(BLACK);
clrscr(); //not needed here bcoz---> intro does it

/*To make user feel that it's Initializing*/
textcolor(RED);
gotoxy(32,22);
cprintf("Initializing");
for(i=46;i<50;i++)
cprintf(".");//delay();}
delay(2000);
/*----File Initialization---*/
rec_size=sizeof(book);
fp=fopen("c:\\library.sjb","ab+");
       //fp=fopen("c:\\library.sjb","rb+");
	if (fp==NULL)	bye();
	else
	{
	read_data(); // Reads data at the initialization time to find
	maxrec--;    // maxrec, which is the maxm no of data in the file
	}            //Decreased by one to avoid COUNTER Error.
/*--Intro Screen of the Program--*/
intro();
welcome();
home();

for(;;) //HOME LOOP OF THE PROGRAM
{
fflush(stdin); //Flushes the stdin input device
ch=tolower(getch());
if (ch==32||ch==13) //IF ALLOWS TO ENTER MAIN LOOP
	{
	setscreen();
	which_view();
	if(maxrec==-1) // Maxrec is decremented for the case of exiting database
	status("Database empty.");
	else
	status("The LIBRARY, welcomes you.");
	mainloop();
	home();
	}// IF THAT ALLOWED TO ENTER MAIN LOOP IS CLOSED NOW
else if (ch==27) bye(); //End of program
else if(ch=='p') printer(0); //Call to printer() from HOME
else if(ch=='x') html(0); //Call to html() from HOME
}// HOME loop of the programme
}
Example #2
0
File: main.c Project: emmanuj/se
void initialize (int argc, char *argv[])
{
	int i;

	Argno = 1;

	if (se_set_term (getenv ("TERM")) == SE_ERR)
		usage ();

	/* Initialize the scratch file: */
	mkbuf ();

	/* Initialize screen format parameters: */
	setscreen ();

	/* Initialize the array of blanks to blanks */
	for (i = 0; i < Ncols; i++)
		Blanks[i] = ' ';
	Blanks[i] = '\0';

	if (dosopt ("") == SE_ERR)
		error (SE_NO, "in initialize: can't happen");
}
Example #3
0
/*--This Function is main USER INTERACTING FUNCTION--*/
void mainloop(void)
{
	for(;;)
	{       fflush(stdin);
		ch=tolower(getch());
		if (ch==32) //SPACE DETECTED
		    {
		    if(recno>=0 && recno<maxrec)
		       {
			 if(tabview==0)
				{
				recno++;
				read_data();
				clsview();
				oneatime_show();
				if(recno == maxrec)
				status("Database - Right Boundary.");
				else
				status("<space> Next Record ->");
				}
			 else status("<space> Switch to One a time view.");
		      }
		    }

		else if (ch==13) //Refresh
		    {
		    setscreen();
		    which_view();
		    status("<CR> Data Refreshed.");
		    }

		else if (ch=='t')
		    {
		    if(tabview==0)
		    {
		    recold=recno;
		    tabview=1;
		    }

		    else
		    {
		    tabview=0;
		    }
		    setscreen();
		    which_view();
		    status("<t> Switch between tab/oneatime view.");
		    }
		else if (ch=='a')
		    {  if (view==1 && tabview==0)
		       {
			recold=recno;
			recno=maxrec+1;
			clsview();
			status("<a>  Please Enter the Book Info.");
			addbook(1);
			//setscreen();
			clsview();
			oneatime_show();
			//which_view();
			//status("Press <H> For Immediate Help.");
		       }
		       else if (tabview==1) status("<a> Switch to one-a-time view.");
		    else  status("<a> You ar not ADMIN!!!.");
		    }
		else if (ch=='e') //edit info
		    {
		    if (view==1)
		       {
			status("Please Enter Records To Modify.");
			truefalse=editbook();
			if(truefalse==0) //if strcmp didn't found records then comes here
			status("Sorry, book number didn't match with stored one.");
			}
		       else if (tabview==1) status("<a> Switch to one-a-time view.");
		       else  status("<a> You ar not ADMIN!!!.");

		    }
	       else if (ch=='f') //edit info
		    {
			if (view==1)
			{
			truefalse=searchbook();
			if(truefalse==0) //if strcmp didn't found records then comes here
			status("Sorry, record not match.");
			else  status("<a> You ar not ADMIN!!!.");
			}
		    }
		else if (ch=='d') //delete
		    {
		    /*strcpy(tempo,book.bookno);
		    ft=fopen("temp.sjb","wb");
		    rewind(fp);
		    while(fread(&tmp,rec_size,1,fp)==1)
		    {
		     if(strcmp(tmp.bookno,tempo)!=0)
		      {fwrite(&tmp,rec_size,1,ft);
		      }
		    else  truefalse=0;
		    }
		    fclose(fp);
		    fclose(ft);
		    remove("library.sjb");
		    rename("temp.sjb","library.sjb");
		    fp=fopen("library.sjb","rb+");
		    recno=0;
		    maxrec=0;
		    read_data(); // Reads data at the initialization time to find
		    maxrec--;

		    if(truefalse==0)*/
		    status("<d> Record can't be deleted.");
		    }
		else if(ch=='x') {html(1);}
		else if (ch==27) break;
		else if(ch==0)
				{//i.e ch==0 if extended code,
				ch2 = getch(); // read second code
				if(ch2==59)
				    status("Function key 1");
				else if(ch2==60)
				    status("Function key 2");
				else if(ch2==75)//LEFT ARROW
				    {
					if(recno>0 && recno<=maxrec)
						{
						if(tabview==0)
						{
						recno--;
						read_data();
						clsview();
						oneatime_show();
						if(recno==0)
						status("Database - Left Boundary.");
						else
						status("<l-arrow> <- Previous Record");
						}
						else status("<space> Switch to One a time view.");
						}
				     }
				else if(ch2==77) //Right Arrow
				    {

				    if(recno>=0 && recno<maxrec)
					{
					if(tabview==0)
					{
					recno++;
					read_data();
					clsview();
					oneatime_show();
					if(recno == maxrec)
					status("Database - Right Boundary.");
					else
					status("<r-arrow> Next Record ->");
					}
					else status("<r-arrow> Switch to One a time view.");
					}
				    }
				else if(ch2==80)  //Down arrow <p>
				    {
				    if (tabview==1)
					{
					if(row <13+25 || recno <maxrec)
					{row++;recno++;
					//if (row>=26) row=13;
					bulet(6,row);
					status("<d-arrow> Select Down"); }
					}
				    else if(tabview==0)  status("<d-arrow> Switch to tabular view.");
				    else printer(1);
				    }
				else if(ch2==72)  //up arrow  <h>
				    {
				    if (tabview==1)
					  {if(row>13 && recno >1) {row--;recno--;} else row=13+25;
					  bulet(6,row);
					  status("<u-arrow> Select Up");
					  }
				    else  status("Please do some Hit n Trial First.");
				    }
				else status("Under construction.");
				}//EXTENDED CODE SCANNED
	}//MAIN LOOP OF THE PROGRAMME
}
Example #4
0
static Bool initCitadel(void)
    {
    if (!read_cfg_messages())
        {
#ifdef WINCIT
        char Buffer[128];
        sprintf(Buffer, getmsg(188), getmsg(671));
        MessageBox(NULL, Buffer, NULL, MB_ICONSTOP | MB_OK);
#else
        printf(getmsg(188), getmsg(671));
#endif
        return (FALSE);
        }

    checkfiles();

    initExtDrivers();

    get_os();

	cfg.battr = 0xff;
    setscreen();

    logo(TRUE); // no go for debug version; td32 go crash crash

    init_internal_sound();

	// some mouse initialization technology!!!!
    initMouseHandler();
    hideCounter = 1;

    if (time(NULL) < 700000000L)
        {
#ifdef WINCIT
        MessageBox(NULL, getcfgmsg(119), NULL, MB_ICONSTOP | MB_OK);
#else
        doccr();
        doccr();
        cPrintf(getcfgmsg(119));
        doccr();
#endif
        dump_cfg_messages();
        return (FALSE);
        }


    static char prompt[92];
    static char citadel[92];
    char *envprompt;
    char *citprompt;

    envprompt = getenv(getcfgmsg(120));
    citprompt = getenv(getcfgmsg(121));
    if (citprompt)
        {
        sprintf(prompt, getcfgmsg(122), citprompt);
        }
    else if (envprompt)
        {
        sprintf(prompt, getcfgmsg(123), envprompt);
        }
    else
        {
        strcpy(prompt, getcfgmsg(124));
        }
    putenv(prompt);

    sprintf(citadel, getcfgmsg(125), programName, version);
    putenv(citadel);


#ifndef WINCIT
    OC.whichIO = CONSOLE;
    OC.SetOutFlag(OUTOK);
    OC.Echo = BOTH;
    OC.setio();
#endif

    VerifyHeap(1);

    // If we aren't reconfiguring, load the tables...
    if (!reconfig)
        {
        // Start by reading ETC.TAB
        getcwd(etcpath, 64);

        FILE *fd;
        if ((fd = fopen(etcTab, FO_RB)) != NULL)
            {
            if (filelength(fileno(fd)) != (long) sizeof(config) ||
					fread(&cfg, 1, sizeof(config), fd) != (long) sizeof(config))
                {
                memset(&cfg, 0, sizeof(cfg));
                reconfig = TRUE;
                }

            fclose(fd);
            unlink(etcTab);


            // If ETC.TAB could be loaded, load the rest
            if (!reconfig)
                {
                changedir(cfg.homepath);

                allocateTables();

                if (!LogTab.Load() || !MessageDat.LoadTable() || !RoomTab.Load())
                    {
                    reconfig = TRUE;
                    }

                Cron.ReadTable(WC_TWpn);
                }
            }
        else
            {
            if (!batchmode)
                {
#ifdef WINCIT
                MessageBox(NULL, "No ETC.TAB.", NULL, MB_ICONSTOP | MB_OK);
#else
                doccr();

                discardable *d;

                if ((d = readData(6)) != NULL)
                    {
                    int i;

                    for (i = 0; ((char **) d->next->aux)[i][0] != '#'; i++)
                        {
                        cPrintf(pcts, ((char **) d->next->aux)[i]);
                        doccr();
                        }

                    doccr();

                    discardData(d);
                    }
                else
                    {
                    cOutOfMemory(28);
                    }

                DeinitializeTimer();
                critical(FALSE);
#endif
                exit(1);
                }

            reconfig = TRUE;
            }
        }



    if (reconfig)
        {
        cfg.attr = 7;

#ifndef WINCIT
        pause(200);
        cls(SCROLL_SAVE);

        cCPrintf(getcfgmsg(126));
        doccr();
#endif


        if (!configcit())
            {
#ifdef WINCIT
            MessageBox(NULL, getcfgmsg(127), NULL, MB_ICONSTOP | MB_OK);
#else
            doccr();
            doccr();
            cPrintf(getcfgmsg(127));
            doccr();
#endif
            dump_cfg_messages();
            return (FALSE);
            }


#ifndef WINCIT
        setdefaultTerm(TT_ANSI);
        CurrentUser->SetWidth(80);
#endif

        Cron.ReadCronCit(WC_TWpn);
        }
    else
        {
#ifndef WINCIT
        if (!CreateScrollBackBuffer())
            {
            cPrintf(getcfgmsg(60));
            doccr();
            }
#endif


        if (readconfigcit)  // forced to read in config.cit
            {
            if (!readconfig(NULL, 1))
                {
#ifdef WINCIT
                MessageBox(NULL, getcfgmsg(129), NULL, MB_ICONSTOP | MB_OK);
#else
                doccr();
                doccr();
                cPrintf(getcfgmsg(129));
                doccr();
#endif
                dump_cfg_messages();
                return (FALSE);
                }
            }
        }

    VerifyHeap(1);

    makeBorders();
    readBordersDat();

    if (cmd_nobells)
        {
        cfg.noBells = 2;
        }

    if (cmd_nochat)
        {
        cfg.noChat = TRUE;
        }

    if (cmd_mdata != CERROR)
        {
        cfg.mdata = cmd_mdata;
        }

    if (*cfg.f6pass)
        {
        if (SameString(cfg.f6pass, getmsg(670)))
            {
            ConsoleLock.LockF6();
            }
        else
            {
            ConsoleLock.Lock();
            }
        }


#ifndef WINCIT
    if (cfg.ovrEms)
        {
        if (_OvrInitEms(0, 0, 0))
            {
            cPrintf(getcfgmsg(130));
            doccr();
            pause(200);
            }
        }

    if (cfg.ovrExt)
        {
        if (_OvrInitExt(0, 0))
            {
            cPrintf(getcfgmsg(131));
            doccr();
            pause(200);
            }
        }

    CommPort->Init();
    setscreen();
#endif

    logo(TRUE); // no go for debug version; td32 go crash crash

#ifndef WINCIT
    StatusLine.Update(WC_TWp);
#endif

    if (cfg.msgpath[(strlen(cfg.msgpath) - 1)] == '\\')
        {
        cfg.msgpath[(strlen(cfg.msgpath) - 1)] = '\0';
        }

    // move to home path
    changedir(cfg.homepath);
    char FileName[128];

    ReIndexFileInfo();  // keep fileinfo.dat nice and pretty

    // open message file
    if (!MessageDat.OpenMessageFile(cfg.msgpath))
		{
		illegal(getmsg(78), MessageDat.GetFilename());
		}

    // Then room file
    sprintf(FileName, sbs, cfg.homepath, roomDat);
    openFile(FileName, &RoomFile);

    citOpen(cfg.trapfile, CO_A, &TrapFile);
    initMenus();
    dump_cfg_messages();

    if(!read_tr_messages())
        {
        errorDisp(getmsg(172));
        }
    else
        {
#ifdef WINCIT
    trap(T_SYSOP, "", gettrmsg(37));
#else
    trap(T_SYSOP, gettrmsg(37));
#endif
        dump_tr_messages();
        }

        read_cfg_messages();            // uh-oh!

    if (!GroupData.Load())
        {
        return (FALSE);
        }

    if (!HallData.Load())
        {
        return (FALSE);
        }

    getRoomPos();

    if (cfg.accounting)
        {
        ReadGrpdataCit(WC_TWpn);
        }

    ReadExternalCit(WC_TWpn);
    ReadProtocolCit(WC_TWpn);
    ReadMdmresltCit(WC_TWpn);
    ReadCommandsCit(WC_TWpn);


#ifndef WINCIT
    ReadMCICit(FALSE);

    CurrentRoom->Load(LOBBY);
    thisRoom = LOBBY;
    checkdir();

    if (!slv_door)
        {
        CITWINDOW *w = CitWindowsMsg(NULL, getmsg(19));

        Initport();
        Initport();

        if (w)
            {
            destroyCitWindow(w, FALSE);
            }
        }
    else
        {
        CommPort->Enable();
        }

    OC.whichIO = MODEM;
    OC.setio();
#endif


    // record when we put system up
    time(&uptimestamp);

#ifndef WINCIT
    setdefaultconfig(FALSE);
    Talley->Fill();
#endif
    logo(FALSE);

    VerifyHeap(1);

    dump_cfg_messages();
    compactMemory(1);

    return (TRUE);
    }
Example #5
0
/************************************************************************
 *      main() Initialize & start citadel
 ************************************************************************/
void main(int argc, char *argv[])
{
    int i, cfg_ctdl = FALSE;
    long b;
    char init_baud;
    static char prompt[92];
    char *envprompt;

    cfg.bios = 1;
	cit_init_timer();			/* initialize cit_time() and cit_timer()	*/
    cfg.attr = 7;       		/* logo gets white letters                  */
    setscreen();				/* initialize screen system					*/
	memset(&parm,0,sizeof(parm));
    for (i = 1; i < argc; i++) {
        if (argv[i][0] == '/'
        || argv[i][0] == '-') {
            switch (tolower(argv[i][1])) {
#ifndef ATARI_ST
                case 'd':       /* DesqView/TopView     */
                    parm.dv = 1;
                    cPrintf("DesqView/TopView mode\n");
                    break;

                case 'b':       /* baud rate (for shell) */
                    if (argv[i + 1]) {
						b = atol(argv[++i]);
                        for (init_baud = 0; bauds[init_baud]; ++init_baud)
                            if (bauds[init_baud] == b) {
                                parm.baud = init_baud;
                                cPrintf("Initial baud rate fixed at %ld\n", b);
                                break;
							}
                    }
                    break;
				case 'm':
					parm.memcheck = !parm.memcheck;
					break;
#endif
                case 'c':       /* Configure system     */
                    cfg_ctdl = TRUE;
                    break;

                case 'p':       /* pace output          */
                    if (argv[i + 1]) {
                        parm.pace = atoi(argv[++i]);
                        cPrintf("Output pacing %d\n", parm.pace);
                    }
                    break;

                case 's':       /* run in shell from another BBS (door).        */
                    cPrintf("Shell mode\n");
                    parm.door = TRUE;
                    break;
/*#ifndef ATARI_ST*/
#ifndef FLOPPY
                case 'e':       /* use EMS                      */
                    if (_OvrInitEms(0, 0, 0)) {
                        cPrintf("EMS memory initialization failed!\n");
                        parm.ems = 1;
                    }
                    break;
#endif
/*#endif*/
				case 'v':       /* just do events       */
                    parm.events = 1;
                    break;
/*#ifndef ATARI_ST*/
#ifndef FLOPPY
                case 'x':       /* use exteneded memory */
					if (_OvrInitExt(0, 0))
                        cPrintf("Extended memory initialization failed!\n");
                    parm.ext = 1;
                    break;
#endif
/*#endif*/
				case 'l':		/* log in user */
                    if (argv[i + 1]) {
						parm.login = argv[++i];
						cPrintf("Auto-login\n");
					}
					break;

				case 'u':		/* log in user */
                    if (argv[i + 1]) {
						parm.user = argv[++i];
						cPrintf("Auto-login %s\n", parm.user);
					}
					break;
					
                default:
                    cPrintf("\nUnknown commandline switch '%s'.\n", argv[i]);
                    cPrintf("Valid DOS command line switches:\n");
                    cPrintf("    -b baud   Starting baud rate (300-19200)\n");
                    cPrintf("    -c        Read configuration files\n");
                    cPrintf("    -d        DesqView/TopView\n");
#ifndef FLOPPY
                    cPrintf("    -e        Use EMS memory for overlays\n");
#endif
					cPrintf("    -l str    Log in using initials;password in str\n");
					cPrintf("    -m        Memory check during idle time, start\n");
                    cPrintf("    -p num    Set output pacing to num\n");
                    cPrintf("    -s        Run as a shell from another BBS\n");
					cPrintf("    -u 'name' Log in using specifed user name");
                    cPrintf("    -v        Just run cron events\n");
#ifndef FLOPPY
					cPrintf("    -x        Use extended memory for overlays (386/486 only!)\n");
#endif
                    exit(1);
            }
        }
    }

    if (cfg_ctdl)				/* force reconfigure?						*/
        unlink("etc.tab");

    logo();						/* prints out system logo                   */

    if (cit_time() < 607415813L) {
        cPrintf("\n\nPlease set your time and date!\n");
        exit(1);
    }
	/* set prompt for shells */
    envprompt = getenv("PROMPT");
	if (!envprompt)
		envprompt = "$p$g";
    sprintf(prompt, "PROMPT=\r\nType EXIT to return to FredCit\r\n%s", envprompt);
    if (putenv(prompt)) {
        cPrintf("\n\nCan not set DOS prompt!\n");
		delay (5000);
	}
	/* initialize citadel */
    initCitadel();

    if (parm.baud) {
        cfg.initbaud = parm.baud;
        baud(cfg.initbaud);
    }
	if (parm.door) {
		detectflag = 1;
//		carrier();
//		if (haveCarrier) {
//			carrdetect();
//			newCarrier = 1;		/* make hello blurb show up */
//		}
	}
    greeting();

	sysReq = FALSE;

	if (cfg.f6pass[0])
		ConLock = TRUE;

	if (parm.dv) {
		cfg.bios = 1;
		directvideo = 0;
	}

	if (parm.login) {
		normalizeString(parm.login);	/* normalize string in environment */
		login(parm.login,NULL);
	} else if (parm.user && !loggedIn) {
		normalizeString(parm.user);	/* normalize string in environment */
		if (findPerson(parm.user, &lBuf) != ERROR)
			login(lBuf.lbin,lBuf.lbpw);
	}

		/* read in door interface files */
	if (parm.door) {
		readDoorFiles(0);
	}
	/* update25();	*/
	do_idle(0);

	/* install critical error handler */
	harderr(cit_herror_handler);
	
	/* execute main command loop */
    if (!parm.events)
        command_loop();
    else {
        do_cron_loop();
    }

    exitcitadel();
}