Subversion Repositories Kolibri OS

Rev

Rev 1408 | Rev 1616 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include <types.h>
  3. #include <syscall.h>
  4.  
  5. #pragma pack(push, 1)
  6. typedef struct
  7. {
  8.   char sec;
  9.   char min;
  10.   char hour;
  11.   char rsv;
  12. }detime_t;
  13.  
  14. typedef struct
  15. {
  16.   char  day;
  17.   char  month;
  18.   short year;
  19. }dedate_t;
  20.  
  21. typedef struct
  22. {
  23.   unsigned    attr;
  24.   unsigned    flags;
  25.   union
  26.   {
  27.      detime_t  ctime;
  28.      unsigned  cr_time;
  29.   };
  30.   union
  31.   {
  32.      dedate_t  cdate;
  33.      unsigned  cr_date;
  34.   };
  35.   union
  36.   {
  37.      detime_t  atime;
  38.      unsigned  acc_time;
  39.   };
  40.   union
  41.   {
  42.      dedate_t  adate;
  43.      unsigned  acc_date;
  44.   };
  45.   union
  46.   {
  47.      detime_t  mtime;
  48.      unsigned  mod_time;
  49.   };
  50.   union
  51.   {
  52.      dedate_t  mdate;
  53.      unsigned  mod_date;
  54.   };
  55.   unsigned    size;
  56.   unsigned    size_high;
  57. } FILEINFO;
  58.  
  59. #pragma pack(pop)
  60.  
  61. typedef struct
  62. {
  63.   char *path;
  64.   int  offset;
  65. } dbgfile_t;
  66.  
  67. static dbgfile_t dbgfile;
  68.  
  69. #define va_start(v,l)   __builtin_va_start(v,l)
  70. #define va_end(v)       __builtin_va_end(v)
  71. #define va_arg(v,l)     __builtin_va_arg(v,l)
  72. #define __va_copy(d,s)  __builtin_va_copy(d,s)
  73.  
  74. typedef __builtin_va_list __gnuc_va_list;
  75. typedef __gnuc_va_list    va_list;
  76.  
  77. #define arg(x) va_arg (ap, u32_t)
  78.  
  79. int dbg_open(char *path)
  80. {
  81.     FILEINFO info;
  82.  
  83.     dbgfile.offset = 0;
  84.  
  85.     if(get_fileinfo(path,&info))
  86.     {
  87.         if(!create_file(path))
  88.         {
  89.             dbgfile.path = path;
  90.             return true;
  91.         }
  92.         else return false;
  93.     };
  94.     set_file_size(path, 0);
  95.     dbgfile.path   = path;
  96.     dbgfile.offset = 0;
  97.     return true;
  98. };
  99.  
  100. int vsnprintf(char *s, size_t n, const char *format, va_list arg);
  101.  
  102.  
  103. int printf(const char* format, ...)
  104. {
  105.     char  txtbuf[256];
  106.     int   len = 0;
  107.  
  108.     va_list ap;
  109.  
  110.     va_start(ap, format);
  111.     if (format)
  112.         len = vsnprintf(txtbuf, 256, format, ap);
  113.     va_end(ap);
  114.  
  115.     if( len )
  116.         SysMsgBoardStr(txtbuf);
  117.  
  118.     return len;
  119. }
  120.  
  121.  
  122. int dbgprintf(const char* format, ...)
  123. {
  124.     char      txtbuf[256];
  125.     unsigned  writes;
  126.     int       len = 0;
  127.  
  128.     va_list   ap;
  129.  
  130.     va_start(ap, format);
  131.     if (format)
  132.       len = vsnprintf(txtbuf, 256, format, ap);
  133.     va_end(ap);
  134.  
  135.     if( len )
  136.     {
  137.         SysMsgBoardStr(txtbuf);
  138.  
  139. /*  do not write into log file if interrupts disabled */
  140.  
  141.         if ( (get_eflags() & (1 << 9)) && dbgfile.path)
  142.         {
  143.             write_file(dbgfile.path,txtbuf,dbgfile.offset,len,&writes);
  144.             dbgfile.offset+=writes;
  145.         };
  146.     };
  147.     return len;
  148. }
  149.  
  150. int xf86DrvMsg(int skip, int code, const char* format, ...)
  151. {
  152.     char      txtbuf[256];
  153.     unsigned  writes;
  154.     va_list   ap;
  155.  
  156.     int       len = 0;
  157.  
  158.     va_start(ap, format);
  159.     if (format)
  160.         len = vsnprintf(txtbuf, 256, format, ap);
  161.     va_end(ap);
  162.  
  163.     if( len )
  164.     {
  165.         SysMsgBoardStr(txtbuf);
  166.  
  167.         if(dbgfile.path)
  168.         {
  169.             write_file(dbgfile.path,txtbuf,dbgfile.offset,len,&writes);
  170.             dbgfile.offset+=writes;
  171.         };
  172.     };
  173.     return len;
  174. }
  175.  
  176. int snprintf(char *s, size_t n, const char *format, ...)
  177. {
  178.         va_list ap;
  179.         int retval;
  180.  
  181.         va_start(ap, format);
  182.         retval = vsnprintf(s, n, format, ap);
  183.         va_end(ap);
  184.  
  185.         return retval;
  186. }
  187.  
  188.  
  189.  
  190.