L1VM file tools directory

This example program shows the files inside the ~/l1vm/test directory. The file/directory names are stored in a string array variable.

// file-tools-dir.l1com
// file library module
// test program
//
//
#include <intr.l1h>
(main func)
    #include <file-def.l1h>
    (set int64 1 zero 0)
    (set int64 1 one 1)
    (set string s directorystr "test")
    (set string s filesstr " files: ")
    (set string s error_files_overflowstr "ERROR: file max overflow!")
    (set int64 1 files 0)
    (set int64 1 ret 0)

    (set int64 1 string_len 256)
    (set int64 1 filesarraylen 256)
    (set string 256 file_entrystr)
    (set string 256 filesarraystr)
    (set int64 1 index 0)

    (set int64 1 f 0)
    (set int64 1 i 0)

    (zero :file_tools_init !)
    (one :string_init !)

    // get number of files
    (directorystr :file_tools_dir_entries !)
    (files stpop)

    print_s (directorystr)
    print_s (filesstr)
    print_i (files)
    print_n

    (((files zero ==) f =) f if)
         exit (zero)
    (endif)

    // get objects in directory: "test"
    (for-loop)
    (((i files <) f =) f for)
         (directorystr filesarraystr string_len filesarraylen i i :file_tools_dir_files !)
         (ret stpop)

         (filesarraystr file_entrystr index string_len filesarraylen :array_to_string !)
         print_s (file_entrystr)
         print_n

         {i = (i + one)}
    (next)
    exit (zero)
(funcend)

#include <file-tools-lib.l1h>
#include <string.l1h>