Fossil

Diff
Login

Diff

Differences From Artifact [ca63d56947]:

To Artifact [0c5ea8884c]:


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178



179
180
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196
197
198
199









200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230


231
232
233
234
235
236
237
164
165
166
167
168
169
170




171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194





195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


233
234
235
236
237
238
239
240
241







-
-
-
-




+
+
+









-
+
+






-
-
-
-
-
+
+
+
+
+
+
+
+
+










-
+


















-
-
+
+







                                "popupwidget", 0);
  }
  builtin_emit_fossil_js_apis("page.pikchrshow", 0);
  builtin_fulfill_js_requests();
  style_footer();
}

static void pikchr_th_init(u32 fThInit){
  Th_FossilInit(fThInit & TH_INIT_MASK);
}

/*
** COMMAND: pikchr
**
** Usage: %fossil pikchr [options] ?INFILE? ?OUTFILE?
**
** Accepts a pikchr script as input and outputs the rendered
** script as an SVG graphic.
**
** Options:
**
**    -div      On success, adds a DIV wrapper around the
**              resulting SVG output which limits its max-width.
**
**    -th       Process the input using TH1 before passing it to pikchr.
**
**    -th-novar Disable $var and $<var> TH1 processing. Only applies
**              with the -th flag.
**              with the -th flag. Use this if the pikchr script uses
**              '$' for its own purposes.
**
**    -th-nosvg When using -th, output the post-TH1'd script
**              instead of the pikchr-rendered output.
**
**    -th-trace Trace TH1 execution (for debugging purposes)
**
** TH1 Caveats: the built-in TH1 commands make some assumptions about
** HTML escaping and output which do not apply via this
** command. e.g. some commands will output directly to stdout, rather
** than the output buffer this command requires. Improvements in that
** regard are under consideration/construction.
** TH1 Caveats:
**
** If the -th flag is used, this command must open a fossil database
** for certain functionality to work. It will run TH1 without opening
** a db if one cannot be found in the current checkout or with the -R
** REPO flag, but any TH1 commands which require a db will then fail.
**
** Many of the fossil-installed TH1 functions do not make any sense
** for pikchr scripts
*/
void pikchr_cmd(void){
  Blob bIn = empty_blob;
  Blob bOut = empty_blob;
  const char * zInfile = "-";
  const char * zOutfile = "-";
  const int fWithDiv = find_option("div",0,0)!=0;
  const int fTh1 = find_option("th",0,0)!=0;
  const int fNosvg = find_option("th-nosvg",0,0)!=0;
  int isErr = 0;
  u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ENCODE
  u32 fThFlags = TH_INIT_NO_ENCODE
    | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0);

  Th_InitTraceLog()/*processes -th-trace flag*/;
  verify_all_options();
  if(g.argc>4){
    usage("?INFILE? ?OUTFILE?");
  }
  if(g.argc>2){
    zInfile = g.argv[2];
  }
  if(g.argc>3){
    zOutfile = g.argv[3];
  }
  blob_read_from_file(&bIn, zInfile, ExtFILE);
  if(fTh1){
    Blob out = empty_blob;
    db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0)
      /* ^^^ needed for certain TH1 functions to work */;
    pikchr_th_init(fThFlags);
    isErr = Th_RenderToBlob(blob_str(&bIn), &out, fThFlags) ? 1 : 0;
    isErr = Th_RenderToBlob(blob_str(&bIn), &out, fThFlags)
      ? 1 : 0;
    if(isErr){
      blob_reset(&bOut);
      bOut = out;
    }else{
      blob_reset(&bIn);
      bIn = out;
    }