?? api.c
字號:
} if (more == 0) { WMF_ERROR (API,"wmf_[*]alloc: insufficient memory!"); API->err = wmf_E_InsMem; return (0); } MM->max += 32; MM->list = more; } if (MM->malloc) { mem = MM->malloc (MM->context,size); } else { mem = malloc (size); } if (mem == 0) { WMF_ERROR (API,"wmf_[*]alloc: insufficient memory!"); API->err = wmf_E_InsMem; return (0); } MM->list[MM->count] = mem; MM->count++; return (mem);}/** * Allocate memory of specified size and attach to the API's memory manager's internal list. * * @param API the API handle * @param number number or elements * @param size size in bytes of memory required by one element * * With syntax similar to calloc(), wmf_calloc() allocates \p number * \p size bytes of memory and adds a * reference to it in the memory manager's list. To free the memory, use wmf_free(). * * @return Pointer to new memory, or zero on failure. * Sets error state \b wmf_E_InsMem on failure. */void* wmf_calloc (wmfAPI* API,size_t number,size_t size){ return (wmf_malloc (API,number * size));}/** * (Re)Allocate memory of specified size and attach to the API's memory manager's internal list. * * @param API the API handle * @param mem pointer to memory previously allocated via the API * @param size new size in bytes of memory required * * With syntax similar to realloc(), wmf_realloc() allocates \p size bytes of memory and adds a reference * to it in the memory manager's list. To free the memory, use wmf_free(). If \p mem is zero, this is * equivalent to a call to wmf_malloc(). If \p size is zero, the memory is released via wmf_free(). * * @return Pointer to new memory, or zero on failure. * Sets error state \b wmf_E_InsMem on failure. */void* wmf_realloc (wmfAPI* API,void* mem,size_t size){ wmfMemoryManager* MM = (wmfMemoryManager*) API->memory_data; void* more = 0; int i; if (mem == 0) return (wmf_malloc (API,size)); if (size == 0) { WMF_DEBUG (API,"wmf_realloc: attempt to allocate zero-sized memory!"); wmf_free (API,mem); return (0); } for (i = 0; i < MM->count; i++) if (MM->list[i] == mem) { if (MM->realloc) { more = MM->realloc (MM->context,mem,size); } else { more = realloc (mem,size); } if (more == 0) { WMF_ERROR (API,"wmf_[*]alloc: insufficient memory!"); API->err = wmf_E_InsMem; } else { MM->list[i] = more; } break; } return (more);}/** * Frees memory attached to the API's memory manager's internal list. * * @param API the API handle * @param mem pointer to memory previously allocated via the API * * Syntax is similar to free(). */void wmf_free (wmfAPI* API,void* mem){ wmfMemoryManager* MM = (wmfMemoryManager*) API->memory_data; int i; for (i = 0; i < MM->count; i++) if (MM->list[i] == mem) { if (MM->free) { MM->free (MM->context,mem); } else { free (mem); } MM->count--; MM->list[i] = MM->list[MM->count]; break; }}/** * Detach memory attached to the API's memory manager's internal list. * * @param API the API handle * @param mem pointer to memory previously allocated via the API * * This removes the reference in the API's memory manager's internal list, and the memory will not, * therefore, be released by wmf_api_destroy(). To free subsequently, use free(). */void wmf_detach (wmfAPI* API,void* mem){ wmfMemoryManager* MM = (wmfMemoryManager*) API->memory_data; int i; for (i = 0; i < MM->count; i++) if (MM->list[i] == mem) { MM->count--; MM->list[i] = MM->list[MM->count]; break; }}/** * Duplicate string and attach to the API's memory manager's internal list. * * @param API the API handle * @param str a string * * With syntax similar to strdup(), wmf_strdup() allocates the necessary memory via wmf_malloc() and copies * the string. Use wmf_free() to free the string. * * @return Pointer to new string, or zero on failure. * Sets error state \b wmf_E_InsMem on failure, or \b wmf_E_Glitch if str is zero. */char* wmf_strdup (wmfAPI* API,char* str){ char* cpy = 0; if (str == 0) { if (ERR (API)) return (0); WMF_ERROR (API,"wmf_strdup: attempt to copy non-existent string!"); API->err = wmf_E_Glitch; return (0); } cpy = (char*) wmf_malloc (API,strlen (str) + 1); if (ERR (API)) return (0); strcpy (cpy,str); return (cpy);}/** * Create concatenatation of two strings and attach to the API's memory manager's internal list. * * @param API the API handle * @param pre a string * @param post a string * * wmf_str_append() allocates the necessary memory via wmf_malloc(), copies \p pre into the string and * appends \p post. Use wmf_free() to free the string. * * @return Pointer to new string, or zero on failure. * Sets error state \b wmf_E_InsMem on failure, or \b wmf_E_Glitch if str is zero. */char* wmf_str_append (wmfAPI* API,char* pre,char* post){ char* cpy = 0; if ((pre == 0) && (post == 0)) return (0); if (pre == 0) return (wmf_strdup (API,post)); if (post == 0) return (wmf_strdup (API,pre)); cpy = (char*) wmf_malloc (API,strlen (pre) + strlen (post) + 1); if (ERR (API)) return (0); strcpy (cpy,pre); strcat (cpy,post); return (cpy);}/** * Substring search. * * @param hatstack a string * @param needle a substring to search for in haystack * * With syntax identical to strstr(), wmf_strstr() searches for string \p needle in string \p haystack. * * @return Pointer to substring \p needle found in \p haystack, or zero if not found. */char* wmf_strstr (const char* haystack,const char* needle){#ifdef HAVE_STRSTR return (strstr (haystack,needle));#else /* HAVE_STRSTR */ const char* ptr1; const char* ptr2; const char* ptr3; ptr1 = haystack; while (*ptr1) { ptr2 = ptr1; ptr3 = needle; while ((*ptr3) == (*ptr2)) { if ((*ptr3) == 0) break; ptr2++; ptr3++; } if ((*ptr3) == 0) break; ptr1++; } return ((*ptr1) ? (char*) ptr1 : 0);#endif /* HAVE_STRSTR */}/* Optional status call-back function * ================================== *//** * Set a status call-back function. * * @param API the API handle * @param context handle for user data * @param function call-back function * * The metafile player calls the status function after each record. */void wmf_status_function (wmfAPI* API,void* context,wmfStatus function){ API->status.context = context; API->status.function = function;}/* Check command line for arg. * =========================== */static void wmf_arg (unsigned long* flags,wmfAPI_Options* options){ char** argv = options->argv; int argc = options->argc; int arg = 0; while ((++arg) < argc) { if (strncmp (argv[arg],"--wmf-",6)) continue; if (strcmp (argv[arg],"--wmf-help") == 0) { /* This is ignored; the controlling program can check for it... */ continue; } if ((strcmp (argv[arg],"--wmf-error" ) == 0) || (strcmp (argv[arg],"--wmf-error=yes") == 0)) { (*flags) &= ~WMF_OPT_NO_ERROR; continue; } if (strcmp (argv[arg],"--wmf-error=no") == 0) { (*flags) |= WMF_OPT_NO_ERROR; continue; } if ((strcmp (argv[arg],"--wmf-debug" ) == 0) || (strcmp (argv[arg],"--wmf-debug=yes") == 0)) { (*flags) &= ~WMF_OPT_NO_DEBUG; continue; } if (strcmp (argv[arg],"--wmf-debug=no") == 0) { (*flags) |= WMF_OPT_NO_DEBUG; continue; } if (strcmp (argv[arg],"--wmf-sys-fonts") == 0) { (*flags) |= WMF_OPT_SYS_FONTS; continue; } if (strncmp (argv[arg],"--wmf-sys-fontmap=",18) == 0) { (*flags) |= WMF_OPT_SYS_FONTS; (*flags) |= WMF_OPT_SYS_FONTMAP; options->sys_fontmap_file = argv[arg] + 18; continue; } if (strcmp (argv[arg],"--wmf-xtra-fonts") == 0) { (*flags) |= WMF_OPT_XTRA_FONTS; continue; } if (strncmp (argv[arg],"--wmf-xtra-fontmap=",19) == 0) { (*flags) |= WMF_OPT_XTRA_FONTS; (*flags) |= WMF_OPT_XTRA_FONTMAP; options->xtra_fontmap_file = argv[arg] + 19; continue; } if (strncmp (argv[arg],"--wmf-gs-fontmap=",17) == 0) { (*flags) |= WMF_OPT_GS_FONTMAP; options->gs_fontmap_file = argv[arg] + 17; continue; } if ((strcmp (argv[arg],"--wmf-ignore-nonfatal" ) == 0) || (strcmp (argv[arg],"--wmf-ignore-nonfatal=yes") == 0)) { (*flags) |= WMF_OPT_IGNORE_NONFATAL; continue; } if (strcmp (argv[arg],"--wmf-ignore-nonfatal=no") == 0) { (*flags) &= ~WMF_OPT_IGNORE_NONFATAL; continue; } if (strcmp (argv[arg],"--wmf-diagnostics") == 0) { (*flags) |= WMF_OPT_DIAGNOSTICS; continue; } if (strncmp (argv[arg],"--wmf-fontdir=",14) == 0) continue; /* ignore for now */ } (*flags) &= 0x000fffff;}static void wmf_arg_fontdirs (wmfAPI* API,wmfAPI_Options* options){ char** argv = options->argv; int argc = options->argc; int arg = 0; if (API->flags & WMF_OPT_ARGS) { while ((++arg) < argc) { if (strncmp (argv[arg],"--wmf-fontdir=",14) == 0) { wmf_ipa_font_dir (API,argv[arg] + 14); } } } if (API->flags & WMF_OPT_FONTDIRS) { argv = options->fontdirs; while (*argv) { wmf_ipa_font_dir (API,(*argv)); argv++; } } wmf_ipa_font_dir (API,WMF_GS_FONTDIR); wmf_ipa_font_dir (API,WMF_FONTDIR);}/** * @verbatim Additional wmf-related options: --wmf-error[=yes|no] switch for error reports. --wmf-debug[=yes|no] switch for debug reports, if any. --wmf-ignore-nonfatal[=yes|no] switch to ignore (some) non-fatal errors. --wmf-diagnostics emit diagnostic information. --wmf-fontdir=<path> add <path> to list of font directories. --wmf-sys-fonts use system fonts, if any found. --wmf-sys-fontmap=<file> use system xml-fontmap file <file>. --wmf-xtra-fonts use non-system fonts, if any found. --wmf-xtra-fontmap=<file> use non-system xml-fontmap file <file>. --wmf-gs-fontmap=<file> use ghostscript file <file>.Report bugs to <http://www.wvware.com/>.@endverbatim * * @return Returns the above as a string. */char* wmf_help (){ static char* help = "\Additional wmf-related options:\n\\n\ --wmf-error[=yes|no] switch for error reports.\n\ --wmf-debug[=yes|no] switch for debug reports, if any.\n\ --wmf-ignore-nonfatal[=yes|no] switch to ignore (some) non-fatal errors.\n\ --wmf-diagnostics emit diagnostic information.\n\ --wmf-fontdir=<path> add <path> to list of font directories.\n\ --wmf-sys-fonts use system fonts, if any found.\n\ --wmf-sys-fontmap=<file> use system xml-fontmap file <file>.\n\ --wmf-xtra-fonts use non-system fonts, if any found.\n\ --wmf-xtra-fontmap=<file> use non-system xml-fontmap file <file>.\n\ --wmf-gs-fontmap=<file> use ghostscript file <file>.\n\\n\Report bugs to <http://www.wvware.com/>.\n"; return (help);}/** * Increase the size of the internal string buffer. * * @param API the API handle * * \b libwmf maintains an internal buffer for string operations. wmf_strbuf_grow() increases the size by 64. * * @return Returns the new size of the buffer. * Uses wmf_realloc(), so may set \b wmf_E_InsMem on failure. */unsigned long wmf_strbuf_grow (wmfAPI* API){ char* more = (char*) wmf_realloc (API,API->string_buffer.buffer,(API->string_buffer.length + 64) * sizeof (char)); if (ERR (API)) { WMF_DEBUG (API,"bailing..."); return (0); } API->string_buffer.length += 64; API->string_buffer.buffer = more; return (API->string_buffer.length);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -