Exemplo n.º 1
0
static bool
loadLCDFile (FILE *f, cstring name)
{
  char buf[BUFLEN];
  
  /*
  ** Check version.  Should be >= SPLINT_LIBVERSION
  */

  if (reader_readLine (f, buf, BUFLEN) == NULL
      || !mstring_equalPrefix (buf, LIBRARY_MARKER))
    {
      loadllmsg (message ("Load library %s is not in Splint library format.  Attempting "
			  "to continue without library.", name));
      return FALSE;
    }
  
  if (reader_readLine (f, buf, BUFLEN) != NULL)
    {
      if (!mstring_equalPrefix (buf, ";;"))
	{
	  loadllmsg (message ("Load library %s is not in Splint library format.  Attempting "
			      "to continue without library.", name));
	  return FALSE;
	}
      else if (mstring_equalPrefix (buf, ";;ctTable"))
	{
	  loadllmsg (message ("Load library %s is in obsolete Splint library format.  Attempting "
			      "to continue anyway, but results may be incorrect.  Rebuild "
			      "the library with this version of splint.", 
			      name));
	}
      else 
	{
	  float version = 0.0;

	  if (sscanf (buf, ";;Splint %f", &version) != 1
	      && (sscanf (buf, ";;LCLint %f", &version) != 1))
	    {
	      loadllmsg (message ("Load library %s is not in Splint library format (missing version "
				  "number).  Attempting "
				  "to continue without library.", name));
	      return FALSE;
	    }
	  else
	    {
	      if ((SPLINT_LIBVERSION - version) >= FLT_EPSILON)
		{
		  cstring vname;
		  char *nl = strchr (buf, '\n');

		  *nl = '\0';

		  vname = cstring_fromChars (buf + 9);

		  loadllmsg (message ("Load library %s is in obsolete Splint library "
				      "format (version %f (%s), expecting version %f).  Attempting "
				      "to continue anyway, but results may be incorrect.  Rebuild "
				      "the library with this version of splint.", 
				      name, 
				      version,
				      vname, 
				      SPLINT_LIBVERSION));
		}
	      else
		{
		  if (reader_readLine (f, buf, BUFLEN) == NULL)
		    {
		      loadllmsg (message ("Load library %s is not in Splint library "
					  "format (missing library code). Attempting "
					  "to continue without library.", name));
		      return FALSE;
		    }
		  else 
		    {
		      int lib;
		      
		      if (sscanf (buf, ";;lib:%d", &lib) != 1)
			{
			  loadllmsg (message ("Load library %s is not in Splint library "
					      "format (missing library code). Attempting "
					      "to continue without library.", name));
			  return FALSE;
			}
		      else
			{
			  flagcode code = (flagcode) lib;

			  if (flagcode_isLibraryFlag (code))
			    {
			      if (context_doMerge ()) 
				{
				  context_setLibrary (code);
				}
			    }
			  else
			    {
			      loadllmsg (message ("Load library %s has invalid library code (%s).  "
						  "Attempting to continue without library.",
						  name,
						  flagcode_unparse (code)));
			      
			      return FALSE;
			    }
			}
		    }
		}
	    }
	}
    }
  else
    {
      loadllmsg (message ("Load library %s is not in Splint library format (missing lines).  "
			  "Attempting to continue without library.", name));
      return FALSE;
    }
  
  ctype_loadTable (f);
  printDot ();
  
  typeIdSet_loadTable (f);
  printDot ();
  
  usymtab_load (f);
  printDot ();
  
  context_loadModuleAccess (f);
  printDot ();
  
  return TRUE;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {

    bool ugly = false, setnumbers = false, all = false;
    int div = 3;
    int c;

    while ((c = getopt(argc, argv, "hud:na")) != -1) {
        switch (c) {
            case 'h':
                printf("%s [file]\n", argv[0]);
                printf("\tAccepts a file to read, otherwise stdin\n");
                printf("\t-u: ugly output\n");
                printf("\t-n: output set numbers\n");
                printf("\t-a: also print input sets\n");
                printf("\t-d [n]: division of sets (2, 4, 8...)\n");
                return 0;
                break;
            case 'u':
                ugly = true;
                break;
            case 'd':
                div = atoi(optarg)+1;
                if (fmod(log2(div-1), 1) != 0) {
                    fprintf(stderr, "Invalid breakdown, pls stop.\n");
                    return 1;
                }
                break;
            case 'n':
                setnumbers = true;
                break;
            case 'a':
                all = true;
                break;
        }

    }

    FILE *in = fopen(argv[optind], "r");
    if (in == NULL) {
        in = stdin;
    }

    Dot **dots = calloc(div, sizeof(Dot**));
    dots[div-1] = malloc(sizeof(Dot));
    parse(in, dots[div-1]);
    int set = 0;

    while (1) {

        //get rid of the first and move the next in its place
        free(dots[0]);
        dots[0] = dots[div-1];
        //print out the first dot
        if (all) {
            if (setnumbers) {
                printf("Set %d:\t\t", set);
            }
            if (ugly) {
                uglyPrintDot(dots[0]);
            }
            else {
                printDot(dots[0]);
            }
        }
        dots[div-1] = malloc(sizeof(Dot)); //make space for new one
        if (parse(in, dots[div-1])) { //read it in, if none exit loop
            break;
        }
        double distance = calc(dots, div); //calculate them all

        //print
        for (int i = 1; i < div-1; i++) {
            if (setnumbers) {
                printf("Set %d & %d/%d:\t", set, i, div-1);
            }
            if (ugly) {
                printf("%.2f\n", distance);
            }
            else {
                printf("%.2f\n", distance);
            }
            free(dots[i]);
        }

        set++; //count the sets, duh
    }

    free(dots[0]);
    free(dots[div-1]);
    free(dots);
    fclose(in);
    return 0;
}
Exemplo n.º 3
0
void
dumpState (cstring cfname)
{
  FILE *f;
  cstring fname = fileLib_addExtension (cfname, cstring_makeLiteralTemp (DUMP_SUFFIX));
  
  f = fileTable_openWriteFile (context_fileTable (), fname);

  displayScanOpen (message ("Dumping to %s ", fname)); 
  
  if (f == NULL)
    {
      lldiagmsg (message ("Cannot open dump file for writing: %s", fname));
    }
  else
    {
      /*
      ** sequence is convulted --- must call usymtab_prepareDump before
      **    dumping ctype table to convert type uid's
      */

      printDot ();

      /*
      DPRINTF (("Before prepare dump:"));
      ctype_printTable ();
      DPRINTF (("Preparing dump..."));
      */

      usymtab_prepareDump ();

      /*
      ** Be careful, these lines must match loadLCDFile checking.
      */

      fprintf (f, "%s %s\n", LIBRARY_MARKER, cstring_toCharsSafe (fname));
      fprintf (f, ";;Splint %f\n", SPLINT_LIBVERSION);
      fprintf (f, ";;lib:%d\n", (int) context_getLibrary ());
      fprintf (f, ";;ctTable\n");
      
      DPRINTF (("Dumping types..."));
      printDot ();
      ctype_dumpTable (f);
      printDot ();
      
      DPRINTF (("Dumping type sets..."));
      fprintf (f, ";;tistable\n");
      typeIdSet_dumpTable (f);
      printDot ();
      
      DPRINTF (("Dumping usymtab..."));
      fprintf (f, ";;symTable\n");
      usymtab_dump (f);
      printDot ();

      DPRINTF (("Dumping modules..."));
      fprintf (f, ";; Modules access\n");
      context_dumpModuleAccess (f);
      fprintf (f, ";;End\n");
      check (fileTable_closeFile (context_fileTable (), f));
    }

  displayScanClose ();
  cstring_free (fname);
}