home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / files < prev    next >
Encoding:
Text File  |  1991-02-04  |  21.9 KB  |  505 lines

  1. /* > $.CLIB.C.files
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  */
  21. #include "includes.h"
  22.  
  23.         icon    *haswin_loadiconok=0;   /* this must be accessed by menu
  24.                                            routines to allow "Files.Load"
  25.                                            selection to work */
  26. static  icon    *haswin_loadiconup=0;
  27. static  icon    *haswin_loadicondn=0;
  28. static  icon    *haswin_loadiconbusy=0;
  29.         icon    *haswin_saveiconok=0;   /* this must be accessed by menu
  30.                                            routines to allow "Files.Save"
  31.                                            selection to work */
  32. static  icon    *haswin_saveiconup=0;
  33. static  icon    *haswin_saveicondn=0;
  34. static  icon    *haswin_saveiconbusy=0;
  35.  
  36. void haswin_setsavefileroutine(int (*user)(char *, buffer *), char *name, char *type) {
  37.  
  38.         char   tmp[9];
  39.  
  40.         if ((haswin_flags & HASWIN_FLAGS_FILEAUTO) == 0) {
  41.                 haswin_internalerror("haswin_setsavefileroutine: called before file initialisation, ignored");
  42.                 return;
  43.         }
  44.         haswin_savefileroutine = user;
  45.         if (!name) {
  46.                 haswin_defaultsavefile[0] = 0;
  47.                 haswin_seticondata(haswin_saveiconname, "");
  48.                 haswin_flags &= ~HASWIN_FLAGS_FILEMENU;
  49.         } else {
  50.                 strcpy(haswin_defaultsavefile, name);
  51.                 haswin_seticondata(haswin_saveiconname, name);
  52.                 haswin_flags |= HASWIN_FLAGS_FILEMENU;
  53.                 haswin_savefiletype = haswin_encodefiletype(type);
  54.                 sprintf(tmp, "file_%3.3x", haswin_savefiletype);
  55.                 if (haswin_findsprite(tmp) != HASWIN_UNKNOWN);
  56.                         haswin_seticondata(haswin_saveicon, tmp);
  57.                 haswin_decodefiletype(haswin_savefiletype, tmp);
  58.                 haswin_seticondata(haswin_saveicontype, tmp);
  59.         }
  60. }
  61.  
  62. void haswin_setloadfileroutine(int (*user)(char *, buffer *), char *name, char *type) {
  63.  
  64.         char   tmp[9];
  65.  
  66.         if ((haswin_flags & HASWIN_FLAGS_FILEAUTO) == 0) {
  67.                 haswin_internalerror("haswin_setloadfileroutine: called before file initialisation, ignored");
  68.                 return;
  69.         }
  70.         haswin_loadfileroutine = user;
  71.         if (!name) {
  72.                 haswin_defaultloadfile[0] = 0;
  73.                 haswin_seticondata(haswin_loadiconname, "");
  74.                 haswin_flags &= ~HASWIN_FLAGS_FILEMENU;
  75.         } else {
  76.                 strcpy(haswin_defaultloadfile, name);
  77.                 haswin_seticondata(haswin_loadiconname, name);
  78.                 haswin_flags |= HASWIN_FLAGS_FILEMENU;
  79.                 haswin_loadfiletype = haswin_encodefiletype(type);
  80.                 sprintf(tmp, "file_%3.3x", haswin_loadfiletype);
  81.                 if (haswin_findsprite(tmp) != HASWIN_UNKNOWN);
  82.                         haswin_seticondata(haswin_loadicon, tmp);
  83.                 haswin_decodefiletype(haswin_loadfiletype, tmp);
  84.                 haswin_seticondata(haswin_loadicontype, tmp);
  85.         }
  86. }
  87.  
  88. void haswin_setautoloadroutine(int (*user)(char *, buffer *), char *type) {
  89.  
  90.         if ((haswin_flags & HASWIN_FLAGS_FILEAUTO) == 0) {
  91.                 haswin_internalerror("haswin_setautoloadroutine: called before file initialisation, ignored");
  92.                 return;
  93.         }
  94.         haswin_autoloadroutine = user;
  95.         haswin_autoloadtype = haswin_encodefiletype(type);
  96. }
  97.  
  98. void haswin_loadfilemugwatch(int direction) {
  99.  
  100. static  char    spin[] = "rotor_0";
  101.  
  102.         if ((haswin_flags & HASWIN_FLAGS_FILEAUTO) == 0) {
  103.                 haswin_internalerror("haswin_loadfilemugwatch: called before file initialisation, ignored");
  104.                 return;
  105.         }
  106.         if (direction == 0)
  107.                 spin[6] = '0';
  108.         else if (direction > 0) {
  109.                 if (++spin[6] >= '9')
  110.                         spin[6] = '1';
  111.         } else if (direction < 0) {
  112.                 if (--spin[6] <= '0')
  113.                         spin[6] = '8';
  114.         }
  115.         haswin_seticondata(haswin_loadiconbusy, spin);
  116. }
  117.  
  118. void haswin_savefilemugwatch(int direction) {
  119.  
  120. static  char    spin[] = "rotor_0";
  121.  
  122.         if ((haswin_flags & HASWIN_FLAGS_FILEAUTO) == 0) {
  123.                 haswin_internalerror("haswin_savefilemugwatch: called before file initialisation, ignored");
  124.                 return;
  125.         }
  126.         if (direction == 0)
  127.                 spin[6] = '0';
  128.         else if (direction > 0) {
  129.                 if (++spin[6] >= '9')
  130.                         spin[6] = '1';
  131.         } else if (direction < 0) {
  132.                 if (--spin[6] <= '0')
  133.                         spin[6] = '8';
  134.         }
  135.         haswin_seticondata(haswin_saveiconbusy, spin);
  136. }
  137.  
  138. int filemousebutton(icon *ic, buffer *pbuf) {
  139.  
  140.         char            type[9], str[256];
  141.         int             i, oldtype = 0, button;
  142.         buffer          mybuf;
  143.  
  144.         if ((ic == haswin_saveiconname) || (ic == haswin_saveiconok)) {
  145.                 if (haswin_savefileroutine) {
  146.                         strcpy(str,haswin_geticontitle(haswin_saveiconname));
  147.                         for (i=asciilen(str); i>=0; i--)
  148.                                 if (str[i] == '.')
  149.                                         break;
  150.                         strcpy(haswin_defaultsavefile, &(str[i+1]));
  151.                         haswin_seticondata(haswin_saveiconname,
  152.                                 haswin_defaultsavefile);
  153.                         /* make a Message Data Block as if we called the
  154.                            user routine from a WIMP DataSave Message */
  155.                         button = pbuf->i[2] & POINTER_MOUSEBUTTONS;
  156.                         mybuf.i[ 1] = 0;
  157.                         mybuf.i[ 2] = 0;
  158.                         mybuf.i[ 3] = 0;
  159.                         mybuf.i[ 4] = MESSAGE_DataSave;
  160.                         mybuf.i[ 5] = pbuf->i[3];
  161.                         mybuf.i[ 6] = pbuf->i[4];
  162.                         mybuf.i[ 7] = pbuf->i[0];
  163.                         mybuf.i[ 8] = pbuf->i[1];
  164.                         mybuf.i[ 9] = 0;
  165.                         mybuf.i[10] = haswin_savefiletype;
  166.                         strcpy(&mybuf.c[44], haswin_defaultsavefile);
  167.                         mybuf.i[ 0] = (48+asciilen(haswin_defaultsavefile))&0xFFFFFFFC;
  168.                         if (((*haswin_savefileroutine)(haswin_defaultsavefile, &mybuf)) && (button == POINTER_MOUSE_L)) {
  169.                                 /*
  170.                                  * close any open menus cos we probably came
  171.                                  * from one.
  172.                                  */
  173.                                 haswin_closewindow(haswin_saveingwindow);
  174.                                 haswin_removemenu();
  175.                         }
  176.                         if ((*haswin_savefileroutine)(&mybuf.c[44], 0))
  177.                                 haswin_setfiletype(&mybuf.c[44],mybuf.i[10]);
  178.                         haswin_flags &= ~HASWIN_FLAGS_SAVING;
  179.                 } else {
  180.                         haswin_interrorprintf("cannot save '%s', no user routine", haswin_defaultsavefile);
  181.                 }
  182.                 haswin_closewindow(haswin_saveingwindow);
  183.         } else if ((ic==haswin_loadiconname) || (ic==haswin_loadiconok)) {
  184.                 if (haswin_loadfileroutine) {
  185.                         strcpy(str,haswin_geticontitle(haswin_loadiconname));
  186.                         for (i=asciilen(str); i>=0; i--)
  187.                                 if (str[i] == '.')
  188.                                         break;
  189.                         strcpy(haswin_defaultloadfile, &(str[i+1]));
  190.                         haswin_seticondata(haswin_loadiconname,
  191.                                 haswin_defaultloadfile);
  192.                         /* make a Message Data Block as if we called the
  193.                            user routine from a WIMP DataLoad Message */
  194.                         button = pbuf->i[2]&POINTER_MOUSEBUTTONS;
  195.                         mybuf.i[ 1] = 0;
  196.                         mybuf.i[ 2] = 0;
  197.                         mybuf.i[ 3] = 0;
  198.                         mybuf.i[ 4] = MESSAGE_DataLoad;
  199.                         mybuf.i[ 5] = pbuf->i[3];
  200.                         mybuf.i[ 6] = pbuf->i[4];
  201.                         mybuf.i[ 7] = pbuf->i[0];
  202.                         mybuf.i[ 8] = pbuf->i[1];
  203.                         mybuf.i[ 9] = 0;
  204.                         mybuf.i[10] = haswin_loadfiletype;
  205.                         strcpy(&mybuf.c[44], haswin_defaultloadfile);
  206.                         mybuf.i[ 0] = (48+asciilen(haswin_defaultloadfile))&0xFFFFFFFC;
  207.                         if (((*haswin_loadfileroutine)(haswin_defaultloadfile, &mybuf)) && (button == POINTER_MOUSE_L)) {
  208.                                 /*
  209.                                  * close any open menus cos we probably came
  210.                                  * from one.
  211.                                  */
  212.                                 haswin_closewindow(haswin_loadingwindow);
  213.                                 haswin_removemenu();
  214.                         }
  215.                 } else {
  216.                         haswin_interrorprintf("cannot load '%s', no user routine", haswin_defaultloadfile);
  217.                 }
  218.                 haswin_closewindow(haswin_loadingwindow);
  219.         } else if (ic == haswin_loadiconup) {
  220.                 oldtype = 0;
  221.                 do {
  222.                         if ((++oldtype & 0x07) == 0)
  223.                                 haswin_loadfilemugwatch(+1);
  224.                         if (++haswin_loadfiletype >= 0x1000)
  225.                                 haswin_loadfiletype = 0;
  226.                         sprintf(type, "file_%3.3x", haswin_loadfiletype);
  227.                 } while (haswin_findsprite(type) == HASWIN_UNKNOWN);
  228.                 haswin_seticondata(haswin_loadicon, type);
  229.                 haswin_decodefiletype(haswin_loadfiletype, type);
  230.                 haswin_seticondata(haswin_loadicontype, type);
  231.                 haswin_loadfilemugwatch(0);
  232.         } else if (ic == haswin_loadicondn) {
  233.                 oldtype = 0;
  234.                 do {
  235.                         if ((++oldtype & 0x07) == 0)
  236.                                 haswin_loadfilemugwatch(-1);
  237.                         if (--haswin_loadfiletype <= 0)
  238.                                 haswin_loadfiletype = 0xFFF;
  239.                         sprintf(type, "file_%3.3x", haswin_loadfiletype);
  240.                 } while (haswin_findsprite(type) == HASWIN_UNKNOWN);
  241.                 haswin_seticondata(haswin_loadicon, type);
  242.                 haswin_decodefiletype(haswin_loadfiletype, type);
  243.                 haswin_seticondata(haswin_loadicontype, type);
  244.                 haswin_loadfilemugwatch(0);
  245.         } else if (ic == haswin_saveiconup) {
  246.                 oldtype = 0;
  247.                 do {
  248.                         if ((++oldtype & 0x07) == 0)
  249.                                 haswin_savefilemugwatch(+1);
  250.                         if (++haswin_savefiletype >= 0x1000)
  251.                                 haswin_savefiletype = 0;
  252.                         sprintf(type, "file_%3.3x", haswin_savefiletype);
  253.                 } while (haswin_findsprite(type) == HASWIN_UNKNOWN);
  254.                 haswin_seticondata(haswin_saveicon, type);
  255.                 haswin_decodefiletype(haswin_savefiletype, type);
  256.                 haswin_seticondata(haswin_saveicontype, type);
  257.                 haswin_savefilemugwatch(0);
  258.         } else if (ic == haswin_saveicondn) {
  259.                 oldtype = 0;
  260.                 do {
  261.                         if ((++oldtype & 0x07) == 0)
  262.                                 haswin_savefilemugwatch(-1);
  263.                         if (--haswin_savefiletype <= 0)
  264.                                 haswin_savefiletype = 0xFFF;
  265.                         sprintf(type, "file_%3.3x", haswin_savefiletype);
  266.                 } while (haswin_findsprite(type) == HASWIN_UNKNOWN);
  267.                 haswin_seticondata(haswin_saveicon, type);
  268.                 haswin_decodefiletype(haswin_savefiletype, type);
  269.                 haswin_seticondata(haswin_saveicontype, type);
  270.                 haswin_savefilemugwatch(0);
  271.         } else if (ic == haswin_loadicontype) {
  272.                 haswin_loadfiletype = haswin_encodefiletype(haswin_geticontitle(ic));
  273.                 sprintf(type, "file_%3.3x", haswin_loadfiletype);
  274.                 if (haswin_findsprite(type) == HASWIN_UNKNOWN)
  275.                         strcpy(type, "file_xxx");
  276.                 haswin_seticondata(haswin_loadicon, type);
  277.                 haswin_decodefiletype(haswin_loadfiletype, type);
  278.                 haswin_seticondata(haswin_loadicontype, type);
  279.         } else if (ic == haswin_saveicontype) {
  280.                 haswin_savefiletype = haswin_encodefiletype(haswin_geticontitle(ic));
  281.                 sprintf(type, "file_%3.3x", haswin_savefiletype);
  282.                 if (haswin_findsprite(type) == HASWIN_UNKNOWN)
  283.                         strcpy(type, "file_xxx");
  284.                 haswin_seticondata(haswin_saveicon, type);
  285.                 haswin_decodefiletype(haswin_savefiletype, type);
  286.                 haswin_seticondata(haswin_saveicontype, type);
  287.         }
  288.         return(HASWIN_TRUE);
  289. }
  290.  
  291. static int savefiledrag(window *win, icon *ic, pointer *mouse, buffer *pbuf) {
  292.  
  293.         int                     i, buttons;
  294.         _kernel_swi_regs        regs;
  295.         char                    str[256];
  296.  
  297.         if ((ic != haswin_saveicon) || (win != haswin_saveingwindow))
  298.                 return(HASWIN_FALSE);
  299.         if (pbuf == 0)
  300.                 /* drag started, let it continue */
  301.                 return(HASWIN_TRUE);
  302.         haswin_flags |= HASWIN_FLAGS_SAVING;
  303.         strcpy(str, haswin_geticontitle(haswin_saveiconname));
  304.         for (i=asciilen(str); i>=0; i--)
  305.                 if (str[i] == '.')
  306.                         break;
  307.         strcpy(haswin_defaultsavefile, &(str[i+1]));
  308.         buttons = mouse->buttons;
  309.         mouse = haswin_getpointerinfo(mouse);
  310.         pbuf->i[ 3] = 0;
  311.         pbuf->i[ 4] = MESSAGE_DataSave;
  312.         pbuf->i[ 5] = mouse->whandle;
  313.         pbuf->i[ 6] = mouse->ihandle;
  314.         pbuf->i[ 7] = mouse->mx;
  315.         pbuf->i[ 8] = mouse->my;
  316.         pbuf->i[ 9] = 0;
  317.         pbuf->i[10] = haswin_savefiletype;
  318.         strcpy(&(pbuf->c[44]), haswin_defaultsavefile);
  319.         pbuf->i[ 0]=(48+asciilen(haswin_defaultsavefile)) & 0xFFFFFFFC;
  320.         regs.r[0] = HASWIN_POLL_Message_Rec;
  321.         regs.r[1] = (int)pbuf;
  322.         regs.r[2] = mouse->whandle;
  323.         regs.r[3] = mouse->ihandle;
  324.         if ((buttons&POINTER_MOUSEBUTTONS) == POINTER_MOUSE_L) {
  325.                 /*
  326.                  * close any open menus cos we probably came from one.
  327.                  */
  328.                 haswin_removemenu();
  329.                 haswin_closewindow(haswin_saveingwindow);
  330.         }
  331.         return(haswin_swi(HASWIN_Send_message, ®s));
  332. }
  333.  
  334. static int loadfiledrag(window *win, icon *ic, pointer *mouse, buffer *pbuf) {
  335.  
  336.         int                     i, buttons;
  337.         _kernel_swi_regs        regs;
  338.         char                    str[256];
  339.  
  340.         if ((ic != haswin_loadicon) || (win != haswin_loadingwindow))
  341.                 return(HASWIN_FALSE);
  342.         if (pbuf == 0)
  343.                 /* drag started, let it continue */
  344.                 return(HASWIN_TRUE);
  345.         haswin_flags |= HASWIN_FLAGS_LOADING;
  346.         strcpy(str, haswin_geticontitle(haswin_loadiconname));
  347.         for (i=asciilen(str); i>=0; i--)
  348.                 if (str[i] == '.')
  349.                         break;
  350.         strcpy(haswin_defaultloadfile, &(str[i+1]));
  351.         buttons = mouse->buttons;
  352.         mouse = haswin_getpointerinfo(0);
  353.         pbuf->i[ 3] = 0;
  354.         pbuf->i[ 4] = MESSAGE_DataSave;
  355.         pbuf->i[ 5] = mouse->whandle;
  356.         pbuf->i[ 6] = mouse->ihandle;
  357.         pbuf->i[ 7] = mouse->mx;
  358.         pbuf->i[ 8] = mouse->my;
  359.         pbuf->i[ 9] = 0;
  360.         pbuf->i[10] = haswin_loadfiletype;
  361.         strcpy(&(pbuf->c[44]), haswin_defaultloadfile);
  362.         pbuf->i[ 0]=(48+asciilen(haswin_defaultloadfile)) & 0xFFFFFFFC;
  363.         regs.r[0] = HASWIN_POLL_Message_Rec;
  364.         regs.r[1] = (int)pbuf;
  365.         regs.r[2] = mouse->whandle;
  366.         regs.r[3] = mouse->ihandle;
  367.         if ((buttons&POINTER_MOUSEBUTTONS) == POINTER_MOUSE_L) {
  368.                 /*
  369.                  * close any open menus cos we probably came from one.
  370.                  */
  371.                 haswin_removemenu();
  372.                 haswin_closewindow(haswin_loadingwindow);
  373.         }
  374.         return(haswin_swi(HASWIN_Send_message, ®s));
  375. }
  376.  
  377. /*
  378.  *      this routine initialises all of the variables used by the HASWIN
  379.  *      automatic file load/save routines.
  380.  */
  381. int haswin_fileinitialise() {
  382.  
  383.         haswin_saveingwindow = haswin_makewindow("Save as:", 250, 240, 7, 2, 7, 1, WINDOW_TITLE_BAR|WINDOW_MOVEABLE);
  384.         haswin_saveingwindow->name = haswin_realloc(haswin_saveingwindow->name, 10, "haswin_fileinitialise", "save window name");
  385.         strcpy(haswin_saveingwindow->name, "file_save");
  386.         haswin_saveingwindow->pointer = haswin_makepointer("ptr_disc", 5, 0);
  387.         haswin_saveiconup = haswin_createicon(haswin_saveingwindow, "P2 S^:uparrow", 7, 0, 0, 8, -160, 35, -110);
  388.         haswin_saveiconup->mousebutton = filemousebutton;
  389.         haswin_saveicondn = haswin_createicon(haswin_saveingwindow, "P2 S^:downarrow", 7, 0, 0, 215, -160, 242, -110);
  390.         haswin_saveicondn->mousebutton = filemousebutton;
  391.         haswin_saveicon = haswin_createicon(haswin_saveingwindow, "SD^:file_xxx", 7, 0, 0, 85, -90, 160, -25);
  392.         haswin_saveicon->dragroutine = savefiledrag;
  393.         haswin_saveiconname = haswin_createicon(haswin_saveingwindow, "BFT+256 ^:SaveFile", 7, 0, 0, 8, -232, 185, -182);
  394.         haswin_saveiconname->mousebutton = filemousebutton;
  395.         haswin_saveiconok = haswin_createicon(haswin_saveingwindow, "P9 TFB^:OK", 7, 14, 1, 190, -232, 240, -182);
  396.         haswin_saveiconok->mousebutton = filemousebutton;
  397.         haswin_saveicontype = haswin_createicon(haswin_saveingwindow, "P15 BFT+15 ^:file_xxx", 7, 0, 0, 45, -160, 205, -110);
  398.         haswin_saveicontype->mousebutton = filemousebutton;
  399.         haswin_saveiconbusy = haswin_createicon(haswin_saveingwindow, "P0 S^:rotor_0", 7, 0, 0, 10, -73, 60, -23);
  400.  
  401.         haswin_loadingwindow = haswin_makewindow("Load from:", 250, 240, 7, 2, 7, 1, WINDOW_TITLE_BAR|WINDOW_MOVEABLE);
  402.         haswin_loadingwindow->name = haswin_realloc(haswin_loadingwindow->name, 10, "haswin_fileinitialise", "load window name");
  403.         strcpy(haswin_loadingwindow->name, "file_load");
  404.         haswin_loadingwindow->pointer = haswin_makepointer("ptr_disc", 5, 0);
  405.         haswin_loadiconup = haswin_createicon(haswin_loadingwindow, "P2 S^:uparrow", 7, 0, 0, 8, -160, 35, -110);
  406.         haswin_loadiconup->mousebutton = filemousebutton;
  407.         haswin_loadicondn = haswin_createicon(haswin_loadingwindow, "P2 S^:downarrow", 7, 0, 0, 215, -160, 242, -110);
  408.         haswin_loadicondn->mousebutton = filemousebutton;
  409.         haswin_loadicon = haswin_createicon(haswin_loadingwindow, "SD^:file_xxx", 7, 0, 0, 85, -90, 160, -25);
  410.         haswin_loadicon->dragroutine = loadfiledrag;
  411.         haswin_loadiconname = haswin_createicon(haswin_loadingwindow, "BFT+256 ^:LoadFile", 7, 0, 0, 8, -232, 185, -182);
  412.         haswin_loadiconname->mousebutton = filemousebutton;
  413.         haswin_loadiconok = haswin_createicon(haswin_loadingwindow, "P9 TFB^:OK", 7, 14, 1, 190, -232, 240, -182);
  414.         haswin_loadiconok->mousebutton = filemousebutton;
  415.         haswin_loadicontype = haswin_createicon(haswin_loadingwindow, "P15 BFT+15 ^:file_xxx", 7, 0, 0, 45, -160, 205, -110);
  416.         haswin_loadicontype->mousebutton = filemousebutton;
  417.         haswin_loadiconbusy = haswin_createicon(haswin_loadingwindow, "P0 S^:rotor_0", 7, 0, 0, 10, -73, 60, -23);
  418.  
  419.         haswin_flags |= HASWIN_FLAGS_FILEAUTO;
  420.         return(HASWIN_TRUE);
  421. }
  422.  
  423. /*
  424.  *      routine to convert a filetype from integer into text
  425.  */
  426. void haswin_decodefiletype(int type, char *str) {
  427.  
  428.         _kernel_swi_regs  regs, ans;
  429.         _kernel_oserror   *err;
  430.  
  431.         if (type == 0x1000) {
  432.                 strcpy(str, "Dir.    ");
  433.                 return;
  434.         }
  435.         if (type == 0x2000) {
  436.                 strcpy(str, "Appl.   ");
  437.                 return;
  438.         }
  439.         regs.r[0] = 18;
  440.         regs.r[2] = type;
  441.         if ((err = _kernel_swi(OS_FSControl|SWI_X, ®s, &ans)) == 0) {
  442.                 ((int *)str)[0] = ans.r[2];
  443.                 ((int *)str)[1] = ans.r[3];
  444.         } else {
  445.                 haswin_interrorprintf("haswin_decodefiletype, filetype %X, %s", type, err->errmess);
  446.                 /* put spaces in str */
  447.                 ((int *)str)[0] = 0x20202020;
  448.                 ((int *)str)[1] = 0x20202020;
  449.         }
  450.         str[8] = 0;
  451.         return;
  452. }
  453.  
  454. /*
  455.  *      routine to convert a filetype from text into an integer
  456.  */
  457. int haswin_encodefiletype(char *str) {
  458.  
  459.         _kernel_swi_regs  regs, ans;
  460.         _kernel_oserror   *err;
  461.  
  462.         if (!strncmp(str, "Dir.", 4))
  463.                 return(0x1000);
  464.         if (!strncmp(str, "Appl.", 5))
  465.                 return(0x2000);
  466.         regs.r[0] = 31;
  467.         regs.r[1] = (int)str;
  468.         if ((err = _kernel_swi(OS_FSControl|SWI_X, ®s, &ans)) == 0)
  469.                 return(ans.r[2]);
  470.         haswin_interrorprintf("haswin_encodefiletype, filetype '%s', %s",
  471.                 str, err->errmess);
  472.         return(0);
  473. }
  474.  
  475. /*
  476.  *      routine to convert a set a filetype in the filesystem
  477.  */
  478. int haswin_setfiletype(char *name, int type) {
  479.  
  480.         _kernel_swi_regs        regs;
  481.  
  482.         regs.r[0] = 18;
  483.         regs.r[1] = (int)name;
  484.         regs.r[2] = type & 0x00000FFF;
  485.         return(haswin_swi(OS_File, ®s));
  486. }
  487.  
  488. int haswin_clearfileoptions(int new) {
  489.  
  490.         haswin_fileoptions &= ~new;
  491.         return(haswin_fileoptions);
  492. }
  493.  
  494. int haswin_getfileoptions(void) {
  495.  
  496.         return(haswin_fileoptions);
  497. }
  498.  
  499. int haswin_setfileoptions(int new) {
  500.  
  501.         haswin_fileoptions |= new;
  502.         return(haswin_fileoptions);
  503. }
  504.  
  505.