jcs
/amend
/amendments
/44
*: Integrate with bile, lots of minor changes
Sprinkle snprintf and strlcpy where useful
Remove ALRT/DITL resources that util doesn't need anymore
Handle diffing deleted files properly
jcs made amendment 44 over 3 years ago
--- amend.π.r Thu Dec 16 20:57:03 2021
+++ amend.π.r Tue Jan 11 19:53:31 2022
@@ -39,26 +39,11 @@ data 'MBAR' (128) {
$"0005 0080 0081 0082 0083 0084" /* ...Ä.Å.Ç.É.Ñ */
};
-data 'ALRT' (129) {
- $"0078 006C 00DA 0196 0081 5555 300A" /* .x.l...ñ.ÅUU0. */
-};
-
-data 'ALRT' (130) {
+data 'ALRT' (130, "ASK") {
$"0078 006C 00DA 0196 0082 5555 300A" /* .x.l...ñ.ÇUU0. */
};
-data 'DITL' (128) {
- $"0000 0000 0000 0014 001E 0032 013B 0802" /* ...........2.;.. */
- $"5E30" /* ^0 */
-};
-
-data 'DITL' (129) {
- $"0001 0000 0000 0046 00E6 005A 0120 0402" /* .......F...Z. .. */
- $"4F4B 0000 0000 000A 003C 0040 011E 0802" /* OK.......<.@.... */
- $"5E30" /* ^0 */
-};
-
-data 'DITL' (130) {
+data 'DITL' (130, "ASK") {
$"0002 0000 0000 0046 00E6 005A 0120 0403" /* .......F...Z. .. */
$"5965 7321 0000 0000 0046 00A0 005A 00DA" /* Yes!.....F.†.Z.. */
$"0402 4E6F 0000 0000 000A 003C 0040 011E" /* ..No.......<.@.. */
@@ -83,7 +68,7 @@ data 'WIND' (128) {
};
data 'vers' (1) {
- $"0100 8000 0000 0331 2E30 1D31 2E30 20A9" /* ..Ä....1.0.1.0 © */
+ $"0110 8000 0000 0331 2E31 1D31 2E31 20A9" /* ..Ä....1.1.1.1 © */
$"2032 3032 302D 3230 3231 2C20 6A6F 7368" /* 2020-2021, josh */
$"7561 2073 7465 696E" /* ua stein */
};
@@ -93,7 +78,7 @@ data 'STR ' (129, "TABWIDTH") {
};
data 'STR ' (128, "AUTHOR") {
- $"0775 6E6B 6E6F 776E" /* .unknown */
+ $"036A 6373" /* .jcs */
};
data 'LDEF' (128, "commit list", purgeable) {
@@ -117,16 +102,6 @@ data 'TMPL' (129, "AFIL") {
$"444C 4E47 116D 6F64 6966 6963 6174 696F" /* DLNG.modificatio */
$"6E20 6461 7465 444C 4E47 0566 6C61 6773" /* n dateDLNG.flags */
$"4842 5954" /* HBYT */
-};
-
-data 'DLOG' (128, "WAIT_DLOG_ID") {
- $"0066 0059 00A0 01A4 0001 0100 0100 0000" /* .f.Y.†.§........ */
- $"0000 0080 001A 280A" /* ...Ä..(. */
-};
-
-data 'DLOG' (129) {
- $"004C 0092 0114 0182 0001 0100 0100 0000" /* .L.í...Ç........ */
- $"0000 0081 00" /* ...Å. */
};
data 'DLOG' (130, "SETTINGS_DLOG_ID") {
--- amend.h Thu Dec 16 17:18:28 2021
+++ amend.h Mon Jan 10 14:12:36 2022
@@ -52,15 +52,4 @@
#define STR_AUTHOR_ID 128
#define STR_TABWIDTH_ID 129
-struct tmpl {
- Handle h;
- ResType type;
- Str255 name;
- short id;
-};
-extern struct tmpl tmpls[10];
-extern short ntmpls;
-
-extern short app_res_frefid;
-
extern MenuHandle file_menu, edit_menu, repo_menu, commit_menu;
--- browser.c Thu Dec 16 17:19:32 2021
+++ browser.c Tue Jan 11 20:38:56 2022
@@ -83,13 +83,13 @@ browser_idle(struct browser *browser)
struct browser *
browser_init(struct repo *repo)
{
- char title[256] = { 0 };
+ char title[256], filename[256];
struct browser *browser;
Rect bounds = { 0 }, te_bounds = { 0 };
Rect data_bounds = { 0, 0, 0, 1 }; /* tlbr */
Point cell_size = { 0, 0 };
Cell cell = { 0 };
- short padding = 10;
+ short padding = 10, colonpos, n;
browser = xmalloczero(sizeof(struct browser));
browser->state = BROWSER_STATE_IDLE;
@@ -104,11 +104,15 @@ browser_init(struct repo *repo)
bounds.right = screenBits.bounds.right - 1 - (padding / 2);
bounds.bottom = screenBits.bounds.bottom - 1 - (padding / 2);
- if (sprintf(title, "%s: %s", PROGRAM_NAME,
- browser->repo->filename) > sizeof(title))
- err(1, "sprintf overflow!");
+ memcpy(filename, browser->repo->bile->filename, sizeof(filename));
+ PtoCstr(filename);
+ for (n = 0, colonpos = 0; n < browser->repo->bile->filename[0]; n++) {
+ if (filename[n] == ':')
+ colonpos = n + 1;
+ }
+ snprintf(title, sizeof(title), "%s: %s", PROGRAM_NAME,
+ filename + colonpos);
CtoPstr(title);
-
browser->win = NewWindow(0L, &bounds, title, false, noGrowDocProc,
(WindowPtr)-1L, true, 0);
if (!browser->win)
@@ -231,9 +235,11 @@ browser_add_files(struct browser *browser)
for (i = 0; i < browser->repo->nfiles; i++) {
LAddRow(1, cell.v, browser->file_list);
if (browser->repo->files[i]->flags & REPO_FILE_DELETED)
- sprintf(filename, "~%s~", browser->repo->files[i]->filename);
+ snprintf(filename, sizeof(filename), "~%s~",
+ browser->repo->files[i]->filename);
else
- strcpy(filename, browser->repo->files[i]->filename);
+ strlcpy(filename, browser->repo->files[i]->filename,
+ sizeof(filename));
LSetCell(&filename, strlen(filename), cell, browser->file_list);
cell.v++;
}
@@ -374,10 +380,10 @@ browser_revert_file(struct browser *browser)
for (i = 0; i < nselected; i++) {
file = repo_file_with_id(browser->repo, selected[i]);
- sprintf(buf, "Save %s:", file->filename);
+ snprintf(buf, sizeof(buf), "Save %s:", file->filename);
CtoPstr(buf);
- strcpy(filename, file->filename);
+ strlcpy(filename, file->filename, sizeof(filename));
CtoPstr(filename);
SFPutFile(pt, buf, filename, NULL, &reply);
--- committer.c Thu Dec 30 14:54:00 2021
+++ committer.c Tue Jan 11 20:30:41 2022
@@ -44,7 +44,6 @@ static TEHandle committer_last_te = NULL;
void committer_generate_diff(struct committer *committer);
void committer_update_menu(struct committer *committer);
-void committer_status(char *format, ...);
void committer_commit(struct committer *committer);
void diff_append_line(char *str, size_t len, bool flush);
void diff_chunk_write(void);
@@ -53,7 +52,7 @@ void diff_finish(void);
void
committer_init(struct browser *browser)
{
- char title[256] = { 0 };
+ char title[256], filename[256];
struct committer *committer;
Rect bounds = { 0 }, te_bounds = { 0 };
TextStyle style;
@@ -70,9 +69,10 @@ committer_init(struct browser *browser)
bounds.right = screenBits.bounds.right - 1 - (padding / 2);
bounds.bottom = screenBits.bounds.bottom - 1 - (padding / 2);
- if (sprintf(title, "%s: %s: diff", PROGRAM_NAME, (browser->repo ?
- browser->repo->filename : "No repo open")) > sizeof(title))
- err(1, "sprintf overflow!");
+ memcpy(filename, browser->repo->bile->filename, 255);
+ PtoCstr(filename);
+ snprintf(title, sizeof(title), "%s: %s: diff", PROGRAM_NAME,
+ (browser->repo ? filename : "No repo open"));
committer->win = NewWindow(0L, &bounds, CtoPstr(title), false,
noGrowDocProc, (WindowPtr)-1L, true, 0);
@@ -207,7 +207,7 @@ committer_update(struct committer *committer, EventRec
if ((*(committer->diff_te))->nLines > 0) {
r = (*(committer->diff_te))->viewRect;
MoveTo(r.left, r.bottom + FontHeight(applFont, 10) + padding);
- len = sprintf((char *)buf, "%d (+), %d (-)",
+ len = snprintf((char *)buf, sizeof(buf), "%d (+), %d (-)",
committer->diff_adds, committer->diff_subs);
DrawText(buf, 0, len);
}
@@ -415,13 +415,13 @@ committer_generate_diff(struct committer *committer)
if (!all_files ||
repo_file_changed(committer->browser->repo, file)) {
- committer_status("Diffing %s...", file->filename);
+ progress("Diffing %s...", file->filename);
if (repo_diff_file(committer->browser->repo, file))
committer->diffed_files[committer->ndiffed_files++] =
file->id;
diff_finish();
} else{
- committer_status("Skipping unchanged %s...", file->filename);
+ progress("Skipping unchanged %s...", file->filename);
}
}
@@ -431,7 +431,7 @@ committer_generate_diff(struct committer *committer)
true);
cur_committer = NULL;
- committer_status(NULL);
+ progress(NULL);
done_diffing:
if (selected_files != NULL)
@@ -445,36 +445,6 @@ done_diffing:
}
void
-committer_status(char *format, ...)
-{
- Handle thandle;
- va_list argptr;
- Str255 status;
- Rect trect;
- size_t len, last_pos, last_line, i;
- short ttype;
-
- if (format == NULL) {
- DisposDialog(committer_dialog);
- committer_dialog = NULL;
- return;
- }
-
- va_start(argptr, format);
- len = vsprintf((char *)status, format, argptr);
- if (len > sizeof(status))
- err(1, "vsprintf overflow!");
- va_end(argptr);
- CtoPstr(status);
-
- if (committer_dialog == NULL)
- committer_dialog = GetNewDialog(WAIT_DLOG_ID, NULL, (WindowPtr)-1);
-
- GetDItem(committer_dialog, 1, &ttype, &thandle, &trect);
- SetIText(thandle, status);
-}
-
-void
committer_commit(struct committer *committer)
{
struct browser *browser;
@@ -486,11 +456,8 @@ committer_commit(struct committer *committer)
loglen = (*(committer->log_te))->teLength;
SetCursor(*(GetCursor(watchCursor)));
-
- committer_status("Backing up repo...");
- repo_backup(committer->browser->repo);
- committer_status("Committing changes...");
+ progress("Committing changes...");
repo_commit(committer->browser->repo, committer->diffed_files,
committer->ndiffed_files, committer->diff_adds, committer->diff_subs,
@@ -498,10 +465,9 @@ committer_commit(struct committer *committer)
(*(committer->diff_te))->hText, committer->diff_te_len);
HUnlock(committer->diff_te);
- ReleaseResource((*(committer->log_te))->hText);
HUnlock(committer->log_te);
- committer_status(NULL);
+ progress(NULL);
SetCursor(&arrow);
browser = committer->browser;
--- commit_list.c Sun Nov 21 10:53:10 2021
+++ commit_list.c Tue Jan 11 20:31:37 2022
@@ -88,9 +88,9 @@ commit_list_draw_cell(ListHandle theList, Cell theCell
HUnlock(commit->log);
ttm = localtime(&commit->date);
- sprintf(tmp, "%04d-%02d-%02d %02d:%02d:%02d", ttm->tm_year + 1900,
- ttm->tm_mon + 1, ttm->tm_mday, ttm->tm_hour, ttm->tm_min,
- ttm->tm_sec);
+ snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d",
+ ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday,
+ ttm->tm_hour, ttm->tm_min, ttm->tm_sec);
MoveTo(textRect.left, textRect.top + height + 6);
TextFace(normal);
DrawText(tmp, 0, strlen(tmp));
@@ -98,7 +98,8 @@ commit_list_draw_cell(ListHandle theList, Cell theCell
MoveTo(textRect.left + 140, textRect.top + height + 6);
DrawText(commit->author, 0, strlen(commit->author));
- sprintf(tmp, "%d (+), %d (-)", commit->adds, commit->subs);
+ snprintf(tmp, sizeof(tmp), "%d (+), %d (-)",
+ commit->adds, commit->subs);
MoveTo(textRect.left + 220, textRect.top + height + 6);
DrawText(tmp, 0, strlen(tmp));
--- main.c Thu Dec 16 17:18:57 2021
+++ main.c Tue Jan 11 20:32:03 2022
@@ -26,13 +26,9 @@
MenuHandle file_menu, edit_menu, repo_menu, commit_menu;
Handle commit_list_ldef_h;
-short app_res_frefid;
short quitting = 0;
struct browser *cur_browser = NULL;
-struct tmpl tmpls[10];
-short ntmpls;
-
void handle_menu(long menu_id);
void cur_browser_close(void);
void update_menu(void);
@@ -59,11 +55,7 @@ main(void)
InitDialogs(0);
InitCursor();
MaxApplZone();
-
- app_res_frefid = CurResFile();
- err_init();
-
settings_load();
mbar = GetNewMBar(MBAR_ID);
@@ -77,19 +69,6 @@ main(void)
update_menu();
DrawMenuBar();
- /* load tmpls before we open a new resource file */
- ntmpls = Count1Resources('TMPL');
- if (ntmpls > nitems(tmpls))
- err(1, "ntmpls %d > %d", ntmpls, nitems(tmpls));
- for (i = 0; i < ntmpls; i++) {
- tmpls[i].h = GetIndResource('TMPL', i + 1);
- if (tmpls[i].h == NULL)
- err(1, "Failed fetching TMPL %d", i + 1);
- GetResInfo(tmpls[i].h, &tmpls[i].id, &tmpls[i].type,
- &tmpls[i].name);
- DetachResource(tmpls[i].h);
- }
-
/* dynamically patch list LDEF to point to our *_list_ldef funcs */
commit_list_ldef_h = GetResource('LDEF', COMMIT_LDEF_ID);
if (!commit_list_ldef_h)
@@ -242,7 +221,8 @@ handle_menu(long menu_id)
memcpy(short_vers, (*vers)->shortVersion + vlen + 1,
sizeof((*vers)->shortVersion) - vlen - 1);
PtoCstr(short_vers);
- sprintf(vers_s, "%s %s", PROGRAM_NAME, short_vers);
+ snprintf(vers_s, sizeof(vers_s), "%s %s", PROGRAM_NAME,
+ short_vers);
ReleaseResource(vers);
note("%s", vers_s);
} else
--- patch.c Thu Oct 28 17:48:58 2021
+++ patch.c Tue Jan 11 20:33:45 2022
@@ -47,14 +47,14 @@ patch_open_source_file(struct repo *repo, char *filena
memcpy(&pfilename, filename, sizeof(pfilename));
CtoPstr(pfilename);
- error = FSOpen(pfilename, repo->vrefnum, &ret);
+ error = FSOpen(pfilename, repo->bile->vrefnum, &ret);
if (error && error == 1234) {
/* TODO: what does it return if file isn't there? */
- error = Create(pfilename, repo->vrefnum,
+ error = Create(pfilename, repo->bile->vrefnum,
repo->files[i]->creator, repo->files[i]->type);
if (error && error != dupFNErr)
err(1, "Failed to create %s: %d", filename, error);
- error = FSOpen(pfilename, repo->vrefnum, &ret);
+ error = FSOpen(pfilename, repo->bile->vrefnum, &ret);
}
if (error)
@@ -72,15 +72,13 @@ patch_open_temp_dest_file(struct repo *repo, char *fil
short error, ret;
char tmpfile[256];
- if (sprintf(tmpfile, "%s.tmp", filename) > sizeof(tmpfile))
- err(1, "sprintf overflow!");
-
+ snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename);
CtoPstr(tmpfile);
- error = Create(tmpfile, repo->vrefnum, AMEND_CREATOR, 'TEXT');
+ error = Create(tmpfile, repo->bile->vrefnum, AMEND_CREATOR, 'TEXT');
if (error && error != dupFNErr)
err(1, "Failed to create %s: %d", PtoCstr(tmpfile), error);
- error = FSOpen(tmpfile, repo->vrefnum, &ret);
+ error = FSOpen(tmpfile, repo->bile->vrefnum, &ret);
if (error)
err(1, "Failed to open %s: %d", PtoCstr(tmpfile), error);
@@ -126,7 +124,8 @@ patch_process(struct repo *repo, Str255 filename, shor
break;
case PATCH_STATE_TO:
if (strncmp(line, "+++ ", 4) != 0) {
- sprintf(patch_err, "Expected '+++ ' on line %d", linenum);
+ snprintf(patch_err, sizeof(patch_err),
+ "Expected '+++ ' on line %d", linenum);
ret = -1;
goto patch_done;
}
@@ -142,8 +141,9 @@ patch_process(struct repo *repo, Str255 filename, shor
}
}
if (tofilename[0] == '\0') {
- sprintf(patch_err, "Failed to parse filename after +++ "
- "on line %d", linenum);
+ snprintf(patch_err, sizeof(patch_err),
+ "Failed to parse filename after +++ on line %d",
+ linenum);
ret = -1;
goto patch_done;
}
@@ -166,14 +166,16 @@ patch_process(struct repo *repo, Str255 filename, shor
short source_line, source_delta, dest_line, dest_delta, count;
if (strncmp(line, "@@ ", 3) != 0) {
- sprintf(patch_err, "Expected '@@ ' on line %d", linenum);
+ snprintf(patch_err, sizeof(patch_err),
+ "Expected '@@ ' on line %d", linenum);
ret = -1;
goto patch_done;
}
if (sscanf(line, "@@ %d,%d %d,%d @@%n",
&source_line, &source_delta, &dest_line, &dest_delta,
&count) != 4 || count < 1) {
- sprintf(patch_err, "Malformed '@@ ' on line %d", linenum);
+ snprintf(patch_err, sizeof(patch_err),
+ "Malformed '@@ ' on line %d", linenum);
ret = -1;
goto patch_done;
}
--- repo.c Tue Jan 11 19:40:43 2022
+++ repo.c Tue Jan 11 20:55:19 2022
@@ -393,7 +393,7 @@ repo_show_diff_text(struct repo *repo, struct repo_com
if (trunc) {
warn_off = MAX_TEXTEDIT_SIZE - header_len -
strlen(REPO_DIFF_TOO_BIG);
- blen = sprintf(truncbuf, REPO_DIFF_TOO_BIG,
+ blen = snprintf(truncbuf, sizeof(truncbuf), REPO_DIFF_TOO_BIG,
diff_len - warn_off);
memcpy(dtext + MAX_TEXTEDIT_SIZE - blen, truncbuf, blen);
}
@@ -652,18 +652,17 @@ repo_sort_commits(struct repo *repo)
short
repo_diff_file(struct repo *repo, struct repo_file *file)
{
- Str255 fromfilename = { 0 }, tofilename = { 0 };
- Str255 fromfilepath = { 0 }, tofilepath = { 0 };
+ static Str255 fromfilename, tofilename, fromfilepath, tofilepath;
+ static Str255 label0, label1;
struct repo_file_attrs attrs;
size_t size;
- char label0[255], label1[255];
char *text;
long len;
short error, ret, frefnum, tofile_empty = 0;
/* write out old file */
- sprintf((char *)fromfilename, "%s (%s tmp)", file->filename,
- PROGRAM_NAME);
+ snprintf((char *)fromfilename, sizeof(fromfilename),
+ "%s (%s tmp)", file->filename, PROGRAM_NAME);
CtoPstr(fromfilename);
error = Create(fromfilename, repo->bile->vrefnum, file->creator,
@@ -681,21 +680,26 @@ repo_diff_file(struct repo *repo, struct repo_file *fi
err(1, "Failed to truncate file %s: %d", PtoCstr(fromfilename),
error);
- getpath(repo->bile->vrefnum, fromfilename, &fromfilepath, true);
-
- /* if there's no existing TEXT resource, it's a new file */
-
- size = bile_read_alloc(repo->bile, REPO_TEXT_RTYPE, file->id, &text);
- if (size > 0) {
- error = FSWrite(frefnum, &size, text);
- if (error)
- err(1, "Failed to write old file to %s: %d",
- PtoCstr(fromfilename), error);
- free(text);
+ if (file->flags & REPO_FILE_DELETED) {
+ /* don't write any TEXT resource, the from file should be blank */
+ } else {
+ /* if there's no existing TEXT resource, it's a new file */
+
+ size = bile_read_alloc(repo->bile, REPO_TEXT_RTYPE, file->id,
+ &text);
+ if (size > 0) {
+ error = FSWrite(frefnum, &size, text);
+ if (error)
+ err(1, "Failed to write old file to %s: %d",
+ PtoCstr(fromfilename), error);
+ free(text);
+ }
}
FSClose(frefnum);
+ getpath(repo->bile->vrefnum, fromfilename, &fromfilepath, true);
+
memcpy((char *)tofilename, file->filename, sizeof(file->filename));
CtoPstr(tofilename);
getpath(repo->bile->vrefnum, tofilename, &tofilepath, true);
@@ -703,8 +707,8 @@ repo_diff_file(struct repo *repo, struct repo_file *fi
error = repo_get_file_attrs(repo, tofilename, &attrs);
if (error == fnfErr) {
/* file no longer exists, create empty temp file */
- sprintf((char *)tofilename, "%s (%s deleted)", file->filename,
- PROGRAM_NAME);
+ snprintf((char *)tofilename, sizeof(tofilename),
+ "%s (%s deleted)", file->filename, PROGRAM_NAME);
CtoPstr(tofilename);
error = Create(tofilename, repo->bile->vrefnum, file->creator,
@@ -721,14 +725,15 @@ repo_diff_file(struct repo *repo, struct repo_file *fi
/* specify diff header labels to avoid printing tmp filename */
/* (TODO: use paths relative to repo) */
label[0] = (char *)&label0;
- sprintf(label0, "%s\t%s", file->filename,
+ snprintf((char *)label0, sizeof(label0), "%s\t%s", file->filename,
ctime(file->mtime ? &file->mtime : &attrs.mtime));
label[1] = (char *)&label1;
- sprintf(label1, "%s\t%s", file->filename, ctime(&attrs.mtime));
+ snprintf((char *)label1, sizeof(label1), "%s\t%s", file->filename,
+ ctime(&attrs.mtime));
/* ctime is stupid, remove trailing \n */
- label0[strlen(label0) - 1] = '\0';
- label1[strlen(label1) - 1] = '\0';
+ label0[strlen((char *)label0) - 1] = '\0';
+ label1[strlen((char *)label1) - 1] = '\0';
PtoCstr(fromfilepath);
PtoCstr(tofilepath);
@@ -772,8 +777,14 @@ repo_file_changed(struct repo *repo, struct repo_file
CtoPstr(filename);
getpath(repo->bile->vrefnum, filename, &filepath, true);
- if (FStat(filepath, &sb) != 0)
+ if (FStat(filepath, &sb) == 0) {
+ if (file->flags & REPO_FILE_DELETED)
+ return 1;
+ } else {
+ if (file->flags & REPO_FILE_DELETED)
+ return 0;
return 1;
+ }
if (sb.st_size != fsize)
return 1;
@@ -1082,8 +1093,10 @@ repo_backup(struct repo *repo)
memcpy(repo_filename, repo->bile->filename, sizeof(repo_filename));
PtoCstr(repo_filename);
- sprintf((char *)source_filename, "%s:%s", path, repo_filename);
- sprintf((char *)dest_filename, "%s (backup)", source_filename);
+ snprintf((char *)source_filename, sizeof(source_filename), "%s:%s",
+ path, repo_filename);
+ snprintf((char *)dest_filename, sizeof(dest_filename), "%s (backup)",
+ source_filename);
CtoPstr(source_filename);
CtoPstr(dest_filename);
--- settings.c Thu Dec 16 20:48:42 2021
+++ settings.c Tue Jan 11 20:37:06 2022
@@ -26,26 +26,20 @@ struct settings settings = { 0 };
void
settings_load(void)
{
- short cur_res;
char *author;
- cur_res = CurResFile();
- UseResFile(app_res_frefid);
-
author = xGetStringAsChar(STR_AUTHOR_ID);
memcpy(settings.author, author, sizeof(settings.author));
settings.author[sizeof(settings.author)] = '\0';
free(author);
if (settings.author[0] == '\0')
- sprintf(settings.author, "unknown");
+ snprintf(settings.author, sizeof(settings.author), "unknown");
settings.tabwidth = (short)xGetStringAsLong(STR_TABWIDTH_ID);
if (settings.tabwidth < 1 || settings.tabwidth > 20) {
warn("Bogus tabwidth resource %d", settings.tabwidth);
settings.tabwidth = 4;
}
-
- UseResFile(cur_res);
}
void
@@ -56,9 +50,6 @@ settings_save(void)
short cur_res;
char tmp[8];
- cur_res = CurResFile();
- UseResFile(app_res_frefid);
-
res = xGetResource('STR ', STR_AUTHOR_ID);
HLock(res);
l = strlen(settings.author);
@@ -72,7 +63,7 @@ settings_save(void)
res = xGetResource('STR ', STR_TABWIDTH_ID);
HLock(res);
- sprintf(tmp, "%d", settings.tabwidth);
+ snprintf(tmp, sizeof(tmp), "%d", settings.tabwidth);
l = strlen(tmp);
SetHandleSize(res, l + 1);
memcpy(*res, tmp, l + 1);
@@ -91,7 +82,7 @@ settings_edit(void)
Str255 txt;
Handle ihandle;
size_t len;
- short done = 0, itype, hit, tabwidth, cur_res;
+ short done = 0, itype, hit, tabwidth;
DialogPtr dlg;
Rect irect;
@@ -105,7 +96,7 @@ settings_edit(void)
SetIText(ihandle, txt);
GetDItem(dlg, SETTINGS_TABWIDTH_ID, &itype, &ihandle, &irect);
- sprintf((char *)&txt, "%d", settings.tabwidth);
+ snprintf((char *)&txt, sizeof(txt), "%d", settings.tabwidth);
CtoPstr(txt);
SetIText(ihandle, txt);
@@ -126,9 +117,6 @@ settings_edit(void)
}
}
- cur_res = CurResFile();
- UseResFile(app_res_frefid);
-
GetDItem(dlg, SETTINGS_AUTHOR_ID, &itype, &ihandle, &irect);
GetIText(ihandle, txt);
PtoCstr(txt);
@@ -153,5 +141,4 @@ settings_edit(void)
done:
DisposeDialog(dlg);
- UseResFile(cur_res);
}