Update of /cvsroot/pure-data/externals/miXed/shared/toxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5003/shared/toxy
Modified Files: scriptlet.c scriptlet.h Log Message: widget: redefine, version control, better kb
Index: scriptlet.h =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/shared/toxy/scriptlet.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** scriptlet.h 10 Mar 2004 10:55:55 -0000 1.4 --- scriptlet.h 21 Dec 2004 11:32:12 -0000 1.5 *************** *** 1,3 **** ! /* Copyright (c) 2003 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ --- 1,3 ---- ! /* Copyright (c) 2003-2004 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ *************** *** 7,10 **** --- 7,11 ----
enum { SCRIPTLET_OK = 0, SCRIPTLET_NOFILE, SCRIPTLET_BADFILE, + SCRIPTLET_NOVERSION, SCRIPTLET_OLDERVERSION, SCRIPTLET_NEWERVERSION, SCRIPTLET_IGNORED }; #define SCRIPTLET_UNLOCK ((t_scriptlet *)0)
Index: scriptlet.c =================================================================== RCS file: /cvsroot/pure-data/externals/miXed/shared/toxy/scriptlet.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** scriptlet.c 10 Dec 2004 20:47:04 -0000 1.14 --- scriptlet.c 21 Dec 2004 11:32:12 -0000 1.15 *************** *** 30,33 **** --- 30,43 ---- enum { SCRIPTLET_CVOK, SCRIPTLET_CVUNKNOWN, SCRIPTLET_CVMISSING };
+ #define VERSLET_MAXPACKAGE 32 + #define VERSLET_MAXVERSION 32 + + typedef struct _verslet + { + t_pd *v_owner; + char v_package[VERSLET_MAXPACKAGE]; + char v_version[VERSLET_MAXVERSION]; + } t_verslet; + struct _scriptlet { *************** *** 619,628 **** }
static int scriptlet_doread(t_scriptlet *sp, t_pd *caller, FILE *fp, ! char *rc, char *builtin, t_scriptlet_cmntfn cmntfn) { t_scriptlet *outsp = sp, *newsp; char buf[MAXPDSTRING]; if (!caller) caller = sp->s_owner; while ((fp && !feof(fp) && fgets(buf, MAXPDSTRING - 1, fp)) || builtin) --- 629,791 ---- }
+ static t_verslet *verslet_new(t_pd *owner) + { + t_verslet *vp = getbytes(sizeof(*vp)); + vp->v_owner = owner; + vp->v_package[0] = 0; + vp->v_version[0] = 0; + return (vp); + } + + static void verslet_free(t_verslet *vp) + { + freebytes(vp, sizeof(*vp)); + } + + static void verslet_set(t_verslet *vp, char *pname, char *vname) + { + strncpy(vp->v_package, pname, VERSLET_MAXPACKAGE-1); + vp->v_package[VERSLET_MAXPACKAGE-1] = 0; + strncpy(vp->v_version, vname, VERSLET_MAXVERSION-1); + vp->v_version[VERSLET_MAXVERSION-1] = 0; + } + + static int verslet_parse(t_verslet *vp, char *buf, int multiline) + { + char *ptr = buf; + int plen = 0; + vp->v_package[0] = 0; + vp->v_version[0] = 0; + if (multiline) + { + while (*ptr) + { + while (*ptr == ' ' || *ptr == '\t') ptr++; + if (strncmp(ptr, "package", 7)) + { + while (*ptr && *ptr != '\n') ptr++; + if (*ptr) + buf = ++ptr; + } + else break; + } + if (*ptr) + ptr += 7; + else + ptr = 0; + } + else + { + while (*ptr == ' ' || *ptr == '\t') ptr++; + if (strncmp(ptr, "package", 7)) + ptr = 0; + else + ptr += 7; + } + if (ptr) + { + while (*ptr == ' ' || *ptr == '\t') ptr++; + if (!strncmp(ptr, "provide", 7)) + { + ptr += 7; + while (*ptr == ' ' || *ptr == '\t') ptr++; + if (*ptr) + { + for (plen = 0; plen < VERSLET_MAXPACKAGE-1 && *ptr; + plen++, ptr++) + { + if (*ptr == '\n' || *ptr == '\r') + break; + else if (*ptr == ' ' || *ptr == '\t') + { + vp->v_package[plen] = 0; + #ifdef SCRIPTLET_DEBUG + fprintf(stderr, "package "%s"\n", vp->v_package); + #endif + while (*ptr == ' ' || *ptr == '\t') ptr++; + if (*ptr >= '0' && *ptr <= '9') + { + int vlen; + for (vlen = 0; vlen < VERSLET_MAXVERSION-1 && *ptr; + vlen++, ptr++) + { + if ((*ptr >= '0' && *ptr <= '9') || *ptr == '.') + vp->v_version[vlen] = *ptr; + else + break; + } + if (vlen) + { + vp->v_version[vlen] = 0; + #ifdef SCRIPTLET_DEBUG + fprintf(stderr, "version "%s"\n", + vp->v_version); + #endif + return (1); + } + } + break; + } + else vp->v_package[plen] = *ptr; + } + } + } + if (plen) + loud_error(vp->v_owner, + "incomplete scriptlet version declaration "%s"", buf); + } + return (0); + } + + static int verslet_compare(t_verslet *vp1, t_verslet *vp2) + { + char *vname1 = vp1->v_version, *vname2 = vp2->v_version; + while (*vname1 || *vname2) + { + int v1, v2; + for (v1 = 0; *vname1 >= '0' && *vname1 <= '9'; vname1++) + v1 = v1 * 10 + *vname1 - '0'; + for (v2 = 0; *vname2 >= '0' && *vname2 <= '9'; vname2++) + v2 = v2 * 10 + *vname2 - '0'; + if (v1 < v2) + return (-1); + else if (v1 > v2) + return (1); + if (*vname1) + { + if (*vname1 == '.') + *vname1++; + if (*vname1 < '0' || *vname1 > '9') + { + loud_error(vp1->v_owner, "invalid version "%s"", + vp1->v_version); + while (*vname1) *vname1++; + } + } + if (*vname2) + { + if (*vname2 == '.') + *vname2++; + if (*vname2 < '0' || *vname2 > '9') + { + loud_error(vp2->v_owner, "invalid version "%s"", + vp2->v_version); + while (*vname2) *vname2++; + } + } + } + return (0); + } + static int scriptlet_doread(t_scriptlet *sp, t_pd *caller, FILE *fp, ! char *rc, t_verslet *vcompare, ! char *builtin, t_scriptlet_cmntfn cmntfn) { t_scriptlet *outsp = sp, *newsp; + t_verslet *vp; + int vdiff = 0; char buf[MAXPDSTRING]; if (!caller) caller = sp->s_owner; + vp = (vcompare ? verslet_new(caller) : 0); while ((fp && !feof(fp) && fgets(buf, MAXPDSTRING - 1, fp)) || builtin) *************** *** 644,650 **** } } ! else for (ptr = buf; *ptr; ptr++) ! if (*ptr == '\r') ! *ptr = ' '; /* LATER rethink */ ptr = buf; while (*ptr == ' ' || *ptr == '\t') ptr++; --- 807,826 ---- } } ! else ! { ! for (ptr = buf; *ptr; ptr++) ! if (*ptr == '\r') ! *ptr = ' '; /* LATER rethink */ ! if (vp && verslet_parse(vp, buf, 0)) ! { ! if (vdiff = verslet_compare(vp, vcompare)) ! goto readfailed; ! else ! { ! verslet_free(vp); ! vp = 0; ! } ! } ! } ptr = buf; while (*ptr == ' ' || *ptr == '\t') ptr++; *************** *** 667,670 **** --- 843,848 ---- ep[1] = 0; } + if (vp) + goto readfailed; /* FIXME call a request cmntfn? */ newsp = cmntfn(caller, rc, sel, ptr); if (newsp == SCRIPTLET_UNLOCK) *************** *** 683,688 **** scriptlet_doappend(outsp, buf); } outsp->s_locked = 0; ! return (SCRIPTLET_OK); }
--- 861,878 ---- scriptlet_doappend(outsp, buf); } + readfailed: outsp->s_locked = 0; ! if (vp) ! { ! verslet_free(vp); ! scriptlet_reset(sp); ! if (vdiff < 0) ! return (SCRIPTLET_OLDERVERSION); ! else if (vdiff > 0) ! return (SCRIPTLET_NEWERVERSION); ! else ! return (SCRIPTLET_NOVERSION); ! } ! else return (SCRIPTLET_OK); }
*************** *** 694,698 **** int result; sp->s_locked = 1; /* see scriptlet_doread() above for unlocking scheme */ ! result = scriptlet_doread(sp, caller, 0, rc, contents, cmntfn); return (result); } --- 884,888 ---- int result; sp->s_locked = 1; /* see scriptlet_doread() above for unlocking scheme */ ! result = scriptlet_doread(sp, caller, 0, rc, 0, contents, cmntfn); return (result); } *************** *** 726,735 **** if (fp = fopen(filename, "r")) { ! result = scriptlet_doread(sp, caller, fp, rc, 0, cmntfn); fclose(fp); } else { ! bug("scriptlet_rcload"); result = SCRIPTLET_NOFILE; } --- 916,939 ---- if (fp = fopen(filename, "r")) { ! t_verslet *vp; ! if (builtin) ! { ! vp = verslet_new(sp->s_owner); ! if (!verslet_parse(vp, builtin, 1)) ! { ! bug("scriptlet_rcload 1"); ! verslet_free(vp); ! vp = 0; ! } ! } ! else vp = 0; ! result = scriptlet_doread(sp, caller, fp, rc, vp, 0, cmntfn); fclose(fp); + if (vp) + verslet_free(vp); } else { ! bug("scriptlet_rcload 2"); result = SCRIPTLET_NOFILE; } *************** *** 737,741 **** if (result != SCRIPTLET_OK) { ! scriptlet_doread(sp, caller, 0, rc, builtin, cmntfn); } return (result); --- 941,945 ---- if (result != SCRIPTLET_OK) { ! scriptlet_doread(sp, caller, 0, rc, 0, builtin, cmntfn); } return (result); *************** *** 757,761 **** { scriptlet_reset(sp); ! result = scriptlet_doread(sp, 0, fp, 0, 0, 0); fclose(fp); } --- 961,965 ---- { scriptlet_reset(sp); ! result = scriptlet_doread(sp, 0, fp, 0, 0, 0, 0); fclose(fp); }