Rev 740 | Rev 748 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 740 | Rev 747 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit STRLIST; |
1 | unit STRLIST; |
2 | 2 | ||
3 | (************************************************) |
3 | (************************************************) |
4 | (* STRLIST.PAS *) |
4 | (* STRLIST.PAS *) |
5 | (* Author: Daniel Marschall *) |
5 | (* Author: Daniel Marschall *) |
6 | (* Revision: 2022-02-14 *) |
6 | (* Revision: 2022-02-16 *) |
7 | (* License: Apache 2.0 *) |
7 | (* License: Apache 2.0 *) |
8 | (* This file contains: *) |
8 | (* This file contains: *) |
9 | (* - StringList implementation for Turbo Pascal *) |
9 | (* - StringList implementation for Turbo Pascal *) |
10 | (************************************************) |
10 | (************************************************) |
11 | 11 | ||
Line 32... | Line 32... | ||
32 | procedure ListInsert(list: PStringlist; str: string; idx: integer); |
32 | procedure ListInsert(list: PStringlist; str: string; idx: integer); |
33 | procedure ListSwapElement(list: PStringList; i, j: integer); |
33 | procedure ListSwapElement(list: PStringList; i, j: integer); |
34 | procedure SplitStrToList(str: string; list: PStringList; separator: string); |
34 | procedure SplitStrToList(str: string; list: PStringList; separator: string); |
35 | procedure OIDtoArcList(oid: string; list: PStringList); |
35 | procedure OIDtoArcList(oid: string; list: PStringList); |
36 | procedure ListBubbleSortNumericString(list: PStringList); |
36 | procedure ListBubbleSortNumericString(list: PStringList); |
- | 37 | function ListLoadFromFile(list: PStringList; filename: string): boolean; |
|
- | 38 | function ListSaveToFile(list: PStringList; filename: string): boolean; |
|
37 | 39 | ||
38 | implementation |
40 | implementation |
39 | 41 | ||
40 | uses |
42 | uses |
41 | VtsFuncs; |
43 | VtsFuncs; |
Line 303... | Line 305... | ||
303 | if not swapped then break; |
305 | if not swapped then break; |
304 | Dec(n); |
306 | Dec(n); |
305 | end; |
307 | end; |
306 | end; |
308 | end; |
307 | 309 | ||
- | 310 | function ListLoadFromFile(list: PStringList; filename: string): boolean; |
|
- | 311 | var |
|
- | 312 | f: Text; |
|
- | 313 | s: string; |
|
- | 314 | begin |
|
- | 315 | Assign(f, filename); |
|
- | 316 | ||
- | 317 | {$I-} |
|
- | 318 | Reset(f); |
|
- | 319 | {$I+} |
|
- | 320 | if IoResult <> 0 then |
|
- | 321 | begin |
|
- | 322 | ListLoadFromFile := false; |
|
- | 323 | (* Must not call Close(f) if file was never opened *) |
|
- | 324 | Exit; |
|
- | 325 | end; |
|
- | 326 | ||
- | 327 | ListClear(list); |
|
- | 328 | ||
- | 329 | while not EOF(f) do |
|
- | 330 | begin |
|
- | 331 | ReadLn(f, s); |
|
- | 332 | ListAppend(list, s); |
|
- | 333 | end; |
|
- | 334 | ||
- | 335 | Close(f); |
|
- | 336 | ListLoadFromFile := true; |
|
- | 337 | end; |
|
- | 338 | ||
- | 339 | function ListSaveToFile(list: PStringList; filename: string): boolean; |
|
- | 340 | var |
|
- | 341 | f: Text; |
|
- | 342 | i: integer; |
|
- | 343 | s: string; |
|
- | 344 | begin |
|
- | 345 | Assign(f, filename); |
|
- | 346 | ||
- | 347 | {$I-} |
|
- | 348 | Rewrite(f); |
|
- | 349 | {$I+} |
|
- | 350 | if IoResult <> 0 then |
|
- | 351 | begin |
|
- | 352 | ListSaveToFile := false; |
|
- | 353 | (* Must not call Close(f) if file was never opened *) |
|
- | 354 | Exit; |
|
- | 355 | end; |
|
- | 356 | ||
- | 357 | for i := 0 to ListCount(list)-1 do |
|
- | 358 | begin |
|
- | 359 | s := ListGetElement(list, i); |
|
- | 360 | WriteLn(f, s); |
|
- | 361 | end; |
|
- | 362 | ||
- | 363 | Close(f); |
|
- | 364 | ListSaveToFile := true; |
|
- | 365 | end; |
|
- | 366 | ||
308 | end. |
367 | end. |