home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_07 / ACS.ZIP / ACS / DIR / DIR.C < prev    next >
C/C++ Source or Header  |  1992-01-28  |  6KB  |  270 lines

  1. /*
  2.     Beispielapplikation    für ACS
  3.  
  4.     "Directory"
  5.  
  6.     28.9.91            Stefan Bachert
  7.  
  8. */
  9.  
  10. #include    <tos.h>
  11. #include    <string.h>
  12. #include    <acs.h>
  13. #include    <dir.h>    
  14.  
  15. static Awindow *file_make (void *not_used);
  16. static void new_drive (void);
  17. static void new_dir (void);
  18. static void ret_dir (void);
  19. static void make_work (Awindow *window);
  20.  
  21. #include    <dir.ah>
  22.  
  23. #define    WIDTH    (80)
  24. #define    HEIGHT    (48)
  25.  
  26. typedef struct {
  27.     unsigned long drives;
  28.     char act_drive;
  29.     char path [128];
  30. } USER;
  31.  
  32.  
  33. static OBJECT  back  = {-1, -1, -1, G_BOX, NONE, AOS_FIXED, 0x00001101L, 0, 0, 100, 100};
  34. static AOBJECT back0 = { A_dummy, A_dummy, AEO, 0, NULL, NULL, 0, 0};
  35.  
  36. static OBJECT  drv   = {-1, -1, -1, G_ICON, EXIT | SELECTABLE, NORMAL, (long) &FLOPPY, 0, 0, WIDTH >> 1, HEIGHT};
  37. static AOBJECT drv0  = {new_drive, A_dummy, AEO, 0, NULL, NULL, 0, 0};
  38.  
  39. static OBJECT  ret   = {-1, -1, -1, G_ICON, EXIT | SELECTABLE, NORMAL, (long) &DOTDOT, 0, 0, WIDTH, HEIGHT};
  40. static AOBJECT ret0  = {ret_dir, A_dummy, AEO, 0, NULL, NULL, 0, 0};
  41.  
  42. static OBJECT  dirs  = {-1, -1, -1, G_ICON, EXIT | SELECTABLE, NORMAL, (long) &DIRECTORY, 0, 0, WIDTH, HEIGHT};
  43. static AOBJECT dirs0 = {new_dir, A_dummy, AEO, 0, NULL, NULL, 0, 0};
  44.  
  45. static OBJECT  files = {-1, -1, -1, G_ICON, NONE, NORMAL, (long) &FILE, 0, 0, WIDTH, HEIGHT};
  46. static AOBJECT files0= { A_dummy, A_dummy, AEO, 0, NULL, NULL, 0, 0};
  47.  
  48.  
  49. static void new_drive (void)
  50.     /*
  51.      *    Dir 
  52.      */
  53. {
  54.   Awindow *window;
  55.   USER *user;
  56.   
  57.   window = ev_window;
  58.   user = window-> user;
  59.  
  60.   user-> act_drive = (char) ev_object [ev_obnr]. ob_spec. iconblk-> ib_char - 'A';
  61.   Dsetdrv (user-> act_drive);
  62.   Dsetpath ("\\");
  63.  
  64.   make_work (window);
  65.   (window-> sized) (window, &window-> wi_act);
  66. }
  67.  
  68.  
  69. static void new_dir (void)
  70.     /*
  71.      *    Dir 
  72.      */
  73. {
  74.   Awindow *window;
  75.   USER *user;
  76.  
  77.   window = ev_window;
  78.   user = window-> user;
  79.   Dsetdrv (user-> act_drive);
  80.   Dsetpath (user-> path);
  81.   Dsetpath (window-> work [ev_obnr]. ob_spec. iconblk-> ib_ptext);
  82.   
  83.   make_work (window);
  84.   (window-> sized) (window, &window-> wi_act);
  85. }
  86.  
  87.  
  88. static void ret_dir (void)
  89.     /*
  90.      *    Dir 
  91.      */
  92. {
  93.   Awindow *window;
  94.   USER *user;
  95.  
  96.   window = ev_window;
  97.   user = window-> user;
  98.   Dsetdrv (user-> act_drive);
  99.   Dsetpath (user-> path);
  100.   Dsetpath ("..");
  101.   
  102.   make_work (window);
  103.   (window-> sized) (window, &window-> wi_act);
  104. }
  105.  
  106.  
  107. static void make_work (Awindow *window)
  108.     /*
  109.      *    Baue das innere Workobjekt zusammen
  110.      */
  111. {
  112.   USER *user;
  113.   DTA dta, *olddta;
  114.   OBJECT *work;
  115.   ICONBLK *iconblk;
  116.   char path [128];
  117.   int i, n;
  118.   long drives;
  119.   char drive;
  120.   int state;
  121.   int first;
  122.   
  123.   user = window-> user;
  124.  
  125.   olddta = Fgetdta ();
  126.   Fsetdta (&dta);            /* auf eigene Dta operieren ! wegen ACCESSORYS ! */
  127.   first = TRUE;
  128. redo:
  129.   strcpy (path, "A:"); *path += user-> act_drive;
  130.   Dgetpath (user-> path, 0); strcpy (path + 2, user-> path);
  131.   Ast_delete (window-> info);
  132.   window-> info = Ast_create (path);
  133.   strcat (path, "\\*.*");
  134.  
  135.   n = 0;
  136.   state = Fsfirst (path, FA_SUBDIR | FA_READONLY | FA_SYSTEM | FA_HIDDEN | FA_SYSTEM | FA_ARCHIVE);
  137.   while (state >= 0) {                    /* was gefunden */
  138.     n ++;
  139.     state = Fsnext ();
  140.   };
  141.   if (state == -33 && first) {        /* bei diskette mit anderen Pfad probieren */
  142.     Dsetpath ("\\");
  143.     first = FALSE;
  144.     goto redo;
  145.   };
  146.   if (window-> wi_id > 0) wind_set (window-> wi_id, WF_INFO, window-> info);
  147.  
  148.   work = Ax_malloc (((n + 17) << 1) * sizeof (AOBJECT));    /* Grösse des Objectes */
  149.   if (work == NULL) return;                /* Fehler */
  150.  
  151.   if (window-> work != NULL) Aob_delete (window-> work);
  152.   window-> work = work;
  153.  
  154.   memcpy (work, &back, sizeof (OBJECT) << 1);    /* Hintergrund */
  155.   work-> ob_head = 2;
  156.  
  157.   work += 2;
  158.   i = 4;
  159.  
  160. /*    Drives aufbauen */
  161.  
  162.   drive = 'A';
  163.   drives = user-> drives;
  164.   n = 0;
  165.   while (drives) {
  166.     if (drives & 1) {
  167.       memcpy (work, &drv, sizeof (OBJECT) << 1);
  168.       iconblk = Aic_create (drv. ob_spec. iconblk);
  169.       (char) iconblk-> ib_char = drive;
  170.       work-> ob_spec. iconblk = iconblk;
  171.       work-> ob_next = i;
  172.       i += 2;
  173.       work += 2;
  174.       n ++;
  175.     };
  176.     drives >>= 1;
  177.     drive ++;
  178.   };
  179.  
  180.   if (n & 1) {        /* ungerade, letzter doppelt so gross */
  181.     (work - 2)-> ob_width <<= 1;
  182.   };
  183.   
  184. /*    Dirs    */
  185.  
  186.   state = Fsfirst (path, FA_SUBDIR);            /* nur dirs */
  187.   dirs. ob_spec. iconblk-> ib_ptext = dta. d_fname;    /*wird dann bei create erzeugt */
  188.   while (state >= 0) {                    /* was gefunden */
  189.     if (strcmp (dta. d_fname, ".") != 0 && dta. d_attrib & FA_SUBDIR) {
  190.       if (strcmp (dta. d_fname, "..") == 0) {
  191.         memcpy (work, &ret, sizeof (OBJECT) << 1);    /* return Wert */
  192.       } else {
  193.         memcpy (work, &dirs, sizeof (OBJECT) << 1);    /* normales Dir */
  194.       };
  195.       work-> ob_spec. iconblk = Aic_create (work-> ob_spec. iconblk);
  196.       work-> ob_next = i;
  197.       i += 2;
  198.       work += 2;
  199.     };
  200.     state = Fsnext ();
  201.   };
  202.  
  203. /*    Files    */
  204.  
  205.   state = Fsfirst (path, 0x27);            /* keine dirs */
  206.   files. ob_spec. iconblk-> ib_ptext = dta. d_fname;    /*wird dann bei create erzeugt */
  207.   while (state >= 0) {                    /* was gefunden */
  208.     memcpy (work, &files, sizeof (OBJECT) << 1);
  209.     work-> ob_spec. iconblk = Aic_create (files. ob_spec. iconblk);
  210.     work-> ob_next = i;
  211.     i += 2;
  212.     work += 2;
  213.     state = Fsnext ();
  214.   };
  215.  
  216. /*    Aufräumen */
  217.  
  218.   (work - 2)-> ob_next = 0;
  219.   (work - 1)-> ob_flags |= LASTOB;
  220.   
  221.   window-> work-> ob_tail = i - 4;
  222.  
  223.   Fsetdta (olddta);
  224. }
  225.  
  226.  
  227. static Awindow *file_make (void *not_used)
  228.     /*
  229.      *    Erzeuge Directory Fenster
  230.      */
  231. {
  232.   Awindow *wi;
  233.   USER *user;
  234.  
  235.   wi = Awi_create (&DIR_WI);
  236.   if (wi == NULL) return NULL;
  237.  
  238.   user = Ax_malloc (sizeof (USER));
  239.   if (user == NULL) return NULL;
  240.  
  241.   wi-> user = user;
  242.   user-> act_drive = Dgetdrv ();                /* welche drive gibt es */
  243.   user-> drives = Dsetdrv (user-> act_drive);    /* welches ist das aktuelle */
  244.   user-> path [0] = '\0';
  245.  
  246.   make_work (wi);                    /* erzeuge das Work object */
  247.  
  248.   (wi-> open) (wi);                    /* öffne gleich, auch als accessory */
  249.   return wi;
  250. }
  251.  
  252.  
  253. int ACSinit (void)
  254.     /*
  255.      *    Doppelklick auf NEU erzeugt ein neues Fenster
  256.      */
  257. {
  258.   Awindow *window;
  259.  
  260.   window = Awi_root ();                        /* root window */
  261.  
  262.   if (window == NULL) return FAIL;            /* lege NEU Icon an */
  263.   (window-> service) (window, AS_NEWCALL, &DIR_WI. create);
  264.  
  265.   window = &DIR_WI;
  266.   (window-> create) (NULL);                    /* ein Fenster gleich erzeugen */
  267.  
  268.   return OK;
  269. }
  270.