home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1989 / 12 / titel / konflikt.c next >
Encoding:
C/C++ Source or Header  |  1989-09-28  |  12.8 KB  |  566 lines

  1.  
  2. /*******   Konflikt-Morphologie in Quick-C, V.1.01  *******/
  3. /*            (c) 1989 Ulrich Schmitz & toolbox           */
  4. /* Zum Compilieren und Linken Befehlszeilen-Compiler ver- */
  5. /* wenden!  Folgende Kommandos als Batchjob abspeichern   */
  6. /* (C.BAT) und dann mit dem Programmnamen als Parameter   */
  7. /* aufrufen (ohne Extension).       Beispiel: c listing   */
  8. /* (Jetzt kommt der Text für den Batch:)                  */
  9. /* qcl /c /AL /Ot %1.c                                    */
  10. /* link %1 ,,, /STACK:0x4800                              */
  11. /**********************************************************/
  12.  
  13. #include <dos.h>
  14. #include <stdio.h>
  15. #include <graph.h>
  16. #include <conio.h>
  17.  
  18. #define MOUSE 0x33
  19. #define MAX_FELDER 150
  20. #define MONO_SEG   0xB0000000
  21. #define COLOR_SEG  0xB8000000
  22. #define DELETE (char)8
  23. #define SPACE (char)32
  24.  
  25. union REGS reg;
  26.  
  27. /****** GLOBALE VARIABLEN *********************************/
  28.  
  29. int xp[8]={ 0,2,14,26,38,50,62,74 },
  30.   Wahl[MAX_FELDER], alte_Farbe;
  31. char ff[11]="           ";
  32. void vm_init (void);
  33. int vm_modus (void);
  34.  
  35. static int
  36. far *intptr_v_ram;
  37.  
  38. /* - - - - - - - -  Strukturen  - - - - - - - - - - - - - */
  39.  
  40. struct Morphos
  41. {
  42.   char c[12];
  43. };
  44.  
  45. struct Morphos Feld[MAX_FELDER];
  46.  
  47. /* - - - - - - -  Unterprogramme  - - - - - - - - - - - - */
  48.  
  49. /* ------------------------------------------------------ */
  50.  
  51. void init_feld(feld)
  52.  
  53. char feld[];
  54. {
  55. int i;
  56.   for( i=0 ;i <= 12 ;i++ )
  57.     feld[i] = NULL;
  58.  
  59.  for(i=7; i<=MAX_FELDER - 7; i+=7)
  60.     Wahl[i] = 0;
  61.  
  62. }
  63.  
  64. /* ------------------------------------------------------ */
  65. /* Funktion ließt 'n'-Zeichen von der Tastatur und sperrt */
  66. /* bei Mehreingaben. DEL und BACKSPACE werden interpre-   */
  67. /* tiert                                                  */
  68. /* Eingabe: char *feld -> speichert die eingegeb. Zeichen */
  69. /*          int n       -> enthält die Anzahl der Zeichen */
  70. /* Ausgabe: KEINE, String wird mit '\0' abgeschlossen !!! */
  71. /* ------------------------------------------------------ */
  72.  
  73. void form_input(feld,n)
  74.  
  75. char feld[];
  76. int n;
  77.  
  78. {
  79.  char cc;
  80.  int i, c;
  81.  start:
  82.  feld[0]=NULL;
  83.  for(i = 0; i <= n-1; i++){
  84.  
  85.   cc=getch();
  86.   c = (int)cc;
  87.  
  88.   if( (c == 0) || (c == 8) || (c == 13) )
  89.                       /*  DEL oder BACKSPACE oder CR      */
  90.   {
  91.      switch(c){
  92.       case 0:
  93.       cc = getch();
  94.       if((i >= 1) && (cc == 'S')){
  95.        putchar(DELETE);
  96.        putchar(SPACE);
  97.        putchar(DELETE);
  98.        feld[i-1]=' ';}
  99.       i-=2;
  100.       break;
  101.  
  102.       case 8:
  103.       if(i >= 1){
  104.        putchar(DELETE);
  105.        putchar(SPACE);
  106.        putchar(DELETE);
  107.        feld[i-1]=' ';}
  108.       i-=2;
  109.       break;
  110.  
  111.       case 13:
  112.       feld[i]=NULL;
  113.       i = n;
  114.       break;
  115.       }
  116.   }
  117.  
  118.   else
  119.     if (i >= 0){      /*  normaler Buchstabe              */
  120.        putchar(cc);
  121.        feld[i]=cc;
  122.       }
  123.  
  124.   if (i < 0)          /*  ABBRUCH, am Anfang DEL ect.     */
  125.       i = n;
  126.  
  127.  }
  128. feld[i]=NULL;
  129. }
  130. /* ------------------------------------------------------ */
  131.  
  132. void Mouse_ON()
  133. {
  134.  reg.x.ax = 0x01;
  135.                       /*  Funktionsnummer 1:  Maus ein    */
  136.  int86(MOUSE, ®, ®);
  137. }
  138. /* ------------------------------------------------------ */
  139.  
  140. int vm_modus (void)
  141. {
  142.  union REGS regs;
  143.  regs.h.ah = 0x0F;
  144.  int86(0x10, ®s, ®s);
  145.  return(regs.h.al);
  146. }
  147. /* ------------------------------------------------------ */
  148.  
  149. void vm_init (void)
  150. {
  151.  if (vm_modus() == 7)
  152.    {
  153.     intptr_v_ram = (int far*) MONO_SEG;
  154.    }
  155.  
  156.    else
  157.    {
  158.     intptr_v_ram = (int far*) COLOR_SEG;
  159.    }
  160. }
  161. /* ------------------------------------------------------ */
  162.  
  163. void screen_buffer( int far *ziel)
  164. {
  165.  register s;
  166.  int far *start;
  167.  int zeile;
  168.  
  169.  for (zeile=0; zeile <= 24; zeile++){
  170.     start = intptr_v_ram + zeile * 80;
  171.     for ( s=0; s<= 79; s++)
  172.   *ziel++ = *start++;
  173.  }
  174. }
  175. /* ------------------------------------------------------ */
  176.  
  177. void buffer_screen( int far *quelle)
  178. {
  179.  register s;
  180.  int far *start;
  181.  int zeile;
  182.  
  183.  for (zeile=0; zeile <= 24; zeile++){
  184.     start = intptr_v_ram + zeile * 80;
  185.     for ( s=0; s<= 79; s++)
  186.   *start++ = *quelle++;
  187.  }
  188. }
  189. /* ------------------------------------------------------ */
  190.  
  191. void Mouse_OFF()
  192. {
  193.  reg.x.ax = 0x02;
  194.                       /*  Funktionsnummer 2:  Maus aus    */
  195.  int86(MOUSE, ®, ®);
  196. }
  197. /* ------------------------------------------------------ */
  198.  
  199. int Mouse_install()
  200. {                     /*  ax = -1 :installiert
  201.                           ax =  0 :Maustreiber fehlt      */
  202.  reg.x.ax = 0x00;
  203.  int86(MOUSE, ®, ®);
  204.  return(reg.x.ax);
  205. }
  206. /* ------------------------------------------------------ */
  207.  
  208. int X_position()
  209. {
  210.  reg.x.ax = 0x05;
  211.                       /*  Funktionsnummer 5: Mausinfo     */
  212.  reg.x.bx = 0x00;
  213.                                 /*  linke Taste           */
  214.  int86(MOUSE, ®, ®);
  215.  return(reg.x.cx);
  216. }
  217. /* ------------------------------------------------------ */
  218. int Mouse_Button()
  219. {
  220.  reg.x.ax = 0x03;
  221.                       /*  Funktionsnummer 3: Maustaste    */
  222.  int86(MOUSE, ®, ®);
  223.  return(reg.x.bx);
  224.                       /*  1=linke, 2=rechte Maustaste     */
  225. }
  226. /* ------------------------------------------------------ */
  227.  
  228. int Y_position()
  229. {
  230.  reg.x.ax = 0x05;
  231.                       /*  Funktionsnummer 5: Mausinfo     */
  232.  reg.x.bx = 0x00;
  233.                                 /*  linke Taste           */
  234.  int86(MOUSE, ®, ®);
  235.  return(reg.x.dx);
  236. }
  237. /* ------------------------------------------------------ */
  238.  
  239. void Cursor_Text()
  240. {
  241.  reg.x.ax = 0x0A;
  242.                       /*  Funktionsnummer 10: Textcursor  */
  243.  reg.x.bx = 0x01;
  244.                                 /*  Hardware-Cursor       */
  245.  reg.x.cx = 0x00;
  246.                                 /*  Bildschirm Maskenwert */
  247.  reg.x.dx = 0x0D;
  248.                                 /*  Cursor Maskenwert     */
  249.  int86(MOUSE, ®, ®);
  250. }
  251. /* ------------------------------------------------------ */
  252.  
  253. void Cursor()
  254. {
  255.  reg.x.ax = 0x0A;
  256.                       /*  Funktionsnummer 10: Textcursor  */
  257.  reg.x.bx = 0x01;
  258.                                 /*  Hardware-Cursor       */
  259.  reg.x.cx = 0x0C;
  260.                                 /*  Bildschirm Maskenwert */
  261.  reg.x.dx = 0x0D;
  262.                                 /*  Cursor Maskenwert     */
  263.  int86(MOUSE, ®, ®);
  264. }
  265. /* ------------------------------------------------------ */
  266.  
  267. void Cursor_OFF()
  268. {
  269.  reg.x.ax = 0x0A;
  270.                       /*  Funktionsnummer 10: Textcursor  */
  271.  reg.x.bx = 0x01;
  272.                                 /*  Hardware-Cursor       */
  273.  reg.x.cx = 0xFF;
  274.                                 /*  Bildschirm Maskenwert */
  275.  reg.x.dx = 0xFF;
  276.                                 /*  Cursor-Maskenwert     */
  277.  int86(MOUSE, ®, ®);
  278. }
  279. /* ------------------------------------------------------ */
  280.  
  281. void Mouse_Text()
  282. {
  283.  static int ix;
  284.  ix++;
  285.  
  286.  if (ix <= 250){
  287.    reg.x.cx = 0x0C;
  288.    reg.x.dx = 0x0D;
  289.    }
  290.  
  291.  else {
  292.    reg.x.cx = 0x01;
  293.    reg.x.dx = 0x0D;
  294.    if (ix == 500)
  295.  ix = 0;
  296.    }
  297.  
  298.  reg.x.ax = 0x0A;
  299.                       /*  Funktionsnummer 10: Textcursor  */
  300.  reg.x.bx = 0x01;
  301.                                     /*  Hardware-Cursor   */
  302.  int86(MOUSE, ®, ®);
  303. }
  304. /* ------------------------------------------------------ */
  305.  
  306. void Eingabe_Maske()
  307. {
  308.  int i;
  309.  
  310.  Cursor_Text();
  311.  Mouse_OFF();
  312.  
  313.  _settextwindow(1,1,25,80);
  314.  
  315.  _wrapon(_GWRAPOFF);
  316.  _clearscreen( _GCLEARSCREEN);
  317.  
  318.  _settextposition(1,1);
  319.  _outtext("<<<  Konflikt-Morphologie, ein toolbox-Utility"\
  320.           " von Ulrich Schmitz   (C) 1989 >>>");
  321.  
  322.  _settextposition(2,1);
  323.  _outtext("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░   "\
  324.           "            ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
  325.  _settextcolor(15);
  326.  _settextposition(2,33);
  327.  _outtext("EINGABE-MASKE");
  328.  
  329.  _settextcolor(alte_Farbe);
  330.  _settextposition(3,1);
  331.  _outtext("░░░░░░░░░░░░░ Forderungen nach Wichtigkeit: 1"\
  332.           " sehr wichtig, 5 unwichtig ░ 1..9 ░");
  333.  
  334.  _settextposition(4,1);
  335.  _outtext("░ PARAMETER ░    <1>    ░    <2>    ░    <3>   "\
  336.           " ░    <4>    ░    <5>    ░ Wert ░");
  337.  
  338.  for (i=1; i<=20; i++){
  339.  
  340.   _settextposition(4+i,1);
  341.   _outtext("░           ░           ░           ░"\
  342.            "           ░           ░           ░      ░");
  343.  }
  344.  _settextposition(25,1);
  345.  _outtext("░░░░░  Um die Eingabe zu beenden, letzten oder"\
  346.           " leeren Parameter eingeben!  ░░░░░");
  347.  
  348. }
  349. /* ------------------------------------------------------ */
  350.  
  351. int Umrechnung(int f)
  352. {
  353.  int x;
  354.  x = (int)*Feld[f].c;
  355.  x-=48;
  356.  
  357.  if ((x < 0) || (x > 9))
  358.      x = 1;
  359. return(x);
  360. }
  361. /* ------------------------------------------------------ */
  362.  
  363. void Eingabe()
  364. {
  365. int i=0, z, f;
  366.  
  367.  for (z=1; z <= MAX_FELDER; z++)
  368.       init_feld(Feld[z].c);
  369.  
  370.  for (z=1; z<=20; z++){
  371.    do {
  372.      i++;
  373.      f = ((z-1) * 7) + i;
  374.      _settextposition(z+4,xp[i]);
  375.  
  376.      if(i==7){
  377.        printf("->");
  378.        form_input(Feld[f].c,1);
  379.        Wahl[f] = Umrechnung(f);
  380.       }
  381.  
  382.      else
  383.      form_input(Feld[f].c,11);
  384.  
  385.    } while( ((*Feld[f].c != NULL)||(i != 1)) && (i <= 6) );
  386.  
  387.  if ((*Feld[f].c == NULL) && (i == 1))
  388.    z=21;
  389.  i=0;
  390.  }
  391.  
  392.  z=0;
  393.  for(i=7; i<=MAX_FELDER - 7; i+=7){
  394.      z++;
  395.      _settextposition(z+4,74);
  396.      if (Wahl[i] != 0)
  397.   printf("░ %d ░░",Wahl[i]);
  398.      else  {
  399.  
  400.   _settextposition(z+4,2);
  401.   printf("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"\
  402.          "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
  403.  
  404.   }
  405.  }
  406. Cursor_OFF();
  407. }
  408. /* ------------------------------------------------------ */
  409.  
  410. void Loesung()
  411. {
  412.  int X_Pos,Y_Pos, f, fy, fn, x=0, i, n;
  413.  
  414.  _settextcolor(15);
  415.  _settextposition(2,33);
  416.  _outtext("AUSWAHL-MASKE");
  417.  
  418.  _settextposition(25,1);
  419.  _outtext("░ Lösungen anwählen <-LINKE MAUSTASTE"\
  420.           "     RECHTE MAUSTASTE->Berechnung starten ░");
  421.  
  422.  _settextcolor(alte_Farbe);
  423.  Mouse_ON();
  424.  
  425.  while(Mouse_Button() != 2){
  426.   X_Pos = X_position();
  427.   Y_Pos = Y_position();
  428.   Mouse_Text();
  429.   Mouse_ON();
  430.   x = 1;
  431.  
  432.   if (Mouse_Button() == 1){
  433.     for (i=104; i<=488; i=i+96){
  434.     x++;
  435.        if ( (X_Pos >= i) && (X_Pos <= (i + 80)) ) {
  436.   fy = (Y_Pos / 8) - 4;
  437.   f = fy * 7 + x;
  438.   _settextcolor(alte_Farbe);
  439.     for (n=2; n<=6; n++){
  440.                                        /* Initialisieren  */
  441.      _settextposition(fy+5,n*12-10);
  442.      fn = fy * 7 + n;
  443.      if (Feld[fn].c)
  444.   _outtext(Feld[fn].c);
  445.  
  446.      Wahl[fn] = 0;
  447.     }
  448.   _settextcolor(15);
  449.                                        /* Feld auswaehlen */
  450.   _settextposition(fy+5,x*12-10);
  451.   _outtext(Feld[f].c);
  452.   Wahl[f] = 1;
  453.        }
  454.     }
  455.   }
  456.  }
  457. }
  458. /* ------------------------------------------------------ */
  459.  
  460. int Ergebnis()
  461. {
  462. int z, i, ii, Nutzwert_A, Nutzwert_B, x, c;
  463.  
  464.  _settextwindow(7,19,20,59); /* Ausgabefenster definieren */
  465.  _settextcolor(15);
  466.  _settextposition(1,1);
  467.  _outtext("           ╔═════════════════╗          ");
  468.  _settextposition(2,1);
  469.  _outtext("╔══════════╣ E R G E B N I S ╠══════════╗");
  470.  _settextposition(3,1);
  471.  _outtext("║          ╚═════════════════╝          ║");
  472.  
  473.  for(z=4; z<=12; z++){
  474.   _settextposition(z,1);
  475.   _outtext("║                                       ║");
  476.  }
  477.  _settextposition(13,1);
  478.  _outtext("╚═══════════════════════════════════════╝");
  479.  
  480.  _settextcolor(alte_Farbe);
  481.  
  482. /*- Berechnung der Nutzwerte :  = Summe der Produkte von -*/
  483. /*-                        Parametergewicht * Skalenwert -*/
  484.  
  485.  Nutzwert_A = 0;
  486.  Nutzwert_B = 0;
  487.  
  488.  for(i=1; i<=MAX_FELDER - 7; i+=7){
  489.   for(ii = 1; ii<=5; ii++){
  490.    if (Wahl[i+ii] == 1)
  491.       x=ii;
  492.   }
  493.   Nutzwert_A = Nutzwert_A + (x * Wahl[i+6]);
  494.   Nutzwert_B = Nutzwert_B + ((6-x) * Wahl[i+6]);
  495.   x=0;
  496.  }
  497.  _settextposition(5,3);
  498.  printf("Die gewählte Lösung erzielte für Sie ");
  499.  _settextposition(6,3);
  500.  printf("einen Nutzwert von %d zu %d"\
  501.         " Punkten.",Nutzwert_B, Nutzwert_A);
  502.  
  503.  _settextcolor(15);
  504.  _settextposition(9,5);
  505.  _outtext("(1) -> Andere Lösung berechnen.");
  506.  _settextposition(10,5);
  507.  _outtext("(2) -> Neuen Konflikt eingeben.");
  508.  _settextposition(11,5);
  509.  _outtext("(3) -> Programm beenden.       ");
  510.  
  511.  _settextwindow(1,1,25,80);
  512.  while((c != '1')&&(c != '2')&&(c != '3'))
  513.  c = getch();
  514.  
  515.  return(c - 48);
  516. }
  517.  
  518. /* ------------------------------------------------------ */
  519.  
  520. /*******   H A U P T P R O G R A M M   ********************/
  521.  
  522. main()
  523. {
  524. int i, screen[2000];
  525.  
  526. _setvideomode( _MRES16COLOR);
  527. vm_init();
  528. alte_Farbe = _gettextcolor();
  529.  
  530. if(Mouse_install() == 0)
  531.  
  532.     { printf("Programm-Ende,"\
  533.              " da kein Maustreiber installiert!   ");
  534.     goto ENDE; }
  535.  
  536.  
  537. START:
  538.  
  539.  Eingabe_Maske();
  540.  Eingabe();
  541.  
  542.  
  543. AUSWAHL:
  544.  
  545.  Loesung();
  546.  
  547.  Mouse_OFF();
  548.  Cursor_OFF();
  549.  screen_buffer(screen);
  550.                                  /* Bildschirm sichern    */
  551.  i = Ergebnis();
  552.  buffer_screen(screen);
  553.  if (i == 1)
  554.      goto AUSWAHL;
  555.  else
  556.  if (i == 2)
  557.      goto START;
  558.  
  559.  _settextcolor(alte_Farbe);
  560.  _clearscreen( _GCLEARSCREEN);
  561.  Cursor();
  562. ENDE: return(0);
  563. }
  564.  
  565. /*******   E N D E  ***************************************/
  566.