Changeset 1c9d98 in git for Singular


Ignore:
Timestamp:
Jan 21, 2020, 1:08:05 PM (4 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c4ae15496628debfb40fd913b30f80d190ebd49a
Parents:
c3239f94e91d849c92850b63ee75974ac46a405b
Message:
adapt to Singulars history (must set SINGULARHIST)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/dyn_modules/machinelearning/machinelearning.cc

    rc3239f9 r1c9d98  
    1010static BOOLEAN predictHelp(leftv result, leftv arg)
    1111{
    12         char *buffer[5];
    13         int lengths[5];
    14         char filename[15] = "~/.history";
    15         int i;
    16         lists L = (lists)omAllocBin(slists_bin);
     12        char *buffer[5];
     13        int lengths[5];
     14        char *filename = getenv("SINGULARHIST");
     15        if (filename==NULL) filename=(char*)"~/.history";
     16        int i;
     17        lists L = (lists)omAllocBin(slists_bin);
    1718
    18         buffer[0] = NULL;
    19         buffer[1] = NULL;
    20         buffer[2] = NULL;
    21         buffer[3] = NULL;
    22         buffer[4] = NULL;
     19        buffer[0] = NULL;
     20        buffer[1] = NULL;
     21        buffer[2] = NULL;
     22        buffer[3] = NULL;
     23        buffer[4] = NULL;
    2324
    24         if (write_history(NULL)) {
    25                 printf("Failed to write history\n");
    26                 return TRUE;
    27         }
     25        if (write_history(filename))
     26        {
     27                printf("Failed to write history\n");
     28                return TRUE;
     29        }
    2830
    29         if (!ml_initialise()) {
    30                 Print("Initialise of ml failed.");
    31                 PrintLn();
    32                 /* Notify singular that an error occured */
    33                 return TRUE;
    34         }
     31        if (!ml_initialise())
     32        {
     33                WerrorS("Initialise of ml failed.");
     34                /* Notify singular that an error occured */
     35                return TRUE;
     36        }
    3537
    36         ml_make_prediction(filename, buffer, lengths, _omStrDup);
     38        ml_make_prediction(filename, buffer, lengths, _omStrDup);
    3739
    38         L->Init(5);
     40        L->Init(5);
    3941
    40         for (i = 0; i < 5; i++) {
    41                 //printf("prediction %d: %s\n", i, buffer[i]);
    42                 L->m[i].rtyp = STRING_CMD;
    43                 L->m[i].data = buffer[i];
    44         }
     42        for (i = 0; i < 5; i++) {
     43                //printf("prediction %d: %s\n", i, buffer[i]);
     44                L->m[i].rtyp = STRING_CMD;
     45                L->m[i].data = buffer[i];
     46        }
    4547
    46         // pass the resultant list to the res datastructure
    47         result->rtyp=LIST_CMD;
    48         result->data=(void *)L;
     48        // pass the resultant list to the res datastructure
     49        result->rtyp=LIST_CMD;
     50        result->data=(void *)L;
    4951
    50         ml_finalise();
    51         return FALSE;
     52        ml_finalise();
     53        return FALSE;
    5254
    53         //result->rtyp=NONE; // set the result type
     55        //result->rtyp=NONE; // set the result type
    5456}
    5557
     
    5759extern "C" int SI_MOD_INIT(machinelearning)(SModulFunctions* psModulFunctions)
    5860{
    59         // this is the initialization routine of the module
    60         // adding the routine predictHelp:
    61         psModulFunctions->iiAddCproc(
    62                         (currPack->libname? currPack->libname: ""),
    63                         "predictHelp",// for the singular interpreter
    64                         FALSE, // should enter the global name space
    65                         predictHelp); // the C/C++ routine
    66         return MAX_TOK;
     61        char *filename = getenv("SINGULARHIST");
     62        if (filename==NULL)
     63        {
     64          WarnS("SINGULARHIST is not set - no history available, using ~/.history");
     65        }
     66        // this is the initialization routine of the module
     67        // adding the routine predictHelp:
     68        psModulFunctions->iiAddCproc(
     69                        (currPack->libname? currPack->libname: ""),
     70                        "predictHelp",// for the singular interpreter
     71                        FALSE, // should enter the global name space
     72                        predictHelp); // the C/C++ routine
     73        return MAX_TOK;
    6774}
Note: See TracChangeset for help on using the changeset viewer.