static MyConfigSection* config_create_section(MyConfig *self, const char *section_name) { MyConfigSection *section = self->get_section(self, section_name); if (section != NULL) { return NULL; } section = (MyConfigSection *)malloc(sizeof(MyConfigSection)); if (section == NULL) { fprintf(stderr, "failed to malloc section\n"); return NULL; } init_section(section); int len = strlen(section_name); section->name = (char *)malloc(len + 1); if (section->name == NULL) { fprintf(stderr, "failed to malloc section name\n"); free(section); return NULL; } strcpy(section->name, section_name); self->section_list->append(self->section_list, section); return section; }
static struct section* alloc_section(const char* name) { struct section* sec = 0; if (name) { sec = (struct section*)malloc(sizeof(struct section)); if (sec) { init_section(sec, name); } } return sec; }
int main(void) { init_config(); init_section(); if (!yyparse()) { return 1; } ini_entry_t *entry = list_entry(config._list.next, ini_entry_t, _list); printf("%s: %s=%s\n", entry->section, entry->key, entry->value); entry = list_entry(entry->_list.next, ini_entry_t, _list); printf("%s: %s=%s\n", entry->section, entry->key, entry->value); return 0; }
/* the program */ int main(int argc, char **argv, char **env) { int i, toAdd, parameterLen; proc_t isokernelP; environment = env; /* initialize IParagraph */ IParagraph = (struct LNLMINIT *) &ipData[8]; /* check the size of the application name */ if (strlen(argv[0]) >= 32768) programError("ERROR: Application name too long."); /* read application name into: dmsStockFilename */ /* translate the references to a real path */ realpath(argv[0], dmsStockFilename); /* - reads commandline parameters into: dmsParameters */ dmsParameters[0] = '\0'; parameterLen = 0; for (i = 1; i < argc; i++) { /* check if there are spaces in the current entry */ if (strchr(argv[i], ' ') == NULL) { /* just insert string */ toAdd = strlen(argv[i]); if ((parameterLen + toAdd + 1) >= 32768) programError ("ERROR: Too many commandline parameters."); strcpy(&dmsParameters[parameterLen], argv[i]); parameterLen += toAdd; strcpy(&dmsParameters[parameterLen], " "); parameterLen++; } else { /* surround string by quotes */ toAdd = strlen(argv[i]); if ((parameterLen + toAdd + 3) >= 32768) programError ("ERROR: Too many commandline parameters."); strcat(&dmsParameters[parameterLen], "\""); parameterLen++; strcat(&dmsParameters[parameterLen], argv[i]); parameterLen += toAdd; strcat(&dmsParameters[parameterLen], "\" "); parameterLen++; } } /* terminate the parameter string if necessary */ if (parameterLen > 0) dmsParameters[--parameterLen] = '\0'; /* allocate and initialize L.IN.OLEUM code area */ init_section(&pCode, IParagraph->app_code_size, "code"); /* allocate and initialize application workspace */ init_section(&pWorkspace, IParagraph->default_ramtop, "workspace"); current_ramtop = IParagraph->default_ramtop; /* open stockfile for reading */ openFile = fopen(dmsStockFilename, "r"); if (!openFile) programError("ERROR: Failed to open Stockfile"); /* read the initialised workspace */ read_section(&pWorkspace, IParagraph->physwsentry, IParagraph->app_ws_size, "workspace"); /* set pointer to uninitialized workspace */ pUIWorkspace = &pWorkspace[IParagraph->app_ws_size]; /* read the code section */ read_section(&pCode, (IParagraph->app_ws_size * sizeof(unit)) + IParagraph->physwsentry, IParagraph->app_code_size, "code"); /* set pointer to application start address */ pCodeEntry = (proc_t) (unit) & pCode[IParagraph->app_code_entry]; /* close file handle */ fclose(openFile); /* transfer commandline parameters */ btrsstring(&pUIWorkspace[mm_ProcessCommandLine], dmsParameters); /* initialize rest of workspace */ isokernelP = isokernel; pWorkspace[mm_ProcessOrigin] = (unit) pCode; pUIWorkspace[mm_ProcessISOcall] = ((unit) isokernelP - (unit) pCode); pUIWorkspace[mm_ProcessRAMtop] = IParagraph->default_ramtop; pUIWorkspace[mm_ProcessPriority] = IParagraph->app_code_pri; /* setup isokernel */ PRINT("initializing ISOKERNEL...\n"); assert(lino_display_init(IParagraph->lfb_x_atstartup, IParagraph->lfb_y_atstartup, IParagraph->lfb_w_atstartup, IParagraph->lfb_h_atstartup, NULL)); assert(initPointerCommand()); assert(initNetCommand()); PRINT1("%s: run main linoleum program.\n", __func__); linoleum(); if (xAtExit == FAIL) { int size = 256, n, result; char *arguments = malloc(size); while (1) { n = snprintf(arguments, size, "xmessage -center \"%s\n\nRegisters after execution.\nA: %d\nB: %d\nC: %d\nD: %d\nE: %d\nX: %d\n\"", dmsStockFilename, (int) aAtExit, (int) bAtExit, (int) cAtExit, (int) dAtExit, (int) eAtExit, (int) xAtExit); if (n > -1 && n < size) break; if (n > -1) size = n + 1; else size *= 2; arguments = realloc(arguments, size); } result = system(arguments); free(arguments); if (result != 0) { printf(dmsStockFilename); printf("Registers after execution.\n"); printf("A: %d\n", (int) aAtExit); printf("B: %d\n", (int) bAtExit); printf("C: %d\n", (int) cAtExit); printf("D: %d\n", (int) dAtExit); printf("E: %d\n", (int) eAtExit); printf("X: %d\n", (int) xAtExit); } } /* break down isokernel */ PRINT("Clear remaining isokernel stuff\n"); lino_display_close(); /* free allocated memory */ free(pCode); free(pWorkspace); /* terminate program */ return (0); }
static int fill_margin(gx_device * dev, const line_list * ll, margin_set *ms, int i0, int i1) { /* Returns the new index (positive) or return code (negative). */ section *sect = ms->sect; int iy = fixed2int_var_pixround(ms->y); int i, ir, h = -2, code; const fill_options * const fo = ll->fo; const bool FILL_DIRECT = fo->fill_direct; if (i0 < 0 || i1 > ll->bbox_width) return_error(gs_error_unregistered); /* Must not happen. */ ir = i0; for (i = i0; i < i1; i++) { int y0 = sect[i].y0, y1 = sect[i].y1, hh; if (y0 == -1) y0 = 0; if (y1 == -1) y1 = fixed_scale - 1; hh = compute_padding(§[i]); # if ADJUST_SERIF if (hh >= 0) { # if !CHECK_SPOT_CONTIGUITY if (i == i0 && i + 1 < i1) { int hhh = compute_padding(§[i + 1]); hh = hhh; } else if (i == i1 - 1 && i > i0) hh = h; /* We could optimize it with moving outside the cycle. * Delaying the optimization until the code is well tested. */ # else if (sect[i].x0 > 0 && sect[i].x1 == fixed_1 && i + 1 < i1) { # if INTERTRAP_STEM_BUG int hhh = hh; # endif hh = (i + 1 < i1 ? compute_padding(§[i + 1]) : -2); /* We could cache hh. * Delaying the optimization until the code is well tested. */ # if INTERTRAP_STEM_BUG /* A bug in the old code. */ if (i > i0 && i + 1 < i1 && hh == -2 && compute_padding(§[i - 1]) == -2) { /* It can be either a thin stem going from left to up or down (See 'r' in 01-001.ps in 'General', ppmraw, 72dpi), or a serif from the left. Since it is between 2 trapezoids, it is better to paint it against a dropout. */ hh = hhh; } # endif } else if (sect[i].x0 == 0 && sect[i].x1 < fixed_1) { # if INTERTRAP_STEM_BUG int hhh = hh; # endif hh = h; # if INTERTRAP_STEM_BUG /* A bug in the old code. */ if (i > i0 && i + 1 < i1 && hh == -2 && compute_padding(§[i - 1]) == -2) { /* It can be either a thin stem going from right to up or down (See 'r' in 01-001.ps in 'General', ppmraw, 72dpi), or a serif from the right. Since it is between 2 trapezoids, it is better to paint it. against a dropout. */ DO_NOTHING; } # endif } # endif } # endif if (h != hh) { if (h >= 0) { VD_RECT(ir + ll->bbox_left, iy + h, i - ir, 1, VD_MARG_COLOR); code = LOOP_FILL_RECTANGLE_DIRECT(fo, ir + ll->bbox_left, iy + h, i - ir, 1); if (code < 0) return code; } ir = i; h = hh; } } if (h >= 0) { VD_RECT(ir + ll->bbox_left, iy + h, i - ir, 1, VD_MARG_COLOR); code = LOOP_FILL_RECTANGLE_DIRECT(fo, ir + ll->bbox_left, iy + h, i - ir, 1); if (code < 0) return code; } init_section(sect, i0, i1); return 0; /* * We added the ADJUST_SERIF feature for small fonts, which are poorly hinted. * An example is 033-52-5873.pdf at 72 dpi. * We either suppress a serif or move it up or down for 1 pixel. * If we would paint it as an entire pixel where it occures, it looks too big * relatively to the character size. Besides, a stem end may * be placed a little bit below the baseline, and our dropout prevention * method desides to paint a pixel below baseline, so that it looks * fallen down (or fallen up in the case of character top). * * We assume that contacting margins are merged in margin_list. * This implies that areas outside a margin are not painted * (Only useful without CHECK_SPOT_CONTIGUITY). * * With no CHECK_SPOT_CONTIGUITY we can't perfectly handle the case when 2 serifs * contact each another inside a margin interior (such as Serif 'n'). * Since we don't know the contiguty, we misrecognize them as a stem and * leave them as they are (possibly still fallen down or up). * * CHECK_SPOT_CONTIGUITY computes the contiguity of the intersection of the spot * and the section window. It allows to recognize contacting serifs properly. * * If a serif isn't painted with regular trapezoids, * it appears a small one, so we don't need to measure its size. * This heuristic isn't perfect, but it is very fast. * Meanwhile with CHECK_SPOT_CONTIGUITY we actually have something * like a bbox for a small serif, and a rough estimation is possible. * * We believe that in normal cases this stuff should work idle, * because a perfect rendering should either use anti-aliasing * (so that the character isn't small in the subpixel grid), * and/or the path must be well fitted into the grid. So please consider * this code as an attempt to do our best for the case of a * non-well-setup rendering. */ }
void TaskStart (void *data) { extern u32 _end; u32 bss_end = (u32)(&_end); BOOL ret = FALSE; u32 *pstack_pnt = NULL; u32 heap_start = 0; // u32 montage_auto = 0; u32 cpuclk = 0; heap_start = ROUNDUP(bss_end,4); mtos_irq_init(); // hal_warriors_attach(&hal_config); extern void hal_concerto_attach(void); hal_concerto_attach( ); mtos_register_putchar(uart_write_byte); mtos_register_getchar(uart_read_byte_polling); //mtos_ticks_init(SYS_CPU_CLOCK); hal_module_clk_get(HAL_CPU0, &cpuclk); mtos_ticks_init(cpuclk); mem_mgr_partition_param_t partition_param = { 0 };//, partition2_param = { 0 }; uart_init(0); uart_init(1); //init memory manager, to the memory end mem_mgr_init((u8 *)heap_start, SYSTEM_MEMORY_END); //create system partition partition_param.id = MEM_SYS_PARTITION; partition_param.size = SYS_PARTITION_SIZE; partition_param.p_addr = (u8 *)heap_start; partition_param.atom_size = SYS_PARTITION_ATOM; partition_param.user_id = SYS_MODULE_SYSTEM; partition_param.method_id = MEM_METHOD_NORMAL; ret = MEM_CREATE_PARTITION(&partition_param); MT_ASSERT(FALSE != ret); #if 0 OS_PRINTF("\n 1. mem_start[0x%x]\n", heap_start); OS_PRINTF("\n 2. system memory size[%d]\n", SYSTEM_MEMORY_END); OS_PRINTF("SYS_PARTITION_SIZE is %x\n", SYS_PARTITION_SIZE); OS_PRINTF("create SYS_PARTITION111 ok!\n"); partition2_param.id = MEM_DMA_PARTITION; partition2_param.size = DMA_PARTITION_SIZE; partition2_param.p_addr = (u8 *)((heap_start + SYS_PARTITION_SIZE + 0x40000) | 0xa0000000); partition2_param.atom_size = DMA_PARTITION_ATOM; partition2_param.user_id = SYS_MODULE_SYSTEM; partition2_param.method_id = MEM_METHOD_NORMAL; OS_PRINTF("\n 1. mem_start[0x%x]\n", partition2_param.p_addr); OS_PRINTF("\n 2. system memory size[%d]\n", SYSTEM_MEMORY_END); OS_PRINTF("SYS_PARTITION_SIZE is 0x%x\n", DMA_PARTITION_SIZE); ret = MEM_CREATE_PARTITION(&partition2_param); MT_ASSERT(FALSE != ret); #endif mtos_mem_init(mt_mem_malloc, mt_mem_free); #if 0 OS_PRINTF("Now check os version!\n"); u32 os_version = get_os_version(); if (os_version != 0x11112222) { OS_PRINTF("Wrong os version, please talk with os person!\n"); } OS_PRINTF("Os version pass!\n"); if(CPU_IS_AP) { OS_PRINTF("AP CPU id get pass \n"); }else{ OS_PRINTF("cannot get right cpu id \n"); } #endif //create timer task pstack_pnt = (u32*)mtos_malloc(SYS_TIMER_TASK_STK_SIZE); MT_ASSERT(pstack_pnt != NULL); ret = mtos_task_create((u8 *)"Timer", Task_SysTimer, (void *)0, SYS_TIMER_TASK_PRIORITY, pstack_pnt, SYS_TIMER_TASK_STK_SIZE); MT_ASSERT(FALSE != ret); // init_dual_printk(); //init message queue //OS_PRINTF("start mtos_irq_enable!!!!!!!!!!!!!!\n"); mtos_irq_enable(TRUE); ret = mtos_message_init(); MT_ASSERT(FALSE != ret); #ifdef CORE_DUMP_DEBUG mtos_stat_init(); #endif init_section(); mtos_task_sleep(100); ap_init(); mtos_task_exit(); }