home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / tapecove.lha / TapeCover / Source / tapecover.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  118.4 KB  |  2,845 lines

  1. #define ASL_V38_NAMES_ONLY
  2. #include <ctype.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <dos.h>
  6. #include <dos/dosextens.h>
  7. #include <exec/types.h>
  8. #include <graphics/displayinfo.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/asl.h>
  12. #include <libraries/gadtools.h>
  13. #include <libraries/locale.h>
  14. #include <prefs/printertxt.h>
  15. #include <clib/asl_protos.h>
  16. #include <clib/diskfont_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/icon_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/locale_protos.h>
  24. #include <clib/wb_protos.h>
  25.  
  26. #define CATCOMP_NUMBERS
  27. #include "tapecover_strings.h"
  28.  
  29. #define MAXFILELEN       FNSIZE
  30. #define MAXPATHLEN       FNSIZE
  31. #define MAXFONTLEN       30
  32. #define MAINGADWIDTH     15
  33. #define TAPELENGTH       1302
  34. #define TITLES_PER_SIDE  14
  35. #define TITLE_LENGTH     34
  36. #define LABELS           2
  37. #define LABEL_LENGTH     68
  38. #define BIGLABEL_LENGTH  46
  39. #define INFOS            3
  40. #define INFO_LENGTH      68
  41. #define MAIN_LINES       (TITLES_PER_SIDE + LABELS + INFOS + 3)
  42. #define BUF_LENGTH       (TITLES_PER_SIDE * TITLE_LENGTH * 2 + LABELS * LABEL_LENGTH + INFOS * INFO_LENGTH)
  43. #define TBUF_LENGTH      (TITLES_PER_SIDE * TITLE_LENGTH * 2)
  44. #define LBUF_LENGTH      (LABELS * LABEL_LENGTH)
  45. #define IBUF_LENGTH      (INFOS * INFO_LENGTH)
  46. #define TLBUF_LENGTH     (TBUF_LENGTH + LBUF_LENGTH)
  47. #define ASLLOADTPC       1
  48. #define ASLSAVETPC       2
  49. #define ASLSAVEEXP       3
  50. #define ASLPATH          4
  51. #define ASLLOADPREF      5
  52. #define ASLSAVEPREF      6
  53. #define PREFGADWIDTH    25
  54. #define PREFSTRGADWIDTH 40
  55. #define OWNSCR_GAD       0
  56. #define SCRNAMESTR_GAD   1
  57. #define SCRMODE_GAD      2
  58. #define SCRMODETXT_GAD   3
  59. #define ICONS_GAD        4
  60. #define FORMFEED_GAD     5
  61. #define CENTERED_GAD     6
  62. #define TAPEPATH_GAD     7
  63. #define TAPEPATHTXT_GAD  8
  64. #define EXPPATH_GAD      9
  65. #define EXPPATHTXT_GAD  10
  66. #define MASKFONT_GAD    11
  67. #define MASKFONTTXT_GAD 12
  68. #define GENFONT_GAD     13
  69. #define GENFONTTXT_GAD  14
  70.  
  71. char tcname_str[]     = "TapeCover",
  72.      tcpname_str[]    = "TapeCover.prefs",
  73.      cat_str[]        = "tapecover.catalog",
  74.      defpath_str[]    = "TapeCover:",
  75.      deftpath_str[]   = "Tapes",
  76.      defxpath_str[]   = "Export",
  77.      defscr_str[]     = "TAPECOVER.1",
  78.      defpub_str[]     = "Workbench",
  79.      tciname_str[]    = "Icons/def_project",
  80.      name_str[]       = "TapeCover V2.12",
  81.      tapehdr_str[]    = "TPCV1.0T",
  82.      confhdr_str[]    = "TPCV2.1C",
  83.      tpcext_str[]     = ".tpc",
  84.      ascext_str[]     = ".asc",
  85.      tpcwld_str[]     = "#?.tpc",
  86.      prefwld_str[]    = "#?.prefs",
  87.      prttxtname_str[] = "ENV:Sys/printer.prefs",
  88.      CMD_INIT[]       = "\x1b\x63\x1b#1",
  89.      CMD_FLEN[]       = "\x1b[36t",
  90.      CMD_LQ_ON[]      = "\x1b[2\"z",
  91.      CMD_NM[]         = "\x1b[0w",
  92.      CMD_CD_ON[]      = "\x1b[4w",
  93.      CMD_EL_ON[]      = "\x1b[2w",
  94.      CMD_EL_OFF[]     = "\x1b[1w",
  95.      CMD_UL_ON[]      = "\x1b[4m",
  96.      CMD_UL_OFF[]     = "\x1b[24m";
  97.  
  98. UWORD __chip waitPointer[] = 
  99.     { 0x0000, 0x0000,
  100.       0x0400, 0x07C0,
  101.       0x0000, 0x07C0,
  102.       0x0100, 0x0380,
  103.       0x0000, 0x07E0,
  104.       0x07C0, 0x1FF8,
  105.       0x1FF0, 0x3FEC,
  106.       0x3FF8, 0x7FDE,
  107.       0x3FF8, 0x7FBE,
  108.       0x7FFC, 0xFF7F,
  109.       0x7EFC, 0xFFFF,
  110.       0x7FFC, 0xFFFF,
  111.       0x3FF8, 0x7FFE,
  112.       0x3FF8, 0x7FFE,
  113.       0x1FF0, 0x3FFC,
  114.       0x07C0, 0x1FF8,
  115.       0x0000, 0x07E0,
  116.       0x0000, 0x0000 };
  117.  
  118. struct NewMenu newmenu[] =
  119.     {
  120.         { NM_TITLE, (STRPTR) MSG_PROJECT_MENU,        0, 0, 0, 0,},
  121.         {  NM_ITEM, (STRPTR) MSG_PROJECT_NEW,         0, 0, 0, 0,},
  122.         {  NM_ITEM, (STRPTR) MSG_PROJECT_OPEN,        0, 0, 0, 0,},
  123.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  124.         {  NM_ITEM, (STRPTR) MSG_PROJECT_SAVE,        0, 0, 0, 0,},
  125.         {  NM_ITEM, (STRPTR) MSG_PROJECT_SAVEAS,      0, 0, 0, 0,},
  126.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  127.         {  NM_ITEM, (STRPTR) MSG_PROJECT_PRINT,       0, 0, 0, 0,},
  128.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  129.         {  NM_ITEM, (STRPTR) MSG_PROJECT_EDIT,        0, 0, 0, 0,},
  130.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  131.         {  NM_ITEM, (STRPTR) MSG_PROJECT_PREFS,       0, 0, 0, 0,},
  132.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  133.         {  NM_ITEM, (STRPTR) MSG_PROJECT_ABOUT,       0, 0, 0, 0,},
  134.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  135.         {  NM_ITEM, (STRPTR) MSG_PROJECT_QUIT,        0, 0, 0, 0,},
  136.         { NM_TITLE, (STRPTR) MSG_MASK_MENU,           0, 0, 0, 0,},
  137.         {  NM_ITEM, (STRPTR) MSG_MASK_LABEL1BOLD,     0, CHECKIT | MENUTOGGLE, 0, 0,},
  138.         {  NM_ITEM, (STRPTR) MSG_MASK_LABEL2BOLD,     0, CHECKIT | MENUTOGGLE, 0, 0,},
  139.         {  NM_ITEM, NM_BARLABEL,                      0, 0, 0, 0,},
  140.         {  NM_ITEM, (STRPTR) MSG_MASK_CLEARSIDES,     0, 0, 0, 0,},
  141.         { NM_TITLE, (STRPTR) MSG_EXPORT_MENU,         0, 0, 0, 0,},
  142.         {  NM_ITEM, (STRPTR) MSG_EXPORT_ASCII,        0, 0, 0, 0,},
  143.         {   NM_END, NULL,                             0, 0, 0, 0,},
  144.     };
  145.  
  146. typedef struct TapeDat
  147.     { char    *sidea[TITLES_PER_SIDE],
  148.               *sideb[TITLES_PER_SIDE];
  149.       char    *label[LABELS];
  150.       char    *info[INFOS];
  151.       struct { unsigned int line1_bold : 1;
  152.                unsigned int line2_bold : 1;
  153.              } size;
  154.     };
  155.  
  156. typedef struct PrefDat
  157.     { char  scrname[100],
  158.             tapepath[MAXPATHLEN],
  159.             exppath[MAXPATHLEN],
  160.             fontname[2][MAXFONTLEN];
  161.       ULONG scrid,
  162.             scrwidth,
  163.             scrheight;
  164.       UWORD scrdepth,
  165.             scroscan,
  166.             fontysize[2];
  167.       WORD  winleft,
  168.             wintop,
  169.             aslwidth,
  170.             aslheight;
  171.       UBYTE fontstyle[2],
  172.             fontflags[2];
  173.       BOOL  ownscr,
  174.             scrascroll,
  175.             centered,
  176.             icons,
  177.             ff;
  178.     };
  179.  
  180. typedef struct IntDat
  181.     { struct LocaleInfo li;
  182.       struct Screen     *scr;
  183.       struct Window     *mainwin;
  184.       struct AppWindow  *mainappwin;
  185.       struct Menu       *mainmenu;
  186.       struct MsgPort    *mainmsgport;
  187.       struct TextAttr   maskfont,
  188.                         genfont;
  189.       struct TextFont   *tmaskfont,
  190.                         *tgenfont;
  191.       struct Gadget     *mainglist,
  192.                         *maingad;
  193.       APTR              *mainvi;
  194.       BPTR              prt;
  195.       char              winname[MAXFILELEN],
  196.                         scrname[MAXFILELEN],
  197.                         maskfontname[MAXFONTLEN],
  198.                         genfontname[MAXFONTLEN],
  199.                         mainpath[MAXPATHLEN],
  200.                         prefpath[MAXPATHLEN],
  201.                         loadpath[MAXPATHLEN],
  202.                         file[MAXFILELEN],
  203.                         expfile[MAXFILELEN],
  204.                         preffile[MAXFILELEN];
  205.       BOOL              firstload,
  206.                         filesaved;
  207.     };
  208.  
  209. char           tdat_buf[BUF_LENGTH];
  210. struct TapeDat tdat;
  211. struct PrefDat prefs,
  212.                newprefs;
  213. struct IntDat  idat;
  214. struct Library *LocaleBase,
  215.                *DiskfontBase,
  216.                *IntuitionBase,
  217.                *GfxBase,
  218.                *IconBase,
  219.                *GadToolsBase,
  220.                *AslBase;
  221.  
  222. UWORD          pens[] = { 0xFFFF };
  223.  
  224. STRPTR __asm GetString(register __a0 struct LocaleInfo *li,
  225.                        register __d0 LONG stringNum);
  226.  
  227. void LocalizeNewMenu(struct LocaleInfo *li, struct NewMenu *nm)
  228.     {
  229.     UWORD i;
  230.  
  231.     for (i = 0; nm[i].nm_Type != NM_END; i++)
  232.         {
  233.         if (nm[i].nm_Type == NM_TITLE)
  234.             nm[i].nm_Label = GetString(li, (LONG)nm[i].nm_Label);
  235.         else if (nm[i].nm_Label != NM_BARLABEL)
  236.             {
  237.             nm[i].nm_CommKey = GetString(li, (LONG)nm[i].nm_Label);
  238.             nm[i].nm_Label = nm[i].nm_CommKey+2;
  239.             if (nm[i].nm_CommKey[0] == ' ')
  240.                 nm[i].nm_CommKey = NULL;
  241.             }
  242.         }
  243.     }
  244.  
  245. int getgadkey(char *gadtext)
  246.     {
  247.     char *gadchar;
  248.     int   intchar;
  249.  
  250.     gadchar = strchr(gadtext, '_');
  251.     if (gadchar)
  252.         {
  253.         intchar = gadchar[1];
  254.         intchar = tolower(intchar);
  255.         }
  256.     return intchar;
  257.     }
  258.  
  259. void busy(struct Window *wp)
  260.     {
  261.     if (IntuitionBase->lib_Version < 39)
  262.         SetPointer(wp, waitPointer, 16, 16, -6, 0);
  263.     else
  264.         SetWindowPointer(wp, WA_BusyPointer, TRUE, TAG_END);
  265.     ModifyIDCMP(wp, IDCMP_REFRESHWINDOW);
  266. /*
  267.     OffMenu(wp, FULLMENUNUM(0, NOITEM, NOSUB));
  268.     OffMenu(wp, FULLMENUNUM(1, NOITEM, NOSUB));
  269.     OffMenu(wp, FULLMENUNUM(2, NOITEM, NOSUB));
  270. */
  271.     }
  272.  
  273. void unbusy(struct Window *wp)
  274.     {
  275.     ModifyIDCMP(wp, IDCMP_CLOSEWINDOW | IDCMP_MENUPICK |
  276.                     IDCMP_RAWKEY | IDCMP_VANILLAKEY |
  277.                     IDCMP_GADGETUP | IDCMP_REFRESHWINDOW);
  278. /*
  279.     OnMenu(wp, FULLMENUNUM(2, NOITEM, NOSUB));
  280.     OnMenu(wp, FULLMENUNUM(1, NOITEM, NOSUB));
  281.     OnMenu(wp, FULLMENUNUM(0, NOITEM, NOSUB));
  282. */
  283.     if (IntuitionBase->lib_Version < 39)
  284.         ClearPointer(wp);
  285.     else
  286.         SetWindowPointer(wp, WA_Pointer, NULL, TAG_END);
  287.     }
  288.  
  289. void fehler(struct IntDat *idat, LONG error_num, char *error_text)
  290.     {
  291.     struct EasyStruct ereq;
  292.     char              errorstr[10 + 40 + FNSIZE + 5];
  293.  
  294.     ereq.es_StructSize = sizeof(struct EasyStruct);
  295.     ereq.es_Flags = 0;
  296.     ereq.es_Title = name_str;
  297.     ereq.es_GadgetFormat = GetString(&idat->li, MSG_ERROR_RGAD);
  298.     strcpy(errorstr, GetString(&idat->li, MSG_ERROR));
  299.     strcat(errorstr, "\n");
  300.     strcat(errorstr, GetString(&idat->li, error_num));
  301.     strcat(errorstr, "\n");
  302.     if (error_text)
  303.         {
  304.         strcat(errorstr, "\"");
  305.         strcat(errorstr, error_text);
  306.         strcat(errorstr, "\"");
  307.         }
  308.     ereq.es_TextFormat = errorstr;
  309.     EasyRequest(idat->mainwin, &ereq, NULL);
  310.     }
  311.  
  312. #include "tapecover_io.c"
  313.  
  314. void save(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat);
  315. void save_as(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat);
  316.  
  317. BOOL open_mainwin(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  318.     {
  319.     struct NewGadget ng;
  320.     BOOL             success = FALSE;
  321.     WORD             wintop,
  322.                      winleftedge,
  323.                      wintopedge,
  324.                      winwidth,
  325.                      winheight,
  326.                      xsize,
  327.                      ysize,
  328.                      hbor;
  329.     FLOAT            gaddis;
  330.     ULONG            appwinid = 1,
  331.                      userdata = 0;
  332.  
  333.     xsize = idat->tgenfont->tf_XSize;
  334.     ysize = idat->tgenfont->tf_YSize;
  335.     wintop = idat->scr->WBorTop + idat->scr->Font->ta_YSize + 1;
  336.     hbor = idat->scr->WBorLeft + idat->scr->WBorRight;
  337.     winwidth = hbor + (INFO_LENGTH - 1) * idat->tmaskfont->tf_XSize + 40;
  338.     idat->maingad = CreateContext(&idat->mainglist);
  339.     ng.ng_TextAttr = &idat->genfont;
  340.     ng.ng_VisualInfo = idat->mainvi;
  341.     ng.ng_Width = 10 + MAINGADWIDTH * xsize;
  342.     if (hbor + 40 + (4 * ng.ng_Width) > winwidth)
  343.         winwidth = hbor + 40 + (4 * ng.ng_Width);
  344.     gaddis = (winwidth - 4 * ng.ng_Width - hbor) / 5;
  345.     ng.ng_Height = 5 + ysize;
  346.     ng.ng_LeftEdge = idat->scr->WBorLeft + gaddis;
  347.     ng.ng_TopEdge = wintop + MAIN_LINES * (idat->tmaskfont->tf_YSize + 6) + 25;
  348.     ng.ng_GadgetText = GetString(&idat->li, MSG_NEW_GAD);
  349.     ng.ng_GadgetID = MSG_NEW_GAD;
  350.     ng.ng_Flags = 0;
  351.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  352.                                                                   TAG_END);
  353.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  354.     ng.ng_GadgetText = GetString(&idat->li, MSG_OPEN_GAD);
  355.     ng.ng_GadgetID = MSG_OPEN_GAD;
  356.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  357.                                                                   TAG_END);
  358.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  359.     ng.ng_GadgetText = GetString(&idat->li, MSG_SAVE_GAD);
  360.     ng.ng_GadgetID = MSG_SAVE_GAD;
  361.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  362.                                                                   TAG_END);
  363.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  364.     ng.ng_GadgetText = GetString(&idat->li, MSG_SAVEAS_GAD);
  365.     ng.ng_GadgetID = MSG_SAVEAS_GAD;
  366.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  367.                                                                   TAG_END);
  368.     ng.ng_TopEdge += ng.ng_Height + 5;
  369.     ng.ng_LeftEdge = idat->scr->WBorLeft + gaddis;
  370.     ng.ng_GadgetText = GetString(&idat->li, MSG_EDIT_GAD);
  371.     ng.ng_GadgetID = MSG_EDIT_GAD;
  372.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  373.                                                                   TAG_END);
  374.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  375.     ng.ng_GadgetText = GetString(&idat->li, MSG_MPRINT_GAD);
  376.     ng.ng_GadgetID = MSG_MPRINT_GAD;
  377.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  378.                                                                   TAG_END);
  379.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  380.     ng.ng_GadgetText = GetString(&idat->li, MSG_PREFS_GAD);
  381.     ng.ng_GadgetID = MSG_PREFS_GAD;
  382.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  383.                                                                   TAG_END);
  384.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  385.     ng.ng_GadgetText = GetString(&idat->li, MSG_QUIT_GAD);
  386.     ng.ng_GadgetID = MSG_QUIT_GAD;
  387.     idat->maingad = CreateGadget(BUTTON_KIND, idat->maingad, &ng, GT_Underscore, '_',
  388.                                                                   TAG_END);
  389.     winheight = wintop + idat->scr->WBorBottom +
  390.                 (MAIN_LINES * (idat->tmaskfont->tf_YSize + 6)) +
  391.                 (2 * ng.ng_Height) + 35;
  392.     if ((winwidth <= idat->scr->Width) && (winheight <= idat->scr->Height))
  393.         {
  394.         if (idat->maingad)
  395.             {
  396.             if (idat->mainmsgport = CreateMsgPort())
  397.                 {
  398.                 if (strlen(idat->file) == 0)
  399.                     strcpy(idat->winname, GetString(&idat->li, MSG_UNNAMED));
  400.                 else
  401.                     strcpy(idat->winname, idat->file);
  402.                 winleftedge = (idat->scr->Width - winwidth) / 2;
  403.                 wintopedge = (idat->scr->Height - winheight) / 2;
  404.                 if (!prefs->centered && ((prefs->winleft + winwidth) <= idat->scr->Width))
  405.                     winleftedge = prefs->winleft;
  406.                 if (!prefs->centered && ((prefs->wintop + winheight) <= idat->scr->Height))
  407.                     wintopedge = prefs->wintop;
  408.                 if (idat->mainwin = OpenWindowTags(NULL,
  409.                                 WA_Left,            winleftedge,
  410.                                 WA_Top,             wintopedge,
  411.                                 WA_Width,           winwidth,
  412.                                 WA_Height,          winheight,
  413.                                 WA_Gadgets,         idat->mainglist,
  414.                                 WA_DragBar,         TRUE,
  415.                                 WA_CloseGadget,     TRUE,
  416.                                 WA_DepthGadget,     TRUE,
  417.                                 WA_Activate,        TRUE,
  418.                                 WA_SmartRefresh,    TRUE,
  419.                                 WA_IDCMP,           IDCMP_CLOSEWINDOW | IDCMP_MENUPICK |
  420.                                                     IDCMP_RAWKEY | IDCMP_VANILLAKEY |
  421.                                                     IDCMP_GADGETUP | IDCMP_REFRESHWINDOW,
  422.                                 WA_Title,           idat->winname,
  423.                                 WA_PubScreen,       idat->scr,
  424.                                 WA_ScreenTitle,     name_str,
  425.                                 WA_NewLookMenus,    TRUE,
  426.                                 TAG_END))
  427.                     {
  428.                     GT_RefreshWindow(idat->mainwin, NULL);
  429.                     SetFont(idat->mainwin->RPort, idat->tmaskfont);
  430.                     if (idat->mainmenu = CreateMenus(newmenu, GTMN_NewLookMenus, TRUE,
  431.                                                               GTMN_FullMenu, TRUE,
  432.                                                               TAG_END))
  433.                         {
  434.                         if (LayoutMenus(idat->mainmenu, idat->mainvi,
  435.                                         GTMN_NewLookMenus, TRUE,
  436.                                         TAG_END))
  437.                             {
  438.                             if (SetMenuStrip(idat->mainwin, idat->mainmenu))
  439.                                 {
  440.                                 if (idat->mainappwin = AddAppWindow(appwinid, userdata, idat->mainwin,
  441.                                                                     idat->mainmsgport, NULL))
  442.                                     {
  443.                                     success = TRUE;
  444.                                     ScreenToFront(idat->scr);
  445.                                     write_mask(idat);
  446.                                     write_dat(idat, tdat);
  447.                                     }
  448.                                 else
  449.                                     fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_AWIN_ERROR));
  450.                                 }
  451.                             else
  452.                                 fehler(idat, MSG_SMENU_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  453.                             }
  454.                         else
  455.                             fehler(idat, MSG_LMENU_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  456.                         }
  457.                     else
  458.                         fehler(idat, MSG_MENU_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  459.                     }
  460.                 else
  461.                     fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  462.                 }
  463.             else
  464.                 fehler(idat, MSG_MSGPORT_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  465.             }
  466.         else
  467.             fehler(idat, MSG_GAD_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  468.         }
  469.     else
  470.         fehler(idat, MSG_WINSIZE_ERROR, GetString(&idat->li, MSG_MWIN_ERROR));
  471.     return success;
  472.     }
  473.  
  474. void close_mainwin(struct IntDat *idat)
  475.     {
  476.     if (idat->mainappwin)
  477.         {
  478.         RemoveAppWindow(idat->mainappwin);
  479.         idat->mainappwin = NULL;
  480.         }
  481.     if (idat->mainmenu)
  482.         {
  483.         ClearMenuStrip(idat->mainwin);
  484.         FreeMenus(idat->mainmenu);
  485.         idat->mainmenu = NULL;
  486.         }
  487.     if (idat->mainwin)
  488.         {
  489.         CloseWindow(idat->mainwin);
  490.         idat->mainwin = NULL;
  491.         }
  492.     if (idat->mainmsgport)
  493.         {
  494.         DeleteMsgPort(idat->mainmsgport);
  495.         idat->mainmsgport = NULL;
  496.         }
  497.     if (idat->mainglist)
  498.         {
  499.         FreeGadgets(idat->mainglist);
  500.         idat->mainglist = NULL;
  501.         }
  502.     }
  503.  
  504. BOOL ask_changed(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  505.     {
  506.     struct EasyStruct ereq;
  507.     char              askstr[MAXFILELEN + 44];
  508.     LONG              answer;
  509.     BOOL              doit = FALSE;
  510.  
  511.     ereq.es_StructSize = sizeof(struct EasyStruct);
  512.     ereq.es_Flags = 0;
  513.     ereq.es_Title = name_str;
  514.     strcpy(askstr, "\"");
  515.     if (strlen(idat->file) == 0)
  516.         strcat(askstr, GetString(&idat->li, MSG_UNNAMED));
  517.     else
  518.         strcat(askstr, idat->file);
  519.     strcat(askstr, "\"\n");
  520.     strcat(askstr, GetString(&idat->li, MSG_CHANGED));
  521.     ereq.es_TextFormat = askstr;
  522.     ereq.es_GadgetFormat = GetString(&idat->li, MSG_CHANGED_RGAD);
  523.     answer = EasyRequest(idat->mainwin, &ereq, NULL);
  524.     switch (answer) {
  525.         case 1:
  526.             if (strlen(idat->file) == 0)
  527.                 save_as(idat, prefs, tdat);
  528.             else
  529.                 save(idat, prefs, tdat);
  530.             doit = TRUE;
  531.             break;
  532.         case 2:
  533.             doit = TRUE;
  534.             break;
  535.         default:
  536.             break;
  537.         }
  538.     return doit;
  539.     }
  540.  
  541. BOOL ask_overwrite(struct IntDat *idat, char *e_file)
  542.     {
  543.     struct EasyStruct ereq;
  544.     char              askstr[MAXFILELEN + 42];
  545.     LONG              answer;
  546.     BOOL              doit = TRUE;
  547.  
  548.     ereq.es_StructSize = sizeof(struct EasyStruct);
  549.     ereq.es_Flags = 0;
  550.     ereq.es_Title = name_str;
  551.     strcpy(askstr, "\"");
  552.     strcat(askstr, e_file);
  553.     strcat(askstr, "\"\n");
  554.     strcat(askstr, GetString(&idat->li, MSG_OVERWRITE_QUEST));
  555.     ereq.es_TextFormat = askstr;
  556.     ereq.es_GadgetFormat = GetString(&idat->li, MSG_OVERWRITE_RGAD);
  557.     answer = EasyRequest(idat->mainwin, &ereq, NULL);
  558.     switch (answer) {
  559.         case 1:
  560.             doit = FALSE;
  561.             break;
  562.         default:
  563.             break;
  564.         }
  565.     return doit;
  566.     }
  567.  
  568. void info(struct IntDat *idat)
  569.     {
  570.     #define MAX_INFO_TXT 40
  571.     #define INFO_LINES   10
  572.  
  573.     struct Window       *info_window;
  574.     struct IntuiMessage *msg;
  575.     struct NewGadget    ng;
  576.     struct Gadget       *glist, *gad;
  577.     BOOL                done = FALSE;
  578.     WORD                xsize,
  579.                         ysize,
  580.                         winwidth,
  581.                         winheight,
  582.                         wintop,
  583.                         hbor;
  584.  
  585.     xsize = idat->tgenfont->tf_XSize;
  586.     ysize = idat->tgenfont->tf_YSize;
  587.     wintop = idat->scr->WBorTop + idat->scr->Font->ta_YSize + 1 + 15;
  588.     hbor = idat->scr->WBorLeft + idat->scr->WBorRight;
  589.     winwidth = hbor + 30 + MAX_INFO_TXT * xsize;
  590.     gad = CreateContext(&glist);
  591.     ng.ng_TextAttr = &idat->genfont;
  592.     ng.ng_VisualInfo = idat->mainvi;
  593.     ng.ng_Width = 20 + (strlen(GetString(&idat->li, MSG_OK_GAD)) - 1) * xsize;
  594.     if (hbor + 10 + ng.ng_Width > winwidth)
  595.         winwidth = hbor + 10 + ng.ng_Width;
  596.     ng.ng_Height = 5 + ysize;
  597.     ng.ng_LeftEdge = (winwidth - ng.ng_Width) / 2;
  598.     ng.ng_TopEdge = wintop + (ysize + 2) * INFO_LINES + 15;
  599.     ng.ng_GadgetText = GetString(&idat->li, MSG_OK_GAD);
  600.     ng.ng_GadgetID = 1;
  601.     ng.ng_Flags = 0;
  602.     gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_',
  603.                                               TAG_END);
  604.     winheight = wintop + idat->scr->WBorBottom +
  605.                 INFO_LINES * (ysize + 2) + ng.ng_Height +
  606.                 20;
  607.     if (gad)
  608.         {
  609.         if (info_window = OpenWindowTags(NULL,
  610.                         WA_Left,            (idat->scr->Width - winwidth) / 2,
  611.                         WA_Top,             (idat->scr->Height - winheight) /2,
  612.                         WA_Width,           winwidth,
  613.                         WA_Height,          winheight,
  614.                         WA_Gadgets,         glist,
  615.                         WA_DragBar,         TRUE,
  616.                         WA_CloseGadget,     TRUE,
  617.                         WA_DepthGadget,     TRUE,
  618.                         WA_Activate,        TRUE,
  619.                         WA_SmartRefresh,    TRUE,
  620.                         WA_IDCMP,           IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY |
  621.                                             IDCMP_GADGETUP | IDCMP_REFRESHWINDOW,
  622.                         WA_Title,           GetString(&idat->li, MSG_INFO_WIN),
  623.                         WA_PubScreen,       idat->scr,
  624.                         WA_ScreenTitle,     name_str,
  625.                         TAG_END))
  626.             {
  627.             busy(idat->mainwin);
  628.             GT_RefreshWindow(info_window, NULL);
  629.             SetFont(info_window->RPort, idat->tgenfont);
  630.             box_bor(info_window, info_window->BorderLeft + 10, wintop - 10,
  631.                     winwidth - info_window->BorderRight - 10,
  632.                     wintop + INFO_LINES * (ysize+ 2) + 5);
  633.             write_ctext3d(info_window, wintop, 1, 3,
  634.                           name_str);
  635.             write_ctext3d(info_window, wintop + ysize + 2, 1, 3,
  636.                           GetString(&idat->li, MSG_RELEASE));
  637.             write_ctext3d(info_window, wintop + (ysize + 2) * 2, 1, 2,
  638.                           GetString(&idat->li, MSG_COPYRIGHT));
  639.             write_ctext3d(info_window, wintop + (ysize + 2) * 3, 2, 1,
  640.                           GetString(&idat->li, MSG_AUTHOR));
  641.             write_ctext3d(info_window, wintop + (ysize + 2) * 4, 2, 1,
  642.                           GetString(&idat->li, MSG_STREET));
  643.             write_ctext3d(info_window, wintop + (ysize + 2) * 5, 2, 1,
  644.                           GetString(&idat->li, MSG_CITY));
  645.             write_ctext3d(info_window, wintop + (ysize + 2) * 6, 2, 1,
  646.                           GetString(&idat->li, MSG_COUNTRY));
  647.             write_ctext3d(info_window, wintop + (ysize + 2) * 7, 2, 1,
  648.                           GetString(&idat->li, MSG_INT_PHONE));
  649.             write_ctext3d(info_window, wintop + (ysize + 2) * 8, 2, 1,
  650.                           GetString(&idat->li, MSG_EMAIL1));
  651.             write_ctext3d(info_window, wintop + (ysize + 2) * 9, 2, 1,
  652.                           GetString(&idat->li, MSG_EMAIL2));
  653.             while (! done)
  654.                 {
  655.                 WaitPort(info_window->UserPort);
  656.                 msg = (struct IntuiMessage *)GT_GetIMsg(info_window->UserPort);
  657.                 if (msg->Class == IDCMP_REFRESHWINDOW)
  658.                     {
  659.                     GT_BeginRefresh(info_window);
  660.                     box_bor(info_window, info_window->BorderLeft + 10, wintop - 10,
  661.                             winwidth - info_window->BorderRight - 10,
  662.                             wintop + INFO_LINES * (ysize+ 2) + 5);
  663.                     write_ctext3d(info_window, wintop, 1, 3,
  664.                                   name_str);
  665.                     write_ctext3d(info_window, wintop + ysize + 2, 1, 3,
  666.                                   GetString(&idat->li, MSG_RELEASE));
  667.                     write_ctext3d(info_window, wintop + (ysize + 2) * 2, 1, 2,
  668.                                   GetString(&idat->li, MSG_COPYRIGHT));
  669.                     write_ctext3d(info_window, wintop + (ysize + 2) * 3, 2, 1,
  670.                                   GetString(&idat->li, MSG_AUTHOR));
  671.                     write_ctext3d(info_window, wintop + (ysize + 2) * 4, 2, 1,
  672.                                   GetString(&idat->li, MSG_STREET));
  673.                     write_ctext3d(info_window, wintop + (ysize + 2) * 5, 2, 1,
  674.                                   GetString(&idat->li, MSG_CITY));
  675.                     write_ctext3d(info_window, wintop + (ysize + 2) * 6, 2, 1,
  676.                                   GetString(&idat->li, MSG_COUNTRY));
  677.                     write_ctext3d(info_window, wintop + (ysize + 2) * 7, 2, 1,
  678.                                   GetString(&idat->li, MSG_INT_PHONE));
  679.                     write_ctext3d(info_window, wintop + (ysize + 2) * 8, 2, 1,
  680.                                   GetString(&idat->li, MSG_EMAIL1));
  681.                     write_ctext3d(info_window, wintop + (ysize + 2) * 9, 2, 1,
  682.                                   GetString(&idat->li, MSG_EMAIL2));
  683.                     GT_EndRefresh(info_window, TRUE);
  684.                     }
  685.                  if (msg->Class == IDCMP_CLOSEWINDOW ||
  686.                      msg->Class == IDCMP_GADGETUP ||
  687.                      msg->Class == IDCMP_VANILLAKEY)
  688.                      done = TRUE;
  689.                  GT_ReplyIMsg(msg);
  690.                  }
  691.              unbusy(idat->mainwin);
  692.              CloseWindow(info_window);
  693.              }
  694.         else
  695.             fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_INFO_WIN));
  696.         FreeGadgets(glist);
  697.         }
  698.     else
  699.         fehler(idat, MSG_GAD_ERROR, GetString(&idat->li, MSG_INFO_WIN));
  700.     }
  701.  
  702. void load_start(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  703.     {
  704.     BPTR            datei;
  705.     char            header[8],
  706.                     buffer[BUF_LENGTH + 2];
  707.     UBYTE           flags;
  708.     LONG            length;
  709.  
  710.     datei = Open(idat->loadpath, MODE_OLDFILE);
  711.     if (datei)
  712.         {
  713.         length = Read(datei, header, 8);
  714.         if (0 == memcmp(header, tapehdr_str, 8))
  715.             {
  716.             length += Read(datei, buffer, BUF_LENGTH + 2);
  717.             if (length == TAPELENGTH)
  718.                 {
  719.                 memcpy(tdat->sidea[0], buffer, BUF_LENGTH);
  720.                 strmid(idat->loadpath, prefs->tapepath, 1, strlen(idat->loadpath)
  721.                        - strlen(FilePart(idat->loadpath)));
  722.                 strcpy(idat->file, FilePart(idat->loadpath));
  723.                 strcpy(idat->expfile, idat->file);
  724.                 flags = buffer[BUF_LENGTH];
  725.                 tdat->size.line2_bold = flags & 1;
  726.                 flags >>= 1;
  727.                 tdat->size.line1_bold = flags & 1;
  728.                 if (tdat->size.line1_bold)
  729.                     newmenu[17].nm_Flags |= CHECKED;
  730.                 else
  731.                     newmenu[17].nm_Flags &= ~CHECKED;
  732.                 if (tdat->size.line2_bold)
  733.                     newmenu[18].nm_Flags |= CHECKED;
  734.                 else
  735.                     newmenu[18].nm_Flags &= ~CHECKED;
  736.                 idat->filesaved = TRUE;
  737.                 }
  738.             else
  739.                 fehler(idat, MSG_LOAD_ERROR, idat->loadpath);
  740.             }
  741.         else
  742.             fehler(idat, MSG_DATASET_ERROR, idat->loadpath);
  743.         }
  744.     else
  745.         fehler(idat, MSG_OPEN_ERROR, idat->loadpath);
  746.     Close(datei);
  747.     }
  748.  
  749. void load_direct(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  750.     {
  751.     struct MenuItem *item;
  752.     BPTR            datei;
  753.     char            header[8],
  754.                     buffer[BUF_LENGTH + 2];
  755.     UBYTE           flags;
  756.     LONG            length;
  757.     BOOL            doit = TRUE;
  758.  
  759.     busy(idat->mainwin);
  760.     if (! idat->filesaved)
  761.         doit = ask_changed(idat, prefs, tdat);
  762.     if (doit)
  763.         {
  764.         datei = Open(idat->loadpath, MODE_OLDFILE);
  765.         if (datei)
  766.             {
  767.             length = Read(datei, header, 8);
  768.             if (0 == memcmp(header, tapehdr_str, 8))
  769.                 {
  770.                 length += Read(datei, buffer, BUF_LENGTH + 2);
  771.                 if (length == TAPELENGTH)
  772.                     {
  773.                     memcpy(tdat->sidea[0], buffer, BUF_LENGTH);
  774.                     strcpy(idat->file, FilePart(idat->loadpath));
  775.                     strcpy(idat->expfile, idat->file);
  776.                     flags = buffer[BUF_LENGTH];
  777.                     tdat->size.line2_bold = flags & 1;
  778.                     flags >>= 1;
  779.                     tdat->size.line1_bold = flags & 1;
  780.                     item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 0, NOSUB));
  781.                     if (tdat->size.line1_bold)
  782.                         {
  783.                         if (item)
  784.                             item->Flags |= CHECKED;
  785.                         newmenu[17].nm_Flags |= CHECKED;
  786.                         }
  787.                     else
  788.                         {
  789.                         if (item)
  790.                             item->Flags &= ~CHECKED;
  791.                         newmenu[17].nm_Flags &= ~CHECKED;
  792.                         }
  793.                     item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 1, NOSUB));
  794.                     if (tdat->size.line2_bold)
  795.                         {
  796.                         if (item)
  797.                             item->Flags |= CHECKED;
  798.                         newmenu[18].nm_Flags |= CHECKED;
  799.                         }
  800.                     else
  801.                         {
  802.                         if (item)
  803.                             item->Flags &= ~CHECKED;
  804.                         newmenu[18].nm_Flags &= ~CHECKED;
  805.                         }
  806.                     write_dat(idat, tdat);
  807.                     SetWindowTitles(idat->mainwin, idat->file, (UBYTE *)-1);
  808.                     idat->filesaved = TRUE;
  809.                     }
  810.                 else
  811.                     fehler(idat, MSG_LOAD_ERROR, idat->loadpath);
  812.                 }
  813.             else
  814.                 fehler(idat, MSG_DATASET_ERROR, idat->loadpath);
  815.             }
  816.         else
  817.             fehler(idat, MSG_OPEN_ERROR, idat->loadpath);
  818.         Close(datei);
  819.         }
  820.     unbusy(idat->mainwin);
  821.     }
  822.  
  823. void load(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  824.     {
  825.     struct MenuItem *item;
  826.     BPTR            datei;
  827.     char            bpath[MAXPATHLEN],
  828.                     bfile[MAXFILELEN],
  829.                     header[8],
  830.                     buffer[BUF_LENGTH + 2];
  831.     UBYTE           flags;
  832.     LONG            length;
  833.     BOOL            doit = TRUE;
  834.  
  835.     busy(idat->mainwin);
  836.     if (! idat->filesaved)
  837.         doit = ask_changed(idat, prefs, tdat);
  838.     if (doit)
  839.         {
  840.         strcpy(bpath, prefs->tapepath);
  841.         strcpy(bfile, idat->file);
  842.         if (asl_fr(idat, prefs, idat->mainwin, ASLLOADTPC, bpath, bfile))
  843.             {
  844.             if (AddPart(bpath, bfile, MAXPATHLEN))
  845.                 {
  846.                 datei = Open(bpath, MODE_OLDFILE);
  847.                 if (datei)
  848.                     {
  849.                     length = Read(datei, header, 8);
  850.                     if (0 == memcmp(header, tapehdr_str, 8))
  851.                         {
  852.                         length += Read(datei, buffer, BUF_LENGTH + 2);
  853.                         if (length == TAPELENGTH)
  854.                             {
  855.                             memcpy(tdat->sidea[0], buffer, BUF_LENGTH);
  856.                             strmid(bpath, prefs->tapepath, 1, strlen(bpath) - strlen(bfile));
  857.                             strcpy(idat->file, bfile);
  858.                             strcpy(idat->expfile, bfile);
  859.                             flags = buffer[BUF_LENGTH];
  860.                             tdat->size.line2_bold = flags & 1;
  861.                             flags >>= 1;
  862.                             tdat->size.line1_bold = flags & 1;
  863.                             item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 0, NOSUB));
  864.                             if (tdat->size.line1_bold)
  865.                                 {
  866.                                 if (item)
  867.                                     item->Flags |= CHECKED;
  868.                                 newmenu[17].nm_Flags |= CHECKED;
  869.                                 }
  870.                             else
  871.                                 {
  872.                                 if (item)
  873.                                     item->Flags &= ~CHECKED;
  874.                                 newmenu[17].nm_Flags &= ~CHECKED;
  875.                                 }
  876.                             item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 1, NOSUB));
  877.                             if (tdat->size.line2_bold)
  878.                                 {
  879.                                 if (item)
  880.                                     item->Flags |= CHECKED;
  881.                                 newmenu[18].nm_Flags |= CHECKED;
  882.                                 }
  883.                             else
  884.                                 {
  885.                                 if (item)
  886.                                     item->Flags &= ~CHECKED;
  887.                                 newmenu[18].nm_Flags &= ~CHECKED;
  888.                                 }
  889.                             write_dat(idat, tdat);
  890.                             SetWindowTitles(idat->mainwin, idat->file, (UBYTE *)-1);
  891.                             idat->filesaved = TRUE;
  892.                             }
  893.                         else
  894.                             fehler(idat, MSG_LOAD_ERROR, bpath);
  895.                         }
  896.                     else
  897.                         fehler(idat, MSG_DATASET_ERROR, bpath);
  898.                     }
  899.                 else
  900.                     fehler(idat, MSG_OPEN_ERROR, bpath);
  901.                 Close(datei);
  902.                 }
  903.             else
  904.                 fehler(idat, MSG_PATH_ERROR, bpath);
  905.             }
  906.         }
  907.     unbusy(idat->mainwin);
  908.     }
  909.  
  910. void add_icon(struct IntDat *idat, char *p_file)
  911.     {
  912.     struct DiskObject *TC_DiskObject;
  913.     char              prog_path[MAXPATHLEN],
  914.                       *olddeftool,
  915.                       **oldtooltypes;
  916.     UBYTE             *newtooltypes[] =
  917.                           {
  918.                           "FILETYPE=TapeCover V1.x",
  919.                           "ACTION=LOAD",
  920.                           NULL
  921.                           };
  922.  
  923.     busy(idat->mainwin);
  924.     strcpy(prog_path, idat->mainpath);
  925.     if(AddPart(prog_path, tciname_str, MAXPATHLEN))
  926.         if (TC_DiskObject = GetDiskObject(prog_path))
  927.             {
  928.             strcpy(prog_path, idat->mainpath);
  929.             if (!AddPart(prog_path, tcname_str, MAXPATHLEN))
  930.                 strcpy(prog_path, tcname_str);
  931.             olddeftool = TC_DiskObject->do_DefaultTool;
  932.             TC_DiskObject->do_DefaultTool = prog_path;
  933.             oldtooltypes = TC_DiskObject->do_ToolTypes;
  934.             TC_DiskObject->do_ToolTypes = newtooltypes;
  935.             TC_DiskObject->do_Type = WBPROJECT;
  936.             TC_DiskObject->do_CurrentX = NO_ICON_POSITION;
  937.             TC_DiskObject->do_CurrentY = NO_ICON_POSITION;
  938.             PutDiskObject(p_file, TC_DiskObject);
  939.             TC_DiskObject->do_DefaultTool = olddeftool;
  940.             TC_DiskObject->do_ToolTypes = oldtooltypes;
  941.             FreeDiskObject(TC_DiskObject);
  942.             }
  943.     unbusy(idat->mainwin);
  944.     }
  945.  
  946. void save(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  947.     {
  948.     BPTR            datei;
  949.     char            bpath[MAXPATHLEN],
  950.                     bfile[MAXFILELEN];
  951.     UBYTE           flags;
  952.     LONG            length;
  953.  
  954.     busy(idat->mainwin);
  955.     strcpy(bpath, prefs->tapepath);
  956.     strcpy(bfile, idat->file);
  957.     if (AddPart(bpath, bfile, MAXPATHLEN))
  958.         {
  959.         datei = Open(bpath, MODE_NEWFILE);
  960.         if (datei)
  961.             {
  962.             length = Write(datei, tapehdr_str, 8);
  963.             length += Write(datei, tdat->sidea[0], BUF_LENGTH);
  964.             flags = tdat->size.line1_bold;
  965.             flags <<= 1;
  966.             flags |= tdat->size.line2_bold;
  967.             length += Write(datei, &flags, 1);
  968.             flags = 0;
  969.             length += Write(datei, &flags, 1);
  970.             if (length != TAPELENGTH)
  971.                 fehler(idat, MSG_SAVE_ERROR, bpath);
  972.             else
  973.                 {
  974.                 SetComment(bpath, GetString(&idat->li, MSG_COMMENT));
  975.                 idat->filesaved = TRUE;
  976.                 if (prefs->icons)
  977.                     add_icon(idat, bpath);
  978.                 }
  979.             }
  980.         else
  981.             fehler(idat, MSG_OPEN_ERROR, bpath);
  982.         Close(datei);
  983.         }
  984.     else
  985.         fehler(idat, MSG_PATH_ERROR, bpath);
  986.     unbusy(idat->mainwin);
  987.     }
  988.  
  989. void save_as(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  990. {
  991. BPTR            datei;
  992. char            bpath[MAXPATHLEN],
  993.                 fpath[MAXPATHLEN],
  994.                 bfile[MAXFILELEN];
  995. UBYTE           flags;
  996. LONG            length;
  997. BOOL            doit,
  998.                 again;
  999.  
  1000.     busy(idat->mainwin);
  1001.     strcpy(bpath, prefs->tapepath);
  1002.     strcpy(bfile, idat->file);
  1003.     do {
  1004.         doit = TRUE;
  1005.         again = FALSE;
  1006.         if (asl_fr(idat, prefs, idat->mainwin, ASLSAVETPC, bpath, bfile))
  1007.             {
  1008.             length = strlen(bfile);
  1009.             if (length >= 4)
  1010.                 {
  1011.                 if (0 != strcmp(bfile + length - 4, tpcext_str))
  1012.                     strcat(bfile, tpcext_str);
  1013.                 }
  1014.             else
  1015.                 strcat(bfile, tpcext_str);
  1016.             strcpy(fpath, bpath);
  1017.             if (AddPart(fpath, bfile, MAXPATHLEN))
  1018.                 {
  1019.                 datei = Open(fpath, MODE_OLDFILE);
  1020.                 if (datei)
  1021.                     {
  1022.                     doit = ask_overwrite(idat, fpath);
  1023.                     if (! doit)
  1024.                         again = TRUE;
  1025.                     }
  1026.                 Close(datei);
  1027.                 if (doit)
  1028.                     {
  1029.                     datei = Open(fpath, MODE_NEWFILE);
  1030.                     if (datei)
  1031.                         {
  1032.                         length = Write(datei, tapehdr_str, 8);
  1033.                         length += Write(datei, tdat->sidea[0], BUF_LENGTH);
  1034.                         flags = tdat->size.line1_bold;
  1035.                         flags <<= 1;
  1036.                         flags |= tdat->size.line2_bold;
  1037.                         length += Write(datei, &flags, 1);
  1038.                         flags = 0;
  1039.                         length += Write(datei, &flags, 1);
  1040.                         if (length != TAPELENGTH)
  1041.                             fehler(idat, MSG_SAVE_ERROR, fpath);
  1042.                         else
  1043.                             {
  1044.                             strcpy(prefs->tapepath, bpath);
  1045.                             strcpy(idat->file, bfile);
  1046.                             strcpy(idat->expfile, bfile);
  1047.                             SetWindowTitles(idat->mainwin, idat->file, (UBYTE *)-1);
  1048.                             SetComment(fpath, GetString(&idat->li, MSG_COMMENT));
  1049.                             idat->filesaved = TRUE;
  1050.                             if (prefs->icons)
  1051.                                 add_icon(idat, fpath);
  1052.                             }
  1053.                         }
  1054.                     else
  1055.                         fehler(idat, MSG_OPEN_ERROR, fpath);
  1056.                     Close(datei);
  1057.                     }
  1058.                 }
  1059.             else
  1060.                 fehler(idat, MSG_PATH_ERROR, fpath);
  1061.             }
  1062.     } while (again);
  1063.     unbusy(idat->mainwin);
  1064. }
  1065.  
  1066. void get_prtname(struct IntDat *idat, char *pnam)
  1067.     {
  1068.     BPTR datei;
  1069.     char buffer[DRIVERNAMESIZE];
  1070.     LONG length;
  1071.  
  1072.     strcpy(pnam, "");
  1073.     datei = Open(prttxtname_str, MODE_OLDFILE);
  1074.     if (datei)
  1075.         {
  1076.         length = Read(datei, buffer, 8);
  1077.         if (0 == memcmp(buffer, "FORM", 4))
  1078.             {
  1079.             length += Read(datei, buffer, 18);
  1080.             if (0 == memcmp(buffer, "PREFPRHD", 8))
  1081.                 {
  1082.                 length += Read(datei, buffer, 24);
  1083.                 if (0 == memcmp(buffer, "PTXT", 4))
  1084.                     {
  1085.                     length += Read(datei, buffer, 30);
  1086.                     strcpy(pnam, buffer);
  1087.                     }
  1088.                 else
  1089.                     fehler(idat, MSG_PTXT_ERROR, prttxtname_str);
  1090.                 }
  1091.             else
  1092.                 fehler(idat, MSG_PREF_ERROR, prttxtname_str);
  1093.             }
  1094.         else
  1095.             fehler(idat, MSG_FORM_ERROR, prttxtname_str);
  1096.         Close(datei);
  1097.         }
  1098.     }
  1099.  
  1100. void print_n(BPTR prt, int n)
  1101.     {
  1102.     unsigned int i;
  1103.  
  1104.     for(i = 0; i < n; i++)
  1105.         {
  1106.         FPuts(prt, " ");
  1107.         }
  1108.     }
  1109.  
  1110. void print_l(BPTR prt, int n)
  1111.     {
  1112.     unsigned int i;
  1113.  
  1114.     for(i = 0; i < n; i++)
  1115.         {
  1116.         FPuts(prt, "-");
  1117.         }
  1118.     }
  1119.  
  1120. void print_dat(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  1121.     {
  1122.     #define MAX_PRINT_TXT DRIVERNAMESIZE
  1123.     #define PRINT_LINES   2
  1124.  
  1125.     struct Window       *print_window;
  1126.     struct IntuiMessage *msg;
  1127.     struct NewGadget    ng;
  1128.     struct Gadget       *glist,
  1129.                         *gad,
  1130.                         *msg_gad;
  1131.     ULONG               msg_class;
  1132.     UWORD               msg_code;
  1133.     BOOL                done = FALSE,
  1134.                         doit = FALSE;
  1135.     WORD                xsize,
  1136.                         ysize,
  1137.                         winwidth,
  1138.                         winheight,
  1139.                         wintop,
  1140.                         hbor,
  1141.                         box_left,
  1142.                         box_top,
  1143.                         box_width,
  1144.                         box_height;
  1145.     UBYTE               i;
  1146.     char                prtname[DRIVERNAMESIZE],
  1147.                         buffer[BIGLABEL_LENGTH];
  1148.     int                 print_key,
  1149.                         cancel_key;
  1150.  
  1151.     get_prtname(idat, prtname);
  1152.     print_key = getgadkey(GetString(&idat->li, MSG_PRINT_GAD));
  1153.     cancel_key = getgadkey(GetString(&idat->li, MSG_CANCEL_GAD));
  1154.     xsize = idat->tgenfont->tf_XSize;
  1155.     ysize = idat->tgenfont->tf_YSize;
  1156.     wintop = idat->scr->WBorTop + idat->scr->Font->ta_YSize + 1 + 5;
  1157.     hbor = idat->scr->WBorLeft + idat->scr->WBorRight;
  1158.     winwidth = hbor + 40 + MAX_PRINT_TXT * xsize;
  1159.     gad = CreateContext(&glist);
  1160.     ng.ng_TextAttr = &idat->genfont;
  1161.     ng.ng_VisualInfo = idat->mainvi;
  1162.     if (strlen(GetString(&idat->li, MSG_PRINT_GAD)) > strlen(GetString(&idat->li, MSG_CANCEL_GAD)))
  1163.         ng.ng_Width = 20 + (strlen(GetString(&idat->li, MSG_PRINT_GAD)) - 1) * xsize;
  1164.     else
  1165.         ng.ng_Width = 20 + (strlen(GetString(&idat->li, MSG_CANCEL_GAD)) - 1) * xsize;
  1166.  
  1167.     if (hbor + 20 + (2 * ng.ng_Width) > winwidth)
  1168.         winwidth = hbor + 20 + (2 * ng.ng_Width);
  1169.     ng.ng_Height = 5 + ysize;
  1170.     ng.ng_LeftEdge = (winwidth - (2 * ng.ng_Width)) / 3;
  1171.     ng.ng_TopEdge = wintop + (ysize + 2) * PRINT_LINES + 15;
  1172.     ng.ng_GadgetText = GetString(&idat->li, MSG_PRINT_GAD);
  1173.     ng.ng_GadgetID = 1;
  1174.     ng.ng_Flags = 0;
  1175.     gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_',
  1176.                                               TAG_END);
  1177.     ng.ng_LeftEdge = 2 * ((winwidth - (2 * ng.ng_Width)) / 3) + ng.ng_Width;
  1178.     ng.ng_GadgetText = GetString(&idat->li, MSG_CANCEL_GAD);
  1179.     ng.ng_GadgetID = 2;
  1180.     gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_',
  1181.                                               TAG_END);
  1182.  
  1183.     ng.ng_Height = 10 + 2 * ysize;
  1184.     ng.ng_TopEdge = wintop + (ysize + 2) * (PRINT_LINES + 1) + 20;
  1185.     ng.ng_LeftEdge = 2 * ((winwidth - (2 * ng.ng_Width)) / 3) + ng.ng_Width;
  1186.     ng.ng_GadgetText = "Field 1\nButton";
  1187.     ng.ng_GadgetID = 3;
  1188.     gad = CreateGadget(BUTTON_KIND, gad, &ng, GT_Underscore, '_',
  1189.                                               TAG_END);
  1190.     winheight = wintop + idat->scr->WBorBottom +
  1191.                 PRINT_LINES * (ysize + 2) + ng.ng_Height +
  1192.                 20;
  1193.     if (gad)
  1194.         {
  1195.         if (print_window = OpenWindowTags(NULL,
  1196.                         WA_Left,            (idat->scr->Width - winwidth) / 2,
  1197.                         WA_Top,             (idat->scr->Height - winheight) /2,
  1198.                         WA_Width,           winwidth,
  1199.                         WA_Height,          winheight,
  1200.                         WA_Gadgets,         glist,
  1201.                         WA_DragBar,         TRUE,
  1202.                         WA_CloseGadget,     TRUE,
  1203.                         WA_DepthGadget,     TRUE,
  1204.                         WA_Activate,        TRUE,
  1205.                         WA_SmartRefresh,    TRUE,
  1206.                         WA_IDCMP,           IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY |
  1207.                                             IDCMP_GADGETUP | IDCMP_REFRESHWINDOW,
  1208.                         WA_Title,           GetString(&idat->li, MSG_PRINT_WIN),
  1209.                         WA_PubScreen,       idat->scr,
  1210.                         WA_ScreenTitle,     name_str,
  1211.                         TAG_END))
  1212.             {
  1213.             busy(idat->mainwin);
  1214.             GT_RefreshWindow(print_window, NULL);
  1215.             SetFont(print_window->RPort,idat-> tgenfont);
  1216.             box_rec(print_window, (winwidth - (MAX_PRINT_TXT * xsize)) / 4,
  1217.                                   wintop,
  1218.                                   3 * ((winwidth - (MAX_PRINT_TXT * xsize)) / 4) +
  1219.                                   MAX_PRINT_TXT * xsize,
  1220.                                   wintop + (ysize + 2) * PRINT_LINES + 5);
  1221.             write_ctext(print_window, wintop + 5, 1, 0,
  1222.                         GetString(&idat->li, MSG_PRINTERDRIVER));
  1223.             write_ctext(print_window, wintop + 5 + ysize + 2, 2, 0,
  1224.                         prtname);
  1225.             while (! done)
  1226.                 {
  1227.                 WaitPort(print_window->UserPort);
  1228.                 msg = (struct IntuiMessage *)GT_GetIMsg(print_window->UserPort);
  1229.                 msg_gad = (struct Gadget *)msg->IAddress;
  1230.                 msg_class = msg->Class;
  1231.                 msg_code = msg->Code;
  1232.                 GT_ReplyIMsg(msg);
  1233.                 switch (msg_class) {
  1234.                     case IDCMP_CLOSEWINDOW:
  1235.                         done = TRUE;
  1236.                         break;
  1237.                     case IDCMP_GADGETUP:
  1238.                         switch (msg_gad->GadgetID) {
  1239.                             case 1:
  1240.                                 doit = TRUE;
  1241.                                 done = TRUE;
  1242.                                 break;
  1243.                             case 2:
  1244.                                 done = TRUE;
  1245.                                 break;
  1246.                             default:
  1247.                                 break;
  1248.                             }
  1249.                         break;
  1250.                     case IDCMP_VANILLAKEY:
  1251.                         if (msg_code == print_key)
  1252.                             {
  1253.                             doit = TRUE;
  1254.                             done = TRUE;
  1255.                             }
  1256.                         else if (msg_code == cancel_key)
  1257.                             done = TRUE;
  1258.                         break;
  1259.                     case IDCMP_REFRESHWINDOW :
  1260.                         GT_BeginRefresh(print_window);
  1261.                         box_rec(print_window, (winwidth - (MAX_PRINT_TXT * xsize)) / 4,
  1262.                                               wintop,
  1263.                                               3 * ((winwidth - (MAX_PRINT_TXT * xsize)) / 4) +
  1264.                                               MAX_PRINT_TXT * xsize,
  1265.                                               wintop + (ysize + 2) * PRINT_LINES + 5);
  1266.                         write_ctext(print_window, wintop + 5, 1, 0,
  1267.                                     GetString(&idat->li, MSG_PRINTERDRIVER));
  1268.                         write_ctext(print_window, wintop + 5 + ysize + 2, 2, 0,
  1269.                                     prtname);
  1270.                         GT_EndRefresh(print_window, TRUE);
  1271.                         break;
  1272.                     default:
  1273.                         break;
  1274.                     }
  1275.                 }
  1276.             CloseWindow(print_window);
  1277.             }
  1278.         else
  1279.             fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_PRINT_WIN));
  1280.         FreeGadgets(glist);
  1281.         }
  1282.     else
  1283.         fehler(idat, MSG_GAD_ERROR, GetString(&idat->li, MSG_PRINT_WIN));
  1284.     if (doit)
  1285.         {
  1286.         hbor = idat->scr->WBorLeft + idat->scr->WBorRight;
  1287.         if (strlen(idat->file) > 40)
  1288.             winwidth = hbor + 10 + strlen(idat->file) * xsize;
  1289.         else
  1290.             winwidth = hbor + 10 + 30 * xsize;
  1291.         wintop = idat->scr->WBorTop + idat->scr->Font->ta_YSize + 1 + 5;
  1292.         winheight = wintop + idat->scr->WBorBottom + 3 * (ysize + 2) + 10;
  1293.         if (print_window = OpenWindowTags(NULL,
  1294.                         WA_Left,            (idat->scr->Width - winwidth) / 2,
  1295.                         WA_Top,             (idat->scr->Height - winheight) /2,
  1296.                         WA_Width,           winwidth,
  1297.                         WA_Height,          winheight,
  1298.                         WA_DragBar,         TRUE,
  1299.                         WA_DepthGadget,     TRUE,
  1300.                         WA_Activate,        TRUE,
  1301.                         WA_SmartRefresh,    TRUE,
  1302.                         WA_NoCareRefresh,   TRUE,
  1303.                         WA_Title,           GetString(&idat->li, MSG_PLEASEWAIT),
  1304.                         WA_PubScreen,       idat->scr,
  1305.                         WA_ScreenTitle,     name_str,
  1306.                         TAG_END))
  1307.             {
  1308.             if (IntuitionBase->lib_Version < 39)
  1309.                 SetPointer(print_window, waitPointer, 16, 16, -6, 0);
  1310.             else
  1311.                 SetWindowPointer(print_window, WA_BusyPointer, TRUE, TAG_END);
  1312.             SetFont(print_window->RPort, idat->tgenfont);
  1313.             write_ctext(print_window, wintop, 1, 0, GetString(&idat->li, MSG_PRINTING));
  1314.             write_ctext(print_window, wintop + ysize + 2, 2, 0, idat->file);
  1315.             box_width = winwidth - hbor - xsize * 6 - 20;
  1316.             box_height = ysize;
  1317.             box_left = print_window->BorderLeft + 2 * xsize + 10;
  1318.             box_top = wintop + 2 * (ysize + 2) + 5;
  1319.             box_rec(print_window, box_left - 1, box_top - 1, box_left + box_width, box_top + box_height);
  1320.             write_textjam2(print_window->RPort, print_window->BorderLeft + 5, box_top, 1, 0, "0%");
  1321.             write_textjam2(print_window->RPort,
  1322.                        winwidth - print_window->BorderRight - 4 * xsize - 5, box_top, 1, 0, "100%");
  1323.             idat->prt = Open("PRT:", MODE_NEWFILE);
  1324.             if (idat->prt)
  1325.                 {
  1326.                 FPuts(idat->prt, CMD_INIT);
  1327.                 if (prefs->ff)
  1328.                     FPuts(idat->prt, CMD_FLEN);
  1329.                 FPuts(idat->prt, CMD_LQ_ON);
  1330.                 FPuts(idat->prt, CMD_NM);
  1331.                 print_l(idat->prt, 40);
  1332.                 print_l(idat->prt, 40);
  1333.                 FPuts(idat->prt, "\n");
  1334.                 FPuts(idat->prt, CMD_NM);
  1335.                 FPuts(idat->prt, CMD_UL_ON);
  1336.                 box_fill(print_window, box_left, box_top, box_width, box_height, 10);
  1337.                 print_n(idat->prt, 1); FPuts(idat->prt, GetString(&idat->li, MSG_SIDEA));
  1338.                 print_n(idat->prt, (20 - strlen(GetString(&idat->li, MSG_SIDEA))));
  1339.                 FPuts(idat->prt, GetString(&idat->li, MSG_SIDEB));
  1340.                 print_n(idat->prt, (18 - strlen(GetString(&idat->li, MSG_SIDEB))));
  1341.  
  1342.                 FPuts(idat->prt, "|");
  1343.  
  1344.                 print_n(idat->prt, 1); FPuts(idat->prt, GetString(&idat->li, MSG_SIDEA));
  1345.                 print_n(idat->prt, (20 - strlen(GetString(&idat->li, MSG_SIDEA))));
  1346.                 FPuts(idat->prt, GetString(&idat->li, MSG_SIDEB));
  1347.                 print_n(idat->prt, (19 - strlen(GetString(&idat->li, MSG_SIDEB))));
  1348.  
  1349.                 FPuts(idat->prt, CMD_UL_OFF);
  1350.                 FPuts(idat->prt, "\n");
  1351.  
  1352.                 FPuts(idat->prt, CMD_CD_ON);
  1353.                 for(i = 0; i < TITLES_PER_SIDE; i++)
  1354.                     {
  1355.                     box_fill(print_window, box_left, box_top, box_width, box_height,
  1356.                              14 + i * 4);
  1357.                     print_n(idat->prt, 1); FPuts(idat->prt, tdat->sidea[i]);
  1358.                     print_n(idat->prt, 1); FPuts(idat->prt, tdat->sideb[i]);
  1359.  
  1360.                     print_n(idat->prt, 2); FPuts(idat->prt, tdat->sidea[i]);
  1361.                     print_n(idat->prt, 1); FPuts(idat->prt, tdat->sideb[i]);
  1362.  
  1363.                     FPuts(idat->prt, "\n");
  1364.  
  1365.                     }
  1366.                 box_fill(print_window, box_left, box_top, box_width, box_height, 75);
  1367.                 FPuts(idat->prt, CMD_NM);
  1368.                 print_l(idat->prt, 40);
  1369.                 print_l(idat->prt, 40);
  1370.                 FPuts(idat->prt, "\n");
  1371.  
  1372.                 if (tdat->size.line1_bold)
  1373.                     {
  1374.                     FPuts(idat->prt, CMD_EL_ON);
  1375.                     strmid(tdat->label[0], buffer, 1, BIGLABEL_LENGTH);
  1376.                     print_n(idat->prt, 1); FPuts(idat->prt, buffer);
  1377.  
  1378.                     strmid(tdat->label[0], buffer, 1, BIGLABEL_LENGTH);
  1379.                     print_n(idat->prt, 2); FPuts(idat->prt, buffer); FPuts(idat->prt, "\n");
  1380.                     FPuts(idat->prt, CMD_EL_OFF);
  1381.                     }
  1382.                 else
  1383.                     {
  1384.                     FPuts(idat->prt, CMD_CD_ON);
  1385.                     print_n(idat->prt, 1); FPuts(idat->prt, tdat->label[0]);
  1386.  
  1387.                     print_n(idat->prt, 2); FPuts(idat->prt, tdat->label[0]); FPuts(idat->prt, "\n");
  1388.                     }
  1389.                 box_fill(print_window, box_left, box_top, box_width, box_height, 80);
  1390.                 if (tdat->size.line2_bold)
  1391.                     {
  1392.                     FPuts(idat->prt, CMD_NM); FPuts(idat->prt, CMD_EL_ON);
  1393.                     strmid(tdat->label[1], buffer, 1, BIGLABEL_LENGTH);
  1394.                     print_n(idat->prt, 1); FPuts(idat->prt, buffer);
  1395.  
  1396.                     strmid(tdat->label[1], buffer, 1, BIGLABEL_LENGTH);
  1397.                     print_n(idat->prt, 2); FPuts(idat->prt, buffer); FPuts(idat->prt, "\n");
  1398.                     FPuts(idat->prt, CMD_EL_OFF);
  1399.                     }
  1400.                 else
  1401.                     {
  1402.                     FPuts(idat->prt, CMD_CD_ON);
  1403.                     print_n(idat->prt, 1); FPuts(idat->prt, tdat->label[1]);
  1404.  
  1405.                     print_n(idat->prt, 2); FPuts(idat->prt, tdat->label[1]); FPuts(idat->prt, "\n");
  1406.                     }
  1407.                 box_fill(print_window, box_left, box_top, box_width, box_height, 85);
  1408.                 FPuts(idat->prt, CMD_NM);
  1409.                 print_l(idat->prt, 40);
  1410.                 print_l(idat->prt, 40);
  1411.                 FPuts(idat->prt, "\n");
  1412.                 FPuts(idat->prt, CMD_CD_ON);
  1413.                 print_n(idat->prt, 1); FPuts(idat->prt, tdat->info[0]);
  1414.                 print_n(idat->prt, 2); FPuts(idat->prt, tdat->info[0]); FPuts(idat->prt, "\n");
  1415.                 print_n(idat->prt, 1); FPuts(idat->prt, tdat->info[1]);
  1416.                 print_n(idat->prt, 2); FPuts(idat->prt, tdat->info[1]); FPuts(idat->prt, "\n");
  1417.                 print_n(idat->prt, 1); FPuts(idat->prt, tdat->info[2]);
  1418.                 print_n(idat->prt, 2); FPuts(idat->prt, tdat->info[2]); FPuts(idat->prt, "\n");
  1419.                 box_fill(print_window, box_left, box_top, box_width, box_height, 100);
  1420.                 FPuts(idat->prt, CMD_NM);
  1421.                 print_l(idat->prt, 40);
  1422.                 print_l(idat->prt, 40);
  1423.                 FPuts(idat->prt, "\n");
  1424.                 FPuts(idat->prt, CMD_NM);
  1425.                 if (prefs->ff)
  1426.                     FPuts(idat->prt, "\f");
  1427.                 Close(idat->prt);
  1428.                 idat->prt = NULL;
  1429.                 }
  1430.             else
  1431.                 fehler(idat, MSG_PRINTER_ERROR, NULL);
  1432.             CloseWindow(print_window);
  1433.             }
  1434.         else
  1435.             fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_PRINT_WIN));
  1436.         }
  1437.     unbusy(idat->mainwin);  
  1438.     }
  1439.  
  1440. void edit(struct IntDat *idat, struct TapeDat *tdat)
  1441.     {
  1442.     struct RastPort *rp;
  1443.     ULONG           font_x,
  1444.                     font_y,
  1445.                     winleft,
  1446.                     wintop;
  1447.     int             pos = 1;
  1448.     BOOL            big;
  1449.  
  1450.     rp = idat->mainwin->RPort;
  1451.     font_x = rp->Font->tf_XSize;
  1452.     font_y = rp->Font->tf_YSize;
  1453.     winleft = (idat->mainwin->Width - (INFO_LENGTH - 1) * font_x) / 2;
  1454.     wintop = idat->mainwin->BorderTop;
  1455.     ClearMenuStrip(idat->mainwin);
  1456.     while (pos <= ((TITLES_PER_SIDE * 2) + LABELS + INFOS)) {
  1457.         if (pos <= TITLES_PER_SIDE)
  1458.            read_line(idat->mainwin, winleft,
  1459.                                 wintop + 10 + pos * (font_y + 6),
  1460.                                 tdat->sidea[pos - 1],
  1461.                                 &pos,
  1462.                                 FALSE);
  1463.         else if (pos <= (TITLES_PER_SIDE * 2))
  1464.            read_line(idat->mainwin, winleft + TITLE_LENGTH * font_x,
  1465.                                 wintop + 10 + (pos - TITLES_PER_SIDE) * (font_y + 6),
  1466.                                 tdat->sideb[pos - TITLES_PER_SIDE - 1],
  1467.                                 &pos,
  1468.                                 FALSE);
  1469.         else if (pos <= (TITLES_PER_SIDE * 2 + LABELS))
  1470.            {
  1471.            if (pos == (TITLES_PER_SIDE * 2 + 1))
  1472.                big = tdat->size.line1_bold;
  1473.            else
  1474.                big = tdat->size.line2_bold;
  1475.            read_line(idat->mainwin, winleft,
  1476.                                 wintop + 10 + (pos - TITLES_PER_SIDE + 1) * (font_y + 6),
  1477.                                 tdat->label[pos - TITLES_PER_SIDE * 2 - 1],
  1478.                                 &pos,
  1479.                                 big);
  1480.            }
  1481.         else
  1482.            read_line(idat->mainwin, winleft,
  1483.                                 wintop + 10 + (pos - TITLES_PER_SIDE + 2) * (font_y + 6),
  1484.                                 tdat->info[pos - TITLES_PER_SIDE * 2 - LABELS - 1],
  1485.                                 &pos,
  1486.                                 FALSE);
  1487.         pos++;
  1488.     }
  1489.     ResetMenuStrip(idat->mainwin, idat->mainmenu);
  1490.     idat->filesaved = FALSE;
  1491.     }
  1492.  
  1493. LONG get_length(char *tapeline)
  1494.     {
  1495.     LONG i;
  1496.  
  1497.     i = strlen(tapeline);
  1498.     while ((i > 0) && (0 == memcmp(tapeline + i - 1, " ", 1)))
  1499.         i--;
  1500.     return i;
  1501.     }
  1502.  
  1503. LONG how_many(char *tapeside[TITLES_PER_SIDE])
  1504.     {
  1505.     LONG i = TITLES_PER_SIDE;
  1506.  
  1507.     while ((i > 0) && (get_length(tapeside[i - 1]) == 0))
  1508.         i--;
  1509.     return i;
  1510.     }
  1511.  
  1512. void exp_ascii(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat)
  1513.     {
  1514.     BPTR            datei;
  1515.     char            bpath[MAXPATHLEN],
  1516.                     fpath[MAXPATHLEN],
  1517.                     bfile[MAXFILELEN];
  1518.     LONG            length,
  1519.                     st_len,
  1520.                     r_len = 0,
  1521.                     i,
  1522.                     j;
  1523.     BOOL            doit,
  1524.                     again;
  1525.  
  1526.     busy(idat->mainwin);
  1527.     strcpy(bpath, prefs->exppath);
  1528.     strcpy(bfile, idat->expfile);
  1529.     length = strlen(bfile);
  1530.     if (0 == strcmp(bfile + length - 4, tpcext_str))
  1531.         bfile[length - 4] = '\0';
  1532.     do {
  1533.         doit = TRUE;
  1534.         again = FALSE;
  1535.         if (asl_fr(idat, prefs, idat->mainwin, ASLSAVEEXP, bpath, bfile))
  1536.             {
  1537.             length = strlen(bfile);
  1538.             if (length >= 4)
  1539.                 {
  1540.                 if (0 != strcmp(bfile + length - 4, ascext_str))
  1541.                     strcat(bfile, ascext_str);
  1542.                 }
  1543.             else
  1544.                 strcat(bfile, ascext_str);
  1545.             strcpy(fpath, bpath);
  1546.             if (AddPart(fpath, bfile, MAXPATHLEN))
  1547.                 {
  1548.                 datei = Open(fpath, MODE_OLDFILE);
  1549.                 if (datei)
  1550.                     {
  1551.                     doit = ask_overwrite(idat, fpath);
  1552.                     if (! doit)
  1553.                         again = TRUE;
  1554.                     }
  1555.                 Close(datei);
  1556.                 if (doit)
  1557.                     {
  1558.                     datei = Open(fpath, MODE_NEWFILE);
  1559.                     if (datei)
  1560.                         {
  1561.                         length = 0;
  1562.                         st_len = get_length(tdat->label[0]);
  1563.                         if (st_len > 0)
  1564.                             {
  1565.                             length += Write(datei, tdat->label[0], st_len);
  1566.                             length += Write(datei, "\n", 1);
  1567.                             r_len += st_len + 1;
  1568.                             }
  1569.                         st_len = get_length(tdat->label[1]);
  1570.                         if (st_len > 0)
  1571.                             {
  1572.                             length += Write(datei, tdat->label[1], st_len);
  1573.                             length += Write(datei, "\n", 1);
  1574.                             r_len += st_len + 1;
  1575.                             }
  1576.                         j = how_many(tdat->sidea);
  1577.                         if (j > 0)
  1578.                             {
  1579.                             st_len = get_length(tdat->sidea[0]);
  1580.                             length += Write(datei, "A:", 2);
  1581.                             length += Write(datei, tdat->sidea[0], st_len);
  1582.                             length += Write(datei, "\n", 1);
  1583.                             r_len += st_len + 3;
  1584.                             if (j > 1)
  1585.                                 {
  1586.                                 for (i = 1; i < j; i++)
  1587.                                     {
  1588.                                     st_len = get_length(tdat->sidea[i]);
  1589.                                     length += Write(datei, "  ", 2);
  1590.                                     length += Write(datei, tdat->sidea[i], st_len);
  1591.                                     length += Write(datei, "\n", 1);
  1592.                                     r_len += st_len + 3;
  1593.                                     }
  1594.                                 }
  1595.                             }
  1596.                         j = how_many(tdat->sideb);
  1597.                         if (j > 0)
  1598.                             {
  1599.                             st_len = get_length(tdat->sideb[0]);
  1600.                             length += Write(datei, "B:", 2);
  1601.                             length += Write(datei, tdat->sideb[0], st_len);
  1602.                             length += Write(datei, "\n", 1);
  1603.                             r_len += st_len + 3;
  1604.                             if (j > 1)
  1605.                                 {
  1606.                                 for (i = 1; i < j; i++)
  1607.                                     {
  1608.                                     st_len = get_length(tdat->sideb[i]);
  1609.                                     length += Write(datei, "  ", 2);
  1610.                                     length += Write(datei, tdat->sideb[i], st_len);
  1611.                                     length += Write(datei, "\n", 1);
  1612.                                     r_len += st_len + 3;
  1613.                                     }
  1614.                                 }
  1615.                             }
  1616.                         if (length != r_len)
  1617.                             fehler(idat, MSG_SAVE_ERROR, fpath);
  1618.                         else
  1619.                             {
  1620.                             strcpy(prefs->exppath, bpath);
  1621.                             strcpy(idat->expfile, bfile);
  1622.                             }
  1623.                         }
  1624.                     else
  1625.                         fehler(idat, MSG_OPEN_ERROR, fpath);
  1626.                     Close(datei);
  1627.                     }
  1628.                 }
  1629.             else
  1630.                 fehler(idat, MSG_PATH_ERROR, fpath);
  1631.             }
  1632.         } while (again);
  1633.     unbusy(idat->mainwin);  
  1634.     }
  1635.  
  1636. void copyta2prefs(UBYTE i, struct PrefDat *dest, struct TextAttr *source)
  1637.     {
  1638.     i--;
  1639.     strcpy(dest->fontname[i], source->ta_Name);
  1640.     dest->fontysize[i] = source->ta_YSize;
  1641.     dest->fontstyle[i] = source->ta_Style;
  1642.     dest->fontflags[i] = source->ta_Flags;
  1643.     }
  1644.  
  1645. void copyprefs2ta(UBYTE i, struct TextAttr *dest, struct PrefDat *source)
  1646.     {
  1647.     i--;
  1648.     strcpy(dest->ta_Name, source->fontname[i]);
  1649.     dest->ta_YSize = source->fontysize[i];
  1650.     dest->ta_Style = source->fontstyle[i];
  1651.     dest->ta_Flags = source->fontflags[i];
  1652.     }
  1653.  
  1654. void convertfontname(char *name, struct TextAttr *tfont)
  1655.     {
  1656.     if (strlen(tfont->ta_Name) > 5)
  1657.         {
  1658.         strmid(tfont->ta_Name, name, 1, strlen(tfont->ta_Name) - 4);
  1659.         stci_d(&name[strlen(name)], tfont->ta_YSize);
  1660.         }
  1661.     }
  1662.  
  1663. void font_default(UBYTE i, struct PrefDat *prefs)
  1664.     {
  1665.     i--;
  1666.     strcpy(&prefs->fontname[i][0], "topaz.font");
  1667.     prefs->fontysize[i] = 8;
  1668.     prefs->fontstyle[i] = NULL;
  1669.     prefs->fontflags[i] = FPF_ROMFONT;
  1670.     }
  1671.  
  1672. void pref_default(struct PrefDat *prefs)
  1673.     {
  1674.     font_default(1, prefs);
  1675.     font_default(2, prefs);
  1676.     strcpy(prefs->scrname, defpub_str);
  1677.     strcpy(prefs->tapepath, deftpath_str);
  1678.     strcpy(prefs->exppath, defxpath_str);
  1679.     prefs->centered = TRUE;
  1680.     prefs->icons = prefs->ff = prefs->ownscr = FALSE;
  1681.     prefs->scrid = PAL_MONITOR_ID | HIRESLACE_KEY;
  1682.     prefs->scrwidth = 640;
  1683.     prefs->scrheight = 512;
  1684.     prefs->scrdepth = 2;
  1685.     prefs->scroscan = OSCAN_TEXT;
  1686.     prefs->scrascroll = TRUE;
  1687.     prefs->winleft = prefs->wintop = 0;
  1688.     prefs->aslwidth = 200;
  1689.     prefs->aslheight = 230;
  1690.     }
  1691.  
  1692. BOOL pref_load(struct IntDat *idat, struct PrefDat *prefs)
  1693.     {
  1694.     struct PrefDat newprefs;
  1695.     BPTR           datei;
  1696.     char           header[8],
  1697.                    loadfile[MAXPATHLEN];
  1698.     LONG           length;
  1699.     BOOL           success = FALSE;
  1700.  
  1701.     strcpy(loadfile, idat->prefpath);
  1702.     if (AddPart(loadfile, idat->preffile, MAXPATHLEN))
  1703.         {
  1704.         datei = Open(loadfile, MODE_OLDFILE);
  1705.         if (datei)
  1706.             {
  1707.             length = Read(datei, header, 8);
  1708.             if (0 == memcmp(header, confhdr_str, 8))
  1709.                 {
  1710.                 length += Read(datei, &newprefs, sizeof newprefs);
  1711.                 if (length == (8 + sizeof newprefs))
  1712.                     {
  1713.                     success = TRUE;
  1714.                     *prefs = newprefs;
  1715.                     }
  1716.                 else
  1717.                     fehler(idat, MSG_CONFIG_ERROR, loadfile);
  1718.                 }
  1719.             else
  1720.                 fehler(idat, MSG_NOCONFIG_ERROR, loadfile);
  1721.             Close(datei);
  1722.             }
  1723.         else
  1724.             if (! idat->firstload)
  1725.                 fehler(idat, MSG_OPEN_ERROR, loadfile);
  1726.         }
  1727.     else
  1728.         if (! idat->firstload)
  1729.             fehler(idat, MSG_PATH_ERROR, loadfile);
  1730.     return success;
  1731.     }
  1732.  
  1733. void pref_save(struct IntDat *idat, struct PrefDat *saveprefs)
  1734.     {
  1735.     BPTR datei;
  1736.     char savefile[MAXPATHLEN];
  1737.     LONG length;
  1738.  
  1739.     strcpy(savefile, idat->prefpath);
  1740.     if (AddPart(savefile, idat->preffile, MAXPATHLEN))
  1741.         {
  1742.         datei = Open(savefile, MODE_NEWFILE);
  1743.         if (datei)
  1744.             {
  1745.             length = Write(datei, confhdr_str, 8);
  1746.             length += Write(datei, saveprefs, sizeof *saveprefs);
  1747.             Close(datei);
  1748.             if (length != (8 + sizeof *saveprefs))
  1749.                 fehler(idat, MSG_SAVE_ERROR, savefile);
  1750.             }
  1751.         else
  1752.             fehler(idat, MSG_OPEN_ERROR, savefile);
  1753.         }
  1754.     else
  1755.         fehler(idat, MSG_PATH_ERROR, savefile);
  1756.     }
  1757.  
  1758. void init_idat(struct IntDat *idat, struct PrefDat *prefs, struct TapeDat *tdat,
  1759.                int argc, char **argv)
  1760.     {
  1761.     struct WBStartup  *argmsg;
  1762.     struct WBArg      *wb_arg;
  1763.     struct DiskObject *dob;
  1764.     int               tmpargcnt;
  1765.     char              *tool;
  1766.     BPTR              olddir;
  1767.     BOOL              noprefs = TRUE;
  1768.  
  1769.     strcpy(idat->scrname, "TAPECOVER.1");
  1770.     strcpy(idat->mainpath, defpath_str);
  1771.     strcpy(idat->prefpath, defpath_str);
  1772.     strcpy(idat->preffile, tcpname_str);
  1773.     idat->maskfont.ta_Name = idat->maskfontname;
  1774.     idat->genfont.ta_Name = idat->genfontname;
  1775.     idat->firstload = idat->filesaved = TRUE;
  1776.     idat->scr = NULL;
  1777.     idat->mainwin = NULL;
  1778.     idat->mainappwin = NULL;
  1779.     idat->mainmenu = NULL;
  1780.     idat->mainmsgport = NULL;
  1781.     idat->tmaskfont = NULL;
  1782.     idat->tgenfont = NULL;
  1783.     idat->mainglist = NULL;
  1784.     idat->maingad = NULL;
  1785.     idat->mainvi = NULL;
  1786.     LocalizeNewMenu(&idat->li, newmenu);
  1787.     if (argc == 0)
  1788.         {
  1789.         argmsg = (struct WBStartup *)argv;
  1790.         wb_arg = argmsg->sm_ArgList;
  1791.         if (dob = GetDiskObject(wb_arg->wa_Name))
  1792.             {
  1793.             tool = FindToolType(dob->do_ToolTypes,"SETTINGS");
  1794.             if (tool)
  1795.                 {
  1796.                 strcpy(idat->preffile, FilePart(tool));
  1797.                 strmid(tool, idat->prefpath, 1, strlen(tool) - strlen(idat->preffile));
  1798.                 noprefs = !pref_load(idat, prefs);
  1799.                 }
  1800.             tool = FindToolType(dob->do_ToolTypes,"PATH");
  1801.             if (tool)
  1802.                 strcpy(idat->mainpath, tool);
  1803.             tool = FindToolType(dob->do_ToolTypes,"FILE");
  1804.             if (tool)
  1805.                 {
  1806.                 strcpy(idat->loadpath, tool);
  1807.                 load_start(idat, prefs, tdat);
  1808.                 }
  1809.             FreeDiskObject(dob);
  1810.             }
  1811.         if (argmsg->sm_NumArgs > 1)
  1812.             {
  1813.             wb_arg++;
  1814.             if ((wb_arg->wa_Lock) && (*wb_arg->wa_Name))
  1815.                 {
  1816.                 olddir = CurrentDir(wb_arg->wa_Lock);
  1817.                 strcpy(idat->loadpath, wb_arg->wa_Name);
  1818.                 load_start(idat, prefs, tdat);
  1819.                 CurrentDir(olddir);
  1820.                 }
  1821.             }
  1822.         }
  1823.     else if (argc > 1)
  1824.         {
  1825.         for(tmpargcnt=1; tmpargcnt<argc; tmpargcnt++)
  1826.             {
  1827.             if ((0 == strcmp(argv[tmpargcnt], "SETTINGS")
  1828.                 && (tmpargcnt < argc - 1)))
  1829.                 {
  1830.                 strcpy(idat->preffile, FilePart(argv[tmpargcnt + 1]));
  1831.                 strmid(argv[tmpargcnt + 1], idat->prefpath, 1, strlen(argv[tmpargcnt + 1]) - strlen(idat->preffile));
  1832.                 tmpargcnt++;
  1833.                 noprefs = !pref_load(idat, prefs);
  1834.                 }
  1835.             else if ((0 == strcmp(argv[tmpargcnt], "PATH") && (tmpargcnt < argc - 1)))
  1836.                 {
  1837.                 strcpy(idat->mainpath, argv[tmpargcnt + 1]);
  1838.                 tmpargcnt++;
  1839.                 }
  1840.             else if ((0 == strcmp(argv[tmpargcnt], "FILE") && (tmpargcnt < argc - 1)))
  1841.                 {
  1842.                 strcpy(idat->loadpath, argv[tmpargcnt + 1]);
  1843.                 load_start(idat, prefs, tdat);
  1844.                 tmpargcnt++;
  1845.                 }
  1846.             }
  1847.         }
  1848.     if (noprefs)
  1849.         {
  1850.         strcpy(idat->prefpath, "");
  1851.         if (! pref_load(idat, prefs))
  1852.             {
  1853.             strcpy(idat->prefpath, idat->mainpath);
  1854.             strcpy(idat->preffile, tcpname_str);
  1855.             if (! pref_load(idat, prefs))
  1856.                  pref_default(prefs);
  1857.             }
  1858.         }
  1859.     idat->firstload = FALSE;
  1860.     }
  1861.  
  1862. BOOL open_all(struct IntDat *idat, struct PrefDat *prefs)
  1863.     {
  1864.     int  i = 1;
  1865.     BOOL success = FALSE;
  1866.     char errorfont[MAXFONTLEN];
  1867.  
  1868.     copyprefs2ta(1, &idat->maskfont, prefs);
  1869.     if (! (idat->tmaskfont = OpenDiskFont(&idat->maskfont)))
  1870.         {
  1871.         convertfontname(errorfont, &idat->maskfont);
  1872.         fehler(idat, MSG_FONT_ERROR, errorfont);
  1873.         font_default(1, prefs);
  1874.         copyprefs2ta(1, &idat->maskfont, prefs);
  1875.         idat->tmaskfont = OpenDiskFont(&idat->maskfont);
  1876.         }
  1877.     copyprefs2ta(2, &idat->genfont, prefs);
  1878.     if (! (idat->tgenfont = OpenDiskFont(&idat->genfont)))
  1879.         {
  1880.         convertfontname(errorfont, &idat->genfont);
  1881.         fehler(idat, MSG_FONT_ERROR, errorfont);
  1882.         font_default(2, prefs);
  1883.         copyprefs2ta(2, &idat->genfont, prefs);
  1884.         idat->tgenfont = OpenDiskFont(&idat->genfont);
  1885.         }
  1886.     if (idat->tmaskfont && idat->tgenfont)
  1887.         {
  1888.         if (prefs->ownscr)
  1889.             {
  1890.             idat->scr = LockPubScreen(idat->scrname);
  1891.             while (idat->scr && (i < 100))
  1892.                 {
  1893.                 UnlockPubScreen(NULL, idat->scr);
  1894.                 i++;
  1895.                 stci_d(&idat->scrname[10], i);
  1896.                 idat->scr = LockPubScreen(idat->scrname);
  1897.                 }
  1898.             if (NULL == (idat->scr = OpenScreenTags(NULL, SA_Pens, (ULONG) pens,
  1899.                                                           SA_PubName, idat->scrname, 
  1900.                                                           SA_Type, PUBLICSCREEN,
  1901.                                                           SA_DisplayID, prefs->scrid,
  1902.                                                           SA_Width, prefs->scrwidth,
  1903.                                                           SA_Height, prefs->scrheight,
  1904.                                                           SA_Depth, prefs->scrdepth,
  1905.                                                           SA_Overscan, prefs->scroscan,
  1906.                                                           SA_AutoScroll, prefs->scrascroll,
  1907.                                                           TAG_END)))
  1908.                 {
  1909.                 fehler(idat, MSG_OPENSCREEN_ERROR, idat->scrname);
  1910.                 prefs->ownscr = FALSE;
  1911.                 if (NULL == (idat->scr = LockPubScreen(prefs->scrname)))
  1912.                     {
  1913.                     fehler(idat, MSG_SCREEN_ERROR, prefs->scrname);
  1914.                     idat->scr = LockPubScreen(NULL);
  1915.                     }
  1916.                 }
  1917.             else
  1918.                 PubScreenStatus(idat->scr, 0);
  1919.             }
  1920.         else
  1921.             {
  1922.             if (NULL == (idat->scr = LockPubScreen(prefs->scrname)))
  1923.                 {
  1924.                 fehler(idat, MSG_SCREEN_ERROR, prefs->scrname);
  1925.                 idat->scr = LockPubScreen(NULL);
  1926.                 }
  1927.             }
  1928.         if (idat->scr)
  1929.             {
  1930.             success = TRUE;
  1931.             idat->mainvi = GetVisualInfo(idat->scr, TAG_END);
  1932.             }
  1933.         else
  1934.             fehler(idat, MSG_SCREEN_ERROR, "Workbench Screen");
  1935.         }
  1936.     else
  1937.         {
  1938.         if (! idat->tmaskfont)
  1939.             {
  1940.             convertfontname(errorfont, &idat->maskfont);
  1941.             fehler(idat, MSG_FONT_ERROR, errorfont);
  1942.             }
  1943.         else
  1944.             {
  1945.             convertfontname(errorfont, &idat->genfont);
  1946.             fehler(idat, MSG_FONT_ERROR, errorfont);
  1947.             }
  1948.         }
  1949.     return success;
  1950.     }
  1951.  
  1952. void close_all(struct IntDat *idat, struct PrefDat *prefs)
  1953.     {
  1954.     if (idat->mainvi)
  1955.         {
  1956.         FreeVisualInfo(idat->mainvi);
  1957.         idat->mainvi = NULL;
  1958.         }
  1959.     if (prefs->ownscr)
  1960.         CloseScreen(idat->scr);
  1961.     else
  1962.         UnlockPubScreen(NULL, idat->scr);
  1963.     idat->scr = NULL;
  1964.     if (idat->tmaskfont)
  1965.         {
  1966.         CloseFont(idat->tmaskfont);
  1967.         idat->tmaskfont = NULL;
  1968.         }
  1969.     if (idat->tgenfont)
  1970.         {
  1971.         CloseFont(idat->tgenfont);
  1972.         idat->tmaskfont = NULL;
  1973.         }
  1974.     }
  1975.  
  1976. void refresh_prgads(struct Window *window, struct Gadget *gads[], struct PrefDat *prefs)
  1977.     {
  1978.     struct NameInfo displaymode;
  1979.     struct TextAttr font;
  1980.     static char     scrmodename[DISPLAYNAMELEN],
  1981.                     maskfontname[PREFSTRGADWIDTH],
  1982.                     genfontname[PREFSTRGADWIDTH],
  1983.                     fontstr[MAXFONTLEN];
  1984.     UWORD           state;
  1985.  
  1986.     font.ta_Name = fontstr;   
  1987.     if (prefs->ownscr)
  1988.         state = 1;
  1989.     else
  1990.         state = 0;
  1991.     GT_SetGadgetAttrs(gads[OWNSCR_GAD], window, NULL,
  1992.                       GTMX_Active, state,
  1993.                       TAG_END);
  1994.     GT_SetGadgetAttrs(gads[SCRMODE_GAD] ,window, NULL,
  1995.                       GA_Disabled, !prefs->ownscr,
  1996.                       TAG_END);  
  1997.     GT_SetGadgetAttrs(gads[SCRNAMESTR_GAD] ,window, NULL,
  1998.                       GA_Disabled, prefs->ownscr,
  1999.                       TAG_END);  
  2000.     GetDisplayInfoData(NULL, (UBYTE *) &displaymode,
  2001.                        sizeof(displaymode), DTAG_NAME,
  2002.                        prefs->scrid);
  2003.     strcpy(scrmodename, displaymode.Name);
  2004.     GT_SetGadgetAttrs(gads[SCRMODETXT_GAD], window, NULL,
  2005.                       GTTX_Text, scrmodename,
  2006.                       TAG_END);
  2007.     GT_SetGadgetAttrs(gads[ICONS_GAD], window, NULL,
  2008.                       GTCB_Checked, prefs->icons,
  2009.                       TAG_END);
  2010.     GT_SetGadgetAttrs(gads[FORMFEED_GAD], window, NULL,
  2011.                       GTCB_Checked, prefs->ff,
  2012.                       TAG_END);
  2013.     if (prefs->centered)
  2014.         state = 1;
  2015.     else
  2016.         state = 0;
  2017.     GT_SetGadgetAttrs(gads[CENTERED_GAD], window, NULL,
  2018.                       GTMX_Active, state,
  2019.                       TAG_END);
  2020.     GT_SetGadgetAttrs(gads[TAPEPATHTXT_GAD], window, NULL,
  2021.                       GTTX_Text, prefs->tapepath,
  2022.                       TAG_END);
  2023.     GT_SetGadgetAttrs(gads[EXPPATHTXT_GAD], window, NULL,
  2024.                       GTTX_Text, prefs->exppath,
  2025.                       TAG_END);
  2026.     copyprefs2ta(1, &font, prefs);
  2027.     convertfontname(maskfontname, &font);
  2028.     GT_SetGadgetAttrs(gads[MASKFONTTXT_GAD], window, NULL,
  2029.                       GTTX_Text, maskfontname,
  2030.                       TAG_END);
  2031.     copyprefs2ta(2, &font, prefs);
  2032.     convertfontname(genfontname, &font);
  2033.     GT_SetGadgetAttrs(gads[GENFONTTXT_GAD], window, NULL,
  2034.                       GTTX_Text, genfontname,
  2035.                       TAG_END);  
  2036.     }
  2037.  
  2038. BOOL prefs_window(struct IntDat *idat, struct PrefDat *newprefs)
  2039.     {
  2040.     struct Window       *pr_window;
  2041.     struct IntuiMessage *msg;
  2042.     struct NewGadget    ng;
  2043.     struct Gadget       *pr_glist,
  2044.                         *pr_gad,
  2045.                         *pr_gads[15],
  2046.                         *msg_gad;
  2047.     struct TextAttr     newfont;
  2048.     APTR                *pr_VisualInfo;
  2049.     BOOL                done = FALSE,
  2050.                         doit = FALSE;
  2051.     WORD                wintop,
  2052.                         winwidth,
  2053.                         winheight,
  2054.                         xsize,
  2055.                         ysize,
  2056.                         hbor;
  2057.     FLOAT               gaddis;
  2058.     char                *mxscrgads[3],
  2059.                         *mxwingads[3],
  2060.                         *strgad,
  2061.                         newfontstr[MAXFONTLEN];
  2062.     ULONG               msg_class;
  2063.     UWORD               msg_code;
  2064.     int                 gad_key[17];
  2065.  
  2066.     gad_key[0] = getgadkey(GetString(&idat->li, MSG_OPEN_GAD));
  2067.     gad_key[1] = getgadkey(GetString(&idat->li, MSG_SAVEAS_GAD));
  2068.     gad_key[2] = getgadkey(GetString(&idat->li, MSG_SAVE_GAD));
  2069.     gad_key[3] = getgadkey(GetString(&idat->li, MSG_OK_GAD));
  2070.     gad_key[4] = getgadkey(GetString(&idat->li, MSG_DEFAULT_GAD));
  2071.     gad_key[5] = getgadkey(GetString(&idat->li, MSG_CANCEL_GAD));
  2072.     gad_key[6] = getgadkey(GetString(&idat->li, MSG_PUBSCR_GAD));
  2073.     gad_key[7] = getgadkey(GetString(&idat->li, MSG_OWNSCR_GAD));
  2074.     gad_key[8] = getgadkey(GetString(&idat->li, MSG_SCRMODE_GAD));
  2075.     gad_key[9] = getgadkey(GetString(&idat->li, MSG_ICONS_GAD));
  2076.     gad_key[10] = getgadkey(GetString(&idat->li, MSG_FORMFEED_GAD));
  2077.     gad_key[11] = getgadkey(GetString(&idat->li, MSG_SNAPSHOT_GAD));
  2078.     gad_key[12] = getgadkey(GetString(&idat->li, MSG_CENTERED_GAD));
  2079.     gad_key[13] = getgadkey(GetString(&idat->li, MSG_TAPEPATH_GAD));
  2080.     gad_key[14] = getgadkey(GetString(&idat->li, MSG_EXPPATH_GAD));
  2081.     gad_key[15] = getgadkey(GetString(&idat->li, MSG_MASKFONT_GAD));
  2082.     gad_key[16] = getgadkey(GetString(&idat->li, MSG_GENFONT_GAD));
  2083.     newfont.ta_Name = newfontstr;
  2084.     newprefs->winleft = idat->mainwin->LeftEdge;
  2085.     newprefs->wintop = idat->mainwin->TopEdge;
  2086.     pr_VisualInfo = GetVisualInfo(idat->scr, TAG_END);
  2087.     xsize = idat->tgenfont->tf_XSize;
  2088.     ysize = idat->tgenfont->tf_YSize;
  2089.     wintop = idat->scr->WBorTop + idat->scr->Font->ta_YSize + 1;
  2090.     hbor = idat->scr->WBorLeft + idat->scr->WBorRight;
  2091.     winwidth = hbor + (PREFGADWIDTH + PREFSTRGADWIDTH) * xsize + 60;
  2092.     if (hbor + 30 + (3 * MAINGADWIDTH * xsize) > winwidth)
  2093.         winwidth = hbor + 30 + (3 * MAINGADWIDTH * xsize);
  2094.     pr_gad = CreateContext(&pr_glist);
  2095.     ng.ng_TextAttr = &idat->genfont;
  2096.     ng.ng_VisualInfo = pr_VisualInfo;
  2097.     mxscrgads[0] = GetString(&idat->li, MSG_PUBSCR_GAD);
  2098.     mxscrgads[1] = GetString(&idat->li, MSG_OWNSCR_GAD);
  2099.     mxscrgads[2] = NULL;
  2100.     ng.ng_Width = 2 * xsize;
  2101.     ng.ng_Height = ysize;
  2102.     ng.ng_LeftEdge = idat->scr->WBorLeft + 20;
  2103.     ng.ng_TopEdge = wintop + 15;
  2104.     ng.ng_GadgetID = OWNSCR_GAD;
  2105.     ng.ng_Flags = PLACETEXT_RIGHT;
  2106.     pr_gads[OWNSCR_GAD] = pr_gad = CreateGadget(MX_KIND, pr_gad, &ng, GT_Underscore, '_',
  2107.                                                                       GTMX_Labels, mxscrgads,
  2108.                                                                       GTMX_Spacing, 10,
  2109.                                                                       GTMX_Scaled, TRUE,
  2110.                                                                       TAG_END);
  2111.     ng.ng_Width = 10 + PREFGADWIDTH * xsize;
  2112.     ng.ng_Height = ysize + 6;
  2113.     ng.ng_TopEdge += 2 * (ysize + 10);
  2114.     ng.ng_GadgetText = GetString(&idat->li, MSG_SCRMODE_GAD);
  2115.     ng.ng_GadgetID = SCRMODE_GAD;
  2116.     ng.ng_Flags = 0;
  2117.     pr_gads[SCRMODE_GAD] = pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2118.                                                                            TAG_END);
  2119.     ng.ng_Width = 3 * xsize;
  2120.     ng.ng_Height = ysize;
  2121.     ng.ng_TopEdge += ysize + 15;
  2122.     ng.ng_GadgetText = GetString(&idat->li, MSG_ICONS_GAD);
  2123.     ng.ng_GadgetID = ICONS_GAD;
  2124.     ng.ng_Flags = PLACETEXT_RIGHT;
  2125.     pr_gads[ICONS_GAD] = pr_gad = CreateGadget(CHECKBOX_KIND, pr_gad, &ng, GT_Underscore, '_',
  2126.                                                                            GTCB_Scaled, TRUE,
  2127.                                                                            TAG_END);
  2128.     ng.ng_TopEdge += ysize + 10;
  2129.     ng.ng_GadgetText = GetString(&idat->li, MSG_FORMFEED_GAD);
  2130.     ng.ng_GadgetID = FORMFEED_GAD;
  2131.     pr_gads[FORMFEED_GAD] = pr_gad = CreateGadget(CHECKBOX_KIND, pr_gad, &ng, GT_Underscore, '_',
  2132.                                                                               GTCB_Scaled, TRUE,
  2133.                                                                               TAG_END);
  2134.     ng.ng_Width = 10 + PREFGADWIDTH * xsize;
  2135.     ng.ng_Height = ysize + 6;
  2136.     ng.ng_TopEdge += ysize + 13;
  2137.     ng.ng_GadgetText = GetString(&idat->li, MSG_TAPEPATH_GAD);
  2138.     ng.ng_GadgetID = TAPEPATH_GAD;
  2139.     ng.ng_Flags = 0;
  2140.     pr_gads[TAPEPATH_GAD] = pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2141.                                                                             TAG_END);
  2142.     ng.ng_TopEdge += ysize + 15;
  2143.     ng.ng_GadgetText = GetString(&idat->li, MSG_EXPPATH_GAD);
  2144.     ng.ng_GadgetID = EXPPATH_GAD;
  2145.     pr_gads[EXPPATH_GAD] = pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2146.                                                                            TAG_END);
  2147.     ng.ng_TopEdge += ysize + 15;
  2148.     ng.ng_GadgetText = GetString(&idat->li, MSG_MASKFONT_GAD);
  2149.     ng.ng_GadgetID = MASKFONT_GAD;
  2150.     pr_gads[MASKFONT_GAD] = pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2151.                                                                             TAG_END);
  2152.     ng.ng_TopEdge += ysize + 15;
  2153.     ng.ng_GadgetText = GetString(&idat->li, MSG_GENFONT_GAD);
  2154.     ng.ng_GadgetID = GENFONT_GAD;
  2155.     pr_gads[GENFONT_GAD] = pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2156.                                                                            TAG_END);
  2157.     ng.ng_Width = xsize * PREFSTRGADWIDTH;
  2158.     ng.ng_LeftEdge = idat->scr->WBorLeft + PREFGADWIDTH * xsize + 40;
  2159.     ng.ng_TopEdge = wintop + 13;
  2160.     ng.ng_GadgetText = NULL;
  2161.     ng.ng_GadgetID = SCRNAMESTR_GAD;
  2162.     ng.ng_Flags = 0;
  2163.     pr_gads[SCRNAMESTR_GAD] = pr_gad = CreateGadget(STRING_KIND, pr_gad, &ng, GTST_String, newprefs->scrname,
  2164.                                                                               GTST_MaxChars, 100,
  2165.                                                                               GA_Disabled, newprefs->ownscr,
  2166.                                                                               TAG_END);
  2167.     if (pr_gad)
  2168.         strgad = ((struct StringInfo *) (pr_gad->SpecialInfo))->Buffer;
  2169.     ng.ng_TopEdge += 2 * ysize + 22;
  2170.     ng.ng_GadgetID = SCRMODETXT_GAD;
  2171.     pr_gads[SCRMODETXT_GAD] = pr_gad = CreateGadget(TEXT_KIND, pr_gad, &ng, GTTX_Border, TRUE,
  2172.                                                                             TAG_END);
  2173.     mxwingads[0] = GetString(&idat->li, MSG_SNAPSHOT_GAD);
  2174.     mxwingads[1] = GetString(&idat->li, MSG_CENTERED_GAD);
  2175.     mxwingads[2] = NULL;
  2176.     ng.ng_Width = 2 * xsize;
  2177.     ng.ng_Height -= 6;
  2178.     ng.ng_TopEdge += ysize + 16;
  2179.     ng.ng_GadgetID = CENTERED_GAD;
  2180.     ng.ng_Flags = PLACETEXT_RIGHT;
  2181.     pr_gads[CENTERED_GAD] = pr_gad = CreateGadget(MX_KIND, pr_gad, &ng, GT_Underscore, '_',
  2182.                                                                         GTMX_Labels, mxwingads,
  2183.                                                                         GTMX_Spacing, 10,
  2184.                                                                         GTMX_Scaled, TRUE,
  2185.                                                                         TAG_END);
  2186.     ng.ng_Width = xsize * PREFSTRGADWIDTH;
  2187.     ng.ng_Height += 6;
  2188.     ng.ng_TopEdge += 2 * ysize + 22;
  2189.     ng.ng_GadgetID = TAPEPATHTXT_GAD;
  2190.     ng.ng_Flags = 0;
  2191.     pr_gads[TAPEPATHTXT_GAD] = pr_gad = CreateGadget(TEXT_KIND, pr_gad, &ng, GTTX_Border, TRUE,
  2192.                                                                              TAG_END);
  2193.     ng.ng_TopEdge += ysize + 15;
  2194.     ng.ng_GadgetID = EXPPATHTXT_GAD;
  2195.     pr_gads[EXPPATHTXT_GAD] = pr_gad = CreateGadget(TEXT_KIND, pr_gad, &ng, GTTX_Border, TRUE,
  2196.                                                                             TAG_END);
  2197.     ng.ng_TopEdge += ysize + 15;
  2198.     ng.ng_GadgetID = MASKFONTTXT_GAD;
  2199.     pr_gads[MASKFONTTXT_GAD] = pr_gad = CreateGadget(TEXT_KIND, pr_gad, &ng, GTTX_Border, TRUE,
  2200.                                                                              TAG_END);
  2201.     ng.ng_TopEdge += ysize + 15;
  2202.     ng.ng_GadgetID = GENFONTTXT_GAD;
  2203.     pr_gads[GENFONTTXT_GAD] = pr_gad = CreateGadget(TEXT_KIND, pr_gad, &ng, GTTX_Border, TRUE,
  2204.                                                                             TAG_END);
  2205.     ng.ng_Width = 10 + MAINGADWIDTH * xsize;
  2206.     gaddis = (winwidth - 3 * ng.ng_Width - hbor) / 4;
  2207.     ng.ng_Height = 5 + ysize;
  2208.     ng.ng_LeftEdge = idat->scr->WBorLeft + gaddis;
  2209.     ng.ng_TopEdge += ysize + 25;
  2210.     ng.ng_GadgetText = GetString(&idat->li, MSG_OPEN_GAD);
  2211.     ng.ng_GadgetID = MSG_OPEN_GAD;
  2212.     ng.ng_Flags = 0;
  2213.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2214.                                                     TAG_END);
  2215.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  2216.     ng.ng_GadgetText = GetString(&idat->li, MSG_SAVEAS_GAD);
  2217.     ng.ng_GadgetID = MSG_SAVEAS_GAD;
  2218.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2219.                                                     TAG_END);
  2220.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  2221.     ng.ng_GadgetText = GetString(&idat->li, MSG_SAVE_GAD);
  2222.     ng.ng_GadgetID = MSG_SAVE_GAD;
  2223.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2224.                                                     TAG_END);
  2225.     ng.ng_TopEdge += ysize + 10;
  2226.     ng.ng_LeftEdge = idat->scr->WBorLeft + gaddis;
  2227.     ng.ng_GadgetText = GetString(&idat->li, MSG_OK_GAD);
  2228.     ng.ng_GadgetID = MSG_OK_GAD;
  2229.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2230.                                                     TAG_END);
  2231.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  2232.     ng.ng_GadgetText = GetString(&idat->li, MSG_DEFAULT_GAD);
  2233.     ng.ng_GadgetID = MSG_DEFAULT_GAD;
  2234.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2235.                                                     TAG_END);
  2236.     ng.ng_LeftEdge += gaddis + ng.ng_Width;
  2237.     ng.ng_GadgetText = GetString(&idat->li, MSG_CANCEL_GAD);
  2238.     ng.ng_GadgetID = MSG_CANCEL_GAD;
  2239.     pr_gad = CreateGadget(BUTTON_KIND, pr_gad, &ng, GT_Underscore, '_',
  2240.                                                     TAG_END);
  2241.     if (pr_gad)
  2242.         {   
  2243.         winheight = wintop + idat->scr->WBorBottom +
  2244.                     11 * (ysize + 10) + 55;
  2245.         if ((winwidth <= idat->scr->Width) && (winheight <= idat->scr->Height))
  2246.             {
  2247.             if (pr_window = OpenWindowTags(NULL,
  2248.                             WA_Left,            (idat->scr->Width - winwidth) / 2,
  2249.                             WA_Top,             (idat->scr->Height - winheight) /2,
  2250.                             WA_Width,           winwidth,
  2251.                             WA_Height,          winheight,
  2252.                             WA_Gadgets,         pr_glist,
  2253.                             WA_DragBar,         TRUE,
  2254.                             WA_DepthGadget,     TRUE,
  2255.                             WA_Activate,        TRUE,
  2256.                             WA_SmartRefresh,    TRUE,
  2257.                             WA_IDCMP,           IDCMP_RAWKEY | IDCMP_VANILLAKEY |
  2258.                                                 IDCMP_GADGETUP | IDCMP_GADGETDOWN |
  2259.                                                 IDCMP_REFRESHWINDOW,
  2260.                             WA_Title,           GetString(&idat->li, MSG_PREF_WIN),
  2261.                             WA_PubScreen,       idat->scr,
  2262.                             WA_ScreenTitle,     name_str,
  2263.                             TAG_END))
  2264.                 {
  2265.                 busy(idat->mainwin);
  2266.                 GT_RefreshWindow(pr_window, NULL);
  2267.                 box_bor(pr_window, pr_window->BorderLeft + 10, wintop + 5,
  2268.                         winwidth - pr_window->BorderRight - 10,
  2269.                         wintop + 9 * (ysize + 10) + 42);
  2270.                 refresh_prgads(pr_window, pr_gads, newprefs);
  2271.                 while (!done)
  2272.                     {
  2273.                     WaitPort(pr_window->UserPort);
  2274.                     while ((!done) &&
  2275.                            (msg = GT_GetIMsg(pr_window->UserPort)))
  2276.                         {
  2277.                         msg_gad = (struct Gadget *)msg->IAddress;
  2278.                         msg_class = msg->Class;
  2279.                         msg_code = msg->Code;
  2280.                         GT_ReplyIMsg(msg);
  2281.                         switch (msg_class) {
  2282.                             case IDCMP_GADGETDOWN:
  2283.                                 switch (msg_gad->GadgetID) {
  2284.                                     case OWNSCR_GAD :
  2285.                                         if (msg_code == 0)
  2286.                                             newprefs->ownscr = FALSE;
  2287.                                         else if (msg_code == 1)
  2288.                                             newprefs->ownscr = TRUE;
  2289.                                         break;
  2290.                                     case CENTERED_GAD :
  2291.                                         if (msg_code == 0)
  2292.                                             {
  2293.                                             newprefs->winleft = idat->mainwin->LeftEdge;
  2294.                                             newprefs->wintop = idat->mainwin->TopEdge;
  2295.                                             newprefs->centered = FALSE;
  2296.                                             }
  2297.                                         else if (msg_code == 1)
  2298.                                             newprefs->centered = TRUE;
  2299.                                         break;
  2300.                                     default:
  2301.                                         break;
  2302.                                     }
  2303.                                 refresh_prgads(pr_window, pr_gads, newprefs);
  2304.                                 break;  
  2305.                             case IDCMP_GADGETUP:
  2306.                                 switch (msg_gad->GadgetID) {
  2307.                                     case MSG_OPEN_GAD :
  2308.                                         if (asl_fr(idat, newprefs, pr_window, ASLLOADPREF,
  2309.                                                    idat->prefpath, idat->preffile))
  2310.                                             {
  2311.                                             pref_load(idat, newprefs);
  2312.                                             GT_SetGadgetAttrs(pr_gads[SCRNAMESTR_GAD] ,pr_window, NULL,
  2313.                                                               GTST_String, newprefs->scrname,
  2314.                                                               GA_Disabled, newprefs->ownscr,
  2315.                                                               TAG_END);  
  2316.                                             }
  2317.                                         break;
  2318.                                     case MSG_SAVEAS_GAD :
  2319.                                         if (asl_fr(idat, newprefs, pr_window, ASLSAVEPREF,
  2320.                                                    idat->prefpath, idat->preffile))
  2321.                                             {
  2322.                                             newprefs->winleft = idat->mainwin->LeftEdge;
  2323.                                             newprefs->wintop = idat->mainwin->TopEdge;
  2324.                                             pref_save(idat, newprefs);
  2325.                                             }
  2326.                                         break;
  2327.                                     case MSG_SAVE_GAD :
  2328.                                         newprefs->winleft = idat->mainwin->LeftEdge;
  2329.                                         newprefs->wintop = idat->mainwin->TopEdge;
  2330.                                         pref_save(idat, newprefs);
  2331.                                         break;
  2332.                                     case MSG_OK_GAD :
  2333.                                         doit = TRUE;
  2334.                                         done = TRUE;
  2335.                                         break;
  2336.                                     case MSG_DEFAULT_GAD :
  2337.                                         pref_default(newprefs);
  2338.                                         GT_SetGadgetAttrs(pr_gads[SCRNAMESTR_GAD] ,pr_window, NULL,
  2339.                                                           GTST_String, newprefs->scrname,
  2340.                                                           GA_Disabled, newprefs->ownscr,
  2341.                                                           TAG_END);  
  2342.                                         break;
  2343.                                     case MSG_CANCEL_GAD :
  2344.                                         done = TRUE;
  2345.                                         break;
  2346.                                     case SCRMODE_GAD :
  2347.                                         asl_smr(idat, pr_window, newprefs);
  2348.                                         break;
  2349.                                     case ICONS_GAD :
  2350.                                         newprefs->icons = !newprefs->icons;
  2351.                                         break;
  2352.                                     case FORMFEED_GAD :
  2353.                                         newprefs->ff = !newprefs->ff;
  2354.                                         break;
  2355.                                     case TAPEPATH_GAD :
  2356.                                         asl_fr(idat, newprefs, pr_window, ASLPATH, newprefs->tapepath, NULL);
  2357.                                         break;
  2358.                                     case EXPPATH_GAD :
  2359.                                         asl_fr(idat, newprefs, pr_window, ASLPATH, newprefs->exppath, NULL);
  2360.                                         break;
  2361.                                     case MASKFONT_GAD :
  2362.                                         copyprefs2ta(1, &newfont, newprefs);
  2363.                                         if (asl_for(idat, newprefs, pr_window, &newfont))
  2364.                                             copyta2prefs(1, newprefs, &newfont);
  2365.                                         break;   
  2366.                                     case GENFONT_GAD :
  2367.                                         copyprefs2ta(2, &newfont, newprefs);
  2368.                                         if (asl_for(idat, newprefs, pr_window, &newfont))
  2369.                                             copyta2prefs(2, newprefs, &newfont);
  2370.                                         break;
  2371.                                     default:
  2372.                                         break;
  2373.                                     }
  2374.                                 refresh_prgads(pr_window, pr_gads, newprefs);
  2375.                                 break;
  2376.                             case IDCMP_VANILLAKEY:
  2377.                                 if (msg_code == gad_key[0])
  2378.                                     {
  2379.                                     if (asl_fr(idat, newprefs, pr_window, ASLLOADPREF,
  2380.                                                idat->prefpath, idat->preffile))
  2381.                                         {
  2382.                                         pref_load(idat, newprefs);
  2383.                                         GT_SetGadgetAttrs(pr_gads[SCRNAMESTR_GAD] ,pr_window, NULL,
  2384.                                                           GTST_String, newprefs->scrname,
  2385.                                                           GA_Disabled, newprefs->ownscr,
  2386.                                                           TAG_END);  
  2387.                                         }
  2388.                                     }
  2389.                                 else if (msg_code == gad_key[1])
  2390.                                     {
  2391.                                     if (asl_fr(idat, newprefs, pr_window, ASLSAVEPREF,
  2392.                                                idat->prefpath, idat->preffile))
  2393.                                         {
  2394.                                         newprefs->winleft = idat->mainwin->LeftEdge;
  2395.                                         newprefs->wintop = idat->mainwin->TopEdge;
  2396.                                         pref_save(idat, newprefs);
  2397.                                         }
  2398.                                     }
  2399.                                 else if (msg_code == gad_key[2])
  2400.                                     {
  2401.                                     newprefs->winleft = idat->mainwin->LeftEdge;
  2402.                                     newprefs->wintop = idat->mainwin->TopEdge;
  2403.                                     pref_save(idat, newprefs);
  2404.                                     }
  2405.                                 else if (msg_code == gad_key[3])
  2406.                                     {
  2407.                                     doit = TRUE;
  2408.                                     done = TRUE;
  2409.                                     }
  2410.                                 else if (msg_code == gad_key[4])
  2411.                                     {
  2412.                                     pref_default(newprefs);
  2413.                                     GT_SetGadgetAttrs(pr_gads[SCRNAMESTR_GAD] ,pr_window, NULL,
  2414.                                                       GTST_String, newprefs->scrname,
  2415.                                                       GA_Disabled, newprefs->ownscr,
  2416.                                                       TAG_END);  
  2417.                                     }
  2418.                                 else if (msg_code == gad_key[5])
  2419.                                     done = TRUE;
  2420.                                 else if (msg_code == gad_key[6])
  2421.                                     newprefs->ownscr = FALSE;
  2422.                                 else if (msg_code == gad_key[7])
  2423.                                     newprefs->ownscr = TRUE;
  2424.                                 else if (msg_code == gad_key[8])
  2425.                                     asl_smr(idat, pr_window, newprefs);
  2426.                                 else if (msg_code == gad_key[9])
  2427.                                     newprefs->icons = !newprefs->icons;
  2428.                                 else if (msg_code == gad_key[10])
  2429.                                     newprefs->ff = !newprefs->ff;
  2430.                                 else if (msg_code == gad_key[11])
  2431.                                     {
  2432.                                     newprefs->winleft = idat->mainwin->LeftEdge;
  2433.                                     newprefs->wintop = idat->mainwin->TopEdge;
  2434.                                     newprefs->centered = FALSE;
  2435.                                     }
  2436.                                 else if (msg_code == gad_key[12])
  2437.                                     newprefs->centered = TRUE;
  2438.                                 else if (msg_code == gad_key[13])
  2439.                                     asl_fr(idat, newprefs, pr_window, ASLPATH, newprefs->tapepath, NULL);
  2440.                                 else if (msg_code == gad_key[14])
  2441.                                     asl_fr(idat, newprefs, pr_window, ASLPATH, newprefs->exppath, NULL);
  2442.                                 else if (msg_code == gad_key[15])
  2443.                                     {
  2444.                                     copyprefs2ta(1, &newfont, newprefs);
  2445.                                     if (asl_for(idat, newprefs, pr_window, &newfont))
  2446.                                         copyta2prefs(1, newprefs, &newfont);
  2447.                                     }
  2448.                                 else if (msg_code == gad_key[16])
  2449.                                     {
  2450.                                     copyprefs2ta(2, &newfont, newprefs);
  2451.                                     if (asl_for(idat, newprefs, pr_window, &newfont))
  2452.                                         copyta2prefs(2, newprefs, &newfont);
  2453.                                     }
  2454.                                 refresh_prgads(pr_window, pr_gads, newprefs);
  2455.                                 break;
  2456.                             case IDCMP_REFRESHWINDOW :
  2457.                                 GT_BeginRefresh(pr_window);
  2458.                                 box_bor(pr_window, pr_window->BorderLeft + 10, wintop + 5,
  2459.                                         winwidth - pr_window->BorderRight - 10,
  2460.                                         wintop + 9 * (ysize + 10) + 42);
  2461.                                 GT_EndRefresh(pr_window, TRUE);
  2462.                                 break;
  2463.                             default:
  2464.                                 break;
  2465.                             }
  2466.                         strcpy(newprefs->scrname, strgad);
  2467.                         }
  2468.                     }
  2469.                 unbusy(idat->mainwin);
  2470.                 CloseWindow(pr_window);
  2471.                 FreeGadgets(pr_glist);
  2472.                 FreeVisualInfo(pr_VisualInfo);
  2473.                 }
  2474.             else
  2475.                 fehler(idat, MSG_WIN_ERROR, GetString(&idat->li, MSG_PREF_WIN));
  2476.             }
  2477.         else
  2478.             fehler(idat, MSG_WINSIZE_ERROR, GetString(&idat->li, MSG_PREF_WIN));
  2479.         }
  2480.     else
  2481.         {
  2482.         FreeGadgets(pr_glist);
  2483.         fehler(idat, MSG_GAD_ERROR, GetString(&idat->li, MSG_PREF_WIN));
  2484.         }
  2485.     return doit;
  2486.     }
  2487.  
  2488. BOOL get_input(struct IntDat *idat, struct PrefDat *prefs,
  2489.                struct PrefDat *newprefs, struct TapeDat *tdat)
  2490.     {
  2491.     struct IntuiMessage *msg;
  2492.     struct MenuItem     *item;
  2493.     struct AppMessage   *amsg;
  2494.     struct Gadget       *msg_gad;
  2495.     struct WBArg        *argptr;
  2496.     BPTR                olddir;
  2497.     ULONG               msg_class,
  2498.                         winsig,
  2499.                         appwinsig,
  2500.                         signals;
  2501.     UWORD               msg_code;
  2502.     UWORD               menuNumber,
  2503.                         menuNum,
  2504.                         itemNum;
  2505.     int                 gad_key[8];
  2506.     BOOL                done = FALSE,
  2507.                         prefs_call = FALSE;
  2508.  
  2509.     gad_key[0] = getgadkey(GetString(&idat->li, MSG_NEW_GAD));
  2510.     gad_key[1] = getgadkey(GetString(&idat->li, MSG_OPEN_GAD));
  2511.     gad_key[2] = getgadkey(GetString(&idat->li, MSG_SAVE_GAD));
  2512.     gad_key[3] = getgadkey(GetString(&idat->li, MSG_SAVEAS_GAD));
  2513.     gad_key[4] = getgadkey(GetString(&idat->li, MSG_EDIT_GAD));
  2514.     gad_key[5] = getgadkey(GetString(&idat->li, MSG_MPRINT_GAD));
  2515.     gad_key[6] = getgadkey(GetString(&idat->li, MSG_PREFS_GAD));
  2516.     gad_key[7] = getgadkey(GetString(&idat->li, MSG_QUIT_GAD));
  2517.     winsig = 1L << idat->mainwin->UserPort->mp_SigBit;
  2518.     appwinsig = 1L << idat->mainmsgport->mp_SigBit;
  2519.     while ((!done) && (!prefs_call))
  2520.         {
  2521.         signals = Wait(winsig | appwinsig);
  2522.         if (signals & winsig)
  2523.             {
  2524.             while ((!done) && (!prefs_call) && (msg = GT_GetIMsg(idat->mainwin->UserPort)))
  2525.                 {
  2526.                 msg_gad = (struct Gadget *)msg->IAddress;
  2527.                 msg_class = msg->Class;
  2528.                 msg_code = msg->Code;
  2529.                 GT_ReplyIMsg(msg);    
  2530.                 switch (msg_class) {
  2531.                     case IDCMP_CLOSEWINDOW:
  2532.                         done = TRUE;
  2533.                         if (!idat->filesaved)
  2534.                             done = ask_changed(idat, prefs, tdat);
  2535.                         break;
  2536.                     case IDCMP_GADGETUP:
  2537.                         switch (msg_gad->GadgetID) {
  2538.                             case MSG_NEW_GAD :
  2539.                                 if (! idat->filesaved)
  2540.                                     idat->filesaved = ask_changed(idat, prefs, tdat);
  2541.                                 if (idat->filesaved)
  2542.                                     {
  2543.                                     strcpy(idat->file, "");
  2544.                                     SetWindowTitles(idat->mainwin, GetString(&idat->li, MSG_UNNAMED), (UBYTE *) - 1);
  2545.                                     init_tdat(tdat, tdat_buf);
  2546.                                     write_dat(idat, tdat);
  2547.                                     idat->filesaved = TRUE;
  2548.                                     strcpy(idat->expfile, idat->file);
  2549.                                     }
  2550.                                 break;
  2551.                             case MSG_OPEN_GAD :
  2552.                                 load(idat, prefs, tdat);
  2553.                                 break;
  2554.                             case MSG_SAVE_GAD :
  2555.                                 if (strlen(idat->file) == 0)
  2556.                                     save_as(idat, prefs, tdat);
  2557.                                 else
  2558.                                     save(idat, prefs, tdat);
  2559.                                 break;
  2560.                             case MSG_SAVEAS_GAD :
  2561.                                 save_as(idat, prefs, tdat);
  2562.                                 break;
  2563.                             case MSG_EDIT_GAD :
  2564.                                 edit(idat, tdat);
  2565.                                 break;
  2566.                             case MSG_MPRINT_GAD :
  2567.                                 print_dat(idat, prefs, tdat);
  2568.                                 break;
  2569.                             case MSG_PREFS_GAD :
  2570.                                 if (! (prefs_call = prefs_window(idat, newprefs)))
  2571.                                     *newprefs = *prefs;
  2572.                                 break;
  2573.                             case MSG_QUIT_GAD :
  2574.                                 done = TRUE;
  2575.                                 if (! idat->filesaved)
  2576.                                     done = ask_changed(idat, prefs, tdat);
  2577.                                 break;
  2578.                             default:
  2579.                                 break;
  2580.                             }
  2581.                         break;
  2582.                     case IDCMP_VANILLAKEY:
  2583.                         if (msg_code == gad_key[0])
  2584.                             {
  2585.                             if (! idat->filesaved)
  2586.                                 idat->filesaved = ask_changed(idat, prefs, tdat);
  2587.                             if (idat->filesaved)
  2588.                                 {
  2589.                                 strcpy(idat->file, "");
  2590.                                 SetWindowTitles(idat->mainwin, GetString(&idat->li, MSG_UNNAMED), (UBYTE *) - 1);
  2591.                                 init_tdat(tdat, tdat_buf);
  2592.                                 write_dat(idat, tdat);
  2593.                                 idat->filesaved = TRUE;
  2594.                                 strcpy(idat->expfile, idat->file);
  2595.                                 }
  2596.                             }
  2597.                         else if (msg_code == gad_key[1])
  2598.                             load(idat, prefs, tdat);
  2599.                         else if (msg_code == gad_key[2])
  2600.                             if (strlen(idat->file) == 0)
  2601.                                 save_as(idat, prefs, tdat);
  2602.                             else
  2603.                                 save(idat, prefs, tdat);
  2604.                         else if (msg_code == gad_key[3])
  2605.                             save_as(idat, prefs, tdat);
  2606.                         else if (msg_code == gad_key[4])
  2607.                             edit(idat, tdat);
  2608.                         else if (msg_code == gad_key[5])
  2609.                             print_dat(idat, prefs, tdat);
  2610.                         else if (msg_code == gad_key[6])
  2611.                             {
  2612.                             if (! (prefs_call = prefs_window(idat, newprefs)))
  2613.                                 *newprefs = *prefs;
  2614.                             }
  2615.                         else if (msg_code == gad_key[7])
  2616.                             {
  2617.                             done = TRUE;
  2618.                             if (! idat->filesaved)
  2619.                                 done = ask_changed(idat, prefs, tdat);
  2620.                             }
  2621.                         break;
  2622.                     case IDCMP_MENUPICK:
  2623.                         menuNumber = msg_code;
  2624.                         while ((menuNumber != MENUNULL) && (!done))
  2625.                             {
  2626.                             item = ItemAddress(idat->mainmenu, menuNumber);
  2627.                             menuNum = MENUNUM(menuNumber);
  2628.                             itemNum = ITEMNUM(menuNumber);
  2629.                             switch (menuNum) {
  2630.                                 case 0:
  2631.                                     switch (itemNum) {
  2632.                                         case 0:
  2633.                                             if (! idat->filesaved)
  2634.                                                 idat->filesaved = ask_changed(idat, prefs, tdat);
  2635.                                             if (idat->filesaved)
  2636.                                                 {
  2637.                                                 strcpy(idat->file, "");
  2638.                                                 strcpy(idat->expfile, idat->file);
  2639.                                                 SetWindowTitles(idat->mainwin, GetString(&idat->li, MSG_UNNAMED), (UBYTE *) - 1);
  2640.                                                 init_tdat(tdat, tdat_buf);
  2641.                                                 write_dat(idat, tdat);
  2642.                                                 idat->filesaved = TRUE;
  2643.                                                 }
  2644.                                             break;
  2645.                                         case 1:
  2646.                                             load(idat, prefs, tdat);
  2647.                                             break;
  2648.                                         case 3:
  2649.                                             if (strlen(idat->file) == 0)
  2650.                                                 save_as(idat, prefs, tdat);
  2651.                                             else
  2652.                                                 save(idat, prefs, tdat);
  2653.                                             break;
  2654.                                         case 4:
  2655.                                             save_as(idat, prefs, tdat);
  2656.                                             break;
  2657.                                         case 6:
  2658.                                             print_dat(idat, prefs, tdat);
  2659.                                             break;
  2660.                                         case 8:
  2661.                                             edit(idat, tdat);
  2662.                                             break;
  2663.                                         case 10:
  2664.                                             if (! (prefs_call = prefs_window(idat, newprefs)))
  2665.                                                 *newprefs = *prefs;
  2666.                                             break;
  2667.                                         case 12:
  2668.                                             info(idat);
  2669.                                             break;
  2670.                                         case 14:
  2671.                                             done = TRUE;
  2672.                                             if (! idat->filesaved)
  2673.                                                 done = ask_changed(idat, prefs, tdat);
  2674.                                             break;
  2675.                                         default:
  2676.                                             break;
  2677.                                     }
  2678.                                     break;
  2679.                                 case 1:
  2680.                                     switch (itemNum) {
  2681.                                         case 0:
  2682.                                             tdat->size.line1_bold = !tdat->size.line1_bold;
  2683.                                             write_dat(idat, tdat);
  2684.                                             break;
  2685.                                         case 1:
  2686.                                             tdat->size.line2_bold = !tdat->size.line2_bold;
  2687.                                             write_dat(idat, tdat);
  2688.                                             break;
  2689.                                         case 3:
  2690.                                             if (! idat->filesaved)
  2691.                                                 idat->filesaved = ask_changed(idat, prefs, tdat);
  2692.                                             if (idat->filesaved)
  2693.                                                 {
  2694.                                                 idat->filesaved = FALSE;
  2695.                                                 clear_sides(tdat->sidea[0]);
  2696.                                                 write_dat(idat, tdat);
  2697.                                                 }
  2698.                                             break;
  2699.      
  2700.                                         default:
  2701.                                             break;
  2702.                                         }
  2703.                                     break;
  2704.                                 case 2:
  2705.                                     switch (itemNum) {
  2706.                                         case 0:
  2707.                                             exp_ascii(idat, prefs, tdat);
  2708.                                             break;
  2709.                                         default:
  2710.                                             break;
  2711.                                         }
  2712.                                     break;
  2713.                                 default:
  2714.                                     break;
  2715.                                 }
  2716.                             menuNumber = item->NextSelect;
  2717.                             }
  2718.                         break;
  2719.                     case IDCMP_REFRESHWINDOW :
  2720.                         GT_BeginRefresh(idat->mainwin);
  2721.                         write_mask(idat);
  2722.                         write_dat(idat, tdat);
  2723.                         GT_EndRefresh(idat->mainwin, TRUE);
  2724.                         break;
  2725.                     default:
  2726.                         break;
  2727.                     }
  2728.                 item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 0, NOSUB));
  2729.                 if (! (((item->Flags & CHECKED) == CHECKED) && (tdat->size.line1_bold)))
  2730.                     {
  2731.                     tdat->size.line1_bold = ((item->Flags & CHECKED) == CHECKED);
  2732.                     write_dat(idat, tdat);
  2733.                     }
  2734.                 item = ItemAddress(idat->mainmenu, FULLMENUNUM(1, 1, NOSUB));
  2735.                 if (! (((item->Flags & CHECKED) == CHECKED) && (tdat->size.line2_bold)))
  2736.                     {
  2737.                     tdat->size.line2_bold = ((item->Flags & CHECKED) == CHECKED);
  2738.                     write_dat(idat, tdat);
  2739.                     }
  2740.                 }
  2741.             }
  2742.         if (signals & appwinsig)
  2743.             {
  2744.             while (amsg = (struct AppMessage *)GetMsg(idat->mainmsgport))
  2745.                 {
  2746.                 argptr = amsg->am_ArgList;
  2747.                 if ((argptr->wa_Lock) && (*argptr->wa_Name))
  2748.                     {
  2749.                     olddir = CurrentDir(argptr->wa_Lock);
  2750.                     strcpy(idat->loadpath, argptr->wa_Name);
  2751.                     load_direct(idat, prefs, tdat);
  2752.                     CurrentDir(olddir);   
  2753.                     }
  2754.                 ReplyMsg((struct Message *) amsg);
  2755.                 }
  2756.             }
  2757.         }
  2758.     while (amsg = (struct AppMessage *)GetMsg(idat->mainmsgport))
  2759.         ReplyMsg((struct Message *)amsg);
  2760.     return prefs_call;
  2761.     }
  2762.  
  2763. void main(int argc, char **argv)
  2764.     {
  2765.     if (LocaleBase = OpenLibrary("locale.library",38L))
  2766.         {
  2767.         idat.li.li_LocaleBase = LocaleBase;
  2768.         idat.li.li_Catalog    = OpenCatalog(NULL, cat_str,
  2769.                                             OC_BuiltInCodeSet, 0,
  2770.                                             OC_Version, 2,
  2771.                                             TAG_END);
  2772.         }
  2773.     if (IntuitionBase = OpenLibrary("intuition.library",37L))
  2774.         {
  2775.         if (AslBase = OpenLibrary("asl.library",38L))
  2776.             {
  2777.             if (GfxBase = OpenLibrary("graphics.library",37L))
  2778.                 {
  2779.                 if (DiskfontBase = OpenLibrary("diskfont.library",37L))
  2780.                     {
  2781.                     if (IconBase = OpenLibrary("icon.library", 37L))
  2782.                         {
  2783.                         if (GadToolsBase = OpenLibrary("gadtools.library",37L))
  2784.                             {
  2785.                             init_tdat(&tdat, tdat_buf);
  2786.                             init_idat(&idat, &prefs, &tdat, argc, argv);
  2787.                             if (open_all(&idat, &prefs))
  2788.                                 {
  2789.                                 if (open_mainwin(&idat, &prefs, &tdat))
  2790.                                     {
  2791.                                     newprefs = prefs;
  2792.                                     while (get_input(&idat, &prefs, &newprefs, &tdat))
  2793.                                         {
  2794.                                         close_mainwin(&idat);
  2795.                                         close_all(&idat, &prefs);
  2796.                                         prefs = newprefs;
  2797.                                         if (open_all(&idat, &prefs))
  2798.                                             {
  2799.                                             if (!open_mainwin(&idat, &prefs, &tdat))
  2800.                                                 break;
  2801.                                             }
  2802.                                         else
  2803.                                             break;
  2804.                                         }
  2805.                                     }
  2806.                                 close_mainwin(&idat);
  2807.                                 }
  2808.                             close_all(&idat, &prefs);
  2809.                             CloseLibrary(GadToolsBase);
  2810.                             }
  2811.                         else
  2812.                             fehler(&idat, MSG_LIB_ERROR, "gadtools.library >= V37");
  2813.                         CloseLibrary(IconBase);
  2814.                         }
  2815.                     else
  2816.                         fehler(&idat, MSG_LIB_ERROR, "icon.library >= V37");
  2817.                     CloseLibrary(DiskfontBase);
  2818.                     }
  2819.                 else
  2820.                     fehler(&idat, MSG_LIB_ERROR, "diskfont.library >= V37");
  2821.                 CloseLibrary(GfxBase);
  2822.                 }
  2823.             else
  2824.                 fehler(&idat, MSG_LIB_ERROR, "graphics.library >= V37");
  2825.             CloseLibrary(AslBase);
  2826.             }
  2827.         else
  2828.             fehler(&idat, MSG_LIB_ERROR, "asl.library >= V38");
  2829.         CloseLibrary(IntuitionBase);
  2830.         }
  2831.     else
  2832.         {
  2833.         printf("%s\n%s\nintuition.library >= V37\n", GetString(&idat.li, MSG_ERROR),
  2834.                                                      GetString(&idat.li, MSG_LIB_ERROR));
  2835.         if (argc == 0)
  2836.             getchar();
  2837.         }
  2838.     if (LocaleBase)
  2839.         {
  2840.         CloseCatalog(idat.li.li_Catalog);
  2841.         CloseLibrary(LocaleBase);
  2842.         }
  2843.     }
  2844.  
  2845.