• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

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

Révision636dc1125de04f272e07fd88db3a94907b8639c4 (tree)
l'heure2022-01-25 09:31:41
Auteurmio <stigma@disr...>
Commitermio

Message de Log

remove unused util.d functions

FossilOrigin-Name: ed3e9654e3d7d5cd797836f3b0eaa6908fac9f474bdcdedd6cfc496c70e5fa58

Change Summary

Modification

--- a/util.d
+++ b/util.d
@@ -1,5 +1,5 @@
11 /*
2- * Copyright (C) 2021 dawning.
2+ * Copyright (C) 2021, 2022 mio <stigma@disroot.org>
33 *
44 * This file is part of medialist-cli.
55 *
@@ -18,47 +18,6 @@
1818 */
1919 module util;
2020
21-import std.stdio : File;
22-import std.typecons : Tuple, tuple;
23-
24-alias HeaderPairType = Tuple!(size_t, string);
25-
26-/**
27- * The number of headers supported by MediaList (CLI).
28- *
29- * - `title`
30- * - `status`
31- * - `progress`
32- * - `start_date`
33- * - `end_date`
34- * - `last_updated`
35- */
36-enum NUMBER_OF_ML_HEADERS = 6;
37-
38-/**
39- * All the supported headers as lowercase strings for comparison.
40- */
41-enum MLHeaders
42-{
43- title = "title",
44- status = "status",
45- progress = "progress",
46- startDate = "start_date",
47- endDate = "end_date",
48- lastUpdated = "last_updated"
49-}
50-
51-@trusted @nogc public void
52-_log(string msg, bool err = false)
53-{
54- import core.stdc.stdio : fprintf, stderr;
55-
56- if (true == err)
57- fprintf(stderr, "*** error: %s ***\n", msg.ptr);
58- else
59- fprintf(stderr, "** warning: %s **\n", msg.ptr);
60-}
61-
6221 /**
6322 * Expand a string which can contain POSIX-style environment variables.
6423 *
@@ -144,158 +103,3 @@ expandEnvironmentVariables(string str)
144103 environment["HOME"] = prevHome;
145104 environment["XDG_CONFIG_HOME"] = prevConf;
146105 }
147-
148-/**
149- * Parse the headers to an array of tuples containing the number of
150- * tabs required to match the header, and the header itself.
151- *
152- * Params:
153- * headerSections = The header line split by horizontal tabs.
154- *
155- * Returns: An array of Tuple(tabIndent (size_t), header (string)).
156- */
157-@trusted public HeaderPairType[NUMBER_OF_ML_HEADERS]
158-parseMLHeader(string[] headerSections)
159-{
160- import std.string : toLower;
161-
162- HeaderPairType[NUMBER_OF_ML_HEADERS] sections;
163- size_t validHeaderCounter = 0;
164-
165- foreach (tabIndent, headerSection; headerSections)
166- {
167- string lowercaseHeader = headerSection.toLower;
168- switch (lowercaseHeader)
169- {
170- case MLHeaders.title:
171- case MLHeaders.status:
172- case MLHeaders.progress:
173- case MLHeaders.startDate:
174- case MLHeaders.endDate:
175- case MLHeaders.lastUpdated:
176- sections[validHeaderCounter++] = tuple(tabIndent, lowercaseHeader);
177- break;
178- default:
179- break;
180- }
181- if (validHeaderCounter >= NUMBER_OF_ML_HEADERS)
182- break;
183- }
184-
185- return sections;
186-}
187-
188-public string[]
189-retrieveListHeaders (File* listFile)
190-{
191- import std.string : strip, split;
192-
193- string line = null;
194- string[] fileHeaders;
195-
196- listFile.rewind ();
197-
198- while ((line = listFile.readln()) !is null)
199- {
200- if ('#' != line[0])
201- {
202- fileHeaders = line.strip().split('\t');
203- break;
204- }
205- }
206-
207- return fileHeaders;
208-}
209-
210-public void
211-addMissingHeaders(ref string[] fileHeaders, File* listFile)
212-{
213- import core.stdc.stdio : SEEK_END;
214- import std.algorithm.searching : canFind;
215-
216- /* Version 0.2 */
217- if (false == canFind(fileHeaders, "start_date"))
218- {
219- addHeader(listFile, "start_date");
220- fileHeaders ~= "start_date";
221- }
222-
223- if (false == canFind(fileHeaders, "end_date"))
224- {
225- addHeader(listFile, "end_date");
226- fileHeaders ~= "end_date";
227- }
228-
229- if (false == canFind(fileHeaders, "last_updated"))
230- {
231- addHeader(listFile, "last_updated");
232- fileHeaders ~= "last_updated";
233- }
234-
235- listFile.seek(0, SEEK_END);
236-}
237-
238-@trusted private void
239-addHeader(File* f, string newHeader)
240-in
241-{
242- assert (f.isOpen == true, "f.isOpen == true (in)");
243- assert (newHeader !is null, "newHeader !is null");
244-}
245-out
246-{
247- assert (f.isOpen == true, "f.isOpen == true (out)");
248-}
249-do
250-{
251- import std.file : remove, tempDir;
252- import std.path : buildPath, baseName;
253- import std.string : strip;
254-
255- immutable originalPath = f.name;
256- immutable tempPath = buildPath(tempDir, baseName(originalPath));
257-
258- File tempFile = File(tempPath, "w+");
259-
260- string line = "";
261- bool pastHeader = false;
262-
263- /* Make sure we're at the start of the file. */
264- f.rewind ();
265-
266- while ((line = f.readln()) !is null)
267- {
268- if (false == pastHeader && '#' != line[0])
269- {
270- pastHeader = true;
271- tempFile.writefln ("%s\t%s", strip (line), newHeader);
272- }
273- else
274- {
275- /* strip + writeln since the previous one may not have had the newline */
276- tempFile.writeln (strip (line));
277- }
278- }
279-
280- f.close ();
281-
282- /*
283- * Since the temporary directory *could* be mounted differently (e.g. remotely)
284- * some systems don't like to copy from the temporary directory.
285- */
286- remove (originalPath);
287-
288- f.open (originalPath, "w+");
289- tempFile.rewind ();
290-
291- while ((line = tempFile.readln()) !is null)
292- {
293- f.write (line);
294- }
295-
296- /* Rewind since we need to re-parse the headers */
297- f.rewind ();
298-
299- tempFile.close();
300- remove (tempPath);
301-}