コード例 #1
0
ファイル: lt_list.c プロジェクト: dcf21/pyxplot8
char *ListPrint(List *in, char *out, int size)
 {
  ListIterator *iter;
  int pos,first;
  iter = ListIterateInit(in);
  pos=0; first=1;
  strcpy(out+pos, "["); pos += strlen(out+pos);
  while (iter != NULL)
   {
    if (pos > (size-30)) { strcpy(out+pos, ", ... ]"); return out; }// Truncate string as we're getting close to the end of the buffer
    if (first!=1) strcpy(out+(pos++), ",");
    if      (iter->DataType == DATATYPE_VOID  ) { strcpy (out+pos, "void"                         ); }
    else if (iter->DataType == DATATYPE_INT   ) { sprintf(out+pos, "%d"  , *((int    *)iter->data)); }
    else if (iter->DataType == DATATYPE_FLOAT ) { sprintf(out+pos, "%e"  , *((double *)iter->data)); }
    else if (iter->DataType == DATATYPE_VALUE ) { sprintf(out+pos, "%e+%ei <unit>", ((value *)iter->data)->real, ((value *)iter->data)->imag); }
    else if (iter->DataType == DATATYPE_STRING) { sprintf(out+pos, "'%s'",  ((char   *)iter->data)); }
    else if (iter->DataType == DATATYPE_LIST  ) { ListPrint( ((List *)iter->data), out+pos, size-pos); }
    else if (iter->DataType == DATATYPE_DICT  ) { DictPrint( ((Dict *)iter->data), out+pos, size-pos); }
    pos += strlen(out+pos);
    first=0;
    iter = ListIterate(iter, NULL);
   }
  strcpy(out+pos, "]"); pos += strlen(out+pos);
  return out;
 }
コード例 #2
0
ファイル: cpost.c プロジェクト: pmuellr/cpost
/*------------------------------------------------------------------
 * get maximum number of calls and called bys for all the functions
 * so figure out which table to use
 *------------------------------------------------------------------*/
int GetMaxFuncTableEntries(
   Info      *info
   )
   {

   info->count1 = 0;

   ListIterate(info->funcTree,
               (ListIterateFunc *)CountFunctionRefs,
               info);

   return info->count1;
   }
コード例 #3
0
ファイル: cpost.c プロジェクト: pmuellr/cpost
/*------------------------------------------------------------------
 * atexit processing
 *------------------------------------------------------------------*/
static void RunAtExit(void)
   {

   if (!AllDone)
      fprintf(stderr,"%s : Program terminated.\n",PROGRAM_NAME);

   /*---------------------------------------------------------------
    * erase any temporary files we might have open
    *---------------------------------------------------------------*/
   if (!AllDone)
      fprintf(stderr,"%s : Cleaning up temporary files.\n",PROGRAM_NAME);

   ListIterate(info.fileList,(ListIterateFunc *)CleanUpFileList,&info);

   /*---------------------------------------------------------------
    * destroy file list
    *---------------------------------------------------------------*/
   ListDestroy(info.fileList);

   /*---------------------------------------------------------------
    * destroy hash tables
    *---------------------------------------------------------------*/
   HashDestroy(info.identHash);
   HashDestroy(info.reservedHash);

   /*---------------------------------------------------------------
    * destroy function list
    *---------------------------------------------------------------*/
   ListIterate(info.funcTree,(ListIterateFunc *)CleanUpFuncList,&info);
   ListDestroy(info.funcTree);

   /*---------------------------------------------------------------
    * dump memory (if debug enabled
    *---------------------------------------------------------------*/
#if defined(__DEBUG_ALLOC__)
   _dump_allocated(0);
#endif
   }
コード例 #4
0
ファイル: hash.c プロジェクト: pmuellr/cpost
/*------------------------------------------------------------------
 * iterate through hash table
 *------------------------------------------------------------------*/
void HashIterate(
   Hash            *hash,
   ListIterateFunc *pIterateFunc,
   void            *pUserData
   )
   {
   int i;

   if (!hash)
      return;

   for (i=0; i<hash->buckets; i++)
      ListIterate(hash->bucket[i],pIterateFunc,pUserData);
   }
コード例 #5
0
ファイル: cpost.c プロジェクト: pmuellr/cpost
/*------------------------------------------------------------------
 * main program
 *------------------------------------------------------------------*/
int main(
   int   argc,
   char *argv[]
   )
   {
   int        i;
   char       dateStr[30];
   struct tm *tm;
   time_t     t;
   char      *origParms;

   /*---------------------------------------------------------------
    * check for help
    *---------------------------------------------------------------*/
   if ((1 == argc) || ('?' == *(argv[1])))
      Usage();

   /*---------------------------------------------------------------
    * get original parms
    *---------------------------------------------------------------*/
   origParms  = malloc(1);
   *origParms = 0;

   for (i=0; i<argc; i++)
      {
      origParms = realloc(origParms,2 + strlen(origParms) + strlen(argv[i]));
      strcat(origParms," ");
      strcat(origParms,argv[i]);
      }

   /*---------------------------------------------------------------
    * zero out info
    *---------------------------------------------------------------*/
   memset(&info,0,sizeof(info));

   /*---------------------------------------------------------------
    * get options
    *---------------------------------------------------------------*/
   GetOptions(&argc,argv,&info);

   /*---------------------------------------------------------------
    * buffer output
    *---------------------------------------------------------------*/
/* setvbuf(info.oFile,NULL,_IOFBF,32000); */

   /*---------------------------------------------------------------
    * put filenames in a list
    *---------------------------------------------------------------*/
   info.fileList = ListCreate(sizeof(File),
                              (ListCompareFunc *)FileNameCompare,
                              cPostNoMem);
   if (!info.fileList)
      cPostError(1,"error creating list of files");

   for (i=1; i<argc; i++)
      FileSpecAdd(&info,info.fileList,argv[i]);

   /*---------------------------------------------------------------
    * check for no files to process
    *---------------------------------------------------------------*/
   if (!ListCount(info.fileList))
      cPostError(1,"no files to process");

   /*---------------------------------------------------------------
    * intialize rest of info structure
    *---------------------------------------------------------------*/
   info.funcTree  = ListCreate(sizeof(Function),
                               (ListCompareFunc *)FunctionNameCompare,
                               cPostNoMem);
   if (!info.fileList)
      cPostError(1,"error creating list of functions");

   info.identHash   = HashCreate(sizeof(char *),
                                 1000,
                                 (HashFunc *)IdentHash,
                                 (ListCompareFunc *)IdentCompare,
                                 cPostNoMem);


   if (!info.identHash)
      cPostError(1,"error creating global hash table");

   /*---------------------------------------------------------------
    * setup error termination processing
    *---------------------------------------------------------------*/
   atexit(RunAtExit);
   signal(SIGINT,  SignalHandler);
   signal(SIGTERM, SignalHandler);

#if defined(OPSYS_OS2) || defined(OPSYS_OS2V2)
   signal(SIGBREAK,SignalHandler);
#endif

   /*---------------------------------------------------------------
    * print header
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"%%! PostScript file generated by %s %s\n\n",
           PROGRAM_NAME,PROGRAM_VERS);

/*------------------------------------------------------------------
 * a macro to write a line to the output file
 *------------------------------------------------------------------*/
#define p(x) fprintf(info.oFile,"%s\n",x);


   /*---------------------------------------------------------------
    * write command line and environment variable setting
    *---------------------------------------------------------------*/
#if defined(ECHO_COMMAND_LINE)
      {
      p("%%-----------------------------------------------------------------")

      fprintf(info.oFile,"%%%% this file created with the command:\n");
      fprintf(info.oFile,"%%%%   %s\n",origParms);
      fprintf(info.oFile,"%%%% the CPOST environment variable ");
      if (!getenv(PROGRAM_ENVV))
         fprintf(info.oFile,"is not set.\n");
      else
         {
         fprintf(info.oFile,"is set to:\n");
         fprintf(info.oFile,"%%%%   %s\n",getenv(PROGRAM_ENVV));
         }

      p("%%-----------------------------------------------------------------")
      p("");
      }
#endif

   /*---------------------------------------------------------------
    * write wrapper prefix
    *---------------------------------------------------------------*/
   if (info.oWrapB && strlen(info.oWrapB))
      processImbedFile(info.oWrapB);

   /*---------------------------------------------------------------
    * get the time
    *---------------------------------------------------------------*/
   t  = time(NULL);
   tm = localtime(&t);
   strftime(dateStr,sizeof(dateStr)-1,"%m/%d/%y   %H:%M:%S",tm);

   p("%%-----------------------------------------------------------------")
   p("%% runtime options and values")
   p("%%-----------------------------------------------------------------")
   p("")
   fprintf(info.oFile,"/printDate (%s) def\n",dateStr);
   fprintf(info.oFile,"/oSpace %d def\n",info.oSpace);
   fprintf(info.oFile,"/oXlate { %d %d translate } def\n",info.oXlateX,info.oXlateY);
   fprintf(info.oFile,"/oDuplex 1 %d eq def\n",info.oDuplex);
   fprintf(info.oFile,"/oNumber 0 %d ne def\n",info.oSpace);
   p("")

   /*---------------------------------------------------------------
    * write replaced header ...
    *---------------------------------------------------------------*/
   if (info.oRepHdr && strlen(info.oRepHdr))
      {
      processImbedFile(info.oImbed);
      p("");
      processImbedFile(info.oRepHdr);
      p("");
      }

   /*---------------------------------------------------------------
    * or default stuff
    *---------------------------------------------------------------*/
   else
      {
      for (i=0; i< sizeof(Header_1)/sizeof(char *); i++)
         p(Header_1[i]);

      p("");
      processImbedFile(info.oImbed);
      p("");

      for (i=0; i< sizeof(Header_2)/sizeof(char *); i++)
         p(Header_2[i]);

      p("");
      }

   /*---------------------------------------------------------------
    * read the files. make copies
    *---------------------------------------------------------------*/
   fprintf(stderr,"Pass 1\n");
   ListIterate(info.fileList,(ListIterateFunc *)Pass1,&info);

   /*---------------------------------------------------------------
    * read the copies. write the output file
    *---------------------------------------------------------------*/
   fprintf(stderr,"Pass 2\n");
   ListIterate(info.fileList,(ListIterateFunc *)Pass2,&info);

   /*---------------------------------------------------------------*
    * print trailing line feed
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"\n");

   /*---------------------------------------------------------------
    * write wrapper suffix
    *---------------------------------------------------------------*/
   if (info.oWrapA && strlen(info.oWrapA))
      processImbedFile(info.oWrapA);

   /*---------------------------------------------------------------
    * close file (another line feed for luck!)
    *---------------------------------------------------------------*/
   fprintf(info.oFile,"\n");
   fclose(info.oFile);

   AllDone = 1;
   return 0;
   }