No longer need to mention bigarray, begin to replace Unix

This commit is contained in:
John Whitington 2020-06-11 18:24:55 +01:00
parent b392d54149
commit 2e6247013b
2 changed files with 59 additions and 1 deletions

View File

@ -3,7 +3,7 @@ MODS = tjutil tjutf16 tjllist tjparserMonad tjjson \
xmlm \ xmlm \
cpdfwriteJSON cpdfstrftime cpdfcoord cpdf cpdfcommand cpdfwriteJSON cpdfstrftime cpdfcoord cpdf cpdfcommand
SOURCES = $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml SOURCES = cpdftime.c $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml
RESULT = cpdf RESULT = cpdf
ANNOTATE = true ANNOTATE = true

58
cpdftime.c Normal file
View File

@ -0,0 +1,58 @@
/**************************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <sys/time.h>
double cpdf_unix_gettimeofday_unboxed(value unit)
{
struct timeval tp;
gettimeofday(&tp, NULL);
return ((double) tp.tv_sec + (double) tp.tv_usec / 1e6);
}
CAMLprim value cpdf_unix_gettimeofday(value unit)
{
return caml_copy_double(cpdf_unix_gettimeofday_unboxed(unit));
}
static value cpdf_alloc_tm(struct tm *tm)
{
value res;
res = caml_alloc_small(9, 0);
Field(res,0) = Val_int(tm->tm_sec);
Field(res,1) = Val_int(tm->tm_min);
Field(res,2) = Val_int(tm->tm_hour);
Field(res,3) = Val_int(tm->tm_mday);
Field(res,4) = Val_int(tm->tm_mon);
Field(res,5) = Val_int(tm->tm_year);
Field(res,6) = Val_int(tm->tm_wday);
Field(res,7) = Val_int(tm->tm_yday);
Field(res,8) = tm->tm_isdst ? Val_true : Val_false;
return res;
}
CAMLprim value cpdf_unix_localtime(value t)
{
time_t clock;
struct tm * tm;
clock = (time_t) Double_val(t);
tm = localtime(&clock);
return cpdf_alloc_tm(tm);
}