/*** MAIN LOOP ***/ int main(int argc, char *argv[]) { #if DEBUG bmem = AvailMem( MEMF_PUBLIC ); #endif ParseArgs(&args, argc, argv); /* Look first if Jano isn't already running */ if( find_janoed( &args ) ) cleanup(0, RETURN_OK); /* Some global initialization */ init_searchtable(); /* Optionnal libraries */ AslBase = (struct Library *) OpenLibrary("asl.library", 36); LocaleBase = (struct LocaleBase *) OpenLibrary("locale.library", 38); DiskfontBase = (struct Library *) OpenLibrary("diskfont.library", 0); IFFParseBase = (struct Library *) OpenLibrary("iffparse.library",36); if(LocaleBase) InitLocale(); /* Localize the prog */ /* Open the required ROM libraries */ if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36)) && (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36)) && (GadToolsBase = (struct Library *) OpenLibrary("gadtools.library", 36)) && (KeymapBase = (struct Library *) OpenLibrary("keymap.library", 36)) && (UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 36)) ) { init_macros(); set_default_prefs(&prefs, IntuitionBase->ActiveScreen); load_prefs(&prefs, NULL); /* See if it exists a config file */ sigport = create_port(); /* Create whether an empty project or an existing one */ if( ( edit = create_projects(NULL, args.sa_ArgLst, args.sa_NbArgs) ) ) { /* Open the main interface */ if(setup() == 0) { /* Makes edit project visible */ reshape_panel(edit); active_project(edit,TRUE); clear_brcorner(); dispatch_events(); } else cleanup(ErrMsg(ERR_NOGUI), RETURN_FAIL); } } else cleanup(ErrMsg(ERR_BADOS), RETURN_FAIL); /* Hope that all were well... */ cleanup(0, RETURN_OK); return 0; }
/*** Try to load a preference file ***/ UBYTE load_prefs(PREFS *prefs, STRPTR filename) { APTR file; UBYTE err = RETURN_OK; /* Locate preference file */ if( (file = open_prefs(filename, MODE_USE)) ) { /* Search for PREF/JANO chunk in this file */ if( !StopChunk(file, ID_PREF, ID_JANO) ) { if( !ParseIFF(file, IFFPARSE_SCAN) ) { struct ContextNode * cn = CurrentChunk(file); STRPTR buffer = NULL; UWORD ByteRead = 0; if( cn->cn_Type == ID_PREF && cn->cn_ID == ID_JANO && (buffer = (STRPTR) AllocVec(cn->cn_Size, MEMF_PUBLIC)) && ReadChunkBytes(file, buffer, cn->cn_Size) == cn->cn_Size ) { /* He have read the file, converts it into PREFS struct */ memset(prefs, 0, sizeof(*prefs)); prefs->wordssep = WordsSep; prefs->attrtxt.ta_Name = FontName; prefs->attrscr.ta_Name = FontName+30; while(ByteRead < cn->cn_Size) { register STRPTR src; src = buffer + ByteRead; if(src[0] < MAX_NUMFIELD) { register STRPTR dest = (STRPTR)prefs+offsets[*src]; if(sizefields[ *src ] == 0) dest = *(STRPTR *)dest; CopyMem(src+2, dest, src[1]); } ByteRead += src[1]+2; } } else err = RETURN_FAIL; if(buffer != NULL) FreeVec( buffer ); } else err = RETURN_FAIL; } else err = RETURN_FAIL; close_prefs(file); } else err = RETURN_FAIL; if(err == RETURN_OK) { info_screen(prefs, IntuitionBase->ActiveScreen); /* If user wants to use a custom font for its interface, try lo ** ** load it, otherwise use default screen font of parent screen: */ if(!prefs->use_scrfont || !(prefs->scrfont = (void *) OpenDiskFont( &prefs->attrscr )) ) prefs->scrfont = prefs->parent->RastPort.Font; /* Ditto with text font */ if(!prefs->use_txtfont || !(prefs->txtfont = (void *) OpenDiskFont( &prefs->attrtxt )) ) prefs->txtfont = GfxBase->DefaultFont; /* Makes valid pointers */ text_to_attr(prefs->scrfont, &prefs->attrscr); text_to_attr(prefs->txtfont, &prefs->attrtxt); /* Special characters that separate words */ unpack_separators(prefs->wordssep); } else set_default_prefs(prefs, IntuitionBase->ActiveScreen); /* All done */ return err; }