home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / anwend / qed453 / src / global.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  8.9 KB  |  406 lines

  1. #include <stdarg.h>
  2. #include <stat.h>
  3. #include <support.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6.  
  7. #include "global.h"
  8. #include "makro.h"
  9. #include "options.h"
  10. #include "rsc.h"
  11. #include "set.h"
  12. #include "window.h"
  13.  
  14.  
  15. /*
  16.  * exportierte Variablen
  17.  */
  18. int        fill_color;            /* aktuell eingestellte Füllfarbe */
  19.  
  20. bool        quick_close;        /* Sichern der Texte ohne Nachfrage */
  21. int        vdi_handle;            /* Virtuelles Workstation Handle */
  22.  
  23. bool        done;                    /* Ende gewählt ? */
  24.  
  25. int        desire_x, return_code;
  26. long        desire_y, undo_y;
  27.  
  28. int        font_id, font_pts, 
  29.             font_wcell, font_hcell,
  30.             min_ascii, max_ascii;
  31. bool        font_prop;
  32.  
  33. int        debug_level;
  34.  
  35. /****** lokale Variablen *****************************************************/
  36.  
  37. static bool     msleep = FALSE;
  38.  
  39. static GRECT     clip;             /* Letztes Clipping Rechteck */
  40. static bool     clip_flag;
  41.  
  42. static long        _idt;                /* Cookie für Datum und Zeit */
  43.  
  44. /*****************************************************************************/
  45. /* Maus-Routinen                                                                                                                         */
  46. /*****************************************************************************/
  47. bool mouse_sleeps(void)
  48. {
  49.     return msleep;
  50. }
  51.  
  52. void sleep_mouse(void)
  53. {
  54.     if (!msleep)
  55.     {
  56.         msleep = TRUE;
  57.         hide_mouse();
  58.     }
  59. }
  60.  
  61. void wake_mouse(void)
  62. {
  63.     if (msleep)
  64.     {
  65.         msleep = FALSE;
  66.         show_mouse();
  67.     }
  68. }
  69.  
  70. /*****************************************************************************/
  71. /* Ausgabe recht oben im Menü */
  72. void print_headline(char *str)
  73. {
  74.     GRECT    c;
  75.         
  76.     if (gl_desk.g_y != 1)        /* gl_desk.g_y = 1: Menü unsichtbar unter N.AES */
  77.     {
  78.         if (str[0] == EOS)        /* löschen */
  79.             menu_bar(menu, 1);
  80.         else
  81.         {
  82.             int     d;
  83.             int    pxy[8];
  84.             
  85.             get_clip(&c);
  86.             set_clip(FALSE, NULL);
  87.             vst_font(vdi_handle, sys_big_id);
  88.             vst_height(vdi_handle, sys_big_height, &d, &d, &d, &d);
  89.             vqt_extent(vdi_handle, str, pxy);
  90.             vswr_mode(vdi_handle, MD_TRANS);
  91.             v_gtext(vdi_handle, gl_desk.g_x + gl_desk.g_w - (pxy[2] - pxy[0]) - 20, 0, str);
  92.             vswr_mode(vdi_handle, MD_REPLACE);
  93.             vst_font(vdi_handle, font_id);
  94.             vst_point(vdi_handle, font_pts, &d, &d, &d, &d);
  95.             set_clip(TRUE, &c);
  96.         }
  97.     }
  98. }
  99.  
  100. /*****************************************************************************/
  101. bool shift_pressed(void)
  102. {
  103.     int    d, kstate;
  104.  
  105.     if (makro_play)
  106.         kstate = makro_shift;
  107.     else
  108.         graf_mkstate(&d, &d, &d, &kstate);
  109.     return ((kstate & (K_LSHIFT|K_RSHIFT)) != 0);
  110. }
  111.  
  112. /*****************************************************************************/
  113. bool inside (int x, int y, GRECT *r)
  114. {
  115.     return (x >= r->g_x && y >= r->g_y && x < r->g_x + r->g_w && y < r->g_y + r->g_h);
  116. }
  117.  
  118. /*****************************************************************************/
  119. bool get_clip (GRECT *size)
  120. {
  121.     *size = clip;
  122.     return clip_flag;
  123. }
  124.  
  125. void set_clip (bool clipflag, GRECT *size)
  126. {
  127.     int    xy[4];
  128.  
  129.     if (!clip_flag && !clipflag) 
  130.         return;                                        /* Es ist aus und bleibt aus */
  131.     clip_flag = clipflag;
  132.     if (clipflag)
  133.     {
  134.         if (size == NULL)
  135.             clip = gl_desk;                        /* Nichts definiert, nimm Desktop */
  136.         else
  137.             clip = *size;                            /* Benutze definierte Grö₧e */
  138.         xy[0] = clip.g_x;
  139.         xy[1] = clip.g_y;
  140.         xy[2] = xy[0] + clip.g_w - 1;
  141.         xy[3] = xy[1] + clip.g_h - 1;
  142.     }
  143.     else
  144.         clip = gl_desk;
  145.     vs_clip (vdi_handle, clipflag, xy);
  146. }
  147.  
  148.  
  149. /*****************************************************************************/
  150.  
  151. static int do_note(int def, int undo, char *s)
  152. {
  153.     wake_mouse();
  154.     return do_walert(def, undo, s, " qed ");
  155. }
  156.  
  157. int note(int def, int undo, int index)
  158. {
  159.     return do_note(def, undo, (char *)alertmsg[index]);
  160. }
  161.  
  162. int inote(int def, int undo, int index, int val)
  163. {
  164.     char    buf[128];
  165.     
  166.     sprintf(buf, (char *)alertmsg[index], val);
  167.     return do_note(def, undo, buf);
  168. }
  169.  
  170. int snote(int def, int undo, int index, char *val)
  171. {
  172.     char    buf[128];
  173.     
  174.     sprintf(buf, (char *)alertmsg[index], val);
  175.     return do_note(def, undo, buf);
  176. }
  177.  
  178. /***************************************************************************/
  179. /* Verschiedenes                                                                                */
  180. /***************************************************************************/
  181.  
  182. void file_name(char *fullname, char *filename, bool withoutExt)
  183. {
  184.     split_filename(fullname, NULL, filename);
  185.     if (withoutExt)
  186.     {
  187.         char    *p;
  188.  
  189.         p = strrchr(filename, '.');
  190.         if (p != NULL)
  191.             *p = EOS;
  192.     }
  193. }
  194.  
  195. /*****************************************************************************/
  196.  
  197. static void make_date(struct tm *stime, char *date)
  198. {
  199.     if (date != NULL)
  200.     {
  201.         switch ((unsigned int)_idt & 0xF00)            /* Reihenfolge im Datum */
  202.         {
  203.             case 0x000:  /* MM/DD/YYYY */
  204.                 strftime(date, 11, "%m/%d/%Y", stime);
  205.                 break;
  206.             case 0x100:  /* DD.MM.YYYY */
  207.                 strftime(date, 11, "%d.%m.%Y", stime);
  208.                 break;
  209.             default:  /* YYYY-MM-DD */
  210.                 strftime(date, 11, "%Y-%m-%d", stime);
  211.                 break;
  212.         }
  213.     }
  214. }
  215. /*****************************************************************************/
  216.  
  217. void get_datum(char *date)
  218. {
  219.     time_t        ttime;
  220.     struct tm    *stime;
  221.  
  222.     time(&ttime);
  223.     stime = localtime(&ttime);
  224.     make_date(stime, date);
  225. }
  226.  
  227. /*****************************************************************************/
  228.  
  229. long file_time(char *filename, char *date, char *time)
  230. {
  231.     struct stat    s;
  232.  
  233.     if (stat(filename, &s) == 0)
  234.     {
  235.         struct tm    *stime;
  236.  
  237.         stime = localtime(&s.st_mtime);
  238.         if (time != NULL)
  239.             strftime(time, 9, "%H:%M:%S", stime);
  240.         if (date != NULL)
  241.             make_date(stime, date);
  242.         return s.st_mtime;
  243.     }
  244.     else
  245.     {
  246.         if (time != NULL)
  247.             strcpy(time, "??");
  248.         if (date != NULL)
  249.             strcpy(date, "??");
  250.         return 0;
  251.     }
  252. }
  253.  
  254. /*****************************************************************************/
  255. long file_size(char *filename)
  256. {
  257.     struct stat    s;
  258.     
  259.     if (stat(filename, &s) == 0)
  260.         return s.st_size;
  261.     else
  262.         return 0;
  263. }
  264.  
  265. /*****************************************************************************/
  266. bool file_readonly (char *filename)
  267. {
  268.     struct stat    s;
  269.     bool        ret = FALSE;
  270.     
  271.     if (stat(filename, &s) == 0)
  272.     {
  273.         int    uid, gid;
  274.  
  275.         uid = getuid();
  276.         gid = getgid();
  277.         if (((uid == s.st_uid) && ((s.st_mode & S_IWUSR) != 0)) ||    
  278.                 /* Besitzer hat Schreibrecht */
  279.            
  280.                ((gid == s.st_gid) && ((s.st_mode & S_IWGRP) != 0)) ||    
  281.                    /* Gruppe hat Schreibrecht */
  282.             
  283.             (((s.st_mode & S_IWOTH) != 0))    ||                                
  284.                 /* Welt hat Schreibrecht */
  285.             
  286.             ((uid == 0) && ((s.st_mode & S_IWUSR) != 0)))                
  287.                 /* root darf, wenn Owner darf */
  288.             ret = FALSE;
  289.         else
  290.             ret = TRUE;
  291.     }
  292.     return ret;
  293. }
  294.  
  295.  
  296. /***************************************************************************/
  297. bool path_from_env(char *env, char *path)
  298. {
  299.     char    *p;
  300.     bool    ret = FALSE;
  301.         
  302.     p = getenv(env);
  303.     if (p != NULL)
  304.     {
  305.         strcpy(path, p);
  306.         ret = make_normalpath(path);
  307. /*
  308.         i = (int)strlen(path);
  309.         if (p[i-1] != '\\')
  310.             strcat(path, "\\");
  311. */
  312.     }
  313.     return ret;
  314. }
  315.  
  316. /***************************************************************************/
  317. bool is_bin_name(char *filename)
  318. {
  319.     char    *p;
  320.     int    i;
  321.     
  322.     p = strrchr(filename, '.');
  323.     if (p != NULL)
  324.     {
  325.         for (i = 0; i < BIN_ANZ; i++)
  326.         {
  327.             if (stricmp(p+1, bin_extension[i]) == 0)
  328.                 return TRUE;
  329.         }
  330.     }
  331.     return FALSE;
  332. }
  333.  
  334. /***************************************************************************/
  335. void font_change(void)
  336. {
  337.     int    ret, w1, w2, d, d1[5], d2[3];
  338.  
  339.     /* *_cell werden NUR hier verändert */
  340.     vst_font(vdi_handle, font_id);
  341.     font_pts = vst_point(vdi_handle, font_pts, &d, &d, 
  342.                                         &font_wcell, &font_hcell);
  343.  
  344.     vqt_width(vdi_handle, 'M', &w1, &ret, &ret);
  345.     vqt_width(vdi_handle, 'i', &w2, &ret, &ret);
  346.     font_prop = (w1 != w2);
  347.  
  348.     vqt_fontinfo(vdi_handle, &min_ascii, &max_ascii, d1, &d, d2);
  349.     if (min_ascii <= 0)
  350.         min_ascii = 1;
  351.  
  352.     /* Alle Fenster updaten */
  353.     do_all_window(CLASS_ALL, do_font_change);
  354. }
  355.  
  356. void select_font(void)
  357. {
  358.     int    n_id, n_pts;
  359.     bool    ok = FALSE;
  360.  
  361.     n_id = font_id;
  362.     n_pts = font_pts;
  363.     ok = do_fontsel(FS_M_ALL, rsc_string(SELWFONTSTR), &n_id, &n_pts);
  364.     if (ok)
  365.     {
  366.         font_id = n_id;
  367.         font_pts = n_pts;
  368.         font_change();
  369.     }
  370.     else if (n_id == -1 && n_pts == -1)
  371.         note(1, 0, NOFSL);
  372. }
  373.  
  374. /***************************************************************************/
  375. /* Initialisieren des Moduls                                                                */
  376. /***************************************************************************/
  377. void init_global (void)
  378. {
  379.     int    work_out[57];
  380.     int    ret, f_anz;
  381.  
  382.     done = FALSE;
  383.     clip_flag = TRUE;
  384.  
  385.     vdi_handle = open_vwork(work_out);
  386.     f_anz = work_out[10];
  387.  
  388.     if (gl_gdos)
  389.         f_anz += vst_load_fonts(vdi_handle, 0);
  390.  
  391.     vst_alignment(vdi_handle, TA_LEFT, TA_TOP, &ret, &ret);
  392.  
  393.     if (!getcookie("_IDT", &_idt))                /* Format für Datum und Zeit */
  394.         _idt = 0x0000112E;                            /* DD.MM.YYYY HH:MM:SS */
  395. }
  396.  
  397. /************************************************************************/
  398. /* Terminieren des Moduls                                                                */
  399. /************************************************************************/
  400. void term_global(void)
  401. {
  402.     if (gl_gdos)
  403.         vst_unload_fonts(vdi_handle, 0);
  404.     v_clsvwk(vdi_handle);
  405. }
  406.