Diff
Not logged in

Differences From:

File src/tkt.c part of check-in [5f3ddcc1b8] - Add ticket configuration editing capability. by drh on 2007-11-25 21:11:33. Also file src/tkt.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

To:

File src/tkt.c part of check-in [3122fc4c7e] - Continuing work on tickets (still not working right.) Improvements to the web pages. by drh on 2008-02-14 02:49:41. Also file src/tkt.c part of check-in [588bb7cd73] - Merged to ed26056bb5. by aku on 2008-02-24 18:50:35. [view]

@@ -38,13 +38,8 @@
 static char **azValue = 0;    /* Original values */
 static char **azAppend = 0;   /* Value to be appended */
 
 /*
-** A subscript interpreter used for processing Tickets.
-*/
-static struct Subscript *pInterp = 0;
-
-/*
 ** Compare two entries in azField for sorting purposes
 */
 static int nameCmpr(const void *a, const void *b){
   return strcmp(*(char**)a, *(char**)b);
@@ -122,19 +117,19 @@
           azValue[j] = mprintf("%s", zVal);
           break;
         }
       }
-      if( SbS_Fetch(pInterp, zName, -1, &size)==0 ){
-        SbS_Store(pInterp, db_column_name(&q,i), zVal, 1);
+      if( Th_Fetch(zName, &size)==0 ){
+        Th_Store(db_column_name(&q,i), zVal);
       }
     }
   }else{
     db_finalize(&q);
     db_prepare(&q, "PRAGMA table_info(ticket)");
     while( db_step(&q)==SQLITE_ROW ){
       const char *zField = db_column_text(&q, 1);
-      if( SbS_Fetch(pInterp, zField, -1, &size)==0 ){
-        SbS_Store(pInterp, zField, "", 0);
+      if( Th_Fetch(zField, &size)==0 ){
+        Th_Store(zField, "");
       }
     }
   }
   db_finalize(&q);
@@ -147,9 +142,9 @@
   int i;
   const char *z;
 
   for(i=0; (z = cgi_parameter_name(i))!=0; i++){
-    SbS_Store(pInterp, z, P(z), 0);
+    Th_Store(z, P(z));
   }
 }
 
 /*
@@ -255,13 +250,12 @@
 ** Create the subscript interpreter and load the ticket configuration.
 */
 void ticket_init(void){
   char *zConfig;
-  if( pInterp ) return;
-  pInterp = SbS_Create();
+  Th_FossilInit();
   zConfig = db_text((char*)zDefaultTicketConfig,
              "SELECT value FROM config WHERE name='ticket-configuration'");
-  SbS_Eval(pInterp, zConfig, -1);
+  Th_Eval(g.interp, 0, (const uchar*)zConfig, -1);
 }
 
 /*
 ** Recreate the ticket table.
@@ -271,9 +265,9 @@
   int nSql;
 
   db_multi_exec("DROP TABLE IF EXISTS ticket;");
   ticket_init();
-  zSql = (char*)SbS_Fetch(pInterp, "ticket_sql", -1, &nSql);
+  zSql = (char*)Th_Fetch("ticket_sql", &nSql);
   if( zSql==0 ){
     fossil_panic("no ticket_sql defined by ticket configuration");
   }
   if( separateConnection ){
@@ -320,52 +314,60 @@
   }
   style_header("View Ticket");
   ticket_init();
   initializeVariablesFromDb();
-  zScript = (char*)SbS_Fetch(pInterp, "tktview_template", -1, &nScript);
+  zScript = (char*)Th_Fetch("tktview_template", &nScript);
   zScript = mprintf("%.*s", nScript, zScript);
-  SbS_Render(pInterp, zScript);
+  Th_Render(zScript);
   style_footer();
 }
 
-
-
 /*
-** Subscript command:   STRING FIELD append_field
+** TH command:   append_field FIELD STRING
 **
 ** FIELD is the name of a database column to which we might want
 ** to append text.  STRING is the text to be appended to that
 ** column.  The append does not actually occur until the
-** submit_ticket_change verb is run.
+** submit_ticket command is run.
 */
-static int appendRemarkCmd(struct Subscript *p, void *notUsed){
-  int idx;
-  const char *zField, *zValue;
-  int nField, nValue;
+static int appendRemarkCmd(
+  Th_Interp *interp,
+  void *p,
+  int argc,
+  const unsigned char **argv,
+  int *argl
+){
+  int idx;
 
-  if( SbS_RequireStack(p, 2, "append_field") ) return 1;
-  zField = SbS_StackValue(p, 0, &nField);
+  if( argc!=3 ){
+    return Th_WrongNumArgs(interp, "append_field FIELD STRING");
+  }
   for(idx=0; idx<nField; idx++){
-    if( strncmp(azField[idx], zField, nField)==0 && azField[idx][nField]==0 ){
+    if( strncmp(azField[idx], (const char*)argv[1], argl[1])==0
+        && azField[idx][argl[1]]==0 ){
       break;
     }
   }
   if( idx>=nField ){
-    SbS_SetErrorMessage(p, "no such TICKET column: %.*s", nField, zField);
-    return SBS_ERROR;
-  }
-  zValue = SbS_StackValue(p, 1, &nValue);
-  azAppend[idx] = mprintf("%.*s", nValue, zValue);
-  SbS_Pop(p, 2);
-  return SBS_OK;
+    Th_ErrorMessage(g.interp, "no such TICKET column: ", argv[1], argl[1]);
+    return TH_ERROR;
+  }
+  azAppend[idx] = mprintf("%.*s", argl[2], argv[2]);
+  return TH_OK;
 }
 
 /*
 ** Subscript command:   submit_ticket
 **
 ** Construct and submit a new ticket artifact.
 */
-static int submitTicketCmd(struct Subscript *p, void *pUuid){
+static int submitTicketCmd(
+  Th_Interp *interp,
+  void *pUuid,
+  int argc,
+  const unsigned char **argv,
+  int *argl
+){
   char *zDate;
   const char *zUuid;
   int i;
   int rid;
@@ -383,9 +385,9 @@
     if( azAppend[i] ){
       blob_appendf(&tktchng, "J +%s %z\n", azField[i],
                    fossilize(azAppend[i], -1));
     }else{
-      zValue = SbS_Fetch(p, azField[i], -1, &nValue);
+      zValue = Th_Fetch(azField[i], &nValue);
       if( zValue ){
         while( nValue>0 && isspace(zValue[nValue-1]) ){ nValue--; }
         if( strncmp(zValue, azValue[i], nValue)
                 || strlen(azValue[i])!=nValue ){
@@ -412,18 +414,17 @@
     @ <hr><pre>
     @ %h(blob_str(&tktchng))
     @ </pre><hr>
     blob_zero(&tktchng);
-    SbS_Pop(p, 1);
-    return SBS_OK;
+    return TH_OK;
   }
 
   rid = content_put(&tktchng, 0, 0);
   if( rid==0 ){
     fossil_panic("trouble committing ticket: %s", g.zErrMsg);
   }
   manifest_crosslink(rid, &tktchng);
-  return SBS_RETURN;
+  return TH_RETURN;
 }
 
 
 /*
@@ -447,16 +448,18 @@
   if( !g.okNewTkt ){ login_needed(); return; }
   style_header("New Ticket");
   ticket_init();
   getAllTicketFields();
+  initializeVariablesFromDb();
   initializeVariablesFromCGI();
   @ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
-  zScript = (char*)SbS_Fetch(pInterp, "tktnew_template", -1, &nScript);
+  zScript = (char*)Th_Fetch("tktnew_template", &nScript);
   zScript = mprintf("%.*s", nScript, zScript);
-  SbS_Store(pInterp, "login", g.zLogin, 0);
-  SbS_Store(pInterp, "date", db_text(0, "SELECT datetime('now')"), 2);
-  SbS_AddVerb(pInterp, "submit_ticket", submitTicketCmd, (void*)&zNewUuid);
-  if( SbS_Render(pInterp, zScript)==SBS_RETURN && zNewUuid ){
+  Th_Store("login", g.zLogin);
+  Th_Store("date", db_text(0, "SELECT datetime('now')"));
+  Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,
+                   (void*)&zNewUuid, 0);
+  if( Th_Render(zScript)==TH_RETURN && zNewUuid ){
     cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zNewUuid));
     return;
   }
   @ </form>
@@ -508,15 +511,15 @@
   initializeVariablesFromCGI();
   initializeVariablesFromDb();
   @ <form method="POST" action="%s(g.zBaseURL)/%s(g.zPath)">
   @ <input type="hidden" name="name" value="%s(zName)">
-  zScript = (char*)SbS_Fetch(pInterp, "tktedit_template", -1, &nScript);
+  zScript = (char*)Th_Fetch("tktedit_template", &nScript);
   zScript = mprintf("%.*s", nScript, zScript);
-  SbS_Store(pInterp, "login", g.zLogin, 0);
-  SbS_Store(pInterp, "date", db_text(0, "SELECT datetime('now')"), 2);
-  SbS_AddVerb(pInterp, "append_field", appendRemarkCmd, 0);
-  SbS_AddVerb(pInterp, "submit_ticket", submitTicketCmd, (void*)&zName);
-  if( SbS_Render(pInterp, zScript)==SBS_RETURN && zName ){
+  Th_Store("login", g.zLogin);
+  Th_Store("date", db_text(0, "SELECT datetime('now')"));
+  Th_CreateCommand(g.interp, "append_field", appendRemarkCmd, 0, 0);
+  Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd, (void*)&zName,0);
+  if( Th_Render(zScript)==TH_RETURN && zName ){
     cgi_redirect(mprintf("%s/tktview/%s", g.zBaseURL, zName));
     return;
   }
   @ </form>
@@ -529,9 +532,8 @@
 ** amiss, then return a pointer to a string (obtained from malloc) that
 ** describes the problem.
 */
 char *ticket_config_check(const char *zConfig){
-  struct Subscript *p;
   char *zErr = 0;
   const char *z;
   int n;
   int i;
@@ -542,27 +544,24 @@
      "tktview_template",
      "tktedit_template",
   };
 
-  p = SbS_Create();
-  rc = SbS_Eval(p, zConfig, strlen(zConfig));
-  if( rc!=SBS_OK ){
-    zErr = mprintf("%s", SbS_GetErrorMessage(p));
-    SbS_Destroy(p);
+  Th_FossilInit();
+  rc = Th_Eval(g.interp, 0, (const uchar*)zConfig, strlen(zConfig));
+  if( rc!=TH_OK ){
+    zErr = (char*)Th_TakeResult(g.interp, 0);
     return zErr;
   }
   for(i=0; i<sizeof(azRequired)/sizeof(azRequired[0]); i++){
-    z = SbS_Fetch(p, azRequired[i], -1, &n);
+    z = Th_Fetch(azRequired[i], &n);
     if( z==0 ){
       zErr = mprintf("missing definition: %s", azRequired[i]);
-      SbS_Destroy(p);
       return zErr;
     }
   }
-  z = SbS_Fetch(p, "ticket_sql", -1, &n);
+  z = Th_Fetch("ticket_sql", &n);
   if( z==0 ){
     zErr = mprintf("missing definition: ticket_sql");
-    SbS_Destroy(p);
     return zErr;
   }
   rc = sqlite3_open(":memory:", &db);
   if( rc==SQLITE_OK ){
@@ -569,13 +568,11 @@
     char *zSql = mprintf("%.*s", n, z);
     rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
     if( rc!=SQLITE_OK ){
       sqlite3_close(db);
-      SbS_Destroy(p);
       return zErr;
     }
     /* TODO: verify that the TICKET table exists and has required fields */
     sqlite3_close(db);
   }
-  SbS_Destroy(p);
   return 0;
 }