Changeset 1004 for trunk/dll/cmdline.c
- Timestamp:
- Apr 20, 2008, 7:59:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/cmdline.c
r985 r1004 17 17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat 18 18 29 Feb 08 GKY Use xfree where appropriate 19 20 Apr 08 GKY New variable names; Save and Load command lines of user set length 19 20 20 21 ***********************************************************************/ … … 35 36 #include "strutil.h" // GetPString 36 37 #include "fm3dll.h" 38 #include "pathutil.h" // MaxCmdLineStr 37 39 38 40 static PSZ pszSrcFile = __FILE__; 39 41 40 #define MAXNUMC LS 25041 42 typedef struct LINKC LS42 #define MAXNUMCMDLINES 250 43 44 typedef struct LINKCMDLINES 43 45 { 44 CHAR *c l;45 struct LINKC LS *next;46 CHAR *cmdline; 47 struct LINKCMDLINES *next; 46 48 } 47 LINKC LS;48 49 static LINKC LS *clbig = NULL, *clsmall= NULL;50 static BOOL loadedbig = FALSE, loadedsmall= FALSE;51 52 VOID load_cmdlines(BOOL big)49 LINKCMDLINES; 50 51 static LINKCMDLINES *DoItYourselfCmdLine = NULL, *MiniCmdLine = NULL; 52 static BOOL DoItYourselfLoaded = FALSE, MiniLoaded = FALSE; 53 54 VOID load_cmdlines(BOOL DoItYourself) 53 55 { 54 /* load linked list of cmdlines from CMDLINES.DAT file */ 56 /** load linked list of cmdlines from CMDLINES.DAT file 57 * if DoItYourself = TRUE (main command line dialog) 58 * else load from CMDMINI.DAT (mini command line at 59 * bottom of main window). 60 */ 55 61 56 62 FILE *fp; 57 LINKCLS *info, *last = NULL, *clhead; 58 CHAR s[1024]; 63 LINKCMDLINES *info, *last = NULL, *CmdLineHead; 64 PSZ pszCmdLine; 65 //CHAR s[1024]; 59 66 INT x = 0; 60 67 61 clhead = (big) ? clbig : clsmall; 62 if (big) 63 loadedbig = TRUE; 68 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 69 if (pszCmdLine) { 70 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine; 71 if (DoItYourself) 72 DoItYourselfLoaded = TRUE; 73 else 74 MiniLoaded = TRUE; 75 save_dir2(pszCmdLine); 76 if (pszCmdLine[strlen(pszCmdLine) - 1] != '\\') 77 strcat(pszCmdLine, "\\"); 78 strcat(pszCmdLine, (DoItYourself) ? "CMDLINES.DAT" : "CMDMINI.DAT"); 79 fp = _fsopen(pszCmdLine, "r", SH_DENYWR); 80 if (fp) { 81 while (x < MAXNUMCMDLINES && !feof(fp)) { 82 if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__)) 83 break; 84 if (pszCmdLine && *pszCmdLine != ';') { 85 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__); 86 if (info) { 87 x++; 88 info->cmdline = xstrdup(pszCmdLine, pszSrcFile, __LINE__); 89 if (!info->cmdline) 90 xfree(info); 91 else { 92 info->next = NULL; 93 if (!CmdLineHead) 94 CmdLineHead = info; 95 else 96 last->next = info; 97 last = info; 98 } 99 } 100 } 101 } 102 fclose(fp); 103 } 104 } 105 xfree(pszCmdLine); 106 if (DoItYourself) 107 DoItYourselfCmdLine = CmdLineHead; 64 108 else 65 loadedsmall = TRUE; 66 save_dir2(s); 67 if (s[strlen(s) - 1] != '\\') 68 strcat(s, "\\"); 69 strcat(s, (big) ? "CMDLINES.DAT" : "CMDMINI.DAT"); 70 fp = _fsopen(s, "r", SH_DENYWR); 71 if (fp) { 72 while (x < MAXNUMCLS && !feof(fp)) { 73 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__)) 74 break; 75 if (*s && *s != ';') { 76 info = xmalloc(sizeof(LINKCLS), pszSrcFile, __LINE__); 77 if (info) { 78 x++; 79 info->cl = xstrdup(s, pszSrcFile, __LINE__); 80 if (!info->cl) 81 xfree(info); 82 else { 83 info->next = NULL; 84 if (!clhead) 85 clhead = info; 86 else 87 last->next = info; 88 last = info; 89 } 90 } 91 } 92 } 93 fclose(fp); 94 } 95 if (big) 96 clbig = clhead; 97 else 98 clsmall = clhead; 109 MiniCmdLine = CmdLineHead; 99 110 } 100 111 101 VOID save_cmdlines(BOOL big)112 VOID save_cmdlines(BOOL DoItYourself) 102 113 { 103 /* save linked list of cmdlines to CMDLINES.DAT file */ 104 105 LINKCLS *info, *clhead; 114 /** save linked list of cmdlines from CMDLINES.DAT file 115 * if DoItYourself = TRUE (main command line dialog) 116 * else load from CMDMINI.DAT (mini command line at 117 * bottom of main window). 118 */ 119 120 LINKCMDLINES *info, *CmdLineHead; 106 121 FILE *fp; 107 CHAR s[CCHMAXPATH + 14]; 108 109 clhead = (big) ? clbig : clsmall; 110 if ((big && !loadedbig) || (!big && !loadedsmall)) 122 PSZ pszCmdLine; 123 //CHAR s[CCHMAXPATH + 14]; 124 125 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine; 126 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded)) 111 127 return; 112 save_dir2(s); 113 if (s[strlen(s) - 1] != '\\') 114 strcat(s, "\\"); 115 strcat(s, (big) ? "CMDLINES.DAT" : "CMDMINI.DAT"); 116 if (clhead) { 117 fp = xfopen(s, "w", pszSrcFile, __LINE__); 128 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__); 129 if (!pszCmdLine) 130 return; 131 save_dir2(pszCmdLine); 132 if (pszCmdLine[strlen(pszCmdLine) - 1] != '\\') 133 strcat(pszCmdLine, "\\"); 134 strcat(pszCmdLine, (DoItYourself) ? "CMDLINES.DAT" : "CMDMINI.DAT"); 135 if (CmdLineHead) { 136 fp = xfopen(pszCmdLine, "w", pszSrcFile, __LINE__); 118 137 if (fp) { 119 138 fputs(GetPString(IDS_COMMANDFILE2TEXT), fp); 120 info = clhead;139 info = CmdLineHead; 121 140 while (info) { 122 fprintf(fp, "%0.*s\n", 1000, info->c l);141 fprintf(fp, "%0.*s\n", 1000, info->cmdline); 123 142 info = info->next; 124 143 } … … 127 146 } 128 147 else 129 unlink( s);130 if ( big)131 clbig = clhead;148 unlink(pszCmdLine); 149 if (DoItYourself) 150 DoItYourselfCmdLine = CmdLineHead; 132 151 else 133 clsmall = clhead;152 MiniCmdLine = CmdLineHead; 134 153 } 135 154 136 BOOL add_cmdline(CHAR * cl, BOOL big)155 BOOL add_cmdline(CHAR *cmdline, BOOL DoItYourself) 137 156 { 138 LINKC LS *info, *last = NULL, *clhead;157 LINKCMDLINES *info, *last = NULL, *CmdLineHead; 139 158 INT x = 0; 140 159 141 if (!c l || !*cl)160 if (!cmdline || !*cmdline) 142 161 return FALSE; 143 clhead = (big) ? clbig : clsmall;144 if (( big && !loadedbig) || (!big && !loadedsmall))145 load_cmdlines( big);146 info = clhead;162 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine; 163 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded)) 164 load_cmdlines(DoItYourself); 165 info = CmdLineHead; 147 166 while (info) { 148 if (!stricmp(info->c l, cl))167 if (!stricmp(info->cmdline, cmdline)) 149 168 return FALSE; 150 169 last = info; … … 152 171 x++; 153 172 } 154 info = xmalloc(sizeof(LINKC LS), pszSrcFile, __LINE__);173 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__); 155 174 if (info) { 156 info->c l = xstrdup(cl, pszSrcFile, __LINE__);157 if (!info->c l)175 info->cmdline = xstrdup(cmdline, pszSrcFile, __LINE__); 176 if (!info->cmdline) 158 177 xfree(info); 159 178 else { 160 179 info->next = NULL; 161 if (! clhead)162 clhead = info;180 if (!CmdLineHead) 181 CmdLineHead = info; 163 182 else 164 183 last->next = info; 165 if (x > MAXNUMC LS) {166 info = clhead;167 clhead = clhead->next;184 if (x > MAXNUMCMDLINES) { 185 info = CmdLineHead; 186 CmdLineHead = CmdLineHead->next; 168 187 xfree(info); 169 188 } 170 if ( big)171 clbig = clhead;189 if (DoItYourself) 190 DoItYourselfCmdLine = CmdLineHead; 172 191 else 173 clsmall = clhead;192 MiniCmdLine = CmdLineHead; 174 193 return TRUE; 175 194 } … … 178 197 } 179 198 180 BOOL remove_cmdline(CHAR * cl, BOOL big)199 BOOL remove_cmdline(CHAR *cmdline, BOOL DoItYourself) 181 200 { 182 LINKC LS *info, *last = NULL, *clhead;183 184 if (!c l || !*cl)201 LINKCMDLINES *info, *last = NULL, *CmdLineHead; 202 203 if (!cmdline || !*cmdline) 185 204 return FALSE; 186 if (( big && !loadedbig) || (!big && !loadedsmall))187 load_cmdlines( big);188 clhead = (big) ? clbig : clsmall;189 info = clhead;205 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded)) 206 load_cmdlines(DoItYourself); 207 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine; 208 info = CmdLineHead; 190 209 while (info) { 191 if (!stricmp(info->c l, cl)) {210 if (!stricmp(info->cmdline, cmdline)) { 192 211 if (last) 193 212 last->next = info->next; 194 213 else 195 clhead = info->next;196 xfree(info->c l);214 CmdLineHead = info->next; 215 xfree(info->cmdline); 197 216 xfree(info); 198 if ( big)199 clbig = clhead;217 if (DoItYourself) 218 DoItYourselfCmdLine = CmdLineHead; 200 219 else 201 clsmall = clhead;220 MiniCmdLine = CmdLineHead; 202 221 return TRUE; 203 222 } … … 208 227 } 209 228 210 VOID free_cmdlines(BOOL big)229 VOID free_cmdlines(BOOL DoItYourself) 211 230 { 212 LINKC LS *info, *next, *clhead;213 214 clhead = (big) ? clbig : clsmall;215 info = clhead;231 LINKCMDLINES *info, *next, *CmdLineHead; 232 233 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine; 234 info = CmdLineHead; 216 235 while (info) { 217 236 next = info->next; 218 xfree(info->c l);237 xfree(info->cmdline); 219 238 xfree(info); 220 239 info = next; 221 240 } 222 clhead = NULL;223 if ( big)224 clbig = clhead;241 CmdLineHead = NULL; 242 if (DoItYourself) 243 DoItYourselfCmdLine = CmdLineHead; 225 244 else 226 clsmall = clhead;245 MiniCmdLine = CmdLineHead; 227 246 DosPostEventSem(CompactSem); 228 247 } … … 495 514 case UM_RESCAN: 496 515 WinSendDlgItemMsg(hwnd, EXEC_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); 497 if (! loadedbig)516 if (!DoItYourselfLoaded) 498 517 load_cmdlines(TRUE); 499 518 { 500 LINKC LS *info;501 502 info = clbig;519 LINKCMDLINES *info; 520 521 info = DoItYourselfCmdLine; 503 522 while (info) { 504 523 WinSendDlgItemMsg(hwnd, 505 524 EXEC_LISTBOX, 506 525 LM_INSERTITEM, 507 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->c l));526 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline)); 508 527 info = info->next; 509 528 } … … 750 769 case UM_RESCAN: 751 770 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); 752 if (! loadedsmall)771 if (!MiniLoaded) 753 772 load_cmdlines(FALSE); 754 773 { 755 LINKC LS *info;756 757 info = clsmall;774 LINKCMDLINES *info; 775 776 info = MiniCmdLine; 758 777 while (info) { 759 778 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_INSERTITEM, 760 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->c l));779 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline)); 761 780 info = info->next; 762 781 }
Note:
See TracChangeset
for help on using the changeset viewer.