• 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évisionf2f1d3a17c9e31ff289e47ae3516b5057f9107ac (tree)
l'heure2022-01-25 10:19:23
Auteurmio <stigma@disr...>
Commitermio

Message de Log

change error handling for ml_fetch_* functions.

FossilOrigin-Name: f02e7ff73665b75e1a87f98c34b9c1c8a0a4eee3452e996afca4b684c385645e

Change Summary

Modification

--- a/medialist.d
+++ b/medialist.d
@@ -43,6 +43,7 @@ struct MediaListItem
4343 string startDate;
4444 string endDate;
4545 string lastUpdated;
46+ bool valid = false;
4647 }
4748
4849 struct MediaListHeader
@@ -187,10 +188,16 @@ MediaListHeader[] ml_fetch_headers(MediaList* list)
187188 return headers;
188189 }
189190
190-MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item)
191+MediaListItem ml_fetch_item(MediaList* list, size_t id, MLError* err = null)
191192 {
192- if (true == list.isOpen)
193- return MLError.fileAlreadyOpen;
193+ MediaListItem newItem;
194+
195+ if (true == list.isOpen) {
196+ if (null !is err)
197+ *err = MLError.fileAlreadyOpen;
198+
199+ return newItem;
200+ }
194201
195202 list.isOpen = true;
196203
@@ -214,8 +221,12 @@ MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item)
214221 currentLine += 1;
215222 }
216223
217- if (false == found)
218- return MLError.itemNotFound;
224+ if (false == found) {
225+ if (null !is err)
226+ *err = MLError.itemNotFound;
227+
228+ return newItem;
229+ }
219230
220231 int[2][6] headerPositions = _ml_get_header_positions(list);
221232
@@ -252,21 +263,27 @@ MLError ml_fetch_item(MediaList* list, size_t id, MediaListItem* item)
252263 }
253264 }
254265
255- MediaListItem newItem = MediaListItem(sections[titleIndex],
256- sections[progressIndex], sections[statusIndex], sections[startIndex],
257- sections[endIndex], sections[lastIndex]);
258-
259- *item = newItem;
266+ newItem.title = sections[titleIndex];
267+ newItem.progress = sections[progressIndex];
268+ newItem.status = sections[statusIndex];
269+ newItem.startDate = sections[startIndex];
270+ newItem.endDate = sections[endIndex];
271+ newItem.lastUpdated = sections[lastIndex];
272+ newItem.valid = true;
260273
261274 list.isOpen = false;
262275
263- return MLError.success;
276+ return newItem;
264277 }
265278
266-MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...)
279+MediaListItem[] ml_fetch_items(MediaList* list, MLError* err, size_t[] ids ...)
267280 {
268- if (list.isOpen)
281+ if (list.isOpen) {
282+ if (null !is err)
283+ *err = MLError.fileAlreadyOpen;
284+
269285 return null;
286+ }
270287
271288 File listFile = File(list.filePath);
272289 list.isOpen = true;
@@ -325,7 +342,7 @@ MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...)
325342 string[] sections = line.strip().split("\t");
326343 items ~= MediaListItem(sections[titleIndex],
327344 sections[progressIndex], sections[statusIndex], sections[startIndex],
328- sections[endIndex], sections[lastIndex]);
345+ sections[endIndex], sections[lastIndex], true);
329346 }
330347
331348 currentID += 1;
@@ -334,10 +351,14 @@ MediaListItem[] ml_fetch_items(MediaList* list, size_t[] ids ...)
334351 return items;
335352 }
336353
337-MediaListItem[] ml_fetch_all(MediaList* list)
354+MediaListItem[] ml_fetch_all(MediaList* list, MLError* err = null)
338355 {
339- if (list.isOpen)
356+ if (list.isOpen) {
357+ if (null !is err)
358+ *err = MLError.fileAlreadyOpen;
359+
340360 return null;
361+ }
341362
342363 File listFile = File(list.filePath);
343364 list.isOpen = true;
@@ -395,7 +416,7 @@ MediaListItem[] ml_fetch_all(MediaList* list)
395416
396417 items ~= MediaListItem(sections[titleIndex],
397418 sections[progressIndex], sections[statusIndex], sections[startIndex],
398- sections[endIndex], sections[lastIndex]);
419+ sections[endIndex], sections[lastIndex], true);
399420 }
400421
401422 list.isOpen = false;