// Free an environment void environment_free(Cfg_Environment *env) { if (env) { env_free_desktop(&env->desktop); env_free_desktop(&env->path_list); env_free_desktop(&env->sound_list); FreeMemHandle(env->memory); FreeMemHandle(env->volatile_memory); FreeMemHandle(env->desktop_memory); FreeVec(env); } }
LOCAL void AutoSenseReqComplete (IO_REQ_PTR Req) { IO_REQ_PTR XReq = ReqAdapterPtr(Req)->Ext->InternalReqDeferQueue; TRACE(3, ("AutoSenseReqComplete(): Completion of autosense for request %lx ", XReq)); TRACE(3, ("cmd = %02x\n", ReqCommand(XReq))); DmsPause(7, 200); FreeMemHandle(Req->ReqDataPtr); TRACE(3, ("AutoSenseReqComplete(): Completion of auto sense\n")); DmsPause(7, 100); CompleteDeferedRequest(ReqAdapterPtr(Req), (APIStatus)((ReqAPIStatus(Req) == S_TAR_NOERROR) ? S_AD_AUTOSENSE_OK : S_AD_AUTOSENSE_FAIL)); }
// Free backdrop info void backdrop_free(BackdropInfo *info) { if (info) { // Free icons backdrop_free_list(info); // Free font if (info->font) CloseFont(info->font); // Free memory FreeMemHandle(info->memory); // Free structure FreeVec(info); } }
// Quit the program void quit(BOOL script) { // If main status window is open, close it if (main_status) { CloseProgressWindow(main_status); main_status=0; } if (GUI) { // Clear 'startup' flag for scripts GUI->flags&=~GUIF_DONE_STARTUP; // Close commodities cx_remove(GUI->cx); // Update environment settings env_update_settings(1); // Stop notify request RemoveNotifyRequest(GUI->notify_req); GUI->notify_req=0; // Is there a hide appicon? if (GUI->hide_appicon) { RemoveAppIcon(GUI->hide_appicon); FreeCachedDiskObject(GUI->hide_diskobject); } // Or an appmenuitem? if (GUI->hide_appitem) RemoveAppMenuItem(GUI->hide_appitem); // Launch shutdown script if (script) RunScript(SCRIPT_SHUTDOWN,0); // Set quit flag GUI->flags|=GUIF_PENDING_QUIT; // Shut the display down close_display(CLOSE_ALL,TRUE); // Send quit notifications quit_notify(); // Stop notifications stop_file_notify(GUI->pattern_notify); stop_file_notify(GUI->font_notify); stop_file_notify(GUI->modules_notify); stop_file_notify(GUI->commands_notify); stop_file_notify(GUI->env_notify); stop_file_notify(GUI->desktop_notify); stop_file_notify(GUI->filetype_notify); // Free application port if (GUI->appmsg_port) { DOpusAppMessage *amsg; RemPort(GUI->appmsg_port); while ((amsg=(DOpusAppMessage *)GetMsg(GUI->appmsg_port))) ReplyAppMessage(amsg); DeleteMsgPort(GUI->appmsg_port); GUI->appmsg_port=0; // Remove public semaphore RemSemaphore((struct SignalSemaphore *)&pub_semaphore); } // Flush IPC port IPC_Flush(&main_ipc); // Close all processes IPC_ListQuit(&GUI->lister_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->group_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->buttons_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->startmenu_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->process_list,&main_ipc,0,TRUE); IPC_ListQuit(&GUI->function_list,&main_ipc,0,TRUE); // Free buffers buffers_clear(0); // Remove all handlers RemFunctionTrap("*","#?"); // Free filetypes FreeMemHandle(GUI->filetype_memory); // Flush the filetype cache ClearFiletypeCache(); // Free lister toolbar FreeToolBar(GUI->toolbar); // Free menus and hotkeys CloseButtonBank(GUI->lister_menu); CloseButtonBank(GUI->hotkeys); // Free user menus CloseButtonBank(GUI->user_menu); FreeVec(GUI->user_menu_data); // Free backdrop list backdrop_free(GUI->backdrop); // Free icons if (GUI->lister_icon) FreeCachedDiskObject(GUI->lister_icon); if (GUI->button_icon) FreeCachedDiskObject(GUI->button_icon); // Free arrow image CloseImage(GUI->toolbar_arrow_image); #ifdef __amigaos3__ FreeVec(arrow_hi_data_chip); FreeVec(arrow_lo_data_chip); FreeVec(small_arrow_chip); FreeVec(big_arrow_chip); #ifndef USE_SCREENTITLE FreeVec(moon_big_data_chip); FreeVec(moon_small_data_chip); #endif FreeVec(command_arrow_chip); FreeVec(parent_arrow_chip); #endif // Free screen signal if (GUI->screen_signal!=-1) FreeSignal(GUI->screen_signal); // Delete notify port if (GUI->notify_port) DeleteMsgPort(GUI->notify_port); // Free position memory FreeMemHandle(GUI->position_memory); // Free command history Att_RemList(GUI->command_history,0); // Delete icon positioning port DeleteMsgPort(GUI->iconpos_port); // Free popup menu PopUpFreeHandle(GUI->desktop_menu); // Clear requester pattern hook in library if (GUI->flags2&GUIF2_BACKFILL_SET) SetReqBackFill(0,0); } // Free scripts FreeScripts(); // Free environment environment_free(environment); // Delete main message ports IPC_Flush(&main_ipc); DeleteMsgPort(main_ipc.command_port); DeleteMsgPort(main_ipc.reply_port); // Pause here for a couple of seconds to let everything clean up Delay(3*50); // Free global data FreeMemHandle(global_memory_pool); // Delete any temporary files delete_temp_files(0); // Free locale data free_locale_data(&locale); // Close input device if (InputBase) { #ifdef __amigaos4__ DropInterface((struct Interface *)IInput); #endif CloseDevice((struct IORequest *)&input_req); } // Close timer device if (TimerBase) { #ifdef __amigaos4__ DropInterface((struct Interface *)ITimer); #endif CloseDevice((struct IORequest *)&timer_req); } // Close console device if (ConsoleDevice) { #ifdef __amigaos4__ DropInterface((struct Interface *)IConsole); #endif CloseDevice((struct IORequest *)&console_req); } // Close libraries #ifdef __amigaos4__ DropInterface((struct Interface *)Imu); #endif CloseLibrary(muBase); #ifndef __amigaos3__ #ifdef __amigaos4__ DropInterface((struct Interface *)INewIcon); #endif CloseLibrary((struct Library *)NewIconBase); #endif #ifdef __amigaos4__ DropInterface((struct Interface *)ICyberGfx); #endif CloseLibrary(CyberGfxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IAmigaGuide); #endif CloseLibrary(AmigaGuideBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IDataTypes); #endif CloseLibrary(DataTypesBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IAsl); #endif CloseLibrary(AslBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IIcon); #endif CloseLibrary(IconBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IDiskfont); #endif CloseLibrary(DiskfontBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IWorkbench); #endif CloseLibrary(WorkbenchBase); #ifdef __amigaos4__ DropInterface((struct Interface *)ICommodities); #endif CloseLibrary(CxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IRexxSys); #endif CloseLibrary((struct Library *)RexxSysBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IUtility); #endif CloseLibrary(UtilityBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IGadTools); #endif CloseLibrary(GadToolsBase); #ifdef __amigaos4__ DropInterface((struct Interface *)ILayers); #endif CloseLibrary((struct Library *)LayersBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IGraphics); #endif CloseLibrary((struct Library *)GfxBase); #ifdef __amigaos4__ DropInterface((struct Interface *)IIntuition); #endif CloseLibrary((struct Library *)IntuitionBase); // Restore old current directory? if (old_current_dir) { UnLock(CurrentDir(old_current_dir)); } // Close the dopus5.library #ifdef __amigaos4__ DropInterface((struct Interface *)IDOpus); #endif CloseLibrary(DOpusBase); // Outahere! exit(0); }
short LIBFUNC L_Config_Filetypes( REG(a0, struct Screen *screen), REG(a1, IPCData *ipc), REG(a2, IPCData *owner_ipc), REG(d0, ULONG command_list), REG(a3, char *name)) { config_filetypes_data *data; IPCMessage *quit_msg=0; short undo_flag=0,pending_quit=0; short ret=0,fontsize; struct IBox pos; ConfigWindow dims; // Allocate data and memory handle if (!(data=AllocVec(sizeof(config_filetypes_data),MEMF_CLEAR)) || !(data->memory=NewMemHandle(4096,256,MEMF_CLEAR))) return 0; // Save pointers data->ipc=ipc; data->owner_ipc=owner_ipc; data->command_list=command_list; // Initialise data NewList(&data->list_list); InitListLock(&data->proc_list,0); // Fill in new window data->newwin.parent=screen; data->newwin.dims=&dims; data->newwin.title=GetString(locale,MSG_FILETYPES_TITLE); data->newwin.locale=locale; data->newwin.flags=WINDOW_SCREEN_PARENT|WINDOW_VISITOR|WINDOW_REQ_FILL|WINDOW_AUTO_KEYS|WINDOW_SIZE_BOTTOM; // Get default size dims=_config_filetypes_window; // Get saved position if (LoadPos("dopus/windows/filetypes",&pos,&fontsize)) { dims.char_dim.Width=0; dims.char_dim.Height=0; dims.fine_dim.Width=pos.Width; dims.fine_dim.Height=pos.Height; } // Open window and add objects if (!(data->window=OpenConfigWindow(&data->newwin)) || !(data->objlist=AddObjectList(data->window,_config_filetypes_objects))) { CloseConfigWindow(data->window); FreeMemHandle(data->memory); FreeVec(data); return 0; } // Set minimum size SetConfigWindowLimits(data->window,&_config_filetypes_window,0); // Read filetype list SetWindowBusy(data->window); filetype_read_list(data->memory,&data->list_list); // Build display list filetype_build_list(data); ClearWindowBusy(data->window); // Name to edit? if (name) filetype_edit_name(data,name); // Event loop FOREVER { struct IntuiMessage *msg; IPCMessage *imsg; int quit_flag=0; // Any IPC messages? while ((imsg=(IPCMessage *)GetMsg(ipc->command_port))) { // Look at command switch (imsg->command) { // Quit case IPC_QUIT: quit_flag=1; quit_msg=imsg; imsg=0; data->change=0; break; // Activate case IPC_ACTIVATE: if (data->window) { // Bring window to front WindowToFront(data->window); ActivateWindow(data->window); // Edit name supplied? if (imsg->data) filetype_edit_name(data,(char *)imsg->data); } break; // Process saying goodbye case IPC_GOODBYE: { FiletypeNode *node; // Handle goodbye if ((node=(FiletypeNode *)IPC_GetGoodbye(imsg))) { // Node no longer has an editor node->editor=0; } // All process gone and pending quit? if (pending_quit && (IsListEmpty(&data->proc_list.list))) { quit_flag=1; pending_quit=2; } } break; // Got a filetype back from the editor case FILETYPEEDIT_RETURN: if (filetype_receive_edit( data, (Cfg_Filetype *)imsg->flags, (FiletypeNode *)imsg->data)) { data->change=1; imsg->command=1; } else imsg->command=0; break; } // Reply message IPC_Reply(imsg); // Check quit flag if (quit_flag) break; } // Intuimessages if (data->window) { while ((msg=GetWindowMsg(data->window->UserPort))) { struct IntuiMessage msg_copy; UWORD id; // Copy message and reply msg_copy=*msg; ReplyWindowMsg(msg); if (pending_quit) continue; // Look at message switch (msg_copy.Class) { // Close window case IDCMP_CLOSEWINDOW: quit_flag=1; undo_flag=1; break; // Gadget case IDCMP_GADGETUP: id=((struct Gadget *)msg_copy.IAddress)->GadgetID; switch (id) { // Cancel case GAD_FILETYPES_CANCEL: undo_flag=1; // Use case GAD_FILETYPES_USE: quit_flag=1; break; // Filetype selected case GAD_FILETYPES_LIST: { Att_Node *node; // Enable buttons filetype_able_buttons(data,FALSE); // Get selection if (!(node=Att_FindNode(data->filetype_list,msg_copy.Code))) break; // Double-click? if (node==data->sel_filetype && DoubleClick( data->seconds,data->micros, msg_copy.Seconds,msg_copy.Micros)) { // Launch editor for this filetype filetype_edit(data,(FiletypeNode *)data->sel_filetype->data,0); } // New selection else { data->sel_filetype=node; data->seconds=msg_copy.Seconds; data->micros=msg_copy.Micros; } } break; // Add a new filetype case GAD_FILETYPES_DUPLICATE: if (!data->sel_filetype) break; case GAD_FILETYPES_ADD: { Cfg_FiletypeList *list; Cfg_Filetype *type=0; // Allocate a new filetype list if ((list=AllocMemH(data->memory,sizeof(Cfg_FiletypeList)))) { // Initialise list NewList(&list->filetype_list); // Copy existing filetype? if ((((struct Gadget *)msg_copy.IAddress)->GadgetID== GAD_FILETYPES_DUPLICATE)) { // Copy filetype type=CopyFiletype( ((FiletypeNode *)data->sel_filetype->data)->type, data->memory); } // Allocate a new filetype else if ((type=NewFiletype(data->memory))) { // Initialise name strcpy(type->type.name,GetString(locale,MSG_UNTITLED)); } // Get a filetype? if (type) { // Add filetype list to main list AddTail(&data->list_list,&list->node); // Add filetype to list AddTail(&list->filetype_list,&type->node); // Set list pointer type->list=list; list->flags=FTLISTF_CHANGED; } // Failed else FreeMemH(list); } // Got new filetype? if (type) { Att_Node *node; // Remove existing list SetGadgetChoices( data->objlist, GAD_FILETYPES_LIST, (APTR)~0); // Add entry for this filetype node=filetype_add_entry(data,type); // Handle new nodes filetype_new_node(data,node); } } break; // Edit filetype case GAD_FILETYPES_EDIT: // Valid selection? if (data->sel_filetype) { // Launch editor for this filetype filetype_edit(data,(FiletypeNode *)data->sel_filetype->data,0); } break; // Remove/Store case GAD_FILETYPES_REMOVE: case GAD_FILETYPES_STORE: // Valid selection? if (data->sel_filetype) { short ret; // Remove filetype if ((ret= filetype_remove( data, data->sel_filetype, (id==GAD_FILETYPES_STORE)))==1) { data->change=1; data->sel_filetype=0; } // Quit? else if (ret==-1) { quit_flag=1; } } break; } break; // Key press case IDCMP_RAWKEY: // Help? if (msg_copy.Code==0x5f && !(msg_copy.Qualifier&VALID_QUALIFIERS)) { // Set busy pointer SetWindowBusy(data->window); // Send help command IPC_Command(data->owner_ipc,IPC_HELP,(1<<31),"File Types",0,REPLY_NO_PORT); // Clear busy pointer ClearWindowBusy(data->window); } break; } // Check quit flag if (quit_flag) break; } } // Check quit flag if (quit_flag) { if (!pending_quit) { SetWindowBusy(data->window); if (!(IPC_ListQuit(&data->proc_list,0,!undo_flag,FALSE))) pending_quit=2; else pending_quit=1; } } // Set to break? if (pending_quit==2) { // Save filetypes? if (data->change && !undo_flag) { if (!(ret=filetype_save(data))) { // Abort save/quit ClearWindowBusy(data->window); pending_quit=0; continue; } } break; } // Wait for an event Wait(1<<ipc->command_port->mp_SigBit| ((data->window)?1<<data->window->UserPort->mp_SigBit:0)); } // Save window position if (data->window) { struct IBox pos; pos.Left=data->window->LeftEdge; pos.Top=data->window->TopEdge; pos.Width=data->window->Width-data->window->BorderLeft-data->window->BorderRight; pos.Height=data->window->Height-data->window->BorderTop-data->window->BorderBottom; SavePos("dopus/windows/filetypes",(struct IBox *)&pos,data->window->RPort->TxHeight); } // Close up CloseConfigWindow(data->window); // Free data Att_RemList(data->filetype_list,REMLIST_FREEDATA); FreeMemHandle(data->memory); FreeVec(data); // Reply quit message IPC_Reply(quit_msg); return ret; }
// Add an AppIcon from rexx long rexx_add_appicon(char *str,struct RexxMsg *msg) { char iconfile[256],menustem[80]; RexxAppThing *app; struct TagItem *tags; short key,menu_count=0,count; long base=0; APTR memory; // Allocate AppNode if (!(app=AllocVec(sizeof(RexxAppThing),MEMF_CLEAR))) return 0; // Allocate memory handle if (!(memory=NewMemHandle(0,0,MEMF_CLEAR))) { FreeVec(app); return 0; } // Set type app->node.ln_Type=REXXAPP_ICON; // Initialise position app->pos_x=NO_ICON_POSITION; app->pos_y=NO_ICON_POSITION; // Get port name rexx_parse_word(&str,app->port_name,sizeof(app->port_name)); // Get icon name rexx_parse_word(&str,app->icon_name,sizeof(app->icon_name)); // Get ID rexx_skip_space(&str); app->id=rexx_parse_number(&str,0,0); // Clear buffers iconfile[0]=0; menustem[0]=0; // Position set? rexx_skip_space(&str); while ((key=rexx_match_keyword(&str,pos_keys,0))!=-1) { // Position? if (key==APPARG_POS) { // Get position app->pos_x=rexx_parse_number(&str,1,NO_ICON_POSITION); app->pos_y=rexx_parse_number(&str,0,NO_ICON_POSITION); } // Quotes? else if (key==APPARG_QUOTES) app->flags|=RATF_QUOTES; // Info? else if (key==APPARG_INFO) app->flags|=RATF_INFO; // Snapshot else if (key==APPARG_SNAP) app->flags|=RATF_SNAP; // Close else if (key==APPARG_CLOSE) app->flags|=RATF_CLOSE; // Local else if (key==APPARG_LOCAL) app->flags|=RATF_LOCAL; // Locked else if (key==APPARG_LOCKED) app->flags|=RATF_LOCKED; // Icon else if (key==APPARG_ICON) { // Get filename rexx_parse_word(&str,iconfile,256); } // Menu else if (key==APPARG_MENU) { // Get menu stem if (rexx_parse_word(&str,menustem,30)) { // Check stem has a period if (menustem[0] && menustem[strlen(menustem)-1]!='.') strcat(menustem,"."); } } // Skip spaces rexx_skip_space(&str); } // Try and get icon if (iconfile[0]) app->icon=GetCachedDiskObject(iconfile,GCDOF_NOCACHE); // Failed? Get default if (!app->icon && !(app->icon=GetCachedDefDiskObject(WBTOOL|GCDOF_NOCACHE))) { // Failed completely FreeVec(app); return 0; } // Set icon position app->icon->do_CurrentX=app->pos_x-WBICONMAGIC_X; app->icon->do_CurrentY=app->pos_y-WBICONMAGIC_Y; SetIconFlags(app->icon,GetIconFlags(app->icon)&~ICONF_POSITION_OK); // Remap the icon (only if a local one) if (app->flags&RATF_LOCAL) RemapIcon(app->icon,GUI->screen_pointer,FALSE); // Menu items? if (menustem[0]) { char buffer[10]; // Get count rexx_get_var(msg,menustem,"COUNT",buffer,10); menu_count=atoi(buffer); // Get base if (rexx_get_var(msg,menustem,"BASE",buffer,10)) base=atoi(buffer); } // Number of tags needed count=7+menu_count; // Allocate tags if ((tags=AllocMemH(memory,sizeof(struct TagItem)*count))) { // Initialise tags tags[0].ti_Tag=DAE_SnapShot; tags[0].ti_Data=(app->flags&RATF_SNAP)?1:0; tags[1].ti_Tag=DAE_Info; tags[1].ti_Data=(app->flags&RATF_INFO)?1:0; tags[2].ti_Tag=DAE_Close; tags[2].ti_Data=(app->flags&RATF_CLOSE)?1:0; tags[3].ti_Tag=(app->flags&RATF_LOCAL)?DAE_Local:TAG_IGNORE; tags[3].ti_Data=1; tags[4].ti_Tag=DAE_Locked; tags[4].ti_Data=(app->flags&RATF_LOCKED)?1:0; tags[5].ti_Tag=DAE_MenuBase; tags[5].ti_Data=base; // Go through menus for (count=0;count<menu_count;count++) { char buffer[80]; // Build variable name lsprintf(iconfile,"%ld",count); // Get variable if (rexx_get_var(msg,menustem,iconfile,buffer,80)) { // Allocate buffer if ((tags[count+6].ti_Data=(ULONG)AllocMemH(memory,strlen(buffer)+1))) { // Copy name strcpy((char *)tags[count+6].ti_Data,buffer); // Set tag ID tags[count+6].ti_Tag=DAE_Menu; } else tags[count+6].ti_Tag=TAG_IGNORE; } // Skip this tag else tags[count+6].ti_Tag=TAG_IGNORE; } } // Add AppIcon app->app_thing= AddAppIconA( app->id, (ULONG)app, app->icon_name, GUI->rexx_app_port, 0, app->icon, tags); // Free memory FreeMemHandle(memory); // Failed? if (!app->app_thing) { // Failed if (app->flags&RATF_LOCAL) RemapIcon(app->icon,GUI->screen_pointer,FALSE); FreeCachedDiskObject(app->icon); FreeVec(app); return 0; } // Add to AppList lock_listlock(&GUI->rexx_apps,TRUE); AddTail(&GUI->rexx_apps.list,(struct Node *)app); unlock_listlock(&GUI->rexx_apps); return (long)app; }