void GSimpleRaportManager::Destroy() { if (raport_file) { fflush(raport_file); fclose(raport_file); raport_file=NULL; if (modified==false) { unlink(file_name); } else { switch(raport_mode) { case RAP_15MIN: case RAP_5MIN: { char buf[256]; strcpy(buf, file_name); char * ptr=strstr(buf,".log"); if(ptr!=NULL) { STRUPR(ptr); rename(file_name, buf); } } break; } } } }
void acpi_db_prep_namestring ( NATIVE_CHAR *name) { if (!name) { return; } STRUPR (name); /* Convert a leading forward slash to a backslash */ if (*name == '/') { *name = '\\'; } /* Ignore a leading backslash, this is the root prefix */ if (*name == '\\') { name++; } /* Convert all slash path separators to dots */ while (*name) { if ((*name == '/') || (*name == '\\')) { *name = '.'; } name++; } }
ACPI_STATUS AcpiDbDisplayStatistics ( NATIVE_CHAR *TypeArg) { UINT32 i; UINT32 Type; UINT32 Size; if (!AcpiGbl_DSDT) { AcpiOsPrintf ("*** Warning: There is no DSDT loaded\n"); } if (!TypeArg) { AcpiOsPrintf ("The following subcommands are available:\n ALLOCATIONS, OBJECTS, MEMORY, MISC, SIZES, TABLES\n"); return (AE_OK); } STRUPR (TypeArg); Type = AcpiDbMatchArgument (TypeArg, AcpiDbStatTypes); if (Type == (UINT32) -1) { AcpiOsPrintf ("Invalid or unsupported argument\n"); return (AE_OK); } switch (Type) { #ifndef PARSER_ONLY case CMD_ALLOCATIONS: #ifdef ACPI_DBG_TRACK_ALLOCATIONS AcpiUtDumpAllocationInfo (); #endif break; #endif case CMD_TABLES: AcpiOsPrintf ("ACPI Table Information:\n\n"); if (AcpiGbl_DSDT) { AcpiOsPrintf ("DSDT Length:................% 7ld (%X)\n", AcpiGbl_DSDT->Length, AcpiGbl_DSDT->Length); } break; case CMD_OBJECTS: #ifndef PARSER_ONLY AcpiDbCountNamespaceObjects (); AcpiOsPrintf ("\nObjects defined in the current namespace:\n\n"); AcpiOsPrintf ("%16.16s % 10.10s % 10.10s\n", "ACPI_TYPE", "NODES", "OBJECTS"); for (i = 0; i < INTERNAL_TYPE_NODE_MAX; i++) { AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", AcpiUtGetTypeName (i), AcpiGbl_NodeTypeCount [i], AcpiGbl_ObjTypeCount [i]); } AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "Misc/Unknown", AcpiGbl_NodeTypeCountMisc, AcpiGbl_ObjTypeCountMisc); AcpiOsPrintf ("%16.16s % 10ld% 10ld\n", "TOTALS:", AcpiGbl_NumNodes, AcpiGbl_NumObjects); #endif break; case CMD_MEMORY: #ifdef ACPI_DBG_TRACK_ALLOCATIONS AcpiOsPrintf ("\n----Object and Cache Statistics---------------------------------------------\n"); for (i = 0; i < ACPI_NUM_MEM_LISTS; i++) { AcpiOsPrintf ("\n%s\n", AcpiGbl_MemoryLists[i].ListName); if (AcpiGbl_MemoryLists[i].MaxCacheDepth > 0) { AcpiOsPrintf (" Cache: [Depth Max Avail Size] % 7d % 7d % 7d % 7d B\n", AcpiGbl_MemoryLists[i].CacheDepth, AcpiGbl_MemoryLists[i].MaxCacheDepth, AcpiGbl_MemoryLists[i].MaxCacheDepth - AcpiGbl_MemoryLists[i].CacheDepth, (AcpiGbl_MemoryLists[i].CacheDepth * AcpiGbl_MemoryLists[i].ObjectSize)); AcpiOsPrintf (" Cache: [Requests Hits Misses ObjSize] % 7d % 7d % 7d % 7d B\n", AcpiGbl_MemoryLists[i].CacheRequests, AcpiGbl_MemoryLists[i].CacheHits, AcpiGbl_MemoryLists[i].CacheRequests - AcpiGbl_MemoryLists[i].CacheHits, AcpiGbl_MemoryLists[i].ObjectSize); } Outstanding = AcpiGbl_MemoryLists[i].TotalAllocated - AcpiGbl_MemoryLists[i].TotalFreed - AcpiGbl_MemoryLists[i].CacheDepth; if (AcpiGbl_MemoryLists[i].ObjectSize) { Size = ROUND_UP_TO_1K (Outstanding * AcpiGbl_MemoryLists[i].ObjectSize); } else { Size = ROUND_UP_TO_1K (AcpiGbl_MemoryLists[i].CurrentTotalSize); } AcpiOsPrintf (" Mem: [Alloc Free Outstanding Size] % 7d % 7d % 7d % 7d Kb\n", AcpiGbl_MemoryLists[i].TotalAllocated, AcpiGbl_MemoryLists[i].TotalFreed, Outstanding, Size); } #endif break; case CMD_MISC: AcpiOsPrintf ("\nMiscellaneous Statistics:\n\n"); AcpiOsPrintf ("Calls to AcpiPsFind:.. ........% 7ld\n", AcpiGbl_PsFindCount); AcpiOsPrintf ("Calls to AcpiNsLookup:..........% 7ld\n", AcpiGbl_NsLookupCount); AcpiOsPrintf ("\n"); AcpiOsPrintf ("Mutex usage:\n\n"); for (i = 0; i < NUM_MTX; i++) { AcpiOsPrintf ("%-28s: % 7ld\n", AcpiUtGetMutexName (i), AcpiGbl_AcpiMutexInfo[i].UseCount); } break; case CMD_SIZES: AcpiOsPrintf ("\nInternal object sizes:\n\n"); AcpiOsPrintf ("Common %3d\n", sizeof (ACPI_OBJECT_COMMON)); AcpiOsPrintf ("Number %3d\n", sizeof (ACPI_OBJECT_INTEGER)); AcpiOsPrintf ("String %3d\n", sizeof (ACPI_OBJECT_STRING)); AcpiOsPrintf ("Buffer %3d\n", sizeof (ACPI_OBJECT_BUFFER)); AcpiOsPrintf ("Package %3d\n", sizeof (ACPI_OBJECT_PACKAGE)); AcpiOsPrintf ("BufferField %3d\n", sizeof (ACPI_OBJECT_BUFFER_FIELD)); AcpiOsPrintf ("Device %3d\n", sizeof (ACPI_OBJECT_DEVICE)); AcpiOsPrintf ("Event %3d\n", sizeof (ACPI_OBJECT_EVENT)); AcpiOsPrintf ("Method %3d\n", sizeof (ACPI_OBJECT_METHOD)); AcpiOsPrintf ("Mutex %3d\n", sizeof (ACPI_OBJECT_MUTEX)); AcpiOsPrintf ("Region %3d\n", sizeof (ACPI_OBJECT_REGION)); AcpiOsPrintf ("PowerResource %3d\n", sizeof (ACPI_OBJECT_POWER_RESOURCE)); AcpiOsPrintf ("Processor %3d\n", sizeof (ACPI_OBJECT_PROCESSOR)); AcpiOsPrintf ("ThermalZone %3d\n", sizeof (ACPI_OBJECT_THERMAL_ZONE)); AcpiOsPrintf ("RegionField %3d\n", sizeof (ACPI_OBJECT_REGION_FIELD)); AcpiOsPrintf ("BankField %3d\n", sizeof (ACPI_OBJECT_BANK_FIELD)); AcpiOsPrintf ("IndexField %3d\n", sizeof (ACPI_OBJECT_INDEX_FIELD)); AcpiOsPrintf ("Reference %3d\n", sizeof (ACPI_OBJECT_REFERENCE)); AcpiOsPrintf ("NotifyHandler %3d\n", sizeof (ACPI_OBJECT_NOTIFY_HANDLER)); AcpiOsPrintf ("AddrHandler %3d\n", sizeof (ACPI_OBJECT_ADDR_HANDLER)); AcpiOsPrintf ("Extra %3d\n", sizeof (ACPI_OBJECT_EXTRA)); AcpiOsPrintf ("\n"); AcpiOsPrintf ("ParseObject %3d\n", sizeof (ACPI_PARSE_OBJECT)); AcpiOsPrintf ("Parse2Object %3d\n", sizeof (ACPI_PARSE2_OBJECT)); AcpiOsPrintf ("OperandObject %3d\n", sizeof (ACPI_OPERAND_OBJECT)); AcpiOsPrintf ("NamespaceNode %3d\n", sizeof (ACPI_NAMESPACE_NODE)); break; case CMD_STACK: Size = AcpiGbl_EntryStackPointer - AcpiGbl_LowestStackPointer; AcpiOsPrintf ("\nSubsystem Stack Usage:\n\n"); AcpiOsPrintf ("Entry Stack Pointer %X\n", AcpiGbl_EntryStackPointer); AcpiOsPrintf ("Lowest Stack Pointer %X\n", AcpiGbl_LowestStackPointer); AcpiOsPrintf ("Stack Use %X (%d)\n", Size, Size); AcpiOsPrintf ("Deepest Procedure Nesting %d\n", AcpiGbl_DeepestNesting); break; } AcpiOsPrintf ("\n"); return (AE_OK); }
void acpi_db_set_method_data ( NATIVE_CHAR *type_arg, NATIVE_CHAR *index_arg, NATIVE_CHAR *value_arg) { NATIVE_CHAR type; u32 index; u32 value; acpi_walk_state *walk_state; acpi_operand_object *obj_desc; /* Validate Type_arg */ STRUPR (type_arg); type = type_arg[0]; if ((type != 'L') && (type != 'A')) { acpi_os_printf ("Invalid SET operand: %s\n", type_arg); return; } /* Get the index and value */ index = STRTOUL (index_arg, NULL, 16); value = STRTOUL (value_arg, NULL, 16); walk_state = acpi_ds_get_current_walk_state (acpi_gbl_current_walk_list); if (!walk_state) { acpi_os_printf ("There is no method currently executing\n"); return; } /* Create and initialize the new object */ obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER); if (!obj_desc) { acpi_os_printf ("Could not create an internal object\n"); return; } obj_desc->integer.value = value; /* Store the new object into the target */ switch (type) { case 'A': /* Set a method argument */ if (index > MTH_NUM_ARGS) { acpi_os_printf ("Arg%d - Invalid argument name\n", index); return; } acpi_ds_store_object_to_local (AML_ARG_OP, index, obj_desc, walk_state); obj_desc = walk_state->arguments[index].object; acpi_os_printf ("Arg%d: ", index); acpi_db_display_internal_object (obj_desc, walk_state); break; case 'L': /* Set a method local */ if (index > MTH_NUM_LOCALS) { acpi_os_printf ("Local%d - Invalid local variable name\n", index); return; } acpi_ds_store_object_to_local (AML_LOCAL_OP, index, obj_desc, walk_state); obj_desc = walk_state->local_variables[index].object; acpi_os_printf ("Local%d: ", index); acpi_db_display_internal_object (obj_desc, walk_state); break; default: break; } }
acpi_status acpi_db_display_statistics ( NATIVE_CHAR *type_arg) { u32 i; u32 type; u32 outstanding; u32 size; if (!acpi_gbl_DSDT) { acpi_os_printf ("*** Warning: There is no DSDT loaded\n"); } if (!type_arg) { acpi_os_printf ("The following subcommands are available:\n ALLOCATIONS, OBJECTS, MEMORY, MISC, SIZES, TABLES\n"); return (AE_OK); } STRUPR (type_arg); type = acpi_db_match_argument (type_arg, acpi_db_stat_types); if (type == (u32) -1) { acpi_os_printf ("Invalid or unsupported argument\n"); return (AE_OK); } switch (type) { #ifndef PARSER_ONLY case CMD_ALLOCATIONS: #ifdef ACPI_DBG_TRACK_ALLOCATIONS acpi_ut_dump_allocation_info (); #endif break; #endif case CMD_TABLES: acpi_os_printf ("ACPI Table Information:\n\n"); if (acpi_gbl_DSDT) { acpi_os_printf ("DSDT Length:................% 7ld (%X)\n", acpi_gbl_DSDT->length, acpi_gbl_DSDT->length); } break; case CMD_OBJECTS: #ifndef PARSER_ONLY acpi_db_count_namespace_objects (); acpi_os_printf ("\n_objects defined in the current namespace:\n\n"); acpi_os_printf ("%16.16s % 10.10s % 10.10s\n", "ACPI_TYPE", "NODES", "OBJECTS"); for (i = 0; i < INTERNAL_TYPE_NODE_MAX; i++) { acpi_os_printf ("%16.16s % 10ld% 10ld\n", acpi_ut_get_type_name (i), acpi_gbl_node_type_count [i], acpi_gbl_obj_type_count [i]); } acpi_os_printf ("%16.16s % 10ld% 10ld\n", "Misc/Unknown", acpi_gbl_node_type_count_misc, acpi_gbl_obj_type_count_misc); acpi_os_printf ("%16.16s % 10ld% 10ld\n", "TOTALS:", acpi_gbl_num_nodes, acpi_gbl_num_objects); #endif break; case CMD_MEMORY: #ifdef ACPI_DBG_TRACK_ALLOCATIONS acpi_os_printf ("\n----Object and Cache Statistics---------------------------------------------\n"); for (i = 0; i < ACPI_NUM_MEM_LISTS; i++) { acpi_os_printf ("\n%s\n", acpi_gbl_memory_lists[i].list_name); if (acpi_gbl_memory_lists[i].max_cache_depth > 0) { acpi_os_printf (" Cache: [Depth Max Avail Size] % 7d % 7d % 7d % 7d B\n", acpi_gbl_memory_lists[i].cache_depth, acpi_gbl_memory_lists[i].max_cache_depth, acpi_gbl_memory_lists[i].max_cache_depth - acpi_gbl_memory_lists[i].cache_depth, (acpi_gbl_memory_lists[i].cache_depth * acpi_gbl_memory_lists[i].object_size)); acpi_os_printf (" Cache: [Requests Hits Misses Obj_size] % 7d % 7d % 7d % 7d B\n", acpi_gbl_memory_lists[i].cache_requests, acpi_gbl_memory_lists[i].cache_hits, acpi_gbl_memory_lists[i].cache_requests - acpi_gbl_memory_lists[i].cache_hits, acpi_gbl_memory_lists[i].object_size); } outstanding = acpi_gbl_memory_lists[i].total_allocated - acpi_gbl_memory_lists[i].total_freed - acpi_gbl_memory_lists[i].cache_depth; if (acpi_gbl_memory_lists[i].object_size) { size = ROUND_UP_TO_1K (outstanding * acpi_gbl_memory_lists[i].object_size); } else { size = ROUND_UP_TO_1K (acpi_gbl_memory_lists[i].current_total_size); } acpi_os_printf (" Mem: [Alloc Free Outstanding Size] % 7d % 7d % 7d % 7d Kb\n", acpi_gbl_memory_lists[i].total_allocated, acpi_gbl_memory_lists[i].total_freed, outstanding, size); } #endif break; case CMD_MISC: acpi_os_printf ("\n_miscellaneous Statistics:\n\n"); acpi_os_printf ("Calls to Acpi_ps_find:.. ........% 7ld\n", acpi_gbl_ps_find_count); acpi_os_printf ("Calls to Acpi_ns_lookup:..........% 7ld\n", acpi_gbl_ns_lookup_count); acpi_os_printf ("\n"); acpi_os_printf ("Mutex usage:\n\n"); for (i = 0; i < NUM_MTX; i++) { acpi_os_printf ("%-28s: % 7ld\n", acpi_ut_get_mutex_name (i), acpi_gbl_acpi_mutex_info[i].use_count); } break; case CMD_SIZES: acpi_os_printf ("\n_internal object sizes:\n\n"); acpi_os_printf ("Common %3d\n", sizeof (ACPI_OBJECT_COMMON)); acpi_os_printf ("Number %3d\n", sizeof (ACPI_OBJECT_INTEGER)); acpi_os_printf ("String %3d\n", sizeof (ACPI_OBJECT_STRING)); acpi_os_printf ("Buffer %3d\n", sizeof (ACPI_OBJECT_BUFFER)); acpi_os_printf ("Package %3d\n", sizeof (ACPI_OBJECT_PACKAGE)); acpi_os_printf ("Buffer_field %3d\n", sizeof (ACPI_OBJECT_BUFFER_FIELD)); acpi_os_printf ("Device %3d\n", sizeof (ACPI_OBJECT_DEVICE)); acpi_os_printf ("Event %3d\n", sizeof (ACPI_OBJECT_EVENT)); acpi_os_printf ("Method %3d\n", sizeof (ACPI_OBJECT_METHOD)); acpi_os_printf ("Mutex %3d\n", sizeof (ACPI_OBJECT_MUTEX)); acpi_os_printf ("Region %3d\n", sizeof (ACPI_OBJECT_REGION)); acpi_os_printf ("Power_resource %3d\n", sizeof (ACPI_OBJECT_POWER_RESOURCE)); acpi_os_printf ("Processor %3d\n", sizeof (ACPI_OBJECT_PROCESSOR)); acpi_os_printf ("Thermal_zone %3d\n", sizeof (ACPI_OBJECT_THERMAL_ZONE)); acpi_os_printf ("Region_field %3d\n", sizeof (ACPI_OBJECT_REGION_FIELD)); acpi_os_printf ("Bank_field %3d\n", sizeof (ACPI_OBJECT_BANK_FIELD)); acpi_os_printf ("Index_field %3d\n", sizeof (ACPI_OBJECT_INDEX_FIELD)); acpi_os_printf ("Reference %3d\n", sizeof (ACPI_OBJECT_REFERENCE)); acpi_os_printf ("Notify_handler %3d\n", sizeof (ACPI_OBJECT_NOTIFY_HANDLER)); acpi_os_printf ("Addr_handler %3d\n", sizeof (ACPI_OBJECT_ADDR_HANDLER)); acpi_os_printf ("Extra %3d\n", sizeof (ACPI_OBJECT_EXTRA)); acpi_os_printf ("\n"); acpi_os_printf ("Parse_object %3d\n", sizeof (acpi_parse_object)); acpi_os_printf ("Parse2_object %3d\n", sizeof (acpi_parse2_object)); acpi_os_printf ("Operand_object %3d\n", sizeof (acpi_operand_object)); acpi_os_printf ("Namespace_node %3d\n", sizeof (acpi_namespace_node)); break; case CMD_STACK: size = acpi_gbl_entry_stack_pointer - acpi_gbl_lowest_stack_pointer; acpi_os_printf ("\n_subsystem Stack Usage:\n\n"); acpi_os_printf ("Entry Stack Pointer %X\n", acpi_gbl_entry_stack_pointer); acpi_os_printf ("Lowest Stack Pointer %X\n", acpi_gbl_lowest_stack_pointer); acpi_os_printf ("Stack Use %X (%d)\n", size, size); acpi_os_printf ("Deepest Procedure Nesting %d\n", acpi_gbl_deepest_nesting); break; } acpi_os_printf ("\n"); return (AE_OK); }
/* * DoCalc */ void DoCalc(char *a, char *b) { if (strstr(b, "+rw1")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw1", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw1", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rw2")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw2", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw2", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rw")) { for (int i=0; i<6; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rw", rw[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rw", rwnum[i]); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb1")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb1", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb1", i); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb2")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb2", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb2", i); DoCalc(tmp_a, tmp_b); } } else if (strstr(b, "+rb")) { for (int i=0; i<4; i++) { char tmp_a[BUFSIZE]; strcpy(tmp_a, a); strreplace(tmp_a, "rb", rb[i]); char tmp_b[BUFSIZE]; strcpy(tmp_b, b); strreplacenum(tmp_b, "rb", i); DoCalc(tmp_a, tmp_b); } } else { //fprintf(stderr, "1 %s %s\n", a, b); strshift(b); //fprintf(stderr, "2 %s %s\n", a, b); stradd(b); //fprintf(stderr, "3 %s %s\n", a, b); STRUPR(a); strtrimtrailing(a); strtrimtrailing(b); int numargs = 0; if (strreplace(a, "*", "~0")) numargs++; if (strreplace(a, "*", "~1")) numargs++; if (strreplace(a, "*", "~2")) numargs++; // ..... //strreplace(b, ":", ""); instruction.fmt = a; //instruction.opcode = strtoul(b,0,16); //instruction.fixed |= strtoul(b,0,16) << ((instruction.flags & FLAG_EXTENDED) ? 1 : 0); unsigned int instruction_fixed = instruction.fixed | (strtoul(b,0,16) << ((instruction.flags & FLAG_EXTENDED) ? 8 : 0)); // no continue flag if (!(instruction.flags & FLAG_EXTENDED)) switch (instruction.fixed & 0xFF) { case 0xF1: case 0xF3: case 0xF4: case 0xF8: case 0xF9: break; default: instruction.flags |= FLAG_CONT; } char s[BUFSIZE], *p = s; // NOTE: leading text is added later // see mindx_type.h for structure fields p += sprintf(p, "%s\"", instruction.fmt); //for (int i=0; i<30-(p-s); i++) { p += sprintf(p, " "); } p += sprintf(p, ",0x%02X,0x%02X,%d,%d", instruction.flags, instruction_fixed, instruction.size, instruction.argnum); for (unsigned int i=0; i<instruction.argnum; i++) { p += sprintf(p, ",%d,%d", instruction.argInfo[i].shift, instruction.argInfo[i].flags); } p += sprintf(p, "\t; %d\n", line); /* p += sprintf(p, "%s\",0x%02X,0x%02X,0x%02X,%d,%d,%d,{", instruction.fmt, instruction.flags, instruction.extended, instruction.opcode, instruction.size, instruction.argnum, instruction.argbytes); for (int i=0; i<MAX_ARGS; i++) { p += sprintf(p, "0x%03X,", instruction.argflags[i]); } //%d,%d", flags, numargs, p += sprintf(p, "}},//%d\n", line); */ output[outputs++] = strdup(s); // this is going to be sorted alphabetically } }
MYBOOL __WINAPI read_params(lprec *lp, char *filename, char *options) { int ret, looping, line; FILE *fp; hashtable *hashfunctions, *hashparameters; hashelem *hp; int i, j, elements, n, intvalue, state = 0; REAL REALvalue; char buf[4096], *header = NULL, *ptr, *ptr1, *ptr2; if((fp = ini_open(filename)) == NULL) ret = FALSE; else { /* create hashtable of all callable commands to find them quickly */ hashfunctions = create_hash_table(sizeof(functions) / sizeof(*functions), 0); for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) { puthash(functions[i].par, i, NULL, hashfunctions); if(functions[i].values != NULL) n += functions[i].elements; } /* create hashtable of all arguments to find them quickly */ hashparameters = create_hash_table(n, 0); for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) { if(functions[i].values != NULL) { elements = functions[i].elements; for(j = 0; j < elements; j++) if((strcmp(functions[i].values[j].svalue, "0") != 0) && (strcmp(functions[i].values[j].svalue, "1") != 0)) puthash(functions[i].values[j].svalue, j, NULL, hashparameters); } } readoptions(options, &header); STRUPR(header); ret = looping = TRUE; line = 0; while((ret) && (looping)) { line++; switch(ini_readdata(fp, buf, sizeof(buf), FALSE)) { case 0: /* End of file */ looping = FALSE; break; case 1: /* header */ switch(state) { case 0: STRUPR(buf); if(strcmp(buf, header) == 0) state = 1; break; case 1: looping = FALSE; break; } break; case 2: /* data */ if(state == 1) { for(ptr = buf; (*ptr) && (isspace(*ptr)); ptr++); } else ptr = NULL; if((ptr != NULL) && (*ptr)) { STRUPR(buf); ptr = strchr(buf, '='); if(ptr == NULL) { report(lp, IMPORTANT, "read_params: No equal sign on line %d\n", line); ret = FALSE; } else { *ptr = 0; for(ptr1 = buf; isspace(*ptr1); ptr1++); for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--); if(ptr2 <= ptr1) { report(lp, IMPORTANT, "read_params: No parameter name before equal sign on line %d\n", line); ret = FALSE; } else { ptr2[1] = 0; hp = findhash(ptr1, hashfunctions); if(hp == NULL) { report(lp, IMPORTANT, "read_params: Unknown parameter name (%s) before equal sign on line %d\n", ptr1, line); ret = FALSE; } else { i = hp->index; ptr1 = ++ptr; intvalue = 0; REALvalue = 0; if(functions[i].values == NULL) { switch(functions[i].type) { case intfunction: case longfunction: case MYBOOLfunction: intvalue = strtol(ptr1, &ptr2, 10); while((*ptr2) && (isspace(*ptr2))) ptr2++; if(*ptr2) { report(lp, IMPORTANT, "read_params: Invalid integer value on line %d\n", line); ret = FALSE; } break; case REALfunction: REALvalue = strtod(ptr1, &ptr2); while((*ptr2) && (isspace(*ptr2))) ptr2++; if(*ptr2) { report(lp, IMPORTANT, "read_params: Invalid real value on line %d\n", line); ret = FALSE; } break; } } else { while(ret) { ptr = strchr(ptr1, '+'); if(ptr == NULL) ptr = ptr1 + strlen(ptr1); for(; isspace(*ptr1); ptr1++); for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--); if(ptr2 <= ptr1) break; else { ptr2[1] = 0; hp = findhash(ptr1, hashparameters); if (hp == NULL) { report(lp, IMPORTANT, "read_params: Invalid parameter name (%s) on line %d\n", ptr1, line); ret = FALSE; } else { j = hp->index; if((j >= functions[i].elements) || (strcmp(functions[i].values[j].svalue, ptr1))) { report(lp, IMPORTANT, "read_params: Inappropriate parameter name (%s) on line %d\n", ptr1, line); ret = FALSE; } else { intvalue += functions[i].values[j].value; } } ptr1 = ptr + 1; } } } if(ret) { switch(functions[i].type) { case intfunction: functions[i].set_function.int_set_function(lp, intvalue); break; case longfunction: functions[i].set_function.long_set_function(lp, intvalue); break; case MYBOOLfunction: functions[i].set_function.MYBOOL_set_function(lp, (MYBOOL) intvalue); break; case REALfunction: functions[i].set_function.REAL_set_function(lp, REALvalue); break; } } } } } } break; } } FREE(header); free_hash_table(hashfunctions); free_hash_table(hashparameters); ini_close(fp); } return( (MYBOOL) ret ); }
MYBOOL __WINAPI write_params(lprec *lp, char *filename, char *options) { int k, ret, params_written; FILE *fp, *fp0; int state = 0, looping, newline; char buf[4096], *filename0, *ptr1, *ptr2, *header = NULL; readoptions(options, &header); k = strlen(filename); filename0 = (char *) malloc(k + 1 + 1); strcpy(filename0, filename); ptr1 = strrchr(filename0, '.'); ptr2 = strrchr(filename0, '\\'); if((ptr1 == NULL) || ((ptr2 != NULL) && (ptr1 < ptr2))) ptr1 = filename0 + k; memmove(ptr1 + 1, ptr1, k + 1 - (int) (ptr1 - filename0)); ptr1[0] = '_'; if(rename(filename, filename0)) { switch(errno) { case ENOENT: /* File or path specified by oldname not found */ FREE(filename0); filename0 = NULL; break; case EACCES: /* File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path. */ FREE(filename0); FREE(header); return(FALSE); break; } } if((fp = ini_create(filename)) == NULL) ret = FALSE; else { params_written = FALSE; newline = TRUE; if(filename0 != NULL) { fp0 = ini_open(filename0); if(fp0 == NULL) { rename(filename0, filename); FREE(filename0); FREE(header); return(FALSE); } looping = TRUE; while(looping) { switch(ini_readdata(fp0, buf, sizeof(buf), TRUE)) { case 0: /* End of file */ looping = FALSE; break; case 1: /* header */ ptr1 = strdup(buf); STRUPR(buf); ptr2 = strdup(header); STRUPR(ptr2); if(strcmp(buf, ptr2) == 0) { write_params1(lp, fp, ptr1, newline); params_written = TRUE; newline = TRUE; state = 1; } else { state = 0; ini_writeheader(fp, ptr1, newline); newline = TRUE; } FREE(ptr2); FREE(ptr1); break; case 2: /* data */ if(state == 0) { ini_writedata(fp, NULL, buf); newline = (*buf != 0); } break; } } ini_close(fp0); } if(!params_written) write_params1(lp, fp, header, newline); ini_close(fp); ret = TRUE; } if(filename0 != NULL) { remove(filename0); FREE(filename0); } FREE(header); return( (MYBOOL) ret ); }
void GSimpleRaportManager::UpdateName(GClock & ) { struct tm *today; time_t ltime; time( <ime ); today = gmtime( <ime ); strftime(date, 128, "%H:%M:%S", today); if (raport_mode == RAP_15MIN) today->tm_min -= (today->tm_min % 15); if (raport_mode == RAP_5MIN) today->tm_min -= (today->tm_min % 5); bool create_new_rap=false; switch(raport_mode) { case RAP_DAY: if (yesterday.tm_mday!=today->tm_mday) create_new_rap=true; break; case RAP_HOUR: if (yesterday.tm_hour!=today->tm_hour) create_new_rap=true; break; case RAP_15MIN: case RAP_5MIN: if (yesterday.tm_min!=today->tm_min) create_new_rap=true; break; } memcpy(&yesterday,today,sizeof(tm)); if (create_new_rap || (raport_file==NULL && wait_for_data==false && create_new_rap==false)) { char time[256]; if(raport_mode==RAP_DAY) strftime(time,256,"[%Y_%m_%d].log",today); else if(raport_mode==RAP_HOUR) strftime(time,256,"[%Y_%m_%d %H_00].log",today); else strftime(time,256,"[%Y_%m_%d %H_%M].log",today); if (raport_file) { fflush(raport_file); fclose(raport_file); raport_file=NULL; if (modified==false) { unlink(file_name); } else { char buf[256]; strcpy(buf, file_name); char * ptr=strstr(buf,".log"); if(ptr!=NULL) { STRUPR(ptr); rename(file_name, buf); } } modified=false; } char buf[512]; sprintf(buf,"%s%s%s",raport_path.c_str(),base_name.c_str(),time); strncpy(file_name,buf,256); wait_for_data=true; } }