Exemplo n.º 1
0
Arquivo: log.c Projeto: KasperD/mx3bot
int log_init(int n, int g)
{
   int i;

   /* dummy init */
   if(n == -1)
   {
      dummy_mode = -1;
      return 0;
   }

   dummy_mode = 0;

   if(n < 1)
      n_logfiles = 32;
   else
      n_logfiles = n;

   if(g < 1)
      n_grow = 8;
   else
      n_grow = g;

   log = malloc(n_logfiles * sizeof(struct logfile_t));
   if(log == NULL)
      return -1;

   for(i = 0; i < n_logfiles; i++)
      clearlog(i);

   logpath[0] = 0;

   return 0;
}
Exemplo n.º 2
0
void CDirectLink::Cascade(CPObject *pPC)
{
    connectorsMutex.lock();
    clearlog();
    Output(pPC);
    connectorsMutex.unlock();
}
Exemplo n.º 3
0
//FlashCS5extension.StartMakeObjectFile(생성할 오브젝트 파일패스, UV 파일패스들)
JSBool StartMakeObjectFile(JSContext *cx, JSObject *obj, unsigned int argc, jsval *argv, jsval *rval) {
    
    clearlog();
    
    *rval = JS_BooleanToValue(JS_FALSE);
    
    if(argc != 3)
        return ReturnString(cx, "error: argument count", rval);
	
	unsigned int filePathLen;
	unsigned short* filePath = JS_ValueToString(cx, argv[0], &filePathLen);
	
	if(filePath == NULL)
        return ReturnString(cx, "error: obj file path", rval);
	
	JSObject* uvObj;
	if(JS_ValueToObject(cx, argv[1], &uvObj) == JS_FALSE)
        return ReturnString(cx, "error: uv file array", rval);
	
	long uvLen = JS_GetArrayLength(cx, uvObj);
	if(uvLen == -1)
        return ReturnString(cx, "error: image file array length", rval);
    
    JSObject* slicePathObj;
    if(JS_ValueToObject(cx, argv[2], &slicePathObj) == JS_FALSE)
        return ReturnString(cx, "error: slicePaht file array", rval);
	
	unsigned int uvPathLen[uvLen];
	unsigned short* uvPath[uvLen];
    
    char* slicePath = GetString(cx, slicePathObj, 0);
	
	int i;
	for(i = 0; i < uvLen; i++) {
		jsval posUV;
		if(JS_GetElement(cx, uvObj, i, &posUV) == JS_FALSE)
			return ReturnString(cx, "error: uv file array element", rval);
		
		uvPath[i] = JS_ValueToString(cx, posUV, &uvPathLen[i]);
		if(uvPath[i] == NULL)
			return ReturnString(cx, "error: uv file array element file path string", rval);
		
		FILE* uvDataFile = OpenFileString(uvPath[i], uvPathLen[i], "r");
        fread(&root_w, sizeof(long), 1, uvDataFile);
        fread(&root_h, sizeof(long), 1, uvDataFile);
		if(uvDataFile) {
			fseek(uvDataFile, 0, SEEK_END);
			long uvDataSize = ftell(uvDataFile);
			fseek(uvDataFile, sizeof(long) + sizeof(long), SEEK_SET);
			int result = sizeof(long) + sizeof(long);
			while(result < uvDataSize)
				result += ReadUVdata(uvDataFile, slicePath);
			fclose(uvDataFile);
		} else {
			return ReturnString(cx, "error: uv data fopen", rval);
		}
	}
    
    free(slicePath);
	
#define BreakStartMakeObjectFile(errorstr) \
fclose(pObjectFile); \
pObjectFile = NULL; \
return ReturnString(cx, errorstr, rval)
    
    if(pObjectFile) {
        fclose(pObjectFile);
        pObjectFile = NULL;
    }
	
	if(pObjectFile == NULL) {
		char* path = StringToAscii(filePath, filePathLen);
		pObjectFile = fopen(path, "w+");
		free(path);
		if(pObjectFile) {
			//fwrite(&imgLen, sizeof(long), 1, pObjectFile);FlashCS5extension.bundle
			for(i = 0; i < uvLen; i++) {
//				FILE* imgFile;
//				path = StringToAscii(imgPath[i], imgPathLen[i]);
//				if(path == NULL) {
//					BreakStartMakeObjectFile("error: image file path");
//				}
//				imgFile = fopen(path, "r");
//				free(path);
//				if(imgFile) {
//					WriteFileToFile(pObjectFile, imgFile);
//                    writelog("success write image");
//					fclose(imgFile);
//				} else {
//					BreakStartMakeObjectFile("error: image file fopen");
//				}
				
				int i;
				fwrite(&uv_data_len, sizeof(unsigned int), 1, pObjectFile);
                writelog("uv data length = %d", uv_data_len);
				for(i = 0; i < uv_data_len; i++) {
					fwrite(&uv_data[i].libID, sizeof(unsigned int), 1, pObjectFile);
                    writelog("libid = %d", uv_data[i].libID);
                    fwrite(&uv_data[i].pathCount, sizeof(int), 1, pObjectFile);
                    writelog("path count = %d", uv_data[i].pathCount);
                    for(int j = 0; j < uv_data[i].pathCount; ++j) {
                        float uv_x = (float)uv_data[i].x[j];
                        float uv_y = (float)uv_data[i].y[j];
                        fwrite(&uv_x, sizeof(float), 1, pObjectFile);
                        fwrite(&uv_y, sizeof(float), 1, pObjectFile);
                        writelog("x = %.3f, y = %.3f", uv_data[i].x[j], uv_data[i].y[j]);
                    }
				}
			}
		} else {
			//return JS_FALSE;
            return ReturnString(cx, "error : fail to make obj file", rval);
		}
	} else {
		//return JS_FALSE;
        return ReturnString(cx, "error : pObjectFile in use", rval);
	}
	
#undef BreakStartMakeObjectFile
	
	*rval = JS_BooleanToValue(JS_TRUE);
	for(int i = 0; i < root_library_name_id_len; i++) {
		writelog("??????????????????????????libname info length = %i data = %s??????????????????????????", strlen(root_library_name_id[i].name), root_library_name_id[i].name);
	}
	
	return JS_TRUE;
}
Exemplo n.º 4
0
Arquivo: log.c Projeto: KasperD/mx3bot
int log_set(int cid, char *chan, char *filename, int type)
{
   int i;
   char pathname[512];

   if(dummy_mode)
   {
      if(type != 0)
         dummy_mode = type;

      return 0;
   }

   /* unset log if filename is null */
   if(filename == NULL)
   {
      if((cid == -1) && (chan == NULL))
         closelog(0);

      i = findlog(cid, chan);
      if(i == -1)
         return -1;

      closelog(i);
      return 0;
   }

   /* adjust filename if logpath is set */
   if(logpath[0] != 0)
      snprintf(pathname, 256, "%s/%s", logpath, filename);

   /* global logfile is always index zero */
   if((cid == -1) && (chan == NULL))
      return openlog(0, -1, NULL, pathname, type);

   /* find empty slot */
   for(i = 1; i < n_logfiles; i++)
   {
      if((log[i].cid == -1) &&
         (log[i].chan[0] == 0))
      {
         return openlog(i, cid, chan, pathname, type);
      }
   }

   /* grow table */
   log = realloc(log, (n_logfiles + n_grow) * sizeof(struct logfile_t));
   if(log == NULL)
   {
      if(n_logfiles > 0)
         log_error("log_set: Out of memory");
      return -2;
   }

   i = n_logfiles;
   n_logfiles += n_grow;

   for(; i < n_logfiles; i++)
      clearlog(i);

   return 0;
}