Home | History | Annotate | Download | only in kati
      1 // Copyright 2016 Google Inc. All rights reserved
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //      http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 // +build ignore
     16 
     17 // This command will dump the contents of a kati stamp file into a more portable
     18 // format for use by other tools. For now, it just exports the files read.
     19 // Later, this will be expanded to include the Glob and Shell commands, but
     20 // those require a more complicated output format.
     21 
     22 #include <stdio.h>
     23 
     24 #include <string>
     25 
     26 #include "io.h"
     27 #include "log.h"
     28 #include "strutil.h"
     29 
     30 int main(int argc, char* argv[]) {
     31   if (argc == 1) {
     32     fprintf(stderr, "Usage: ckati_stamp_dump <stamp>\n");
     33     return 1;
     34   }
     35 
     36   FILE *fp = fopen(argv[1], "rb");
     37   if(!fp)
     38     PERROR("fopen");
     39 
     40   ScopedFile sfp(fp);
     41   double gen_time;
     42   size_t r = fread(&gen_time, sizeof(gen_time), 1, fp);
     43   if (r != 1)
     44     ERROR("Incomplete stamp file");
     45 
     46   int num_files = LoadInt(fp);
     47   if (num_files < 0)
     48     ERROR("Incomplete stamp file");
     49   for (int i = 0; i < num_files; i++) {
     50     string s;
     51     if (!LoadString(fp, &s))
     52       ERROR("Incomplete stamp file");
     53     printf("%s\n", s.c_str());
     54   }
     55 
     56   return 0;
     57 }
     58