Changeset 985 for trunk/dll/assoc.c
- Timestamp:
- Mar 1, 2008, 2:37:14 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/assoc.c
r959 r985 16 16 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat 17 17 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry 18 29 Feb 08 GKY Changes to enable user settable command line length 19 29 Feb 08 GKY Use xfree where appropriate 18 20 19 21 **************************************************************************************/ … … 40 42 typedef struct 41 43 { 42 CHAR mask[CCHMAXPATH];43 CHAR cl[MAXCOMLINESTRG];44 CHAR sig[CCHMAXPATH];45 44 LONG offset; 46 45 ULONG flags; 46 PSZ pszCmdLine; 47 CHAR mask[CCHMAXPATH]; 48 CHAR sig[CCHMAXPATH]; 47 49 } 48 50 ASSOC; … … 51 53 { 52 54 CHAR *mask; 53 CHAR *cl;55 PSZ pszCmdLine; 54 56 CHAR *sig; 55 57 LONG offset; … … 118 120 next = info->next; 119 121 xfree(info->mask); 120 xfree(info-> cl);122 xfree(info->pszCmdLine); 121 123 xfree(info->sig); 122 124 xfree(info); … … 130 132 FILE *fp; 131 133 LINKASSOC *info; 132 CHAR cl[1024];134 PSZ pszCmdLine; 133 135 CHAR mask[CCHMAXPATH + 24]; 134 136 CHAR sig[CCHMAXPATH + 24]; … … 144 146 strcat(mask, "ASSOC.DAT"); 145 147 fp = _fsopen(mask, "r", SH_DENYWR); 148 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 149 if (!pszCmdLine) { 150 if (fp) 151 fclose(fp); //already complained 152 } 146 153 if (fp) { 147 154 while (!feof(fp)) { … … 152 159 if (!*mask || *mask == ';') 153 160 continue; 154 if (!xfgets( cl, sizeof(cl), fp, pszSrcFile, __LINE__) ||161 if (!xfgets(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__) || 155 162 !xfgets(sig, CCHMAXPATH + 24, fp, pszSrcFile, __LINE__) || 156 163 !xfgets(offset, sizeof(offset), fp, pszSrcFile, __LINE__) || 157 164 !xfgets(flags, sizeof(flags), fp, pszSrcFile, __LINE__)) 158 165 break; /* error! */ 159 cl[1000] = 0;160 bstripcr( cl);166 pszCmdLine[MaxComLineStrg - 1] = 0; 167 bstripcr(pszCmdLine); 161 168 sig[CCHMAXPATH] = 0; 162 169 bstripcr(sig); … … 165 172 flags[34] = 0; 166 173 bstripcr(flags); 167 if (!* cl)174 if (!*pszCmdLine) 168 175 continue; 169 176 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__); 170 177 if (info) { 171 info-> cl = xstrdup(cl, pszSrcFile, __LINE__);178 info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__); 172 179 info->mask = xstrdup(mask, pszSrcFile, __LINE__); 173 180 if (*sig) … … 175 182 info->offset = atol(offset); 176 183 info->flags = atol(flags); 177 if (!info-> cl|| !info->mask) {178 xfree(info-> cl);184 if (!info->pszCmdLine || !info->mask) { 185 xfree(info->pszCmdLine); 179 186 xfree(info->mask); 180 187 xfree(info); … … 191 198 } 192 199 fclose(fp); 200 } 201 } 202 203 VOID display_associations(HWND hwnd, ASSOC *temp, LINKASSOC *info) 204 { 205 CHAR szEnviroment[2048]; 206 PSZ pszDisplayStr; 207 SHORT x; 208 209 *szEnviroment = 0; 210 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 2048, szEnviroment); 211 bstripcr(szEnviroment); 212 if (*szEnviroment) 213 PrfWriteProfileString(fmprof, FM3Str, temp->pszCmdLine, szEnviroment); 214 pszDisplayStr = xmallocz((CCHMAXPATH * 2) + MaxComLineStrg + 6, 215 pszSrcFile, __LINE__); 216 if (pszDisplayStr) { 217 sprintf(pszDisplayStr, "%-12s \x1a %-24s %s%s%s", temp->mask, 218 temp->pszCmdLine, (*temp->sig) ? 219 "[" : NullStr, (*temp->sig) ? temp->sig : NullStr, 220 (*temp->sig) ? "]" : NullStr); 221 x = (SHORT) WinSendDlgItemMsg(hwnd, 222 ASS_LISTBOX, 223 LM_INSERTITEM, 224 MPFROM2SHORT(LIT_END, 0), MPFROMP(pszDisplayStr)); 225 if (x >= 0) { 226 WinSendDlgItemMsg(hwnd, 227 ASS_LISTBOX, 228 LM_SETITEMHANDLE, 229 MPFROMSHORT(x), MPFROMP(info)); 230 WinSendDlgItemMsg(hwnd, 231 ASS_LISTBOX, 232 LM_SELECTITEM, 233 MPFROMSHORT(x), MPFROMSHORT(TRUE)); 234 } 235 xfree(pszDisplayStr); 193 236 } 194 237 } … … 232 275 while (info) { 233 276 fprintf(fp, 234 ";\n%0.*s\n%0. 1000s\n%0.*s\n%lu\n%lu\n",277 ";\n%0.*s\n%0.4096s\n%0.*s\n%lu\n%lu\n", 235 278 CCHMAXPATH, 236 279 info->mask, 237 info-> cl,280 info->pszCmdLine, 238 281 CCHMAXPATH, 239 282 (info->sig) ? info->sig : NullStr, info->offset, info->flags); … … 248 291 LINKASSOC *info; 249 292 250 if (addme && *addme-> cl&& *addme->mask) {293 if (addme && *addme->pszCmdLine && *addme->mask) { 251 294 info = asshead; 252 295 while (info) { … … 260 303 info = xmallocz(sizeof(LINKASSOC), pszSrcFile, __LINE__); 261 304 if (info) { 262 info-> cl = xstrdup(addme->cl, pszSrcFile, __LINE__);305 info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__); 263 306 info->mask = xstrdup(addme->mask, pszSrcFile, __LINE__); 264 307 if (*addme->sig) … … 268 311 if (addme->flags) 269 312 info->flags = addme->flags; 270 if (!info-> cl|| !info->mask) {271 xfree(info-> cl);313 if (!info->pszCmdLine || !info->mask) { 314 xfree(info->pszCmdLine); 272 315 xfree(info->mask); 273 316 xfree(info); … … 315 358 asstail = info->prev; 316 359 } 317 xfree(info-> cl);360 xfree(info->pszCmdLine); 318 361 xfree(info->mask); 319 362 xfree(info->sig); … … 392 435 393 436 if (fAmAV2) { 394 if (stristr(info-> cl, "AV2.EXE") ||395 stristr(info-> cl, "AV2.CMD") || stristr(info->cl, "<>"))437 if (stristr(info->pszCmdLine, "AV2.EXE") || 438 stristr(info->pszCmdLine, "AV2.CMD") || stristr(info->pszCmdLine, "<>")) 396 439 return -1; 397 440 } 398 if (!strcmp(info-> cl, "<>")) {441 if (!strcmp(info->pszCmdLine, "<>")) { 399 442 OpenObject(datafile, Default, hwnd); 400 443 return 0; … … 414 457 flags &= (~DIEAFTER); 415 458 rc = ExecOnList(hwnd, 416 info-> cl,459 info->pszCmdLine, 417 460 flags, 418 461 NULL, list, GetPString(IDS_EXECASSOCTITLETEXT), … … 467 510 case UM_UNDO: 468 511 { 469 CHAR s[ 1002 + CCHMAXPATH +6];512 CHAR s[4096]; 470 513 471 514 WinSendDlgItemMsg(hwnd, ASS_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); … … 475 518 "%-12s \x1a %-24s %s%s%s", 476 519 info->mask, 477 info-> cl,520 info->pszCmdLine, 478 521 (info->sig && *info->sig) ? 479 522 "[" : NullStr, … … 518 561 } 519 562 WinSetDlgItemText(hwnd, ASS_MASK, info->mask); 520 WinSetDlgItemText(hwnd, ASS_CL, info-> cl);563 WinSetDlgItemText(hwnd, ASS_CL, info->pszCmdLine); 521 564 WinSetDlgItemText(hwnd, ASS_SIG, 522 565 (info->sig && *info->sig) ? info->sig : NullStr); … … 545 588 size = sizeof(env) - 1; 546 589 if (PrfQueryProfileData(fmprof, 547 FM3Str, info-> cl, env, &size) && *env)590 FM3Str, info->pszCmdLine, env, &size) && *env) 548 591 WinSetDlgItemText(hwnd, ASS_ENVIRON, env); 549 592 else … … 629 672 replace = FALSE; 630 673 674 memset(&temp, 0, sizeof(ASSOC)); 675 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 676 if (!temp.pszCmdLine) 677 break; //already complained 678 631 679 { 632 680 x = (SHORT) WinSendDlgItemMsg(hwnd, … … 639 687 MPFROMSHORT(0), MPFROMSHORT(TRUE)); 640 688 } 641 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__); 642 if (!pszWorkBuf) 689 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 690 if (!pszWorkBuf) { 691 xfree(temp.pszCmdLine); 643 692 break; //already complained 644 memset(&temp, 0, sizeof(ASSOC)); 693 } 645 694 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 646 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl); 647 NormalizeCmdLine(pszWorkBuf, temp.cl); 648 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1); 695 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine); 696 if (strcmp(temp.pszCmdLine, "<>")) { 697 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine); 698 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1); 699 } 649 700 xfree(pszWorkBuf); 650 701 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig); … … 655 706 } 656 707 bstrip(temp.mask); 657 bstrip(temp. cl);708 bstrip(temp.pszCmdLine); 658 709 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT)) 659 710 temp.flags = 0; … … 674 725 if (fCancelAction){ 675 726 fCancelAction = FALSE; 727 xfree(temp.pszCmdLine); 676 728 break; 677 729 } … … 680 732 if (!info) 681 733 WinDismissDlg(hwnd, 1); /* Runtime_Error(pszSrcFile, __LINE__, "add_association"); */ 682 else { 683 684 CHAR s[1002 + CCHMAXPATH + 6]; 685 686 *s = 0; 687 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s); 688 bstripcr(s); 689 if (*s) 690 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s); 691 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask, 692 temp.cl, (*temp.sig) ? 693 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr, 694 (*temp.sig) ? "]" : NullStr); 695 x = (SHORT) WinSendDlgItemMsg(hwnd, 696 ASS_LISTBOX, 697 LM_INSERTITEM, 698 MPFROM2SHORT(LIT_END, 0), MPFROMP(s)); 699 if (x >= 0) { 700 WinSendDlgItemMsg(hwnd, 701 ASS_LISTBOX, 702 LM_SETITEMHANDLE, 703 MPFROMSHORT(x), MPFROMP(info)); 704 WinSendDlgItemMsg(hwnd, 705 ASS_LISTBOX, 706 LM_SELECTITEM, 707 MPFROMSHORT(x), MPFROMSHORT(TRUE)); 708 } 734 else { 735 display_associations(hwnd, &temp, info); 709 736 save_associations(); 710 } 737 } 738 xfree(temp.pszCmdLine); 711 739 } 712 740 WinDismissDlg(hwnd, 1); … … 728 756 CHAR dummy[34]; 729 757 PSZ pszWorkBuf; 730 replace = FALSE; 731 732 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__); 733 if (!pszWorkBuf) 758 replace = FALSE; 759 760 memset(&temp, 0, sizeof(ASSOC)); 761 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 762 if (!temp.pszCmdLine) 734 763 break; //already complained 735 memset(&temp, 0, sizeof(ASSOC)); 736 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 737 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl); 738 NormalizeCmdLine(pszWorkBuf, temp.cl); 739 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1); 764 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 765 if (!pszWorkBuf) { 766 xfree(temp.pszCmdLine); 767 break; //already complained 768 } 769 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 770 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine); 771 if (strcmp(temp.pszCmdLine, "<>")) { 772 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine); 773 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1); 774 } 740 775 xfree(pszWorkBuf); 741 776 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig); … … 746 781 } 747 782 bstrip(temp.mask); 748 bstrip(temp. cl);783 bstrip(temp.pszCmdLine); 749 784 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT)) 750 785 temp.flags = 0; … … 765 800 if (fCancelAction){ 766 801 fCancelAction = FALSE; 802 xfree(temp.pszCmdLine); 767 803 break; 768 804 } … … 771 807 //Add will fail if mask is not changed 772 808 if (info) { 773 774 CHAR s[1002 + CCHMAXPATH + 6]; 775 776 *s = 0; 777 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s); 778 bstripcr(s); 779 if (*s) 780 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s); 781 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask, 782 temp.cl, (*temp.sig) ? 783 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr, 784 (*temp.sig) ? "]" : NullStr); 785 x = (SHORT) WinSendDlgItemMsg(hwnd, 786 ASS_LISTBOX, 787 LM_INSERTITEM, 788 MPFROM2SHORT(LIT_END, 0), MPFROMP(s)); 789 if (x >= 0) { 790 WinSendDlgItemMsg(hwnd, 791 ASS_LISTBOX, 792 LM_SETITEMHANDLE, 793 MPFROMSHORT(x), MPFROMP(info)); 794 WinSendDlgItemMsg(hwnd, 795 ASS_LISTBOX, 796 LM_SELECTITEM, 797 MPFROMSHORT(x), MPFROMSHORT(TRUE)); 798 } 809 display_associations(hwnd, &temp, info); 799 810 save_associations(); 800 811 } 812 xfree(temp.pszCmdLine); 801 813 } 802 814 break; … … 805 817 { 806 818 ASSOC temp; 807 CHAR dummy[34]; 808 809 memset(&temp, 0, sizeof(ASSOC)); 819 CHAR dummy[34]; 820 821 memset(&temp, 0, sizeof(ASSOC)); 822 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 823 if (!temp.pszCmdLine) 824 break; //already complained 810 825 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 811 826 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig); … … 817 832 bstrip(temp.mask); 818 833 PrfWriteProfileData(fmprof, FM3Str, temp.mask, NULL, 0L); 819 if (kill_association(&temp)) 820 /* Runtime_Error(pszSrcFile, __LINE__, "kill_association"); 821 else */{ 834 if (kill_association(&temp)) { 822 835 x = (SHORT) WinSendDlgItemMsg(hwnd, 823 836 ASS_LISTBOX, … … 832 845 } 833 846 save_associations(); 834 } 835 } 847 } 848 xfree(temp.pszCmdLine); 849 } 850 836 851 break; 837 852 case ASS_REPLACE: … … 841 856 CHAR dummy[34]; 842 857 PSZ pszWorkBuf; 843 replace = TRUE; 844 858 replace = TRUE; 859 860 memset(&temp, 0, sizeof(ASSOC)); 861 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 862 if (!temp.pszCmdLine) 863 break; //already complained 845 864 y = (SHORT) WinSendDlgItemMsg(hwnd, 846 865 ASS_LISTBOX, 847 866 LM_QUERYSELECTION, 848 867 MPFROMSHORT(LIT_CURSOR), MPVOID); 849 pszWorkBuf = xmalloc(MAXCOMLINESTRG, pszSrcFile, __LINE__); 850 if (!pszWorkBuf) 868 pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 869 if (!pszWorkBuf) { 870 xfree(temp.pszCmdLine); 851 871 break; //already complained 852 memset(&temp, 0, sizeof(ASSOC)); 872 } 853 873 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 854 WinQueryDlgItemText(hwnd, ASS_CL, sizeof(temp.cl), temp.cl); 855 NormalizeCmdLine(pszWorkBuf, temp.cl); 856 memcpy(temp.cl, pszWorkBuf, strlen(pszWorkBuf) + 1); 874 WinQueryDlgItemText(hwnd, ASS_CL, MaxComLineStrg, temp.pszCmdLine); 875 if (strcmp(temp.pszCmdLine, "<>")) { 876 NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine); 877 memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1); 878 } 857 879 xfree(pszWorkBuf); 858 880 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig); … … 863 885 } 864 886 bstrip(temp.mask); 865 bstrip(temp. cl);887 bstrip(temp.pszCmdLine); 866 888 if (WinQueryButtonCheckstate(hwnd, ASS_DEFAULT)) 867 889 temp.flags = 0; … … 882 904 if (fCancelAction){ 883 905 fCancelAction = FALSE; 906 xfree(temp.pszCmdLine); 884 907 break; 885 908 } 886 909 else 887 910 info = add_association(&temp); 888 //Add will fail if mask is not changed889 911 if (info) { 890 891 CHAR s[1002 + CCHMAXPATH + 6]; 892 893 *s = 0; 894 WinQueryDlgItemText(hwnd, ASS_ENVIRON, 1000, s); 895 bstripcr(s); 896 if (*s) 897 PrfWriteProfileString(fmprof, FM3Str, temp.cl, s); 898 sprintf(s, "%-12s \x1a %-24s %s%s%s", temp.mask, 899 temp.cl, (*temp.sig) ? 900 "[" : NullStr, (*temp.sig) ? temp.sig : NullStr, 901 (*temp.sig) ? "]" : NullStr); 902 x = (SHORT) WinSendDlgItemMsg(hwnd, 903 ASS_LISTBOX, 904 LM_INSERTITEM, 905 MPFROM2SHORT(LIT_END, 0), MPFROMP(s)); 906 if (x >= 0) { 907 WinSendDlgItemMsg(hwnd, 908 ASS_LISTBOX, 909 LM_SETITEMHANDLE, 910 MPFROMSHORT(x), MPFROMP(info)); 911 WinSendDlgItemMsg(hwnd, 912 ASS_LISTBOX, 913 LM_SELECTITEM, 914 MPFROMSHORT(x), MPFROMSHORT(TRUE)); 915 } 912 display_associations(hwnd, &temp, info); 916 913 save_associations(); 917 } 914 } 915 xfree(temp.pszCmdLine); 918 916 } 919 917 { 920 918 ASSOC temp; 921 CHAR dummy[34]; 922 919 CHAR dummy[34]; 920 921 temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__); 922 if (!temp.pszCmdLine) 923 break; //already complained 923 924 WinSendDlgItemMsg(hwnd, 924 925 ASS_LISTBOX, 925 926 LM_SELECTITEM, MPFROMSHORT(y), MPFROMSHORT(TRUE)); 926 memset(&temp, 0, sizeof(ASSOC)); 927 memset(temp.sig, 0, sizeof(temp.sig)); 928 memset(temp.mask, 0, sizeof(temp.mask)); 929 temp.offset = 0; 927 930 WinQueryDlgItemText(hwnd, ASS_MASK, sizeof(temp.mask), temp.mask); 928 931 WinQueryDlgItemText(hwnd, ASS_SIG, sizeof(temp.sig), temp.sig); … … 946 949 } 947 950 save_associations(); 948 } 951 } 952 xfree(temp.pszCmdLine); 949 953 } 950 954 break; … … 968 972 } 969 973 970 #pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations )974 #pragma alloc_text(ASSOC2,free_commands,load_associations,save_associations,display_associations) 971 975 #pragma alloc_text(ASSOC2,ExecAssociation,AssocTextProc) 972 976 #pragma alloc_text(ASSOC,add_association,kill_association,AssocDlgProc,EditAssociations)
Note:
See TracChangeset
for help on using the changeset viewer.