• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

CLI interface to medialist (fossil mirror)


Commit MetaInfo

Revisiond3ba7203f744eef499ca853ef45d0010b5f88059 (tree)
Zeit2021-09-23 18:21:19
Autormio <stigma@disr...>
Commitermio

Log Message

Reformat add.d

FossilOrigin-Name: 8aebd101bd198417cc803e6bec754c85bc035907cc104c223d12d9af271c0288

Ändern Zusammenfassung

Diff

--- a/add.d
+++ b/add.d
@@ -116,86 +116,85 @@ private string[] retrieveListHeaders(File* listFile)
116116
117117 private void addMissingHeaders(ref string[] fileHeaders, File* listFile)
118118 {
119- import std.algorithm.searching : canFind;
120-
121- if (false == canFind(fileHeaders, "start_date"))
122- {
123- addHeader(listFile, "start_date");
124- fileHeaders ~= "start_date";
125- }
126-
127- if (false == canFind(fileHeaders, "end_date"))
128- {
129- addHeader(listFile, "end_date");
130- fileHeaders ~= "end_date";
131- }
132-
133- if (false == canFind(fileHeaders, "last_updated"))
134- {
135- addHeader(listFile, "last_updated");
136- fileHeaders ~= "last_updated";
137- }
119+ import std.algorithm.searching : canFind;
120+
121+ if (false == canFind(fileHeaders, "start_date"))
122+ {
123+ addHeader(listFile, "start_date");
124+ fileHeaders ~= "start_date";
125+ }
126+
127+ if (false == canFind(fileHeaders, "end_date"))
128+ {
129+ addHeader(listFile, "end_date");
130+ fileHeaders ~= "end_date";
131+ }
132+
133+ if (false == canFind(fileHeaders, "last_updated"))
134+ {
135+ addHeader(listFile, "last_updated");
136+ fileHeaders ~= "last_updated";
137+ }
138138 }
139139
140140 private
141141 void addHeader(File* f, string newHeader) @trusted
142142 in
143143 {
144- assert(f.isOpen == true);
145- assert(newHeader !is null);
144+ assert(f.isOpen == true);
145+ assert(newHeader !is null);
146146 }
147147 out
148148 {
149- assert(f.isOpen == true);
149+ assert(f.isOpen == true);
150150 }
151151 do
152152 {
153- import std.file : rename, remove, tempDir;
154- import std.path : buildPath, baseName;
153+ import std.file : rename, remove, tempDir;
154+ import std.path : buildPath, baseName;
155155
156- immutable origPath = f.name;
157- immutable tempPath = buildPath(tempDir(), baseName(origPath));
156+ immutable origPath = f.name;
157+ immutable tempPath = buildPath(tempDir(), baseName(origPath));
158158
159- File tempFile = File(tempPath, "w+");
159+ File tempFile = File(tempPath, "w+");
160160
161- string line = "";
162- bool pastHeader = false;
161+ string line = "";
162+ bool pastHeader = false;
163163
164- f.rewind();
164+ f.rewind();
165165
166- while ((line = f.readln()) !is null)
167- {
168- if (false == pastHeader && '#' != line[0])
169- {
170- pastHeader = true;
171- tempFile.writefln("%s\t%s", line.strip, newHeader);
172- }
173- else
174- {
175- /* line may not have a newline character */
176- tempFile.writeln(line.strip);
177- }
178- }
179-
180- f.close();
166+ while ((line = f.readln()) !is null)
167+ {
168+ if (false == pastHeader && '#' != line[0])
169+ {
170+ pastHeader = true;
171+ tempFile.writefln("%s\t%s", line.strip, newHeader);
172+ }
173+ else
174+ {
175+ /* line may not have a newline character */
176+ tempFile.writeln(line.strip);
177+ }
178+ }
181179
182- /* for whatever fucking reason, both "copy" and "rename" don't work. */
180+ f.close();
183181
184- remove(origPath);
182+ remove(origPath);
185183
186- f.open(origPath, "a+");
187- tempFile.rewind();
184+ /* some operating systems don't like to copy from the tempdir? */
185+ f.open(origPath, "a+");
186+ tempFile.rewind();
188187
189- while ((line = tempFile.readln()) !is null)
190- {
191- f.write(line);
192- }
188+ while ((line = tempFile.readln()) !is null)
189+ {
190+ f.write(line);
191+ }
193192
194- /* rewind because we need to re-read the headers */
195- f.rewind();
193+ /* rewind because we need to re-read the headers */
194+ f.rewind();
196195
197- tempFile.close();
198- remove(tempPath);
196+ tempFile.close();
197+ remove(tempPath);
199198 }
200199
201200 private void writeNewItem(File* listFile, HeaderPairType[NUMBER_OF_ML_HEADERS] headersAndPositions,
@@ -258,15 +257,25 @@ private void replicateIndent(File* listFile, HeaderPairType headerPair, size_t*
258257 *previousIndent = headerPair[0];
259258 }
260259
261-@trusted private void display_usage(string program_name)
260+@trusted @nogc private void display_usage(string programName)
262261 {
263- stderr.writefln("usage: %s add <list_name> <title> [options]
262+ import core.stdc.stdio : fprintf;
263+ import core.stdc.stdio : cstderr = stderr;
264+ import core.stdc.stdlib : malloc, free;
265+
266+ // Can't add NULL byte to D string, so allocate a temp string and free it.
267+ char* progname = cast(char*)malloc(char.sizeof * programName.length);
268+ scope(exit) free(progname);
269+
270+ progname[0..programName.length] = programName[];
271+ progname[programName.length] = '\0';
272+
273+ fprintf(cstderr, "usage: %s add <list_name> <title> [options]
264274
265275 list_name = the list name to add the new item to
266276 title = the title of the new item
267277
268278 options:
269- -p, --progress the initial progress of the new item (default: ??/??)
270- -s, --status the initial status of the new item (default: UNKNOWN)",
271- program_name);
279+-p, --progress the initial progress of the new item (default: ??/??)
280+-s, --status the initial status of the new item (default: UNKNOWN)\n", progname);
272281 }