home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 480.lha / SmartField / Programs / example / e.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-06  |  16.5 KB  |  621 lines

  1. /**************************************
  2. *  SMART FIELDS EXAMPLE PROGRAM v1.01
  3. *  © Copyright 1988 Timm Martin
  4. *  All Rights Reserved
  5. ***************************************/
  6.  
  7. #include <exec/io.h>
  8. #include <exec/memory.h>
  9. #include <exec/ports.h>
  10. #include <exec/types.h>
  11. #include <graphics/gfxbase.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/intuitionbase.h>
  14. #include <console/console.h>
  15. #include <console/fields.h>
  16. #include <console/functions.h>
  17. #include <toolkit/toolkit.h>
  18. #include <functions.h>
  19.  
  20. /************************
  21. *  INTUITION STRUCTURES
  22. *************************/
  23.  
  24. struct IntuitionBase *IntuitionBase = NULL;
  25. struct GfxBase       *GfxBase = NULL;
  26. struct Window        *win = NULL;
  27. struct RastPort      *rp;
  28.  
  29. /********************
  30. *  VENDOR STRUCTURE
  31. *********************/
  32.  
  33. struct Phone {
  34.   int AreaCode;
  35.   int Prefix;
  36.   int Suffix;
  37. };
  38.  
  39. #define NAME_SIZE 30
  40. #define ADDRESS_SIZE 30
  41. struct Vendor {
  42.   char   Name[NAME_SIZE];
  43.   char   Address[4][ADDRESS_SIZE];
  44.   char   Contact[NAME_SIZE];
  45.   struct Phone Telephone;
  46.   int    Number;
  47.   struct Vendor *Next;
  48. };
  49.  
  50. struct Vendor *first_vendor = NULL;  /* top of vendor list */
  51. struct Vendor *chnge_vendor = NULL;  /* vendor being changed */
  52.  
  53. /********************
  54. *  FIELD STRUCTURES
  55. *********************/
  56.  
  57. /*** TITLES ***/
  58.  
  59. #define STRING_TEXT 1,0,JAM1,-3,-11,NULL
  60. struct IntuiText name_text = { STRING_TEXT, (STRPTR)"Name", NULL };
  61. struct IntuiText addr_text = { STRING_TEXT, (STRPTR)"Address", NULL };
  62. struct IntuiText cont_text = { STRING_TEXT, (STRPTR)"Contact", NULL };
  63. struct IntuiText phon_text = { STRING_TEXT, (STRPTR)"Phone", NULL };
  64. struct IntuiText numb_text = { STRING_TEXT, (STRPTR)"Vendor Number", NULL };
  65.  
  66. /*** BORDERS ***/
  67.  
  68. SHORT name_pairs2[] = { 2,11, 274,11, 274, 1, 275, 1, 275,11 };
  69. SHORT name_pairs1[] = { 0, 0, 273, 0, 273,10,   0,10,   0, 0 };
  70. SHORT addr_pairs2[] = { 2,41, 274,41, 274, 1, 275, 1, 275,41 };
  71. SHORT phon_pairs2[] = { 2,11, 140,11, 140, 1, 141, 1, 141,11 };
  72. SHORT phon_pairs1[] = { 0, 0, 139, 0, 139,10,   0,10,   0, 0 };
  73. SHORT numb_pairs2[] = { 2,11, 102,11, 102, 1, 103, 1, 103,11 };
  74. SHORT numb_pairs1[] = { 0, 0, 101, 0, 101,10,   0,10,   0, 0 };
  75.  
  76. #define BORDER2 -3,-2,2,0,JAM1,5
  77. #define BORDER1 -3,-2,1,0,JAM1,5
  78. struct Border name_border2 = { BORDER1, name_pairs1, NULL };
  79. struct Border name_border1 = { BORDER2, name_pairs2, &name_border2 };
  80. struct Border addr_border1 = { BORDER2, addr_pairs2, &name_border2 };
  81. struct Border phon_border2 = { BORDER2, phon_pairs2, NULL };
  82. struct Border phon_border1 = { BORDER1, phon_pairs1, &phon_border2 };
  83. struct Border numb_border2 = { BORDER2, numb_pairs2, NULL };
  84. struct Border numb_border1 = { BORDER1, numb_pairs1, &numb_border2 };
  85.  
  86. /*** BUFFERS ***/
  87.  
  88. #define PHONE_SIZE 15  /* (xxx) xxx-xxxx */
  89. #define NUMBER_SIZE 5  /* #### */
  90.  
  91. UBYTE name_input[NAME_SIZE];
  92. UBYTE add1_input[ADDRESS_SIZE];
  93. UBYTE add2_input[ADDRESS_SIZE];
  94. UBYTE add3_input[ADDRESS_SIZE];
  95. UBYTE add4_input[ADDRESS_SIZE];
  96. UBYTE cont_input[NAME_SIZE];
  97. UBYTE phon_input[PHONE_SIZE];
  98. UBYTE numb_input[NUMBER_SIZE];
  99.  
  100. UBYTE name_undo[NAME_SIZE];
  101. UBYTE add1_undo[ADDRESS_SIZE];
  102. UBYTE add2_undo[ADDRESS_SIZE];
  103. UBYTE add3_undo[ADDRESS_SIZE];
  104. UBYTE add4_undo[ADDRESS_SIZE];
  105. UBYTE cont_undo[NAME_SIZE];
  106. UBYTE phon_undo[PHONE_SIZE];
  107. UBYTE numb_undo[NUMBER_SIZE];
  108.  
  109. UBYTE name_dup[NAME_SIZE];
  110. UBYTE add1_dup[ADDRESS_SIZE];
  111. UBYTE add2_dup[ADDRESS_SIZE];
  112. UBYTE add3_dup[ADDRESS_SIZE];
  113. UBYTE add4_dup[ADDRESS_SIZE];
  114. UBYTE cont_dup[NAME_SIZE];
  115. UBYTE phon_dup[PHONE_SIZE];
  116. UBYTE numb_dup[NUMBER_SIZE];
  117.  
  118. /*** FIELDS ***/
  119.  
  120. #define NAME_FIELD 1
  121. #define ADD1_FIELD 2
  122. #define ADD2_FIELD 3
  123. #define ADD3_FIELD 4
  124. #define ADD4_FIELD 5
  125. #define CONT_FIELD 6
  126. #define PHON_FIELD 7
  127. #define NUMB_FIELD 8
  128.  
  129. struct FieldMask phon_mask = MASK_ENTIRE_DISABLED;
  130. struct FieldMask numb_mask = MASK_ENTIRE_DISABLED;
  131.  
  132. #define LEFT_EDGE  78
  133. #define RIGHT_EDGE 251
  134.  
  135. #define FIRST_FIELD name_field
  136. struct Field name_field = {
  137.   NULL, LATER, name_input, name_undo, name_dup, 1, 0, CON_PLAIN,
  138.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 28, 0, 0, NAME_SIZE, 0,
  139.   0, 0, 0, &name_text, &name_border1, NULL, NAME_FIELD, NULL, NULL, NULL
  140. };
  141. struct Field add1_field = {
  142.   &name_field, LATER, add1_input, add1_undo, add1_dup, 1, 0, CON_PLAIN,
  143.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 54, 0, 0, ADDRESS_SIZE, 0,
  144.   0, 0, 0, &addr_text, &addr_border1, NULL, ADD1_FIELD, NULL, NULL, NULL
  145. };
  146. struct Field add2_field = {
  147.   &add1_field, LATER, add2_input, add2_undo, add2_dup, 1, 0, CON_PLAIN,
  148.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 64, 0, 0, ADDRESS_SIZE, 0,
  149.   0, 0, 0, NULL, &name_border2, NULL, ADD2_FIELD, NULL, NULL, NULL
  150. };
  151. struct Field add3_field = {
  152.   &add2_field, LATER, add3_input, add3_undo, add3_dup, 1, 0, CON_PLAIN,
  153.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 74, 0, 0, ADDRESS_SIZE, 0,
  154.   0, 0, 0, NULL, &name_border2, NULL, ADD3_FIELD, NULL, NULL, NULL
  155. };
  156. struct Field add4_field = {
  157.   &add3_field, LATER, add4_input, add4_undo, add4_dup, 1, 0, CON_PLAIN,
  158.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 84, 0, 0, ADDRESS_SIZE, 0,
  159.   0, 0, 0, NULL, &name_border2, NULL, ADD4_FIELD, NULL, NULL, NULL
  160. };
  161. struct Field cont_field = {
  162.   &add4_field, LATER, cont_input, cont_undo, cont_dup, 1, 0, CON_PLAIN,
  163.   FIELD_ENABLED, NULL, NULL, LEFT_EDGE, 111, 0, 0, NAME_SIZE, 0,
  164.   0, 0, 0, &cont_text, &name_border1, NULL, CONT_FIELD, NULL, NULL, NULL
  165. };
  166. struct Field phon_field = {
  167.   &cont_field, LATER, phon_input, phon_undo, phon_dup, 1, 0, CON_PLAIN,
  168.   FIELD_ENABLED, &phon_mask, NULL, LEFT_EDGE, 138, 0, 0, PHONE_SIZE, 0,
  169.   0, 0, 0, &phon_text, &phon_border1, NULL, PHON_FIELD, NULL, NULL, NULL
  170. };
  171. struct Field numb_field = {
  172.   &phon_field, NULL, numb_input, numb_undo, numb_dup, 1, 0, CON_PLAIN,
  173.   FIELD_ENABLED, &numb_mask, NULL, RIGHT_EDGE, 138, 0, 0, NUMBER_SIZE, 0,
  174.   0, 0, 0, &numb_text, &numb_border1, NULL, NUMB_FIELD, NULL, NULL, NULL
  175. };
  176. #define FINAL_FIELD numb_field
  177.  
  178. struct  FieldHeader field_header = { INIT_FIELD_HEADER };
  179. #define CURRENT_FIELD field_header.CurrentField
  180. UBYTE   con_buffer[CONSOLE_BUFFER_SIZE];
  181.  
  182. /***************
  183. *  WINDOW TEXT
  184. ****************/
  185.  
  186. UBYTE add_string[]    = (STRPTR)"Mode: ADD   ";
  187. UBYTE change_string[] = (STRPTR)"Mode: CHANGE";
  188. UBYTE blank_string[]  = (STRPTR)"            ";
  189.  
  190. struct IntuiText mode_wtext = {
  191.   1, 0, JAM2, LEFT_EDGE, 160, NULL, LATER, NULL
  192. };
  193.  
  194. /*******************
  195. *  MENU STRUCTURES
  196. ********************/
  197.  
  198. #define MENU_TEXT 2,1,JAM1,4,1,NULL
  199. struct IntuiText cancel_mtext = { MENU_TEXT, (STRPTR)"Cancel Changes", NULL };
  200. struct IntuiText enter_mtext  = { MENU_TEXT, (STRPTR)"Enter Vendor", NULL };
  201.  
  202. #define ACTION_MENU   0
  203. #define ACTION_CANCEL 0
  204. #define ACTION_ENTER  1
  205. #define ACTION_WIDTH  160
  206.  
  207. #define MENUNUMBER(m,i,s) (m|(i<<5)|(s<<11))
  208. #define ACTION_ENTER_ITEM MENUNUMBER(ACTION_MENU,ACTION_ENTER,NULL)
  209.  
  210. struct MenuItem enter_item = {
  211.   NULL, 0, 10, ACTION_WIDTH, 10, HIGHCOMP | ITEMTEXT | COMMSEQ,
  212.   NULL, (APTR)&enter_mtext, NULL, 'E', NULL, MENUNULL
  213. };
  214. struct MenuItem cancel_item = {
  215.   &enter_item, 0, 0, ACTION_WIDTH, 10, HIGHCOMP | ITEMTEXT | COMMSEQ | ITEMENABLED,
  216.   NULL, (APTR)&cancel_mtext, NULL, 'C', NULL, MENUNULL
  217. };
  218. struct Menu action_menu = {
  219.   NULL, 0, 0, 56, 0, MENUENABLED, "Action", &cancel_item
  220. };
  221.  
  222. /************************
  223. *  NEW WINDOW STRUCTURE
  224. *************************/
  225.  
  226. struct NewWindow new_window = {
  227.   0, 0, 430, 200, 0, 1, CLOSEWINDOW | MENUPICK | MOUSEBUTTONS | REFRESHWINDOW,
  228.   ACTIVATE | SMART_REFRESH | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG |
  229.   WINDOWSIZING, NULL, NULL, (STRPTR)"SmartFields Example Program v1.0",
  230.   NULL, NULL, 50, 25, 430, 200, WBENCHSCREEN
  231. };
  232.  
  233. /********************
  234. *  GLOBAL VARIABLES
  235. *********************/
  236.  
  237. #define WAIT_FOR_INPUT Wait(1L<<field_header.ReadPort->mp_SigBit|1L<<win->UserPort->mp_SigBit)
  238. #define CONSOLE_INPUT  message=(struct Message *)GetMsg(field_header.ReadPort)
  239. #define WINDOW_INPUT   imessage=(struct IntuiMessage *)GetMsg(win->UserPort)
  240.  
  241. int working_ven = FALSE;  /* whether working on a vendor */
  242.  
  243. /**************************
  244. *  M A I N  P R O G R A M
  245. ***************************/
  246.  
  247. main()
  248. {
  249.   open_all();
  250.   initialize();
  251.   get_inputs();
  252. }
  253.  
  254. /**************
  255. *  ADD VENDOR
  256. ***************/
  257.  
  258. add_vendor()
  259. {
  260.   struct Vendor *new;
  261.  
  262.   /* dynamically allocate memory to hold new vendor structure */
  263.   if (!(new = (struct Vendor *) AllocMem( (long)sizeof(struct Vendor), MEMF_CLEAR )))
  264.     end_program( 1 );
  265.  
  266.   get_data( new );           /* returns pointer to Vendor struct in RAM */
  267.   new->Next = first_vendor;  /* point new vendor to top of list */
  268.   first_vendor = new;        /* new vendor becomes top of list */
  269.   new_vendor();              /* clear fields */
  270. }
  271.  
  272. /*****************
  273. *  CHANGE VENDOR
  274. ******************/
  275.  
  276. change_vendor()
  277. {
  278.   get_data( chnge_vendor );  /* write over old field values */
  279.   chnge_vendor = NULL;       /* no longer changing a vendor */
  280.   new_vendor();              /* clear fields */
  281. }
  282.  
  283. /************
  284. *  DO MENUS
  285. *************/
  286.  
  287. do_menus( menu, item, subitem )
  288.   int menu, item, subitem;
  289. {
  290.   switch (menu) {      /* this is set up for more than one menu */
  291.     case ACTION_MENU:
  292.       switch (item) {
  293.         case ACTION_ENTER:
  294.           if (chnge_vendor)
  295.             change_vendor();
  296.           else
  297.             add_vendor();
  298.           break;
  299.         case ACTION_CANCEL:
  300.           new_vendor();
  301.           break;
  302.         }
  303.       break;
  304.   } /* switch menu */
  305. }
  306.  
  307. /***************
  308. *  DRAW SCREEN
  309. ****************/
  310.  
  311. draw_screen()
  312. {
  313.   PrintIText( rp, &mode_wtext, 0L, 0L );
  314.   field_refresh( &field_header, &FIRST_FIELD, -1, CURRENT_FIELD );
  315. }
  316.  
  317. /***************
  318. *  END PROGRAM
  319. ****************/
  320.  
  321. end_program( return_code )
  322.   int return_code;
  323. {
  324.   struct Vendor *hold;
  325.  
  326.   /* deallocate memory used by vendor list */
  327.   while (first_vendor) {
  328.     hold = first_vendor->Next;
  329.     FreeMem( first_vendor, (long)sizeof(struct Vendor) );
  330.     first_vendor = hold;
  331.   }
  332.  
  333.   field_close( &field_header );
  334.  
  335.   if (win)           { ClearMenuStrip( win ); CloseWindow( win ); }
  336.   if (GfxBase)         CloseLibrary( GfxBase );
  337.   if (IntuitionBase)   CloseLibrary( IntuitionBase );
  338.  
  339.   exit( return_code );
  340. }
  341.  
  342. /************
  343. *  GET DATA
  344. *************/
  345.  
  346. get_data( new )
  347.   struct Vendor *new;
  348. {
  349.   strcpy( new->Name, name_input );
  350.   strcpy( new->Address[0], add1_input );
  351.   strcpy( new->Address[1], add2_input );
  352.   strcpy( new->Address[2], add3_input );
  353.   strcpy( new->Address[3], add4_input );
  354.   strcpy( new->Contact, cont_input );
  355.   to_phone( &(new->Telephone), phon_input );
  356.   new->Number = atoi( numb_input );
  357. }
  358.  
  359. /**************
  360. *  GET INPUTS
  361. ***************/
  362.  
  363. get_inputs()
  364. {
  365.   #define MENU_NUMBERS MENUNUM(imessage->Code),ITEMNUM(imessage->Code),SUBNUM(imessage->Code)
  366.   struct  IntuiMessage *imessage;
  367.   ULONG   key;
  368.   struct  Message *message;
  369.   struct  Field *where;
  370.  
  371.   FOREVER {
  372.     WAIT_FOR_INPUT;
  373.  
  374.     if (CONSOLE_INPUT) {
  375.       key = field_input( &field_header );
  376.       switch (key) {
  377.         case FIELD_SWALLOW:  break;
  378.         case FIELD_RETURN:
  379.         case FIELD_NEXT:     next_field(); break;
  380.         case FIELD_PREVIOUS: previous_field(); break;
  381.         case FIELD_FIRST:
  382.           if (working_ven)
  383.             field_goto( &field_header, &add1_field );
  384.           break;
  385.         case FIELD_FINAL:
  386.           if (working_ven)
  387.             field_goto( &field_header, &FINAL_FIELD );
  388.           break;
  389.       } /* switch key */
  390.     }   /* if keyboard input */
  391.  
  392.     while (WINDOW_INPUT) {
  393.       switch (imessage->Class) {
  394.         case MENUPICK:
  395.           if (MENUNUM( imessage->Code ) != MENUNULL)
  396.             do_menus( MENU_NUMBERS );
  397.           break;
  398.         case MOUSEBUTTONS:
  399.           if (imessage->Code == LEFT_MOUSE_BUTTON)
  400.             if (where = field_click( &field_header,
  401.                         imessage->MouseX, imessage->MouseY ))
  402.               if (working_ven ||
  403.                 (!working_ven && where->FieldID == NAME_FIELD)) {
  404.                 where->BufferPos = field_header.BufferPos;
  405.                 field_goto( &field_header, where );
  406.               }
  407.           break;
  408.         case REFRESHWINDOW:
  409.           draw_screen();
  410.           BeginRefresh( win );
  411.           EndRefresh( win, TRUE );
  412.           break;
  413.         case CLOSEWINDOW:
  414.           end_program( 0 );
  415.           break;
  416.       } /* switch */
  417.       ReplyMsg( imessage );
  418.     } /* while window messages */
  419.   }   /* forever */
  420. }
  421.  
  422. /**************
  423. *  INITIALIZE
  424. ***************/
  425.  
  426. initialize()
  427. {
  428.   mask_chars( &phon_mask, "0123456789()-/ ", MASK_ENABLE );
  429.   mask_range( &numb_mask, '0', '9', MASK_ENABLE );
  430.   draw_screen();
  431.   SetMenuStrip( win, &action_menu );
  432. }
  433.  
  434. /************
  435. *  OPEN ALL
  436. *************/
  437.  
  438. open_all()
  439. {
  440.   int error;
  441.  
  442.   if (!(IntuitionBase = (struct IntuitionBase *)
  443.         OpenLibrary( "intuition.library", LIBRARY_VERSION )))
  444.     end_program( 0x0100 );
  445.   if (!(GfxBase = (struct GfxBase *) OpenLibrary( "graphics.library", 0L )))
  446.     end_program( 0x0101 );
  447.  
  448.   if (!(win = OpenWindow( &new_window )))
  449.     end_program( 0x0102 );
  450.   rp = win->RPort;
  451.  
  452.   if (error = field_open( win, &field_header, &FIRST_FIELD, &FINAL_FIELD, con_buffer ))
  453.     end_program( error );
  454. }
  455.  
  456. /**************
  457. *  NEW VENDOR
  458. ***************/
  459.  
  460. new_vendor()
  461. {
  462.   field_clear( &field_header, &FIRST_FIELD, -1, &FIRST_FIELD );
  463.   OffMenu( win, ACTION_ENTER_ITEM );
  464.   working_ven = FALSE;
  465.   mode_wtext.IText = (STRPTR)blank_string;
  466.   PrintIText( rp, &mode_wtext, 0L, 0L );
  467. }
  468.  
  469. /**************
  470. *  NEXT FIELD
  471. ***************/
  472.  
  473. next_field()
  474. {
  475.   switch (CURRENT_FIELD->FieldID) {
  476.     case NAME_FIELD:
  477.       vendor_lookup();
  478.       break;
  479.     case ADD1_FIELD:
  480.       if (add1_input[0])
  481.         field_goto( &field_header, &add2_field );
  482.       else
  483.         field_goto( &field_header, &cont_field );
  484.       break;
  485.     case ADD2_FIELD:
  486.       if (add2_input[0])
  487.         field_goto( &field_header, &add3_field );
  488.       else
  489.         field_goto( &field_header, &cont_field );
  490.       break;
  491.     case ADD3_FIELD:
  492.       if (add3_input[0])
  493.         field_goto( &field_header, &add4_field );
  494.       else
  495.         field_goto( &field_header, &cont_field );
  496.       break;
  497.     case PHON_FIELD:
  498.       vendor_phone();
  499.       break;
  500.     case NUMB_FIELD:
  501.       vendor_number();
  502.       break;
  503.     default:
  504.       field_goto( &field_header, CURRENT_FIELD->NextField );
  505.       break;
  506.   } /* switch current field */
  507. }
  508.  
  509. /************
  510. *  PUT DATA
  511. *************/
  512.  
  513. put_data( old )
  514.   struct Vendor *old;
  515. {
  516.   strcpy( name_input, old->Name );
  517.   strcpy( add1_input, old->Address[0] );
  518.   strcpy( add2_input, old->Address[1] );
  519.   strcpy( add3_input, old->Address[2] );
  520.   strcpy( add4_input, old->Address[3] );
  521.   strcpy( cont_input, old->Contact );
  522.   sprintf( phon_input, "(%03d) %03d-%04d",
  523.            old->Telephone.AreaCode, old->Telephone.Prefix, old->Telephone.Suffix );
  524.   sprintf( numb_input, "%04d", old->Number );
  525. }
  526.  
  527. /******************
  528. *  PREVIOUS FIELD
  529. *******************/
  530.  
  531. previous_field()
  532. {
  533.   if (CURRENT_FIELD->FieldID == CONT_FIELD) {
  534.          if (add4_input[0]) field_goto( &field_header, &add4_field );
  535.     else if (add3_input[0]) field_goto( &field_header, &add3_field );
  536.     else if (add2_input[0]) field_goto( &field_header, &add2_field );
  537.     else                    field_goto( &field_header, &add1_field );
  538.   }
  539.   else if (CURRENT_FIELD->FieldID == NAME_FIELD);
  540.   else if (CURRENT_FIELD->FieldID == ADD1_FIELD)
  541.     field_goto( &field_header, &FINAL_FIELD );
  542.   else
  543.     field_goto( &field_header, CURRENT_FIELD->PrevField );
  544. }
  545.  
  546. /************
  547. *  TO PHONE
  548. *************/
  549.  
  550. to_phone( p, s )
  551.   struct Phone *p;
  552.   char *s;
  553. {
  554.   int i;
  555.  
  556.   p->AreaCode = p->Prefix = p->Suffix = 0;
  557.  
  558.   for (i = 0; i < 3 && *s; s++)
  559.     if (*s >= '0' && *s <= '9')
  560.       { p->AreaCode = p->AreaCode * 10 + *s - '0'; i++; }
  561.   for (i = 0; i < 3 && *s; s++)
  562.     if (*s >= '0' && *s <= '9')
  563.       { p->Prefix = p->Prefix * 10 + *s - '0'; i++; }
  564.   for (i = 0; i < 4 && *s; s++)
  565.     if (*s >= '0' && *s <= '9')
  566.       { p->Suffix = p->Suffix * 10 + *s - '0'; i++; }
  567. }
  568.  
  569. /*****************
  570. *  VENDOR LOOKUP
  571. ******************/
  572.  
  573. vendor_lookup()
  574. {
  575.   struct Vendor *next;
  576.  
  577.   next = first_vendor;
  578.   while (next && strcmp( name_input, next->Name ))
  579.     next = next->Next;
  580.  
  581.   chnge_vendor = next;
  582.   if (chnge_vendor) {
  583.     put_data( chnge_vendor );
  584.     field_redisplay( &field_header, &add1_field, -1 );
  585.     mode_wtext.IText = (STRPTR)change_string;
  586.   }
  587.   else
  588.     mode_wtext.IText = (STRPTR)add_string;
  589.   PrintIText( rp, &mode_wtext, 0L, 0L );
  590.   OnMenu( win, ACTION_ENTER_ITEM );
  591.   working_ven = TRUE;
  592.   field_goto( &field_header, &add1_field );
  593. }
  594.  
  595. /*****************
  596. *  VENDOR NUMBER
  597. ******************/
  598.  
  599. vendor_number()
  600. {
  601.   int number, atoi();
  602.  
  603.   number = atoi( numb_input );
  604.   sprintf( numb_input, "%04d", number );
  605.   field_redisplay( &field_header, &numb_field, 1, &add1_field );
  606. }
  607.  
  608. /****************
  609. *  VENDOR PHONE
  610. *****************/
  611.  
  612. vendor_phone()
  613. {
  614.   struct Phone phone;
  615.  
  616.   to_phone( &phone, phon_input );
  617.   sprintf( phon_input, "(%03d) %03d-%04d",
  618.            phone.AreaCode, phone.Prefix, phone.Suffix );
  619.   field_redisplay( &field_header, &phon_field, 1, &numb_field );
  620. }
  621.