\doxysection{psse\+\_\+time.\+c}
\hypertarget{psse__time_8c_source}{}\label{psse__time_8c_source}\index{workspace/post-\/scarcity/src/time/psse\_time.c@{workspace/post-\/scarcity/src/time/psse\_time.c}}
\mbox{\hyperlink{psse__time_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00001}00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00002}00002\ \textcolor{comment}{\ *\ psse\_time.c}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00003}00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00004}00004\ \textcolor{comment}{\ *\ Bare\ bones\ of\ PSSE\ time.\ See\ issue\ \#16.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00005}00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00006}00006\ \textcolor{comment}{\ *\ (c)\ 2019\ Simon\ Brooke\ <simon@journeyman.cc>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00007}00007\ \textcolor{comment}{\ *\ Licensed\ under\ GPL\ version\ 2.0,\ or,\ at\ your\ option,\ any\ later\ version.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00008}00008\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00009}00009\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00010}00010\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00011}00011\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00012}00012\ \textcolor{preprocessor}{\#include\ <time.h>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00013}00013\ \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00014}00014\ \textcolor{comment}{\ *\ wide\ characters}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00015}00015\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00016}00016\ \textcolor{preprocessor}{\#include\ <wchar.h>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00017}00017\ \textcolor{preprocessor}{\#include\ <wctype.h>}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00018}00018\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00019}00019\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{conspage_8h}{memory/conspage.h}}"{}}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00020}00020\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{consspaceobject_8h}{memory/consspaceobject.h}}"{}}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00021}00021\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{integer_8h}{arith/integer.h}}"{}}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00022}00022\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{psse__time_8h}{time/psse\_time.h}}"{}}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00023}\mbox{\hyperlink{psse__time_8c_a369266c24eacffb87046522897a570d5}{00023}}\ \textcolor{preprocessor}{\#define\ \_GNU\_SOURCE}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00024}00024\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00025}\mbox{\hyperlink{psse__time_8c_afedbc7754156f23b86028f925a7c19b1}{00025}}\ \textcolor{preprocessor}{\#define\ seconds\_per\_year\ 31557600L}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00026}00026\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00027}00027\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00028}00028\ \textcolor{comment}{\ *\ PSSE\ Lisp\ epoch\ is\ 14\ Bn\ years,\ or\ 441,806,400,000,000,000\ seconds,\ before}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00029}00029\ \textcolor{comment}{\ *\ the\ UNIX\ epoch;\ the\ value\ in\ microseconds\ will\ break\ the\ C\ reader.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00030}00030\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00031}\mbox{\hyperlink{psse__time_8c_ad48a548e14fcf5d9badb36ad678147e9}{00031}}\ \textcolor{keywordtype}{unsigned}\ \_\_int128\ \mbox{\hyperlink{psse__time_8c_ad48a548e14fcf5d9badb36ad678147e9}{epoch\_offset}}\ =}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00032}00032\ \ \ \ \ (\ (\ \_\_int128\ )\ (\ \mbox{\hyperlink{psse__time_8c_afedbc7754156f23b86028f925a7c19b1}{seconds\_per\_year}}\ *\ 1000000000L\ )\ *}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00033}00033\ \ \ \ \ \ \ (\ \_\_int128\ )\ (\ 14L\ *\ 1000000000L\ )\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00034}00034\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00035}00035\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00036}00036\ \textcolor{comment}{\ *\ Return\ the\ UNIX\ time\ value\ which\ represents\ this\ time,\ if\ it\ falls\ within}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00037}00037\ \textcolor{comment}{\ *\ the\ period\ representable\ in\ UNIX\ time,\ or\ zero\ otherwise.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00038}00038\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00039}\mbox{\hyperlink{psse__time_8c_a51ce7b6c694f7a4e972260b9b35bd485}{00039}}\ \textcolor{keywordtype}{long}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{psse__time_8c_a51ce7b6c694f7a4e972260b9b35bd485}{lisp\_time\_to\_unix\_time}}(\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ t\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00040}00040\ \ \ \ \ \textcolor{keywordtype}{long}\ \textcolor{keywordtype}{int}\ result\ =\ 0;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00041}00041\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00042}00042\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ \mbox{\hyperlink{consspaceobject_8h_a3ad5d08399d0601635ee20ffe4c925a5}{timep}}(\ t\ )\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00043}00043\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \_\_int128\ value\ =\ \mbox{\hyperlink{consspaceobject_8h_af31e1da9438d7ae4410864ecc901b131}{pointer2cell}}(\ t\ ).payload.time.value;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00044}00044\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00045}00045\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\ value\ >\ \mbox{\hyperlink{psse__time_8c_ad48a548e14fcf5d9badb36ad678147e9}{epoch\_offset}}\ )\ \{\ \textcolor{comment}{//\ \(\backslash\)todo\ \&\&\ value\ <\ UNIX\ time\ rollover}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00046}00046\ \ \ \ \ \ \ \ \ \ \ \ \ result\ =\ (\ (\ value\ -\/\ \mbox{\hyperlink{psse__time_8c_ad48a548e14fcf5d9badb36ad678147e9}{epoch\_offset}}\ )\ /\ 1000000000\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00047}00047\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00048}00048\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00049}00049\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00050}00050\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00051}00051\ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00052}00052\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00053}\mbox{\hyperlink{psse__time_8c_a06a36fdf3aead5f88fc1da556f4f63cf}{00053}}\ \textcolor{keywordtype}{unsigned}\ \_\_int128\ \mbox{\hyperlink{psse__time_8c_a06a36fdf3aead5f88fc1da556f4f63cf}{unix\_time\_to\_lisp\_time}}(\ time\_t\ t\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00054}00054\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \_\_int128\ result\ =\ \mbox{\hyperlink{psse__time_8c_ad48a548e14fcf5d9badb36ad678147e9}{epoch\_offset}}\ +\ (\ t\ *\ 1000000000\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00055}00055\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00056}00056\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00057}00057\ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00058}00058\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00059}\mbox{\hyperlink{psse__time_8c_acdecd05c91cfe78f2f5989101a68123a}{00059}}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ \mbox{\hyperlink{psse__time_8c_acdecd05c91cfe78f2f5989101a68123a}{make\_time}}(\ struct\ \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ integer\_or\_nil\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00060}00060\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ pointer\ =\ \mbox{\hyperlink{conspage_8c_a04ba7c874b05e9789d0aca9ee6b106a7}{allocate\_cell}}(\ \mbox{\hyperlink{consspaceobject_8h_a4628563add0c56fbe9785f015e159022}{TIMETV}}\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00061}00061\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__space__object}{cons\_space\_object}}\ *cell\ =\ \&\mbox{\hyperlink{consspaceobject_8h_af31e1da9438d7ae4410864ecc901b131}{pointer2cell}}(\ pointer\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00062}00062\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00063}00063\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ \mbox{\hyperlink{consspaceobject_8h_af99c355c0b2f78228a1e9e4e68dcfe76}{integerp}}(\ integer\_or\_nil\ )\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00064}00064\ \ \ \ \ \ \ \ \ cell-\/>\mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{payload}}.time.value\ =}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00065}00065\ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{consspaceobject_8h_af31e1da9438d7ae4410864ecc901b131}{pointer2cell}}(\ integer\_or\_nil\ ).\mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{payload}}.integer.value;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00066}00066\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00067}00067\ \ \ \ \ \ \ \ \ cell-\/>\mbox{\hyperlink{consspaceobject_8h_a259b3afe36776f8ba8498fdf95904f25}{payload}}.time.value\ =\ \mbox{\hyperlink{psse__time_8c_a06a36fdf3aead5f88fc1da556f4f63cf}{unix\_time\_to\_lisp\_time}}(\ time(\ NULL\ )\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00068}00068\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00069}00069\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00070}00070\ \ \ \ \ \textcolor{keywordflow}{return}\ pointer;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00071}00071\ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00072}00072\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00073}00073\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00074}00074\ \textcolor{comment}{\ *\ Function;\ return\ a\ time\ representation\ of\ the\ first\ argument\ in\ the\ frame;}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00075}00075\ \textcolor{comment}{\ *\ further\ arguments\ are\ ignored.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00076}00076\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00077}00077\ \textcolor{comment}{\ *\ *\ (time\ integer\_or\_nil)}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00078}00078\ \textcolor{comment}{\ *}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00079}00079\ \textcolor{comment}{\ *\ @param\ frame\ my\ stack\_frame.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00080}00080\ \textcolor{comment}{\ *\ @param\ frame\_pointer\ a\ pointer\ to\ my\ stack\_frame.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00081}00081\ \textcolor{comment}{\ *\ @param\ env\ my\ environment.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00082}00082\ \textcolor{comment}{\ *\ @return\ a\ lisp\ time;\ if\ \`{}integer\_or\_nil`\ is\ an\ integer,\ return\ a\ time\ which}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00083}00083\ \textcolor{comment}{\ *\ is\ that\ number\ of\ microseconds\ after\ the\ notional\ big\ bang;\ else\ the\ current}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00084}00084\ \textcolor{comment}{\ *\ time.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00085}00085\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00086}\mbox{\hyperlink{psse__time_8c_a577c1ca3a52e477c2a5cd1e3ac7e0030}{00086}}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ \mbox{\hyperlink{psse__time_8c_a577c1ca3a52e477c2a5cd1e3ac7e0030}{lisp\_time}}(\ struct\ \mbox{\hyperlink{consspaceobject_8h_structstack__frame}{stack\_frame}}\ *frame,}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00087}00087\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ frame\_pointer,}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00088}00088\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ struct\ \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ env\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00089}00089\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{psse__time_8c_acdecd05c91cfe78f2f5989101a68123a}{make\_time}}(\ frame-\/>arg[0]\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00090}00090\ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00091}00091\ \textcolor{comment}{}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00092}00092\ \textcolor{comment}{/**}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00093}00093\ \textcolor{comment}{\ *\ This\ is\ temporary,\ for\ bootstrapping.}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00094}00094\ \textcolor{comment}{\ */}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00095}\mbox{\hyperlink{psse__time_8c_a186e6b6a13bf5f7ba53bbcd1e546f75f}{00095}}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ \mbox{\hyperlink{psse__time_8c_a186e6b6a13bf5f7ba53bbcd1e546f75f}{time\_to\_string}}(\ struct\ \mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ pointer\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00096}00096\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{consspaceobject_8h_structcons__pointer}{cons\_pointer}}\ result\ =\ \mbox{\hyperlink{consspaceobject_8h_a263efce0e5cda1d387a1a43f94715445}{NIL}};}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00097}00097\ \ \ \ \ \textcolor{keywordtype}{long}\ \textcolor{keywordtype}{int}\ t\ =\ \mbox{\hyperlink{psse__time_8c_a51ce7b6c694f7a4e972260b9b35bd485}{lisp\_time\_to\_unix\_time}}(\ pointer\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00098}00098\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00099}00099\ \ \ \ \ \textcolor{keywordflow}{if}\ (\ t\ !=\ 0\ )\ \{}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00100}00100\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{char}\ *bytes\ =\ ctime(\ \&t\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00101}00101\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ l\ =\ strlen(\ bytes\ )\ +\ 1;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00102}00102\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{wchar\_t}\ buffer[l];}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00103}00103\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00104}00104\ \ \ \ \ \ \ \ \ mbstowcs(\ buffer,\ bytes,\ l\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00105}00105\ \ \ \ \ \ \ \ \ result\ =\ \mbox{\hyperlink{consspaceobject_8h_a9e4202c8555763ca9a119f0d63a058cd}{c\_string\_to\_lisp\_string}}(\ buffer\ );}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00106}00106\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00107}00107\ }
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00108}00108\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{\Hypertarget{psse__time_8c_source_l00109}00109\ \}}

\end{DoxyCode}
