View Raw SPL
/* add string to a external file loader list */
_fileafadd(dext = "", dfunc = "", title = "", cmd = "")
{
        local j = 1, dstr;

        /* file association list */
        if (strlen(dext) > 0 && strlen(dfunc) > 0)
        {
                /* runtime file association list */
                dfile = _fileafname();

                /* load file as string */
                dstr = strfile(dfile, 0, 1);

                do
                {
                        /* get extensions delimited by ";" */
                        ext = strget(j++, dext, ";");

                        if (strlen(ext) == 0)
                        {
                                break;
                        }

                        /* add leading extension char */
                        if (not(ext[1] == charstr(".")))
                        {
                                ext = "." + ext;
                        }

                        /* check if string already in file */
                        if (strlen(strfind(ext, dstr)) == 0)
                        {
                                try
                                {
                                        /* not in file, add string */
                                        fopen(dfile, "a");
                                        fseek(dfile, 0, 2);

                                        fprintf(dfile, "%s,%s\n", ext, dfunc);

                                        fclose(dfile);
                                }
                                catch
                                {
                                        fclose(dfile);
                                }
                        }
                }
                while(1);
        }

        /* data reader menu */
        if (strlen(title) > 0 && strlen(cmd) > 0)
        {
                /* runtime datareader menu */
                dfile = _filerfname();

                /* load reader file as string */
                dstr = strfile(dfile, 0, 1);

                /* check if string already in file */
                if (strlen(strfind(title, dstr)) == 0)
                {
                        try
                        {
                                /* not in file, add string */
                                fopen(dfile, "a");
                                fseek(dfile, 0, 2);

                                fprintf(dfile, "\n%s~%s\n", title, cmd);

                                fclose(dfile);
                        }
                        catch
                        {
                                fclose(dfile);
                        }
                }
        }
}