Exemple #1
0
static int
compare_lists (char **ret, char **expected,
               int (*compare) (const char *, const char *))
{
  size_t i;

  for (i = 0; ret[i] != NULL; ++i) {
    if (!expected[i]) {
      fprintf (stderr, "test failed: returned list is too long\n");
      goto fail;
    }
    if (compare (ret[i], expected[i]) != 0) {
      fprintf (stderr, "test failed: elements differ at position %zu\n", i);
      goto fail;
    }
  }
  if (expected[i]) {
    fprintf (stderr, "test failed: returned list is too short\n");
    goto fail;
  }

  return 1; /* test expecting true for OK */

 fail:
  fprintf (stderr, "returned list was:\n");
  print_strings (ret);
  fprintf (stderr, "expected list was:\n");
  print_strings (expected);
  return 0; /* test expecting false for failure */
}
static bool test_set_get_includes(struct smbconf_ctx *ctx)
{
	sbcErr err;
	uint32_t count;
	bool ret = false;
	const char *set_includes[] = {
		"/path/to/include1",
		"/path/to/include2"
	};
	uint32_t set_num_includes = 2;
	char **get_includes = NULL;
	uint32_t get_num_includes = 0;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("TEST: set_get_includes\n");

	err = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
	if (!SBC_ERROR_IS_OK(err)) {
		printf("FAIL: get_set_includes (setting includes) - %s\n",
		       sbcErrorString(err));
		goto done;
	}

	err = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
					  &get_includes);
	if (!SBC_ERROR_IS_OK(err)) {
		printf("FAIL: get_set_includes (getting includes) - %s\n",
		       sbcErrorString(err));
		goto done;
	}

	if (get_num_includes != set_num_includes) {
		printf("FAIL: get_set_includes - set %d includes, got %d\n",
		       set_num_includes, get_num_includes);
		goto done;
	}

	for (count = 0; count < get_num_includes; count++) {
		if (!strequal(set_includes[count], get_includes[count])) {
			printf("expected: \n");
			print_strings("* ", set_num_includes,
				      (const char * const *)set_includes);
			printf("got: \n");
			print_strings("* ", get_num_includes,
				      (const char * const *)get_includes);
			printf("FAIL: get_set_includes - data mismatch:\n");
			goto done;
		}
	}

	printf("OK: set_includes\n");
	ret = true;

done:
	talloc_free(mem_ctx);
	return ret;
}
static bool test_set_get_includes(struct smbconf_ctx *ctx)
{
	WERROR werr;
	uint32_t count;
	bool ret = false;
	const char *set_includes[] = {
		"/path/to/include1",
		"/path/to/include2"
	};
	uint32_t set_num_includes = 2;
	char **get_includes = NULL;
	uint32_t get_num_includes = 0;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("test: set_get_includes\n");

	werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
	if (!W_ERROR_IS_OK(werr)) {
		printf("failure: get_set_includes (setting includes) - %s\n",
		       dos_errstr(werr));
		goto done;
	}

	werr = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
					   &get_includes);
	if (!W_ERROR_IS_OK(werr)) {
		printf("failure: get_set_includes (getting includes) - %s\n",
		       dos_errstr(werr));
		goto done;
	}

	if (get_num_includes != set_num_includes) {
		printf("failure: get_set_includes - set %d includes, got %d\n",
		       set_num_includes, get_num_includes);
		goto done;
	}

	for (count = 0; count < get_num_includes; count++) {
		if (!strequal(set_includes[count], get_includes[count])) {
			printf("expected: \n");
			print_strings("* ", set_num_includes, set_includes);
			printf("got: \n");
			print_strings("* ", get_num_includes,
				      (const char **)get_includes);
			printf("failure: get_set_includes - data mismatch:\n");
			goto done;
		}
	}

	printf("success: set_includes\n");
	ret = true;

done:
	TALLOC_FREE(mem_ctx);
	return ret;
}
Exemple #4
0
static bool test_get_includes(struct smbconf_ctx *ctx)
{
	sbcErr err;
	bool ret = false;
	uint32_t num_includes = 0;
	char **includes = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("TEST: get_includes\n");
	err = smbconf_get_global_includes(ctx, mem_ctx,
					  &num_includes, &includes);
	if (!SBC_ERROR_IS_OK(err)) {
		printf("FAIL: get_includes - %s\n", sbcErrorString(err));
		goto done;
	}

	printf("got %u includes%s\n", num_includes,
	       (num_includes > 0) ? ":" : ".");
	print_strings("", num_includes, (const char **)includes);

	printf("OK: get_includes\n");
	ret = true;

done:
	talloc_free(mem_ctx);
	return ret;
}
static bool test_get_includes(struct smbconf_ctx *ctx)
{
	WERROR werr;
	bool ret = false;
	uint32_t num_includes = 0;
	char **includes = NULL;
	TALLOC_CTX *mem_ctx = talloc_stackframe();

	printf("test: get_includes\n");
	werr = smbconf_get_global_includes(ctx, mem_ctx,
					   &num_includes, &includes);
	if (!W_ERROR_IS_OK(werr)) {
		printf("failure: get_includes - %s\n", dos_errstr(werr));
		goto done;
	}

	printf("got %u includes%s\n", num_includes,
	       (num_includes > 0) ? ":" : ".");
	print_strings("", num_includes, (const char **)includes);

	printf("success: get_includes\n");
	ret = true;

done:
	TALLOC_FREE(mem_ctx);
	return ret;
}
Exemple #6
0
int main(void)
{
    char *message[8] = { "Four", "score", "and", "seven",
                     "years", "ago,", "our", "forefathers" };

    print_strings(message, 8);
	printf ("\n");
    return 0;
}
Exemple #7
0
static void normalize(int n) {
	const int p = page;

	if (n < 0 ) n = 0;
	if (n >= rl.cur_entries ) n = rl.cur_entries - 1;
	x = N2X(n);
	y = N2Y(n);
	page = N2P(n);
	if ( p != page ) print_strings();
}
Exemple #8
0
int main() {
    print_strings("print_strings", "a", "b", "c", NULL);
    print_strings("print_strings", "a", "b", "c", (void *)NULL);

    /* WARN: missing sentinel. */
    /*print_strings("a", "b", "c");*/

    /* Nope, 0 does not work, need the pointer. */
    /*print_strings("a", "b", "c", 0);*/

    /*
    execl is a prototypical example of null termination of vararg..

    It is impemented as a GCC 5.2 built-in.
    */
    {
        /*execl("/usr/bin/env", "echo", "a", "b");*/
    }

    return EXIT_SUCCESS;
}
int main(){
	
	int number_of_lines;
	number_of_lines = get_lines(lines);

	if(number_of_lines < 0)
	{
		puts("Erreur d'Allocation mémoire");
	exit(EXIT_FAILURE);
	}

	sort(lines, number_of_lines);
	print_strings(lines, number_of_lines);
	return 0;
}
Exemple #10
0
void
print_rc_style (GtkRcStyle *rc, GtkStyle *style)
{
    if (print_rc_colors ("fg", rc->fg, 5, rc->color_flags, GTK_RC_FG))
    	print_colors ("fg", style->fg, 5);
    if (print_rc_colors ("bg", rc->bg, 5, rc->color_flags, GTK_RC_BG))
    	print_colors ("bg", style->bg, 5);
    if (print_rc_colors ("text", rc->text, 5, rc->color_flags, GTK_RC_TEXT))
    	print_colors ("text", style->text, 5);
    if (print_rc_colors ("base", rc->base, 5, rc->color_flags, GTK_RC_BASE))
    	print_colors ("base", style->base, 5);
    print_colors ("light", style->light, 5);
    print_colors ("dark", style->dark, 5);
    print_colors ("mid", style->mid, 5);
    print_strings ("bg-pixmap", rc->bg_pixmap_name, 5);
}
Exemple #11
0
int main(void)
{
    int ret;

    LIBXML_TEST_VERSION
    fill_strings();
#ifdef WITH_PRINT
    print_strings();
#endif
    ret = run_test1();
    if (ret == 0) {
        printf("dictionary tests succeeded %d strings\n", 2 * NB_STRINGS_MAX);
    } else {
        printf("dictionary tests failed with %d errors\n", nbErrors);
    }
    clean_strings();
    xmlCleanupParser();
    xmlMemoryDump();
    return(ret);
}
Exemple #12
0
void Testbench::test(){

	int x, y , ci;

	cout<<"Time\tx\ty\tci\tz\tco"<<endl;
	cout<<"--------------------------------------------"<<endl;	
	srand(time(NULL));	
	for(int i =0; i<10; i++){

		x = rand()%4;
		y = rand()%4;
		ci= rand()%2;
		
	x_out.write(x);
	y_out.write(y);
	ci_out.write(ci);

	wait();
	print_strings();
	print_integers();	
	}
	sc_stop();

}
Exemple #13
0
/**
 * This is the C task that is created multiple times.  Each task receives its
 * own parameter therefore differentiating between different tasks.
 */
void scheduler_c_task_private(void *task_ptr)
{
    scheduler_task& task = *(scheduler_task*)task_ptr;

    /* Have the responsible task call taskEntry() for each task */
    if (mTaskEntryTaskHandle == task.mHandle) {
        bool failure = false;

        print_strings(task.mName, " task calling taskEntry() for all tasks ... ");
        for (uint32_t i=0; i < gTaskList->size(); i++)
        {
            scheduler_task *t = gTaskList->at(i);
            if (!t->taskEntry()) {
                print_strings(t->mName, "  --> FAILED taskEntry()");
                failure = true;
            }
        }

        if (failure) {
            puts("ERROR: Killing FreeRTOS due to error(s)");
            vTaskEndScheduler();
        } else {
            /* Give permission for everyone to start the run() loop */
            for (uint32_t i=0; i < gTaskList->size(); i++)
            {
                xSemaphoreGive(mRunTask);
            }
        }
    }

    // Wait until we're given the go ahead by the task giving semaphore above
    xSemaphoreTake(mRunTask, portMAX_DELAY);

    portTickType xLastWakeTime = xTaskGetTickCount();
    portTickType xNextStatTime = 0;

    for (;;)
    {
#if (0 != configUSE_QUEUE_SETS)
        if (task.mQueueSet) {
            task.mQueueSetType = xQueueSelectFromSet(task.mQueueSet, task.mQueueSetBlockTime);
        }
#endif

        // Run the task code and suspend when an error occurs
        if (!task.run((void*)task.mParam)) {
            print_strings(task.mName, " --> FAILURE detected; suspending this task ...");
            vTaskSuspend(0);
        }
        ++(task.mRunCount);

        // Update the task statistics once in a short while :
        if (xTaskGetTickCount() > xNextStatTime) {
            xNextStatTime = xTaskGetTickCount() + OS_MS(task.mStatUpdateRateMs);
            task.mFreeStack = uxTaskGetStackHighWaterMark(task.mHandle);
            task.mCpuPercent = uxTaskGetCpuUsage(task.mHandle);
        }

        // Delay if set
        if (task.mTaskDelayMs) {
            vTaskDelayUntil( &xLastWakeTime, OS_MS(task.mTaskDelayMs));
        }
    }
}
Exemple #14
0
bool scheduler_init_all(bool register_internal_tlm)
{
    bool failure = false;

    /* If not tasks ... */
    if (0 == gTaskList || 0 == gTaskList->size()) {
        puts("ERROR: NO tasks added by scheduler_add_task()");
        failure = true;
        return failure;
    }

    /* Initialize all tasks */
    puts("*  Initializing tasks ...");
    for (uint32_t i=0; i < gTaskList->size(); i++)
    {
        scheduler_task *task = gTaskList->at(i);
        if (!task->init()) {
            print_strings(task->getTaskName(), "  --> FAILED init()");
            failure = true;
        }
    }

    /* Register telemetry for all tasks */
#if ENABLE_TELEMETRY
    puts("*  Registering tasks' telemetry ...");
    for (uint32_t i=0; i < gTaskList->size(); i++)
    {
        scheduler_task *task = gTaskList->at(i);
        if (!task->regTlm()) {
            failure = true;
        }

        /* Register statistical variables of this task */
        if (register_internal_tlm) {
            tlm_component *comp = tlm_component_add(task->mName);
            if (!tlm_variable_register(comp, "cpu_percent", &(task->mCpuPercent),
                                       sizeof(task->mCpuPercent), 1, tlm_uint)) {
                failure = true;
            }
            if (!tlm_variable_register(comp, "free_stack", &(task->mFreeStack),
                                       sizeof(task->mFreeStack), 1, tlm_uint)) {
                failure = true;
            }
            if (!tlm_variable_register(comp, "run_count", &(task->mRunCount),
                                       sizeof(task->mRunCount), 1, tlm_uint)) {
                failure = true;
            }
        }
        if (failure) {
            print_strings(task->mName, "  --> FAILED telemetry registration");
        }
    }

    puts("*  Restoring disk telemetry");
    // Restore telemetry registered by "disk" component
    FILE *fd = fopen(DISK_TLM_NAME, "r");
    if (fd) {
        tlm_stream_decode_file(fd);
        fclose(fd);
    }
#endif

    puts("*  Creating tasks ...");
    mRunTask = xSemaphoreCreateCounting(gTaskList->size(), 0);
    if (NULL == mRunTask) {
        failure = true;
    }

    for (uint32_t i=0; i < gTaskList->size(); i++)
    {
        scheduler_task *task = gTaskList->at(i);
        if (!xTaskCreate(scheduler_c_task_private,
                         (signed char*)task->mName,      /* Name  */
                         STACK_BYTES(task->mStackSize),  /* Stack */
                         task,                           /* Task param    */
                         task->mPriority,                /* Task priority */
                         &(task->mHandle)))              /* Task Handle   */
        {
            print_strings(task->mName, "  --> FAILED xTaskCreate()");
            failure = true;
        }
    }

    /* Find the task with highest stack, and this task will then be used
     * to call taskEntry() for everyone once FreeRTOS starts.
     * We have one task do taskEntry() for all because otherwise tasks will perform
     * taskEntry() independent of each other, and one task might complete it and
     * start running without other tasks completing their taskEntry().
     */
    uint32_t highestStack = 0;
    for (uint32_t i=0; i < gTaskList->size(); i++)
    {
        scheduler_task *task = gTaskList->at(i);
        if (task->mStackSize > highestStack) {
            highestStack = task->mStackSize;
            mTaskEntryTaskHandle = task->mHandle;
        }
    }

    return failure;
}
Exemple #15
0
void Quads_to_Assembly(qnode **head, FILE *f) {
		fp = f;
        qnode *temp;
        temp = *head;

		quad *x ;
		quad *y ;
		quad *z ;
		char *MainName;
		MainName = (char *)malloc(246);
			snprintf(MainName, 256, "_%s", main_program->id);

		fprintf(fp, "xseg\tsegment public 'code'\n"
				"\tassume\tcs:xseg, ds:xseg, ss:xseg\n"
				"\torg\t100h\n"
				"main\tproc near\n"
				"\tcall\tnear ptr %s\n"
				"\tmov\tax, 4C00h\n"
				"\tint\t21h\n"
				"main\tendp\n\n", MainName);
		free(MainName);
        if (temp == NULL)
                fprintf(stdout, "\nThe list is empty!\n");
        else {
       		while (temp != NULL) {	
				fprintf(fp, "@%d:\n", temp->n);
				x = temp->x;
				y = temp->y;
				z = temp->z;
		
				switch(temp->op) {
				case OP_UNIT:
				{
					
					char *nm = name(x);
					fprintf(fp, "%s proc near\n"
							"\tpush\tbp\n"
							"\tmov\tbp, sp\n"
							"\tsub\tsp, %d\n", nm, -temp->negOffset);
					free(nm);
					break;
				}
				case OP_ENDU:
				{
					char *end = endof(x->value.se, temp->nestingLevel);
					fprintf(fp, "\tjmp\t%s\n", end);
					char *nm = name(x);
					fprintf(fp, "%s:\n"
								"\tmov\tsp, bp\n"
								"\tpop\tbp\n"
								"\tret\n"
								"%s\tendp\n", end, nm);
					free(nm);
					free(end);
					break;
				}
				case OP_JUMP: 
				{
					char *lbl = label(z);
					fprintf(fp, "\tjmp\t%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_JUMPL:
				{
					char *lbl = label(z);
					fprintf(fp,  "\tjmp\t%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_LABEL:
				{
					char *lbl = label(z);
					free(lbl);
					break;
				}
				case OP_IFB:
				{
					load("al", x,  temp);
					char *lbl = label(z);
					fprintf(fp,  "\tor\tal, al\n"
							"\tjnz\t%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_CALL:
				{
					/*If z is procedure*/
					if (equalType(z->value.se->u.eFunction.resultType, typeVoid))
						fprintf(fp, "\tsub\tsp, 2\n");	
					fprintf(fp, "\tsub\tsp, 2\n");
					/*updateAL(temp, z->value.se);
					*/
					char *nm = name(z);
					fprintf(fp,	"\tcall\tnear ptr %s\n"
							"\tadd\tsp, %d\n", nm, size + 4);	
					free(nm);
					size  = 0;
					break;
				}
				case OP_PAR:
				{
					if (x->type == QUAD_SE) 
						size += sizeOfType(x->value.se->u.eParameter.type);
					else if (x->type == QUAD_POINTER) 
						size += sizeOfType(x->value.se->u.eParameter.type->refType);
					else 
						size += (x->type == QUAD_INTEGER) ?
						(sizeOfType(typeInteger)) : (sizeOfType(typeChar));

					if (y->mode == PASS_BY_VALUE) {
						if (x->type == QUAD_INTEGER || (x->type == QUAD_SE &&
						equalType(x->value.se->u.eParameter.type, typeInteger))) {
							load("ax", x, temp);
							fprintf(fp, "\tpush	ax\n");
						}
						else if (x->type == QUAD_CHAR || x->type == QUAD_BOOL || 
						(x->type == QUAD_SE && 
						(equalType(x->value.se->u.eParameter.type, typeChar) ||
						equalType(x->value.se->u.eParameter.type, typeBoolean)))) {
						load("al", x, temp);
						fprintf(fp, "\tsub\tsp, 1\n"
								"\tmov\tsi, sp\n"
								"\tmov\tbyte ptr [si], al\n");
						} 
						else fprintf(fp, "Error 1");
					}
					else if (y->mode == PASS_BY_REFERENCE || y->mode == RET) {
						loadAddr("si", x, temp);
						fprintf(fp, "\tpush\tsi\n");
					}
					else {
						fprintf(fp, "Error 2\n");
						return;
					}
					break;
				}
				case OP_RET:
				{	
					char *end = endof(temp->inFunction, temp->nestingLevel);
					fprintf(fp, "\tjmp %s\n", end);
					free(end);
					break;
				}
				case OP_RETV:
				{	
					if (x->type == QUAD_INTEGER || (x->type == QUAD_SE &&
						equalType(x->value.se->u.eVariable.type, typeInteger))) {
						fprintf(fp, "\tmov\tsi, word ptr [bp+6]\n");	// Address of result
						load("ax", x, temp);
						fprintf(fp, "\tmov\tword ptr [si], ax\n"); // store it
					}
					else if (x->type == QUAD_CHAR || x->type == QUAD_BOOL || 
						(x->type == QUAD_SE && 
						(equalType(x->value.se->u.eVariable.type, typeChar) ||
						equalType(x->value.se->u.eVariable.type, typeBoolean)))) {
						fprintf(fp, "\tmov\tsi, byte ptr [bp+6]\n");	// Address of result
						load("al", x, temp);
						fprintf(fp, "\tmov\tbyte ptr [si], al\n"); // store it
					}	
					break;
				}
				case OP_eq:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "cmp\tax, dx\n");
					fprintf(fp, "\tje\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_neq:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tcmp\tax, dx\n");
					fprintf(fp, "\tjne\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_less:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tcmp\tax, dx\n");
					fprintf(fp, "\tjl\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_greater:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tcmp\tax, dx\n");
					fprintf(fp, "\tjg\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_leq:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tcmp\tax, dx\n");
					fprintf(fp, "\tjle\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_geq:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tcmp\tax, dx\n");
					fprintf(fp, "\tjge\t");
					char *lbl = label(z);
					fprintf(fp, "%s\n", lbl);
					free(lbl);
					break;
				}
				case OP_PLUS:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tadd\tax, dx\n");
					store("ax", z, temp);
					break;
				}
				case OP_MINUS:
				{
					load("ax", x, temp);
					load("dx", y, temp);
					fprintf(fp, "\tsub\tax, dx\n");
					store("ax", z, temp);
					break;
				}
				case OP_bmul:
				{
					load("ax", x, temp);
					load("cx", y, temp);
					fprintf(fp, "\timul\tcx\n");
					store("ax", z, temp);
					break;
				}
				case OP_bdiv:
				{
					load("ax", x, temp);
					fprintf(fp, "\tcwd\n");
					load("cx", y, temp);
					fprintf(fp, "\tidiv\tcx\n");
					store("ax", z, temp);
					break;
				}
				case OP_bmod:
				{
					load("ax", x, temp);
					fprintf(fp, "cwd\n");
					load("cx", y, temp);
					fprintf(fp, "\tidiv\tcx\n");
					store("dx", z, temp);
					break;
				}
				case OP_mod:
				{
					load("ax", x, temp);
					fprintf(fp, "\tcwd\n");
					load("cx", y, temp);
					fprintf(fp, "\tidiv\tcx\n");
					store("dx", z, temp);
					break;
				}
				case OP_assign:
				{
					/*Fix this*/
					if (x->type == QUAD_SE || x->type == QUAD_POINTER) {
						if (equalType(x->value.se->u.eVariable.type, typeInteger) ||
							equalType(x->value.se->u.eVariable.type, typePointer(typeInteger))) {
							load("ax", x, temp);
							store("ax", z, temp);
						} else if (equalType(x->value.se->u.eVariable.type, typeChar) ||
								   equalType(x->value.se->u.eVariable.type, typePointer(typeChar)) || 
								   equalType(x->value.se->u.eVariable.type, typeBoolean) ||
								   equalType(x->value.se->u.eVariable.type, typePointer(typeBoolean))) {
							load("al", x, temp);
							store("al", z, temp);
						}
					}
					else if (x->type == QUAD_INTEGER) {
						load("ax", x, temp);
						store("ax", z, temp);
					}	
					else if (x->type == QUAD_CHAR || x->type == QUAD_BOOL) {
						load("al", x, temp);
						store("al", z, temp);
					}
					break;
				}
				case OP_ARRAY:
				{
					load("ax", y, temp);
					fprintf(fp, "\tmov\tcx, %d\n"
							"\timul	cx\n", size);
					loadAddr("cx", x, temp);
					fprintf(fp, "\tadd\tax, cx\n");
					store("ax", z, temp);
					break;
				}
				default:
					fprintf(fp, "For debugging\n");
					break;
				}
				temp = temp->next;
			}
        }
		fprintf(fp, //"extrn\t_putchar:proc\n"
					//"extrn\t_puts:proc\n"
					"extrn\t_writeInteger:proc\n"
					"extrn\t_writeBoolean:proc\n"
					"extrn\t_writeChar:proc\n"
					"extrn\t_writeReal:proc\n"
					"extrn\t_writeString:proc\n"
					"extrn\t_READ_INT:proc\n"
					"extrn\t_READ_BOOL:proc\n"
					"extrn\t_READ_CHAR:proc\n"
					"extrn\t_READ_REAL:proc\n"
					"extrn\t_READ_STRING:proc\n"
					"extrn\t_abs:proc\n"
					"extrn\t_fabs:proc\n"
					"extrn\t_sqrt:proc\n"
					"extrn\t_sin:proc\n"
					"extrn\t_cos:proc\n"
					"extrn\t_tan:proc\n"
					"extrn\t_arctan:proc\n"
					"extrn\t_exp:proc\n"
					"extrn\t_ln:proc\n"
					"extrn\t_pi:proc\n"
					"extrn\t_trunc:proc\n"
					"extrn\t_round:proc\n"
					"extrn\t_TRUNC:proc\n"
					"extrn\t_ROUND:proc\n"
					//"extrn\t_strlen:proc\n"
					//"extrn\t_strcmp:proc\n"
					//"extrn\t_strcpy:proc\n"
					//"extrn\t_strcat:proc\n"
					);

		print_strings(fp, head_str);

		fprintf(fp, "xseg ends\n"
					"\tend\tmain\n");
		}
Exemple #16
0
/**
 * main program.  Processes all files and returns one string
 * for each file in strings[]. In the process, all strings are
 * used to construct the trie we use to get the substring with
 * great f value.
 */
int main (int argc, char **argv)
{

    extern int optind;
    extern char *optarg;
    int opt;
    int i;
    int n_passes = MAX_PASSES;
    FILE *out = stdout;
    time_t now;

    time(&now);
    while ((opt = getopt(argc, argv, "dhPp:o:s")) != EOF) {
        switch(opt) {
        case 'h': do_usage(); exit(0);
        case 'P': flags |= FLAG_PROGRESS; break;
        case 'p': n_passes = atol(optarg); break;
        case 'd': flags |= FLAG_DEBUG; break;
        case 'o': out = fopen(optarg, "wb"); break;
        case 's': flags |= FLAG_PRINT_STATE; break;
        } /* switch */
    } /* while */

    if (n_passes > MAX_PASSES) n_passes = MAX_PASSES;
    if (n_passes < 1) n_passes = 1;

    if (argc > optind) {
        for (i = optind; i < argc; i++)
            process_file(argv[i]);
    } else  process_file(stdin_name);

    mark = strings_n; /* beginning of macros */

    /* print the strings in the begining */
    if (flags & FLAG_PRINT_STATE)
        print_strings();

    for(i = 0; i < n_passes; i++) {
        struct trie_node *root_trie, *max;
        int j;
        char *o;
        struct ref_buff *ref;

        if (flags & FLAG_DEBUG) {
            fprintf(stderr, D("PASS #%d:\n"), i);
        } /* if */

        /* INITIALIZE THE TRIE */
        assert(root_trie = new_trie());
        for (j = 0; j < strings_n; j++) {
            const byte *s;
            int l;

            for (s = strings[j], l = strings_sz[j]; l; s++, l--) {
                add_string(s, l, root_trie, j);
                if (*s == ESCAPE) {
                    s++; l--;
                } /* if */
            } /* for */
            if (flags & FLAG_PROGRESS) {
                static char *progress[] = {
                    "\\", "|", "/", "-",
                };
                fprintf(stderr,
                    "\r%s %d/%d",
                    progress[j % 4], j+1, strings_n);
            } /* if */
        } /* for */

        /* SEARCH FOR THE MOST EFFICIENT MACRO SUBSTITUTION */
        max = walk_trie(root_trie, savings_calculation);

        /* IF NOT FOUND, FINISH */
        if (max == root_trie) {
            if (flags & FLAG_DEBUG) {
                fprintf(stderr,
                    D("MACRO NOT FOUND, FINISHING\n"));
            } /* if */
            break;
        } /* if */

        if (flags & FLAG_DEBUG) {
            /* WRITE THE MACRO FOUND */
            fprintbuf(stderr,
                max->l, max->refs->b,
                D("MACRO FOUND: len=%d, nrep=%d, savings=%d"),
                max->l, max->n, savings_calculation(max));
        } /* if */

        /* copy the string macro as a new string. */
        strings[strings_n] = buffer + bs;
        memcpy(strings[strings_n], max->refs->b, max->l);
        bs += max->l;
        strings_sz[strings_n] = max->l;
        strings_n++;

        /* print the substitutions to be made. */
        if (flags & FLAG_DEBUG) {

#define FOREACHSUBST(X) \
            for (ref = max->refs; ref; ref = ref->nxt) { \
                int          ix = ref->ix; \
                const byte *src = ref->b + max->l; \
                byte       *dst = (byte *)ref->b; \
                const byte *end = strings[ix] + strings_sz[ix]; \
                int           n = end - src; \
                X \
            } /* for */

            FOREACHSUBST(
                    fprintf(stderr,
                        D("SUBST: string[%d], beg_hole=0x%lx, end_hole=0x%lx, hole_sz=%ld, end=0x%lx\n"),
                        ix, dst - strings[ix], src - strings[ix], src - dst, end - strings[ix]);
                ) /* FOREACHSUBST */
        } /* if */

        /* substitute the strings as macro calls */
        FOREACHSUBST(

                assert((strings[ix] <= dst) && (dst + MACRO_SIZE < src) && (src <= end));

                *dst++ = ESCAPE;
                *dst++ = i + OFFSET; /* i is the macro index */
                assert(n >= 0);
                while (n--) *dst++ = *src++;
                strings_sz[ix] -= max->l - MACRO_SIZE;

            ) /* FOREACHSUBST */
Exemple #17
0
int main() {
    print_strings("Lel", "Wot", "Lelling");
}
Exemple #18
0
void print_strings(std::string str, Args... args) {
    std::cout << str << ", ";
    print_strings(args...);
}
Exemple #19
0
int request_strings(req_list *rlp0, int n) {

	assert(rlp0->cur_entries > 0);

	int ne_lines0 = 0, ne_columns0 = 0;
	bool reordered = false;
	max_names_per_line = max_names_per_col = x = y = page = fuzz_len = 0;
	if ( ! request_strings_init(rlp0) ) return ERROR;

	const int dx = rl.max_entry_len + 1 + (rl.suffix ? 1 : 0);

	while(true) {
		if (ne_lines0 != ne_lines || ne_columns0 != ne_columns) {
			if (ne_lines0 && ne_columns0 ) n = PXY2N(page,x,y);
			if (!(max_names_per_line = ne_columns / dx)) max_names_per_line = 1;
			max_names_per_col = ne_lines - 1;
			names_per_page = max_names_per_line * max_names_per_col;
			ne_lines0 = ne_lines;
			ne_columns0 = ne_columns;
			page = N2P(n);
			x = N2X(n);
			y = N2Y(n);
			print_strings();
			print_message(NULL);
		}

		n = PXY2N(page,x,y);

		assert(fuzz_len >= 0);

		fuzz_len = min(fuzz_len, strlen(rl.entries[n]));

		move_cursor(y, x * dx + fuzz_len);

		int c;
		input_class ic;
		do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID);

		switch(ic) {
			case ALPHA:
				if (n >= rl.cur_entries) n = rl.cur_entries - 1;

				c = localised_up_case[(unsigned char)c];

				fuzz_forward( c );

				break;

			case TAB:
				if (! rlp0->ignore_tab) {
					n = request_strings_cleanup(reordered);
					if (n >= rlp0->cur_entries) return ERROR;
					else return -n - 2;
				}
				break;

			case RETURN:
				n = request_strings_cleanup(reordered);
				if (n >= rlp0->cur_entries) return ERROR;
				else return n;

			case COMMAND:
				if (c < 0) c = -c - 1;
				const int a = parse_command_line(key_binding[c], NULL, NULL, false);
				if (a >= 0) {
					switch(a) {
					case BACKSPACE_A:
						fuzz_back();
						break;

					case MOVERIGHT_A:
						request_move_right();
						break;

					case MOVELEFT_A:
						request_move_left();
						break;

					case MOVESOL_A:
						request_move_to_sol();
						break;

					case MOVEEOL_A:
						request_move_to_eol();
						break;

					case TOGGLESEOL_A:
						if (x != 0) x = 0;
						else request_move_to_eol();
						break;

					case LINEUP_A:
						request_move_up();
						break;

					case LINEDOWN_A:
						request_move_down();
						break;

					case MOVEINCUP_A:
						request_move_inc_up();
						break;

					case MOVEINCDOWN_A:
						request_move_inc_down();
						break;

					case PAGEUP_A:
					case PREVPAGE_A:
						request_prev_page();
						break;

					case PAGEDOWN_A:
					case NEXTPAGE_A:
						request_next_page();
						break;

					case MOVESOF_A:
						request_move_to_sof();
						break;

					case MOVEEOF_A:
						request_move_to_eof();
						break;

					case TOGGLESEOF_A:
						request_toggle_seof();
						break;

					case NEXTWORD_A:
						request_move_next();
						break;

					case PREVWORD_A:
						request_move_previous();
						break;

					case NEXTDOC_A:
						reordered |= request_reorder(1);
						break;

					case PREVDOC_A:
						reordered |= request_reorder(-1);
						break;

					case INSERT_A:
					case DELETECHAR_A:
						prune = !prune;
						break;

					case CLOSEDOC_A:
					case ESCAPE_A:
					case QUIT_A:
					case SELECTDOC_A:
						request_strings_cleanup(reordered);
						return -1;
					}
				}
				break;

			default:
				break;
		}
	}
}
Exemple #20
0
/* If mark_char is not '\0', we bold names ending with it. */
int request_strings(const char * const * const _entries, const int _num_entries, int n, const int _max_name_len, int _mark_char) {

	action a;
	input_class ic;
	int c, i, ne_lines0, ne_columns0;

	assert(_num_entries > 0);

	ne_lines0 = ne_columns0 = max_names_per_line = max_names_per_col = x = y = page = 0;
	entries = _entries;
	num_entries = _num_entries;
	max_name_len = _max_name_len + 1;
	mark_char = _mark_char;

	while(TRUE) {
		if (ne_lines0 != ne_lines || ne_columns0 != ne_columns) {
			if (ne_lines0 && ne_columns0 ) n = PXY2N(page,x,y);
			if (!(max_names_per_line = ne_columns / (max_name_len))) max_names_per_line = 1;
			max_names_per_col = ne_lines - 1;
			names_per_page = max_names_per_line * max_names_per_col;
			ne_lines0 = ne_lines;
			ne_columns0 = ne_columns;
			page = N2P(n);
			x = N2X(n);
			y = N2Y(n);
			print_strings();
			print_message(NULL);
		}

		move_cursor(y, x * max_name_len);

		do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID);

		n = PXY2N(page,x,y);

		switch(ic) {
			case ALPHA:
				if (n >= num_entries) n = num_entries - 1;

				c = localised_up_case[(unsigned char)c];

				for(i = 1; i < num_entries; i++)
					if (localised_up_case[(unsigned char)entries[(n + i) % num_entries][0]] == c) {
						normalize((n + i) % num_entries);
						break;
					}
				break;

			case TAB:
				if (n >= num_entries) return ERROR;
				else return -n - 2;

			case RETURN:
				if (n >= num_entries) return ERROR;
				else return n;

			case COMMAND:
				if (c < 0) c = -c - 1;
				if ((a = parse_command_line(key_binding[c], NULL, NULL, FALSE))>=0) {
					switch(a) {
					case MOVERIGHT_A:
						request_move_right();
						break;

					case MOVELEFT_A:
						request_move_left();
						break;

					case MOVESOL_A:
						request_move_to_sol();
						break;

					case MOVEEOL_A:
						request_move_to_eol();
						break;

					case TOGGLESEOL_A:
						if (x != 0) x = 0;
						else request_move_to_eol();
						break;

					case LINEUP_A:
						request_move_up();
						break;

					case LINEDOWN_A:
						request_move_down();
						break;

					case MOVEINCUP_A:
						request_move_inc_up();
						break;

					case MOVEINCDOWN_A:
						request_move_inc_down();
						break;

					case PAGEUP_A:
					case PREVPAGE_A:
						request_prev_page();
						break;

					case PAGEDOWN_A:
					case NEXTPAGE_A:
						request_next_page();
						break;

					case MOVESOF_A:
						request_move_to_sof();
						break;

					case MOVEEOF_A:
						request_move_to_eof();
						break;

					case TOGGLESEOF_A:
						request_toggle_seof();
						break;

					case ESCAPE_A:
						return -1;
					}
				}
				break;

			default:
				break;
		}
	}
}