src/osd/windows/main.c
| r7076 | r7077 | |
| 2 | 2 | // |
| 3 | 3 | // main.c - Win32 main program |
| 4 | 4 | // |
| 5 | | // Copyright Nicola Salmoria and the MAME Team. |
| 6 | | // Visit http://mamedev.org for licensing and usage restrictions. |
| 5 | //============================================================ |
| 7 | 6 | // |
| 7 | // Copyright Aaron Giles |
| 8 | // All rights reserved. |
| 9 | // |
| 10 | // Redistribution and use in source and binary forms, with or |
| 11 | // without modification, are permitted provided that the |
| 12 | // following conditions are met: |
| 13 | // |
| 14 | // * Redistributions of source code must retain the above |
| 15 | // copyright notice, this list of conditions and the |
| 16 | // following disclaimer. |
| 17 | // * Redistributions in binary form must reproduce the |
| 18 | // above copyright notice, this list of conditions and |
| 19 | // the following disclaimer in the documentation and/or |
| 20 | // other materials provided with the distribution. |
| 21 | // * Neither the name 'MAME' nor the names of its |
| 22 | // contributors may be used to endorse or promote |
| 23 | // products derived from this software without specific |
| 24 | // prior written permission. |
| 25 | // |
| 26 | // THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND |
| 27 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 28 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 29 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 30 | // EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 31 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | // DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 33 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 34 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 35 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 36 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 37 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 38 | // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 | // |
| 8 | 40 | //============================================================ |
| 9 | 41 | |
| 10 | 42 | // standard windows headers |
| r7076 | r7077 | |
| 15 | 47 | // MAMEOS headers |
| 16 | 48 | #include "strconv.h" |
| 17 | 49 | |
| 18 | | extern int utf8_main(int argc, char **argv); |
| 50 | extern int utf8_main(int argc, char *argv[]); |
| 19 | 51 | |
| 20 | 52 | |
| 21 | 53 | |
| r7076 | r7077 | |
| 24 | 56 | //============================================================ |
| 25 | 57 | |
| 26 | 58 | // undo the command-line #define that maps main to utf8_main in all other cases |
| 27 | | #ifndef MESSLIB |
| 28 | | #if !defined(WINUI) || defined(MESS) |
| 59 | #ifndef WINUI |
| 29 | 60 | #undef main |
| 30 | 61 | #undef wmain |
| 31 | 62 | #endif |
| 32 | | #endif |
| 33 | 63 | |
| 34 | | #ifdef __GNUC__ |
| 35 | | int main(int argc, char **a_argv) |
| 36 | | #else // !__GNUC__ |
| 37 | | int _tmain(int argc, TCHAR **argv) |
| 38 | | #endif // __GNUC__ |
| 64 | extern "C" int _tmain(int argc, TCHAR **argv) |
| 39 | 65 | { |
| 40 | 66 | int i, rc; |
| 41 | 67 | char **utf8_argv; |
| 42 | 68 | |
| 43 | | #ifdef __GNUC__ |
| 44 | | TCHAR **argv; |
| 45 | | #ifdef UNICODE |
| 46 | | // MinGW doesn't support wmain() directly, so we have to jump through some hoops |
| 47 | | extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, int expand_wildcards, int *startupinfo); |
| 48 | | WCHAR **wenviron; |
| 49 | | int startupinfo; |
| 50 | | __wgetmainargs(&argc, &argv, &wenviron, 0, &startupinfo); |
| 51 | | #else // !UNICODE |
| 52 | | argv = a_argv; |
| 53 | | #endif // UNICODE |
| 54 | | #endif // __GNUC__ |
| 55 | | |
| 56 | | #ifdef MALLOC_DEBUG |
| 57 | | { |
| 58 | | extern int winalloc_in_main_code; |
| 59 | | winalloc_in_main_code = TRUE; |
| 60 | | #endif |
| 61 | | |
| 62 | 69 | /* convert arguments to UTF-8 */ |
| 63 | 70 | utf8_argv = (char **) malloc(argc * sizeof(*argv)); |
| 64 | 71 | if (utf8_argv == NULL) |
| r7076 | r7077 | |
| 78 | 85 | free(utf8_argv[i]); |
| 79 | 86 | free(utf8_argv); |
| 80 | 87 | |
| 81 | | #ifdef MALLOC_DEBUG |
| 82 | | { |
| 83 | | void check_unfreed_mem(void); |
| 84 | | check_unfreed_mem(); |
| 85 | | } |
| 86 | | winalloc_in_main_code = FALSE; |
| 87 | | } |
| 88 | | #endif |
| 89 | | |
| 90 | 88 | return rc; |
| 91 | 89 | } |
src/mess/osd/sdl/glob.c
| r7076 | r7077 | |
| 158 | 158 | static void g_Ctoc __P((const Char *, char *)); |
| 159 | 159 | //static int g_lstat __P((Char *, struct stat *, glob_t *)); |
| 160 | 160 | static osd_directory *g_opendir __P((Char *, glob_t *)); |
| 161 | | static Char *g_strchr __P((const Char *, int)); |
| 161 | static Char *g_strchr __P((Char *, int)); |
| 162 | 162 | #ifdef notdef |
| 163 | 163 | static Char *g_strcat __P((Char *, const Char *)); |
| 164 | 164 | #endif |
| r7076 | r7077 | |
| 176 | 176 | static void qprintf __P((const char *, Char *)); |
| 177 | 177 | #endif |
| 178 | 178 | |
| 179 | | int |
| 180 | | glob(pattern, flags, errfunc, pglob) |
| 181 | | const char *pattern; |
| 182 | | int flags, (*errfunc) __P((const char *, int)); |
| 183 | | glob_t *pglob; |
| 179 | int glob (const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob) |
| 184 | 180 | { |
| 185 | 181 | const u_char *patnext; |
| 186 | 182 | int c; |
| r7076 | r7077 | |
| 228 | 224 | * invoke the standard globbing routine to glob the rest of the magic |
| 229 | 225 | * characters |
| 230 | 226 | */ |
| 231 | | static int globexp1(pattern, pglob) |
| 232 | | const Char *pattern; |
| 233 | | glob_t *pglob; |
| 227 | static int globexp1(const Char *pattern, glob_t *pglob) |
| 234 | 228 | { |
| 235 | | const Char* ptr = pattern; |
| 229 | const Char* ptr = (const Char *) pattern; |
| 236 | 230 | int rv; |
| 237 | 231 | |
| 238 | 232 | /* Protect a single {}, for find(1), like csh */ |
| 239 | 233 | if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) |
| 240 | 234 | return glob0(pattern, pglob); |
| 241 | 235 | |
| 242 | | while ((ptr = (const Char *) g_strchr(ptr, LBRACE)) != NULL) |
| 236 | while ((ptr = (Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) |
| 243 | 237 | if (!globexp2(ptr, pattern, pglob, &rv)) |
| 244 | 238 | return rv; |
| 245 | 239 | |
| r7076 | r7077 | |
| 252 | 246 | * If it succeeds then it invokes globexp1 with the new pattern. |
| 253 | 247 | * If it fails then it tries to glob the rest of the pattern and returns. |
| 254 | 248 | */ |
| 255 | | static int globexp2(ptr, pattern, pglob, rv) |
| 256 | | const Char *ptr, *pattern; |
| 257 | | glob_t *pglob; |
| 258 | | int *rv; |
| 249 | static int globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv) |
| 259 | 250 | { |
| 260 | 251 | int i; |
| 261 | 252 | Char *lm, *ls; |
| r7076 | r7077 | |
| 357 | 348 | /* |
| 358 | 349 | * expand tilde from the passwd file. |
| 359 | 350 | */ |
| 360 | | static const Char * |
| 361 | | globtilde(pattern, patbuf, patbuf_len, pglob) |
| 362 | | const Char *pattern; |
| 363 | | Char *patbuf; |
| 364 | | size_t patbuf_len; |
| 365 | | glob_t *pglob; |
| 351 | static const Char *globtilde(const Char *pattern,Char *patbuf, size_t patbuf_len, glob_t *pglob) |
| 366 | 352 | { |
| 367 | 353 | struct passwd *pwd; |
| 368 | 354 | char *h; |
| r7076 | r7077 | |
| 428 | 414 | * if things went well, nonzero if errors occurred. It is not an error |
| 429 | 415 | * to find no matches. |
| 430 | 416 | */ |
| 431 | | static int |
| 432 | | glob0(pattern, pglob) |
| 433 | | const Char *pattern; |
| 434 | | glob_t *pglob; |
| 417 | static int glob0(const Char *pattern,glob_t *pglob) |
| 435 | 418 | { |
| 436 | 419 | const Char *qpatnext; |
| 437 | 420 | int c, err, oldpathc; |
| r7076 | r7077 | |
| 513 | 496 | return(0); |
| 514 | 497 | } |
| 515 | 498 | |
| 516 | | static int compare(p, q) |
| 517 | | const void *p, *q; |
| 499 | static int compare(const void *p, const void *q) |
| 518 | 500 | { |
| 519 | 501 | return(strcmp(*(char **)p, *(char **)q)); |
| 520 | 502 | } |
| 521 | 503 | |
| 522 | | static int |
| 523 | | glob1(pattern, pglob) |
| 524 | | Char *pattern; |
| 525 | | glob_t *pglob; |
| 504 | static int glob1(Char *pattern,glob_t *pglob) |
| 526 | 505 | { |
| 527 | 506 | Char pathbuf[_MAX_PATH+1]; |
| 528 | 507 | |
| r7076 | r7077 | |
| 537 | 516 | * of recursion for each segment in the pattern that contains one or more |
| 538 | 517 | * meta characters. |
| 539 | 518 | */ |
| 540 | | static int |
| 541 | | glob2(pathbuf, pathend, pattern, pglob) |
| 542 | | Char *pathbuf, *pathend, *pattern; |
| 543 | | glob_t *pglob; |
| 519 | static int glob2(Char *pathbuf, Char *pathend, Char *pattern,glob_t *pglob) |
| 544 | 520 | { |
| 545 | 521 | Char *p, *q; |
| 546 | 522 | int anymeta; |
| r7076 | r7077 | |
| 595 | 571 | /* NOTREACHED */ |
| 596 | 572 | } |
| 597 | 573 | |
| 598 | | static int |
| 599 | | glob3(pathbuf, pathend, pattern, restpattern, pglob) |
| 600 | | Char *pathbuf, *pathend, *pattern, *restpattern; |
| 601 | | glob_t *pglob; |
| 574 | static int glob3(Char *pathbuf,Char *pathend,Char *pattern,Char *restpattern,glob_t *pglob) |
| 602 | 575 | { |
| 603 | 576 | register const osd_directory_entry *dp; |
| 604 | 577 | osd_directory *dirp; |
| r7076 | r7077 | |
| 676 | 649 | * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and |
| 677 | 650 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. |
| 678 | 651 | */ |
| 679 | | static int |
| 680 | | globextend(path, pglob) |
| 681 | | const Char *path; |
| 682 | | glob_t *pglob; |
| 652 | static int globextend(const Char *path, glob_t *pglob) |
| 683 | 653 | { |
| 684 | 654 | register char **pathv; |
| 685 | 655 | register int i; |
| r7076 | r7077 | |
| 689 | 659 | |
| 690 | 660 | newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); |
| 691 | 661 | pathv = pglob->gl_pathv ? |
| 692 | | realloc((char *)pglob->gl_pathv, newsize) : |
| 693 | | malloc(newsize); |
| 662 | (char **)realloc(pglob->gl_pathv, newsize) : |
| 663 | (char **)malloc(newsize); |
| 694 | 664 | if (pathv == NULL) |
| 695 | 665 | return(GLOB_NOSPACE); |
| 696 | 666 | |
| r7076 | r7077 | |
| 704 | 674 | |
| 705 | 675 | for (p = path; *p++;) |
| 706 | 676 | continue; |
| 707 | | if ((copy = malloc(p - path)) != NULL) { |
| 677 | if ((copy = (char *)malloc(p - path)) != NULL) { |
| 708 | 678 | g_Ctoc(path, copy); |
| 709 | 679 | pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; |
| 710 | 680 | } |
| r7076 | r7077 | |
| 716 | 686 | * pattern matching function for filenames. Each occurrence of the * |
| 717 | 687 | * pattern causes a recursion level. |
| 718 | 688 | */ |
| 719 | | static int |
| 720 | | match(name, pat, patend) |
| 721 | | register Char *name, *pat, *patend; |
| 689 | static int match(register Char *name, register Char *pat, register Char *patend) |
| 722 | 690 | { |
| 723 | 691 | int ok, negate_range; |
| 724 | 692 | Char c, k; |
| r7076 | r7077 | |
| 764 | 732 | } |
| 765 | 733 | |
| 766 | 734 | /* Free allocated data belonging to a glob_t structure. */ |
| 767 | | void |
| 768 | | globfree(pglob) |
| 769 | | glob_t *pglob; |
| 735 | void globfree(glob_t *pglob) |
| 770 | 736 | { |
| 771 | 737 | register int i; |
| 772 | 738 | register char **pp; |
| r7076 | r7077 | |
| 780 | 746 | } |
| 781 | 747 | } |
| 782 | 748 | |
| 783 | | static osd_directory * |
| 784 | | g_opendir(str, pglob) |
| 785 | | register Char *str; |
| 786 | | glob_t *pglob; |
| 749 | static osd_directory *g_opendir(register Char *str,glob_t *pglob) |
| 787 | 750 | { |
| 788 | 751 | char buf[_MAX_PATH]; |
| 789 | 752 | |
| r7076 | r7077 | |
| 793 | 756 | g_Ctoc(str, buf); |
| 794 | 757 | |
| 795 | 758 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
| 796 | | return((*pglob->gl_opendir)(buf)); |
| 759 | return((osd_directory *)(*pglob->gl_opendir)(buf)); |
| 797 | 760 | |
| 798 | 761 | return osd_opendir(buf); |
| 799 | 762 | } |
| 800 | | #if 0 |
| 801 | | static int |
| 802 | | g_lstat(fn, sb, pglob) |
| 803 | | register Char *fn; |
| 804 | | struct stat *sb; |
| 805 | | glob_t *pglob; |
| 806 | | { |
| 807 | | char buf[_MAX_PATH]; |
| 808 | 763 | |
| 809 | | g_Ctoc(fn, buf); |
| 810 | | if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
| 811 | | return((*pglob->gl_lstat)(buf, sb)); |
| 812 | | return (lstat(buf, sb)); |
| 813 | | } |
| 814 | | |
| 815 | | static int |
| 816 | | g_stat(fn, sb, pglob) |
| 817 | | register Char *fn; |
| 818 | | struct stat *sb; |
| 819 | | glob_t *pglob; |
| 764 | static Char *g_strchr(Char *str,int ch) |
| 820 | 765 | { |
| 821 | | char buf[_MAX_PATH]; |
| 822 | | |
| 823 | | g_Ctoc(fn, buf); |
| 824 | | if (pglob->gl_flags & GLOB_ALTDIRFUNC) |
| 825 | | return((*pglob->gl_stat)(buf, sb)); |
| 826 | | return(stat(buf, sb)); |
| 827 | | } |
| 828 | | #endif |
| 829 | | static Char * |
| 830 | | g_strchr(str, ch) |
| 831 | | const Char *str; |
| 832 | | int ch; |
| 833 | | { |
| 834 | 766 | do { |
| 835 | 767 | if (*str == ch) |
| 836 | | return ((Char *)str); |
| 768 | return (str); |
| 837 | 769 | } while (*str++); |
| 838 | 770 | return (NULL); |
| 839 | 771 | } |
| r7076 | r7077 | |
| 856 | 788 | } |
| 857 | 789 | #endif |
| 858 | 790 | |
| 859 | | static void |
| 860 | | g_Ctoc(str, buf) |
| 861 | | register const Char *str; |
| 862 | | char *buf; |
| 791 | static void g_Ctoc(register const Char *str, char *buf) |
| 863 | 792 | { |
| 864 | 793 | register char *dc; |
| 865 | 794 | |