Fossil

Diff
Login

Diff

Differences From Artifact [782f046f14]:

To Artifact [3354bae872]:


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
242
243
244
245
246
247
248
249
250
251

252
253


254
255
256
257
258
259
260
261
  }
  builtin_emit_fossil_js_apis("page.pikchrshow", 0);
  builtin_fulfill_js_requests();
  style_footer();
}

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

/*
** COMMAND: pikchr
**
** Usage: %fossil pikchr [options] ?INFILE? ?OUTFILE?
**
** 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.



**
**    -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.
*/
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 fNoVar = find_option("th-novar",0,0)!=0;
  int isErr = 0;
  u32 fThInit = TH_INIT_DEFAULT;


  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;
    Blob * oldOut;
    db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0)
      /* ^^^ needed for certain functions to work */;
    oldOut = Th_SetOutputBlob(&out);
    pikchr_th_init(fThInit);
    isErr = Th_RenderToBlob(blob_str(&bIn), &out,


                            fNoVar ? TH_R2B_NO_VARS : 0);

    blob_reset(&bIn);
    bIn = out;
    Th_SetOutputBlob(oldOut);
    /*fossil_print("th'd:\n%b\n", &bIn);*/
  }

  if(!isErr){




    int w = 0, h = 0;
    const char * zContent = blob_str(&bIn);


    char *zOut = pikchr(zContent, "pikchr", 0, &w, &h);
    if( w>0 && h>0 ){
      if(fWithDiv){
        blob_appendf(&bOut,"<div style='max-width:%dpx;'>\n", w);
      }
      blob_append(&bOut, zOut, -1);
      if(fWithDiv){
        blob_append(&bOut,"</div>\n", 7);
      }
    }else{
      isErr = 1;
      blob_append(&bOut, zOut, -1);
    }
    fossil_free(zOut);

  }
  if(isErr){


    fossil_fatal("ERROR: %b", &bOut);
  }else{
    blob_write_to_file(&bOut, zOutfile);
  }
  Th_PrintTraceLog();
  blob_reset(&bIn);
  blob_reset(&bOut);
}







|
















>
>
>
















|

|
>















<

|
<
|
|
>
>
|
>
|
|
<
<
|
>

>
>
>
>
|
|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>


>
>
|







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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
  }
  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?
**
** 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.
**
**    -th-nopic 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.
*/
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 fNoPic = find_option("th-nopic",0,0)!=0;
  int isErr = 0;
  u32 fThFlags = TH_INIT_DEFAULT | TH_INIT_NO_ESC
    | (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;
    if(isErr){
      blob_reset(&bOut);
      bOut = out;
    }else{
      blob_reset(&bIn);
      bIn = out;


    }
  }
  if(!isErr){
    if(fTh1 && fNoPic){
      bOut = bIn;
      bIn = empty_blob;
    }else{
      int w = 0, h = 0;
      const char * zContent = blob_str(&bIn);
      char *zOut;

      zOut = pikchr(zContent, "pikchr", 0, &w, &h);
      if( w>0 && h>0 ){
        if(fWithDiv){
          blob_appendf(&bOut,"<div style='max-width:%dpx;'>\n", w);
        }
        blob_append(&bOut, zOut, -1);
        if(fWithDiv){
          blob_append(&bOut,"</div>\n", 7);
        }
      }else{
        isErr = 2;
        blob_append(&bOut, zOut, -1);
      }
      fossil_free(zOut);
    }
  }
  if(isErr){
    /*fossil_print("ERROR: raw input:\n%b\n", &bIn);*/
    fossil_fatal("%s ERROR: %b", 1==isErr ? "TH1" : "pikchr",
                 &bOut);
  }else{
    blob_write_to_file(&bOut, zOutfile);
  }
  Th_PrintTraceLog();
  blob_reset(&bIn);
  blob_reset(&bOut);
}