int main(void) { unsigned int result; // Przetestuj kalkulator dla sumowania. if (DoMath(&result, OP_SUM, 27, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999) == 0) { printf("result: %u (should be 55485)\n", result); } else { puts("failed"); } // Przetestuj kalkulator dla mnożenia. if (DoMath(&result, OP_MUL, 29, 70, 108, 97, 103, 123, 77, 89, 45, 80, 73, 80, 69, 45, 73, 83, 45, 67, 65, 76, 76, 69, 68, 45, 72, 69, 78, 82, 89, 125) == 0) { printf("result: %u (should be 1270874112)\n", result); } else { puts("failed"); } // Przetestuj kalkulator dla dzielenia. if (DoMath(&result, OP_DIV, 21, 1048576, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) == 0) { printf("result: %u (shoule be 1)\n", result); } else { puts("failed"); } return 0; }
static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args) { Boolean refresh = False; #ifdef DEBUG printf("NumEntry - set_values(%s) - >%s< >%s<\n", XtName(new_w), NumEntry_Value(old), NumEntry_Value(new_w)); #endif if (XtIsSensitive(old) != XtIsSensitive(new_w) && !XtIsSensitive(new_w)) { if (NumEntry_TimerId(new_w)) { XtRemoveTimeOut(NumEntry_TimerId(new_w)); NumEntry_TimerId(new_w) = (XtIntervalId)NULL; } } if (NumEntry_LabelString(old) != NumEntry_LabelString(new_w)) { NumEntry_LabelString(new_w) = XmStringCopy(NumEntry_LabelString(new_w)); XtVaSetValues(NumEntry_Label(new_w), XmNlabelString, NumEntry_LabelString(new_w), NULL); if (NumEntry_LabelString(old)) { XmStringFree(NumEntry_LabelString(old)); } } if (NumEntry_Value(old) != NumEntry_Value(new_w)) { char *tmp; Position Place; #ifdef DEBUG printf("NumEntry - set_values(%s) - value old >%s< new >%s<\n", XtName(new_w), NumEntry_Value(old), NumEntry_Value(new_w)); #endif tmp = NumEntry_Value(new_w); NumEntry_Value(new_w) = XtNewString(tmp); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(new_w)); XmTextFieldSetString(NumEntry_TextField(new_w), NumEntry_Value(new_w)); XmTextFieldSetInsertionPosition(NumEntry_TextField(new_w), Place); if (NumEntry_Value(old)) { XtFree(NumEntry_Value(old)); } refresh = True; DoMath(new_w); } if (NumEntry_Columns(old) != NumEntry_Columns(new_w)) { Dimension old_width = XtWidth(NumEntry_TextField(new_w)); XtVaSetValues(NumEntry_TextField(new_w), XmNcolumns, NumEntry_Columns(new_w), NULL); XtWidth(new_w) -= (old_width - XtWidth(NumEntry_TextField(new_w))); refresh = True; } return (refresh); }
static void Activate(Widget W, XtPointer client_data, XtPointer call_data) { #ifdef DEBUG printf("NumEntry - Activate(%s) - %s\n", XtName(W), XtName(XtParent(W))); #endif DoMath(XtParent(W)); XtCallCallbacks(XtParent(W), XmNactivateCallback, call_data); }
static void LosingFocus(Widget W, XtPointer client_data, XtPointer call_data) { #ifdef DEBUG printf("NumEntry - LosingFocus(%s) - >%s<\n", XtName(W), NumEntry_Value(XtParent(W))); #endif AutoRepeat(W, False); DoMath(XtParent(W)); XtCallCallbacks(XtParent(W), XmNlosingFocusCallback, call_data); }
int main() { struct sigaction act; act.sa_sigaction = Handle; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaction(SIGSEGV, &act, 0); /* * Do some FP math, then raise a SEGV. The SEGV handler below verifies * that the saved FP state has the expected values. */ DoMath(); /* does not return */ return 0; }
static void StepValue(Widget W, int a, int b) { Widget Rc = XtParent(XtParent(W)); Position Place; char *buf; #ifdef DEBUG printf("NumEntry - StepValue(%s) - %s\n", XtName(W), XtName(Rc)); #endif buf = XmTextFieldGetString(NumEntry_TextField(Rc)); Place = XmTextFieldGetInsertionPosition(NumEntry_TextField(Rc)); if (buf[Place] != '.') { buf = IncDigit(buf, &Place, a); XmTextFieldSetString(NumEntry_TextField(Rc), buf); XmTextFieldSetInsertionPosition(NumEntry_TextField(Rc), Place); DoMath(Rc); } XtFree(buf); }
void WriteToMem(int num_measures) { int i, ii, j; char laux[LONGSTRINGSIZE]; double currentcost; i=1; /*It must start with 1*/ while (measure[i].search[0] != '\0') { /*LTspice special case*/ switch(spice) { case 1: /*Eldo*/ break; case 2: /*HSPICE*/ break; case 3: /*LTspice*/ /*Str2Lower(laux);*/ ii=strpos2(measure[i].data, "=", 1); /* LTspice measurement format is different than Eldo and HSPICE */ if (ii) { /* so specific code is added in here to cope with the difference */ strsub(laux, measure[i].data, ii+1, LONGSTRINGSIZE); /* */ strcpy(measure[i].data, laux); /* */ if (strpos2(laux, "dB,", 1)) { /*Is the measurement a complex AC signal?*/ ii=1; if (strpos2(measure[i].search, "phase", 1)) ReadSubKey(laux, measure[i].data, &ii, ',', 0xB0, 0); /*measure the AC phase */ else ReadSubKey(laux, measure[i].data, &ii, '(', 'd', 0); /*measure the AC magnitude*/ strcpy(measure[i].data, laux); } } break; case 4: /*Spectre*/ break; case 50: /*Qucs*/ break; case 51: /*ngspice*/ break; case 100: /*general*/ break; default: printf("errfunc.c - WriteToMem -- Something unexpected has happened!\n"); exit(EXIT_FAILURE); } i++; } DoMath(num_measures); /*'MATH=&...'; information is in the variable 'measured_data'*/ i=1; /*It must start with 1*/ while (measure[i].search[0] != '\0') { strcpy(laux, UNIQUECHAR); ii=0; ii= strpos2(measure[i].var_name, laux, 1); /*if UNIQUECHAR is inexisting in measure[i].var_name and in Str2Lower(UNIQUECHAR) */ Str2Lower(laux); /*as well, this means we are processing a "MEASURE_VAR" line with intermediate data. */ ii=ii + strpos2(measure[i].var_name, laux, 1); /*ALL OTHERS MUST enter the following 'if' to have its measure[i].data processed */ if (ii >1) { ii=0; /*UNIQUECHAR must be the first character. If not, this is an intermediate "MEASURE_VAR"*/ } if (ii) { strcpy(laux, UNIQUECHAR); ii=(int)strlen(laux); strsub(laux, measure[i].var_name, ii+1, LONGSTRINGSIZE); /*1- find output measure variable */ /* by copying the last part of the string starting from UNIQUECHAR*/ j=0; while (strcasecmp(laux, measurements[j].meas_symbol)) { /*2- get its order in measurements[i] */ if (measurements[j].meas_symbol[0] == '\0') { /*if symbol is not found*/ printf("errfunc.c - WriteToMem -- Symbol from SPICE simulation not found in memory: %s\n", laux); exit(EXIT_FAILURE); } j++; } if ((int)strlen(measure[i].data)) { strcpy(laux, measure[i].data); /*3- read measurement */ StripSpaces(laux); } else { #ifdef DEBUG i--; /* to keep the same code from initialize.c */ sprintf(lkk, "%i", i); /* to remove integer added in (*) */ ii=(int)strlen(lkk); /* to remove integer added in (*) */ strcpy(lkk, measurements[i].meas_symbol); /* to remove integer added in (*) */ lkk[(int)strlen(lkk)-ii]='\0'; /* to remove integer added in (*) */ printf("errfunc.c - WriteToMem -- Data not read for measurement in *.cfg: %s\n", lkk); fflush(stdout); /*Sometimes the simulation does not converge, and so do not exit*/ i++; #endif } measurements[j].measured_value=asc2real(laux, 1, (int)strlen(laux)); /*4- convert it to double */ if (!fcmp(measurements[j].measured_value, 0)) { /*5- check NaN and other text strings */ if ((laux[0] < 43) || (laux[0] > 57) ) /*if its text*/ if (measurements[j].objective_constraint == 1) /*1=MIN*/ measurements[j].measured_value=+1e+30; /*so that a large cost is later assigned*/ if (measurements[j].objective_constraint == 2) /*2=MAX*/ measurements[j].measured_value=-1e+30; /*so that a large cost is later assigned*/ if (measurements[j].objective_constraint == 4) /*4=LE*/ measurements[j].measured_value=+1e+30; /*so that a large cost is later assigned*/ if (measurements[j].objective_constraint > 4) /*5=GE, 6=EQ*/ measurements[j].measured_value=-1e+30; /*so that a large cost is later assigned*/ } } i++; } /*----------------------------------------------------------------------------*/ /**/ /*Step5: find cost*/ currentcost=CostFunction(); if (maxcost<currentcost) maxcost=currentcost; /**/ /*Step6: save log information to file <hostname>.log*/ if (LOG) { LogtoFile(currentcost); } /*----------------------------------------------------------------------------*/ }