Example #1
0
File: Code.c Project: muddana/tws
void InitializeCode(int argc, char *argv[])
{
    int index;

    Frames = AllocateStack(20);
    LabelStack = AllocateStack(500);
    OpStack = AllocateStack(500);
    Op1Stack = AllocateStack(500);
    Op2Stack = AllocateStack(500);
    index = System_Flag ("-trace", argc, argv);

    if (index)
    {
        TraceSpecified = true;
        TraceFileName = System_Argument
                        ("-trace", "_TRACE", argc, argv);
        TraceFile = Open_File (TraceFileName, "w");
#if 1
        fprintf (TraceFile,"Hello.\n");
        rewind (TraceFile);
#endif
    }

    else
        TraceSpecified = false;
}
Example #2
0
/** Get the width of a string. */
int GetStringWidth(FontType ft, const char *str)
{
#ifdef USE_XFT
   XGlyphInfo extents;
#endif
#ifdef USE_FRIBIDI
   FriBidiChar *temp_i;
   FriBidiChar *temp_o;
   FriBidiParType type = FRIBIDI_PAR_ON;
   int unicodeLength;
#endif
   int len;
   char *output;
   int result;
   char *utf8String;

   /* Convert to UTF-8 if necessary. */
   utf8String = GetUTF8String(str);

   /* Length of the UTF-8 string. */
   len = strlen(utf8String);

   /* Apply the bidi algorithm if requested. */
#ifdef USE_FRIBIDI
   temp_i = AllocateStack((len + 1) * sizeof(FriBidiChar));
   temp_o = AllocateStack((len + 1) * sizeof(FriBidiChar));
   unicodeLength = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8,
                                              utf8String, len, temp_i);
   fribidi_log2vis(temp_i, unicodeLength, &type, temp_o, NULL, NULL, NULL);
   output = AllocateStack(4 * len + 1);
   fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, temp_o, unicodeLength,
                              (char*)output);
   len = strlen(output);
#else
   output = utf8String;
#endif

   /* Get the width of the string. */
#ifdef USE_XFT
   JXftTextExtentsUtf8(display, fonts[ft], (const unsigned char*)output,
                       len, &extents);
   result = extents.xOff;
#else
   result = XTextWidth(fonts[ft], output, len);
#endif

   /* Clean up. */
#ifdef USE_FRIBIDI
   ReleaseStack(temp_i);
   ReleaseStack(temp_o);
   ReleaseStack(output);
#endif
   ReleaseUTF8String(utf8String);

   return result;
}
Example #3
0
/** Load a gradient background. */
void LoadGradientBackground(BackgroundNode *bp) {

   XColor color1;
   XColor color2;
   char *temp;
   char *sep;
   int len;

   sep = strchr(bp->value, ':');
   if(!sep) {
      bp->pixmap = None;
      bp->window = None;
      return;
   }

   /* Get the first color. */
   len = (int)(sep - bp->value);
   temp = AllocateStack(len + 1);
   memcpy(temp, bp->value, len);
   temp[len] = 0;
   ParseColor(temp, &color1);
   ReleaseStack(temp);

   /* Get the second color. */
   len = strlen(sep + 1);
   temp = AllocateStack(len + 1);
   memcpy(temp, sep + 1, len);
   temp[len] = 0;
   ParseColor(temp, &color2);
   ReleaseStack(temp);

   /* Create the window. */
   bp->window = JXCreateSimpleWindow(display, rootWindow, 0, 0,
                                     rootWidth, rootHeight, 0, 0, 0);

   bp->pixmap = JXCreatePixmap(display, bp->window,
                               rootWidth, rootHeight, rootDepth);

   if(color1.pixel == color2.pixel) {
      JXSetForeground(display, rootGC, color1.pixel);
      JXFillRectangle(display, bp->pixmap, rootGC,
                      0, 0, rootWidth, rootHeight);
   } else {
      DrawHorizontalGradient(bp->pixmap, rootGC,
         color1.pixel, color2.pixel, 0, 0, rootWidth, rootHeight);
   }

}
Example #4
0
File: lex.c Project: GustavoMOG/JWM
/** Parse an entity reference.
 * The entity value is returned in ch and the length of the entity
 * is returned as the value of the function.
 */
int ParseEntity(const char *entity, char *ch, const char *file, int line) {
   char *temp;
   int x;

   if(!strncmp(""", entity, 6)) {
      *ch = '\"';
      return 6;
   } else if(!strncmp("<", entity, 4)) {
      *ch = '<';
      return 4;
   } else if(!strncmp("&gt;", entity, 4)) {
      *ch = '>';
      return 4;
   } else if(!strncmp("&amp;", entity, 5)) {
      *ch = '&';
      return 5;
   } else if(!strncmp("&apos;", entity, 6)) {
      *ch = '\'';
      return 6;
   } else {
      for(x = 0; entity[x]; x++) {
         if(entity[x] == ';') {
            break;
         }
      }
      temp = AllocateStack(x + 2);
      strncpy(temp, entity, x + 1);
      temp[x + 1] = 0;
      Warning("%s[%d]: invalid entity: \"%.8s\"", file, line, temp);
      ReleaseStack(temp);
      *ch = '&';
      return 1;
   }
}
Example #5
0
File: place.c Project: KarlGodt/jwm
/** Set _NET_WORKAREA. */
void SetWorkarea(void)
{
   BoundingBox box;
   unsigned long *array;
   unsigned int count;
   int x;

   count = 4 * settings.desktopCount * sizeof(unsigned long);
   array = (unsigned long*)AllocateStack(count);

   box.x = 0;
   box.y = 0;
   box.width = rootWidth;
   box.height = rootHeight;

   SubtractTrayBounds(GetTrays(), &box, LAYER_NORMAL);
   SubtractStrutBounds(&box, NULL);

   for(x = 0; x < settings.desktopCount; x++) {
      array[x * 4 + 0] = box.x;
      array[x * 4 + 1] = box.y;
      array[x * 4 + 2] = box.width;
      array[x * 4 + 3] = box.height;
   }
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_WORKAREA],
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*)array, settings.desktopCount * 4);

   ReleaseStack(array);

}
Example #6
0
/** Parse a color which may be a gradient. */
void ParseGradient(const char *value, ColorType a, ColorType b)
{

   const char *sep;
   char *temp;
   int len;

   /* Find the separator. */
   sep = strchr(value, ':');

   if(!sep) {

      /* Only one color given - use the same color for both. */
      SetColor(a, value);
      SetColor(b, value);

   } else {

      /* Two colors. */

      /* Get the first color. */
      len = (int)(sep - value);
      temp = AllocateStack(len + 1);
      memcpy(temp, value, len);
      temp[len] = 0;
      SetColor(a, temp);
      ReleaseStack(temp);

      /* Get the second color. */
      len = strlen(sep + 1);
      temp = AllocateStack(len + 1);
      memcpy(temp, sep + 1, len);
      temp[len] = 0;
      SetColor(b, temp);
      ReleaseStack(temp);

   }

}
Example #7
0
/** Helper for loading icons by name. */
IconNode *LoadNamedIconHelper(const char *name, const char *path, char save)
{

   IconNode *result;
   char *temp;

   temp = AllocateStack(strlen(name) + strlen(path) + 1);
   strcpy(temp, path);
   strcat(temp, name);
   result = CreateIconFromFile(temp, save);
   ReleaseStack(temp);

   return result;

}
Example #8
0
/** Maintain the _NET_CLIENT_LIST[_STACKING] properties on the root. */
void UpdateNetClientList(void)
{
   TaskEntry *tp;
   ClientNode *client;
   Window *windows;
   unsigned int count;
   int layer;

   /* Determine how much we need to allocate. */
   if(clientCount == 0) {
      windows = NULL;
   } else {
      windows = AllocateStack(clientCount * sizeof(Window));
   }

   /* Set _NET_CLIENT_LIST */
   count = 0;
   for(tp = taskEntries; tp; tp = tp->next) {
      ClientEntry *cp;
      for(cp = tp->clients; cp; cp = cp->next) {
         windows[count] = cp->client->window;
         count += 1;
      }
   }
   Assert(count <= clientCount);
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_CLIENT_LIST],
                    XA_WINDOW, 32, PropModeReplace,
                    (unsigned char*)windows, count);

   /* Set _NET_CLIENT_LIST_STACKING */
   count = 0;
   for(layer = FIRST_LAYER; layer <= LAST_LAYER; layer++) {
      for(client = nodes[layer]; client; client = client->next) {
         windows[count] = client->window;
         count += 1;
      }
   }
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_CLIENT_LIST_STACKING],
                    XA_WINDOW, 32, PropModeReplace,
                    (unsigned char*)windows, count);

   if(windows != NULL) {
      ReleaseStack(windows);
   }
   
}
Example #9
0
File: Code.c Project: muddana/tws
void ItoC(int N)
{
    Stack Temp;
    Temp = AllocateStack(50);

    if (N == 0)
        AdvanceOnCharacter ('0');

    else
    {
        while (N > 0)
        {
            Push (Temp, (N % 10) + 48);
            N /= 10;
        }
        while (!(IsEmpty (Temp)))
            AdvanceOnCharacter ((char)(Pop(Temp)));
    }
}
Example #10
0
File: icon.c Project: Miteam/jwm
/** Helper for loading icons by name. */
IconNode *LoadNamedIconHelper(const char *name, const char *path,
                              char save, char preserveAspect)
{
   IconNode *result;
   char *temp;
   const unsigned nameLength = strlen(name);
   const unsigned pathLength = strlen(path);
   unsigned i, has_extension = 0;
   ImageNode *image;

   temp = AllocateStack(nameLength + pathLength + MAX_EXTENSION_LENGTH + 1);
   memcpy(&temp[0], path, pathLength);
   memcpy(&temp[pathLength], name, nameLength+1);

   result = NULL;
   size_t templen = pathLength + nameLength;
   for(i = 1; i < EXTENSION_COUNT; i++){
      if (!strcmp(ICON_EXTENSIONS[i],temp+templen-strlen(ICON_EXTENSIONS[i]))){ 
         has_extension = 1;
         break; 
      }
   }
   if (has_extension){
      image = LoadImage(temp, 0, 0, 1);
   }else for(i = 0; i < EXTENSION_COUNT; i++) {
      const unsigned len = strlen(ICON_EXTENSIONS[i]);
      memcpy(&temp[templen], ICON_EXTENSIONS[i], len + 1);
      image = LoadImage(temp, 0, 0, 1);
      if (image) break;
   }
   if (image) {
      result = CreateIcon(image);
      result->preserveAspect = preserveAspect;
      result->name = CopyString(temp);
      if (save) InsertIcon(result);
      DestroyImage(image);
   }
   ReleaseStack(temp);

   return result;
}
Example #11
0
/** Startup the dock. */
void StartupDock(void)
{

   char *selectionName;

   if(!dock) {
      /* No dock has been requested. */
      return;
   }

   if(dock->window == None) {

      /* No dock yet. */

      /* Get the selection atom. */
      selectionName = AllocateStack(sizeof(BASE_SELECTION_NAME));
      snprintf(selectionName, sizeof(BASE_SELECTION_NAME),
               BASE_SELECTION_NAME, rootScreen);
      dockAtom = JXInternAtom(display, selectionName, False);
      ReleaseStack(selectionName);

      /* The location and size of the window doesn't matter here. */
      dock->window = JXCreateSimpleWindow(display, rootWindow,
         /* x, y, width, height */ 0, 0, 1, 1,
         /* border_size, border_color */ 0, 0,
         /* background */ colors[COLOR_TRAY_BG2]);
      JXSelectInput(display, dock->window,
           SubstructureNotifyMask
         | SubstructureRedirectMask
         | EnterWindowMask
         | PointerMotionMask | PointerMotionHintMask);

   }
   dock->cp->window = dock->window;

}
Example #12
0
/** Raise all clients in a group and focus the top-most. */
void FocusGroup(const TaskEntry *tp)
{
   const char *className = tp->clients->client->className;
   ClientNode **toRestore;
   const ClientEntry *cp;
   unsigned restoreCount;
   int i;
   char shouldSwitch;

   /* If there is no class name, then there will only be one client. */
   if(!className || !settings.groupTasks) {
      if(!(tp->clients->client->state.status & STAT_STICKY)) {
         ChangeDesktop(tp->clients->client->state.desktop);
      }
      RestoreClient(tp->clients->client, 1);
      FocusClient(tp->clients->client);
      return;
   }

   /* If there is a client in the group on this desktop,
    * then we remain on the same desktop. */
   shouldSwitch = 1;
   for(cp = tp->clients; cp; cp = cp->next) {
      if(IsClientOnCurrentDesktop(cp->client)) {
         shouldSwitch = 0;
         break;
      }
   }

   /* Switch to the desktop of the top-most client in the group. */
   if(shouldSwitch) {
      for(i = 0; i < LAYER_COUNT; i++) {
         ClientNode *np;
         for(np = nodes[i]; np; np = np->next) {
            if(np->className && !strcmp(np->className, className)) {
               if(ShouldFocus(np, 0)) {
                  if(!(np->state.status & STAT_STICKY)) {
                     ChangeDesktop(np->state.desktop);
                  }
                  break;
               }
            }
         }
      }
   }

   /* Build up the list of clients to restore in correct order. */
   toRestore = AllocateStack(sizeof(ClientNode*) * clientCount);
   restoreCount = 0;
   for(i = 0; i < LAYER_COUNT; i++) {
      ClientNode *np;
      for(np = nodes[i]; np; np = np->next) {
         if(!ShouldFocus(np, 1)) {
            continue;
         }
         if(np->className && !strcmp(np->className, className)) {
            toRestore[restoreCount] = np;
            restoreCount += 1;
         }
      }
   }
   Assert(restoreCount <= clientCount);
   for(i = restoreCount - 1; i >= 0; i--) {
      RestoreClient(toRestore[i], 1);
   }
   for(i = 0; i < restoreCount; i++) {
      if(toRestore[i]->state.status & (STAT_CANFOCUS | STAT_TAKEFOCUS)) {
         FocusClient(toRestore[i]);
         break;
      }
   }
   ReleaseStack(toRestore);
}
Example #13
0
/** Display a string. */
void RenderString(Drawable d, FontType font, ColorType color,
                  int x, int y, int width, const char *str)
{

#ifdef USE_ICONV
   static char isUTF8 = -1;
#endif
   XRectangle rect;
   Region renderRegion;
   int len;
   char *output;
#ifdef USE_FRIBIDI
   FriBidiChar *temp_i;
   FriBidiChar *temp_o;
   FriBidiParType type = FRIBIDI_PAR_ON;
   int unicodeLength;
#endif
#ifdef USE_XFT
   XGlyphInfo extents;
#endif
   char *utf8String;

   /* Early return for empty strings. */
   if(!str || !str[0]) {
      return;
   }

   /* Convert to UTF-8 if necessary. */
   utf8String = GetUTF8String(str);

   /* Get the length of the UTF-8 string. */
   len = strlen(utf8String);

   /* Apply the bidi algorithm if requested. */
#ifdef USE_FRIBIDI
   temp_i = AllocateStack((len + 1) * sizeof(FriBidiChar));
   temp_o = AllocateStack((len + 1) * sizeof(FriBidiChar));
   unicodeLength = fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8,
                                              utf8String, len, temp_i);
   fribidi_log2vis(temp_i, unicodeLength, &type, temp_o, NULL, NULL, NULL);
   output = AllocateStack(4 * len + 1);
   fribidi_unicode_to_charset(FRIBIDI_CHAR_SET_UTF8, temp_o, unicodeLength,
                              (char*)output);
   len = strlen(output);
#else
   output = utf8String;
#endif

   /* Get the bounds for the string based on the specified width. */
   rect.x = x;
   rect.y = y;
   rect.height = GetStringHeight(font);
#ifdef USE_XFT
   JXftTextExtentsUtf8(display, fonts[font], (const unsigned char*)output,
                       len, &extents);
   rect.width = extents.xOff;
#else
   rect.width = XTextWidth(fonts[font], output, len);
#endif
   rect.width = Min(rect.width, width) + 2;

   /* Combine the width bounds with the region to use. */
   renderRegion = XCreateRegion();
   XUnionRectWithRegion(&rect, renderRegion, renderRegion);

   /* Display the string. */
#ifdef USE_XFT
   JXftDrawChange(xd, d);
   JXftDrawSetClip(xd, renderRegion);
   JXftDrawStringUtf8(xd, GetXftColor(color), fonts[font],
                      x, y + fonts[font]->ascent,
                      (const unsigned char*)output, len);
   JXftDrawChange(xd, rootWindow);
#else
   JXSetForeground(display, fontGC, colors[color]);
   JXSetRegion(display, fontGC, renderRegion);
   JXSetFont(display, fontGC, fonts[font]->fid);
   JXDrawString(display, d, fontGC, x, y + fonts[font]->ascent, output, len);
#endif

   /* Free any memory used for UTF conversion. */
#ifdef USE_FRIBIDI
   ReleaseStack(temp_i);
   ReleaseStack(temp_o);
   ReleaseStack(output);
#endif
   ReleaseUTF8String(utf8String);

   XDestroyRegion(renderRegion);

}
Example #14
0
short ResolveReferences(void)
{
   Stack Ref;
   Instruction I,j;
   int Labelref;

   Ref = AllocateStack (200);

   for (I = 1; I <= SizeOf (Labels); I++) 
   {
      if (LabelOf(I) != UndefinedString)
         if (Element(Ref,LabelOf(I)) == UndefinedString)
            Assign(Ref,LabelOf(I),I);
         else 
         {
            fprintf(output,"<<< MACHINE ERROR >>>: ");
            fprintf(output,"DUPLICATE INSTRUCTION WITH LABEL ");
    	    fprintf(output," %d **",LabelOf(I));
    	    WriteString(output,LabelOf(I));
            fprintf(output,"**: LINE %1d \n",I);
            return(false);
         }
   }

   for (I = 1; I <= SizeOf(Labels); I++) 
   {
      if (OpCodeOf(I) == GOTOOP || OpCodeOf(I) == CONDOP ||
                                   OpCodeOf(I) == CODEOP) 
      {
         Labelref = Element(Ref,Operand1Of(I));
         if (Labelref == 0) 
         {
            fprintf(output,"<<< MACHINE ERROR >>>: ");
            fprintf(output,"NO INSTRUCTION WITH LABEL ");
    	    fprintf(TraceFile," %d ",Operand1Of(I));
            fprintf(output,"': LINE %1d \n",I);
            return(false);
         }
         
         Assign ( Ref, Operand1Of(I), 1000000+Labelref );
         Assign ( Operand1, I, Labelref % 1000000);
      }

      if (OpCodeOf(I) == CONDOP) 
      {
         Labelref = Element(Ref,Operand2Of(I));
         if (Labelref == 0) 
         {
            fprintf(output,"<<< MACHINE ERROR >>>: ");
            fprintf(output,"NO INSTRUCTION WITH LABEL ");
    	    fprintf(output," %d ",Operand2Of(I));
            fprintf(output,"': LINE %1d \n",I);
            return(false);
         }
         Assign (Ref, Operand2Of(I), 1000000+Labelref );
         Assign (Operand2, I, Labelref % 1000000);
      }

      if (OpCodeOf(I) == LITOP || OpCodeOf(I) ==  LLVOP
            || OpCodeOf(I) ==  LGVOP  || OpCodeOf(I) == SLVOP
            || OpCodeOf(I) ==  SGVOP  || OpCodeOf(I) == LLIVOP
            || OpCodeOf(I) ==  LGIVOP || OpCodeOf(I) == SLIVOP
            || OpCodeOf(I) ==  SGIVOP || OpCodeOf(I) == LLAOP
            || OpCodeOf(I) ==  LGAOP  || OpCodeOf(I) == LUVOP
            || OpCodeOf(I) ==  SUVOP  || OpCodeOf(I) == POPOP
            || OpCodeOf(I) ==  CALLOP || OpCodeOf(I) == RTNOP)
          Assign (Operand1,I,StringToInteger(Operand1Of(I)));

       if (OpCodeOf(I) == LUVOP || OpCodeOf(I) == SUVOP )
          Assign(Operand2,I,StringToInteger(Operand2Of(I)));
   }

   for (I =1; I <= TextSize(); I++ ) 
   {
      if (Element(Ref,I) != 0)
         if (Element(Ref,I) < 1000000) 
         {
            fprintf(output,"<<< MACHINE ERROR >>>: ");
            fprintf(output,"NO REFERENCE TO INSTRUCTION WITH LABEL ");
	    fprintf(output,"%d ", I);
            fprintf(output,": LINE %1d \n",I);
            fprintf(output,"Element(Ref)= %d\n",Element(Ref,I));
            PrintAllStrings(stdout);
            return(false);
	 }
   }

   return(true);
}
Example #15
0
File: image.c Project: Israel-/jwm
ImageNode *LoadPNGImage(const char *fileName, int rwidth, int rheight,
                        char preserveAspect)
{

   static ImageNode *result;
   static FILE *fd;
   static unsigned char **rows;
   static png_structp pngData;
   static png_infop pngInfo;
   static png_infop pngEndInfo;

   unsigned char header[8];
   unsigned long rowBytes;
   int bitDepth, colorType;
   unsigned int x, y;
   png_uint_32 width;
   png_uint_32 height;

   Assert(fileName);

   result = NULL;
   fd = NULL;
   rows = NULL;
   pngData = NULL;
   pngInfo = NULL;
   pngEndInfo = NULL;

   fd = fopen(fileName, "rb");
   if(!fd) {
      return NULL;
   }

   x = fread(header, 1, sizeof(header), fd);
   if(x != sizeof(header) || png_sig_cmp(header, 0, sizeof(header))) {
      fclose(fd);
      return NULL;
   }

   pngData = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
   if(JUNLIKELY(!pngData)) {
      fclose(fd);
      Warning(_("could not create read struct for PNG image: %s"), fileName);
      return NULL;
   }

   if(JUNLIKELY(setjmp(png_jmpbuf(pngData)))) {
      png_destroy_read_struct(&pngData, &pngInfo, &pngEndInfo);
      if(fd) {
         fclose(fd);
      }
      if(rows) {
         ReleaseStack(rows);
      }
      DestroyImage(result);
      Warning(_("error reading PNG image: %s"), fileName);
      return NULL;
   }

   pngInfo = png_create_info_struct(pngData);
   if(JUNLIKELY(!pngInfo)) {
      png_destroy_read_struct(&pngData, NULL, NULL);
      fclose(fd);
      Warning(_("could not create info struct for PNG image: %s"), fileName);
      return NULL;
   }

   pngEndInfo = png_create_info_struct(pngData);
   if(JUNLIKELY(!pngEndInfo)) {
      png_destroy_read_struct(&pngData, &pngInfo, NULL);
      fclose(fd);
      Warning("could not create end info struct for PNG image: %s", fileName);
      return NULL;
   }

   png_init_io(pngData, fd);
   png_set_sig_bytes(pngData, sizeof(header));

   png_read_info(pngData, pngInfo);

   png_get_IHDR(pngData, pngInfo, &width, &height,
                &bitDepth, &colorType, NULL, NULL, NULL);
   result = CreateImage(width, height, 0);

   png_set_expand(pngData);

   if(bitDepth == 16) {
      png_set_strip_16(pngData);
   } else if(bitDepth < 8) {
      png_set_packing(pngData);
   }

   png_set_swap_alpha(pngData);
   png_set_filler(pngData, 0xFF, PNG_FILLER_BEFORE);

   if(colorType == PNG_COLOR_TYPE_GRAY
      || colorType == PNG_COLOR_TYPE_GRAY_ALPHA) {
      png_set_gray_to_rgb(pngData);
   }

   png_read_update_info(pngData, pngInfo);

   rowBytes = png_get_rowbytes(pngData, pngInfo);
   rows = AllocateStack(result->height * sizeof(result->data));
   y = 0;
   for(x = 0; x < result->height; x++) {
      rows[x] = &result->data[y];
      y += rowBytes;
   }

   png_read_image(pngData, rows);

   png_read_end(pngData, pngInfo);
   png_destroy_read_struct(&pngData, &pngInfo, &pngEndInfo);

   fclose(fd);

   ReleaseStack(rows);
   rows = NULL;

   return result;

}
Example #16
0
void InitializeTreeModule(void) 
{
   Tree = AllocateStack(3000);
   TreeOrchard = AllocateStack(500);
}
Example #17
0
int main() 
{

    rtx_dbug_outs((CHAR *)"rtx: Entering main()\r\n");

    /* get the third party test proc initialization info */
    __REGISTER_TEST_PROCS_ENTRY__();
	
	rtxEnd = &(_end);
	m_nextPid = 1;
	
	// Setting up trap # 0
    // Load vector table for trap # 0
    asm( "move.l #asm_trap_entry, %d0" );
    asm( "move.l %d0, 0x10000080" );
	
	#ifdef _DEBUG_
	rtx_dbug_outs( (CHAR*)"Start\r\n" );
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address before PCBS\r\n" );
	#endif
	// Allocate and initialize pcbs and its stacks
	//rtxProcess* pcbs = AllocatePCBs( MAX_NUMPROCS );
	pcbs = AllocatePCBs( MAX_NUMPROCS );
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after PCBS\r\n" );
	#endif
	// Initialize the process manager
	rtxProcMan = InitProcessManager();
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after Procman?\r\n" );
	#endif
	// Create the null process
	rtxProcess* nullProc = CreateProcess( pcbs, null_process, AllocateStack(256), 0, NULLPROCPRIORITY );
	nullProc->status = READY;
	rtxProcMan->nullProc = nullProc;
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after nullproc?\r\n" );
	#endif
	//Create the Processes
	rtxProcess* cp2 = CreateProcess( pcbs, &keyboardCommandDecoder, AllocateStack(2048), KCDPID, MEDIUM );
	rtxProcess* cp1 = CreateProcess( pcbs, &CRTDisplay, AllocateStack(512), CRTPID, MEDIUM);
	rtxProcess* cp3 = CreateProcess( pcbs, &UART_PROCESS, AllocateStack(512), UARTPID, HIGH );
	
	CRT = cp1;
   	KCD = cp2;
	UART = cp3;	
	
	// Creating and enqueueing the test processes
	for( m_nextPid = 1 ; m_nextPid < (NUM_TEST_PROCS + 1); m_nextPid++ ){
		EnqueueProcess( 
			rtxProcMan, 
			CreateProcess( 
				pcbs, 
				g_test_proc[m_nextPid-1].entry, 
				AllocateStack( g_test_proc[m_nextPid-1].sz_stack ),
				g_test_proc[m_nextPid-1].pid,
				g_test_proc[m_nextPid-1].priority
			),
			READYQUEUE
		);
	}
	
	// Set the next pid to be 1 greater than last test proc pid
	//m_nextPid = g_test_proc[m_nextPid-2].pid + 1;
	
	// Initialize some of our own system processes
	
	EnqueueProcess( rtxProcMan, cp2,READYQUEUE);
	EnqueueProcess( rtxProcMan, cp1,READYQUEUE );

	
	
	// Initialize the scheduler
	InitializeScheduler( (ProcessManager*)(rtxProcMan) );
	
	// Time to allocate and initialize free memory
	UINT32 numTotalBlocks = ( (UINT32)0x10200000 - (UINT32)malloc(0)) / sizeof(MemoryBlock);
	
	//numTotalBlocks = 1;
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address At start of freemem\r\n" );
	#endif
	// Allocate free memory and create memory table
	MemoryBlock* memstart = AllocateFreeMemory( sizeof(MemoryBlock), numTotalBlocks );
	#ifdef _DEBUG_
	WriteHex((int)malloc(0) );
	rtx_dbug_outs( (CHAR*)" Address after freemem?\r\n" );
	rtx_dbug_outs( (CHAR*)"Allocated Free Memory\r\n" );
	#endif
	InitMemQueue( &freeMemory );
	InitializeMemory( &freeMemory, memstart, numTotalBlocks );
	#ifdef _DEBUG_	
    rtx_dbug_outs( (CHAR*)"Number of free memory blocks: " );
    WriteNumber( freeMemory.count );	
    WriteLine();

	rtx_dbug_outs( (CHAR*)"Initialized Free Memory\r\n" );
	#endif
	
	UINT32 mask;
	
	//disable all interupts 
	asm( "move.w #0x2700,%sr" );
	
	coldfire_vbr_init();
	
	//store the serial ISR at user vector #64
	asm( "move.l #asm_serial_entry,%d0" );
	asm( "move.l %d0,0x10000100" );

	//reset the entire UART 
	SERIAL1_UCR = 0x10;

	//reset the receiver 
	SERIAL1_UCR = 0x20;
	
	//reset the transmitter 
	SERIAL1_UCR = 0x30;

	//reset the error condition
	SERIAL1_UCR = 0x40;

	//install the interupt
	SERIAL1_ICR = 0x17;
	SERIAL1_IVR = 64;

	//enable interrupts on rx only
	SERIAL1_IMR = 0x02;

	//set the baud rate
	SERIAL1_UBG1 = 0x00;
#ifdef _CFSERVER_           /* add -D_CFSERVER_ for cf-server build */
	SERIAL1_UBG2 = 0x49;    /* cf-server baud rate 19200 */ 
#else
	SERIAL1_UBG2 = 0x92;    /* lab board baud rate 9600 */
#endif 

	//set clock mode
	SERIAL1_UCSR = 0xDD;

	//setup the UART (no parity, 8 bits )
	SERIAL1_UMR = 0x13;
	
	//setup the rest of the UART (noecho, 1 stop bit )
	SERIAL1_UMR = 0x07;

	//setup for transmit and receive
	SERIAL1_UCR = 0x05;

	//enable interupts
	mask = SIM_IMR;
	mask &= 0x0003dfff;
	SIM_IMR = mask;

	//enable all interupts
	asm( "move.w #0x2000,%sr" );
	// end of keyboard interrupts
	
	
	// Start it up
	ScheduleNextProcess( rtxProcMan, NULL );
	
    return 0;
}
Example #18
0
File: place.c Project: KarlGodt/jwm
/** Tiled placement. */
char TileClient(const BoundingBox *box, ClientNode *np)
{

   const ClientNode *tp;
   int layer;
   int north, south, east, west;
   int i, j;
   int count;
   int *xs;
   int *ys;

   /* Determine how much space to allocate. */
   count = 1;
   for(layer = np->state.layer; layer < LAYER_COUNT; layer++) {
      for(tp = nodes[layer]; tp; tp = tp->next) {
         if(tp->state.desktop != currentDesktop) {
            if(!(tp->state.status & STAT_STICKY)) {
               continue;
            }
         }
         if(!(tp->state.status & STAT_MAPPED)) {
            continue;
         }
         if(tp == np) {
            continue;
         }
         count += 2;
      }
   }

   /* Allocate space for the points. */
   xs = AllocateStack(sizeof(int) * count);
   ys = AllocateStack(sizeof(int) * count);

   /* Insert points. */
   xs[0] = box->x;
   ys[0] = box->y;
   count = 1;
   for(layer = np->state.layer; layer < LAYER_COUNT; layer++) {
      for(tp = nodes[layer]; tp; tp = tp->next) {
         if(tp->state.desktop != currentDesktop) {
            if(!(tp->state.status & STAT_STICKY)) {
               continue;
            }
         }
         if(!(tp->state.status & STAT_MAPPED)) {
            continue;
         }
         if(tp == np) {
            continue;
         }
         GetBorderSize(&tp->state, &north, &south, &east, &west);
         xs[count + 0] = tp->x - west;
         xs[count + 1] = tp->x + tp->width + east;
         ys[count + 0] = tp->y - north;
         ys[count + 1] = tp->y + tp->height + south;
         count += 2;
      }
   }

   /* Sort the points. */
   qsort(xs, count, sizeof(int), IntComparator);
   qsort(ys, count, sizeof(int), IntComparator);

   /* Try all possible positions. */
   for(i = 0; i < count; i++) {
      for(j = 0; j < count; j++) {
         if(TryTileClient(box, np, xs[i], ys[j])) {
            ReleaseStack(xs);
            ReleaseStack(ys);
            return 1;
         }
      }
   }

   ReleaseStack(xs);
   ReleaseStack(ys);

   /* Tiled placement failed. */
   return 0;

}
Example #19
0
void AddTree(String NodeName, TreeNode T, int Nkid)
{
   Stack TempTree;
   TreeNode TempNode,KidNode,NewKid;
   int i, CurrKid;

   TempTree = AllocateStack(500);

   if(Nkid==1)
   {
      KidNode = T;
    
      while (Rank(KidNode) != 0)
         KidNode = Child(KidNode, 1);
   }

   else 
   {
      KidNode = Child(T, Nkid-1);
      KidNode = KidNode + Rank(KidNode) + 3;
   }

   for (i=1; i <= KidNode-1; i++)
      Push(TempTree, Element(Tree,i));                 /*copy previous nodes      */

   Push(TempTree, NodeName);
   NewKid = SizeOf(TempTree);
   Push(TempTree, UndefinedString);                    /* insert new node         */
   Push(TempTree, 0);
   TempNode = KidNode;
   
   while(TempNode < T)                                 /* Process nodes before T  */
   {
      Push(TempTree, Element(Tree, TempNode));         /*    copy Name,           */
      Push(TempTree, Element(Tree, TempNode+1));       /*          SourceLocation,*/
      Push(TempTree, Element(Tree, TempNode+2));       /*           Number of Kids*/

      for(i=1;i<=Element(Tree,TempNode+2);i++)
      {
         CurrKid = Element (Tree, TempNode + i + 2);

         if (CurrKid >= KidNode)                       /* copy pointers to kids   */
	    Push (TempTree, CurrKid+3);          
         else 
	    Push (TempTree, CurrKid);
      }

      TempNode = TempNode + Element (Tree, TempNode + 2) + 3;
   }
                                                       /* Process Node T          */
   Push(TempTree, Element(Tree, TempNode));    
   Push(TempTree, Element(Tree, TempNode+1));  
   Push(TempTree, Element(Tree, TempNode+2)+1);
  
   for(i=1;i<=Element(Tree, TempNode+2) - Nkid + 1;i++)
   {
      CurrKid = Element(Tree, TempNode + i + 2);

      if (CurrKid >= KidNode)                          /* copy pointers to kids   */
         Push(TempTree, CurrKid+3);                    /* before the new one.     */
      else 
         Push(TempTree, CurrKid);
   }

   Push (TempTree, NewKid);                             /* insert new kid          */

   for(i=1; i <= Nkid-1; i++)                           /* copy the remaining kids */
   { 
      CurrKid = Element (Tree, TempNode + Element(Tree,TempNode+2)-Nkid+3+i);

      if (CurrKid >= KidNode)                      
         Push(TempTree, CurrKid+3);         
      else 
         Push(TempTree, CurrKid);
   }

   TempNode = TempNode + Element (Tree, TempNode + 2) + 3;

   while(TempNode <= SizeOf(Tree))                     /* Process nodes after T   */
   {
      Push(TempTree, Element(Tree, TempNode));         /*    copy Name,           */
      Push(TempTree, Element(Tree, TempNode+1));       /*          SourceLocation,*/
      Push(TempTree, Element(Tree, TempNode+2));       /*           Number of Kids*/

      for(i=1;i<=Element(Tree, TempNode+2);i++)
      {
         CurrKid = Element (Tree, TempNode + i + 2);

         if(CurrKid >= KidNode)                        /* copy pointers to kids   */
	 {
            if (CurrKid > T) 
	       Push(TempTree, CurrKid+4);         
	    else 
	       Push(TempTree, CurrKid+3);
	 }

         else 
	    Push(TempTree, CurrKid);
      }

      TempNode = TempNode + Element (Tree, TempNode + 2) + 3;
   }

   if (RootOfTree(1) > T)
      Assign (TreeOrchard, 1, RootOfTree(1)+4);
   else 
      Assign (TreeOrchard, 1, RootOfTree(1)+3);

   Empty(Tree);

   for (i=1; i <= SizeOf(TempTree); i++)
      Push(Tree, Element(TempTree,i));
}
Example #20
0
File: hint.c Project: Miteam/jwm
/** Set root hints and intern atoms. */
void StartupHints(void)
{

   unsigned long *array;
   char *data;
   Atom *supported;
   Window win;
   unsigned int x;
   unsigned int count;

   /* Determine how much space we will need on the stack and allocate it. */
   count = 0;
   for(x = 0; x < settings.desktopCount; x++) {
      count += strlen(GetDesktopName(x)) + 1;
   }
   if(count < 2 * sizeof(unsigned long)) {
      count = 2 * sizeof(unsigned long);
   }
   if(count < ATOM_COUNT * sizeof(Atom)) {
      count = ATOM_COUNT * sizeof(Atom);
   }
   data = AllocateStack(count);
   array = (unsigned long*)data;
   supported = (Atom*)data;

   /* Intern the atoms */
   for(x = 0; x < ATOM_COUNT; x++) {
      *atomList[x].atom = JXInternAtom(display, atomList[x].name, False);
   }

   /* _NET_SUPPORTED */
   for(x = FIRST_NET_ATOM; x <= LAST_NET_ATOM; x++) {
      supported[x - FIRST_NET_ATOM] = atoms[x];
   }
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_SUPPORTED],
                    XA_ATOM, 32, PropModeReplace, (unsigned char*)supported,
                    LAST_NET_ATOM - FIRST_NET_ATOM + 1);

   /* _NET_NUMBER_OF_DESKTOPS */
   SetCardinalAtom(rootWindow, ATOM_NET_NUMBER_OF_DESKTOPS,
                   settings.desktopCount);

   /* _NET_DESKTOP_NAMES */
   count = 0;
   for(x = 0; x < settings.desktopCount; x++) {
      const char *name = GetDesktopName(x);
      const unsigned len = strlen(name);
      memcpy(&data[count], name, len + 1);
      count += len + 1;
   }
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_DESKTOP_NAMES],
                    atoms[ATOM_UTF8_STRING], 8, PropModeReplace,
                    (unsigned char*)data, count);

   /* _NET_DESKTOP_GEOMETRY */
   array[0] = rootWidth;
   array[1] = rootHeight;
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_DESKTOP_GEOMETRY],
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*)array, 2);

   /* _NET_DESKTOP_VIEWPORT */
   array[0] = 0;
   array[1] = 0;
   JXChangeProperty(display, rootWindow, atoms[ATOM_NET_DESKTOP_VIEWPORT],
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*)array, 2);

   /* _NET_WM_NAME */
   win = supportingWindow;
   JXChangeProperty(display, win, atoms[ATOM_NET_WM_NAME],
                    atoms[ATOM_UTF8_STRING], 8, PropModeReplace,
                    (unsigned char*)"JWM", 3);

   /* _NET_WM_PID */
   array[0] = getpid();
   JXChangeProperty(display, win, atoms[ATOM_NET_WM_PID],
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*)array, 1);

   /* _NET_SUPPORTING_WM_CHECK */
   SetWindowAtom(rootWindow, ATOM_NET_SUPPORTING_WM_CHECK, win);
   SetWindowAtom(win, ATOM_NET_SUPPORTING_WM_CHECK, win);

   ReleaseStack(data);

}
Example #21
0
/** Restack the clients according the way we want them. */
void RestackClients(void)
{

   TrayType *tp;
   ClientNode *np;
   unsigned int layer, index;
   int trayCount;
   Window *stack;
   Window fw;

   if(JUNLIKELY(shouldExit)) {
      return;
   }

   /* Allocate memory for restacking. */
   trayCount = GetTrayCount();
   stack = AllocateStack((clientCount + trayCount) * sizeof(Window));

   /* Prepare the stacking array. */
   fw = None;
   index = 0;
   if(activeClient && (activeClient->state.status & STAT_FULLSCREEN)) {
      fw = activeClient->window;
      for(np = nodes[activeClient->state.layer]; np; np = np->next) {
         if(np->owner == fw) {
            if(np->parent != None) {
               stack[index] = np->parent;
            } else {
               stack[index] = np->window;
            }
            index += 1;
         }
      }
      if(activeClient->parent != None) {
         stack[index] = activeClient->parent;
      } else {
         stack[index] = activeClient->window;
      }
      index += 1;
   }
   layer = LAST_LAYER;
   for(;;) {

      for(np = nodes[layer]; np; np = np->next) {
         if(    (np->state.status & (STAT_MAPPED | STAT_SHADED))
            && !(np->state.status & STAT_HIDDEN)) {
            if(fw != None && (np->window == fw || np->owner == fw)) {
               continue;
            }
            if(np->parent != None) {
               stack[index] = np->parent;
            } else {
               stack[index] = np->window;
            }
            index += 1;
         }
      }

      for(tp = GetTrays(); tp; tp = tp->next) {
         if(layer == tp->layer) {
            stack[index] = tp->window;
            index += 1;
         }
      }

      if(layer == FIRST_LAYER) {
         break;
      }
      layer -= 1;

   }

   JXRestackWindows(display, stack, index);

   ReleaseStack(stack);
   UpdateNetClientList();
   RequirePagerUpdate();

}