Mercurial > dwindows
comparison mac/dw.m @ 1306:dbd507f42947
Added dw_debug() logging function which will output a message to the debugging console.
On Windows this uses OutputDebugMessage(), on Mac it uses NSLog() ...
The other platforms currently just dump it to stderr. Maybe more enhancements to come.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 03 Nov 2011 23:34:10 +0000 |
parents | ca02c24e80c9 |
children | c5db6c70905c |
comparison
equal
deleted
inserted
replaced
1305:18a31ab94e3d | 1306:dbd507f42947 |
---|---|
3027 } | 3027 } |
3028 return _user_dir; | 3028 return _user_dir; |
3029 } | 3029 } |
3030 | 3030 |
3031 /* | 3031 /* |
3032 * Displays a debug message on the console... | |
3033 * Parameters: | |
3034 * format: printf style format string. | |
3035 * ...: Additional variables for use in the format. | |
3036 */ | |
3037 void API dw_debug(char *format, ...) | |
3038 { | |
3039 va_list args; | |
3040 char outbuf[1025] = {0}; | |
3041 | |
3042 va_start(args, format); | |
3043 vsnprintf(outbuf, 1024, format, args); | |
3044 va_end(args); | |
3045 | |
3046 NSLog(@"%s", outbuf); | |
3047 } | |
3048 | |
3049 /* | |
3032 * Displays a Message Box with given text and title.. | 3050 * Displays a Message Box with given text and title.. |
3033 * Parameters: | 3051 * Parameters: |
3034 * title: The title of the message box. | 3052 * title: The title of the message box. |
3035 * flags: flags to indicate buttons and icon | 3053 * flags: flags to indicate buttons and icon |
3036 * format: printf style format string. | 3054 * format: printf style format string. |
3041 int iResponse; | 3059 int iResponse; |
3042 NSString *button1 = @"OK"; | 3060 NSString *button1 = @"OK"; |
3043 NSString *button2 = nil; | 3061 NSString *button2 = nil; |
3044 NSString *button3 = nil; | 3062 NSString *button3 = nil; |
3045 va_list args; | 3063 va_list args; |
3046 char outbuf[1000]; | 3064 char outbuf[1025] = {0}; |
3047 | 3065 |
3048 va_start(args, format); | 3066 va_start(args, format); |
3049 vsprintf(outbuf, format, args); | 3067 vsnprintf(outbuf, 1024, format, args); |
3050 va_end(args); | 3068 va_end(args); |
3051 | 3069 |
3052 if(flags & DW_MB_OKCANCEL) | 3070 if(flags & DW_MB_OKCANCEL) |
3053 { | 3071 { |
3054 button2 = @"Cancel"; | 3072 button2 = @"Cancel"; |
5792 char *str = *((char **)data); | 5810 char *str = *((char **)data); |
5793 object = [ NSString stringWithUTF8String:str ]; | 5811 object = [ NSString stringWithUTF8String:str ]; |
5794 } | 5812 } |
5795 else | 5813 else |
5796 { | 5814 { |
5797 char textbuffer[100]; | 5815 char textbuffer[101] = {0}; |
5798 | 5816 |
5799 if(type & DW_CFA_ULONG) | 5817 if(type & DW_CFA_ULONG) |
5800 { | 5818 { |
5801 ULONG tmp = *((ULONG *)data); | 5819 ULONG tmp = *((ULONG *)data); |
5802 | 5820 |
5803 sprintf(textbuffer, "%lu", tmp); | 5821 snprintf(textbuffer, 100, "%lu", tmp); |
5804 } | 5822 } |
5805 else if(type & DW_CFA_DATE) | 5823 else if(type & DW_CFA_DATE) |
5806 { | 5824 { |
5807 struct tm curtm; | 5825 struct tm curtm; |
5808 CDATE cdate = *((CDATE *)data); | 5826 CDATE cdate = *((CDATE *)data); |
6864 */ | 6882 */ |
6865 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) | 6883 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) |
6866 { | 6884 { |
6867 DWCalendar *calendar = handle; | 6885 DWCalendar *calendar = handle; |
6868 NSDate *date; | 6886 NSDate *date; |
6869 char buffer[100]; | 6887 char buffer[101]; |
6870 | 6888 |
6871 sprintf(buffer, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); | 6889 snprintf(buffer, 100, "%04d-%02d-%02d 00:00:00 +0600", year, month, day); |
6872 | 6890 |
6873 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; | 6891 date = [[NSDate alloc] initWithString:[ NSString stringWithUTF8String:buffer ]]; |
6874 [calendar setDateValue:date]; | 6892 [calendar setDateValue:date]; |
6875 [date release]; | 6893 [date release]; |
6876 } | 6894 } |
8793 */ | 8811 */ |
8794 int dw_module_load(char *name, HMOD *handle) | 8812 int dw_module_load(char *name, HMOD *handle) |
8795 { | 8813 { |
8796 int len; | 8814 int len; |
8797 char *newname; | 8815 char *newname; |
8798 char errorbuf[1024]; | 8816 char errorbuf[1025]; |
8799 | 8817 |
8800 | 8818 |
8801 if(!handle) | 8819 if(!handle) |
8802 return -1; | 8820 return -1; |
8803 | 8821 |
9554 * size: Size in bytes of the shared memory region to allocate. | 9572 * size: Size in bytes of the shared memory region to allocate. |
9555 * name: A string pointer to a unique memory name. | 9573 * name: A string pointer to a unique memory name. |
9556 */ | 9574 */ |
9557 HSHM dw_named_memory_new(void **dest, int size, char *name) | 9575 HSHM dw_named_memory_new(void **dest, int size, char *name) |
9558 { | 9576 { |
9559 char namebuf[1024]; | 9577 char namebuf[1025] = {0}; |
9560 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); | 9578 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); |
9561 | 9579 |
9562 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); | 9580 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); |
9563 sprintf(namebuf, "/tmp/.dw/%s", name); | 9581 snprintf(namebuf, 1024, "/tmp/.dw/%s", name); |
9564 | 9582 |
9565 if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) | 9583 if((handle->fd = open(namebuf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) < 0) |
9566 { | 9584 { |
9567 free(handle); | 9585 free(handle); |
9568 return NULL; | 9586 return NULL; |
9595 * size: Size in bytes of the shared memory region to requested. | 9613 * size: Size in bytes of the shared memory region to requested. |
9596 * name: A string pointer to a unique memory name. | 9614 * name: A string pointer to a unique memory name. |
9597 */ | 9615 */ |
9598 HSHM dw_named_memory_get(void **dest, int size, char *name) | 9616 HSHM dw_named_memory_get(void **dest, int size, char *name) |
9599 { | 9617 { |
9600 char namebuf[1024]; | 9618 char namebuf[1025]; |
9601 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); | 9619 struct _dw_unix_shm *handle = malloc(sizeof(struct _dw_unix_shm)); |
9602 | 9620 |
9603 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); | 9621 mkdir("/tmp/.dw", S_IWGRP|S_IWOTH); |
9604 sprintf(namebuf, "/tmp/.dw/%s", name); | 9622 snprintf(namebuf, 1024, "/tmp/.dw/%s", name); |
9605 | 9623 |
9606 if((handle->fd = open(namebuf, O_RDWR)) < 0) | 9624 if((handle->fd = open(namebuf, O_RDWR)) < 0) |
9607 { | 9625 { |
9608 free(handle); | 9626 free(handle); |
9609 return NULL; | 9627 return NULL; |